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 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 | « 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 std::deque<std::function<void()>> m_tasks; 86 std::deque<std::function<void()>> m_tasks;
87 std::unique_ptr<NotificationBorderWindow> m_notificationWindow; 87 std::unique_ptr<NotificationBorderWindow> m_notificationWindow;
88 } _AtlModule; 88 } _AtlModule;
89 89
90 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 90 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
91 std::auto_ptr<Updater> updater; 91 std::auto_ptr<Updater> updater;
92 int activeConnections = 0; 92 int activeConnections = 0;
93 CriticalSection activeConnectionsLock; 93 CriticalSection activeConnectionsLock;
94 HWND callbackWindow; 94 HWND callbackWindow;
95 95
96 // it's a helper for the function below.
97 std::string GetWhitelistingFilter(const std::string& url, const std::string& p arent, AdblockPlus::FilterEngine::ContentType type)
98 {
99 AdblockPlus::FilterPtr match = filterEngine->Matches(url, type, parent);
100 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
101 {
102 return match->GetProperty("text")->AsString();
103 }
104 return "";
105 };
106
107 std::string GetWhitelistingFilter(const std::string& urlArg,
108 const std::vector<std::string>& frameHierarchy, AdblockPlus::FilterEngine::C ontentType type)
109 {
110 if (frameHierarchy.empty())
111 {
112 return GetWhitelistingFilter(urlArg, "", type);
113 }
114 auto frameIterator = frameHierarchy.begin();
115 std::string parentUrl;
116 std::string url = urlArg;
117 while (frameIterator != frameHierarchy.end())
118 {
119 parentUrl = *frameIterator;
120 auto filterText = GetWhitelistingFilter(url, parentUrl, type);
121 if (!filterText.empty())
122 {
123 return filterText;
124 }
125 url = parentUrl;
126 ++frameIterator;
127 }
128 return "";
129 }
130
96 void WriteSubscriptions(Communication::OutputBuffer& response, 131 void WriteSubscriptions(Communication::OutputBuffer& response,
97 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) 132 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
98 { 133 {
99 int32_t count = static_cast<int32_t>(subscriptions.size()); 134 int32_t count = static_cast<int32_t>(subscriptions.size());
100 response << count; 135 response << count;
101 for (int32_t i = 0; i < count; i++) 136 for (int32_t i = 0; i < count; i++)
102 { 137 {
103 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 138 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
104 response << subscription->GetProperty("url")->AsString() 139 response << subscription->GetProperty("url")->AsString()
105 << subscription->GetProperty("title")->AsString() 140 << subscription->GetProperty("title")->AsString()
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 284 }
250 } 285 }
251 286
252 response << domains; 287 response << domains;
253 break; 288 break;
254 } 289 }
255 case Communication::PROC_GET_WHITELISTING_FITER: 290 case Communication::PROC_GET_WHITELISTING_FITER:
256 { 291 {
257 std::string url; 292 std::string url;
258 request >> url; 293 request >> url;
259 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 294 std::vector<std::string> frameHierarchy;
260 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, url); 295 request >> frameHierarchy;
261 std::string filterText; 296 response << GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::Filt erEngine::CONTENT_TYPE_DOCUMENT);
262 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
263 {
264 filterText = match->GetProperty("text")->AsString();
265 }
266 response << filterText;
267 break; 297 break;
268 } 298 }
269 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: 299 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL:
270 { 300 {
271 std::string url; 301 std::string url;
272 request >> url; 302 request >> url;
273 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 303 std::vector<std::string> frameHierarchy;
274 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url); 304 request >> frameHierarchy;
275 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 305 response << !GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::Fil terEngine::CONTENT_TYPE_ELEMHIDE).empty();
276 break; 306 break;
277 } 307 }
278 case Communication::PROC_ADD_FILTER: 308 case Communication::PROC_ADD_FILTER:
279 { 309 {
280 std::string text; 310 std::string text;
281 request >> text; 311 request >> text;
282 312
283 filterEngine->GetFilter(text)->AddToList(); 313 filterEngine->GetFilter(text)->AddToList();
284 break; 314 break;
285 } 315 }
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 }); 757 });
728 758
729 int retValue = _AtlModule.WinMain(cmdShow); 759 int retValue = _AtlModule.WinMain(cmdShow);
730 if (communicationThread.joinable()) 760 if (communicationThread.joinable())
731 { 761 {
732 communicationThread.join(); 762 communicationThread.join();
733 } 763 }
734 764
735 return retValue; 765 return retValue;
736 } 766 }
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