Correctly use QueryInterface in GetDocument to ensure that we only return an IHTMLDocument2 pointer if one is available. Check GetDocument being NULL when used. This fixes the displaying of non-html documents such as pdfs.

Fixes #14060

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Steve Lamerton
2012-03-27 19:33:59 +00:00
parent 0ffc170455
commit e81ef29720

View File

@@ -122,6 +122,10 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
hr = SafeArrayUnaccessData(psaStrings);
IHTMLDocument2* document = GetDocument();
if(!document)
return;
document->write(psaStrings);
document->close();
document->Release();
@@ -140,6 +144,10 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
hr = SafeArrayUnaccessData(psaStrings);
document = GetDocument();
if(!document)
return;
document->write(psaStrings);
document->Release();
@@ -172,6 +180,9 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
wxString wxWebViewIE::GetPageSource() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLElement *bodyTag = NULL;
IHTMLElement *htmlTag = NULL;
wxString source;
@@ -192,6 +203,11 @@ wxString wxWebViewIE::GetPageSource() const
document->Release();
return source;
}
else
{
return "";
}
}
wxWebViewZoom wxWebViewIE::GetZoom() const
{
@@ -521,12 +537,19 @@ wxString wxWebViewIE::GetCurrentURL() const
wxString wxWebViewIE::GetCurrentTitle() const
{
IHTMLDocument2* document = GetDocument();
BSTR title;
if(document)
{
BSTR title;
document->get_nameProp(&title);
document->Release();
return wxString(title);
}
else
{
return "";
}
}
bool wxWebViewIE::CanCut() const
{
@@ -579,6 +602,9 @@ void wxWebViewIE::Redo()
void wxWebViewIE::SetEditable(bool enable)
{
IHTMLDocument2* document = GetDocument();
if(document)
{
if( enable )
document->put_designMode(SysAllocString(L"On"));
else
@@ -586,10 +612,14 @@ void wxWebViewIE::SetEditable(bool enable)
document->Release();
}
}
bool wxWebViewIE::IsEditable() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
BSTR mode;
document->get_designMode(&mode);
document->Release();
@@ -598,6 +628,11 @@ bool wxWebViewIE::IsEditable() const
else
return false;
}
else
{
return false;
}
}
void wxWebViewIE::SelectAll()
{
@@ -607,6 +642,9 @@ void wxWebViewIE::SelectAll()
bool wxWebViewIE::HasSelection() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString sel;
HRESULT hr = document->get_selection(&selection);
@@ -620,6 +658,11 @@ bool wxWebViewIE::HasSelection() const
document->Release();
return sel != "None";
}
else
{
return false;
}
}
void wxWebViewIE::DeleteSelection()
{
@@ -629,6 +672,9 @@ void wxWebViewIE::DeleteSelection()
wxString wxWebViewIE::GetSelectedText() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
@@ -654,10 +700,18 @@ wxString wxWebViewIE::GetSelectedText() const
document->Release();
return selected;
}
else
{
return "";
}
}
wxString wxWebViewIE::GetSelectedSource() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
@@ -683,10 +737,18 @@ wxString wxWebViewIE::GetSelectedSource() const
document->Release();
return selected;
}
else
{
return "";
}
}
void wxWebViewIE::ClearSelection()
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
@@ -697,10 +759,14 @@ void wxWebViewIE::ClearSelection()
}
document->Release();
}
}
wxString wxWebViewIE::GetPageText() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
wxString text;
IHTMLElement* body;
HRESULT hr = document->get_body(&body);
@@ -714,10 +780,18 @@ wxString wxWebViewIE::GetPageText() const
document->Release();
return text;
}
else
{
return "";
}
}
void wxWebViewIE::RunScript(const wxString& javascript)
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLWindow2* window;
wxString language = "javascript";
HRESULT hr = document->get_parentWindow(&window);
@@ -732,6 +806,7 @@ void wxWebViewIE::RunScript(const wxString& javascript)
}
document->Release();
}
}
void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
{
@@ -767,6 +842,9 @@ void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
bool wxWebViewIE::CanExecCommand(wxString command) const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
VARIANT_BOOL enabled;
document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
@@ -774,23 +852,40 @@ bool wxWebViewIE::CanExecCommand(wxString command) const
return (enabled == VARIANT_TRUE);
}
else
{
return false;
}
}
void wxWebViewIE::ExecCommand(wxString command)
{
IHTMLDocument2* document = GetDocument();
if(document)
{
document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
document->Release();
}
}
IHTMLDocument2* wxWebViewIE::GetDocument() const
{
wxVariant variant = m_ie.GetProperty("Document");
IHTMLDocument2* document = (IHTMLDocument2*)variant.GetVoidPtr();
wxASSERT(document);
IDispatch* dispatch;
HRESULT result = m_webBrowser->get_Document(&dispatch);
if(SUCCEEDED(result))
{
IHTMLDocument2* document;
dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document);
//document is set to null automatically if the interface isn't supported
return document;
}
else
{
return NULL;
}
}
bool wxWebViewIE::EnableControlFeature(long flag, bool enable)
{