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

Unified Diff: third_party/WebKit/Source/core/html/HTMLIFrameElementAllow.cpp

Issue 2680083002: Initial Implementation of Iframe Attribute for Feature Policy (Part 1) (Closed)
Patch Set: Codereview: nit Created 3 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLIFrameElementAllow.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLIFrameElementAllow.cpp b/third_party/WebKit/Source/core/html/HTMLIFrameElementAllow.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1d31463110f5fbb59f4afb78eb3adae8dc92c142
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/HTMLIFrameElementAllow.cpp
@@ -0,0 +1,72 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/HTMLIFrameElementAllow.h"
+
+#include "core/html/HTMLIFrameElement.h"
+#include "platform/feature_policy/FeaturePolicy.h"
+
+using blink::WebFeaturePolicyFeature;
+
+namespace blink {
+
+HTMLIFrameElementAllow::HTMLIFrameElementAllow(HTMLIFrameElement* element)
+ : DOMTokenList(this), m_element(element) {}
+
+HTMLIFrameElementAllow::~HTMLIFrameElementAllow() {}
+
+DEFINE_TRACE(HTMLIFrameElementAllow) {
+ visitor->trace(m_element);
+ DOMTokenList::trace(visitor);
+ DOMTokenListObserver::trace(visitor);
+}
+
+Vector<WebFeaturePolicyFeature>
+HTMLIFrameElementAllow::parseAllowedFeatureNames(
+ String& invalidTokensErrorMessage) const {
+ Vector<WebFeaturePolicyFeature> featureNames;
+ unsigned numTokenErrors = 0;
+ StringBuilder tokenErrors;
+ const SpaceSplitString& tokens = this->tokens();
+
+ // Collects a list of valid feature names.
+ for (size_t i = 0; i < tokens.size(); ++i) {
+ WebFeaturePolicyFeature feature =
+ FeaturePolicy::getWebFeaturePolicyFeature(tokens[i]);
+ if (feature == WebFeaturePolicyFeature::NotFound) {
+ tokenErrors.append(tokenErrors.isEmpty() ? "'" : ", '");
+ tokenErrors.append(tokens[i]);
+ tokenErrors.append("'");
+ ++numTokenErrors;
+ } else {
+ featureNames.push_back(feature);
+ }
+ }
+
+ if (numTokenErrors) {
+ tokenErrors.append(numTokenErrors > 1 ? " are invalid feature names."
+ : " is an invalid feature name.");
+ invalidTokensErrorMessage = tokenErrors.toString();
+ }
+
+ // Create a unique set of feature names.
+ std::sort(featureNames.begin(), featureNames.end());
+ auto it = std::unique(featureNames.begin(), featureNames.end());
+ featureNames.shrink(it - featureNames.begin());
+
+ return featureNames;
+}
+
+bool HTMLIFrameElementAllow::validateTokenValue(const AtomicString& tokenValue,
+ ExceptionState&) const {
+ return FeaturePolicy::getWebFeaturePolicyFeature(tokenValue.getString()) !=
+ WebFeaturePolicyFeature::NotFound;
+}
+
+void HTMLIFrameElementAllow::valueWasSet() {
+ DCHECK(m_element);
+ m_element->allowValueWasSet();
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698