Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginTabBase.cpp

Issue 11364091: Fix ABP pages on refresh (Closed)
Patch Set: Created Aug. 8, 2013, 6:45 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginTabBase.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginTabBase.cpp
===================================================================
--- a/src/plugin/PluginTabBase.cpp
+++ b/src/plugin/PluginTabBase.cpp
@@ -109,6 +109,52 @@
#endif
}
+void CPluginTabBase::InjectABP(IWebBrowser2* browser)
+{
+ CString url = GetDocumentUrl();
+ CString log;
+ log.Format(L"Current URL: %s, settings URL: %s", url, UserSettingsFileUrl().c_str());
+ DEBUG_GENERAL(log);
+ if (0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
+ 0 == url.CompareNoCase(CString(FirstRunPageFileUrl().c_str())) )
+ {
+ CComPtr<IDispatch> pDocDispatch;
+ browser->get_Document(&pDocDispatch);
+ CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch;
+ if (pDoc2)
Wladimir Palant 2013/08/13 09:48:34 Now that this is a separate function we can avoid
+ {
+ CComPtr<IHTMLWindow2> pWnd2;
+ pDoc2->get_parentWindow(&pWnd2);
+ if (pWnd2)
+ {
+ CComQIPtr<IDispatchEx> pWndEx = pWnd2;
+ if (pWndEx)
+ {
+ // Create "Settings" object in JavaScript.
+ // A method call of "Settings" in JavaScript, transfered to "Invoke" of m_pluginUserSettings
+ DISPID dispid;
+ HRESULT hr = pWndEx->GetDispID(L"Settings", fdexNameEnsure, &dispid);
+ if (SUCCEEDED(hr))
+ {
+ CComVariant var((IDispatch*)&m_pluginUserSettings);
+
+ DISPPARAMS params;
+ params.cArgs = 1;
+ params.cNamedArgs = 0;
+ params.rgvarg = &var;
+ params.rgdispidNamedArgs = 0;
+ hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0);
+ if (FAILED(hr))
+ {
+ DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::OnDocumentComplete - Failed to create Settings in JavaScript");
Felix Dahlke 2013/08/08 08:47:53 It's CPluginTabBase::InjectABP now, isn't it?
Oleksandr 2013/08/08 14:08:47 It is, yes. On 2013/08/08 08:47:53, Felix H. Dahlk
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser)
{
#ifdef SUPPORT_DOM_TRAVERSER
@@ -117,9 +163,10 @@
m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl());
}
#endif // SUPPORT_DOM_TRAVERSER
+
+ InjectABP(browser);
}
-
void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& url, bool isDocumentBrowser)
{
CString documentUrl = GetDocumentUrl();
@@ -130,48 +177,7 @@
{
SetDocumentUrl(url);
}
-
- CString log;
- log.Format(L"Current URL: %s, settings URL: %s", url, UserSettingsFileUrl().c_str());
- DEBUG_GENERAL(log);
- if (0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
- 0 == url.CompareNoCase(CString(FirstRunPageFileUrl().c_str())) )
- {
- CComPtr<IDispatch> pDocDispatch;
- browser->get_Document(&pDocDispatch);
- CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch;
- if (pDoc2)
- {
- CComPtr<IHTMLWindow2> pWnd2;
- pDoc2->get_parentWindow(&pWnd2);
- if (pWnd2)
- {
- CComQIPtr<IDispatchEx> pWndEx = pWnd2;
- if (pWndEx)
- {
- // Create "Settings" object in JavaScript.
- // A method call of "Settings" in JavaScript, transfered to "Invoke" of m_pluginUserSettings
- DISPID dispid;
- HRESULT hr = pWndEx->GetDispID(L"Settings", fdexNameEnsure, &dispid);
- if (SUCCEEDED(hr))
- {
- CComVariant var((IDispatch*)&m_pluginUserSettings);
-
- DISPPARAMS params;
- params.cArgs = 1;
- params.cNamedArgs = 0;
- params.rgvarg = &var;
- params.rgdispidNamedArgs = 0;
- hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0);
- if (FAILED(hr))
- {
- DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::OnDocumentComplete - Failed to create Settings in JavaScript");
- }
- }
- }
- }
- }
- }
+ InjectABP(browser);
Felix Dahlke 2013/08/08 08:47:53 So OnDocumentComplete is only called once, not on
Oleksandr 2013/08/08 14:08:47 No, I have checked the events raised. It isn't fir
Felix Dahlke 2013/08/08 14:19:05 So, initially, OnDocumentComplete is fired and OnD
Oleksandr 2013/08/08 16:00:04 No, I got it a bit wrong actually. Both events are
Felix Dahlke 2013/08/08 16:20:59 That's fine by me, but isn't InjectABP being calle
Oleksandr 2013/08/09 07:07:48 InjectABP can get called even more then twice per
}
#ifdef SUPPORT_DOM_TRAVERSER
« no previous file with comments | « src/plugin/PluginTabBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld