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

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: Fixing c++ vector initialization in the test 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..f0c215dc6ce367f4b58a1d8be29ca6fc2a7fcaf2 100644
--- a/third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/MediaListDirective.cpp
@@ -26,6 +26,8 @@ bool MediaListDirective::allows(const String& type) {
}
void MediaListDirective::parse(const UChar* begin, const UChar* end) {
+ // TODO(amalika): Revisit parsing algorithm. Right now plugin types are not
+ // validated when they are added to m_pluginTypes.
const UChar* position = begin;
// 'plugin-types ____;' OR 'plugin-types;'
@@ -81,4 +83,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