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

Side by Side Diff: src/plugin/PluginClass.cpp

Issue 4937147073167360: Issue 1672 - Subscribe and listen COM events using ATL::IDispEventImpl and BEGIN_SINK_MAP (Closed)
Patch Set: rebase, parent = 5d5eb4df1bf2 Created March 13, 2015, 3:20 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginErrorCodes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return right - left; 87 return right - left;
88 } 88 }
89 }; 89 };
90 } 90 }
91 91
92 CPluginClass::CPluginClass() 92 CPluginClass::CPluginClass()
93 { 93 {
94 //Use this line to debug memory leaks 94 //Use this line to debug memory leaks
95 // _CrtDumpMemoryLeaks(); 95 // _CrtDumpMemoryLeaks();
96 96
97 m_isAdviced = false; 97 m_isAdvised = false;
98 m_nConnectionID = 0;
99 m_hTabWnd = NULL; 98 m_hTabWnd = NULL;
100 m_hStatusBarWnd = NULL; 99 m_hStatusBarWnd = NULL;
101 m_hPaneWnd = NULL; 100 m_hPaneWnd = NULL;
102 m_nPaneWidth = 0; 101 m_nPaneWidth = 0;
103 m_pWndProcStatus = NULL; 102 m_pWndProcStatus = NULL;
104 m_hTheme = NULL; 103 m_hTheme = NULL;
105 m_isInitializedOk = false; 104 m_isInitializedOk = false;
106 105
107 106
108 m_tab = new CPluginTab(this); 107 m_tab = new CPluginTab(this);
(...skipping 17 matching lines...) Expand all
126 125
127 void CPluginClass::FinalRelease() 126 void CPluginClass::FinalRelease()
128 { 127 {
129 s_criticalSectionBrowser.Lock(); 128 s_criticalSectionBrowser.Lock();
130 { 129 {
131 m_webBrowser2.Release(); 130 m_webBrowser2.Release();
132 } 131 }
133 s_criticalSectionBrowser.Unlock(); 132 s_criticalSectionBrowser.Unlock();
134 } 133 }
135 134
136
137 // This method tries to get a 'connection point' from the stored browser, which can be
138 // used to attach or detach from the stream of browser events
139 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPoint()
140 {
141 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser());
142 if (!pContainer)
143 {
144 return NULL;
145 }
146
147 CComPtr<IConnectionPoint> pPoint;
148 HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint) ;
149 if (FAILED(hr))
150 {
151 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint")
152 return NULL;
153 }
154
155 return pPoint;
156 }
157
158 HWND CPluginClass::GetBrowserHWND() const 135 HWND CPluginClass::GetBrowserHWND() const
159 { 136 {
160 SHANDLE_PTR hBrowserWndHandle = NULL; 137 SHANDLE_PTR hBrowserWndHandle = NULL;
161 138
162 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 139 CComQIPtr<IWebBrowser2> browser = GetBrowser();
163 if (browser) 140 if (browser)
164 { 141 {
165 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); 142 HRESULT hr = browser->get_HWND(&hBrowserWndHandle);
166 if (FAILED(hr)) 143 if (FAILED(hr))
167 { 144 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 196 }
220 return url; 197 return url;
221 } 198 }
222 199
223 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
224 { 201 {
225 if (thisPtr == NULL) 202 if (thisPtr == NULL)
226 return 0; 203 return 0;
227 if (!((CPluginClass*)thisPtr)->InitObject(true)) 204 if (!((CPluginClass*)thisPtr)->InitObject(true))
228 { 205 {
229 ((CPluginClass*)thisPtr)->Unadvice(); 206 ((CPluginClass*)thisPtr)->Unadvise();
230 } 207 }
231 208
232 return 0; 209 return 0;
233 } 210 }
234 211
235
236
237 // This gets called when a new browser window is created (which also triggers th e 212 // This gets called when a new browser window is created (which also triggers th e
238 // creation of this object). The pointer passed in should be to a IWebBrowser2 213 // creation of this object). The pointer passed in should be to a IWebBrowser2
239 // interface that represents the browser for the window. 214 // interface that represents the browser for the window.
240 // it is also called when a tab is closed, this unknownSite will be null 215 // it is also called when a tab is closed, this unknownSite will be null
241 // so we should handle that it is called this way several times during a session 216 // so we should handle that it is called this way several times during a session
242 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 217 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
243 { 218 {
244 CPluginSettings* settings = CPluginSettings::GetInstance(); 219 CPluginSettings* settings = CPluginSettings::GetInstance();
245 220
246 MULTIPLE_VERSIONS_CHECK(); 221 MULTIPLE_VERSIONS_CHECK();
(...skipping 24 matching lines...) Expand all
271 // Always register on startup, then check if we need to unregister in a se parate thread 246 // Always register on startup, then check if we need to unregister in a se parate thread
272 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 247 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
273 s_asyncWebBrowser2 = unknownSite; 248 s_asyncWebBrowser2 = unknownSite;
274 s_instances.insert(this); 249 s_instances.insert(this);
275 } 250 }
276 s_criticalSectionLocal.Unlock(); 251 s_criticalSectionLocal.Unlock();
277 252
278 try 253 try
279 { 254 {
280 // Check if loaded as BHO 255 // Check if loaded as BHO
281 if (GetBrowser()) 256 auto webBrowser = GetBrowser();
257 if (webBrowser)
282 { 258 {
283 DEBUG_GENERAL("Loaded as BHO"); 259 DEBUG_GENERAL("Loaded as BHO");
284 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 260 HRESULT hr = DispEventAdvise(webBrowser);
285 if (pPoint) 261 if (SUCCEEDED(hr))
286 { 262 {
287 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID); 263 m_isAdvised = true;
288 if (SUCCEEDED(hr)) 264 try
289 { 265 {
290 m_isAdviced = true; 266 std::thread startInitObjectThread(StartInitObject, this);
291 267 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
292 try
293 {
294 std::thread startInitObjectThread(StartInitObject, this);
295 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr.
296 }
297 catch (const std::system_error& ex)
298 {
299 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_ THREAD_CREATE_PROCESS,
300 "Class::Thread - Failed to create StartInitObject thread");
301 }
302 } 268 }
303 else 269 catch (const std::system_error& ex)
304 { 270 {
305 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advice"); 271 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS,
272 "Class::Thread - Failed to create StartInitObject thread");
306 } 273 }
307 } 274 }
275 else
276 {
277 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
278 }
308 } 279 }
309 else // Check if loaded as toolbar handler 280 else // Check if loaded as toolbar handler
310 { 281 {
311 DEBUG_GENERAL("Loaded as toolbar handler"); 282 DEBUG_GENERAL("Loaded as toolbar handler");
312 CComPtr<IServiceProvider> pServiceProvider; 283 CComPtr<IServiceProvider> pServiceProvider;
313 284
314 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); 285 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider);
315 if (SUCCEEDED(hr)) 286 if (SUCCEEDED(hr))
316 { 287 {
317 if (pServiceProvider) 288 if (pServiceProvider)
(...skipping 18 matching lines...) Expand all
336 } 307 }
337 else 308 else
338 { 309 {
339 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); 310 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)");
340 } 311 }
341 } 312 }
342 } 313 }
343 catch (const std::runtime_error& ex) 314 catch (const std::runtime_error& ex)
344 { 315 {
345 DEBUG_EXCEPTION(ex); 316 DEBUG_EXCEPTION(ex);
346 Unadvice(); 317 Unadvise();
347 } 318 }
348 } 319 }
349 else 320 else
350 { 321 {
351 // Unadvice 322 Unadvise();
352 Unadvice();
353 323
354 // Destroy window 324 // Destroy window
355 if (m_pWndProcStatus) 325 if (m_pWndProcStatus)
356 { 326 {
357 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP rocStatus); 327 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP rocStatus);
358 328
359 m_pWndProcStatus = NULL; 329 m_pWndProcStatus = NULL;
360 } 330 }
361 331
362 if (m_hPaneWnd) 332 if (m_hPaneWnd)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 480 }
511 } 481 }
512 else 482 else
513 { 483 {
514 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state"); 484 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
515 } 485 }
516 } 486 }
517 DEBUG_GENERAL("ShowStatusBar end"); 487 DEBUG_GENERAL("ShowStatusBar end");
518 } 488 }
519 489
520 /* 490 // Entry point
521 * #1163 This class is the implementation for method DISPID_BEFORENAVIGATE2 in C PluginClass::Invoke. 491 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2(
522 * - It validates and convertes its own arguments, rather than unifying them in the Invoke body. 492 /* [in] */ IDispatch* frameBrowserDisp,
523 * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu rn S_OK. 493 /* [in] */ VARIANT* urlVariant,
524 */ 494 /* [in] */ VARIANT* /*Flags*/,
525 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) 495 /* [in] */ VARIANT* /*TargetFrameName*/,
526 { 496 /* [in] */ VARIANT* /*PostData*/,
527 497 /* [in] */ VARIANT* /*Headers*/,
528 if (pDispParams->cArgs < 7) 498 /* [in, out] */ VARIANT_BOOL* /*Cancel*/)
529 { 499 {
530 return; 500 try
531 } 501 {
532 //Register a mime filter if it's not registered yet 502 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
533 if (s_mimeFilter == NULL) 503 if (!webBrowser)
534 { 504 {
535 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 505 return;
536 } 506 }
537 507 if (!urlVariant || urlVariant->vt != VT_BSTR)
538 // Get the IWebBrowser2 interface 508 {
539 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr; 509 return;
540 VARTYPE vt = pDispParams->rgvarg[6].vt; 510 }
541 if (vt == VT_DISPATCH) 511 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
542 { 512 UnescapeUrl(url);
543 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; 513
544 } 514 //Register a mime filter if it's not registered yet
545 else 515 if (s_mimeFilter == nullptr)
546 { 516 {
547 // Wrong type, return. 517 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
548 return; 518 }
549 } 519 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
550 520 // navigating new page
551 // Get the URL 521 CPluginClient* client = CPluginClient::GetInstance();
552 std::wstring url; 522 if (url.find(L"javascript") == 0)
553 const auto& arg = pDispParams->rgvarg[5]; 523 {
554 vt = arg.vt; 524 }
555 if (vt == (VT_BYREF | VT_VARIANT) && arg.pvarVal->vt == VT_BSTR) 525 else if (GetBrowser().IsEqualObject(webBrowser))
556 { 526 {
557 BSTR b = arg.pvarVal->bstrVal; 527 m_tab->OnNavigate(url);
558 if (b) { 528 DEBUG_GENERAL(
559 url = std::wstring(b, SysStringLen(b));
560 UnescapeUrl(url);
561 }
562 }
563 else
564 {
565 // Wrong type, return.
566 return;
567 }
568
569 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page
570 CPluginClient* client = CPluginClient::GetInstance();
571 CString urlLegacy = ToCString(url);
572 if (urlLegacy.Find(L"javascript") == 0)
573 {
574 }
575 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr))
576 {
577 m_tab->OnNavigate(url);
578
579 DEBUG_GENERAL(
580 L"======================================================================== ========\n" 529 L"======================================================================== ========\n"
581 L"Begin main navigation url:" + url + L"\n" 530 L"Begin main navigation url:" + url + L"\n"
582 L"======================================================================== ========") 531 L"======================================================================== ========")
583 532
584 #ifdef ENABLE_DEBUG_RESULT 533 #ifdef ENABLE_DEBUG_RESULT
585 CPluginDebug::DebugResultDomain(url); 534 CPluginDebug::DebugResultDomain(url);
586 #endif 535 #endif
587 536 UpdateStatusBar();
588 UpdateStatusBar(); 537 }
589 } 538 else
590 else 539 {
591 { 540 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
592 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 541 m_tab->CacheFrame(url);
593 m_tab->CacheFrame(url); 542 }
594 } 543 }
595 } 544 catch (...)
596 545 {
597 /* 546 }
598 * #1163 implements behavior for method DISPID_WINDOWSTATECHANGED in CPluginClas s::Invoke 547 }
599 * - should validate and convert arguments in Invoke, not here 548
600 * - does not validate number of arguments before indexing into 'rgvarg' 549 // Entry point
601 * - does not validate type of argument before using its value 550 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
602 */
603 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags)
604 {
605 DEBUG_GENERAL("Tab changed");
606 bool newtabshown = pDispParams->rgvarg[1].intVal==3;
607 if (newtabshown)
608 {
609 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId());
610 if (it == s_threadInstances.end())
611 {
612 s_threadInstances[::GetCurrentThreadId()] = this;
613 if (!m_isInitializedOk)
614 {
615 m_isInitializedOk = true;
616 InitObject(true);
617 UpdateStatusBar();
618 }
619 }
620 }
621 notificationMessage.Hide();
622 DEBUG_GENERAL("Tab change end");
623 return S_OK;
624 }
625
626 // This gets called whenever there's a browser event
627 // ENTRY POINT
628 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
629 { 551 {
630 try 552 try
631 { 553 {
632 WCHAR tmp[256]; 554 DEBUG_NAVI(L"Navi::Download Complete")
633 wsprintf(tmp, L"Invoke: %d\n", dispidMember); 555 ATL::CComPtr<IWebBrowser2> browser = GetBrowser();
634 DEBUG_GENERAL(tmp); 556 if (browser)
635 switch (dispidMember) 557 {
636 { 558 m_tab->OnDownloadComplete(browser);
637 case DISPID_WINDOWSTATECHANGED: 559 }
638 { 560 }
639 // #1163 should validate and convert arguments here 561 catch (...)
640 return OnTabChanged(pDispParams, wFlags); 562 {
641 } 563 }
642 564 }
643 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE: 565
644 break; 566 // Entry point
645 567 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
646 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK: 568 {
647 break; 569 try
648 570 {
649 case DISPID_EVMETH_ONLOAD: 571 DEBUG_NAVI(L"Navi::Document Complete");
650 DEBUG_NAVI("Navi::OnLoad") 572 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
651 break; 573 if (!webBrowser2)
652 574 {
653 case DISPID_EVMETH_ONCHANGE: 575 return;
654 break; 576 }
655 577 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
656 case DISPID_EVMETH_ONMOUSEDOWN: 578 UnescapeUrl(frameSrc);
657 break; 579 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2);
658 580 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
659 case DISPID_EVMETH_ONMOUSEENTER: 581 }
660 break; 582 catch (...)
661 583 {
662 case DISPID_IHTMLIMGELEMENT_START: 584 }
663 break; 585 }
664 586
665 case STDDISPID_XOBJ_ERRORUPDATE: 587 // Entry point
666 break; 588 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
667 589 {
668 case STDDISPID_XOBJ_ONPROPERTYCHANGE: 590 try
669 break; 591 {
670 592 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)");
671 case DISPID_READYSTATECHANGE: 593 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED)
672 DEBUG_NAVI("Navi::ReadyStateChange"); 594 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA BLED);
673 break; 595 if (newtabshown)
674 596 {
675 case DISPID_BEFORENAVIGATE: 597 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find( GetCurrentThreadId());
676 DEBUG_NAVI("Navi::BeforeNavigate"); 598 if (it == s_threadInstances.end())
677 break; 599 {
678 600 s_threadInstances[::GetCurrentThreadId()] = this;
679 case DISPID_COMMANDSTATECHANGE: 601 if (!m_isInitializedOk)
680 if (m_hPaneWnd == NULL) 602 {
681 { 603 m_isInitializedOk = true;
682 CreateStatusBarPane(); 604 InitObject(true);
683 } 605 UpdateStatusBar();
684 else 606 }
685 { 607 }
608 }
609 notificationMessage.Hide();
610 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end");
611 }
612 catch (...)
613 {
614 }
615 }
616
617 // Entry point
618 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/)
619 {
620 try
621 {
622 if (m_hPaneWnd == NULL)
623 {
624 CreateStatusBarPane();
625 }
626 else
627 {
686 if (AdblockPlus::IE::InstalledMajorVersion() > 6) 628 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
687 { 629 {
688 RECT rect; 630 RECT rect;
689 //Get the RECT for the leftmost pane (the status text pane) 631 //Get the RECT for the leftmost pane (the status text pane)
690 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)& rect); 632 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&re ct);
691 if (rectRes == TRUE) 633 if (rectRes == TRUE)
692 { 634 {
693 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, r ect.bottom - rect.top, TRUE); 635 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, rec t.bottom - rect.top, TRUE);
694 } 636 }
695 } 637 }
696 } 638 }
697 break; 639 }
698 640 catch (...)
699 case DISPID_STATUSTEXTCHANGE: 641 {
700 break; 642 }
701 643 }
702 case DISPID_BEFORENAVIGATE2: 644
703 { 645 // Entry point
704 // #1163 should validate and convert parameters here 646 void STDMETHODCALLTYPE CPluginClass::OnOnQuit()
705 BeforeNavigate2(pDispParams); 647 {
706 } 648 try
707 break; 649 {
708 650 Unadvise();
709 case DISPID_DOWNLOADBEGIN: 651 }
710 { 652 catch (...)
711 DEBUG_NAVI("Navi::Download Begin") 653 {
712 } 654 }
713 break;
714
715 case DISPID_DOWNLOADCOMPLETE:
716 {
717 DEBUG_NAVI("Navi::Download Complete");
718 CComQIPtr<IWebBrowser2> browser = GetBrowser();
719 if (browser)
720 {
721 m_tab->OnDownloadComplete(browser);
722 }
723 }
724 break;
725
726 case DISPID_DOCUMENTCOMPLETE:
727 {
728 DEBUG_NAVI("Navi::Document Complete");
729 CComQIPtr<IWebBrowser2> browser = GetBrowser();
730 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V T_DISPATCH)
731 {
732 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
733 if (pBrowser)
734 {
735 CComBSTR bstrUrl;
736 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && bstrUrl && ::S ysStringLen(bstrUrl) > 0)
737 {
738 std::wstring url = std::wstring(bstrUrl, SysStringLen(bstrUrl));
739 UnescapeUrl(url);
740 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBro wser));
741 }
742 }
743 }
744 }
745 break;
746
747 case DISPID_ONQUIT:
748 case DISPID_QUIT:
749 {
750 Unadvice();
751 }
752 break;
753
754 default:
755 {
756 CString did;
757 did.Format(L"DispId:%u", dispidMember);
758
759 DEBUG_NAVI(L"Navi::Default " + did)
760 }
761 /*
762 * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND.
763 * As a conservative initial change, we leave it behaving as before,
764 * which is to do nothing and return S_OK.
765 */
766 // do nothing
767 break;
768 }
769 }
770 catch(...)
771 {
772 DEBUG_GENERAL( "Caught unknown exception in CPluginClass::Invoke" );
773 return E_FAIL;
774 }
775 return S_OK;
776 } 655 }
777 656
778 bool CPluginClass::InitObject(bool bBHO) 657 bool CPluginClass::InitObject(bool bBHO)
779 { 658 {
780 DEBUG_GENERAL("InitObject"); 659 DEBUG_GENERAL("InitObject");
781 CPluginSettings* settings = CPluginSettings::GetInstance(); 660 CPluginSettings* settings = CPluginSettings::GetInstance();
782 661
783 if (!settings->GetPluginEnabled()) 662 if (!settings->GetPluginEnabled())
784 { 663 {
785 s_mimeFilter->Unregister(); 664 s_mimeFilter->Unregister();
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 { 1645 {
1767 CreateStatusBarPane(); 1646 CreateStatusBarPane();
1768 } 1647 }
1769 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1648 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1770 { 1649 {
1771 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1650 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1772 } 1651 }
1773 } 1652 }
1774 1653
1775 1654
1776 void CPluginClass::Unadvice() 1655 void CPluginClass::Unadvise()
1777 { 1656 {
1778 s_criticalSectionLocal.Lock(); 1657 s_criticalSectionLocal.Lock();
1779 { 1658 {
1780 if (m_isAdviced) 1659 if (m_isAdvised)
1781 { 1660 {
1782 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 1661 HRESULT hr = DispEventUnadvise(GetBrowser());
1783 if (pPoint) 1662 if (FAILED(hr))
1784 { 1663 {
1785 HRESULT hr = pPoint->Unadvise(m_nConnectionID); 1664 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1786 if (FAILED(hr)) 1665 }
1787 { 1666 m_isAdvised = false;
1788 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV ICE, "Class::Unadvice - Unadvise");
1789 }
1790 }
1791
1792 m_isAdviced = false;
1793 } 1667 }
1794 } 1668 }
1795 s_criticalSectionLocal.Unlock(); 1669 s_criticalSectionLocal.Unlock();
1796 } 1670 }
1797 1671
1798 HICON CPluginClass::GetIcon(int type) 1672 HICON CPluginClass::GetIcon(int type)
1799 { 1673 {
1800 HICON icon = NULL; 1674 HICON icon = NULL;
1801 1675
1802 s_criticalSectionLocal.Lock(); 1676 s_criticalSectionLocal.Lock();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 break; 1756 break;
1883 } 1757 }
1884 s_criticalSectionLocal.Unlock(); 1758 s_criticalSectionLocal.Unlock();
1885 1759
1886 } 1760 }
1887 } 1761 }
1888 } 1762 }
1889 1763
1890 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1764 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1891 } 1765 }
1892
1893 return hTabWnd; 1766 return hTabWnd;
1894 1767 }
1895 }
OLDNEW
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginErrorCodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld