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 rename webBrowser to parentBrowser Created Nov. 30, 2015, 3:27 p.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 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 url = urlArg;
116 do
117 {
118 std::string parentUrl = *frameIterator++;
119 auto filterText = GetWhitelistingFilter(url, parentUrl, type);
120 if (!filterText.empty())
121 {
122 return filterText;
123 }
124 url = parentUrl;
125 }
126 while (frameIterator != frameHierarchy.end());
127 return "";
128 }
129
96 void WriteSubscriptions(Communication::OutputBuffer& response, 130 void WriteSubscriptions(Communication::OutputBuffer& response,
97 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) 131 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
98 { 132 {
99 int32_t count = static_cast<int32_t>(subscriptions.size()); 133 int32_t count = static_cast<int32_t>(subscriptions.size());
100 response << count; 134 response << count;
101 for (int32_t i = 0; i < count; i++) 135 for (int32_t i = 0; i < count; i++)
102 { 136 {
103 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 137 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
104 response << subscription->GetProperty("url")->AsString() 138 response << subscription->GetProperty("url")->AsString()
105 << subscription->GetProperty("title")->AsString() 139 << subscription->GetProperty("title")->AsString()
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 283 }
250 } 284 }
251 285
252 response << domains; 286 response << domains;
253 break; 287 break;
254 } 288 }
255 case Communication::PROC_GET_WHITELISTING_FITER: 289 case Communication::PROC_GET_WHITELISTING_FITER:
256 { 290 {
257 std::string url; 291 std::string url;
258 request >> url; 292 request >> url;
259 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 293 std::vector<std::string> frameHierarchy;
260 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, url); 294 request >> frameHierarchy;
261 std::string filterText; 295 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; 296 break;
268 } 297 }
269 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: 298 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL:
270 { 299 {
271 std::string url; 300 std::string url;
272 request >> url; 301 request >> url;
273 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 302 std::vector<std::string> frameHierarchy;
274 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url); 303 request >> frameHierarchy;
275 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 304 response << !GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::Fil terEngine::CONTENT_TYPE_ELEMHIDE).empty();
276 break; 305 break;
277 } 306 }
278 case Communication::PROC_ADD_FILTER: 307 case Communication::PROC_ADD_FILTER:
279 { 308 {
280 std::string text; 309 std::string text;
281 request >> text; 310 request >> text;
282 311
283 filterEngine->GetFilter(text)->AddToList(); 312 filterEngine->GetFilter(text)->AddToList();
284 break; 313 break;
285 } 314 }
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 }); 756 });
728 757
729 int retValue = _AtlModule.WinMain(cmdShow); 758 int retValue = _AtlModule.WinMain(cmdShow);
730 if (communicationThread.joinable()) 759 if (communicationThread.joinable())
731 { 760 {
732 communicationThread.join(); 761 communicationThread.join();
733 } 762 }
734 763
735 return retValue; 764 return retValue;
736 } 765 }
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