Use wxBSTR to prevent leaking BSTRs in wxWebViewIE.

This commit is contained in:
pbfordev
2017-06-16 21:38:13 +02:00
parent db22c91d44
commit 82104e0e54

View File

@@ -231,9 +231,9 @@ wxString wxWebViewIE::GetPageSource() const
hr = bodyTag->get_parentElement(&htmlTag); hr = bodyTag->get_parentElement(&htmlTag);
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
BSTR bstr; wxBSTR wxbstr;
if ( htmlTag->get_outerHTML(&bstr) == S_OK ) if ( htmlTag->get_outerHTML(wxbstr.GetAddress()) == S_OK )
source = wxString(bstr); source = wxbstr.GetwxString();
} }
} }
return source; return source;
@@ -576,9 +576,9 @@ wxString wxWebViewIE::GetCurrentTitle() const
wxString s; wxString s;
if(document) if(document)
{ {
BSTR title; wxBSTR title;
if ( document->get_nameProp(&title) == S_OK ) if ( document->get_nameProp(title.GetAddress()) == S_OK )
s = title; s = title.GetwxString();
} }
return s; return s;
@@ -705,10 +705,10 @@ bool wxWebViewIE::IsEditable() const
if(document) if(document)
{ {
BSTR mode; wxBSTR mode;
if ( document->get_designMode(&mode) == S_OK ) if ( document->get_designMode(mode.GetAddress()) == S_OK )
{ {
if ( wxString(mode) == "On" ) if ( mode.GetwxString() == "On" )
return true; return true;
} }
} }
@@ -731,9 +731,9 @@ bool wxWebViewIE::HasSelection() const
HRESULT hr = document->get_selection(&selection); HRESULT hr = document->get_selection(&selection);
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
BSTR type; wxBSTR type;
if ( selection->get_type(&type) == S_OK ) if ( selection->get_type(type.GetAddress()) == S_OK )
sel = wxString(type); sel = type.GetwxString();
} }
return sel != "None"; return sel != "None";
} }
@@ -767,9 +767,9 @@ wxString wxWebViewIE::GetSelectedText() const
hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range); hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
BSTR text; wxBSTR text;
if ( range->get_text(&text) == S_OK ) if ( range->get_text(text.GetAddress()) == S_OK )
selected = wxString(text); selected = text.GetwxString();
} }
} }
} }
@@ -800,9 +800,9 @@ wxString wxWebViewIE::GetSelectedSource() const
hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range); hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
BSTR text; wxBSTR text;
if ( range->get_htmlText(&text) == S_OK ) if ( range->get_htmlText(text.GetAddress()) == S_OK )
selected = wxString(text); selected = text.GetwxString();
} }
} }
} }
@@ -841,9 +841,9 @@ wxString wxWebViewIE::GetPageText() const
HRESULT hr = document->get_body(&body); HRESULT hr = document->get_body(&body);
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
BSTR out; wxBSTR out;
if ( body->get_innerText(&out) == S_OK ) if ( body->get_innerText(out.GetAddress()) == S_OK )
text = wxString(out); text = out.GetwxString();
} }
return text; return text;
} }
@@ -950,7 +950,7 @@ wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const
bool wxWebViewIE::IsElementVisible(wxCOMPtr<IHTMLElement> elm) bool wxWebViewIE::IsElementVisible(wxCOMPtr<IHTMLElement> elm)
{ {
wxCOMPtr<IHTMLElement> elm1 = elm; wxCOMPtr<IHTMLElement> elm1 = elm;
BSTR tmp_bstr; wxBSTR tmp_bstr;
bool is_visible = true; bool is_visible = true;
//This method is not perfect but it does discover most of the hidden elements. //This method is not perfect but it does discover most of the hidden elements.
//so if a better solution is found, then please do improve. //so if a better solution is found, then please do improve.
@@ -963,13 +963,13 @@ bool wxWebViewIE::IsElementVisible(wxCOMPtr<IHTMLElement> elm)
if(SUCCEEDED(elm2->get_currentStyle(&style))) if(SUCCEEDED(elm2->get_currentStyle(&style)))
{ {
//Check if the object has the style display:none. //Check if the object has the style display:none.
if((style->get_display(&tmp_bstr) != S_OK) || if((style->get_display(tmp_bstr.GetAddress()) != S_OK) ||
(tmp_bstr != NULL && (wxCRT_StricmpW(tmp_bstr, L"none") == 0))) (tmp_bstr != NULL && (wxCRT_StricmpW(tmp_bstr, L"none") == 0)))
{ {
is_visible = false; is_visible = false;
} }
//Check if the object has the style visibility:hidden. //Check if the object has the style visibility:hidden.
if((is_visible && (style->get_visibility(&tmp_bstr) != S_OK)) || if((is_visible && (style->get_visibility(tmp_bstr.GetAddress()) != S_OK)) ||
(tmp_bstr != NULL && wxCRT_StricmpW(tmp_bstr, L"hidden") == 0)) (tmp_bstr != NULL && wxCRT_StricmpW(tmp_bstr, L"hidden") == 0))
{ {
is_visible = false; is_visible = false;
@@ -1007,8 +1007,8 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla
if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC))) if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC)))
{ {
wxCOMPtr<wxIMarkupPointer> ptrBegin, ptrEnd; wxCOMPtr<wxIMarkupPointer> ptrBegin, ptrEnd;
BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\""); wxBSTR attr_bstr(L"style=\"background-color:#ffff00\"");
BSTR text_bstr = SysAllocString(text.wc_str()); wxBSTR text_bstr(text.wc_str());
pIMS->CreateMarkupPointer(&ptrBegin); pIMS->CreateMarkupPointer(&ptrBegin);
pIMS->CreateMarkupPointer(&ptrEnd); pIMS->CreateMarkupPointer(&ptrEnd);
@@ -1064,9 +1064,6 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla
} }
ptrBegin->MoveToPointer(ptrEnd); ptrBegin->MoveToPointer(ptrEnd);
} }
//Clean up.
SysFreeString(text_bstr);
SysFreeString(attr_bstr);
} }
} }
} }