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

Side by Side Diff: src/plugin/PluginTabBase.cpp

Issue 5447868882092032: Issue 1793 - check whether the frame is whitelisted before injecting CSS (Closed)
Patch Set: rebase Created Oct. 27, 2015, 11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/AdblockPlusClient.cpp ('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
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 <Mshtmhst.h> 26 #include <Mshtmhst.h>
26 27
27 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) 28 CPluginTabBase::CPluginTabBase(CPluginClass* plugin)
28 : m_plugin(plugin) 29 : m_plugin(plugin)
29 , m_isActivated(false) 30 , m_isActivated(false)
30 , m_continueThreadRunning(true) 31 , m_continueThreadRunning(true)
31 { 32 {
32 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); 33 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
33 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); 34 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL);
34 35
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 params.rgvarg = &var; 197 params.rgvarg = &var;
197 params.rgdispidNamedArgs = 0; 198 params.rgdispidNamedArgs = 0;
198 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0); 199 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0);
199 DEBUG_GENERAL("Invoke"); 200 DEBUG_GENERAL("Invoke");
200 if (FAILED(hr)) 201 if (FAILED(hr))
201 { 202 {
202 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");
203 } 204 }
204 } 205 }
205 206
207 namespace
208 {
209 ATL::CComPtr<IWebBrowser2> GetParent(IWebBrowser2& browser)
210 {
211 ATL::CComPtr<IDispatch> parentDispatch;
212 if (FAILED(browser.get_Parent(&parentDispatch)) || !parentDispatch)
213 {
214 return nullptr;
215 }
216 // The InternetExplorer application always returns a pointer to itself.
Oleksandr 2015/10/28 10:12:12 Nit: I'd include a link here: https://msdn.microso
sergei 2015/10/28 10:33:28 Done.
217 if (parentDispatch.IsEqualObject(&browser))
218 {
219 return nullptr;
220 }
221 ATL::CComQIPtr<IServiceProvider> parentDocumentServiceProvider = parentDispa tch;
222 if (!parentDocumentServiceProvider)
223 {
224 return nullptr;
225 }
226 ATL::CComPtr<IWebBrowserApp> webBrowserApp;
227 if (FAILED(parentDocumentServiceProvider->QueryService(IID_IWebBrowserApp, & webBrowserApp)) || !webBrowserApp)
228 {
229 return nullptr;
230 }
231 return ATL::CComQIPtr<IWebBrowser2>(webBrowserApp);
232 }
233
234 bool IsFrameWhiteListed(ATL::CComPtr<IWebBrowser2> frame)
235 {
236 if (!frame)
237 {
238 return false;
239 }
240 auto url = GetLocationUrl(*frame);
241 std::vector<std::string> frameHierarchy;
242 while(frame = GetParent(*frame))
243 {
244 frameHierarchy.push_back(ToUtf8String(GetLocationUrl(*frame)));
245 }
246 CPluginClient* client = CPluginClient::GetInstance();
247 return client->IsWhitelistedUrl(url, frameHierarchy)
248 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy);
249 }
250 }
251
206 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) 252 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser)
207 { 253 {
208 CPluginClient* client = CPluginClient::GetInstance(); 254 CPluginClient* client = CPluginClient::GetInstance();
209 std::wstring url = GetDocumentUrl(); 255 std::wstring url = GetDocumentUrl();
210 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl)) 256 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl))
211 { 257 {
212 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() ); 258 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() );
213 } 259 }
214 InjectABP(browser); 260 InjectABP(browser);
215 } 261 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId()); 431 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
386 } 432 }
387 433
388 // Non-hanging sleep 434 // Non-hanging sleep
389 Sleep(50); 435 Sleep(50);
390 } 436 }
391 437
392 tabLoopIteration++; 438 tabLoopIteration++;
393 } 439 }
394 } 440 }
OLDNEW
« no previous file with comments | « src/plugin/AdblockPlusClient.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld