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().
See #17204.
(this is a backport of 4489ec80e0
from master)
This commit is contained in:
committed by
Vadim Zeitlin
parent
668be48b65
commit
56a3441663
@@ -281,8 +281,8 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return source;
|
return source;
|
||||||
@@ -622,16 +622,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
|
||||||
@@ -756,16 +755,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;
|
if ( wxString(mode) == "On" )
|
||||||
else
|
return true;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewIE::SelectAll()
|
void wxWebViewIE::SelectAll()
|
||||||
@@ -785,8 +781,8 @@ 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";
|
||||||
}
|
}
|
||||||
@@ -821,8 +817,8 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -854,8 +850,8 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -895,8 +891,8 @@ 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