OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/html/HTMLIFrameElementAllow.h" | |
6 | |
7 #include "core/html/HTMLIFrameElement.h" | |
8 #include "platform/feature_policy/FeaturePolicy.h" | |
9 | |
10 using blink::WebFeaturePolicyFeature; | |
11 | |
12 namespace blink { | |
13 | |
14 HTMLIFrameElementAllow::HTMLIFrameElementAllow(HTMLIFrameElement* element) | |
15 : DOMTokenList(this), m_element(element) {} | |
16 | |
17 HTMLIFrameElementAllow::~HTMLIFrameElementAllow() {} | |
18 | |
19 DEFINE_TRACE(HTMLIFrameElementAllow) { | |
20 visitor->trace(m_element); | |
21 DOMTokenList::trace(visitor); | |
22 DOMTokenListObserver::trace(visitor); | |
23 } | |
24 | |
25 Vector<WebFeaturePolicyFeature> | |
26 HTMLIFrameElementAllow::parseAllowedFeatureNames( | |
27 String& invalidTokensErrorMessage) const { | |
28 Vector<WebFeaturePolicyFeature> featureNames; | |
29 Vector<WebFeaturePolicyFeature> allowedFeatureNames; | |
30 unsigned numTokenErrors = 0; | |
31 StringBuilder tokenErrors; | |
32 const SpaceSplitString& tokens = this->tokens(); | |
33 | |
34 // Collects a list of valid feature names. | |
35 for (size_t i = 0; i < tokens.size(); ++i) { | |
36 WebFeaturePolicyFeature feature = | |
37 FeaturePolicy::getWebFeaturePolicyFeature(tokens[i]); | |
38 if (feature == WebFeaturePolicyFeature::NotFound) { | |
39 tokenErrors.append(tokenErrors.isEmpty() ? "'" : ", '"); | |
40 tokenErrors.append(tokens[i]); | |
41 tokenErrors.append("'"); | |
42 ++numTokenErrors; | |
43 } else { | |
44 featureNames.push_back(feature); | |
45 } | |
46 } | |
47 | |
48 if (numTokenErrors) { | |
49 tokenErrors.append(numTokenErrors > 1 ? " are invalid feature names." | |
50 : " is an invalid feature name."); | |
51 invalidTokensErrorMessage = tokenErrors.toString(); | |
52 } | |
53 | |
54 // Create a unique set of feature names. | |
55 std::sort(featureNames.begin(), featureNames.end()); | |
56 WebFeaturePolicyFeature lastFeature = WebFeaturePolicyFeature::NotFound; | |
57 for (auto const feature : featureNames) { | |
jbroman
2017/02/11 05:34:29
nit: STL has an efficient uniqueness thing that is
jbroman
2017/02/11 05:36:09
This line should be:
featureNames.shrink(it - fea
| |
58 if (feature == lastFeature) | |
59 continue; | |
60 allowedFeatureNames.push_back(feature); | |
61 lastFeature = feature; | |
62 } | |
63 | |
64 return allowedFeatureNames; | |
65 } | |
66 | |
67 bool HTMLIFrameElementAllow::validateTokenValue(const AtomicString& tokenValue, | |
68 ExceptionState&) const { | |
69 return FeaturePolicy::getWebFeaturePolicyFeature(tokenValue.getString()) != | |
70 WebFeaturePolicyFeature::NotFound; | |
71 } | |
72 | |
73 void HTMLIFrameElementAllow::valueWasSet() { | |
74 DCHECK(m_element); | |
75 m_element->allowValueWasSet(); | |
76 } | |
77 | |
78 } // namespace blink | |
OLD | NEW |