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: use SID_SWebBrowserApp as service ID Created Nov. 20, 2015, 10:09 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.
217 // https://msdn.microsoft.com/en-us/library/aa752136(v=vs.85).aspx
218 if (parentDispatch.IsEqualObject(&browser))
219 {
220 return nullptr;
221 }
222 ATL::CComQIPtr<IServiceProvider> parentDocumentServiceProvider = parentDispa tch;
223 if (!parentDocumentServiceProvider)
224 {
225 return nullptr;
226 }
227 ATL::CComPtr<IWebBrowser2> webBrowser;
228 if (FAILED(parentDocumentServiceProvider->QueryService(SID_SWebBrowserApp, & webBrowser)))
229 {
230 return nullptr;
231 }
232 return webBrowser;
233 }
234
235 bool IsFrameWhiteListed(ATL::CComPtr<IWebBrowser2> frame)
236 {
237 if (!frame)
238 {
239 return false;
240 }
241 auto url = GetLocationUrl(*frame);
242 std::vector<std::string> frameHierarchy;
243 while(frame = GetParent(*frame))
244 {
245 frameHierarchy.push_back(ToUtf8String(GetLocationUrl(*frame)));
246 }
247 CPluginClient* client = CPluginClient::GetInstance();
248 return client->IsWhitelistedUrl(url, frameHierarchy)
249 || client->IsElemhideWhitelistedOnDomain(url, frameHierarchy);
250 }
251 }
252
206 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) 253 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser)
207 { 254 {
208 CPluginClient* client = CPluginClient::GetInstance(); 255 CPluginClient* client = CPluginClient::GetInstance();
209 std::wstring url = GetDocumentUrl(); 256 std::wstring url = GetDocumentUrl();
210 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl)) 257 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl))
211 { 258 {
212 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() ); 259 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() );
213 } 260 }
214 InjectABP(browser); 261 InjectABP(browser);
215 } 262 }
(...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()); 432 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
386 } 433 }
387 434
388 // Non-hanging sleep 435 // Non-hanging sleep
389 Sleep(50); 436 Sleep(50);
390 } 437 }
391 438
392 tabLoopIteration++; 439 tabLoopIteration++;
393 } 440 }
394 } 441 }
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