OLD | NEW |
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 { | 194 { |
195 url = m_tab->GetDocumentUrl(); | 195 url = m_tab->GetDocumentUrl(); |
196 } | 196 } |
197 return url; | 197 return url; |
198 } | 198 } |
199 | 199 |
200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 200 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
201 { | 201 { |
202 if (thisPtr == NULL) | 202 if (thisPtr == NULL) |
203 return 0; | 203 return 0; |
204 if (!((CPluginClass*)thisPtr)->InitObject(true)) | 204 if (!((CPluginClass*)thisPtr)->InitObject()) |
205 { | 205 { |
206 ((CPluginClass*)thisPtr)->Unadvise(); | 206 ((CPluginClass*)thisPtr)->Unadvise(); |
207 } | 207 } |
208 | 208 |
209 return 0; | 209 return 0; |
210 } | 210 } |
211 | 211 |
212 // This gets called when a new browser window is created (which also triggers th
e | 212 /* |
213 // creation of this object). The pointer passed in should be to a IWebBrowser2 | 213 * IE calls this when it creates a new browser window or tab, immediately after
it also |
214 // interface that represents the browser for the window. | 214 * creates the object. The argument 'unknownSite' in is the OLE "site" of the ob
ject, |
215 // it is also called when a tab is closed, this unknownSite will be null | 215 * which is an IWebBrowser2 interface associated with the window/tab. |
216 // so we should handle that it is called this way several times during a session | 216 * |
| 217 * IE also ordinarily calls this again when its window/tab is closed, in which c
ase |
| 218 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w
hen IE |
| 219 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru
ctor, |
| 220 * but it is not a proper substitute for one. |
| 221 */ |
217 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) | 222 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) |
218 { | 223 { |
219 CPluginSettings* settings = CPluginSettings::GetInstance(); | 224 try |
| 225 { |
| 226 if (unknownSite) |
| 227 { |
220 | 228 |
221 MULTIPLE_VERSIONS_CHECK(); | 229 DEBUG_GENERAL(L"==========================================================
======================\nNEW TAB UI\n============================================
====================================") |
222 | 230 |
223 if (unknownSite) | 231 HRESULT hr = ::CoInitialize(NULL); |
224 { | 232 if (FAILED(hr)) |
| 233 { |
| 234 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
"Class::SetSite - CoInitialize"); |
| 235 } |
225 | 236 |
226 DEBUG_GENERAL(L"============================================================
====================\nNEW TAB UI\n==============================================
==================================") | 237 s_criticalSectionBrowser.Lock(); |
| 238 { |
| 239 m_webBrowser2 = unknownSite; |
| 240 } |
| 241 s_criticalSectionBrowser.Unlock(); |
227 | 242 |
228 HRESULT hr = ::CoInitialize(NULL); | 243 //register the mimefilter |
229 if (FAILED(hr)) | 244 //and only mimefilter |
| 245 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread |
| 246 |
| 247 s_criticalSectionLocal.Lock(); |
| 248 { |
| 249 // Always register on startup, then check if we need to unregister in a
separate thread |
| 250 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
| 251 s_asyncWebBrowser2 = unknownSite; |
| 252 s_instances.insert(this); |
| 253 } |
| 254 s_criticalSectionLocal.Unlock(); |
| 255 |
| 256 try |
| 257 { |
| 258 auto webBrowser = GetBrowser(); |
| 259 if (webBrowser) |
| 260 { |
| 261 DEBUG_GENERAL("Loaded as BHO"); |
| 262 HRESULT hr = DispEventAdvise(webBrowser); |
| 263 if (SUCCEEDED(hr)) |
| 264 { |
| 265 m_isAdvised = true; |
| 266 try |
| 267 { |
| 268 std::thread startInitObjectThread(StartInitObject, this); |
| 269 startInitObjectThread.detach(); // TODO: but actually we should wa
it for the thread in the dtr. |
| 270 } |
| 271 catch (const std::system_error& ex) |
| 272 { |
| 273 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_
THREAD_CREATE_PROCESS, |
| 274 "Class::Thread - Failed to create StartInitObject thread"); |
| 275 } |
| 276 } |
| 277 else |
| 278 { |
| 279 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV
ICE, "Class::SetSite - Advise"); |
| 280 } |
| 281 } |
| 282 } |
| 283 catch (const std::runtime_error& ex) |
| 284 { |
| 285 DEBUG_EXCEPTION(ex); |
| 286 Unadvise(); |
| 287 } |
| 288 } |
| 289 else |
230 { | 290 { |
231 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "
Class::SetSite - CoInitialize"); | 291 Unadvise(); |
| 292 |
| 293 // Destroy window |
| 294 if (m_pWndProcStatus) |
| 295 { |
| 296 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
dProcStatus); |
| 297 |
| 298 m_pWndProcStatus = NULL; |
| 299 } |
| 300 |
| 301 if (m_hPaneWnd) |
| 302 { |
| 303 DestroyWindow(m_hPaneWnd); |
| 304 m_hPaneWnd = NULL; |
| 305 } |
| 306 |
| 307 m_hTabWnd = NULL; |
| 308 m_hStatusBarWnd = NULL; |
| 309 |
| 310 // Remove instance from the list, shutdown threads |
| 311 HANDLE hMainThread = NULL; |
| 312 HANDLE hTabThread = NULL; |
| 313 |
| 314 s_criticalSectionLocal.Lock(); |
| 315 { |
| 316 s_instances.erase(this); |
| 317 |
| 318 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge
tCurrentThreadId()); |
| 319 if (it != s_threadInstances.end()) |
| 320 { |
| 321 s_threadInstances.erase(it); |
| 322 } |
| 323 if (s_instances.empty()) |
| 324 { |
| 325 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr |
| 326 CPluginClientFactory::ReleaseMimeFilterClientInstance(); |
| 327 } |
| 328 } |
| 329 s_criticalSectionLocal.Unlock(); |
| 330 |
| 331 // Release browser interface |
| 332 s_criticalSectionBrowser.Lock(); |
| 333 { |
| 334 m_webBrowser2.Release(); |
| 335 } |
| 336 s_criticalSectionBrowser.Unlock(); |
| 337 |
| 338 DEBUG_GENERAL("===========================================================
=====================\nNEW TAB UI - END\n=======================================
=========================================") |
| 339 |
| 340 ::CoUninitialize(); |
232 } | 341 } |
233 | 342 |
234 s_criticalSectionBrowser.Lock(); | 343 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); |
235 { | |
236 m_webBrowser2 = unknownSite; | |
237 } | |
238 s_criticalSectionBrowser.Unlock(); | |
239 | |
240 //register the mimefilter | |
241 //and only mimefilter | |
242 //on some few computers the mimefilter does not get properly registered when
it is done on another thread | |
243 | |
244 s_criticalSectionLocal.Lock(); | |
245 { | |
246 // Always register on startup, then check if we need to unregister in a se
parate thread | |
247 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | |
248 s_asyncWebBrowser2 = unknownSite; | |
249 s_instances.insert(this); | |
250 } | |
251 s_criticalSectionLocal.Unlock(); | |
252 | |
253 try | |
254 { | |
255 // Check if loaded as BHO | |
256 auto webBrowser = GetBrowser(); | |
257 if (webBrowser) | |
258 { | |
259 DEBUG_GENERAL("Loaded as BHO"); | |
260 HRESULT hr = DispEventAdvise(webBrowser); | |
261 if (SUCCEEDED(hr)) | |
262 { | |
263 m_isAdvised = true; | |
264 try | |
265 { | |
266 std::thread startInitObjectThread(StartInitObject, this); | |
267 startInitObjectThread.detach(); // TODO: but actually we should wait
for the thread in the dtr. | |
268 } | |
269 catch (const std::system_error& ex) | |
270 { | |
271 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH
READ_CREATE_PROCESS, | |
272 "Class::Thread - Failed to create StartInitObject thread"); | |
273 } | |
274 } | |
275 else | |
276 { | |
277 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC
E, "Class::SetSite - Advise"); | |
278 } | |
279 } | |
280 else // Check if loaded as toolbar handler | |
281 { | |
282 DEBUG_GENERAL("Loaded as toolbar handler"); | |
283 CComPtr<IServiceProvider> pServiceProvider; | |
284 | |
285 HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); | |
286 if (SUCCEEDED(hr)) | |
287 { | |
288 if (pServiceProvider) | |
289 { | |
290 s_criticalSectionBrowser.Lock(); | |
291 { | |
292 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, &m
_webBrowser2); | |
293 if (SUCCEEDED(hr)) | |
294 { | |
295 if (m_webBrowser2) | |
296 { | |
297 InitObject(false); | |
298 } | |
299 } | |
300 else | |
301 { | |
302 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE
_QUERY_BROWSER, "Class::SetSite - QueryService (IID_IWebBrowserApp)"); | |
303 } | |
304 } | |
305 s_criticalSectionBrowser.Unlock(); | |
306 } | |
307 } | |
308 else | |
309 { | |
310 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUERY
_SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); | |
311 } | |
312 } | |
313 } | |
314 catch (const std::runtime_error& ex) | |
315 { | |
316 DEBUG_EXCEPTION(ex); | |
317 Unadvise(); | |
318 } | |
319 } | 344 } |
320 else | 345 catch (...) |
321 { | 346 { |
322 Unadvise(); | |
323 | |
324 // Destroy window | |
325 if (m_pWndProcStatus) | |
326 { | |
327 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWndP
rocStatus); | |
328 | |
329 m_pWndProcStatus = NULL; | |
330 } | |
331 | |
332 if (m_hPaneWnd) | |
333 { | |
334 DestroyWindow(m_hPaneWnd); | |
335 m_hPaneWnd = NULL; | |
336 } | |
337 | |
338 m_hTabWnd = NULL; | |
339 m_hStatusBarWnd = NULL; | |
340 | |
341 // Remove instance from the list, shutdown threads | |
342 HANDLE hMainThread = NULL; | |
343 HANDLE hTabThread = NULL; | |
344 | |
345 s_criticalSectionLocal.Lock(); | |
346 { | |
347 s_instances.erase(this); | |
348 | |
349 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC
urrentThreadId()); | |
350 if (it != s_threadInstances.end()) | |
351 { | |
352 s_threadInstances.erase(it); | |
353 } | |
354 if (s_instances.empty()) | |
355 { | |
356 // TODO: Explicitly releasing a resource when a container becomes empty
looks like a job better suited for shared_ptr | |
357 CPluginClientFactory::ReleaseMimeFilterClientInstance(); | |
358 } | |
359 } | |
360 s_criticalSectionLocal.Unlock(); | |
361 | |
362 // Release browser interface | |
363 s_criticalSectionBrowser.Lock(); | |
364 { | |
365 m_webBrowser2.Release(); | |
366 } | |
367 s_criticalSectionBrowser.Unlock(); | |
368 | |
369 DEBUG_GENERAL("=============================================================
===================\nNEW TAB UI - END\n=========================================
=======================================") | |
370 | |
371 ::CoUninitialize(); | |
372 } | 347 } |
373 | 348 return S_OK; |
374 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); | |
375 } | 349 } |
376 | 350 |
377 bool CPluginClass::IsStatusBarEnabled() | 351 bool CPluginClass::IsStatusBarEnabled() |
378 { | 352 { |
379 DEBUG_GENERAL("IsStatusBarEnabled start"); | 353 DEBUG_GENERAL("IsStatusBarEnabled start"); |
380 HKEY pHkey; | 354 HKEY pHkey; |
381 HKEY pHkeySub; | 355 HKEY pHkeySub; |
382 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); | 356 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); |
383 DWORD truth = 1; | 357 DWORD truth = 1; |
384 DWORD truthSize = sizeof(truth); | 358 DWORD truthSize = sizeof(truth); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA
BLED); | 568 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA
BLED); |
595 if (newtabshown) | 569 if (newtabshown) |
596 { | 570 { |
597 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(
GetCurrentThreadId()); | 571 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(
GetCurrentThreadId()); |
598 if (it == s_threadInstances.end()) | 572 if (it == s_threadInstances.end()) |
599 { | 573 { |
600 s_threadInstances[::GetCurrentThreadId()] = this; | 574 s_threadInstances[::GetCurrentThreadId()] = this; |
601 if (!m_isInitializedOk) | 575 if (!m_isInitializedOk) |
602 { | 576 { |
603 m_isInitializedOk = true; | 577 m_isInitializedOk = true; |
604 InitObject(true); | 578 InitObject(); |
605 UpdateStatusBar(); | 579 UpdateStatusBar(); |
606 } | 580 } |
607 } | 581 } |
608 } | 582 } |
609 notificationMessage.Hide(); | 583 notificationMessage.Hide(); |
610 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end"); | 584 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end"); |
611 } | 585 } |
612 catch (...) | 586 catch (...) |
613 { | 587 { |
614 } | 588 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 { | 621 { |
648 try | 622 try |
649 { | 623 { |
650 Unadvise(); | 624 Unadvise(); |
651 } | 625 } |
652 catch (...) | 626 catch (...) |
653 { | 627 { |
654 } | 628 } |
655 } | 629 } |
656 | 630 |
657 bool CPluginClass::InitObject(bool bBHO) | 631 bool CPluginClass::InitObject() |
658 { | 632 { |
659 DEBUG_GENERAL("InitObject"); | 633 DEBUG_GENERAL("InitObject"); |
660 CPluginSettings* settings = CPluginSettings::GetInstance(); | 634 CPluginSettings* settings = CPluginSettings::GetInstance(); |
661 | 635 |
662 if (!settings->GetPluginEnabled()) | 636 if (!settings->GetPluginEnabled()) |
663 { | 637 { |
664 s_mimeFilter->Unregister(); | 638 s_mimeFilter->Unregister(); |
665 } | 639 } |
666 | 640 |
667 // Load theme module | 641 // Load theme module |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 698 |
725 if (!GetAtomPaneClass()) | 699 if (!GetAtomPaneClass()) |
726 { | 700 { |
727 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"); |
728 return false; | 702 return false; |
729 } | 703 } |
730 } | 704 } |
731 | 705 |
732 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); | 706 int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); |
733 // Create status pane | 707 // Create status pane |
734 if (bBHO && ieVersion > 6 && !CreateStatusBarPane()) | 708 if (ieVersion > 6 && !CreateStatusBarPane()) |
735 { | 709 { |
736 return false; | 710 return false; |
737 } | 711 } |
738 | 712 |
739 s_criticalSectionLocal.Lock(); | 713 s_criticalSectionLocal.Lock(); |
740 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"); |
741 | 715 |
742 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun(); | 716 bool isFirstRun = CPluginClient::GetInstance()->IsFirstRun(); |
743 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN
_VERSION)); | 717 CPluginClient::GetInstance()->SetPref(L"currentVersion", std::wstring(IEPLUGIN
_VERSION)); |
744 // This is the first time ABP was installed | 718 // This is the first time ABP was installed |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 s_criticalSectionLocal.Unlock(); | 1732 s_criticalSectionLocal.Unlock(); |
1759 | 1733 |
1760 } | 1734 } |
1761 } | 1735 } |
1762 } | 1736 } |
1763 | 1737 |
1764 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 1738 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |
1765 } | 1739 } |
1766 return hTabWnd; | 1740 return hTabWnd; |
1767 } | 1741 } |
OLD | NEW |