| 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" |
| 11 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 MediaListDirective::MediaListDirective(const String& name, | 15 MediaListDirective::MediaListDirective(const String& name, |
| 16 const String& value, | 16 const String& value, |
| 17 ContentSecurityPolicy* policy) | 17 ContentSecurityPolicy* policy) |
| 18 : CSPDirective(name, value, policy) { | 18 : CSPDirective(name, value, policy) { |
| 19 Vector<UChar> characters; | 19 Vector<UChar> characters; |
| 20 value.appendTo(characters); | 20 value.appendTo(characters); |
| 21 parse(characters.data(), characters.data() + characters.size()); | 21 parse(characters.data(), characters.data() + characters.size()); |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool MediaListDirective::allows(const String& type) { | 24 bool MediaListDirective::allows(const String& type) const { |
| 25 return m_pluginTypes.contains(type); | 25 return m_pluginTypes.contains(type); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void MediaListDirective::parse(const UChar* begin, const UChar* end) { | 28 void MediaListDirective::parse(const UChar* begin, const UChar* end) { |
| 29 // TODO(amalika): Revisit parsing algorithm. Right now plugin types are not | 29 // TODO(amalika): Revisit parsing algorithm. Right now plugin types are not |
| 30 // validated when they are added to m_pluginTypes. | 30 // validated when they are added to m_pluginTypes. |
| 31 const UChar* position = begin; | 31 const UChar* position = begin; |
| 32 | 32 |
| 33 // 'plugin-types ____;' OR 'plugin-types;' | 33 // 'plugin-types ____;' OR 'plugin-types;' |
| 34 if (position == end) { | 34 if (position == end) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 policy()->reportInvalidPluginTypes(String(begin, position - begin)); | 77 policy()->reportInvalidPluginTypes(String(begin, position - begin)); |
| 78 continue; | 78 continue; |
| 79 } | 79 } |
| 80 m_pluginTypes.add(String(begin, position - begin)); | 80 m_pluginTypes.add(String(begin, position - begin)); |
| 81 | 81 |
| 82 ASSERT(position == end || isASCIISpace(*position)); | 82 ASSERT(position == end || isASCIISpace(*position)); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool MediaListDirective::subsumes( | 86 bool MediaListDirective::subsumes( |
| 87 const std::vector<MediaListDirective*>& other) { | 87 const HeapVector<Member<MediaListDirective>>& other) const { |
| 88 if (!other.size()) | 88 if (!other.size()) |
| 89 return false; | 89 return false; |
| 90 | 90 |
| 91 // Find the effective set of plugins allowed by `other`. | 91 // Find the effective set of plugins allowed by `other`. |
| 92 HashSet<String> normalizedB = other[0]->m_pluginTypes; | 92 HashSet<String> normalizedB = other[0]->m_pluginTypes; |
| 93 for (size_t i = 1; i < other.size(); i++) | 93 for (size_t i = 1; i < other.size(); i++) |
| 94 normalizedB = other[i]->getIntersect(normalizedB); | 94 normalizedB = other[i]->getIntersect(normalizedB); |
| 95 | 95 |
| 96 // Empty list of plugins is equivalent to no plugins being allowed. | 96 // Empty list of plugins is equivalent to no plugins being allowed. |
| 97 if (!m_pluginTypes.size()) | 97 if (!m_pluginTypes.size()) |
| 98 return !normalizedB.size(); | 98 return !normalizedB.size(); |
| 99 | 99 |
| 100 // Check that each element of `normalizedB` is allowed by `m_pluginTypes`. | 100 // Check that each element of `normalizedB` is allowed by `m_pluginTypes`. |
| 101 for (auto it = normalizedB.begin(); it != normalizedB.end(); ++it) { | 101 for (auto it = normalizedB.begin(); it != normalizedB.end(); ++it) { |
| 102 if (!allows(*it)) | 102 if (!allows(*it)) |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 HashSet<String> MediaListDirective::getIntersect(const HashSet<String>& other) { | 109 HashSet<String> MediaListDirective::getIntersect( |
| 110 const HashSet<String>& other) const { |
| 110 HashSet<String> normalized; | 111 HashSet<String> normalized; |
| 111 for (const auto& type : m_pluginTypes) { | 112 for (const auto& type : m_pluginTypes) { |
| 112 if (other.contains(type)) | 113 if (other.contains(type)) |
| 113 normalized.add(type); | 114 normalized.add(type); |
| 114 } | 115 } |
| 115 | 116 |
| 116 return normalized; | 117 return normalized; |
| 117 } | 118 } |
| 118 | 119 |
| 119 } // namespace blink | 120 } // namespace blink |
| OLD | NEW |