| Index: third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp
|
| diff --git a/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp b/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp
|
| index 86b77badc9da2a4f5d97468a699d1dd2f5ae1758..9b8a0578467160ba1737dfa649a9bfbbe79b4064 100644
|
| --- a/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp
|
| +++ b/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp
|
| @@ -7,61 +7,12 @@
|
| #include "platform/RuntimeEnabledFeatures.h"
|
| #include "platform/json/JSONValues.h"
|
| #include "platform/network/HTTPParsers.h"
|
| -#include "platform/weborigin/KURL.h"
|
| #include "platform/weborigin/SecurityOrigin.h"
|
| #include "wtf/PtrUtil.h"
|
| -#include "wtf/text/StringBuilder.h"
|
|
|
| namespace blink {
|
|
|
| -namespace {
|
| -
|
| -// Given a string name, return the matching feature struct, or nullptr if it is
|
| -// not the name of a policy-controlled feature.
|
| -const FeaturePolicy::Feature* featureForName(
|
| - const String& featureName,
|
| - FeaturePolicy::FeatureList& features) {
|
| - for (const FeaturePolicy::Feature* feature : features) {
|
| - if (featureName == feature->featureName)
|
| - return feature;
|
| - }
|
| - return nullptr;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -// Definitions of all features controlled by Feature Policy should appear here.
|
| -const FeaturePolicy::Feature kDocumentCookie{
|
| - "cookie", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kDocumentDomain{
|
| - "domain", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kDocumentWrite{
|
| - "docwrite", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kFullscreenFeature{
|
| - "fullscreen", FeaturePolicy::FeatureDefault::EnableForSelf};
|
| -const FeaturePolicy::Feature kGeolocationFeature{
|
| - "geolocation", FeaturePolicy::FeatureDefault::EnableForSelf};
|
| -const FeaturePolicy::Feature kMidiFeature{
|
| - "midi", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kNotificationsFeature{
|
| - "notifications", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kPaymentFeature{
|
| - "payment", FeaturePolicy::FeatureDefault::EnableForSelf};
|
| -const FeaturePolicy::Feature kPushFeature{
|
| - "push", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kSyncScript{
|
| - "sync-script", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kSyncXHR{
|
| - "sync-xhr", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kUsermedia{
|
| - "usermedia", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -const FeaturePolicy::Feature kVibrateFeature{
|
| - "vibrate", FeaturePolicy::FeatureDefault::EnableForSelf};
|
| -const FeaturePolicy::Feature kWebRTC{
|
| - "webrtc", FeaturePolicy::FeatureDefault::EnableForAll};
|
| -
|
| -WebFeaturePolicyFeature FeaturePolicy::getWebFeaturePolicyFeature(
|
| - const String& feature) {
|
| +WebFeaturePolicyFeature getWebFeaturePolicyFeature(const String& feature) {
|
| if (feature == "fullscreen")
|
| return WebFeaturePolicyFeature::Fullscreen;
|
| if (feature == "payment")
|
| @@ -95,127 +46,9 @@ WebFeaturePolicyFeature FeaturePolicy::getWebFeaturePolicyFeature(
|
| return WebFeaturePolicyFeature::NotFound;
|
| }
|
|
|
| -// static
|
| -std::unique_ptr<FeaturePolicy::Whitelist> FeaturePolicy::Whitelist::from(
|
| - const WebParsedFeaturePolicyDeclaration& parsedDeclaration) {
|
| - std::unique_ptr<Whitelist> whitelist(new FeaturePolicy::Whitelist);
|
| - if (parsedDeclaration.matchesAllOrigins) {
|
| - whitelist->addAll();
|
| - } else {
|
| - for (const WebSecurityOrigin& origin : parsedDeclaration.origins)
|
| - whitelist->add(static_cast<WTF::PassRefPtr<SecurityOrigin>>(origin));
|
| - }
|
| - return whitelist;
|
| -}
|
| -
|
| -FeaturePolicy::Whitelist::Whitelist() : m_matchesAllOrigins(false) {}
|
| -
|
| -void FeaturePolicy::Whitelist::addAll() {
|
| - m_matchesAllOrigins = true;
|
| -}
|
| -
|
| -void FeaturePolicy::Whitelist::add(RefPtr<SecurityOrigin> origin) {
|
| - m_origins.push_back(std::move(origin));
|
| -}
|
| -
|
| -bool FeaturePolicy::Whitelist::contains(const SecurityOrigin& origin) const {
|
| - if (m_matchesAllOrigins)
|
| - return true;
|
| - for (const auto& targetOrigin : m_origins) {
|
| - if (targetOrigin->isSameSchemeHostPortAndSuborigin(&origin))
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -String FeaturePolicy::Whitelist::toString() {
|
| - StringBuilder sb;
|
| - sb.append("[");
|
| - if (m_matchesAllOrigins) {
|
| - sb.append("*");
|
| - } else {
|
| - for (size_t i = 0; i < m_origins.size(); ++i) {
|
| - if (i > 0) {
|
| - sb.append(", ");
|
| - }
|
| - sb.append(m_origins[i]->toString());
|
| - }
|
| - }
|
| - sb.append("]");
|
| - return sb.toString();
|
| -}
|
| -
|
| -// static
|
| -const FeaturePolicy::FeatureList& FeaturePolicy::getDefaultFeatureList() {
|
| - DEFINE_STATIC_LOCAL(
|
| - Vector<const FeaturePolicy::Feature*>, defaultFeatureList,
|
| - ({&kDocumentCookie, &kDocumentDomain, &kDocumentWrite,
|
| - &kGeolocationFeature, &kFullscreenFeature, &kMidiFeature,
|
| - &kNotificationsFeature, &kPaymentFeature, &kPushFeature, &kSyncScript,
|
| - &kSyncXHR, &kUsermedia, &kVibrateFeature, &kWebRTC}));
|
| - return defaultFeatureList;
|
| -}
|
| -
|
| -// static
|
| -std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy(
|
| - const FeaturePolicy* parent,
|
| - const WebParsedFeaturePolicyHeader* containerPolicy,
|
| - RefPtr<SecurityOrigin> currentOrigin,
|
| - FeaturePolicy::FeatureList& features) {
|
| - DCHECK(currentOrigin);
|
| - std::unique_ptr<FeaturePolicy> newPolicy =
|
| - WTF::wrapUnique(new FeaturePolicy(currentOrigin, features));
|
| - for (const FeaturePolicy::Feature* feature : features) {
|
| - if (!parent ||
|
| - parent->isFeatureEnabledForOrigin(*feature, *currentOrigin)) {
|
| - newPolicy->m_inheritedFeatures.set(feature, true);
|
| - } else {
|
| - newPolicy->m_inheritedFeatures.set(feature, false);
|
| - }
|
| - }
|
| - if (containerPolicy)
|
| - newPolicy->addContainerPolicy(containerPolicy, parent);
|
| - return newPolicy;
|
| -}
|
| -
|
| -// static
|
| -std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy(
|
| - const FeaturePolicy* parent,
|
| - const WebParsedFeaturePolicyHeader* containerPolicy,
|
| - RefPtr<SecurityOrigin> currentOrigin) {
|
| - return createFromParentPolicy(parent, containerPolicy,
|
| - std::move(currentOrigin),
|
| - getDefaultFeatureList());
|
| -}
|
| -
|
| -void FeaturePolicy::addContainerPolicy(
|
| - const WebParsedFeaturePolicyHeader* containerPolicy,
|
| - const FeaturePolicy* parent) {
|
| - DCHECK(containerPolicy);
|
| - DCHECK(parent);
|
| - for (const WebParsedFeaturePolicyDeclaration& parsedDeclaration :
|
| - *containerPolicy) {
|
| - // If a feature is enabled in the parent frame, and the parent chooses to
|
| - // delegate it to the child frame, using the iframe attribute, then the
|
| - // feature should be enabled in the child frame.
|
| - const FeaturePolicy::Feature* feature =
|
| - featureForName(parsedDeclaration.featureName, m_features);
|
| - if (!feature)
|
| - continue;
|
| - if (Whitelist::from(parsedDeclaration)->contains(*m_origin) &&
|
| - parent->isFeatureEnabled(*feature)) {
|
| - m_inheritedFeatures.set(feature, true);
|
| - } else {
|
| - m_inheritedFeatures.set(feature, false);
|
| - }
|
| - }
|
| -}
|
| -
|
| -// static
|
| -WebParsedFeaturePolicyHeader FeaturePolicy::parseFeaturePolicy(
|
| - const String& policy,
|
| - RefPtr<SecurityOrigin> origin,
|
| - Vector<String>* messages) {
|
| +WebParsedFeaturePolicyHeader parseFeaturePolicy(const String& policy,
|
| + RefPtr<SecurityOrigin> origin,
|
| + Vector<String>* messages) {
|
| Vector<WebParsedFeaturePolicyDeclaration> whitelists;
|
|
|
| // Use a reasonable parse depth limit; the actual maximum depth is only going
|
| @@ -275,69 +108,4 @@ WebParsedFeaturePolicyHeader FeaturePolicy::parseFeaturePolicy(
|
| return whitelists;
|
| }
|
|
|
| -void FeaturePolicy::setHeaderPolicy(
|
| - const WebParsedFeaturePolicyHeader& policy) {
|
| - DCHECK(m_headerWhitelists.isEmpty());
|
| - for (const WebParsedFeaturePolicyDeclaration& parsedDeclaration : policy) {
|
| - const FeaturePolicy::Feature* feature =
|
| - featureForName(parsedDeclaration.featureName, m_features);
|
| - if (!feature)
|
| - continue;
|
| - m_headerWhitelists.set(feature, Whitelist::from(parsedDeclaration));
|
| - }
|
| -}
|
| -
|
| -bool FeaturePolicy::isFeatureEnabledForOrigin(
|
| - const FeaturePolicy::Feature& feature,
|
| - const SecurityOrigin& origin) const {
|
| - DCHECK(m_inheritedFeatures.contains(&feature));
|
| - if (!m_inheritedFeatures.at(&feature)) {
|
| - return false;
|
| - }
|
| - if (m_headerWhitelists.contains(&feature)) {
|
| - return m_headerWhitelists.at(&feature)->contains(origin);
|
| - }
|
| - if (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForAll) {
|
| - return true;
|
| - }
|
| - if (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForSelf) {
|
| - return m_origin->isSameSchemeHostPortAndSuborigin(&origin);
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -bool FeaturePolicy::isFeatureEnabled(
|
| - const FeaturePolicy::Feature& feature) const {
|
| - DCHECK(m_origin);
|
| - return isFeatureEnabledForOrigin(feature, *m_origin);
|
| -}
|
| -
|
| -FeaturePolicy::FeaturePolicy(RefPtr<SecurityOrigin> currentOrigin,
|
| - FeaturePolicy::FeatureList& features)
|
| - : m_origin(std::move(currentOrigin)), m_features(features) {}
|
| -
|
| -String FeaturePolicy::toString() {
|
| - StringBuilder sb;
|
| - sb.append("Feature Policy for frame in origin: ");
|
| - sb.append(m_origin->toString());
|
| - sb.append("\n");
|
| - sb.append("Inherited features:\n");
|
| - for (const auto& inheritedFeature : m_inheritedFeatures) {
|
| - sb.append(" ");
|
| - sb.append(inheritedFeature.key->featureName);
|
| - sb.append(": ");
|
| - sb.append(inheritedFeature.value ? "true" : "false");
|
| - sb.append("\n");
|
| - }
|
| - sb.append("Header whitelists:\n");
|
| - for (const auto& whitelist : m_headerWhitelists) {
|
| - sb.append(" ");
|
| - sb.append(whitelist.key->featureName);
|
| - sb.append(": ");
|
| - sb.append(whitelist.value->toString());
|
| - sb.append("\n");
|
| - }
|
| - return sb.toString();
|
| -}
|
| -
|
| } // namespace blink
|
|
|