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

Side by Side Diff: src/engine/Main.cpp

Issue 5447868882092032: Issue 1793 - check whether the frame is whitelisted before injecting CSS (Closed)
Patch Set: fix according to comments Created May 15, 2015, 11:55 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 | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | 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
(...skipping 22 matching lines...) Expand all
33 #include "Updater.h" 33 #include "Updater.h"
34 34
35 namespace 35 namespace
36 { 36 {
37 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 37 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
38 std::auto_ptr<Updater> updater; 38 std::auto_ptr<Updater> updater;
39 int activeConnections = 0; 39 int activeConnections = 0;
40 CriticalSection activeConnectionsLock; 40 CriticalSection activeConnectionsLock;
41 HWND callbackWindow; 41 HWND callbackWindow;
42 42
43 // it's a helper for the function below.
44 std::string GetWhitelistingFilter(const std::string& url, const std::string& p arent, AdblockPlus::FilterEngine::ContentType type)
45 {
46 AdblockPlus::FilterPtr match = filterEngine->Matches(url, type, parent);
47 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
48 {
49 return match->GetProperty("text")->AsString();
50 }
51 return "";
52 };
53
54 std::string GetWhitelistingFilter(const std::string& urlArg,
55 const std::vector<std::string>& frameHierarchy, AdblockPlus::FilterEngine::C ontentType type)
56 {
57 if (frameHierarchy.empty())
58 {
59 return GetWhitelistingFilter(urlArg, "", type);
60 }
61 auto frameIterator = frameHierarchy.begin();
62 std::string parentUrl;
63 std::string url = urlArg;
64 while (frameIterator != frameHierarchy.end())
65 {
66 parentUrl = *frameIterator;
67 auto filterText = GetWhitelistingFilter(url, parentUrl, type);
68 if (!filterText.empty())
69 {
70 return filterText;
71 }
72 url = parentUrl;
73 ++frameIterator;
74 }
75 return "";
76 }
77
43 void WriteSubscriptions(Communication::OutputBuffer& response, 78 void WriteSubscriptions(Communication::OutputBuffer& response,
44 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) 79 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
45 { 80 {
46 int32_t count = static_cast<int32_t>(subscriptions.size()); 81 int32_t count = static_cast<int32_t>(subscriptions.size());
47 response << count; 82 response << count;
48 for (int32_t i = 0; i < count; i++) 83 for (int32_t i = 0; i < count; i++)
49 { 84 {
50 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 85 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
51 response << subscription->GetProperty("url")->AsString() 86 response << subscription->GetProperty("url")->AsString()
52 << subscription->GetProperty("title")->AsString() 87 << subscription->GetProperty("title")->AsString()
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 231 }
197 } 232 }
198 233
199 response << domains; 234 response << domains;
200 break; 235 break;
201 } 236 }
202 case Communication::PROC_GET_WHITELISTING_FITER: 237 case Communication::PROC_GET_WHITELISTING_FITER:
203 { 238 {
204 std::string url; 239 std::string url;
205 request >> url; 240 request >> url;
206 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 241 std::vector<std::string> frameHierarchy;
207 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, url); 242 request >> frameHierarchy;
208 std::string filterText; 243 response << GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::Filt erEngine::CONTENT_TYPE_DOCUMENT);
209 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
210 {
211 filterText = match->GetProperty("text")->AsString();
212 }
213 response << filterText;
214 break; 244 break;
215 } 245 }
216 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: 246 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL:
217 { 247 {
218 std::string url; 248 std::string url;
219 request >> url; 249 request >> url;
220 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 250 std::vector<std::string> frameHierarchy;
221 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url); 251 request >> frameHierarchy;
222 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 252 response << !GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::Fil terEngine::CONTENT_TYPE_ELEMHIDE).empty();
223 break; 253 break;
224 } 254 }
225 case Communication::PROC_ADD_FILTER: 255 case Communication::PROC_ADD_FILTER:
226 { 256 {
227 std::string text; 257 std::string text;
228 request >> text; 258 request >> text;
229 259
230 filterEngine->GetFilter(text)->AddToList(); 260 filterEngine->GetFilter(text)->AddToList();
231 break; 261 break;
232 } 262 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 532 }
503 catch (const std::runtime_error& e) 533 catch (const std::runtime_error& e)
504 { 534 {
505 DebugException(e); 535 DebugException(e);
506 return 1; 536 return 1;
507 } 537 }
508 } 538 }
509 539
510 return 0; 540 return 0;
511 } 541 }
OLDNEW
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld