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..8d7c6ad7cc0eb5acfcc9dbea0342590e9d790dcb 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 (uint32_t i = 1; i < other.size(); i++) |
Mike West
2016/12/06 13:39:07
s/uint32_t/size_t/
|
+ 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 |