Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/PluginTabBase.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
« 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