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

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

Issue 4805561958793216: Noissue - Remove dead code in CPluginClass::SetSite (Closed)
Left Patch Set: Created March 6, 2015, 10:57 a.m.
Right Patch Set: rebased + removed more dead code Created March 17, 2015, 10:29 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
« no previous file with change/comment | « src/plugin/PluginClass.h ('k') | src/plugin/abp.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12 matching lines...) Expand all
121 120
122 HRESULT CPluginClass::FinalConstruct() 121 HRESULT CPluginClass::FinalConstruct()
123 { 122 {
124 return S_OK; 123 return S_OK;
125 } 124 }
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();
Eric 2015/03/06 15:58:04 Explicit 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 { 194 {
218 url = m_tab->GetDocumentUrl(); 195 url = m_tab->GetDocumentUrl();
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())
228 { 205 {
229 ((CPluginClass*)thisPtr)->Unadvice(); 206 ((CPluginClass*)thisPtr)->Unadvise();
230 } 207 }
231 208
232 return 0; 209 return 0;
233 } 210 }
234
235 211
236 /* 212 /*
237 * IE calls this when it creates a new browser window or tab, immediately after it also 213 * IE calls this when it creates a new browser window or tab, immediately after it also
238 * creates the object. The argument 'unknownSite' in is the OLE "site" of the ob ject, 214 * creates the object. The argument 'unknownSite' in is the OLE "site" of the ob ject,
239 * which is an IWebBrowser2 interface associated with the window/tab. 215 * which is an IWebBrowser2 interface associated with the window/tab.
240 * 216 *
241 * IE also ordinarily calls this again when its window/tab is closed, in which c ase 217 * IE also ordinarily calls this again when its window/tab is closed, in which c ase
242 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE 218 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE
243 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor, 219 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor,
244 * but it is not a proper substitute for one. 220 * but it is not a proper substitute for one.
sergei 2015/03/09 10:23:50 I'm not sure that we need this comment except the
Eric 2015/03/09 13:31:29 I was just rewriting the comment, mostly, with the
Oleksandr 2015/03/10 08:38:26 I am pretty sure it _is_ called every time when IE
Oleksandr 2015/03/10 08:42:04 https://msdn.microsoft.com/en-us/library/bb250489(
245 */ 221 */
sergei 2015/03/30 11:26:23 This comment
246 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 222 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
247 { 223 {
248 try 224 try
249 { 225 {
250 if (unknownSite) 226 if (unknownSite)
251 { 227 {
252 228
253 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================") 229 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
254 230
255 HRESULT hr = ::CoInitialize(NULL); 231 HRESULT hr = ::CoInitialize(NULL);
256 if (FAILED(hr)) 232 if (FAILED(hr))
257 { 233 {
258 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 234 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
259 } 235 }
260 236
261 s_criticalSectionBrowser.Lock(); 237 s_criticalSectionBrowser.Lock();
262 { 238 {
263 m_webBrowser2 = unknownSite; 239 m_webBrowser2 = unknownSite;
Eric 2015/03/06 15:58:04 Assigned to m_webBrowser2 here, declared as CComQI
sergei 2015/03/06 16:07:19 Here `AddRef` is called.
264 } 240 }
265 s_criticalSectionBrowser.Unlock(); 241 s_criticalSectionBrowser.Unlock();
266 242
267 //register the mimefilter 243 //register the mimefilter
268 //and only mimefilter 244 //and only mimefilter
269 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 245 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
270 246
271 s_criticalSectionLocal.Lock(); 247 s_criticalSectionLocal.Lock();
272 { 248 {
273 // Always register on startup, then check if we need to unregister in a separate thread 249 // Always register on startup, then check if we need to unregister in a separate thread
274 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 250 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
275 s_asyncWebBrowser2 = unknownSite; 251 s_asyncWebBrowser2 = unknownSite;
276 s_instances.insert(this); 252 s_instances.insert(this);
277 } 253 }
278 s_criticalSectionLocal.Unlock(); 254 s_criticalSectionLocal.Unlock();
279 255
280 try 256 try
281 { 257 {
282 // Check if loaded as BHO 258 auto webBrowser = GetBrowser();
283 if (GetBrowser()) 259 if (webBrowser)
sergei 2015/03/09 10:23:50 We don't need this comment now.
Eric 2015/03/09 13:31:29 We don't need this particular comment, but we'll n
Eric 2015/03/17 10:41:07 Done.
284 { 260 {
285 DEBUG_GENERAL("Loaded as BHO"); 261 DEBUG_GENERAL("Loaded as BHO");
286 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 262 HRESULT hr = DispEventAdvise(webBrowser);
287 if (pPoint) 263 if (SUCCEEDED(hr))
288 { 264 {
289 HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID); 265 m_isAdvised = true;
290 if (SUCCEEDED(hr)) 266 try
291 { 267 {
292 m_isAdviced = true; 268 std::thread startInitObjectThread(StartInitObject, this);
293 269 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr.
294 try
295 {
296 std::thread startInitObjectThread(StartInitObject, this);
297 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
298 }
299 catch (const std::system_error& ex)
300 {
301 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAI N_THREAD_CREATE_PROCESS,
302 "Class::Thread - Failed to create StartInitObject thread");
303 }
304 } 270 }
305 else 271 catch (const std::system_error& ex)
306 { 272 {
307 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_A DVICE, "Class::SetSite - Advice"); 273 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_ THREAD_CREATE_PROCESS,
274 "Class::Thread - Failed to create StartInitObject thread");
308 } 275 }
309 } 276 }
277 else
278 {
279 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advise");
280 }
310 } 281 }
311 } 282 }
312 catch (const std::runtime_error& ex) 283 catch (const std::runtime_error& ex)
313 { 284 {
314 DEBUG_EXCEPTION(ex); 285 DEBUG_EXCEPTION(ex);
315 Unadvice(); 286 Unadvise();
316 } 287 }
317 } 288 }
318 else 289 else
319 { 290 {
320 // Unadvice 291 Unadvise();
321 Unadvice();
322 292
323 // Destroy window 293 // Destroy window
324 if (m_pWndProcStatus) 294 if (m_pWndProcStatus)
325 { 295 {
326 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus); 296 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus);
327 297
328 m_pWndProcStatus = NULL; 298 m_pWndProcStatus = NULL;
329 } 299 }
330 300
331 if (m_hPaneWnd) 301 if (m_hPaneWnd)
(...skipping 22 matching lines...) Expand all
354 { 324 {
355 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 325 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
356 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 326 CPluginClientFactory::ReleaseMimeFilterClientInstance();
357 } 327 }
358 } 328 }
359 s_criticalSectionLocal.Unlock(); 329 s_criticalSectionLocal.Unlock();
360 330
361 // Release browser interface 331 // Release browser interface
362 s_criticalSectionBrowser.Lock(); 332 s_criticalSectionBrowser.Lock();
363 { 333 {
364 m_webBrowser2.Release(); 334 m_webBrowser2.Release();
Eric 2015/03/06 15:58:04 Explicit release here.
sergei 2015/03/06 16:07:19 So, since `AddRef` is called and `m_webBrowser2` i
Eric 2015/03/06 16:27:22 Calling 'Release' through 'CComPtr' apparently als
365 } 335 }
366 s_criticalSectionBrowser.Unlock(); 336 s_criticalSectionBrowser.Unlock();
367 337
368 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 338 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
369 339
370 ::CoUninitialize(); 340 ::CoUninitialize();
371 } 341 }
372 342
373 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); 343 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
374 } 344 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 454 }
485 } 455 }
486 else 456 else
487 { 457 {
488 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state"); 458 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
489 } 459 }
490 } 460 }
491 DEBUG_GENERAL("ShowStatusBar end"); 461 DEBUG_GENERAL("ShowStatusBar end");
492 } 462 }
493 463
494 /* 464 // Entry point
495 * #1163 This class is the implementation for method DISPID_BEFORENAVIGATE2 in C PluginClass::Invoke. 465 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2(
496 * - It validates and convertes its own arguments, rather than unifying them in the Invoke body. 466 IDispatch* frameBrowserDisp /**< [in] */,
497 * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu rn S_OK. 467 VARIANT* urlVariant /**< [in] */,
498 */ 468 VARIANT* /**< [in] Flags*/,
499 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) 469 VARIANT* /**< [in] TargetFrameName*/,
500 { 470 VARIANT* /**< [in] PostData*/,
501 471 VARIANT* /**< [in] Headers*/,
502 if (pDispParams->cArgs < 7) 472 VARIANT_BOOL* /**< [in, out] Cancel*/)
503 { 473 {
504 return; 474 try
505 } 475 {
506 //Register a mime filter if it's not registered yet 476 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
507 if (s_mimeFilter == NULL) 477 if (!webBrowser)
508 { 478 {
509 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 479 return;
510 } 480 }
511 481 if (!urlVariant || urlVariant->vt != VT_BSTR)
512 // Get the IWebBrowser2 interface 482 {
513 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr; 483 return;
514 VARTYPE vt = pDispParams->rgvarg[6].vt; 484 }
515 if (vt == VT_DISPATCH) 485 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
516 { 486 UnescapeUrl(url);
517 WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; 487
518 } 488 //Register a mime filter if it's not registered yet
519 else 489 if (s_mimeFilter == nullptr)
520 { 490 {
521 // Wrong type, return. 491 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
522 return; 492 }
523 } 493 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
524 494 // navigating new page
525 // Get the URL 495 CPluginClient* client = CPluginClient::GetInstance();
526 std::wstring url; 496 if (url.find(L"javascript") == 0)
527 const auto& arg = pDispParams->rgvarg[5]; 497 {
528 vt = arg.vt; 498 }
529 if (vt == (VT_BYREF | VT_VARIANT) && arg.pvarVal->vt == VT_BSTR) 499 else if (GetBrowser().IsEqualObject(webBrowser))
530 { 500 {
531 BSTR b = arg.pvarVal->bstrVal; 501 m_tab->OnNavigate(url);
532 if (b) { 502 DEBUG_GENERAL(
533 url = std::wstring(b, SysStringLen(b));
534 UnescapeUrl(url);
535 }
536 }
537 else
538 {
539 // Wrong type, return.
540 return;
541 }
542
543 // If webbrowser2 is equal to top level browser (as set in SetSite), we are na vigating new page
544 CPluginClient* client = CPluginClient::GetInstance();
545 CString urlLegacy = ToCString(url);
546 if (urlLegacy.Find(L"javascript") == 0)
547 {
548 }
549 else if (GetBrowser().IsEqualObject(WebBrowser2Ptr))
550 {
551 m_tab->OnNavigate(url);
552
553 DEBUG_GENERAL(
554 L"======================================================================== ========\n" 503 L"======================================================================== ========\n"
555 L"Begin main navigation url:" + url + L"\n" 504 L"Begin main navigation url:" + url + L"\n"
556 L"======================================================================== ========") 505 L"======================================================================== ========")
557 506
558 #ifdef ENABLE_DEBUG_RESULT 507 #ifdef ENABLE_DEBUG_RESULT
559 CPluginDebug::DebugResultDomain(url); 508 CPluginDebug::DebugResultDomain(url);
560 #endif 509 #endif
561 510 UpdateStatusBar();
562 UpdateStatusBar(); 511 }
563 } 512 else
564 else 513 {
565 { 514 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
566 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 515 m_tab->CacheFrame(url);
567 m_tab->CacheFrame(url); 516 }
568 } 517 }
569 } 518 catch (...)
570 519 {
571 /* 520 }
572 * #1163 implements behavior for method DISPID_WINDOWSTATECHANGED in CPluginClas s::Invoke 521 }
573 * - should validate and convert arguments in Invoke, not here 522
574 * - does not validate number of arguments before indexing into 'rgvarg' 523 // Entry point
575 * - does not validate type of argument before using its value 524 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
576 */
577 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags)
578 {
579 DEBUG_GENERAL("Tab changed");
580 bool newtabshown = pDispParams->rgvarg[1].intVal==3;
581 if (newtabshown)
582 {
583 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge tCurrentThreadId());
584 if (it == s_threadInstances.end())
585 {
586 s_threadInstances[::GetCurrentThreadId()] = this;
587 if (!m_isInitializedOk)
588 {
589 m_isInitializedOk = true;
590 InitObject(true);
591 UpdateStatusBar();
592 }
593 }
594 }
595 notificationMessage.Hide();
596 DEBUG_GENERAL("Tab change end");
597 return S_OK;
598 }
599
600 // This gets called whenever there's a browser event
601 // ENTRY POINT
602 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
603 { 525 {
604 try 526 try
605 { 527 {
606 WCHAR tmp[256]; 528 DEBUG_NAVI(L"Navi::Download Complete")
607 wsprintf(tmp, L"Invoke: %d\n", dispidMember); 529 ATL::CComPtr<IWebBrowser2> browser = GetBrowser();
608 DEBUG_GENERAL(tmp); 530 if (browser)
609 switch (dispidMember) 531 {
610 { 532 m_tab->OnDownloadComplete(browser);
611 case DISPID_WINDOWSTATECHANGED: 533 }
612 { 534 }
613 // #1163 should validate and convert arguments here 535 catch (...)
614 return OnTabChanged(pDispParams, wFlags); 536 {
615 } 537 }
616 538 }
617 case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE: 539
618 break; 540 // Entry point
619 541 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
620 case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK: 542 {
621 break; 543 try
622 544 {
623 case DISPID_EVMETH_ONLOAD: 545 DEBUG_NAVI(L"Navi::Document Complete");
624 DEBUG_NAVI("Navi::OnLoad") 546 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
625 break; 547 if (!webBrowser2)
626 548 {
627 case DISPID_EVMETH_ONCHANGE: 549 return;
628 break; 550 }
629 551 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
630 case DISPID_EVMETH_ONMOUSEDOWN: 552 UnescapeUrl(frameSrc);
631 break; 553 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2);
632 554 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
633 case DISPID_EVMETH_ONMOUSEENTER: 555 }
634 break; 556 catch (...)
635 557 {
636 case DISPID_IHTMLIMGELEMENT_START: 558 }
637 break; 559 }
638 560
639 case STDDISPID_XOBJ_ERRORUPDATE: 561 // Entry point
640 break; 562 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
641 563 {
642 case STDDISPID_XOBJ_ONPROPERTYCHANGE: 564 try
643 break; 565 {
644 566 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)");
645 case DISPID_READYSTATECHANGE: 567 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL ECMDIDF_WINDOWSTATE_ENABLED)
646 DEBUG_NAVI("Navi::ReadyStateChange"); 568 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA BLED);
647 break; 569 if (newtabshown)
648 570 {
649 case DISPID_BEFORENAVIGATE: 571 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find( GetCurrentThreadId());
650 DEBUG_NAVI("Navi::BeforeNavigate"); 572 if (it == s_threadInstances.end())
651 break; 573 {
652 574 s_threadInstances[::GetCurrentThreadId()] = this;
653 case DISPID_COMMANDSTATECHANGE: 575 if (!m_isInitializedOk)
654 if (m_hPaneWnd == NULL) 576 {
655 { 577 m_isInitializedOk = true;
656 CreateStatusBarPane(); 578 InitObject();
657 } 579 UpdateStatusBar();
658 else 580 }
659 { 581 }
582 }
583 notificationMessage.Hide();
584 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end");
585 }
586 catch (...)
587 {
588 }
589 }
590
591 // Entry point
592 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI ANT_BOOL /*enable*/)
593 {
594 try
595 {
596 if (m_hPaneWnd == NULL)
597 {
598 CreateStatusBarPane();
599 }
600 else
601 {
660 if (AdblockPlus::IE::InstalledMajorVersion() > 6) 602 if (AdblockPlus::IE::InstalledMajorVersion() > 6)
661 { 603 {
662 RECT rect; 604 RECT rect;
663 //Get the RECT for the leftmost pane (the status text pane) 605 //Get the RECT for the leftmost pane (the status text pane)
664 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)& rect); 606 BOOL rectRes = ::SendMessage(m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&re ct);
665 if (rectRes == TRUE) 607 if (rectRes == TRUE)
666 { 608 {
667 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, r ect.bottom - rect.top, TRUE); 609 MoveWindow(m_hPaneWnd, rect.right - m_nPaneWidth, 0, m_nPaneWidth, rec t.bottom - rect.top, TRUE);
668 } 610 }
669 } 611 }
670 } 612 }
671 break; 613 }
672 614 catch (...)
673 case DISPID_STATUSTEXTCHANGE: 615 {
674 break; 616 }
675 617 }
676 case DISPID_BEFORENAVIGATE2: 618
677 { 619 // Entry point
678 // #1163 should validate and convert parameters here 620 void STDMETHODCALLTYPE CPluginClass::OnOnQuit()
679 BeforeNavigate2(pDispParams); 621 {
680 } 622 try
681 break; 623 {
682 624 Unadvise();
683 case DISPID_DOWNLOADBEGIN: 625 }
684 { 626 catch (...)
685 DEBUG_NAVI("Navi::Download Begin") 627 {
686 } 628 }
687 break; 629 }
688 630
689 case DISPID_DOWNLOADCOMPLETE: 631 bool CPluginClass::InitObject()
690 {
691 DEBUG_NAVI("Navi::Download Complete");
692 CComQIPtr<IWebBrowser2> browser = GetBrowser();
693 if (browser)
694 {
695 m_tab->OnDownloadComplete(browser);
696 }
697 }
698 break;
699
700 case DISPID_DOCUMENTCOMPLETE:
701 {
702 DEBUG_NAVI("Navi::Document Complete");
703 CComQIPtr<IWebBrowser2> browser = GetBrowser();
704 if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V T_DISPATCH)
705 {
706 CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal;
707 if (pBrowser)
708 {
709 CComBSTR bstrUrl;
710 if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && bstrUrl && ::S ysStringLen(bstrUrl) > 0)
711 {
712 std::wstring url = std::wstring(bstrUrl, SysStringLen(bstrUrl));
713 UnescapeUrl(url);
714 m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBro wser));
715 }
716 }
717 }
718 }
719 break;
720
721 case DISPID_ONQUIT:
722 case DISPID_QUIT:
723 {
724 Unadvice();
725 }
726 break;
727
728 default:
729 {
730 CString did;
731 did.Format(L"DispId:%u", dispidMember);
732
733 DEBUG_NAVI(L"Navi::Default " + did)
734 }
735 /*
736 * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND.
737 * As a conservative initial change, we leave it behaving as before,
738 * which is to do nothing and return S_OK.
739 */
740 // do nothing
741 break;
742 }
743 }
744 catch(...)
745 {
746 DEBUG_GENERAL( "Caught unknown exception in CPluginClass::Invoke" );
747 return E_FAIL;
748 }
749 return S_OK;
750 }
751
752 bool CPluginClass::InitObject(bool bBHO)
753 { 632 {
754 DEBUG_GENERAL("InitObject"); 633 DEBUG_GENERAL("InitObject");
755 CPluginSettings* settings = CPluginSettings::GetInstance(); 634 CPluginSettings* settings = CPluginSettings::GetInstance();
756 635
757 if (!settings->GetPluginEnabled()) 636 if (!settings->GetPluginEnabled())
758 { 637 {
759 s_mimeFilter->Unregister(); 638 s_mimeFilter->Unregister();
760 } 639 }
761 640
762 // Load theme module 641 // Load theme module
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 698
820 if (!GetAtomPaneClass()) 699 if (!GetAtomPaneClass())
821 { 700 {
822 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx"); 701 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTE R_PANE_CLASS, "Class::InitObject - RegisterClassEx");
823 return false; 702 return false;
824 } 703 }
825 } 704 }
826 705
827 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); 706 int ieVersion = AdblockPlus::IE::InstalledMajorVersion();
828 // Create status pane 707 // Create status pane
829 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) 708 if (ieVersion > 6 && !CreateStatusBarPane())
830 { 709 {
831 return false; 710 return false;
832 } 711 }
833 712
834 s_criticalSectionLocal.Lock(); 713 s_criticalSectionLocal.Lock();
835 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2"); 714 int versionCompRes = CPluginClient::GetInstance()->CompareVersions(CPluginClie nt::GetInstance()->GetPref(L"currentVersion", L"0.0"), L"1.2");
836 715
837 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun(); 716 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun();
838 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN _VERSION)); 717 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN _VERSION));
839 // This is the first time ABP was installed 718 // This is the first time ABP was installed
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 { 1619 {
1741 CreateStatusBarPane(); 1620 CreateStatusBarPane();
1742 } 1621 }
1743 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1622 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1744 { 1623 {
1745 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1624 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1746 } 1625 }
1747 } 1626 }
1748 1627
1749 1628
1750 void CPluginClass::Unadvice() 1629 void CPluginClass::Unadvise()
1751 { 1630 {
1752 s_criticalSectionLocal.Lock(); 1631 s_criticalSectionLocal.Lock();
1753 { 1632 {
1754 if (m_isAdviced) 1633 if (m_isAdvised)
1755 { 1634 {
1756 CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); 1635 HRESULT hr = DispEventUnadvise(GetBrowser());
1757 if (pPoint) 1636 if (FAILED(hr))
1758 { 1637 {
1759 HRESULT hr = pPoint->Unadvise(m_nConnectionID); 1638 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1760 if (FAILED(hr)) 1639 }
1761 { 1640 m_isAdvised = false;
1762 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV ICE, "Class::Unadvice - Unadvise");
1763 }
1764 }
1765
1766 m_isAdviced = false;
1767 } 1641 }
1768 } 1642 }
1769 s_criticalSectionLocal.Unlock(); 1643 s_criticalSectionLocal.Unlock();
1770 } 1644 }
1771 1645
1772 HICON CPluginClass::GetIcon(int type) 1646 HICON CPluginClass::GetIcon(int type)
1773 { 1647 {
1774 HICON icon = NULL; 1648 HICON icon = NULL;
1775 1649
1776 s_criticalSectionLocal.Lock(); 1650 s_criticalSectionLocal.Lock();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 break; 1730 break;
1857 } 1731 }
1858 s_criticalSectionLocal.Unlock(); 1732 s_criticalSectionLocal.Unlock();
1859 1733
1860 } 1734 }
1861 } 1735 }
1862 } 1736 }
1863 1737
1864 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1738 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1865 } 1739 }
1866
1867 return hTabWnd; 1740 return hTabWnd;
1868 1741 }
1869 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld