Commit 4907629e authored by qi1988.yang's avatar qi1988.yang Committed by Commit Bot

Rename FeaturePolicy::Whitelist to "Allowlist"

Fix the TODO(crbug.com/822317): Rename to Allowlist

Bug:822317
Signed-off-by: default avatarqi1988.yang <qi1988.yang@samsung.com>
Change-Id: I1dd676fd5953b4cfc90e6b24d75ab9e3d69bc4da
Reviewed-on: https://chromium-review.googlesource.com/968043Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Reviewed-by: default avatarLuna Lu <loonybear@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Commit-Queue: Philip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544685}
parent 9b372f07
...@@ -52,16 +52,16 @@ Vector<String> Policy::allowedFeatures() const { ...@@ -52,16 +52,16 @@ Vector<String> Policy::allowedFeatures() const {
Vector<String> Policy::getAllowlistForFeature(const String& feature) const { Vector<String> Policy::getAllowlistForFeature(const String& feature) const {
if (GetDefaultFeatureNameMap().Contains(feature)) { if (GetDefaultFeatureNameMap().Contains(feature)) {
const FeaturePolicy::Whitelist whitelist = const FeaturePolicy::Allowlist allowlist =
GetPolicy()->GetWhitelistForFeature( GetPolicy()->GetAllowlistForFeature(
GetDefaultFeatureNameMap().at(feature)); GetDefaultFeatureNameMap().at(feature));
if (whitelist.MatchesAll()) if (allowlist.MatchesAll())
return Vector<String>({"*"}); return Vector<String>({"*"});
Vector<String> allowlist; Vector<String> result;
for (const auto& origin : whitelist.Origins()) { for (const auto& origin : allowlist.Origins()) {
allowlist.push_back(WTF::String::FromUTF8(origin.Serialize().c_str())); result.push_back(WTF::String::FromUTF8(origin.Serialize().c_str()));
} }
return allowlist; return result;
} }
AddWarningForUnrecognizedFeature(feature); AddWarningForUnrecognizedFeature(feature);
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
namespace blink { namespace blink {
namespace { namespace {
// Extracts a Whitelist from a ParsedFeaturePolicyDeclaration. // Extracts an Allowlist from a ParsedFeaturePolicyDeclaration.
std::unique_ptr<FeaturePolicy::Whitelist> WhitelistFromDeclaration( std::unique_ptr<FeaturePolicy::Allowlist> AllowlistFromDeclaration(
const ParsedFeaturePolicyDeclaration& parsed_declaration) { const ParsedFeaturePolicyDeclaration& parsed_declaration) {
std::unique_ptr<FeaturePolicy::Whitelist> result = std::unique_ptr<FeaturePolicy::Allowlist> result =
base::WrapUnique(new FeaturePolicy::Whitelist()); base::WrapUnique(new FeaturePolicy::Allowlist());
if (parsed_declaration.matches_all_origins) if (parsed_declaration.matches_all_origins)
result->AddAll(); result->AddAll();
for (const auto& origin : parsed_declaration.origins) for (const auto& origin : parsed_declaration.origins)
...@@ -49,30 +49,30 @@ bool operator==(const ParsedFeaturePolicyDeclaration& lhs, ...@@ -49,30 +49,30 @@ bool operator==(const ParsedFeaturePolicyDeclaration& lhs,
// This method returns true only when the arguments are actually identical, // This method returns true only when the arguments are actually identical,
// including the order of elements in the origins vector. // including the order of elements in the origins vector.
// TODO(iclelland): Consider making this return true when comparing equal- // TODO(iclelland): Consider making this return true when comparing equal-
// but-not-identical whitelists, or eliminate those comparisons by maintaining // but-not-identical allowlists, or eliminate those comparisons by maintaining
// the whiteslists in a normalized form. // the allowlists in a normalized form.
// https://crbug.com/710324 // https://crbug.com/710324
return std::tie(lhs.feature, lhs.matches_all_origins, lhs.origins) == return std::tie(lhs.feature, lhs.matches_all_origins, lhs.origins) ==
std::tie(rhs.feature, rhs.matches_all_origins, rhs.origins); std::tie(rhs.feature, rhs.matches_all_origins, rhs.origins);
} }
FeaturePolicy::Whitelist::Whitelist() : matches_all_origins_(false) {} FeaturePolicy::Allowlist::Allowlist() : matches_all_origins_(false) {}
FeaturePolicy::Whitelist::Whitelist(const Whitelist& rhs) = default; FeaturePolicy::Allowlist::Allowlist(const Allowlist& rhs) = default;
FeaturePolicy::Whitelist::~Whitelist() = default; FeaturePolicy::Allowlist::~Allowlist() = default;
void FeaturePolicy::Whitelist::Add(const url::Origin& origin) { void FeaturePolicy::Allowlist::Add(const url::Origin& origin) {
origins_.push_back(origin); origins_.push_back(origin);
} }
void FeaturePolicy::Whitelist::AddAll() { void FeaturePolicy::Allowlist::AddAll() {
matches_all_origins_ = true; matches_all_origins_ = true;
} }
bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const { bool FeaturePolicy::Allowlist::Contains(const url::Origin& origin) const {
// This does not handle the case where origin is an opaque origin, which is // This does not handle the case where origin is an opaque origin, which is
// also supposed to exist in the whitelist. (The identical opaque origins // also supposed to exist in the allowlist. (The identical opaque origins
// should match in that case) // should match in that case)
// TODO(iclelland): Fix that, possibly by having another flag for // TODO(iclelland): Fix that, possibly by having another flag for
// 'matches_self', which will explicitly match the policy's origin. // 'matches_self', which will explicitly match the policy's origin.
...@@ -86,11 +86,11 @@ bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const { ...@@ -86,11 +86,11 @@ bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const {
return false; return false;
} }
bool FeaturePolicy::Whitelist::MatchesAll() const { bool FeaturePolicy::Allowlist::MatchesAll() const {
return matches_all_origins_; return matches_all_origins_;
} }
const std::vector<url::Origin>& FeaturePolicy::Whitelist::Origins() const { const std::vector<url::Origin>& FeaturePolicy::Allowlist::Origins() const {
return origins_; return origins_;
} }
...@@ -110,9 +110,9 @@ std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromPolicyWithOrigin( ...@@ -110,9 +110,9 @@ std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromPolicyWithOrigin(
std::unique_ptr<FeaturePolicy> new_policy = std::unique_ptr<FeaturePolicy> new_policy =
base::WrapUnique(new FeaturePolicy(origin, policy.feature_list_)); base::WrapUnique(new FeaturePolicy(origin, policy.feature_list_));
new_policy->inherited_policies_ = policy.inherited_policies_; new_policy->inherited_policies_ = policy.inherited_policies_;
for (const auto& feature : policy.whitelists_) { for (const auto& feature : policy.allowlists_) {
new_policy->whitelists_[feature.first] = new_policy->allowlists_[feature.first] =
base::WrapUnique(new Whitelist(*feature.second)); base::WrapUnique(new Allowlist(*feature.second));
} }
return new_policy; return new_policy;
} }
...@@ -129,9 +129,9 @@ bool FeaturePolicy::IsFeatureEnabledForOrigin( ...@@ -129,9 +129,9 @@ bool FeaturePolicy::IsFeatureEnabledForOrigin(
DCHECK(base::ContainsKey(inherited_policies_, feature)); DCHECK(base::ContainsKey(inherited_policies_, feature));
if (!inherited_policies_.at(feature)) if (!inherited_policies_.at(feature))
return false; return false;
auto whitelist = whitelists_.find(feature); auto allowlist = allowlists_.find(feature);
if (whitelist != whitelists_.end()) if (allowlist != allowlists_.end())
return whitelist->second->Contains(origin); return allowlist->second->Contains(origin);
const FeaturePolicy::FeatureDefault default_policy = const FeaturePolicy::FeatureDefault default_policy =
feature_list_.at(feature); feature_list_.at(feature);
...@@ -146,37 +146,37 @@ bool FeaturePolicy::IsFeatureEnabledForOrigin( ...@@ -146,37 +146,37 @@ bool FeaturePolicy::IsFeatureEnabledForOrigin(
return false; return false;
} }
const FeaturePolicy::Whitelist FeaturePolicy::GetWhitelistForFeature( const FeaturePolicy::Allowlist FeaturePolicy::GetAllowlistForFeature(
mojom::FeaturePolicyFeature feature) const { mojom::FeaturePolicyFeature feature) const {
DCHECK(base::ContainsKey(feature_list_, feature)); DCHECK(base::ContainsKey(feature_list_, feature));
DCHECK(base::ContainsKey(inherited_policies_, feature)); DCHECK(base::ContainsKey(inherited_policies_, feature));
// Disabled through inheritance. // Disabled through inheritance.
if (!inherited_policies_.at(feature)) if (!inherited_policies_.at(feature))
return FeaturePolicy::Whitelist(); return FeaturePolicy::Allowlist();
// Return defined policy if exists; otherwise return default policy. // Return defined policy if exists; otherwise return default policy.
auto whitelist = whitelists_.find(feature); auto allowlist = allowlists_.find(feature);
if (whitelist != whitelists_.end()) if (allowlist != allowlists_.end())
return FeaturePolicy::Whitelist(*(whitelist->second)); return FeaturePolicy::Allowlist(*(allowlist->second));
const FeaturePolicy::FeatureDefault default_policy = const FeaturePolicy::FeatureDefault default_policy =
feature_list_.at(feature); feature_list_.at(feature);
FeaturePolicy::Whitelist default_whitelist; FeaturePolicy::Allowlist default_allowlist;
if (default_policy == FeaturePolicy::FeatureDefault::EnableForAll) if (default_policy == FeaturePolicy::FeatureDefault::EnableForAll)
default_whitelist.AddAll(); default_allowlist.AddAll();
else if (default_policy == FeaturePolicy::FeatureDefault::EnableForSelf) else if (default_policy == FeaturePolicy::FeatureDefault::EnableForSelf)
default_whitelist.Add(origin_); default_allowlist.Add(origin_);
return default_whitelist; return default_allowlist;
} }
void FeaturePolicy::SetHeaderPolicy(const ParsedFeaturePolicy& parsed_header) { void FeaturePolicy::SetHeaderPolicy(const ParsedFeaturePolicy& parsed_header) {
DCHECK(whitelists_.empty()); DCHECK(allowlists_.empty());
for (const ParsedFeaturePolicyDeclaration& parsed_declaration : for (const ParsedFeaturePolicyDeclaration& parsed_declaration :
parsed_header) { parsed_header) {
mojom::FeaturePolicyFeature feature = parsed_declaration.feature; mojom::FeaturePolicyFeature feature = parsed_declaration.feature;
DCHECK(feature != mojom::FeaturePolicyFeature::kNotFound); DCHECK(feature != mojom::FeaturePolicyFeature::kNotFound);
whitelists_[feature] = WhitelistFromDeclaration(parsed_declaration); allowlists_[feature] = AllowlistFromDeclaration(parsed_declaration);
} }
} }
...@@ -226,7 +226,7 @@ void FeaturePolicy::AddContainerPolicy( ...@@ -226,7 +226,7 @@ void FeaturePolicy::AddContainerPolicy(
mojom::FeaturePolicyFeature feature = parsed_declaration.feature; mojom::FeaturePolicyFeature feature = parsed_declaration.feature;
if (feature == mojom::FeaturePolicyFeature::kNotFound) if (feature == mojom::FeaturePolicyFeature::kNotFound)
continue; continue;
if (WhitelistFromDeclaration(parsed_declaration)->Contains(origin_) && if (AllowlistFromDeclaration(parsed_declaration)->Contains(origin_) &&
parent_policy->IsFeatureEnabled(feature)) { parent_policy->IsFeatureEnabled(feature)) {
inherited_policies_[feature] = true; inherited_policies_[feature] = true;
} else { } else {
......
...@@ -113,12 +113,11 @@ class BLINK_COMMON_EXPORT FeaturePolicy { ...@@ -113,12 +113,11 @@ class BLINK_COMMON_EXPORT FeaturePolicy {
// policy. This collection may be set to match every origin (corresponding to // policy. This collection may be set to match every origin (corresponding to
// the "*" syntax in the policy string, in which case the Contains() method // the "*" syntax in the policy string, in which case the Contains() method
// will always return true. // will always return true.
// TODO(crbug.com/822317): Rename to Allowlist class BLINK_COMMON_EXPORT Allowlist final {
class BLINK_COMMON_EXPORT Whitelist final {
public: public:
Whitelist(); Allowlist();
Whitelist(const Whitelist& rhs); Allowlist(const Allowlist& rhs);
~Whitelist(); ~Allowlist();
// Adds a single origin to the allowlist. // Adds a single origin to the allowlist.
void Add(const url::Origin& origin); void Add(const url::Origin& origin);
...@@ -180,7 +179,7 @@ class BLINK_COMMON_EXPORT FeaturePolicy { ...@@ -180,7 +179,7 @@ class BLINK_COMMON_EXPORT FeaturePolicy {
const url::Origin& origin) const; const url::Origin& origin) const;
// Returns the allowlist of a given feature by this policy. // Returns the allowlist of a given feature by this policy.
const Whitelist GetWhitelistForFeature( const Allowlist GetAllowlistForFeature(
mojom::FeaturePolicyFeature feature) const; mojom::FeaturePolicyFeature feature) const;
// Sets the declared policy from the parsed Feature-Policy HTTP header. // Sets the declared policy from the parsed Feature-Policy HTTP header.
...@@ -212,7 +211,7 @@ class BLINK_COMMON_EXPORT FeaturePolicy { ...@@ -212,7 +211,7 @@ class BLINK_COMMON_EXPORT FeaturePolicy {
// Map of feature names to declared allowlists. Any feature which is missing // Map of feature names to declared allowlists. Any feature which is missing
// from this map should use the inherited policy. // from this map should use the inherited policy.
std::map<mojom::FeaturePolicyFeature, std::unique_ptr<Whitelist>> whitelists_; std::map<mojom::FeaturePolicyFeature, std::unique_ptr<Allowlist>> allowlists_;
// Records whether or not each feature was enabled for this frame by its // Records whether or not each feature was enabled for this frame by its
// parent frame. // parent frame.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment