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: change type of m_webBrowser2 Created Nov. 18, 2015, 6:08 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)
sergei 2015/11/30 15:52:08 We don't need it because ATL::CComPtr default cons
Eric 2015/11/30 16:31:51 I'd rather have it explicit as a lightweight form
sergei 2015/12/07 10:49:08 ATL::CComPtr initializes it to nullptr in the cons
Eric 2015/12/07 14:04:12 The very-lightweight documentation is that every v
sergei 2015/12/08 09:41:59 I think it will go away in a future and I don't un
sergei 2015/12/08 09:41:59 It sounds not convincing. Why are we not doing it
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;
sergei 2015/11/30 15:52:09 it would be good to initialize it to NULL.
Eric 2015/11/30 16:31:51 Welcome to MicrosoftLand. SHANDLE_PTR is not a poi
Oleksandr 2015/12/03 11:51:58 We don't check its value now, but we might in futu
Eric 2015/12/03 14:24:54 Initialized it to zero, which matches its type. A
sergei 2015/12/07 10:49:08 Agree, except following some good practices, like
sergei 2015/12/07 10:49:08 Although zero is OK, NULL looks better here.
Eric 2015/12/07 14:04:12 I disagree. Sometimes NULL is defined as '(void*)0
Eric 2015/12/07 14:04:12 Almost always. But even saying that is saying too
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")
sergei 2015/11/30 15:52:08 Actually, I think we should return nullptr in case
Eric 2015/11/30 16:31:51 Done. That's a good idea.
130 }
150 return (HWND)hBrowserWndHandle; 131 return (HWND)hBrowserWndHandle;
151 } 132 }
152 133
153 134 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser)
154 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const
155 { 135 {
156 CComQIPtr<IWebBrowser2> browser; 136 return m_webBrowser2.IsEqualObject(otherBrowser);
157
158 s_criticalSectionBrowser.Lock();
159 {
160 browser = m_webBrowser2;
161 }
162 s_criticalSectionBrowser.Unlock();
163
164 return browser;
165 } 137 }
166 138
167
168 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() 139 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
169 { 140 {
170 CComQIPtr<IWebBrowser2> browser; 141 CComQIPtr<IWebBrowser2> browser;
171 142
172 s_criticalSectionLocal.Lock(); 143 s_criticalSectionLocal.Lock();
173 { 144 {
174 browser = s_asyncWebBrowser2; 145 browser = s_asyncWebBrowser2;
175 } 146 }
176 s_criticalSectionLocal.Unlock(); 147 s_criticalSectionLocal.Unlock();
177 148
178 return browser; 149 return browser;
179 } 150 }
180 151
181 std::wstring CPluginClass::GetBrowserUrl() const 152 std::wstring CPluginClass::GetBrowserUrl() const
182 { 153 {
183 std::wstring url; 154 std::wstring url;
184 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 155 if (m_webBrowser2)
185 if (browser)
186 { 156 {
187 CComBSTR bstrURL; 157 CComBSTR bstrURL;
188 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) 158 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL)
189 { 159 {
190 url = std::wstring(bstrURL, SysStringLen(bstrURL)); 160 url = std::wstring(bstrURL, SysStringLen(bstrURL));
191 UnescapeUrl(url); 161 UnescapeUrl(url);
192 } 162 }
193 } 163 }
194 else 164 else
195 { 165 {
166 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr owser2 == nullptr");
196 url = m_tab->GetDocumentUrl(); 167 url = m_tab->GetDocumentUrl();
197 } 168 }
198 return url; 169 return url;
199 } 170 }
200 171
201 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 172 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
202 { 173 {
203 if (thisPtr == NULL) 174 if (thisPtr == NULL)
204 return 0; 175 return 0;
205 if (!((CPluginClass*)thisPtr)->InitObject()) 176 if (!((CPluginClass*)thisPtr)->InitObject())
(...skipping 22 matching lines...) Expand all
228 { 199 {
229 200
230 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================") 201 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
231 202
232 HRESULT hr = ::CoInitialize(NULL); 203 HRESULT hr = ::CoInitialize(NULL);
233 if (FAILED(hr)) 204 if (FAILED(hr))
234 { 205 {
235 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 206 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
236 } 207 }
237 208
238 s_criticalSectionBrowser.Lock(); 209 /*
210 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2.
211 */
212 m_webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite);
213 if (!m_webBrowser2)
239 { 214 {
240 m_webBrowser2 = unknownSite; 215 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*");
241 } 216 }
242 s_criticalSectionBrowser.Unlock();
243 217
244 //register the mimefilter 218 //register the mimefilter
245 //and only mimefilter 219 //and only mimefilter
246 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 220 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
247
248 s_criticalSectionLocal.Lock(); 221 s_criticalSectionLocal.Lock();
249 { 222 {
250 // Always register on startup, then check if we need to unregister in a separate thread 223 // Always register on startup, then check if we need to unregister in a separate thread
251 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 224 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
252 s_asyncWebBrowser2 = unknownSite; 225 s_asyncWebBrowser2 = unknownSite;
253 s_instances.insert(this); 226 s_instances.insert(this);
254 } 227 }
255 s_criticalSectionLocal.Unlock(); 228 s_criticalSectionLocal.Unlock();
256 229
257 try 230 try
258 { 231 {
259 auto webBrowser = GetBrowser(); 232 DEBUG_GENERAL("Loaded as BHO");
260 if (webBrowser) 233 HRESULT hr = DispEventAdvise(m_webBrowser2);
234 if (SUCCEEDED(hr))
261 { 235 {
262 DEBUG_GENERAL("Loaded as BHO"); 236 m_isAdvised = true;
263 HRESULT hr = DispEventAdvise(webBrowser); 237 try
264 if (SUCCEEDED(hr))
265 { 238 {
266 m_isAdvised = true; 239 std::thread startInitObjectThread(StartInitObject, this);
267 try 240 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 } 241 }
278 else 242 catch (const std::system_error& ex)
279 { 243 {
280 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advise"); 244 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS,
245 "Class::Thread - Failed to create StartInitObject thread");
281 } 246 }
282 } 247 }
248 else
249 {
250 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
251 }
283 } 252 }
284 catch (const std::runtime_error& ex) 253 catch (const std::runtime_error& ex)
285 { 254 {
286 DEBUG_EXCEPTION(ex); 255 DEBUG_EXCEPTION(ex);
287 Unadvise(); 256 Unadvise();
288 } 257 }
289 } 258 }
290 else 259 else
291 { 260 {
292 Unadvise(); 261 Unadvise();
(...skipping 29 matching lines...) Expand all
322 s_threadInstances.erase(it); 291 s_threadInstances.erase(it);
323 } 292 }
324 if (s_instances.empty()) 293 if (s_instances.empty())
325 { 294 {
326 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 295 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
327 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 296 CPluginClientFactory::ReleaseMimeFilterClientInstance();
328 } 297 }
329 } 298 }
330 s_criticalSectionLocal.Unlock(); 299 s_criticalSectionLocal.Unlock();
331 300
332 // Release browser interface
333 s_criticalSectionBrowser.Lock();
334 {
335 m_webBrowser2.Release();
sergei 2015/11/30 15:52:08 It's still good to call `m_webBrowser2.Release();`
Eric 2015/11/30 16:31:51 Basically right. The correct thing to do is to nul
336 }
337 s_criticalSectionBrowser.Unlock();
338
339 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 301 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
340 302
341 ::CoUninitialize(); 303 ::CoUninitialize();
342 } 304 }
343 305
344 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
345 } 306 }
346 catch (...) 307 catch (...)
347 { 308 {
348 } 309 }
310 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
349 return S_OK; 311 return S_OK;
350 } 312 }
351 313
352 bool CPluginClass::IsStatusBarEnabled() 314 bool CPluginClass::IsStatusBarEnabled()
353 { 315 {
354 DEBUG_GENERAL("IsStatusBarEnabled start"); 316 DEBUG_GENERAL("IsStatusBarEnabled start");
355 HKEY pHkey; 317 HKEY pHkey;
356 HKEY pHkeySub; 318 HKEY pHkeySub;
357 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); 319 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey);
358 DWORD truth = 1; 320 DWORD truth = 1;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 447 }
486 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); 448 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
487 UnescapeUrl(url); 449 UnescapeUrl(url);
488 450
489 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 451 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
490 // navigating new page 452 // navigating new page
491 CPluginClient* client = CPluginClient::GetInstance(); 453 CPluginClient* client = CPluginClient::GetInstance();
492 if (url.find(L"javascript") == 0) 454 if (url.find(L"javascript") == 0)
493 { 455 {
494 } 456 }
495 else if (GetBrowser().IsEqualObject(webBrowser)) 457 else if (IsRootBrowser(webBrowser))
496 { 458 {
497 m_tab->OnNavigate(url); 459 m_tab->OnNavigate(url);
498 DEBUG_GENERAL( 460 DEBUG_GENERAL(
499 L"======================================================================== ========\n" 461 L"======================================================================== ========\n"
500 L"Begin main navigation url:" + url + L"\n" 462 L"Begin main navigation url:" + url + L"\n"
501 L"======================================================================== ========") 463 L"======================================================================== ========")
502 464
503 #ifdef ENABLE_DEBUG_RESULT 465 #ifdef ENABLE_DEBUG_RESULT
504 CPluginDebug::DebugResultDomain(url); 466 CPluginDebug::DebugResultDomain(url);
505 #endif 467 #endif
506 UpdateStatusBar(); 468 UpdateStatusBar();
507 } 469 }
508 else 470 else
509 { 471 {
510 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 472 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
511 m_tab->CacheFrame(url); 473 m_tab->CacheFrame(url);
512 } 474 }
513 } 475 }
514 catch (...) 476 catch (...)
515 { 477 {
516 } 478 }
517 } 479 }
518 480
519 // Entry point 481 // Entry point
520 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() 482 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
521 { 483 {
522 try 484 try
523 { 485 {
486 if (!m_webBrowser2)
487 {
488 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with m_webBrowser2 == nullptr");
489 return;
490 }
524 DEBUG_NAVI(L"Navi::Download Complete") 491 DEBUG_NAVI(L"Navi::Download Complete")
525 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); 492 m_tab->OnDownloadComplete(m_webBrowser2);
526 if (browser)
527 {
528 m_tab->OnDownloadComplete(browser);
529 }
530 } 493 }
531 catch (...) 494 catch (...)
532 { 495 {
533 } 496 }
534 } 497 }
535 498
536 // Entry point 499 // Entry point
537 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/) 500 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD isp, VARIANT* /*urlOrPidl*/)
538 { 501 {
539 try 502 try
540 { 503 {
541 DEBUG_NAVI(L"Navi::Document Complete"); 504 DEBUG_NAVI(L"Navi::Document Complete");
542 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; 505 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
543 if (!webBrowser2) 506 if (!webBrowser2)
544 { 507 {
545 return; 508 return;
546 } 509 }
547 std::wstring frameSrc = GetLocationUrl(*webBrowser2); 510 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
548 UnescapeUrl(frameSrc); 511 UnescapeUrl(frameSrc);
549 bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); 512 m_tab->OnDocumentComplete(webBrowser2, frameSrc, IsRootBrowser(webBrowser2)) ;
550 m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
551 } 513 }
552 catch (...) 514 catch (...)
553 { 515 {
554 } 516 }
555 } 517 }
556 518
557 // Entry point 519 // Entry point
558 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 520 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
559 { 521 {
560 try 522 try
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 { 581 {
620 Unadvise(); 582 Unadvise();
621 } 583 }
622 catch (...) 584 catch (...)
623 { 585 {
624 } 586 }
625 } 587 }
626 588
627 bool CPluginClass::InitObject() 589 bool CPluginClass::InitObject()
628 { 590 {
629 DEBUG_GENERAL("InitObject"); 591 DEBUG_GENERAL("InitObject - begin");
630 CPluginSettings* settings = CPluginSettings::GetInstance(); 592 CPluginSettings* settings = CPluginSettings::GetInstance();
631 593
632 if (!settings->GetPluginEnabled()) 594 if (!settings->GetPluginEnabled())
633 { 595 {
634 s_mimeFilter->Unregister(); 596 s_mimeFilter->Unregister();
635 } 597 }
636 598
637 // Load theme module 599 // Load theme module
638 s_criticalSectionLocal.Lock(); 600 s_criticalSectionLocal.Lock();
639 { 601 {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun) 694 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun)
733 { 695 {
734 ShowStatusBar(); 696 ShowStatusBar();
735 } 697 }
736 698
737 // Enable acceptable ads by default 699 // Enable acceptable ads by default
738 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L""); 700 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L"");
739 CPluginClient::GetInstance()->AddSubscription(aaUrl); 701 CPluginClient::GetInstance()->AddSubscription(aaUrl);
740 } 702 }
741 s_criticalSectionLocal.Unlock(); 703 s_criticalSectionLocal.Unlock();
704
705 DEBUG_GENERAL("InitObject - end");
742 return true; 706 return true;
743 } 707 }
744 708
745 bool CPluginClass::CreateStatusBarPane() 709 bool CPluginClass::CreateStatusBarPane()
746 { 710 {
747 CriticalSection::Lock lock(m_csStatusBar); 711 CriticalSection::Lock lock(m_csStatusBar);
748 712
749 CPluginClient* client = CPluginClient::GetInstance(); 713 CPluginClient* client = CPluginClient::GetInstance();
750 714
751 std::array<wchar_t, MAX_PATH> className; 715 std::array<wchar_t, MAX_PATH> className;
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 } 1585 }
1622 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1586 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1623 { 1587 {
1624 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1588 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1625 } 1589 }
1626 } 1590 }
1627 1591
1628 1592
1629 void CPluginClass::Unadvise() 1593 void CPluginClass::Unadvise()
1630 { 1594 {
1595 if (!m_webBrowser2)
1596 {
1597 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with m_webBrowser 2 == nullptr");
1598 return;
1599 }
1631 s_criticalSectionLocal.Lock(); 1600 s_criticalSectionLocal.Lock();
1632 { 1601 {
1633 if (m_isAdvised) 1602 if (m_isAdvised)
1634 { 1603 {
1635 HRESULT hr = DispEventUnadvise(GetBrowser()); 1604 HRESULT hr = DispEventUnadvise(m_webBrowser2);
1636 if (FAILED(hr)) 1605 if (FAILED(hr))
1637 { 1606 {
1638 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise"); 1607 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1639 } 1608 }
1640 m_isAdvised = false; 1609 m_isAdvised = false;
1641 } 1610 }
1642 } 1611 }
1643 s_criticalSectionLocal.Unlock(); 1612 s_criticalSectionLocal.Unlock();
1644 } 1613 }
1645 1614
(...skipping 19 matching lines...) Expand all
1665 s_criticalSectionLocal.Unlock(); 1634 s_criticalSectionLocal.Unlock();
1666 1635
1667 return icon; 1636 return icon;
1668 } 1637 }
1669 1638
1670 ATOM CPluginClass::GetAtomPaneClass() 1639 ATOM CPluginClass::GetAtomPaneClass()
1671 { 1640 {
1672 return s_atomPaneClass; 1641 return s_atomPaneClass;
1673 } 1642 }
1674 1643
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