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-2016 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 |
(...skipping 11 matching lines...) Expand all Loading... |
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 <Mshtmhst.h> | 26 #include <Mshtmhst.h> |
27 | 27 |
28 CPluginTab::CPluginTab() | 28 CPluginTab::CPluginTab() |
29 : m_isActivated(false) | 29 : m_isActivated(false) |
30 , m_continueThreadRunning(true) | 30 , m_continueThreadRunning(true) |
31 { | 31 { |
32 m_filter.hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); | |
33 | |
34 CPluginClient* client = CPluginClient::GetInstance(); | 32 CPluginClient* client = CPluginClient::GetInstance(); |
35 if (AdblockPlus::IE::InstalledMajorVersion() < 10) | 33 if (AdblockPlus::IE::InstalledMajorVersion() < 10) |
36 { | 34 { |
37 m_isActivated = true; | 35 m_isActivated = true; |
38 } | 36 } |
39 | 37 |
40 try | 38 try |
41 { | 39 { |
42 m_thread = std::thread(&CPluginTab::ThreadProc, this); | 40 m_thread = std::thread(&CPluginTab::ThreadProc, this); |
43 } | 41 } |
(...skipping 28 matching lines...) Expand all Loading... |
72 { | 70 { |
73 m_isActivated = true; | 71 m_isActivated = true; |
74 } | 72 } |
75 | 73 |
76 | 74 |
77 void CPluginTab::OnUpdate() | 75 void CPluginTab::OnUpdate() |
78 { | 76 { |
79 m_isActivated = true; | 77 m_isActivated = true; |
80 } | 78 } |
81 | 79 |
82 namespace | |
83 { | |
84 // Entry Point | |
85 void FilterLoader(CPluginFilter* filter, const std::wstring& domain) | |
86 { | |
87 try | |
88 { | |
89 filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementHidingSele
ctors(domain)); | |
90 SetEvent(filter->hideFiltersLoadedEvent); | |
91 } | |
92 catch (...) | |
93 { | |
94 // As a thread-main function, we truncate any C++ exception. | |
95 } | |
96 } | |
97 } | |
98 | |
99 void CPluginTab::OnNavigate(const std::wstring& url) | 80 void CPluginTab::OnNavigate(const std::wstring& url) |
100 { | 81 { |
101 SetDocumentUrl(url); | 82 SetDocumentUrl(url); |
102 ClearFrameCache(GetDocumentDomain()); | 83 } |
103 std::wstring domainString = GetDocumentDomain(); | 84 |
104 ResetEvent(m_filter.hideFiltersLoadedEvent); | 85 void CPluginTab::OnDownloadBegin() |
105 try | 86 { |
| 87 std::wstring domain = GetDocumentDomain(); |
| 88 ClearFrameCache(domain); |
| 89 if (!filter) |
106 { | 90 { |
107 std::thread filterLoaderThread(&FilterLoader, &m_filter, GetDocumentDomain()
); | 91 try |
108 filterLoaderThread.detach(); // TODO: but actually we should wait for the th
read in the dtr. | 92 { |
| 93 filter.reset(new CPluginFilter(domain)); |
| 94 } |
| 95 catch (const std::exception& e) |
| 96 { |
| 97 DEBUG_EXCEPTION(e); |
| 98 } |
109 } | 99 } |
110 catch (const std::system_error& ex) | 100 else |
111 { | 101 { |
112 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CRE
ATE_PROCESS, | 102 DEBUG_GENERAL("Suspicious: Reached CPluginTab::OnDownloadBegin with a non-nu
ll filter") |
113 "Class::Thread - Failed to start filter loader thread"); | |
114 } | 103 } |
115 } | 104 } |
116 | 105 |
117 namespace | 106 namespace |
118 { | 107 { |
119 /** | 108 /** |
120 * Determine if the HTML file is one of ours. | 109 * Determine if the HTML file is one of ours. |
121 * The criterion is that it appear in the "html/templates" folder within our i
nstallation. | 110 * The criterion is that it appear in the "html/templates" folder within our i
nstallation. |
122 * | 111 * |
123 * Warning: This function may fail if the argument is not a "file://" URL. | 112 * Warning: This function may fail if the argument is not a "file://" URL. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy); | 243 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy); |
255 } | 244 } |
256 } | 245 } |
257 | 246 |
258 void CPluginTab::OnDownloadComplete(IWebBrowser2* browser) | 247 void CPluginTab::OnDownloadComplete(IWebBrowser2* browser) |
259 { | 248 { |
260 CPluginClient* client = CPluginClient::GetInstance(); | 249 CPluginClient* client = CPluginClient::GetInstance(); |
261 std::wstring url = GetDocumentUrl(); | 250 std::wstring url = GetDocumentUrl(); |
262 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u
rl)) | 251 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u
rl)) |
263 { | 252 { |
264 CPluginDomTraverser traversal(&m_filter); | 253 CPluginFilter* f = filter.get(); |
265 traversal.TraverseDocumentRoot(browser, GetDocumentDomain(), GetDocumentUrl(
)); | 254 if (f) |
| 255 { |
| 256 f->EnsureInitialized(); |
| 257 CPluginDomTraverser traversal(f); |
| 258 traversal.TraverseDocumentRoot(browser, GetDocumentDomain(), GetDocumentUr
l()); |
| 259 } |
266 } | 260 } |
| 261 filter.reset(); |
267 InjectABP(browser); | 262 InjectABP(browser); |
268 } | 263 } |
269 | 264 |
270 void CPluginTab::OnDocumentComplete(IWebBrowser2* browser, const std::wstring& u
rl, bool isDocumentBrowser) | 265 void CPluginTab::OnDocumentComplete(IWebBrowser2* browser, const std::wstring& u
rl, bool isDocumentBrowser) |
271 { | 266 { |
272 std::wstring documentUrl = GetDocumentUrl(); | 267 std::wstring documentUrl = GetDocumentUrl(); |
273 | 268 |
274 if (isDocumentBrowser) | 269 if (isDocumentBrowser) |
275 { | 270 { |
276 if (url != documentUrl) | 271 if (url != documentUrl) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr
rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p
luginError.GetProcessId(), pluginError.GetThreadId()); | 435 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr
rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p
luginError.GetProcessId(), pluginError.GetThreadId()); |
441 } | 436 } |
442 | 437 |
443 // Non-hanging sleep | 438 // Non-hanging sleep |
444 Sleep(50); | 439 Sleep(50); |
445 } | 440 } |
446 | 441 |
447 tabLoopIteration++; | 442 tabLoopIteration++; |
448 } | 443 } |
449 } | 444 } |
OLD | NEW |