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: fix-NITs Created Jan. 9, 2015, 4:06 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
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginClass.h" 3 #include "PluginClass.h"
4 #include "PluginSettings.h" 4 #include "PluginSettings.h"
5 #include "PluginSystem.h" 5 #include "PluginSystem.h"
6 #include "PluginFilter.h" 6 #include "PluginFilter.h"
7 #include "PluginMimeFilterClient.h" 7 #include "PluginMimeFilterClient.h"
8 #include "PluginClient.h" 8 #include "PluginClient.h"
9 #include "PluginClientFactory.h" 9 #include "PluginClientFactory.h"
10 #include "PluginMutex.h" 10 #include "PluginMutex.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return right - left; 68 return right - left;
69 } 69 }
70 }; 70 };
71 } 71 }
72 72
73 CPluginClass::CPluginClass() 73 CPluginClass::CPluginClass()
74 { 74 {
75 //Use this line to debug memory leaks 75 //Use this line to debug memory leaks
76 // _CrtDumpMemoryLeaks(); 76 // _CrtDumpMemoryLeaks();
77 77
78 m_isAdviced = false; 78 m_isAdvised = false;
79 m_nConnectionID = 0;
80 m_hTabWnd = NULL; 79 m_hTabWnd = NULL;
81 m_hStatusBarWnd = NULL; 80 m_hStatusBarWnd = NULL;
82 m_hPaneWnd = NULL; 81 m_hPaneWnd = NULL;
83 m_nPaneWidth = 0; 82 m_nPaneWidth = 0;
84 m_pWndProcStatus = NULL; 83 m_pWndProcStatus = NULL;
85 m_hTheme = NULL; 84 m_hTheme = NULL;
86 m_isInitializedOk = false; 85 m_isInitializedOk = false;
87 86
88 87
89 m_tab = new CPluginTab(this); 88 m_tab = new CPluginTab(this);
(...skipping 17 matching lines...) Expand all
107 106
108 void CPluginClass::FinalRelease() 107 void CPluginClass::FinalRelease()
109 { 108 {
110 s_criticalSectionBrowser.Lock(); 109 s_criticalSectionBrowser.Lock();
111 { 110 {
112 m_webBrowser2.Release(); 111 m_webBrowser2.Release();
113 } 112 }
114 s_criticalSectionBrowser.Unlock(); 113 s_criticalSectionBrowser.Unlock();
115 } 114 }
116 115
117
118 // This method tries to get a 'connection point' from the stored browser, which can be
119 // used to attach or detach from the stream of browser events
120 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPoint()
121 {
122 CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine r(GetBrowser());
123 if (!pContainer)
124 {
125 return NULL;
126 }
127
128 CComPtr<IConnectionPoint> pPoint;
129 HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint) ;
130 if (FAILED(hr))
131 {
132 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint")
133 return NULL;
134 }
135
136 return pPoint;
137 }
138
139 HWND CPluginClass::GetBrowserHWND() const 116 HWND CPluginClass::GetBrowserHWND() const
140 { 117 {
141 SHANDLE_PTR hBrowserWndHandle = NULL; 118 SHANDLE_PTR hBrowserWndHandle = NULL;
142 119
143 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 120 CComQIPtr<IWebBrowser2> browser = GetBrowser();
144 if (browser) 121 if (browser)
145 { 122 {
146 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); 123 HRESULT hr = browser->get_HWND(&hBrowserWndHandle);
147 if (FAILED(hr)) 124 if (FAILED(hr))
148 { 125 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 180
204 return url; 181 return url;
205 } 182 }
206 183
207 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 184 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
208 { 185 {
209 if (thisPtr == NULL) 186 if (thisPtr == NULL)
210 return 0; 187 return 0;
211 if (!((CPluginClass*)thisPtr)->InitObject(true)) 188 if (!((CPluginClass*)thisPtr)->InitObject(true))
212 { 189 {
213 ((CPluginClass*)thisPtr)->Unadvice(); 190 ((CPluginClass*)thisPtr)->Unadvise();
214 } 191 }
215 192
216 return 0; 193 return 0;
217 } 194 }
218 195
219 196
220 197
221 // This gets called when a new browser window is created (which also triggers th e 198 // This gets called when a new browser window is created (which also triggers th e
222 // creation of this object). The pointer passed in should be to a IWebBrowser2 199 // creation of this object). The pointer passed in should be to a IWebBrowser2
223 // interface that represents the browser for the window. 200 // interface that represents the browser for the window.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Always register on startup, then check if we need to unregister in a se parate thread 232 // Always register on startup, then check if we need to unregister in a se parate thread
256 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 233 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
257 s_asyncWebBrowser2 = unknownSite; 234 s_asyncWebBrowser2 = unknownSite;
258 s_instances.insert(this); 235 s_instances.insert(this);
259 } 236 }
260 s_criticalSectionLocal.Unlock(); 237 s_criticalSectionLocal.Unlock();
261 238
262 try 239 try
263 { 240 {
264 // Check if loaded as BHO 241 // Check if loaded as BHO
265 if (GetBrowser()) 242 auto webBrowser = GetBrowser();
243 if (webBrowser)
266 { 244 {
267 DEBUG_GENERAL("Loaded as BHO"); 245 DEBUG_GENERAL("Loaded as BHO");
268 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 246 HRESULT hr = DispEventAdvise(webBrowser);
Eric 2015/01/12 14:18:07 The Advise/Unadvise life cycle belong in a constru
sergei 2015/01/13 11:49:12 It does not belong to constructor/destructor pair.
Eric 2015/01/13 18:44:30 It absolutely should be paired. As it's written n
269 if (pPoint) 247 if (SUCCEEDED(hr))
270 { 248 {
271 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID); 249 m_isAdvised = true;
272 if (SUCCEEDED(hr)) 250 try
273 { 251 {
274 m_isAdviced = true; 252 std::thread startInitObjectThread(StartInitObject, this);
275 253 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
276 try
277 {
278 std::thread startInitObjectThread(StartInitObject, this);
279 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr.
280 }
281 catch (const std::system_error& ex)
282 {
283 auto errDescription = std::string("Class::Thread - Failed to creat e StartInitObject thread, ") +
284 ex.code().message() + ex.what();
285 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERR OR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str());
286 }
287 } 254 }
288 else 255 catch (const std::system_error& ex)
289 { 256 {
290 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advice"); 257 auto errDescription = std::string("Class::Thread - Failed to create StartInitObject thread, ") +
258 ex.code().message() + ex.what();
259 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR _MAIN_THREAD_CREATE_PROCESS, errDescription.c_str());
291 } 260 }
292 } 261 }
262 else
263 {
264 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advice");
265 }
293 } 266 }
294 else // Check if loaded as toolbar handler 267 else // Check if loaded as toolbar handler
295 { 268 {
296 DEBUG_GENERAL("Loaded as toolbar handler"); 269 DEBUG_GENERAL("Loaded as toolbar handler");
297 CComPtr<IServiceProvider> pServiceProvider; 270 CComPtr<IServiceProvider> pServiceProvider;
298 271
299 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); 272 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider);
300 if (SUCCEEDED(hr)) 273 if (SUCCEEDED(hr))
301 { 274 {
302 if (pServiceProvider) 275 if (pServiceProvider)
(...skipping 18 matching lines...) Expand all
321 } 294 }
322 else 295 else
323 { 296 {
324 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); 297 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY _SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)");
325 } 298 }
326 } 299 }
327 } 300 }
328 catch (std::runtime_error e) 301 catch (std::runtime_error e)
329 { 302 {
330 DEBUG_ERROR(e.what()); 303 DEBUG_ERROR(e.what());
331 Unadvice(); 304 Unadvise();
332 } 305 }
333 } 306 }
334 else 307 else
335 { 308 {
336 // Unadvice 309 // Unadvise
Oleksandr 2015/01/10 23:27:24 I guess we can loose the captain obvious comment h
sergei 2015/01/13 11:49:12 removed
337 Unadvice(); 310 Unadvise();
338 311
339 // Destroy window 312 // Destroy window
340 if (m_pWndProcStatus) 313 if (m_pWndProcStatus)
341 { 314 {
342 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP rocStatus); 315 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP rocStatus);
343 316
344 m_pWndProcStatus = NULL; 317 m_pWndProcStatus = NULL;
345 } 318 }
346 319
347 if (m_hPaneWnd) 320 if (m_hPaneWnd)
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 } 467 }
495 } 468 }
496 } 469 }
497 else 470 else
498 { 471 {
499 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state"); 472 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
500 } 473 }
501 } 474 }
502 DEBUG_GENERAL("ShowStatusBar end"); 475 DEBUG_GENERAL("ShowStatusBar end");
503 } 476 }
504 477
Eric 2015/01/12 14:18:07 // Entry point We need to annotate all the entry
505 /* 478 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2(
506 * #1163 This class is the implementation for method DISPID_BEFORENAVIGATE2 in C PluginClass::Invoke. 479 /* [in] */ IDispatch* frameBrowserDisp,
507 * - It validates and convertes its own arguments, rather than unifying them in the Invoke body. 480 /* [in] */ VARIANT* urlVariant,
508 * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu rn S_OK. 481 /* [in] */ VARIANT* /*Flags*/,
509 */ 482 /* [in] */ VARIANT* /*TargetFrameName*/,
510 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) 483 /* [in] */ VARIANT* /*PostData*/,
484 /* [in] */ VARIANT* /*Headers*/,
485 /* [in, out] */ VARIANT_BOOL* /*Cancel*/)
511 { 486 {
Eric 2015/01/12 14:18:07 This patch set changes OnBeforeNavigate2 into an e
512 487 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
513 if (pDispParams->cArgs < 7) 488 if (!webBrowser)
514 { 489 {
515 return; 490 return;
516 } 491 }
492
493 if (!urlVariant || urlVariant->vt != VT_BSTR)
494 {
495 return;
496 }
497 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
498 UnescapeUrl(url);
499
517 //Register a mime filter if it's not registered yet 500 //Register a mime filter if it's not registered yet
518 if (s_mimeFilter == NULL) 501 if (s_mimeFilter == NULL)
519 { 502 {
520 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 503 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
521 } 504 }
522 505
523 // Get the IWebBrowser2 interface 506 CString urlCString = ToCString(url);
524 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr;
525 VARTYPE vt = pDispParams->rgvarg[6].vt;
526 if (vt == VT_DISPATCH)
527 {
528 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal;
529 }
530 else
531 {
532 // Wrong type, return.
533 return;
534 }
535
536 // Get the URL
537 CString url;
538 vt = pDispParams->rgvarg[5].vt;
539 if (vt == VT_BYREF + VT_VARIANT)
540 {
541 url = pDispParams->rgvarg[5].pvarVal->bstrVal;
542
543 CPluginClient::UnescapeUrl(url);
544 }
545 else
546 {
547 // Wrong type, return.
548 return;
549 }
550 507
551 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page 508 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page
552 CPluginClient* client = CPluginClient::GetInstance(); 509 CPluginClient* client = CPluginClient::GetInstance();
553 510
554 if (url.Find(L"javascript") == 0) 511 if (urlCString.Find(L"javascript") == 0)
555 { 512 {
556 } 513 }
557 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) 514 else if (GetBrowser().IsEqualObject(webBrowser))
558 { 515 {
559 m_tab->OnNavigate(url); 516 m_tab->OnNavigate(urlCString);
560 517
561 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + url + "\n=================== =============================================================") 518 DEBUG_GENERAL(L"============================================================ ====================\nBegin main navigation url:" + urlCString + "\n============ ====================================================================")
562 519
563 #ifdef ENABLE_DEBUG_RESULT 520 #ifdef ENABLE_DEBUG_RESULT
564 CPluginDebug::DebugResultDomain(url); 521 CPluginDebug::DebugResultDomain(urlCString);
565 #endif 522 #endif
566 523
567 UpdateStatusBar(); 524 UpdateStatusBar();
568 } 525 }
569 else 526 else
570 { 527 {
571 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 528 DEBUG_NAVI(L"Navi::Begin navigation url:" + urlCString)
572 m_tab->CacheFrame(url); 529 m_tab->CacheFrame(urlCString);
573 } 530 }
574 } 531 }
575 532
Eric 2015/01/12 14:18:07 // Entry point
576 /* 533 void STDMETHODCALLTYPE CPluginClass::OnDownloadBegin()
577 * #1163 implements behavior for method DISPID_WINDOWSTATECHANGED in CPluginClas s::Invoke 534 {
578 * - should validate and convert arguments in Invoke, not here 535 DEBUG_NAVI("Navi::Download Begin")
579 * - does not validate number of arguments before indexing into 'rgvarg' 536 }
580 * - does not validate type of argument before using its value 537
Eric 2015/01/12 14:18:07 // Entry point
581 */ 538 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
582 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) 539 {
Eric 2015/01/12 14:18:07 try-statement and catch-all
540 DEBUG_NAVI("Navi::Download Complete")
541 ATL::CComPtr<IWebBrowser2> browser = GetBrowser();
542 if (browser)
543 {
544 m_tab->OnDownloadComplete(browser);
545 }
546 }
547
Eric 2015/01/12 14:18:07 // Entry point
548 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
549 {
Eric 2015/01/12 14:18:07 try-statement and catch-all
550 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
551 if (!webBrowser2)
552 {
553 return;
554 }
555 ATL::CString frameSrc;
556 ATL::CComBSTR locationUrl;
557 if (FAILED(webBrowser2->get_LocationURL(&locationUrl)) && !!locationUrl)
558 {
559 return;
560 }
561 frameSrc = locationUrl;
562 CPluginClient::UnescapeUrl(frameSrc);
563 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2);
564 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
565 }
566
Eric 2015/01/12 14:18:07 // Entry point
567 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
583 { 568 {
Eric 2015/01/12 14:18:07 try-statement and catch-all
584 DEBUG_GENERAL("Tab changed"); 569 DEBUG_GENERAL("Tab changed");
585 bool newtabshown = pDispParams->rgvarg[1].intVal==3; 570 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLEC MDIDF_WINDOWSTATE_ENABLED)
571 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WIN DOWSTATE_ENABLED);
586 if (newtabshown) 572 if (newtabshown)
587 { 573 {
588 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId()); 574 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId());
589 if (it == s_threadInstances.end()) 575 if (it == s_threadInstances.end())
590 { 576 {
591 s_threadInstances[::GetCurrentThreadId()] = this; 577 s_threadInstances[::GetCurrentThreadId()] = this;
592 if (!m_isInitializedOk) 578 if (!m_isInitializedOk)
593 { 579 {
594 m_isInitializedOk = true; 580 m_isInitializedOk = true;
595 InitObject(true); 581 if (!InitObject(true))
582 {
583 //» » » » » Unadvise();
584 }
Oleksandr 2015/01/10 23:27:24 This doesn't seem to be rebased to the current tip
596 UpdateStatusBar(); 585 UpdateStatusBar();
597 } 586 }
598 } 587 }
599 } 588 }
600 notificationMessage.Hide(); 589 notificationMessage.Hide();
601 DEBUG_GENERAL("Tab change end"); 590 DEBUG_GENERAL("Tab change end");
602 return S_OK;
603 } 591 }
604 592
Eric 2015/01/12 14:18:07 // Entry point
605 // This gets called whenever there's a browser event 593 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/)
606 // ENTRY POINT
607 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
608 { 594 {
Eric 2015/01/12 14:18:07 try-statement and catch-all
609 try 595 if (m_hPaneWnd == NULL)
610 { 596 {
611 WCHAR tmp[256]; 597 CreateStatusBarPane();
612 wsprintf(tmp, L"Invoke: %d\n", dispidMember); 598 }
613 DEBUG_GENERAL(tmp); 599 else
614 switch (dispidMember) 600 {
601 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
615 { 602 {
616 case DISPID_WINDOWSTATECHANGED: 603 RECT rect;
604 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect);
605 if (rectRes == TRUE)
617 { 606 {
618 // #1163 should validate and convert arguments here 607 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom - rect.top, TRUE);
619 return OnTabChanged(pDispParams, wFlags);
620 } 608 }
621
622 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE:
623 break;
624
625 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK:
626 break;
627
628 case DISPID_EVMETH_ONLOAD:
629 DEBUG_NAVI("Navi::OnLoad")
630 break;
631
632 case DISPID_EVMETH_ONCHANGE:
633 break;
634
635 case DISPID_EVMETH_ONMOUSEDOWN:
636 break;
637
638 case DISPID_EVMETH_ONMOUSEENTER:
639 break;
640
641 case DISPID_IHTMLIMGELEMENT_START:
642 break;
643
644 case STDDISPID_XOBJ_ERRORUPDATE:
645 break;
646
647 case STDDISPID_XOBJ_ONPROPERTYCHANGE:
648 break;
649
650 case DISPID_READYSTATECHANGE:
651 DEBUG_NAVI("Navi::ReadyStateChange");
652 break;
653
654 case DISPID_BEFORENAVIGATE:
655 DEBUG_NAVI("Navi::BeforeNavigate");
656 break;
657
658 case DISPID_COMMANDSTATECHANGE:
659 if (m_hPaneWnd == NULL)
660 {
661 CreateStatusBarPane();
662 }
663 else
664 {
665 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
666 {
667 RECT rect;
668 BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect);
669 if (rectRes == TRUE)
670 {
671 MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.botto m - rect.top, TRUE);
672 }
673 }
674 }
675 break;
676
677 case DISPID_STATUSTEXTCHANGE:
678 break;
679
680 case DISPID_BEFORENAVIGATE2:
681 {
682 // #1163 should validate and convert parameters here
683 BeforeNavigate2(pDispParams);
684 }
685 break;
686
687 case DISPID_DOWNLOADBEGIN:
688 {
689 DEBUG_NAVI("Navi::Download Begin")
690 }
691 break;
692
693 case DISPID_DOWNLOADCOMPLETE:
694 {
695 DEBUG_NAVI("Navi::Download Complete");
696 CComQIPtr<IWebBrowser2> browser = GetBrowser();
697 if (browser)
698 {
699 m_tab->OnDownloadComplete(browser);
700 }
701 }
702 break;
703
704 case DISPID_DOCUMENTCOMPLETE:
705 {
706 DEBUG_NAVI("Navi::Document Complete");
707 CComQIPtr<IWebBrowser2> browser = GetBrowser();
708 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V T_DISPATCH)
709 {
710 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
711 if (pBrowser)
712 {
713 CString url;
714 CComBSTR bstrUrl;
715 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && ::SysStringLen (bstrUrl) > 0)
716 {
717 url = bstrUrl;
718 CPluginClient::UnescapeUrl(url);
719 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBro wser));
720 }
721 }
722 }
723 }
724 break;
725
726 case DISPID_ONQUIT:
727 case DISPID_QUIT:
728 {
729 Unadvice();
730 }
731 break;
732
733 default:
734 {
735 CString did;
736 did.Format(L"DispId:%u", dispidMember);
737
738 DEBUG_NAVI(L"Navi::Default " + did)
739 }
740 /*
741 * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND.
742 * As a conservative initial change, we leave it behaving as before,
743 * which is to do nothing and return S_OK.
744 */
745 // do nothing
746 break;
747 } 609 }
748 } 610 }
749 catch(...)
750 {
751 DEBUG_GENERAL( "Caught unknown exception in CPluginClass::Invoke" );
752 return E_FAIL;
753 }
754 return S_OK;
755 } 611 }
756 612
757 bool CPluginClass::InitObject(bool bBHO) 613 bool CPluginClass::InitObject(bool bBHO)
758 { 614 {
759 DEBUG_GENERAL("InitObject"); 615 DEBUG_GENERAL("InitObject");
760 CPluginSettings* settings = CPluginSettings::GetInstance(); 616 CPluginSettings* settings = CPluginSettings::GetInstance();
761 617
762 if (!settings->GetPluginEnabled()) 618 if (!settings->GetPluginEnabled())
763 { 619 {
764 s_mimeFilter->Unregister(); 620 s_mimeFilter->Unregister();
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 { 1592 {
1737 CreateStatusBarPane(); 1593 CreateStatusBarPane();
1738 } 1594 }
1739 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1595 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1740 { 1596 {
1741 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1597 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1742 } 1598 }
1743 } 1599 }
1744 1600
1745 1601
1746 void CPluginClass::Unadvice() 1602 void STDMETHODCALLTYPE CPluginClass::Unadvise()
Eric 2015/01/12 14:18:07 If no OnQuit function is provided, this is an entr
1747 { 1603 {
1748 s_criticalSectionLocal.Lock(); 1604 s_criticalSectionLocal.Lock();
1749 { 1605 {
1750 if (m_isAdviced) 1606 if (m_isAdvised)
1751 { 1607 {
1752 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 1608 HRESULT hr = DispEventUnadvise(GetBrowser());
1753 if (pPoint) 1609 if (FAILED(hr))
1754 { 1610 {
1755 HRESULT hr = pPoint->Unadvise(m_nConnectionID); 1611 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1756 if (FAILED(hr))
1757 {
1758 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV ICE, "Class::Unadvice - Unadvise");
1759 }
1760 } 1612 }
1761 1613 m_isAdvised = false;
1762 m_isAdviced = false;
1763 } 1614 }
1764 } 1615 }
1765 s_criticalSectionLocal.Unlock(); 1616 s_criticalSectionLocal.Unlock();
1766 } 1617 }
1767 1618
1768 HICON CPluginClass::GetIcon(int type) 1619 HICON CPluginClass::GetIcon(int type)
1769 { 1620 {
1770 HICON icon = NULL; 1621 HICON icon = NULL;
1771 1622
1772 s_criticalSectionLocal.Lock(); 1623 s_criticalSectionLocal.Lock();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 } 1705 }
1855 } 1706 }
1856 } 1707 }
1857 1708
1858 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1709 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1859 } 1710 }
1860 1711
1861 return hTabWnd; 1712 return hTabWnd;
1862 1713
1863 } 1714 }
OLDNEW

Powered by Google App Engine
This is Rietveld