OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/frame/csp/MediaListDirective.h" | 5 #include "core/frame/csp/MediaListDirective.h" |
6 | 6 |
7 #include "core/frame/csp/ContentSecurityPolicy.h" | 7 #include "core/frame/csp/ContentSecurityPolicy.h" |
8 #include "platform/network/ContentSecurityPolicyParsers.h" | 8 #include "platform/network/ContentSecurityPolicyParsers.h" |
9 #include "wtf/HashSet.h" | 9 #include "wtf/HashSet.h" |
10 #include "wtf/text/ParsingUtilities.h" | 10 #include "wtf/text/ParsingUtilities.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 skipWhile<UChar, isNotASCIISpace>(position, end); | 74 skipWhile<UChar, isNotASCIISpace>(position, end); |
75 policy()->reportInvalidPluginTypes(String(begin, position - begin)); | 75 policy()->reportInvalidPluginTypes(String(begin, position - begin)); |
76 continue; | 76 continue; |
77 } | 77 } |
78 m_pluginTypes.add(String(begin, position - begin)); | 78 m_pluginTypes.add(String(begin, position - begin)); |
79 | 79 |
80 ASSERT(position == end || isASCIISpace(*position)); | 80 ASSERT(position == end || isASCIISpace(*position)); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 bool MediaListDirective::subsumes( | |
85 const std::vector<MediaListDirective*>& other) { | |
86 if (!other.size()) | |
87 return false; | |
88 | |
89 // Find the effective set of plugins allowed by `other`. | |
90 HashSet<String> normalizedB = other[0]->m_pluginTypes; | |
91 for (uint32_t i = 1; i < other.size(); i++) | |
Mike West
2016/12/06 13:39:07
s/uint32_t/size_t/
| |
92 normalizedB = other[i]->getIntersect(normalizedB); | |
93 | |
94 // Empty list of plugins is equivalent to no plugins being allowed. | |
95 if (!m_pluginTypes.size()) | |
96 return !normalizedB.size(); | |
97 | |
98 // Check that each element of `normalizedB` is allowed by `m_pluginTypes`. | |
99 for (auto it = normalizedB.begin(); it != normalizedB.end(); ++it) { | |
100 if (!allows(*it)) | |
101 return false; | |
102 } | |
103 | |
104 return true; | |
105 } | |
106 | |
107 HashSet<String> MediaListDirective::getIntersect(const HashSet<String>& other) { | |
108 HashSet<String> normalized; | |
109 for (const auto& type : m_pluginTypes) { | |
110 if (other.contains(type)) | |
111 normalized.add(type); | |
112 } | |
113 | |
114 return normalized; | |
115 } | |
116 | |
84 } // namespace blink | 117 } // namespace blink |
OLD | NEW |