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: add link Created Oct. 28, 2015, 10:32 a.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 5c06428d324eebf1263deac78d6703e7c5fcccc4..55d012f4e2cc0dc35325c4bc33e85df9734dcbbd 100644
--- a/src/engine/Main.cpp
+++ b/src/engine/Main.cpp
@@ -93,6 +93,41 @@ namespace
CriticalSection activeConnectionsLock;
HWND callbackWindow;
+ // it's a helper for the function below.
+ std::string GetWhitelistingFilter(const std::string& url, const std::string& parent, AdblockPlus::FilterEngine::ContentType type)
+ {
+ AdblockPlus::FilterPtr match = filterEngine->Matches(url, type, parent);
+ if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
+ {
+ return match->GetProperty("text")->AsString();
+ }
+ return "";
+ };
+
+ std::string GetWhitelistingFilter(const std::string& urlArg,
+ const std::vector<std::string>& frameHierarchy, AdblockPlus::FilterEngine::ContentType type)
+ {
+ if (frameHierarchy.empty())
+ {
+ return GetWhitelistingFilter(urlArg, "", type);
+ }
+ auto frameIterator = frameHierarchy.begin();
+ std::string parentUrl;
Eric 2015/11/14 20:28:13 This declaration can go inside the loop.
sergei 2015/11/17 20:15:59 Done.
+ std::string url = urlArg;
+ while (frameIterator != frameHierarchy.end())
Eric 2015/11/14 20:28:13 Since you've already taken care of the empty case
sergei 2015/11/17 20:15:59 Done.
+ {
+ parentUrl = *frameIterator;
Eric 2015/11/14 20:28:13 The rvalue expression could be "*frameIterator++".
sergei 2015/11/17 20:15:59 Done.
+ auto filterText = GetWhitelistingFilter(url, parentUrl, type);
+ if (!filterText.empty())
+ {
+ return filterText;
+ }
+ url = parentUrl;
+ ++frameIterator;
+ }
+ return "";
+ }
+
void WriteSubscriptions(Communication::OutputBuffer& response,
const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
{
@@ -256,23 +291,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:
« 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