Index: src/engine/Main.cpp |
diff --git a/src/engine/Main.cpp b/src/engine/Main.cpp |
index 11ddf7eb13f0837c5bfeba071d9f3c9af1480bb8..c93790656eb4331245063739e8ca7cc1ee61e840 100644 |
--- a/src/engine/Main.cpp |
+++ b/src/engine/Main.cpp |
@@ -23,6 +23,35 @@ namespace |
CriticalSection activeConnectionsLock; |
HWND callbackWindow; |
+ bool IsWhitelisted(const std::string& urlArg, |
+ const std::vector<std::string>& frameHierarchy, const std::string& type) |
+ { |
+ auto IsWhitelisted = [&type](const std::string& url, const std::string& parent)->bool |
+ { |
+ AdblockPlus::FilterPtr match = filterEngine->Matches(url, type, parent); |
+ return match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION; |
+ }; |
+ 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
|
+ if (frameHierarchy.empty()) |
+ { |
+ 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
|
+ } |
+ else |
+ { |
+ 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
|
+ std::string parentUrl; |
+ std::string url = urlArg; |
+ 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
|
+ { |
+ parentUrl = *frame_ii; |
+ isWhitelisted = IsWhitelisted(url, parentUrl); |
Eric
2015/01/13 19:52:52
if (IsWhitelisted(...)) return true;
sergei
2015/04/13 08:06:41
fixed
|
+ url = parentUrl; |
+ ++frame_ii; |
+ } |
Eric
2015/01/13 19:52:52
Just return false if the loop terminates having re
sergei
2015/04/13 08:06:41
fixed
|
+ } |
+ return isWhitelisted; |
+ } |
+ |
void WriteStrings(Communication::OutputBuffer& response, |
const std::vector<std::string>& strings) |
{ |
@@ -193,16 +222,18 @@ namespace |
{ |
std::string url; |
request >> url; |
- AdblockPlus::FilterPtr match = filterEngine->Matches(url, "DOCUMENT", url); |
- response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION); |
+ std::vector<std::string> frameHierarchy; |
+ request >> frameHierarchy; |
+ response << IsWhitelisted(url, frameHierarchy, "DOCUMENT");; |
break; |
} |
case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: |
{ |
std::string url; |
request >> url; |
- AdblockPlus::FilterPtr match = filterEngine->Matches(url, "ELEMHIDE", url); |
- response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION); |
+ std::vector<std::string> frameHierarchy; |
+ request >> frameHierarchy; |
+ response << IsWhitelisted(url, frameHierarchy, "ELEMHIDE"); |
break; |
} |
case Communication::PROC_ADD_FILTER: |