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

Side by Side 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 unified diff | Download patch
OLDNEW
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) {
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
30 // validated when they are added to m_pluginTypes.
29 const UChar* position = begin; 31 const UChar* position = begin;
30 32
31 // 'plugin-types ____;' OR 'plugin-types;' 33 // 'plugin-types ____;' OR 'plugin-types;'
32 if (position == end) { 34 if (position == end) {
33 policy()->reportInvalidPluginTypes(String()); 35 policy()->reportInvalidPluginTypes(String());
34 return; 36 return;
35 } 37 }
36 38
37 while (position < end) { 39 while (position < end) {
38 // _____ OR _____mime1/mime1 40 // _____ OR _____mime1/mime1
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 skipWhile<UChar, isNotASCIISpace>(position, end); 76 skipWhile<UChar, isNotASCIISpace>(position, end);
75 policy()->reportInvalidPluginTypes(String(begin, position - begin)); 77 policy()->reportInvalidPluginTypes(String(begin, position - begin));
76 continue; 78 continue;
77 } 79 }
78 m_pluginTypes.add(String(begin, position - begin)); 80 m_pluginTypes.add(String(begin, position - begin));
79 81
80 ASSERT(position == end || isASCIISpace(*position)); 82 ASSERT(position == end || isASCIISpace(*position));
81 } 83 }
82 } 84 }
83 85
86 bool MediaListDirective::subsumes(
87 const std::vector<MediaListDirective*>& other) {
88 if (!other.size())
89 return false;
90
91 // Find the effective set of plugins allowed by `other`.
92 HashSet<String> normalizedB = other[0]->m_pluginTypes;
93 for (size_t i = 1; i < other.size(); i++)
94 normalizedB = other[i]->getIntersect(normalizedB);
95
96 // Empty list of plugins is equivalent to no plugins being allowed.
97 if (!m_pluginTypes.size())
98 return !normalizedB.size();
99
100 // Check that each element of `normalizedB` is allowed by `m_pluginTypes`.
101 for (auto it = normalizedB.begin(); it != normalizedB.end(); ++it) {
102 if (!allows(*it))
103 return false;
104 }
105
106 return true;
107 }
108
109 HashSet<String> MediaListDirective::getIntersect(const HashSet<String>& other) {
110 HashSet<String> normalized;
111 for (const auto& type : m_pluginTypes) {
112 if (other.contains(type))
113 normalized.add(type);
114 }
115
116 return normalized;
117 }
118
84 } // namespace blink 119 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698