Skip to content
Permalink
Browse files
Add ReferrerPolicy to the PolicyContainer
https://bugs.webkit.org/show_bug.cgi?id=244561

Reviewed by Brent Fulgham.

The HTML spec calls for ReferrerPolicy to be in the PolicyContainer
struct.[1] This adds the ReferrerPolicy enum to the PolicyContainer
struct to keep our implementation more in line with the spec.

This also shuffles around the virtual referrerPolicy getter so the
SecurityContext can construct a PolicyContainer given the implementation
from its subclasses.

No new tests, ReferrerPolicy already covered by existing tests.

[1] https://html.spec.whatwg.org/multipage/origin.html#policy-containers

* Source/WebCore/dom/ScriptExecutionContext.h:
* Source/WebCore/dom/SecurityContext.cpp:
(WebCore::SecurityContext::policyContainer const):
* Source/WebCore/dom/SecurityContext.h:
* Source/WebCore/loader/PolicyContainer.h:
(WebCore::PolicyContainer::isolatedCopy const):
(WebCore::PolicyContainer::isolatedCopy):
(WebCore::operator==):
(WebCore::PolicyContainer::encode const):
(WebCore::PolicyContainer::decode):

Canonical link: https://commits.webkit.org/254003@main
  • Loading branch information
rreno authored and Brent Fulgham committed Aug 31, 2022
1 parent 3950cf6 commit ea311869338ebe3af77d0ba9a935442816954bcf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
@@ -78,7 +78,6 @@ class ResourceRequest;
class SocketProvider;
class WebCoreOpaqueRoot;
enum class LoadedFromOpaqueSource : uint8_t;
enum class ReferrerPolicy : uint8_t;
enum class TaskSource : uint8_t;

#if ENABLE(NOTIFICATIONS)
@@ -115,8 +114,6 @@ class ScriptExecutionContext : public SecurityContext, public CanMakeWeakPtr<Scr

virtual String userAgent(const URL&) const = 0;

virtual ReferrerPolicy referrerPolicy() const = 0;

virtual const Settings::Values& settingsValues() const = 0;

virtual NotificationClient* notificationClient() { return nullptr; }
@@ -174,7 +174,8 @@ PolicyContainer SecurityContext::policyContainer() const
{
return {
crossOriginEmbedderPolicy(),
crossOriginOpenerPolicy()
crossOriginOpenerPolicy(),
referrerPolicy()
};
}

@@ -40,6 +40,7 @@ class SecurityOriginPolicy;
class ContentSecurityPolicy;
struct CrossOriginOpenerPolicy;
struct PolicyContainer;
enum class ReferrerPolicy : uint8_t;

enum SandboxFlag {
// See http://www.whatwg.org/specs/web-apps/current-work/#attr-iframe-sandbox for a list of the sandbox flags.
@@ -96,6 +97,8 @@ class SecurityContext {

virtual const CrossOriginOpenerPolicy& crossOriginOpenerPolicy() const;

virtual ReferrerPolicy referrerPolicy() const = 0;

PolicyContainer policyContainer() const;

WEBCORE_EXPORT SecurityOrigin* securityOrigin() const;
@@ -34,23 +34,24 @@ namespace WebCore {
struct PolicyContainer {
CrossOriginEmbedderPolicy crossOriginEmbedderPolicy;
CrossOriginOpenerPolicy crossOriginOpenerPolicy;
// FIXME: CSP list and referrer policy should be part of the PolicyContainer.
ReferrerPolicy referrerPolicy = ReferrerPolicy::Default;
// FIXME: CSP list should be part of the PolicyContainer.

PolicyContainer isolatedCopy() const & { return { crossOriginEmbedderPolicy.isolatedCopy(), crossOriginOpenerPolicy.isolatedCopy() }; }
PolicyContainer isolatedCopy() && { return { WTFMove(crossOriginEmbedderPolicy).isolatedCopy(), WTFMove(crossOriginOpenerPolicy).isolatedCopy() }; }
PolicyContainer isolatedCopy() const & { return { crossOriginEmbedderPolicy.isolatedCopy(), crossOriginOpenerPolicy.isolatedCopy(), referrerPolicy }; }
PolicyContainer isolatedCopy() && { return { WTFMove(crossOriginEmbedderPolicy).isolatedCopy(), WTFMove(crossOriginOpenerPolicy).isolatedCopy(), referrerPolicy }; }
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<PolicyContainer> decode(Decoder&);
};

inline bool operator==(const PolicyContainer& a, const PolicyContainer& b)
{
return a.crossOriginEmbedderPolicy == b.crossOriginEmbedderPolicy && a.crossOriginOpenerPolicy == b.crossOriginOpenerPolicy;
return a.crossOriginEmbedderPolicy == b.crossOriginEmbedderPolicy && a.crossOriginOpenerPolicy == b.crossOriginOpenerPolicy && a.referrerPolicy == b.referrerPolicy;
}

template<class Encoder>
void PolicyContainer::encode(Encoder& encoder) const
{
encoder << crossOriginEmbedderPolicy << crossOriginOpenerPolicy;
encoder << crossOriginEmbedderPolicy << crossOriginOpenerPolicy << referrerPolicy;
}

template<class Decoder>
@@ -66,9 +67,15 @@ std::optional<PolicyContainer> PolicyContainer::decode(Decoder& decoder)
if (!crossOriginOpenerPolicy)
return std::nullopt;

std::optional<ReferrerPolicy> referrerPolicy;
decoder >> referrerPolicy;
if (!referrerPolicy)
return std::nullopt;

return {{
WTFMove(*crossOriginEmbedderPolicy),
WTFMove(*crossOriginOpenerPolicy)
WTFMove(*crossOriginOpenerPolicy),
*referrerPolicy
}};
}

0 comments on commit ea31186

Please sign in to comment.