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: update Created Jan. 13, 2015, 3:20 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') | src/plugin/PluginTabBase.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <functional> 2 #include <functional>
3 #include <vector> 3 #include <vector>
4 #include <thread> 4 #include <thread>
5 #include <Windows.h> 5 #include <Windows.h>
6 6
7 #include "../shared/AutoHandle.h" 7 #include "../shared/AutoHandle.h"
8 #include "../shared/Communication.h" 8 #include "../shared/Communication.h"
9 #include "../shared/Dictionary.h" 9 #include "../shared/Dictionary.h"
10 #include "../shared/Utils.h" 10 #include "../shared/Utils.h"
11 #include "../shared/Version.h" 11 #include "../shared/Version.h"
12 #include "../shared/CriticalSection.h" 12 #include "../shared/CriticalSection.h"
13 #include "../shared/IE_version.h" 13 #include "../shared/IE_version.h"
14 #include "AdblockPlus.h" 14 #include "AdblockPlus.h"
15 #include "Debug.h" 15 #include "Debug.h"
16 #include "Updater.h" 16 #include "Updater.h"
17 17
18 namespace 18 namespace
19 { 19 {
20 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 20 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
21 std::auto_ptr<Updater> updater; 21 std::auto_ptr<Updater> updater;
22 int activeConnections = 0; 22 int activeConnections = 0;
23 CriticalSection activeConnectionsLock; 23 CriticalSection activeConnectionsLock;
24 HWND callbackWindow; 24 HWND callbackWindow;
25 25
26 bool IsWhitelisted(const std::string& urlArg,
27 const std::vector<std::string>& frameHierarchy, const std::string& type)
28 {
29 auto IsWhitelisted = [&type](const std::string& url, const std::string& pare nt)->bool
30 {
31 AdblockPlus::FilterPtr match = filterEngine->Matches(url, type, parent);
32 return match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION;
33 };
34 bool isWhitelisted = false;
Eric 2015/01/13 19:52:52 I dislike identifiers that differ only in capitali
sergei 2015/04/13 08:06:41 fixed
35 if (frameHierarchy.empty())
36 {
37 isWhitelisted = IsWhitelisted(urlArg, "");
Eric 2015/01/13 19:52:52 We can simply return here and skip the subsequent
sergei 2015/04/13 08:06:41 fixed
38 }
39 else
40 {
41 auto frame_ii = frameHierarchy.begin();
Eric 2015/01/13 19:52:52 As much as I prefer underscores, ABP doesn't use t
sergei 2015/04/13 08:06:41 fixed
42 std::string parentUrl;
43 std::string url = urlArg;
44 while (!isWhitelisted && frame_ii != frameHierarchy.end())
Eric 2015/01/13 19:52:52 We only need the second term here.
sergei 2015/04/13 08:06:41 fixed
45 {
46 parentUrl = *frame_ii;
47 isWhitelisted = IsWhitelisted(url, parentUrl);
Eric 2015/01/13 19:52:52 if (IsWhitelisted(...)) return true;
sergei 2015/04/13 08:06:41 fixed
48 url = parentUrl;
49 ++frame_ii;
50 }
Eric 2015/01/13 19:52:52 Just return false if the loop terminates having re
sergei 2015/04/13 08:06:41 fixed
51 }
52 return isWhitelisted;
53 }
54
26 void WriteStrings(Communication::OutputBuffer& response, 55 void WriteStrings(Communication::OutputBuffer& response,
27 const std::vector<std::string>& strings) 56 const std::vector<std::string>& strings)
28 { 57 {
29 int32_t count = static_cast<int32_t>(strings.size()); 58 int32_t count = static_cast<int32_t>(strings.size());
30 response << count; 59 response << count;
31 for (int32_t i = 0; i < count; i++) 60 for (int32_t i = 0; i < count; i++)
32 response << strings[i]; 61 response << strings[i];
33 } 62 }
34 63
35 void WriteSubscriptions(Communication::OutputBuffer& response, 64 void WriteSubscriptions(Communication::OutputBuffer& response,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 215 }
187 } 216 }
188 217
189 WriteStrings(response, domains); 218 WriteStrings(response, domains);
190 break; 219 break;
191 } 220 }
192 case Communication::PROC_IS_WHITELISTED_URL: 221 case Communication::PROC_IS_WHITELISTED_URL:
193 { 222 {
194 std::string url; 223 std::string url;
195 request >> url; 224 request >> url;
196 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "DOCUMENT", ur l); 225 std::vector<std::string> frameHierarchy;
197 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 226 request >> frameHierarchy;
227 response << IsWhitelisted(url, frameHierarchy, "DOCUMENT");;
198 break; 228 break;
199 } 229 }
200 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: 230 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL:
201 { 231 {
202 std::string url; 232 std::string url;
203 request >> url; 233 request >> url;
204 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "ELEMHIDE", ur l); 234 std::vector<std::string> frameHierarchy;
205 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 235 request >> frameHierarchy;
236 response << IsWhitelisted(url, frameHierarchy, "ELEMHIDE");
206 break; 237 break;
207 } 238 }
208 case Communication::PROC_ADD_FILTER: 239 case Communication::PROC_ADD_FILTER:
209 { 240 {
210 std::string text; 241 std::string text;
211 request >> text; 242 request >> text;
212 243
213 filterEngine->GetFilter(text)->AddToList(); 244 filterEngine->GetFilter(text)->AddToList();
214 break; 245 break;
215 } 246 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 516 }
486 catch (const std::runtime_error& e) 517 catch (const std::runtime_error& e)
487 { 518 {
488 DebugException(e); 519 DebugException(e);
489 return 1; 520 return 1;
490 } 521 }
491 } 522 }
492 523
493 return 0; 524 return 0;
494 } 525 }
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