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

Unified Diff: src/FilterEngine.cpp

Issue 29331737: Issue 3363 - Implement IsDocumentWhitelisted and IsElemhideWhitelisted (Closed)
Patch Set: Removed unnecessary @throw doc param. Created Dec. 2, 2015, 2:01 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
« include/AdblockPlus/FilterEngine.h ('K') | « include/AdblockPlus/FilterEngine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/FilterEngine.cpp
diff --git a/src/FilterEngine.cpp b/src/FilterEngine.cpp
index 95ef0c4c37ff2ee111551879f0790a7e01cf4fb6..b9d7694b149c92822b7643cd90f2c757573e84f7 100644
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -325,6 +325,20 @@ AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
return CheckFilterMatch(url, contentType, lastDocumentUrl);
}
+bool FilterEngine::IsDocumentWhitelisted(const std::string& url,
+ const std::vector<std::string>& documentUrls) const
+{
+ return !GetWhitelistingFilter(url, documentUrls,
+ CONTENT_TYPE_DOCUMENT).empty();
+}
+
+bool FilterEngine::IsElemhideWhitelisted(const std::string& url,
+ const std::vector<std::string>& documentUrls) const
+{
+ return !GetWhitelistingFilter(url, documentUrls,
+ CONTENT_TYPE_ELEMHIDE).empty();
+}
+
AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url,
ContentType contentType,
const std::string& documentUrl) const
@@ -462,3 +476,40 @@ int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
return func->Call(params)->AsInt();
}
+
+std::string FilterEngine::GetWhitelistingFilter(const std::string& url,
+ const std::string& parent, ContentType contentType) const
+{
+ FilterPtr match = Matches(url, contentType, parent);
+
+ if (match && match->GetType() == Filter::TYPE_EXCEPTION)
+ {
+ return match->GetProperty("text")->AsString();
Felix Dahlke 2015/12/02 17:27:44 Why return the filter text and not the filter obje
René Jeschke 2015/12/02 17:38:40 Done.
+ }
+ return "";
+}
+
+std::string FilterEngine::GetWhitelistingFilter(const std::string& urlArg,
+ const std::vector<std::string>& documentUrls,
+ ContentType contentType) const
+{
+ if (documentUrls.empty())
+ {
+ return GetWhitelistingFilter(urlArg, "", contentType);
+ }
+
+ std::vector<std::string>::const_iterator urlIterator = documentUrls.begin();
+ std::string url = urlArg;
+ do
+ {
+ std::string parentUrl = *urlIterator++;
+ std::string filterText = GetWhitelistingFilter(url, parentUrl, contentType);
+ if (!filterText.empty())
+ {
+ return filterText;
+ }
+ url = parentUrl;
+ }
+ while (urlIterator != documentUrls.end());
+ return "";
+}
« include/AdblockPlus/FilterEngine.h ('K') | « include/AdblockPlus/FilterEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld