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, ¶ms, 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, ¶ms, 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 |