Index: src/engine/Main.cpp |
diff --git a/src/engine/Main.cpp b/src/engine/Main.cpp |
index 5930826552739e39188d440297e252135bcd9aa1..478b3f7181b5ec6ff7649561d87adb64ee2ca97f 100644 |
--- a/src/engine/Main.cpp |
+++ b/src/engine/Main.cpp |
@@ -40,6 +40,39 @@ namespace |
CriticalSection activeConnectionsLock; |
HWND callbackWindow; |
+ std::string GetWhitelistingFilter(const std::string& urlArg, |
+ const std::vector<std::string>& frameHierarchy, AdblockPlus::FilterEngine::ContentType type) |
+ { |
+ auto GetWhitelistingFilter = [&type](const std::string& url, const std::string& 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.
|
+ { |
+ AdblockPlus::FilterPtr match = filterEngine->Matches(url, type, parent); |
+ if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
+ { |
+ return match->GetProperty("text")->AsString(); |
+ } |
+ return ""; |
+ }; |
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.
|
+ if (frameHierarchy.empty()) |
+ { |
+ return GetWhitelistingFilter(urlArg, ""); |
+ } |
+ auto frameIterator = frameHierarchy.begin(); |
+ std::string parentUrl; |
+ std::string url = urlArg; |
+ while (frameIterator != frameHierarchy.end()) |
+ { |
+ parentUrl = *frameIterator; |
+ auto filterText = GetWhitelistingFilter(url, parentUrl); |
+ if (!filterText.empty()) |
+ { |
+ return filterText; |
+ } |
+ url = parentUrl; |
+ ++frameIterator; |
+ } |
+ return ""; |
+ } |
+ |
void WriteSubscriptions(Communication::OutputBuffer& response, |
const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) |
{ |
@@ -203,23 +236,18 @@ namespace |
{ |
std::string url; |
request >> url; |
- AdblockPlus::FilterPtr match = filterEngine->Matches(url, |
- AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, url); |
- std::string filterText; |
- if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
- { |
- filterText = match->GetProperty("text")->AsString(); |
- } |
- response << filterText; |
+ std::vector<std::string> frameHierarchy; |
+ request >> frameHierarchy; |
+ response << GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::FilterEngine::CONTENT_TYPE_DOCUMENT); |
break; |
} |
case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: |
{ |
std::string url; |
request >> url; |
- AdblockPlus::FilterPtr match = filterEngine->Matches(url, |
- AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url); |
- response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION); |
+ std::vector<std::string> frameHierarchy; |
+ request >> frameHierarchy; |
+ response << !GetWhitelistingFilter(url, frameHierarchy, AdblockPlus::FilterEngine::CONTENT_TYPE_ELEMHIDE).empty(); |
break; |
} |
case Communication::PROC_ADD_FILTER: |