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 unsigned numTokenErrors = 0; |
| 30 StringBuilder tokenErrors; |
| 31 const SpaceSplitString& tokens = this->tokens(); |
| 32 |
| 33 // Collects a list of valid feature names. |
| 34 for (size_t i = 0; i < tokens.size(); ++i) { |
| 35 WebFeaturePolicyFeature feature = |
| 36 FeaturePolicy::getWebFeaturePolicyFeature(tokens[i]); |
| 37 if (feature == WebFeaturePolicyFeature::NotFound) { |
| 38 tokenErrors.append(tokenErrors.isEmpty() ? "'" : ", '"); |
| 39 tokenErrors.append(tokens[i]); |
| 40 tokenErrors.append("'"); |
| 41 ++numTokenErrors; |
| 42 } else { |
| 43 featureNames.push_back(feature); |
| 44 } |
| 45 } |
| 46 |
| 47 if (numTokenErrors) { |
| 48 tokenErrors.append(numTokenErrors > 1 ? " are invalid feature names." |
| 49 : " is an invalid feature name."); |
| 50 invalidTokensErrorMessage = tokenErrors.toString(); |
| 51 } |
| 52 |
| 53 // Create a unique set of feature names. |
| 54 std::sort(featureNames.begin(), featureNames.end()); |
| 55 auto it = std::unique(featureNames.begin(), featureNames.end()); |
| 56 featureNames.shrink(it - featureNames.begin()); |
| 57 |
| 58 return featureNames; |
| 59 } |
| 60 |
| 61 bool HTMLIFrameElementAllow::validateTokenValue(const AtomicString& tokenValue, |
| 62 ExceptionState&) const { |
| 63 return FeaturePolicy::getWebFeaturePolicyFeature(tokenValue.getString()) != |
| 64 WebFeaturePolicyFeature::NotFound; |
| 65 } |
| 66 |
| 67 void HTMLIFrameElementAllow::valueWasSet() { |
| 68 DCHECK(m_element); |
| 69 m_element->allowValueWasSet(); |
| 70 } |
| 71 |
| 72 } // namespace blink |
OLD | NEW |