Commit b7398679 authored by Antonio Sartori's avatar Antonio Sartori Committed by Commit Bot

Refactor policy data in PolicyContainerHost

The content::PolicyContainerHost is a class containing some policy
data and implementing a mojo interface to change that data. As we add
more policies to the PolicyContainerHost, it becomes cleaner to
separate the raw data (the policies) into a separate struct
(DocumentPolicies), which the PolicyContainerHost owns. This will also
make it easier to store the DocumentPolicies in places where we don't
need the mojo logic (for example, in the FrameNavigationEntry).

Bug: 1130587
Change-Id: Ic46a3189f9f6939fbdb279916a9c1288942ce271
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529165
Commit-Queue: Antonio Sartori <antoniosartori@chromium.org>
Reviewed-by: default avatarPâris Meuleman <pmeuleman@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826782}
parent 464810d2
......@@ -8,13 +8,13 @@ namespace content {
PolicyContainerHost::PolicyContainerHost() = default;
PolicyContainerHost::PolicyContainerHost(
network::mojom::ReferrerPolicy referrer_policy)
: referrer_policy_(referrer_policy) {}
PolicyContainerHost::DocumentPolicies document_policies)
: document_policies_(document_policies) {}
PolicyContainerHost::~PolicyContainerHost() = default;
void PolicyContainerHost::SetReferrerPolicy(
network::mojom::ReferrerPolicy referrer_policy) {
referrer_policy_ = referrer_policy;
document_policies_.referrer_policy = referrer_policy;
}
blink::mojom::PolicyContainerPtr
......@@ -28,14 +28,13 @@ PolicyContainerHost::CreatePolicyContainerForBlink() {
// received before we try to create a new remote.
policy_container_host_receiver_.reset();
return blink::mojom::PolicyContainer::New(
blink::mojom::PolicyContainerDocumentPolicies::New(referrer_policy_),
blink::mojom::PolicyContainerDocumentPolicies::New(
document_policies_.referrer_policy),
policy_container_host_receiver_.BindNewEndpointAndPassRemote());
}
std::unique_ptr<PolicyContainerHost> PolicyContainerHost::Clone() const {
std::unique_ptr<PolicyContainerHost> copy =
std::make_unique<PolicyContainerHost>(referrer_policy_);
return copy;
return std::make_unique<PolicyContainerHost>(document_policies_);
}
void PolicyContainerHost::Bind(
......
......@@ -17,33 +17,46 @@ namespace content {
// should be owned by a RenderFrameHost. It keep tracks of the policies assigned
// to a document. When a document creates/opens another document with a local
// scheme (about:blank, about:srcdoc, data, blob, filesystem), the
// PolicyContainerhost of the opener is cloned and a copy is attached to the new
// PolicyContainerHost of the opener is cloned and a copy is attached to the new
// document, so that the same security policies are applied to it. It implements
// a mojo interface that allows updates coming from Blink.
class CONTENT_EXPORT PolicyContainerHost
: public blink::mojom::PolicyContainerHost {
public:
struct DocumentPolicies {
// The referrer policy for the associated document. If not overwritten via a
// call to SetReferrerPolicy (for example after parsing the Referrer-Policy
// header or a meta tag), the default referrer policy will be applied to the
// document.
network::mojom::ReferrerPolicy referrer_policy =
network::mojom::ReferrerPolicy::kDefault;
};
PolicyContainerHost();
explicit PolicyContainerHost(network::mojom::ReferrerPolicy referrer_policy);
explicit PolicyContainerHost(DocumentPolicies document_policies);
PolicyContainerHost(const PolicyContainerHost&) = delete;
PolicyContainerHost& operator=(const PolicyContainerHost&) = delete;
~PolicyContainerHost() override;
network::mojom::ReferrerPolicy referrer_policy() const {
return referrer_policy_;
return document_policies_.referrer_policy;
}
const DocumentPolicies& document_policies() const {
return document_policies_;
}
// Return a PolicyContainer, containing copies of the policies and a
// pending mojo remote that can be used to update policies in this object. If
// called a second time, it resets the receiver and creates a new
// PolicyContainer, invalidating the remote of the previous one.
// Return a PolicyContainer containing copies of the policies and a pending
// mojo remote that can be used to update policies in this object. If called a
// second time, it resets the receiver and creates a new PolicyContainer,
// invalidating the remote of the previous one.
blink::mojom::PolicyContainerPtr CreatePolicyContainerForBlink();
// Create a new PolicyContainer with the same policies (i.e. a deep copy), but
// with a new, unbound mojo receiver.
// Create a new PolicyContainerHost with the same policies (i.e. a deep copy),
// but with a new, unbound mojo receiver.
std::unique_ptr<PolicyContainerHost> Clone() const;
// Bind this PolicyContainer with the given mojo receiver, so that it can
// Bind this PolicyContainerHost with the given mojo receiver, so that it can
// handle mojo messages coming from the corresponding remote.
void Bind(mojo::PendingAssociatedReceiver<blink::mojom::PolicyContainerHost>
receiver);
......@@ -51,12 +64,7 @@ class CONTENT_EXPORT PolicyContainerHost
private:
void SetReferrerPolicy(network::mojom::ReferrerPolicy referrer_policy) final;
// The referrer policy for the associated document. If not overwritten via a
// call to SetReferrerPolicy (for example after parsing the Referrer-Policy
// header or a meta tag), the default referrer policy will be applied to the
// document.
network::mojom::ReferrerPolicy referrer_policy_ =
network::mojom::ReferrerPolicy::kDefault;
DocumentPolicies document_policies_;
mojo::AssociatedReceiver<blink::mojom::PolicyContainerHost>
policy_container_host_receiver_{this};
......
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