Add better error checking to wxWebViewIE
Verify that accessing a property really succeeded before using the returned value. This should fix at least one crash due to the use of uninitialized BSTR in wxWebViewIE::GetCurrentTitle(). Closes #17204.
This commit is contained in:
committed by
Vadim Zeitlin
parent
8ce5b9099b
commit
4489ec80e0
@@ -232,7 +232,7 @@ wxString wxWebViewIE::GetPageSource() const
|
|||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
BSTR bstr;
|
BSTR bstr;
|
||||||
htmlTag->get_outerHTML(&bstr);
|
if ( htmlTag->get_outerHTML(&bstr) == S_OK )
|
||||||
source = wxString(bstr);
|
source = wxString(bstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -573,16 +573,15 @@ wxString wxWebViewIE::GetCurrentTitle() const
|
|||||||
{
|
{
|
||||||
wxCOMPtr<IHTMLDocument2> document(GetDocument());
|
wxCOMPtr<IHTMLDocument2> document(GetDocument());
|
||||||
|
|
||||||
|
wxString s;
|
||||||
if(document)
|
if(document)
|
||||||
{
|
{
|
||||||
BSTR title;
|
BSTR title;
|
||||||
document->get_nameProp(&title);
|
if ( document->get_nameProp(&title) == S_OK )
|
||||||
return wxString(title);
|
s = title;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxWebViewIE::CanCut() const
|
bool wxWebViewIE::CanCut() const
|
||||||
@@ -707,16 +706,13 @@ bool wxWebViewIE::IsEditable() const
|
|||||||
if(document)
|
if(document)
|
||||||
{
|
{
|
||||||
BSTR mode;
|
BSTR mode;
|
||||||
document->get_designMode(&mode);
|
if ( document->get_designMode(&mode) == S_OK )
|
||||||
if(wxString(mode) == "On")
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return false;
|
if ( wxString(mode) == "On" )
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewIE::SelectAll()
|
void wxWebViewIE::SelectAll()
|
||||||
@@ -736,7 +732,7 @@ bool wxWebViewIE::HasSelection() const
|
|||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
BSTR type;
|
BSTR type;
|
||||||
selection->get_type(&type);
|
if ( selection->get_type(&type) == S_OK )
|
||||||
sel = wxString(type);
|
sel = wxString(type);
|
||||||
}
|
}
|
||||||
return sel != "None";
|
return sel != "None";
|
||||||
@@ -772,7 +768,7 @@ wxString wxWebViewIE::GetSelectedText() const
|
|||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
BSTR text;
|
BSTR text;
|
||||||
range->get_text(&text);
|
if ( range->get_text(&text) == S_OK )
|
||||||
selected = wxString(text);
|
selected = wxString(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -805,7 +801,7 @@ wxString wxWebViewIE::GetSelectedSource() const
|
|||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
BSTR text;
|
BSTR text;
|
||||||
range->get_htmlText(&text);
|
if ( range->get_htmlText(&text) == S_OK )
|
||||||
selected = wxString(text);
|
selected = wxString(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -846,7 +842,7 @@ wxString wxWebViewIE::GetPageText() const
|
|||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
BSTR out;
|
BSTR out;
|
||||||
body->get_innerText(&out);
|
if ( body->get_innerText(&out) == S_OK )
|
||||||
text = wxString(out);
|
text = wxString(out);
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
|
Reference in New Issue
Block a user