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

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

Issue 6567422169448448: Issue 119 - Switch to injecting CSS for element hiding (Closed)
Left Patch Set: rebase Created Dec. 1, 2015, 11:29 a.m.
Right Patch Set: rename OnQuit Created Sept. 30, 2016, 3:25 p.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/PluginTabBase.h ('k') | src/plugin/WebBrowserEventsListener.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-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
19 #include "AdblockPlusClient.h" 19 #include "AdblockPlusClient.h"
20 #include "PluginClientBase.h" 20 #include "PluginClientBase.h"
21 #include "PluginSettings.h" 21 #include "PluginSettings.h"
22 #include "AdblockPlusDomTraverser.h" 22 #include "AdblockPlusDomTraverser.h"
23 #include "PluginTabBase.h" 23 #include "PluginTabBase.h"
24 #include "IeVersion.h" 24 #include "IeVersion.h"
25 #include "../shared/Utils.h" 25 #include "../shared/Utils.h"
26 #include "../shared/EventWithSetter.h"
26 #include <Mshtmhst.h> 27 #include <Mshtmhst.h>
27 #include "../shared/Utils.h" 28 #include <mutex>
28 29
29 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) 30 class CPluginTab::AsyncPluginFilter
30 : m_plugin(plugin) 31 {
31 , m_isActivated(false) 32 public:
33 static std::shared_ptr<AsyncPluginFilter> CreateAsync(const std::wstring& doma in)
34 {
35 std::shared_ptr<AsyncPluginFilter> asyncFilter = std::make_shared<AsyncPlugi nFilter>();
36 std::weak_ptr<AsyncPluginFilter> weakAsyncData = asyncFilter;
37 auto eventSetter = asyncFilter->event.CreateSetter();
38 try
39 {
40 std::thread([domain, weakAsyncData, eventSetter]
41 {
42 try
43 {
44 CreateAsyncImpl(domain, weakAsyncData, eventSetter);
45 }
46 » catch (...)
47 {
48 // As a thread-main function, we truncate any C++ exception.
49 }
50 }).detach();
51 // TODO: we should do something with that `detach` above.
52 }
53 catch (const std::system_error& ex)
54 {
55 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_C REATE_PROCESS,
56 "Class::Thread - Failed to start filter loader thread");
57 }
58 return asyncFilter;
59 }
60 PluginFilterPtr GetFilter()
61 {
62 if (!event.Wait())
63 return PluginFilterPtr();
64 std::lock_guard<std::mutex> lock(mutex);
65 return filter;
66 }
67 private:
68 static void CreateAsyncImpl(const std::wstring& domain, std::weak_ptr<AsyncPlu ginFilter> weakAsyncData, const std::shared_ptr<EventWithSetter::Setter>& setter )
69 {
70 std::unique_ptr<CPluginFilter> pluginFilter(new CPluginFilter(CPluginClient: :GetInstance()->GetElementHidingSelectors(domain)));
71 if (auto asyncData = weakAsyncData.lock())
72 {
73 {
74 std::lock_guard<std::mutex> lock(asyncData->mutex);
75 asyncData->filter = move(pluginFilter);
76 }
77 setter->Set();
78 }
79 }
80 EventWithSetter event;
81 std::mutex mutex;
82 PluginFilterPtr filter;
83 };
84
85 CPluginTab::CPluginTab()
86 : m_isActivated(false)
32 , m_continueThreadRunning(true) 87 , m_continueThreadRunning(true)
33 { 88 {
34 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
35 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL);
36
37 CPluginClient* client = CPluginClient::GetInstance(); 89 CPluginClient* client = CPluginClient::GetInstance();
38 if (AdblockPlus::IE::InstalledMajorVersion() < 10) 90 if (AdblockPlus::IE::InstalledMajorVersion() < 10)
39 { 91 {
40 m_isActivated = true; 92 m_isActivated = true;
41 } 93 }
42 94
43 try 95 try
44 { 96 {
45 m_thread = std::thread(&CPluginTabBase::ThreadProc, this); 97 m_thread = std::thread(&CPluginTab::ThreadProc, this);
46 } 98 }
47 catch (const std::system_error& ex) 99 catch (const std::system_error& ex)
48 { 100 {
49 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THREAD_CREA TE_PROCESS, 101 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THREAD_CREA TE_PROCESS,
50 "Tab::Thread - Failed to create tab thread"); 102 "Tab::Thread - Failed to create tab thread");
51 } 103 }
52 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this)); 104 }
53 } 105
54 106
55 107 CPluginTab::~CPluginTab()
56 CPluginTabBase::~CPluginTabBase() 108 {
57 {
58 delete m_traverser;
59 m_traverser = NULL;
60 m_continueThreadRunning = false; 109 m_continueThreadRunning = false;
61 if (m_thread.joinable()) { 110 if (m_thread.joinable()) {
62 m_thread.join(); 111 m_thread.join();
63 } 112 }
64 } 113 }
65 114
66 void CPluginTabBase::OnActivate() 115 /**
116 * ABP only intercepts protocols "http:" and "https:".
117 * We can disable any domain used in those protocol with an appropriate whitelis t filter.
118 * Thus, the possibility to disable on a particular site depends only on the pro tocol.
119 */
120 bool CPluginTab::IsPossibleToDisableOnSite()
121 {
122 auto url = GetDocumentUrl();
123 return BeginsWith(url, L"http:") || BeginsWith(url, L"https:");
124 }
125
126 void CPluginTab::OnActivate()
67 { 127 {
68 m_isActivated = true; 128 m_isActivated = true;
69 } 129 }
70 130
71 131
72 void CPluginTabBase::OnUpdate() 132 void CPluginTab::OnUpdate()
73 { 133 {
74 m_isActivated = true; 134 m_isActivated = true;
75 } 135 }
76 136
77 namespace 137 void CPluginTab::OnNavigate(const std::wstring& url)
78 {
79 // Entry Point
80 void FilterLoader(CPluginTabBase* tabBase)
81 {
82 try
83 {
84 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElemen tHidingSelectors(tabBase->GetDocumentDomain()));
85 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent);
86 }
87 catch (...)
88 {
89 // As a thread-main function, we truncate any C++ exception.
90 }
91 }
92 }
93
94 void CPluginTabBase::OnNavigate(const std::wstring& url)
95 { 138 {
96 SetDocumentUrl(url); 139 SetDocumentUrl(url);
97 ClearFrameCache(GetDocumentDomain()); 140 std::wstring domain = GetDocumentDomain();
98 std::wstring domainString = GetDocumentDomain(); 141 ClearFrameCache(domain);
99 ResetEvent(m_filter->hideFiltersLoadedEvent); 142 m_asyncPluginFilter = AsyncPluginFilter::CreateAsync(domain);
100 try 143 m_traverser.reset();
101 {
102 std::thread filterLoaderThread(&FilterLoader, this);
103 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr.
104 }
105 catch (const std::system_error& ex)
106 {
107 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CRE ATE_PROCESS,
108 "Class::Thread - Failed to start filter loader thread");
109 }
110 m_traverser->ClearCache();
111 } 144 }
112 145
113 namespace 146 namespace
114 { 147 {
115 /** 148 /**
116 * Determine if the HTML file is one of ours. 149 * Determine if the HTML file is one of ours.
117 * The criterion is that it appear in the "html/templates" folder within our i nstallation. 150 * The criterion is that it appear in the "html/templates" folder within our i nstallation.
118 * 151 *
119 * Warning: This function may fail if the argument is not a "file://" URL. 152 * Warning: This function may fail if the argument is not a "file://" URL.
120 * This is occasionally the case in circumstances yet to be characterized. 153 * This is occasionally the case in circumstances yet to be characterized.
(...skipping 20 matching lines...) Expand all
141 return false; 174 return false;
142 } 175 }
143 auto urlCstr = url.c_str(); 176 auto urlCstr = url.c_str();
144 // Check the prefix to match our directory 177 // Check the prefix to match our directory
145 // Check the suffix to be an HTML file 178 // Check the suffix to be an HTML file
146 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) && 179 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) &&
147 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0); 180 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0);
148 } 181 }
149 } 182 }
150 183
151 void CPluginTabBase::InjectABP(IWebBrowser2* browser) 184 void CPluginTab::InjectABP(IWebBrowser2* browser)
152 { 185 {
153 CriticalSection::Lock lock(m_csInject); 186 CriticalSection::Lock lock(m_csInject);
154 auto url = GetDocumentUrl(); 187 auto url = GetDocumentUrl();
155 if (!IsOurHtmlFile(url)) 188 if (!IsOurHtmlFile(url))
156 { 189 {
157 DEBUG_GENERAL(L"InjectABP. Not injecting"); 190 DEBUG_GENERAL(L"InjectABP. Not injecting");
158 return; 191 return;
159 } 192 }
160 DEBUG_GENERAL(L"InjectABP. Injecting"); 193 DEBUG_GENERAL(L"InjectABP. Injecting");
161 CComPtr<IDispatch> pDocDispatch; 194 CComPtr<IDispatch> pDocDispatch;
162 browser->get_Document(&pDocDispatch); 195 browser->get_Document(&pDocDispatch);
163 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch; 196 CComQIPtr<IHTMLDocument2> pDoc2(pDocDispatch);
164 if (!pDoc2) 197 if (!pDoc2)
165 { 198 {
166 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI docume nt"); 199 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTab::InjectABP - Failed to QI document") ;
167 return; 200 return;
168 } 201 }
169
170 CComPtr<IHTMLWindow2> pWnd2; 202 CComPtr<IHTMLWindow2> pWnd2;
171 pDoc2->get_parentWindow(&pWnd2); 203 pDoc2->get_parentWindow(&pWnd2);
172 if (!pWnd2) 204 if (!pWnd2)
173 { 205 {
174 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to get paren t window"); 206 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTab::InjectABP - Failed to get parent wi ndow");
175 return; 207 return;
176 } 208 }
177 CComQIPtr<IDispatchEx> pWndEx = pWnd2; 209 CComQIPtr<IDispatchEx> pWndEx(pWnd2);
178 if (!pWndEx) 210 if (!pWndEx)
179 { 211 {
180 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI dispat ch"); 212 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTab::InjectABP - Failed to QI dispatch") ;
181 return; 213 return;
182 } 214 }
183 // Create "Settings" object in JavaScript. 215 // Create "Settings" object in JavaScript.
184 // A method call of "Settings" in JavaScript, transfered to "Invoke" of m_plug inUserSettings 216 // A method call of "Settings" in JavaScript, transfered to "Invoke" of m_plug inUserSettings
185 DISPID dispid; 217 DISPID dispid;
186 HRESULT hr = pWndEx->GetDispID(L"Settings", fdexNameEnsure, &dispid); 218 HRESULT hr = pWndEx->GetDispID(L"Settings", fdexNameEnsure, &dispid);
187 if (FAILED(hr)) 219 if (FAILED(hr))
188 { 220 {
189 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CR EATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to get disp atch"); 221 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CR EATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTab::InjectABP - Failed to get dispatch ");
190 return; 222 return;
191 } 223 }
192 CComVariant var((IDispatch*)&m_pluginUserSettings); 224 CComVariant var((IDispatch*)&m_pluginUserSettings);
193 225
194 DEBUG_GENERAL("Injecting"); 226 DEBUG_GENERAL("Injecting");
195 227
196 DISPPARAMS params; 228 DISPPARAMS params;
197 params.cArgs = 1; 229 params.cArgs = 1;
198 params.cNamedArgs = 0; 230 params.cNamedArgs = 0;
199 params.rgvarg = &var; 231 params.rgvarg = &var;
200 params.rgdispidNamedArgs = 0; 232 params.rgdispidNamedArgs = 0;
201 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0); 233 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0);
202 DEBUG_GENERAL("Invoke"); 234 DEBUG_GENERAL("Invoke");
203 if (FAILED(hr)) 235 if (FAILED(hr))
204 { 236 {
205 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CR EATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to create S ettings in JavaScript"); 237 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CR EATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTab::InjectABP - Failed to create Setti ngs in JavaScript");
206 } 238 }
207 } 239 }
208 240
209 bool CPluginTabBase::IsTraverserEnabled() 241 bool CPluginTab::IsTraverserEnabled()
210 { 242 {
211 return !IsCSSInjectionEnabled(); 243 return !IsCSSInjectionEnabled();
212 } 244 }
213 245
214 bool CPluginTabBase::IsCSSInjectionEnabled() 246 bool CPluginTab::IsCSSInjectionEnabled()
215 { 247 {
216 return IsWindowsVistaOrLater() && AdblockPlus::IE::InstalledMajorVersion() >= 10; 248 return IsWindowsVistaOrLater() && AdblockPlus::IE::InstalledMajorVersion() >= 10;
217 } 249 }
218 250
219 namespace 251 namespace
220 { 252 {
221 void InjectABPCSS(IHTMLDocument2& htmlDocument2, const std::vector<std::wstrin g>& hideFilters) 253 void InjectABPCSS(IHTMLDocument2& htmlDocument2, const std::vector<std::wstrin g>& hideFilters)
222 { 254 {
223 // pseudocode: styleHtmlElement = htmlDocument2.createElement("style"); 255 // pseudocode: styleHtmlElement = htmlDocument2.createElement("style");
224 ATL::CComQIPtr<IHTMLStyleElement> styleHtmlElement; 256 ATL::CComQIPtr<IHTMLStyleElement> styleHtmlElement;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 while(frame = GetParent(*frame)) 390 while(frame = GetParent(*frame))
359 { 391 {
360 frameHierarchy.push_back(ToUtf8String(GetLocationUrl(*frame))); 392 frameHierarchy.push_back(ToUtf8String(GetLocationUrl(*frame)));
361 } 393 }
362 CPluginClient* client = CPluginClient::GetInstance(); 394 CPluginClient* client = CPluginClient::GetInstance();
363 return client->IsWhitelistedUrl(url, frameHierarchy) 395 return client->IsWhitelistedUrl(url, frameHierarchy)
364 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy); 396 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy);
365 } 397 }
366 } 398 }
367 399
368 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) 400 void CPluginTab::OnDownloadComplete(IWebBrowser2* browser)
369 { 401 {
370 if (IsTraverserEnabled()) 402 if (IsTraverserEnabled())
371 { 403 {
372 CPluginClient* client = CPluginClient::GetInstance(); 404 CPluginClient* client = CPluginClient::GetInstance();
373 std::wstring url = GetDocumentUrl(); 405 std::wstring url = GetDocumentUrl();
374 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain (url)) 406 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain (url))
375 { 407 {
376 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl ()); 408 if (!m_traverser)
409 {
410 assert(m_asyncPluginFilter && "Filter initialization should be already a t least started");
411 if (m_asyncPluginFilter)
412 {
413 auto pluginFilter = m_asyncPluginFilter->GetFilter();
414 assert(pluginFilter && "Plugin filter should be a valid object");
415 if (pluginFilter)
416 m_traverser.reset(new CPluginDomTraverser(pluginFilter));
417 }
418 }
419 assert(m_traverser && "Traverser should be a valid object");
420 if (m_traverser)
421 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentU rl());
377 } 422 }
378 } 423 }
379 InjectABP(browser); 424 InjectABP(browser);
380 } 425 }
381 426
382 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const std::wstrin g& url, bool isDocumentBrowser) 427 void CPluginTab::OnDocumentComplete(IWebBrowser2* browser, const std::wstring& u rl, bool isDocumentBrowser)
383 { 428 {
384 std::wstring documentUrl = GetDocumentUrl(); 429 std::wstring documentUrl = GetDocumentUrl();
385 430
386 if (isDocumentBrowser) 431 if (isDocumentBrowser)
387 { 432 {
388 if (url != documentUrl) 433 if (url != documentUrl)
389 { 434 {
390 SetDocumentUrl(url); 435 SetDocumentUrl(url);
391 } 436 }
392 InjectABP(browser); 437 InjectABP(browser);
393 } 438 }
394 CString urlLegacy = ToCString(url); 439 if (BeginsWith(url, L"res://"))
395 if (urlLegacy.Left(6) == "res://")
396 { 440 {
397 return; 441 return;
398 } 442 }
399 // Get document 443 // Get document
400 CComPtr<IDispatch> pDocDispatch; 444 CComPtr<IDispatch> pDocDispatch;
401 HRESULT hr = browser->get_Document(&pDocDispatch); 445 HRESULT hr = browser->get_Document(&pDocDispatch);
402 if (FAILED(hr) || !pDocDispatch) 446 if (FAILED(hr) || !pDocDispatch)
403 { 447 {
404 return; 448 return;
405 } 449 }
406 450
407 CComQIPtr<IHTMLDocument2> pDoc = pDocDispatch; 451 CComQIPtr<IHTMLDocument2> pDoc(pDocDispatch);
408 if (!pDoc) 452 if (!pDoc)
409 { 453 {
410 return; 454 return;
411 } 455 }
412 456
413 if (IsCSSInjectionEnabled() && CPluginSettings::GetInstance()->GetPluginEnable d()) 457 if (IsCSSInjectionEnabled() && CPluginSettings::GetInstance()->GetPluginEnable d())
414 { 458 {
415 if (!IsFrameWhiteListed(browser)) 459 if (!IsFrameWhiteListed(browser))
416 { 460 {
417 DEBUG_GENERAL(L"Inject CSS into " + url); 461 DEBUG_GENERAL(L"Inject CSS into " + url);
418 InjectABPCSS(*pDoc, m_filter->GetHideFilters()); 462 assert(m_asyncPluginFilter && "Filter initialization should be already at least started");
463 if (m_asyncPluginFilter)
464 {
465 auto pluginFilter = m_asyncPluginFilter->GetFilter();
466 assert(pluginFilter && "Plugin filter should be a valid object");
467 if (pluginFilter)
468 {
469 InjectABPCSS(*pDoc, pluginFilter->GetHideFilters());
470 }
471 }
419 } 472 }
420 } 473 }
421 474
422 CComPtr<IOleObject> pOleObj; 475 CComPtr<IOleObject> pOleObj;
423 pDocDispatch->QueryInterface(IID_IOleObject, (void**)&pOleObj); 476 pDocDispatch->QueryInterface(&pOleObj);
424 477 if (!pOleObj)
478 {
479 return;
480 }
425 CComPtr<IOleClientSite> pClientSite; 481 CComPtr<IOleClientSite> pClientSite;
426 pOleObj->GetClientSite(&pClientSite); 482 pOleObj->GetClientSite(&pClientSite);
427 if (pClientSite != NULL) 483 if (pClientSite != NULL)
428 { 484 {
429 CComPtr<IDocHostUIHandler> docHostUIHandler; 485 CComPtr<IDocHostUIHandler> docHostUIHandler;
430 pClientSite->QueryInterface(IID_IDocHostUIHandler, (void**)&docHostUIHandler ); 486 pClientSite->QueryInterface(&docHostUIHandler);
431 if (docHostUIHandler != NULL) 487 if (docHostUIHandler != NULL)
432 { 488 {
433 docHostUIHandler->UpdateUI(); 489 docHostUIHandler->UpdateUI();
434 } 490 }
435 } 491 }
436 } 492 }
437 493
438 std::wstring CPluginTabBase::GetDocumentDomain() 494 std::wstring CPluginTab::GetDocumentDomain()
439 { 495 {
440 std::wstring domain; 496 std::wstring domain;
441 497
442 m_criticalSection.Lock(); 498 m_criticalSection.Lock();
443 { 499 {
444 domain = m_documentDomain; 500 domain = m_documentDomain;
445 } 501 }
446 m_criticalSection.Unlock(); 502 m_criticalSection.Unlock();
447 503
448 return domain; 504 return domain;
449 } 505 }
450 506
451 void CPluginTabBase::SetDocumentUrl(const std::wstring& url) 507 void CPluginTab::SetDocumentUrl(const std::wstring& url)
452 { 508 {
453 m_criticalSection.Lock(); 509 m_criticalSection.Lock();
454 { 510 {
455 m_documentUrl = url; 511 m_documentUrl = url;
456 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(url); 512 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(url);
457 } 513 }
458 m_criticalSection.Unlock(); 514 m_criticalSection.Unlock();
459 } 515 }
460 516
461 std::wstring CPluginTabBase::GetDocumentUrl() 517 std::wstring CPluginTab::GetDocumentUrl()
462 { 518 {
463 std::wstring url; 519 std::wstring url;
464 520
465 m_criticalSection.Lock(); 521 m_criticalSection.Lock();
466 { 522 {
467 url = m_documentUrl; 523 url = m_documentUrl;
468 } 524 }
469 m_criticalSection.Unlock(); 525 m_criticalSection.Unlock();
470 526
471 return url; 527 return url;
472 } 528 }
473 529
474 530
475 // ============================================================================ 531 // ============================================================================
476 // Frame caching 532 // Frame caching
477 // ============================================================================ 533 // ============================================================================
478 bool CPluginTabBase::IsFrameCached(const std::wstring& url) 534 bool CPluginTab::IsFrameCached(const std::wstring& url)
479 { 535 {
480 bool isFrame; 536 bool isFrame;
481 537
482 m_criticalSectionCache.Lock(); 538 m_criticalSectionCache.Lock();
483 { 539 {
484 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); 540 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end();
485 } 541 }
486 m_criticalSectionCache.Unlock(); 542 m_criticalSectionCache.Unlock();
487 543
488 return isFrame; 544 return isFrame;
489 } 545 }
490 546
491 void CPluginTabBase::CacheFrame(const std::wstring& url) 547 void CPluginTab::CacheFrame(const std::wstring& url)
492 { 548 {
493 m_criticalSectionCache.Lock(); 549 m_criticalSectionCache.Lock();
494 { 550 {
495 m_cacheFrames.insert(url); 551 m_cacheFrames.insert(url);
496 } 552 }
497 m_criticalSectionCache.Unlock(); 553 m_criticalSectionCache.Unlock();
498 } 554 }
499 555
500 void CPluginTabBase::ClearFrameCache(const std::wstring& domain) 556 void CPluginTab::ClearFrameCache(const std::wstring& domain)
501 { 557 {
502 m_criticalSectionCache.Lock(); 558 m_criticalSectionCache.Lock();
503 { 559 {
504 if (domain.empty() || domain != m_cacheDomain) 560 if (domain.empty() || domain != m_cacheDomain)
505 { 561 {
506 m_cacheFrames.clear(); 562 m_cacheFrames.clear();
507 m_cacheDomain = domain; 563 m_cacheDomain = domain;
508 } 564 }
509 } 565 }
510 m_criticalSectionCache.Unlock(); 566 m_criticalSectionCache.Unlock();
511 } 567 }
512 568
513 void CPluginTabBase::ThreadProc() 569 void CPluginTab::ThreadProc()
514 { 570 {
515 // Force loading/creation of settings 571 // Force loading/creation of settings
516 CPluginSettings::GetInstance()->SetWorkingThreadId(); 572 CPluginSettings::GetInstance();
517 573
518 std::string message = 574 std::string message =
519 "=========================================================================== =====\n" 575 "=========================================================================== =====\n"
520 "TAB THREAD process="; 576 "TAB THREAD process=";
521 message += std::to_string(::GetCurrentProcessId()); 577 message += std::to_string(::GetCurrentProcessId());
522 message + " thread="; 578 message + " thread=";
523 message += std::to_string(::GetCurrentThreadId()); 579 message += std::to_string(::GetCurrentThreadId());
524 message += 580 message +=
525 "\n" 581 "\n"
526 "=========================================================================== ====="; 582 "=========================================================================== =====";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId()); 615 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
560 } 616 }
561 617
562 // Non-hanging sleep 618 // Non-hanging sleep
563 Sleep(50); 619 Sleep(50);
564 } 620 }
565 621
566 tabLoopIteration++; 622 tabLoopIteration++;
567 } 623 }
568 } 624 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld