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

Delta Between Two Patch Sets: src/plugin/PluginClass.cpp

Issue 5137721374801920: Issue #1173 - Default behavior for catch-all blocks
Left Patch Set: Add ExceptionDefault() Created March 5, 2015, 2:56 p.m.
Right Patch Set: Changed entry point defaults in CPluginClass to match rebase Created March 20, 2015, 9:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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
235
236 211
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
(...skipping 25 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 }
274 }
275 else
276 {
277 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
307 } 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 {
(...skipping 19 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 IDispatch* frameBrowserDisp /**< [in] */,
523 * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu rn S_OK. 493 VARIANT* urlVariant /**< [in] */,
524 */ 494 VARIANT* /**< [in] Flags*/,
525 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) 495 VARIANT* /**< [in] TargetFrameName*/,
526 { 496 VARIANT* /**< [in] PostData*/,
527 497 VARIANT* /**< [in] Headers*/,
528 if (pDispParams->cArgs < 7) 498 VARIANT_BOOL* /**< [in, out] 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 EntryPointExceptionDefault("CPluginClass::OnBeforeNavigate2");
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
601 * - does not validate type of argument before using its value 550 // Entry point
602 */ 551 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
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 { 552 {
630 try 553 try
631 { 554 {
632 WCHAR tmp[256]; 555 DEBUG_NAVI(L"Navi::Download Complete")
633 wsprintf(tmp, L"Invoke: %d\n", dispidMember); 556 ATL::CComPtr<IWebBrowser2> browser = GetBrowser();
634 DEBUG_GENERAL(tmp); 557 if (browser)
635 switch (dispidMember) 558 {
636 { 559 m_tab->OnDownloadComplete(browser);
637 case DISPID_WINDOWSTATECHANGED: 560 }
638 { 561 }
639 // #1163 should validate and convert arguments here 562 catch (...)
640 return OnTabChanged(pDispParams, wFlags); 563 {
641 } 564 EntryPointExceptionDefault("CPluginClass::OnDownloadComplete");
642 565 }
643 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE: 566 }
644 break; 567
645 568 // Entry point
646 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK: 569 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
647 break; 570 {
648 571 try
649 case DISPID_EVMETH_ONLOAD: 572 {
650 DEBUG_NAVI("Navi::OnLoad") 573 DEBUG_NAVI(L"Navi::Document Complete");
651 break; 574 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
652 575 if (!webBrowser2)
653 case DISPID_EVMETH_ONCHANGE: 576 {
654 break; 577 return;
655 578 }
656 case DISPID_EVMETH_ONMOUSEDOWN: 579 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
657 break; 580 UnescapeUrl(frameSrc);
658 581 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2);
659 case DISPID_EVMETH_ONMOUSEENTER: 582 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
660 break; 583 }
661 584 catch (...)
662 case DISPID_IHTMLIMGELEMENT_START: 585 {
663 break; 586 EntryPointExceptionDefault("CPluginClass::OnDocumentComplete");
664 587 }
665 case STDDISPID_XOBJ_ERRORUPDATE: 588 }
666 break; 589
667 590 // Entry point
668 case STDDISPID_XOBJ_ONPROPERTYCHANGE: 591 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
669 break; 592 {
670 593 try
671 case DISPID_READYSTATECHANGE: 594 {
672 DEBUG_NAVI("Navi::ReadyStateChange"); 595 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)");
673 break; 596 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED)
674 597 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA BLED);
675 case DISPID_BEFORENAVIGATE: 598 if (newtabshown)
676 DEBUG_NAVI("Navi::BeforeNavigate"); 599 {
677 break; 600 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find( GetCurrentThreadId());
678 601 if (it == s_threadInstances.end())
679 case DISPID_COMMANDSTATECHANGE: 602 {
680 if (m_hPaneWnd == NULL) 603 s_threadInstances[::GetCurrentThreadId()] = this;
681 { 604 if (!m_isInitializedOk)
682 CreateStatusBarPane(); 605 {
683 } 606 m_isInitializedOk = true;
684 else 607 InitObject(true);
685 { 608 UpdateStatusBar();
609 }
610 }
611 }
612 notificationMessage.Hide();
613 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end");
614 }
615 catch (...)
616 {
617 EntryPointExceptionDefault("CPluginClass::OnWindowStateChanged");
618 }
619 }
620
621 // Entry point
622 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/)
623 {
624 try
625 {
626 if (m_hPaneWnd == NULL)
627 {
628 CreateStatusBarPane();
629 }
630 else
631 {
686 if (AdblockPlus::IE::InstalledMajorVersion() > 6) 632 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
687 { 633 {
688 RECT rect; 634 RECT rect;
689 //Get the RECT for the leftmost pane (the status text pane) 635 //Get the RECT for the leftmost pane (the status text pane)
690 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)& rect); 636 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&re ct);
691 if (rectRes == TRUE) 637 if (rectRes == TRUE)
692 { 638 {
693 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, r ect.bottom - rect.top, TRUE); 639 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, rec t.bottom - rect.top, TRUE);
694 } 640 }
695 } 641 }
696 }
697 break;
698
699 case DISPID_STATUSTEXTCHANGE:
700 break;
701
702 case DISPID_BEFORENAVIGATE2:
703 {
704 // #1163 should validate and convert parameters here
705 BeforeNavigate2(pDispParams);
706 }
707 break;
708
709 case DISPID_DOWNLOADBEGIN:
710 {
711 DEBUG_NAVI("Navi::Download Begin")
712 }
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 } 642 }
769 } 643 }
770 catch (...) 644 catch (...)
771 { 645 {
772 EntryPointExceptionDefault("CPluginClass::Invoke"); 646 EntryPointExceptionDefault("CPluginClass::OnCommandStateChange");
sergei 2015/03/06 13:51:12 I expected such methods to determine what should b
Eric 2015/03/06 17:29:59 For the generic version for arbitrary entry point
773 return E_FAIL; 647 }
774 } 648 }
775 return S_OK; 649
650 // Entry point
651 void STDMETHODCALLTYPE CPluginClass::OnOnQuit()
652 {
653 try
654 {
655 Unadvise();
656 }
657 catch (...)
658 {
659 EntryPointExceptionDefault("CPluginClass::OnOnQuit");
660 }
776 } 661 }
777 662
778 bool CPluginClass::InitObject(bool bBHO) 663 bool CPluginClass::InitObject(bool bBHO)
779 { 664 {
780 DEBUG_GENERAL("InitObject"); 665 DEBUG_GENERAL("InitObject");
781 CPluginSettings* settings = CPluginSettings::GetInstance(); 666 CPluginSettings* settings = CPluginSettings::GetInstance();
782 667
783 if (!settings->GetPluginEnabled()) 668 if (!settings->GetPluginEnabled())
784 { 669 {
785 s_mimeFilter->Unregister(); 670 s_mimeFilter->Unregister();
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 { 1651 {
1767 CreateStatusBarPane(); 1652 CreateStatusBarPane();
1768 } 1653 }
1769 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1654 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1770 { 1655 {
1771 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1656 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1772 } 1657 }
1773 } 1658 }
1774 1659
1775 1660
1776 void CPluginClass::Unadvice() 1661 void CPluginClass::Unadvise()
1777 { 1662 {
1778 s_criticalSectionLocal.Lock(); 1663 s_criticalSectionLocal.Lock();
1779 { 1664 {
1780 if (m_isAdviced) 1665 if (m_isAdvised)
1781 { 1666 {
1782 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 1667 HRESULT hr = DispEventUnadvise(GetBrowser());
1783 if (pPoint) 1668 if (FAILED(hr))
1784 { 1669 {
1785 HRESULT hr = pPoint->Unadvise(m_nConnectionID); 1670 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1786 if (FAILED(hr)) 1671 }
1787 { 1672 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 } 1673 }
1794 } 1674 }
1795 s_criticalSectionLocal.Unlock(); 1675 s_criticalSectionLocal.Unlock();
1796 } 1676 }
1797 1677
1798 HICON CPluginClass::GetIcon(int type) 1678 HICON CPluginClass::GetIcon(int type)
1799 { 1679 {
1800 HICON icon = NULL; 1680 HICON icon = NULL;
1801 1681
1802 s_criticalSectionLocal.Lock(); 1682 s_criticalSectionLocal.Lock();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 break; 1762 break;
1883 } 1763 }
1884 s_criticalSectionLocal.Unlock(); 1764 s_criticalSectionLocal.Unlock();
1885 1765
1886 } 1766 }
1887 } 1767 }
1888 } 1768 }
1889 1769
1890 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1770 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1891 } 1771 }
1892
1893 return hTabWnd; 1772 return hTabWnd;
1894 1773 }
1895 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld