Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2015 Eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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/>. | |
16 */ | |
17 | |
1 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
2 | 19 #include "AdblockPlusClient.h" |
3 #include "PluginClient.h" | 20 #include "PluginClientBase.h" |
4 #include "PluginSettings.h" | 21 #include "PluginSettings.h" |
5 #include "PluginTab.h" | |
6 #include "AdblockPlusDomTraverser.h" | 22 #include "AdblockPlusDomTraverser.h" |
7 #include "PluginClass.h" | |
8 #include "PluginTabBase.h" | 23 #include "PluginTabBase.h" |
9 #include "PluginUtil.h" | 24 #include "IeVersion.h" |
10 #include "../shared/IE_version.h" | |
11 #include "../shared/Utils.h" | 25 #include "../shared/Utils.h" |
12 #include <dispex.h> | |
13 #include <Mshtmhst.h> | 26 #include <Mshtmhst.h> |
14 | |
15 int CPluginTabBase::s_dictionaryVersion = 0; | |
16 int CPluginTabBase::s_settingsVersion = 1; | |
17 int CPluginTabBase::s_filterVersion = 0; | |
18 int CPluginTabBase::s_whitelistVersion = 0; | |
19 | 27 |
20 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) | 28 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) |
21 : m_plugin(plugin) | 29 : m_plugin(plugin) |
22 , m_isActivated(false) | 30 , m_isActivated(false) |
23 , m_continueThreadRunning(true) | 31 , m_continueThreadRunning(true) |
24 { | 32 { |
25 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); | 33 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); |
26 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); | 34 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); |
27 | 35 |
28 CPluginClient* client = CPluginClient::GetInstance(); | 36 CPluginClient* client = CPluginClient::GetInstance(); |
29 if (AdblockPlus::IE::InstalledMajorVersion() < 10) | 37 if (AdblockPlus::IE::InstalledMajorVersion() < 10) |
30 { | 38 { |
31 m_isActivated = true; | 39 m_isActivated = true; |
32 } | 40 } |
33 | 41 |
34 try | 42 try |
35 { | 43 { |
36 m_thread = std::thread(&CPluginTabBase::ThreadProc, this); | 44 m_thread = std::thread(&CPluginTabBase::ThreadProc, this); |
37 } | 45 } |
38 catch (const std::system_error& ex) | 46 catch (const std::system_error& ex) |
39 { | 47 { |
40 auto errDescription = std::string("Tab::Thread - Failed to create tab thread ") + | 48 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THREAD_CREA TE_PROCESS, |
41 ex.code().message() + ex.what(); | 49 "Tab::Thread - Failed to create tab thread"); |
42 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THR EAD_CREATE_PROCESS, errDescription.c_str()); | |
43 } | 50 } |
44 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this)); | 51 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this)); |
45 } | 52 } |
46 | 53 |
47 | 54 |
48 CPluginTabBase::~CPluginTabBase() | 55 CPluginTabBase::~CPluginTabBase() |
49 { | 56 { |
50 delete m_traverser; | 57 delete m_traverser; |
51 m_traverser = NULL; | 58 m_traverser = NULL; |
52 m_continueThreadRunning = false; | 59 m_continueThreadRunning = false; |
53 if (m_thread.joinable()) { | 60 if (m_thread.joinable()) { |
54 m_thread.join(); | 61 m_thread.join(); |
55 } | 62 } |
56 } | 63 } |
57 | 64 |
58 void CPluginTabBase::OnActivate() | 65 void CPluginTabBase::OnActivate() |
59 { | 66 { |
60 m_isActivated = true; | 67 m_isActivated = true; |
61 } | 68 } |
62 | 69 |
63 | 70 |
64 void CPluginTabBase::OnUpdate() | 71 void CPluginTabBase::OnUpdate() |
65 { | 72 { |
66 m_isActivated = true; | 73 m_isActivated = true; |
67 } | 74 } |
68 | 75 |
69 namespace | 76 namespace |
70 { | 77 { |
78 // Entry Point | |
71 void FilterLoader(CPluginTabBase* tabBase) | 79 void FilterLoader(CPluginTabBase* tabBase) |
72 { | 80 { |
73 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementH idingSelectors(tabBase->GetDocumentDomain())); | 81 try |
74 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent); | 82 { |
75 } | 83 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElemen tHidingSelectors(tabBase->GetDocumentDomain())); |
76 } | 84 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent); |
77 | 85 } |
78 void CPluginTabBase::OnNavigate(const CString& url) | 86 catch (...) |
87 { | |
88 // As a thread-main function, we truncate any C++ exception. | |
89 } | |
90 } | |
91 } | |
92 | |
93 void CPluginTabBase::OnNavigate(const std::wstring& url) | |
79 { | 94 { |
80 SetDocumentUrl(url); | 95 SetDocumentUrl(url); |
81 ClearFrameCache(GetDocumentDomain()); | 96 ClearFrameCache(GetDocumentDomain()); |
82 std::wstring domainString = GetDocumentDomain(); | 97 std::wstring domainString = GetDocumentDomain(); |
83 ResetEvent(m_filter->hideFiltersLoadedEvent); | 98 ResetEvent(m_filter->hideFiltersLoadedEvent); |
84 try | 99 try |
85 { | 100 { |
86 std::thread filterLoaderThread(&FilterLoader, this); | 101 std::thread filterLoaderThread(&FilterLoader, this); |
87 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr. | 102 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr. |
88 } | 103 } |
89 catch (const std::system_error& ex) | 104 catch (const std::system_error& ex) |
90 { | 105 { |
91 auto errDescription = std::string("Class::Thread - Failed to start filter lo ader thread, ") + | 106 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CRE ATE_PROCESS, |
92 ex.code().message() + ex.what(); | 107 "Class::Thread - Failed to start filter loader thread"); |
93 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, errDescription.c_str()); | |
94 } | 108 } |
95 m_traverser->ClearCache(); | 109 m_traverser->ClearCache(); |
96 } | 110 } |
97 | 111 |
112 namespace | |
113 { | |
114 /** | |
115 * Determine if the HTML file is one of ours. | |
116 * The criterion is that it appear in the "html/templates" folder within our i nstallation. | |
117 * | |
118 * Warning: This function may fail if the argument is not a "file://" URL. | |
119 * This is occasionally the case in circumstances yet to be characterized. | |
120 */ | |
121 bool IsOurHtmlFile(const std::wstring& url) | |
122 { | |
123 // Declared static because the value is derived from an installation directo ry, which won't change during run-time. | |
124 static auto dir = FileUrl(HtmlFolderPath()); | |
125 | |
126 DEBUG_GENERAL([&]() -> std::wstring { | |
127 std::wstring log = L"InjectABP. Current URL: "; | |
128 log += url; | |
129 log += L", template directory URL: "; | |
130 log += dir; | |
131 return log; | |
132 }()); | |
133 | |
134 /* | |
135 * The length check here is defensive, in case the document URL is truncated for some reason. | |
136 */ | |
137 if (url.length() < 5) | |
138 { | |
139 // We can't match ".html" at the end of the URL if it's too short. | |
140 return false; | |
141 } | |
142 auto urlCstr = url.c_str(); | |
143 // Check the prefix to match our directory | |
144 // Check the suffix to be an HTML file | |
145 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) && | |
146 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0); | |
147 } | |
148 } | |
149 | |
98 void CPluginTabBase::InjectABP(IWebBrowser2* browser) | 150 void CPluginTabBase::InjectABP(IWebBrowser2* browser) |
99 { | 151 { |
100 CriticalSection::Lock lock(m_csInject); | 152 CriticalSection::Lock lock(m_csInject); |
101 CString url = GetDocumentUrl(); | 153 auto url = GetDocumentUrl(); |
102 CString log; | 154 if (!IsOurHtmlFile(url)) |
103 log.Format(L"InjectABP. Current URL: %s, settings URL: %s", url, UserSettingsF ileUrl().c_str()); | 155 { |
104 DEBUG_GENERAL(log); | 156 DEBUG_GENERAL(L"InjectABP. Not injecting"); |
105 if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) || | |
106 0 == url.CompareNoCase(CString(FirstRunPageFileUrl().c_str())))) | |
107 { | |
108 DEBUG_GENERAL(L"Not injecting"); | |
109 return; | 157 return; |
110 } | 158 } |
111 DEBUG_GENERAL(L"Going to inject"); | 159 DEBUG_GENERAL(L"InjectABP. Injecting"); |
112 CComPtr<IDispatch> pDocDispatch; | 160 CComPtr<IDispatch> pDocDispatch; |
113 browser->get_Document(&pDocDispatch); | 161 browser->get_Document(&pDocDispatch); |
114 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch; | 162 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch; |
115 if (!pDoc2) | 163 if (!pDoc2) |
116 { | 164 { |
117 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI docume nt"); | 165 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI docume nt"); |
118 return; | 166 return; |
119 } | 167 } |
120 | |
121 CComPtr<IHTMLWindow2> pWnd2; | 168 CComPtr<IHTMLWindow2> pWnd2; |
122 pDoc2->get_parentWindow(&pWnd2); | 169 pDoc2->get_parentWindow(&pWnd2); |
123 if (!pWnd2) | 170 if (!pWnd2) |
124 { | 171 { |
125 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to get paren t window"); | 172 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to get paren t window"); |
126 return; | 173 return; |
127 } | 174 } |
128 CComQIPtr<IDispatchEx> pWndEx = pWnd2; | 175 CComQIPtr<IDispatchEx> pWndEx = pWnd2; |
129 if (!pWndEx) | 176 if (!pWndEx) |
130 { | 177 { |
(...skipping 21 matching lines...) Expand all Loading... | |
152 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, ¶ms, 0, 0, 0); | 199 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, ¶ms, 0, 0, 0); |
153 DEBUG_GENERAL("Invoke"); | 200 DEBUG_GENERAL("Invoke"); |
154 if (FAILED(hr)) | 201 if (FAILED(hr)) |
155 { | 202 { |
156 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"); | 203 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"); |
157 } | 204 } |
158 } | 205 } |
159 | 206 |
160 namespace | 207 namespace |
161 { | 208 { |
162 void InjectABPCSS(IHTMLDocument2& htmlDocument2, const std::vector<std::wstrin g>& hideFilters) | 209 ATL::CComPtr<IWebBrowser2> GetParent(IWebBrowser2& browser) |
Eric
2015/01/13 19:52:52
We're not distinguishing between fatal errors and
Oleksandr
2015/03/13 10:00:27
On 2015/01/13 19:52:52, Eric wrote:
What's not cor
sergei
2015/04/13 08:06:41
I agree this function should not be in this code r
| |
163 { | 210 { |
164 ATL::CComPtr<IHTMLElement> stylePureHtmlElement; | 211 ATL::CComPtr<IDispatch> parentDispatch; |
165 ATL::CComQIPtr<IHTMLStyleElement> styleHtmlElement; | 212 if (FAILED(browser.get_Parent(&parentDispatch)) || !parentDispatch) |
166 if (FAILED(htmlDocument2.createElement(ATL::CComBSTR(L"style"), &stylePureHt mlElement))) | 213 { |
167 { | 214 return nullptr; |
168 DEBUG_GENERAL(L"Cannot create style element"); | 215 } |
169 return; | 216 // The InternetExplorer application always returns a pointer to itself. |
170 } | 217 // https://msdn.microsoft.com/en-us/library/aa752136(v=vs.85).aspx |
171 if (!(styleHtmlElement = stylePureHtmlElement)) | 218 if (parentDispatch.IsEqualObject(&browser)) |
172 { | 219 { |
173 DEBUG_GENERAL(L"Cannot obtain IHTMLStyleElement from IHTMLElement"); | 220 return nullptr; |
174 return; | 221 } |
175 } | 222 ATL::CComQIPtr<IServiceProvider> parentDocumentServiceProvider = parentDispa tch; |
176 if (FAILED(styleHtmlElement->put_type(ATL::CComBSTR("text/css")))) | 223 if (!parentDocumentServiceProvider) |
177 { | 224 { |
178 DEBUG_GENERAL(L"Cannot set type text/css"); | 225 return nullptr; |
179 return; | 226 } |
180 } | 227 ATL::CComPtr<IWebBrowser2> parentBrowser; |
181 ATL::CComQIPtr<IHTMLStyleSheet> styleSheet; | 228 if (FAILED(parentDocumentServiceProvider->QueryService(SID_SWebBrowserApp, & parentBrowser))) |
182 // IHTMLStyleElement2 is availabe starting from IE9, Vista | 229 { |
183 ATL::CComQIPtr<IHTMLStyleElement2> styleHtmlElement2 = styleHtmlElement; | 230 return nullptr; |
184 if (!styleHtmlElement2) | 231 } |
185 { | 232 return parentBrowser; |
186 DEBUG_GENERAL(L"Cannot obtain IHTMLStyleElement2 from IHTMLStyleElement"); | 233 } |
187 return; | 234 |
188 } | 235 bool IsFrameWhiteListed(ATL::CComPtr<IWebBrowser2> frame) |
189 if (FAILED(styleHtmlElement2->get_sheet(&styleSheet)) || !styleSheet) | 236 { |
190 { | 237 if (!frame) |
191 DEBUG_GENERAL(L"Cannot obtain IHTMLStyleSheet"); | 238 { |
192 return; | 239 return false; |
193 } | 240 } |
194 // IHTMLStyleSheet4 is availabe starting from IE9, Vista | 241 auto url = GetLocationUrl(*frame); |
195 ATL::CComQIPtr<IHTMLStyleSheet4> styleSheet4 = styleSheet; | 242 std::vector<std::string> frameHierarchy; |
196 if (!styleSheet4) | 243 while(frame = GetParent(*frame)) |
197 { | 244 { |
198 DEBUG_GENERAL(L"Cannot obtain IHTMLStyleSheet4"); | 245 frameHierarchy.push_back(ToUtf8String(GetLocationUrl(*frame))); |
199 return; | 246 } |
200 } | 247 CPluginClient* client = CPluginClient::GetInstance(); |
201 long newIndex = 0; | 248 return client->IsWhitelistedUrl(url, frameHierarchy) |
202 std::wstring cssValue = L"{ display: none !important; }"; | 249 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy); |
203 for (const auto& selector : hideFilters) | |
204 { | |
205 auto cssRule = selector + cssValue; | |
206 ATL::CComBSTR selector(cssRule.size(), cssRule.c_str()); | |
207 if (SUCCEEDED(styleSheet4->insertRule(selector, newIndex, &newIndex))) | |
208 { | |
209 ++newIndex; | |
210 } | |
211 else | |
212 { | |
213 DEBUG_GENERAL(ToCString(L"Cannot add rule for selector " + cssRule)); | |
214 } | |
215 } | |
216 | |
217 ATL::CComQIPtr<IHTMLDOMNode> styleNode = stylePureHtmlElement; | |
218 if (!styleNode) | |
219 { | |
220 DEBUG_GENERAL(L"Cannot obtain IHTMLDOMNode from stylePureHtmlElement"); | |
221 return; | |
222 } | |
223 ATL::CComPtr<IHTMLElement> headHtmlElement; | |
224 // IHTMLDocument7 is availabe starting from IE9, Vista | |
225 ATL::CComQIPtr<IHTMLDocument7> htmlDocument7 = &htmlDocument2; | |
226 if (!htmlDocument7) | |
227 { | |
228 DEBUG_GENERAL(L"Cannot obtain IHTMLDocument7 from htmlDocument2"); | |
229 return; | |
230 } | |
231 if (FAILED(htmlDocument7->get_head(&headHtmlElement))) | |
232 { | |
233 DEBUG_GENERAL(L"Cannot obtain head from pDoc7"); | |
234 return; | |
235 } | |
236 ATL::CComQIPtr<IHTMLDOMNode> headNode = headHtmlElement; | |
237 if (!headNode) | |
238 { | |
239 DEBUG_GENERAL(L"Cannot obtain headNode from headHtmlElement"); | |
240 return; | |
241 } | |
242 if (FAILED(headNode->appendChild(styleNode, nullptr))) | |
243 { | |
244 DEBUG_GENERAL(L"Cannot append blocking style"); | |
245 } | |
246 } | 250 } |
247 } | 251 } |
248 | 252 |
249 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) | 253 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) |
250 { | 254 { |
251 CPluginClient* client = CPluginClient::GetInstance(); | 255 CPluginClient* client = CPluginClient::GetInstance(); |
252 std::wstring url = to_wstring(GetDocumentUrl()); | 256 std::wstring url = GetDocumentUrl(); |
253 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl)) | 257 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl)) |
254 { | 258 { |
255 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() ); | 259 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() ); |
256 } | 260 } |
257 InjectABP(browser); | 261 InjectABP(browser); |
258 } | 262 } |
259 | 263 |
260 ATL::CComPtr<IWebBrowser2> GetParent(const ATL::CComPtr<IWebBrowser2>& browser) | 264 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const std::wstrin g& url, bool isDocumentBrowser) |
Eric
2015/01/13 19:52:52
Since you're not copying the CComPtr and incurring
sergei
2015/04/13 08:06:41
fixed to use `IWebBrowser2&`.
| |
261 { | 265 { |
262 ATL::CComPtr<IWebBrowser2> retValue; | 266 std::wstring documentUrl = GetDocumentUrl(); |
263 ATL::CComPtr<IDispatch> browserParentDispatch; | |
264 if (FAILED(browser->get_Parent(&browserParentDispatch)) || !browserParentDispa tch) | |
265 { | |
266 return retValue; | |
Eric
2015/01/13 19:52:52
"return nullptr" is much clearer here.
sergei
2015/04/13 08:06:41
fixed
| |
267 } | |
268 // The InternetExplorer application always returns a pointer to itself. | |
269 if (browserParentDispatch.IsEqualObject(browser)) | |
270 { | |
271 return retValue; | |
Eric
2015/01/13 19:52:52
As before "return nullptr"
sergei
2015/04/13 08:06:41
fixed
| |
272 } | |
273 ATL::CComQIPtr<IServiceProvider> parentDocumentServiceProvider = browserParent Dispatch; | |
274 if (!parentDocumentServiceProvider) | |
275 { | |
276 return retValue; | |
Eric
2015/01/13 19:52:52
return nullptr
sergei
2015/04/13 08:06:41
fixed
| |
277 } | |
Eric
2015/01/13 19:52:52
This is the right place to declare 'retValue'.
As
sergei
2015/04/13 08:06:41
fixed
| |
278 if (FAILED(parentDocumentServiceProvider->QueryService(IID_IWebBrowserApp, &re tValue)) || !retValue) | |
Oleksandr
2015/03/13 10:00:27
Why is this querying for IWebBrowserApp and not IW
sergei
2015/04/13 08:06:41
fixed
| |
279 { | |
280 // error | |
Eric
2015/01/13 19:52:52
You've got to do something here, since a failed CO
Oleksandr
2015/03/13 10:00:27
return nullptr would be better IMO
sergei
2015/04/13 08:06:41
I don't think we should expect undefined state of
| |
281 } | |
282 return retValue; | |
283 } | |
284 | |
285 bool IsFrameWhiteListed(ATL::CComPtr<IWebBrowser2> frame) | |
286 { | |
287 if (!frame) | |
288 { | |
289 return false; | |
290 } | |
291 CPluginClient* client = CPluginClient::GetInstance(); | |
292 if (!client) | |
293 { | |
294 return false; | |
Eric
2015/01/13 19:52:52
This is really a pretty serious error.
Personally
| |
295 } | |
296 auto url = GetLocationUrl(*frame); | |
297 std::vector<std::string> frameHierarchy; | |
298 for(frame = GetParent(frame); frame; frame = GetParent(frame)) | |
299 { | |
300 frameHierarchy.push_back(ToUtf8String(GetLocationUrl(*frame))); | |
301 } | |
302 return client->IsWhitelistedUrl(url, frameHierarchy) | |
303 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy); | |
304 } | |
305 | |
306 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur l, bool isDocumentBrowser) | |
307 { | |
308 CString documentUrl = GetDocumentUrl(); | |
309 | 267 |
310 if (isDocumentBrowser) | 268 if (isDocumentBrowser) |
311 { | 269 { |
312 if (url != documentUrl) | 270 if (url != documentUrl) |
313 { | 271 { |
314 SetDocumentUrl(url); | 272 SetDocumentUrl(url); |
315 } | 273 } |
316 InjectABP(browser); | 274 InjectABP(browser); |
317 } | 275 } |
318 if (url.Left(6) != "res://") | 276 CString urlLegacy = ToCString(url); |
277 if (urlLegacy.Left(6) != "res://") | |
319 { | 278 { |
320 // Get document | 279 // Get document |
321 CComPtr<IDispatch> pDocDispatch; | 280 CComPtr<IDispatch> pDocDispatch; |
322 HRESULT hr = browser->get_Document(&pDocDispatch); | 281 HRESULT hr = browser->get_Document(&pDocDispatch); |
323 if (FAILED(hr) || !pDocDispatch) | 282 if (FAILED(hr) || !pDocDispatch) |
324 { | 283 { |
325 return; | 284 return; |
326 } | 285 } |
327 | 286 |
328 CComQIPtr<IHTMLDocument2> pDoc = pDocDispatch; | 287 CComQIPtr<IHTMLDocument2> pDoc = pDocDispatch; |
(...skipping 26 matching lines...) Expand all Loading... | |
355 | 314 |
356 m_criticalSection.Lock(); | 315 m_criticalSection.Lock(); |
357 { | 316 { |
358 domain = m_documentDomain; | 317 domain = m_documentDomain; |
359 } | 318 } |
360 m_criticalSection.Unlock(); | 319 m_criticalSection.Unlock(); |
361 | 320 |
362 return domain; | 321 return domain; |
363 } | 322 } |
364 | 323 |
365 void CPluginTabBase::SetDocumentUrl(const CString& url) | 324 void CPluginTabBase::SetDocumentUrl(const std::wstring& url) |
366 { | 325 { |
367 m_criticalSection.Lock(); | 326 m_criticalSection.Lock(); |
368 { | 327 { |
369 m_documentUrl = url; | 328 m_documentUrl = url; |
370 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(to_wstr ing(url)); | 329 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(url); |
371 } | 330 } |
372 m_criticalSection.Unlock(); | 331 m_criticalSection.Unlock(); |
373 } | 332 } |
374 | 333 |
375 CString CPluginTabBase::GetDocumentUrl() | 334 std::wstring CPluginTabBase::GetDocumentUrl() |
376 { | 335 { |
377 CString url; | 336 std::wstring url; |
378 | 337 |
379 m_criticalSection.Lock(); | 338 m_criticalSection.Lock(); |
380 { | 339 { |
381 url = m_documentUrl; | 340 url = m_documentUrl; |
382 } | 341 } |
383 m_criticalSection.Unlock(); | 342 m_criticalSection.Unlock(); |
384 | 343 |
385 return url; | 344 return url; |
386 } | 345 } |
387 | 346 |
388 | 347 |
389 // ============================================================================ | 348 // ============================================================================ |
390 // Frame caching | 349 // Frame caching |
391 // ============================================================================ | 350 // ============================================================================ |
392 bool CPluginTabBase::IsFrameCached(const CString& url) | 351 bool CPluginTabBase::IsFrameCached(const std::wstring& url) |
393 { | 352 { |
394 bool isFrame; | 353 bool isFrame; |
395 | 354 |
396 m_criticalSectionCache.Lock(); | 355 m_criticalSectionCache.Lock(); |
397 { | 356 { |
398 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); | 357 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); |
399 } | 358 } |
400 m_criticalSectionCache.Unlock(); | 359 m_criticalSectionCache.Unlock(); |
401 | 360 |
402 return isFrame; | 361 return isFrame; |
403 } | 362 } |
404 | 363 |
405 void CPluginTabBase::CacheFrame(const CString& url) | 364 void CPluginTabBase::CacheFrame(const std::wstring& url) |
406 { | 365 { |
407 m_criticalSectionCache.Lock(); | 366 m_criticalSectionCache.Lock(); |
408 { | 367 { |
409 m_cacheFrames.insert(url); | 368 m_cacheFrames.insert(url); |
410 } | 369 } |
411 m_criticalSectionCache.Unlock(); | 370 m_criticalSectionCache.Unlock(); |
412 } | 371 } |
413 | 372 |
414 void CPluginTabBase::ClearFrameCache(const std::wstring& domain) | 373 void CPluginTabBase::ClearFrameCache(const std::wstring& domain) |
415 { | 374 { |
416 m_criticalSectionCache.Lock(); | 375 m_criticalSectionCache.Lock(); |
417 { | 376 { |
418 if (domain.empty() || domain != m_cacheDomain) | 377 if (domain.empty() || domain != m_cacheDomain) |
419 { | 378 { |
420 m_cacheFrames.clear(); | 379 m_cacheFrames.clear(); |
421 m_cacheDomain = domain; | 380 m_cacheDomain = domain; |
422 } | 381 } |
423 } | 382 } |
424 m_criticalSectionCache.Unlock(); | 383 m_criticalSectionCache.Unlock(); |
425 } | 384 } |
426 | 385 |
427 void CPluginTabBase::ThreadProc() | 386 void CPluginTabBase::ThreadProc() |
428 { | 387 { |
429 // Force loading/creation of settings | 388 // Force loading/creation of settings |
430 CPluginSettings* settings = CPluginSettings::GetInstance(); | 389 CPluginSettings::GetInstance()->SetWorkingThreadId(); |
431 | 390 |
432 settings->SetWorkingThreadId(); | 391 std::string message = |
433 | 392 "=========================================================================== =====\n" |
434 CString threadInfo; | 393 "TAB THREAD process="; |
435 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId()); | 394 message += std::to_string(::GetCurrentProcessId()); |
436 | 395 message + " thread="; |
437 CString debugText; | 396 message += std::to_string(::GetCurrentThreadId()); |
438 | 397 message += |
439 debugText += L"=============================================================== ================="; | 398 "\n" |
440 debugText += L"\nTAB THREAD " + threadInfo; | 399 "=========================================================================== ====="; |
441 debugText += L"\n============================================================= ==================="; | 400 DEBUG_GENERAL(message); |
442 | |
443 DEBUG_GENERAL(debugText) | |
444 | 401 |
445 // -------------------------------------------------------------------- | 402 // -------------------------------------------------------------------- |
446 // Tab loop | 403 // Tab loop |
447 // -------------------------------------------------------------------- | 404 // -------------------------------------------------------------------- |
448 | 405 |
449 DWORD loopCount = 0; | 406 DWORD loopCount = 0; |
450 DWORD tabLoopIteration = 1; | 407 DWORD tabLoopIteration = 1; |
451 | 408 |
452 while (this->m_continueThreadRunning) | 409 while (this->m_continueThreadRunning) |
453 { | 410 { |
454 #ifdef ENABLE_DEBUG_THREAD | 411 #ifdef ENABLE_DEBUG_THREAD |
455 CStringA sTabLoopIteration; | 412 CStringA sTabLoopIteration; |
456 sTabLoopIteration.Format("%u", tabLoopIteration); | 413 sTabLoopIteration.Format("%u", tabLoopIteration); |
457 | 414 |
458 DEBUG_THREAD("-------------------------------------------------------------- ------------------") | 415 DEBUG_THREAD("-------------------------------------------------------------- ------------------") |
459 DEBUG_THREAD("Loop iteration " + sTabLoopIteration); | 416 DEBUG_THREAD("Loop iteration " + sTabLoopIteration); |
460 DEBUG_THREAD("-------------------------------------------------------------- ------------------") | 417 DEBUG_THREAD("-------------------------------------------------------------- ------------------") |
461 #endif | 418 #endif |
462 if (this->m_isActivated) | 419 this->m_isActivated = false; |
463 { | |
464 bool isChanged = false; | |
465 | |
466 if (isChanged) | |
467 { | |
468 this->m_plugin->UpdateStatusBar(); | |
469 } | |
470 | |
471 this->m_isActivated = false; | |
472 } | |
473 | 420 |
474 // -------------------------------------------------------------------- | 421 // -------------------------------------------------------------------- |
475 // End loop | 422 // End loop |
476 // -------------------------------------------------------------------- | 423 // -------------------------------------------------------------------- |
477 | 424 |
478 // Sleep loop | 425 // Sleep loop |
479 while (this->m_continueThreadRunning && !this->m_isActivated && (++loopCou nt % (TIMER_THREAD_SLEEP_TAB_LOOP / 50)) != 0) | 426 while (this->m_continueThreadRunning && !this->m_isActivated && (++loopCou nt % (TIMER_THREAD_SLEEP_TAB_LOOP / 50)) != 0) |
480 { | 427 { |
481 // Post async plugin error | 428 // Post async plugin error |
482 CPluginError pluginError; | 429 CPluginError pluginError; |
483 if (CPluginClient::PopFirstPluginError(pluginError)) | 430 if (LogQueue::PopFirstPluginError(pluginError)) |
484 { | 431 { |
485 CPluginClient::LogPluginError(pluginError.GetErrorCode(), pluginError. GetErrorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), tr ue, pluginError.GetProcessId(), pluginError.GetThreadId()); | 432 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId()); |
486 } | 433 } |
487 | 434 |
488 // Non-hanging sleep | 435 // Non-hanging sleep |
489 Sleep(50); | 436 Sleep(50); |
490 } | 437 } |
491 | 438 |
492 tabLoopIteration++; | 439 tabLoopIteration++; |
493 } | 440 } |
494 } | 441 } |
LEFT | RIGHT |