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 and rename webBrowser to parentBrowser Created Nov. 30, 2015, 3:27 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') | no next file with comments »
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..0e2302f4be4460abbbab641f725537f464590ad3 100644
--- a/src/engine/Main.cpp
+++ b/src/engine/Main.cpp
@@ -93,6 +93,40 @@ 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 url = urlArg;
+ do
+ {
+ std::string parentUrl = *frameIterator++;
+ auto filterText = GetWhitelistingFilter(url, parentUrl, type);
+ if (!filterText.empty())
+ {
+ return filterText;
+ }
+ url = parentUrl;
+ }
+ while (frameIterator != frameHierarchy.end());
+ return "";
+ }
+
void WriteSubscriptions(Communication::OutputBuffer& response,
const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
{
@@ -256,23 +290,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld