Commit 3f978485 authored by Charlie Hu's avatar Charlie Hu Committed by Commit Bot

Replace ParsedFeaturePolicy with FeatureState

This CL removes ParsedFeaturePolicy and several helper functions that
are not used in later implementation.

Change-Id: I650013086fff1fcd56ad0b7b3d6d0e5373026197
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1943621Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Commit-Queue: Charlie Hu <chenleihu@google.com>
Cr-Commit-Position: refs/heads/master@{#720272}
parent 6cb48f44
......@@ -62,25 +62,6 @@ bool DocumentPolicy::IsFeatureSupported(
}
}
void DocumentPolicy::SetHeaderPolicy(
const ParsedDocumentPolicy& parsed_header) {
for (const ParsedDocumentPolicyDeclaration& parsed_declaration :
parsed_header) {
mojom::FeaturePolicyFeature feature = parsed_declaration.feature;
// TODO(iclelland): Generate this switch block
switch (feature) {
case mojom::FeaturePolicyFeature::kFontDisplay:
font_display_ = parsed_declaration.value.BoolValue();
break;
case mojom::FeaturePolicyFeature::kUnoptimizedLosslessImages:
unoptimized_lossless_images_ = parsed_declaration.value.DoubleValue();
break;
default:
NOTREACHED();
}
}
}
void DocumentPolicy::UpdateFeatureState(const FeatureState& feature_state) {
for (const auto& feature_and_value : feature_state) {
// TODO(iclelland): Generate this switch block
......@@ -136,30 +117,14 @@ const DocumentPolicy::FeatureState& DocumentPolicy::GetFeatureDefaults() {
}
bool DocumentPolicy::IsPolicyCompatible(
const ParsedDocumentPolicy& required_policy) {
FeatureState p_map = ParsedDocumentPolicyToFeatureState(RequiredPolicy());
for (const ParsedDocumentPolicyDeclaration& req_p : required_policy) {
const DocumentPolicy::FeatureState& incoming_policy) {
const DocumentPolicy::FeatureState& state = GetFeatureState();
for (const auto& e : incoming_policy) {
// feature value > threshold => enabled
// value_a > value_b => value_a looser than value_b
if (p_map[req_p.feature] > req_p.value)
// value_a > value_b => value_a less strict than value_b
if (state.at(e.first) > e.second)
return false;
}
return true;
}
// static
DocumentPolicy::FeatureState DocumentPolicy::ParsedDocumentPolicyToFeatureState(
const ParsedDocumentPolicy& policies) {
FeatureState result;
for (const ParsedDocumentPolicyDeclaration& policy : policies)
result[policy.feature] = policy.value;
return result;
}
ParsedDocumentPolicy DocumentPolicy::RequiredPolicy() const {
// TODO(iclelland): This is currently a placeholder.
// To be implemented later.
return ParsedDocumentPolicy();
}
} // namespace blink
......@@ -64,13 +64,6 @@ namespace blink {
// Each defined feature has a default policy, which determines the threshold
// value to use when no policy has been declared.
struct BLINK_COMMON_EXPORT ParsedDocumentPolicyDeclaration {
mojom::FeaturePolicyFeature feature;
PolicyValue value;
};
using ParsedDocumentPolicy = std::vector<ParsedDocumentPolicyDeclaration>;
class BLINK_COMMON_EXPORT DocumentPolicy {
public:
using FeatureState = std::map<mojom::FeaturePolicyFeature, PolicyValue>;
......@@ -97,21 +90,14 @@ class BLINK_COMMON_EXPORT DocumentPolicy {
// Returns the value of the given feature on the given origin.
PolicyValue GetFeatureValue(mojom::FeaturePolicyFeature feature) const;
// Sets the declared policy from the parsed Document-Policy HTTP header.
// Unrecognized features will be ignored.
void SetHeaderPolicy(const ParsedDocumentPolicy& parsed_header);
// Returns the current threshold values assigned to all document policies.
// the declared header policy as well as any unadvertised required policies
// (such as sandbox policies).
FeatureState GetFeatureState() const;
// Returns the required policy to advertise for an outgoing HTTP request.
ParsedDocumentPolicy RequiredPolicy() const;
// Returns true if this document policy is compatible with the given required
// policy.
bool IsPolicyCompatible(const ParsedDocumentPolicy& required_policy);
// Returns true if this document policy is compatible with the incoming
// document policy.
bool IsPolicyCompatible(const FeatureState& incoming_policy);
// Returns the list of features which can be controlled by Document Policy,
// and their default values.
......@@ -127,9 +113,6 @@ class BLINK_COMMON_EXPORT DocumentPolicy {
void UpdateFeatureState(const FeatureState& feature_state);
static FeatureState ParsedDocumentPolicyToFeatureState(
const ParsedDocumentPolicy& policies);
// Threshold values for each defined feature.
// TODO(iclelland): Generate these members; pack booleans in bitfields if
// possible.
......
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