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: rebase and address comments Created April 13, 2015, 7:31 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') | src/plugin/PluginTabBase.cpp » ('J')
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 std::string GetWhitelistingFilter(const std::string& urlArg,
44 const std::vector<std::string>& frameHierarchy, AdblockPlus::FilterEngine::C ontentType type)
45 {
46 auto GetWhitelistingFilter = [&type](const std::string& url, const std::stri ng& parent)->std::string
Eric 2015/05/14 17:07:26 Code style comment. It's not a good idea to use t
sergei 2015/05/15 11:55:55 extracted as a separate function.
47 {
48 AdblockPlus::FilterPtr match = filterEngine->Matches(url, type, parent);
49 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
50 {
51 return match->GetProperty("text")->AsString();
52 }
53 return "";
54 };
Eric 2015/05/14 17:07:26 The whole loop below would be clearer if implement
sergei 2015/05/15 11:55:55 It seems such overhead will only complicate it.
55 if (frameHierarchy.empty())
56 {
57 return GetWhitelistingFilter(urlArg, "");
58 }
59 auto frameIterator = frameHierarchy.begin();
60 std::string parentUrl;
61 std::string url = urlArg;
62 while (frameIterator != frameHierarchy.end())
63 {
64 parentUrl = *frameIterator;
65 auto filterText = GetWhitelistingFilter(url, parentUrl);
66 if (!filterText.empty())
67 {
68 return filterText;
69 }
70 url = parentUrl;
71 ++frameIterator;
72 }
73 return "";
74 }
75
43 void WriteSubscriptions(Communication::OutputBuffer& response, 76 void WriteSubscriptions(Communication::OutputBuffer& response,
44 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) 77 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
45 { 78 {
46 int32_t count = static_cast<int32_t>(subscriptions.size()); 79 int32_t count = static_cast<int32_t>(subscriptions.size());
47 response << count; 80 response << count;
48 for (int32_t i = 0; i < count; i++) 81 for (int32_t i = 0; i < count; i++)
49 { 82 {
50 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 83 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
51 response << subscription->GetProperty("url")->AsString() 84 response << subscription->GetProperty("url")->AsString()
52 << subscription->GetProperty("title")->AsString() 85 << subscription->GetProperty("title")->AsString()
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 229 }
197 } 230 }
198 231
199 response << domains; 232 response << domains;
200 break; 233 break;
201 } 234 }
202 case Communication::PROC_GET_WHITELISTING_FITER: 235 case Communication::PROC_GET_WHITELISTING_FITER:
203 { 236 {
204 std::string url; 237 std::string url;
205 request >> url; 238 request >> url;
206 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 239 std::vector<std::string> frameHierarchy;
207 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, url); 240 request >> frameHierarchy;
208 std::string filterText; 241 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; 242 break;
215 } 243 }
216 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: 244 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL:
217 { 245 {
218 std::string url; 246 std::string url;
219 request >> url; 247 request >> url;
220 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 248 std::vector<std::string> frameHierarchy;
221 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url); 249 request >> frameHierarchy;
222 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 250 response << !GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::Fil terEngine::CONTENT_TYPE_ELEMHIDE).empty();
223 break; 251 break;
224 } 252 }
225 case Communication::PROC_ADD_FILTER: 253 case Communication::PROC_ADD_FILTER:
226 { 254 {
227 std::string text; 255 std::string text;
228 request >> text; 256 request >> text;
229 257
230 filterEngine->GetFilter(text)->AddToList(); 258 filterEngine->GetFilter(text)->AddToList();
231 break; 259 break;
232 } 260 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 530 }
503 catch (const std::runtime_error& e) 531 catch (const std::runtime_error& e)
504 { 532 {
505 DebugException(e); 533 DebugException(e);
506 return 1; 534 return 1;
507 } 535 }
508 } 536 }
509 537
510 return 0; 538 return 0;
511 } 539 }
OLDNEW
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/PluginTabBase.cpp » ('J')

Powered by Google App Engine
This is Rietveld