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

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

Issue 29323561: Issue #3383 - Rewrite and simplify browser-site handling in CPluginClass (Closed)
Patch Set: Created Aug. 13, 2015, 4:52 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
« src/plugin/PluginClass.h ('K') | « src/plugin/PluginClass.h ('k') | no next file » | 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 CLOSETHEMEDATA pfnClose = NULL; 53 CLOSETHEMEDATA pfnClose = NULL;
54 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; 54 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL;
55 OPENTHEMEDATA pfnOpenThemeData = NULL; 55 OPENTHEMEDATA pfnOpenThemeData = NULL;
56 56
57 ATOM CPluginClass::s_atomPaneClass = NULL; 57 ATOM CPluginClass::s_atomPaneClass = NULL;
58 HINSTANCE CPluginClass::s_hUxtheme = NULL; 58 HINSTANCE CPluginClass::s_hUxtheme = NULL;
59 std::set<CPluginClass*> CPluginClass::s_instances; 59 std::set<CPluginClass*> CPluginClass::s_instances;
60 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; 60 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances;
61 61
62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; 62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal;
63 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser;
64 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; 63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow;
65 64
66 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; 65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2;
67 66
68 /* 67 /*
69 * Without namespace declaration, the identifier "Rectangle" is ambiguous 68 * Without namespace declaration, the identifier "Rectangle" is ambiguous
70 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx 69 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx
71 */ 70 */
72 namespace AdblockPlus 71 namespace AdblockPlus
73 { 72 {
(...skipping 10 matching lines...) Expand all
84 } 83 }
85 84
86 int Width() const 85 int Width() const
87 { 86 {
88 return right - left; 87 return right - left;
89 } 88 }
90 }; 89 };
91 } 90 }
92 91
93 CPluginClass::CPluginClass() 92 CPluginClass::CPluginClass()
93 : m_webBrowser2(nullptr)
94 { 94 {
95 //Use this line to debug memory leaks 95 //Use this line to debug memory leaks
96 // _CrtDumpMemoryLeaks(); 96 // _CrtDumpMemoryLeaks();
97 97
98 m_isAdvised = false; 98 m_isAdvised = false;
99 m_hTabWnd = NULL; 99 m_hTabWnd = NULL;
100 m_hStatusBarWnd = NULL; 100 m_hStatusBarWnd = NULL;
101 m_hPaneWnd = NULL; 101 m_hPaneWnd = NULL;
102 m_nPaneWidth = 0; 102 m_nPaneWidth = 0;
103 m_pWndProcStatus = NULL; 103 m_pWndProcStatus = NULL;
104 m_hTheme = NULL; 104 m_hTheme = NULL;
105 m_isInitializedOk = false; 105 m_isInitializedOk = false;
106 106
107 107
108 m_tab = new CPluginTab(this); 108 m_tab = new CPluginTab(this);
109 109
110 Dictionary::Create(GetBrowserLanguage()); 110 Dictionary::Create(GetBrowserLanguage());
111 } 111 }
112 112
113 CPluginClass::~CPluginClass() 113 CPluginClass::~CPluginClass()
114 { 114 {
115 delete m_tab; 115 delete m_tab;
116 } 116 }
117 117
118
119 /////////////////////////////////////////////////////////////////////////////
120 // Initialization
121
122 HRESULT CPluginClass::FinalConstruct()
123 {
124 return S_OK;
125 }
126
127 void CPluginClass::FinalRelease()
128 {
129 s_criticalSectionBrowser.Lock();
130 {
131 m_webBrowser2.Release();
132 }
133 s_criticalSectionBrowser.Unlock();
134 }
135
136 HWND CPluginClass::GetBrowserHWND() const 118 HWND CPluginClass::GetBrowserHWND() const
137 { 119 {
138 SHANDLE_PTR hBrowserWndHandle = NULL; 120 if (!m_webBrowser2)
139
140 CComQIPtr<IWebBrowser2> browser = GetBrowser();
141 if (browser)
142 { 121 {
143 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); 122 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr");
144 if (FAILED(hr)) 123 return nullptr;
145 {
146 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, " Class::GetBrowserHWND - failed")
147 }
148 } 124 }
149 125 SHANDLE_PTR hBrowserWndHandle;
126 HRESULT hr = m_webBrowser2->get_HWND(&hBrowserWndHandle);
127 if (FAILED(hr))
128 {
129 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed")
130 }
150 return (HWND)hBrowserWndHandle; 131 return (HWND)hBrowserWndHandle;
151 } 132 }
152 133
153 134 bool CPluginClass::IsRootPageBrowser(IWebBrowser2* otherBrowser)
154 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const
155 { 135 {
156 CComQIPtr<IWebBrowser2> browser; 136 /*
157 137 * The ownership overhead of 'CComPtr', which we don't need, is what we
158 s_criticalSectionBrowser.Lock(); 138 * pay for the convenience of using its member function 'IsEqualObject'.
159 { 139 */
160 browser = m_webBrowser2; 140 CComPtr<IWebBrowser> thisBrowser = m_webBrowser2;
sergei 2015/10/01 16:15:51 NIT: why is `IWebBrowser` and not `IWebBrowser2`?
Eric 2015/11/18 13:57:31 Typo. Fixed.
161 } 141 return thisBrowser.IsEqualObject(otherBrowser);
162 s_criticalSectionBrowser.Unlock();
163
164 return browser;
165 } 142 }
166 143
167
168 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() 144 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
169 { 145 {
170 CComQIPtr<IWebBrowser2> browser; 146 CComQIPtr<IWebBrowser2> browser;
171 147
172 s_criticalSectionLocal.Lock(); 148 s_criticalSectionLocal.Lock();
173 { 149 {
174 browser = s_asyncWebBrowser2; 150 browser = s_asyncWebBrowser2;
175 } 151 }
176 s_criticalSectionLocal.Unlock(); 152 s_criticalSectionLocal.Unlock();
177 153
178 return browser; 154 return browser;
179 } 155 }
180 156
181 std::wstring CPluginClass::GetBrowserUrl() const 157 std::wstring CPluginClass::GetBrowserUrl() const
182 { 158 {
183 std::wstring url; 159 std::wstring url;
184 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 160 if (m_webBrowser2)
185 if (browser)
186 { 161 {
187 CComBSTR bstrURL; 162 CComBSTR bstrURL;
188 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) 163 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL)
189 { 164 {
190 url = std::wstring(bstrURL, SysStringLen(bstrURL)); 165 url = std::wstring(bstrURL, SysStringLen(bstrURL));
191 UnescapeUrl(url); 166 UnescapeUrl(url);
192 } 167 }
193 } 168 }
194 else 169 else
195 { 170 {
171 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr owser2 == nullptr");
196 url = m_tab->GetDocumentUrl(); 172 url = m_tab->GetDocumentUrl();
197 } 173 }
198 return url; 174 return url;
199 } 175 }
200 176
201 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 177 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
202 { 178 {
203 if (thisPtr == NULL) 179 if (thisPtr == NULL)
204 return 0; 180 return 0;
205 if (!((CPluginClass*)thisPtr)->InitObject()) 181 if (!((CPluginClass*)thisPtr)->InitObject())
(...skipping 22 matching lines...) Expand all
228 { 204 {
229 205
230 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================") 206 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
231 207
232 HRESULT hr = ::CoInitialize(NULL); 208 HRESULT hr = ::CoInitialize(NULL);
233 if (FAILED(hr)) 209 if (FAILED(hr))
234 { 210 {
235 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 211 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
236 } 212 }
237 213
238 s_criticalSectionBrowser.Lock(); 214 /*
215 * We have a responsibility to call 'AdRef' on 'unknownSite' here.
216 * We discharge that responsibility by calling our base class function
217 * 'SetSite' at the end of this function.
218 * Since the base class is taking care of that, 'm_webBrowser2' can be
219 * defined as a plain pointer.
220 */
sergei 2015/10/01 16:15:51 I'm sorry, but this comment seems just wrong.
Oleksandr 2015/10/05 10:44:47 Whatever the base class SetSite does it doesn't kn
sergei 2015/10/05 11:00:56 The base class calls `AddRef` and corresponding `R
Eric 2015/11/18 13:57:30 I've done this in the new patch set.
Eric 2015/11/18 13:57:31 The base class SetSite() assigns its argument 'unk
221 hr = unknownSite->QueryInterface(IID_IWebBrowser2, (void**)(&m_webBrowser2 ));
sergei 2015/10/01 16:15:51 I cannot find the call of `Release` on `m_webBrows
Eric 2015/11/18 13:57:30 Done.
222 if (FAILED(hr))
239 { 223 {
240 m_webBrowser2 = unknownSite; 224 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*");
241 } 225 }
242 s_criticalSectionBrowser.Unlock();
243 226
244 //register the mimefilter 227 //register the mimefilter
245 //and only mimefilter 228 //and only mimefilter
246 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 229 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
247 230
248 s_criticalSectionLocal.Lock(); 231 s_criticalSectionLocal.Lock();
249 { 232 {
250 // Always register on startup, then check if we need to unregister in a separate thread 233 // Always register on startup, then check if we need to unregister in a separate thread
251 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 234 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
252 s_asyncWebBrowser2 = unknownSite; 235 s_asyncWebBrowser2 = unknownSite;
253 s_instances.insert(this); 236 s_instances.insert(this);
254 } 237 }
255 s_criticalSectionLocal.Unlock(); 238 s_criticalSectionLocal.Unlock();
256 239
257 try 240 try
258 { 241 {
259 auto webBrowser = GetBrowser(); 242 DEBUG_GENERAL("Loaded as BHO");
260 if (webBrowser) 243 HRESULT hr = DispEventAdvise(m_webBrowser2);
244 if (SUCCEEDED(hr))
261 { 245 {
262 DEBUG_GENERAL("Loaded as BHO"); 246 m_isAdvised = true;
263 HRESULT hr = DispEventAdvise(webBrowser); 247 try
264 if (SUCCEEDED(hr))
265 { 248 {
266 m_isAdvised = true; 249 std::thread startInitObjectThread(StartInitObject, this);
267 try 250 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
268 {
269 std::thread startInitObjectThread(StartInitObject, this);
270 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr.
271 }
272 catch (const std::system_error& ex)
273 {
274 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_ THREAD_CREATE_PROCESS,
275 "Class::Thread - Failed to create StartInitObject thread");
276 }
277 } 251 }
278 else 252 catch (const std::system_error& ex)
279 { 253 {
280 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advise"); 254 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS,
255 "Class::Thread - Failed to create StartInitObject thread");
281 } 256 }
282 } 257 }
258 else
259 {
260 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
261 }
283 } 262 }
284 catch (const std::runtime_error& ex) 263 catch (const std::runtime_error& ex)
285 { 264 {
286 DEBUG_EXCEPTION(ex); 265 DEBUG_EXCEPTION(ex);
287 Unadvise(); 266 Unadvise();
288 } 267 }
289 } 268 }
290 else 269 else
291 { 270 {
292 Unadvise(); 271 Unadvise();
(...skipping 29 matching lines...) Expand all
322 s_threadInstances.erase(it); 301 s_threadInstances.erase(it);
323 } 302 }
324 if (s_instances.empty()) 303 if (s_instances.empty())
325 { 304 {
326 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 305 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
327 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 306 CPluginClientFactory::ReleaseMimeFilterClientInstance();
328 } 307 }
329 } 308 }
330 s_criticalSectionLocal.Unlock(); 309 s_criticalSectionLocal.Unlock();
331 310
332 // Release browser interface
333 s_criticalSectionBrowser.Lock();
334 {
335 m_webBrowser2.Release();
sergei 2015/10/01 16:15:51 Why is this line removed?
336 }
337 s_criticalSectionBrowser.Unlock();
338
339 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 311 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
340 312
341 ::CoUninitialize(); 313 ::CoUninitialize();
342 } 314 }
343 315
344 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
345 } 316 }
346 catch (...) 317 catch (...)
347 { 318 {
348 } 319 }
320 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
Eric 2015/08/13 16:58:41 Moving this statement outside the try-block ensure
349 return S_OK; 321 return S_OK;
350 } 322 }
351 323
352 bool CPluginClass::IsStatusBarEnabled() 324 bool CPluginClass::IsStatusBarEnabled()
353 { 325 {
354 DEBUG_GENERAL("IsStatusBarEnabled start"); 326 DEBUG_GENERAL("IsStatusBarEnabled start");
355 HKEY pHkey; 327 HKEY pHkey;
356 HKEY pHkeySub; 328 HKEY pHkeySub;
357 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); 329 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey);
358 DWORD truth = 1; 330 DWORD truth = 1;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 457 }
486 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); 458 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
487 UnescapeUrl(url); 459 UnescapeUrl(url);
488 460
489 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 461 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
490 // navigating new page 462 // navigating new page
491 CPluginClient* client = CPluginClient::GetInstance(); 463 CPluginClient* client = CPluginClient::GetInstance();
492 if (url.find(L"javascript") == 0) 464 if (url.find(L"javascript") == 0)
493 { 465 {
494 } 466 }
495 else if (GetBrowser().IsEqualObject(webBrowser)) 467 else if (IsRootPageBrowser(webBrowser))
496 { 468 {
497 m_tab->OnNavigate(url); 469 m_tab->OnNavigate(url);
498 DEBUG_GENERAL( 470 DEBUG_GENERAL(
499 L"======================================================================== ========\n" 471 L"======================================================================== ========\n"
500 L"Begin main navigation url:" + url + L"\n" 472 L"Begin main navigation url:" + url + L"\n"
501 L"======================================================================== ========") 473 L"======================================================================== ========")
502 474
503 #ifdef ENABLE_DEBUG_RESULT 475 #ifdef ENABLE_DEBUG_RESULT
504 CPluginDebug::DebugResultDomain(url); 476 CPluginDebug::DebugResultDomain(url);
505 #endif 477 #endif
506 UpdateStatusBar(); 478 UpdateStatusBar();
507 } 479 }
508 else 480 else
509 { 481 {
510 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 482 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
511 m_tab->CacheFrame(url); 483 m_tab->CacheFrame(url);
512 } 484 }
513 } 485 }
514 catch (...) 486 catch (...)
515 { 487 {
516 } 488 }
517 } 489 }
518 490
519 // Entry point 491 // Entry point
520 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() 492 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
521 { 493 {
522 try 494 try
523 { 495 {
496 if (!m_webBrowser2)
497 {
498 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with m_webBrowser2 == nullptr");
499 return;
500 }
524 DEBUG_NAVI(L"Navi::Download Complete") 501 DEBUG_NAVI(L"Navi::Download Complete")
525 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); 502 m_tab->OnDownloadComplete(m_webBrowser2);
526 if (browser)
527 {
528 m_tab->OnDownloadComplete(browser);
529 }
530 } 503 }
531 catch (...) 504 catch (...)
532 { 505 {
533 } 506 }
534 } 507 }
535 508
536 // Entry point 509 // Entry point
537 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/) 510 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
538 { 511 {
539 try 512 try
540 { 513 {
541 DEBUG_NAVI(L"Navi::Document Complete"); 514 DEBUG_NAVI(L"Navi::Document Complete");
542 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; 515 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
543 if (!webBrowser2) 516 if (!webBrowser2)
544 { 517 {
545 return; 518 return;
546 } 519 }
547 std::wstring frameSrc = GetLocationUrl(*webBrowser2); 520 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
548 UnescapeUrl(frameSrc); 521 UnescapeUrl(frameSrc);
549 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); 522 m_tab->OnDocumentComplete(webBrowser2, frameSrc, IsRootPageBrowser(webBrowse r2));
550 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
551 } 523 }
552 catch (...) 524 catch (...)
553 { 525 {
554 } 526 }
555 } 527 }
556 528
557 // Entry point 529 // Entry point
558 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 530 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
559 { 531 {
560 try 532 try
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 { 591 {
620 Unadvise(); 592 Unadvise();
621 } 593 }
622 catch (...) 594 catch (...)
623 { 595 {
624 } 596 }
625 } 597 }
626 598
627 bool CPluginClass::InitObject() 599 bool CPluginClass::InitObject()
628 { 600 {
629 DEBUG_GENERAL("InitObject"); 601 DEBUG_GENERAL("InitObject - begin");
630 CPluginSettings* settings = CPluginSettings::GetInstance(); 602 CPluginSettings* settings = CPluginSettings::GetInstance();
631 603
632 if (!settings->GetPluginEnabled()) 604 if (!settings->GetPluginEnabled())
633 { 605 {
634 s_mimeFilter->Unregister(); 606 s_mimeFilter->Unregister();
635 } 607 }
636 608
637 // Load theme module 609 // Load theme module
638 s_criticalSectionLocal.Lock(); 610 s_criticalSectionLocal.Lock();
639 { 611 {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun) 704 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun)
733 { 705 {
734 ShowStatusBar(); 706 ShowStatusBar();
735 } 707 }
736 708
737 // Enable acceptable ads by default 709 // Enable acceptable ads by default
738 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L""); 710 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L"");
739 CPluginClient::GetInstance()->AddSubscription(aaUrl); 711 CPluginClient::GetInstance()->AddSubscription(aaUrl);
740 } 712 }
741 s_criticalSectionLocal.Unlock(); 713 s_criticalSectionLocal.Unlock();
714
715 DEBUG_GENERAL("InitObject - end");
742 return true; 716 return true;
743 } 717 }
744 718
745 bool CPluginClass::CreateStatusBarPane() 719 bool CPluginClass::CreateStatusBarPane()
746 { 720 {
747 CriticalSection::Lock lock(m_csStatusBar); 721 CriticalSection::Lock lock(m_csStatusBar);
748 722
749 CPluginClient* client = CPluginClient::GetInstance(); 723 CPluginClient* client = CPluginClient::GetInstance();
750 724
751 std::array<wchar_t, MAX_PATH> className; 725 std::array<wchar_t, MAX_PATH> className;
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 } 1595 }
1622 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1596 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1623 { 1597 {
1624 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1598 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1625 } 1599 }
1626 } 1600 }
1627 1601
1628 1602
1629 void CPluginClass::Unadvise() 1603 void CPluginClass::Unadvise()
1630 { 1604 {
1605 if (!m_webBrowser2)
1606 {
1607 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with m_webBrowser 2 == nullptr");
1608 return;
1609 }
1631 s_criticalSectionLocal.Lock(); 1610 s_criticalSectionLocal.Lock();
1632 { 1611 {
1633 if (m_isAdvised) 1612 if (m_isAdvised)
1634 { 1613 {
1635 HRESULT hr = DispEventUnadvise(GetBrowser()); 1614 HRESULT hr = DispEventUnadvise(m_webBrowser2);
1636 if (FAILED(hr)) 1615 if (FAILED(hr))
1637 { 1616 {
1638 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise"); 1617 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1639 } 1618 }
1640 m_isAdvised = false; 1619 m_isAdvised = false;
1641 } 1620 }
1642 } 1621 }
1643 s_criticalSectionLocal.Unlock(); 1622 s_criticalSectionLocal.Unlock();
1644 } 1623 }
1645 1624
(...skipping 19 matching lines...) Expand all
1665 s_criticalSectionLocal.Unlock(); 1644 s_criticalSectionLocal.Unlock();
1666 1645
1667 return icon; 1646 return icon;
1668 } 1647 }
1669 1648
1670 ATOM CPluginClass::GetAtomPaneClass() 1649 ATOM CPluginClass::GetAtomPaneClass()
1671 { 1650 {
1672 return s_atomPaneClass; 1651 return s_atomPaneClass;
1673 } 1652 }
1674 1653
1675 HWND CPluginClass::GetTabHWND() const
1676 {
1677 std::array<wchar_t, MAX_PATH> className;
1678 // Get browser window and url
1679 HWND hBrowserWnd = GetBrowserHWND();
1680 if (!hBrowserWnd)
1681 {
1682 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::GetTabWindow - No tab window")
1683 s_criticalSectionWindow.Unlock();
1684
1685 return false;
1686 }
1687
1688 // Looking for a TabWindowClass window in IE7
1689
1690 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
1691 while (hTabWnd)
1692 {
1693 className[0] = L'\0';
1694 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz e());
1695
1696 if (classNameLength && (wcscmp(className.data(), L"TabWindowClass") == 0 || wcscmp(className.data(), L"Frame Tab") == 0))
1697 {
1698 // IE8 support
1699 HWND hTabWnd2 = hTabWnd;
1700 if (wcscmp(className.data(), L"Frame Tab") == 0)
1701 {
1702 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL);
1703 }
1704
1705 if (hTabWnd2)
1706 {
1707 DWORD nProcessId;
1708 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
1709 if (::GetCurrentProcessId() == nProcessId)
1710 {
1711 bool bExistingTab = false;
1712 s_criticalSectionLocal.Lock();
1713
1714 {
1715 for (auto instance : s_instances)
1716 {
1717 if (instance->m_hTabWnd == hTabWnd2)
1718 {
1719 bExistingTab = true;
1720 break;
1721 }
1722 }
1723 }
1724
1725 if (!bExistingTab)
1726 {
1727 hBrowserWnd = hTabWnd2;
1728 hTabWnd = hTabWnd2;
1729 s_criticalSectionLocal.Unlock();
1730 break;
1731 }
1732 s_criticalSectionLocal.Unlock();
1733
1734 }
1735 }
1736 }
1737
1738 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1739 }
1740 return hTabWnd;
1741 }
OLDNEW
« src/plugin/PluginClass.h ('K') | « src/plugin/PluginClass.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld