Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Unified Diff: third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp

Issue 2541843002: Part 5.1: Is policy list subsumed under subsuming policy? (Closed)
Patch Set: More test cases Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp b/third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp
index c067b3ce3c9ee6c6dcda9668f741be9e57aa87db..b031f79ec1219ee8779a0a5c98d1060f0645460a 100644
--- a/third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp
@@ -81,4 +81,37 @@ void MediaListDirective::parse(const UChar* begin, const UChar* end) {
}
}
+bool MediaListDirective::subsumes(
+ const std::vector<MediaListDirective*>& other) {
+ if (!other.size())
+ return false;
+
+ // Find the effective set of plugins allowed by `other`.
+ HashSet<String> normalizedB = other[0]->m_pluginTypes;
+ for (size_t i = 1; i < other.size(); i++)
+ normalizedB = other[i]->getIntersect(normalizedB);
+
+ // Empty list of plugins is equivalent to no plugins being allowed.
+ if (!m_pluginTypes.size())
+ return !normalizedB.size();
+
+ // Check that each element of `normalizedB` is allowed by `m_pluginTypes`.
+ for (auto it = normalizedB.begin(); it != normalizedB.end(); ++it) {
+ if (!allows(*it))
+ return false;
+ }
+
+ return true;
+}
+
+HashSet<String> MediaListDirective::getIntersect(const HashSet<String>& other) {
+ HashSet<String> normalized;
+ for (const auto& type : m_pluginTypes) {
+ if (other.contains(type))
+ normalized.add(type);
+ }
+
+ return normalized;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698