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: rebase Created Oct. 27, 2015, 11 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;
+ std::string url = urlArg;
+ while (frameIterator != frameHierarchy.end())
+ {
+ parentUrl = *frameIterator;
+ 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