Commit 9b85bdd1 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Remove Document::GetContentSecurityPolicyDelegate(), use the LocalDOMWindow variant

Bug: 1029822
Change-Id: I3b14ea528a0b82ca79a63566921d3c72abb141c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2233493
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Auto-Submit: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776348}
parent 3362188c
...@@ -1069,10 +1069,6 @@ PublicURLManager& Document::GetPublicURLManager() { ...@@ -1069,10 +1069,6 @@ PublicURLManager& Document::GetPublicURLManager() {
return GetExecutionContext()->GetPublicURLManager(); return GetExecutionContext()->GetPublicURLManager();
} }
ContentSecurityPolicyDelegate& Document::GetContentSecurityPolicyDelegate() {
return GetExecutionContext()->GetContentSecurityPolicyDelegate();
}
SecureContextMode Document::GetSecureContextMode() const { SecureContextMode Document::GetSecureContextMode() const {
return GetSecurityContext().GetSecureContextMode(); return GetSecurityContext().GetSecureContextMode();
} }
...@@ -7248,7 +7244,7 @@ FontMatchingMetrics* Document::GetFontMatchingMetrics() { ...@@ -7248,7 +7244,7 @@ FontMatchingMetrics* Document::GetFontMatchingMetrics() {
void Document::InitContentSecurityPolicy(ContentSecurityPolicy* csp) { void Document::InitContentSecurityPolicy(ContentSecurityPolicy* csp) {
GetSecurityContext().SetContentSecurityPolicy(csp); GetSecurityContext().SetContentSecurityPolicy(csp);
GetContentSecurityPolicy()->BindToDelegate( GetContentSecurityPolicy()->BindToDelegate(
GetContentSecurityPolicyDelegate()); GetExecutionContext()->GetContentSecurityPolicyDelegate());
} }
void Document::InitSecurityContext(const DocumentInit& initializer) { void Document::InitSecurityContext(const DocumentInit& initializer) {
...@@ -7287,7 +7283,7 @@ void Document::InitSecurityContext(const DocumentInit& initializer) { ...@@ -7287,7 +7283,7 @@ void Document::InitSecurityContext(const DocumentInit& initializer) {
void Document::BindContentSecurityPolicy() { void Document::BindContentSecurityPolicy() {
DCHECK(!GetContentSecurityPolicy()->IsBound()); DCHECK(!GetContentSecurityPolicy()->IsBound());
GetContentSecurityPolicy()->BindToDelegate( GetContentSecurityPolicy()->BindToDelegate(
GetContentSecurityPolicyDelegate()); GetExecutionContext()->GetContentSecurityPolicyDelegate());
} }
bool Document::AllowInlineEventHandler(Node* node, bool Document::AllowInlineEventHandler(Node* node,
......
...@@ -350,7 +350,6 @@ class CORE_EXPORT Document : public ContainerNode, ...@@ -350,7 +350,6 @@ class CORE_EXPORT Document : public ContainerNode,
network::mojom::blink::WebSandboxFlags GetSandboxFlags() const; network::mojom::blink::WebSandboxFlags GetSandboxFlags() const;
bool IsSandboxed(network::mojom::blink::WebSandboxFlags mask) const; bool IsSandboxed(network::mojom::blink::WebSandboxFlags mask) const;
PublicURLManager& GetPublicURLManager(); PublicURLManager& GetPublicURLManager();
ContentSecurityPolicyDelegate& GetContentSecurityPolicyDelegate();
SecureContextMode GetSecureContextMode() const; SecureContextMode GetSecureContextMode() const;
bool IsSecureContext() const; bool IsSecureContext() const;
bool IsSecureContext(String& error_message) const; bool IsSecureContext(String& error_message) const;
......
...@@ -1138,7 +1138,7 @@ void ContentSecurityPolicy::ReportViolation( ...@@ -1138,7 +1138,7 @@ void ContentSecurityPolicy::ReportViolation(
// |delegate_|. // |delegate_|.
ContentSecurityPolicyDelegate* relevant_delegate = ContentSecurityPolicyDelegate* relevant_delegate =
context_frame context_frame
? &context_frame->GetDocument()->GetContentSecurityPolicyDelegate() ? &context_frame->DomWindow()->GetContentSecurityPolicyDelegate()
: delegate_.Get(); : delegate_.Get();
DCHECK(relevant_delegate); DCHECK(relevant_delegate);
GatherSecurityPolicyViolationEventData( GatherSecurityPolicyViolationEventData(
...@@ -1219,7 +1219,7 @@ void ContentSecurityPolicy::PostViolationReport( ...@@ -1219,7 +1219,7 @@ void ContentSecurityPolicy::PostViolationReport(
bool is_frame_ancestors_violation = !!context_frame; bool is_frame_ancestors_violation = !!context_frame;
ContentSecurityPolicyDelegate* relevant_delegate = ContentSecurityPolicyDelegate* relevant_delegate =
is_frame_ancestors_violation is_frame_ancestors_violation
? &context_frame->GetDocument()->GetContentSecurityPolicyDelegate() ? &context_frame->DomWindow()->GetContentSecurityPolicyDelegate()
: delegate_.Get(); : delegate_.Get();
DCHECK(relevant_delegate); DCHECK(relevant_delegate);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_init.h" #include "third_party/blink/renderer/core/dom/document_init.h"
#include "third_party/blink/renderer/core/frame/csp/csp_directive_list.h" #include "third_party/blink/renderer/core/frame/csp/csp_directive_list.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/html_script_element.h" #include "third_party/blink/renderer/core/html/html_script_element.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/testing/null_execution_context.h" #include "third_party/blink/renderer/core/testing/null_execution_context.h"
...@@ -85,7 +86,7 @@ TEST_F(ContentSecurityPolicyTest, ParseInsecureRequestPolicy) { ...@@ -85,7 +86,7 @@ TEST_F(ContentSecurityPolicyTest, ParseInsecureRequestPolicy) {
security_context.SetSecurityOriginForTesting(secure_origin); security_context.SetSecurityOriginForTesting(secure_origin);
csp->BindToDelegate( csp->BindToDelegate(
dummy->GetDocument().GetContentSecurityPolicyDelegate()); dummy->GetFrame().DomWindow()->GetContentSecurityPolicyDelegate());
EXPECT_EQ(test.expected_policy, EXPECT_EQ(test.expected_policy,
security_context.GetInsecureRequestPolicy()); security_context.GetInsecureRequestPolicy());
bool expect_upgrade = bool expect_upgrade =
...@@ -414,8 +415,8 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) { ...@@ -414,8 +415,8 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) {
// We need document for HTMLScriptElement tests. // We need document for HTMLScriptElement tests.
auto dummy = std::make_unique<DummyPageHolder>(); auto dummy = std::make_unique<DummyPageHolder>();
auto& document = dummy->GetDocument(); auto* window = dummy->GetFrame().DomWindow();
document.GetSecurityContext().SetSecurityOriginForTesting(secure_origin); window->GetSecurityContext().SetSecurityOriginForTesting(secure_origin);
for (const auto& test : cases) { for (const auto& test : cases) {
SCOPED_TRACE(testing::Message() << "Policy: `" << test.policy SCOPED_TRACE(testing::Message() << "Policy: `" << test.policy
...@@ -423,12 +424,12 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) { ...@@ -423,12 +424,12 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) {
unsigned expected_reports = test.allowed ? 0u : 1u; unsigned expected_reports = test.allowed ? 0u : 1u;
auto* element = MakeGarbageCollected<HTMLScriptElement>( auto* element = MakeGarbageCollected<HTMLScriptElement>(
document, CreateElementFlags::ByParser()); *window->document(), CreateElementFlags::ByParser());
// Enforce 'script-src' // Enforce 'script-src'
Persistent<ContentSecurityPolicy> policy = Persistent<ContentSecurityPolicy> policy =
MakeGarbageCollected<ContentSecurityPolicy>(); MakeGarbageCollected<ContentSecurityPolicy>();
policy->BindToDelegate(document.GetContentSecurityPolicyDelegate()); policy->BindToDelegate(window->GetContentSecurityPolicyDelegate());
policy->DidReceiveHeader(String("script-src ") + test.policy, policy->DidReceiveHeader(String("script-src ") + test.policy,
ContentSecurityPolicyType::kEnforce, ContentSecurityPolicyType::kEnforce,
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
...@@ -440,7 +441,7 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) { ...@@ -440,7 +441,7 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) {
// Enforce 'style-src' // Enforce 'style-src'
policy = MakeGarbageCollected<ContentSecurityPolicy>(); policy = MakeGarbageCollected<ContentSecurityPolicy>();
policy->BindToDelegate(document.GetContentSecurityPolicyDelegate()); policy->BindToDelegate(window->GetContentSecurityPolicyDelegate());
policy->DidReceiveHeader(String("style-src ") + test.policy, policy->DidReceiveHeader(String("style-src ") + test.policy,
ContentSecurityPolicyType::kEnforce, ContentSecurityPolicyType::kEnforce,
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
...@@ -452,7 +453,7 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) { ...@@ -452,7 +453,7 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) {
// Report 'script-src' // Report 'script-src'
policy = MakeGarbageCollected<ContentSecurityPolicy>(); policy = MakeGarbageCollected<ContentSecurityPolicy>();
policy->BindToDelegate(document.GetContentSecurityPolicyDelegate()); policy->BindToDelegate(window->GetContentSecurityPolicyDelegate());
policy->DidReceiveHeader(String("script-src ") + test.policy, policy->DidReceiveHeader(String("script-src ") + test.policy,
ContentSecurityPolicyType::kReport, ContentSecurityPolicyType::kReport,
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
...@@ -463,7 +464,7 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) { ...@@ -463,7 +464,7 @@ TEST_F(ContentSecurityPolicyTest, NonceInline) {
// Report 'style-src' // Report 'style-src'
policy = MakeGarbageCollected<ContentSecurityPolicy>(); policy = MakeGarbageCollected<ContentSecurityPolicy>();
policy->BindToDelegate(document.GetContentSecurityPolicyDelegate()); policy->BindToDelegate(window->GetContentSecurityPolicyDelegate());
policy->DidReceiveHeader(String("style-src ") + test.policy, policy->DidReceiveHeader(String("style-src ") + test.policy,
ContentSecurityPolicyType::kReport, ContentSecurityPolicyType::kReport,
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
...@@ -1436,7 +1437,7 @@ TEST_F(ContentSecurityPolicyTest, ReasonableRestrictionMetrics) { ...@@ -1436,7 +1437,7 @@ TEST_F(ContentSecurityPolicyTest, ReasonableRestrictionMetrics) {
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
auto dummy = std::make_unique<DummyPageHolder>(); auto dummy = std::make_unique<DummyPageHolder>();
csp->BindToDelegate( csp->BindToDelegate(
dummy->GetDocument().GetContentSecurityPolicyDelegate()); dummy->GetFrame().DomWindow()->GetContentSecurityPolicyDelegate());
EXPECT_EQ(test.expected_object, EXPECT_EQ(test.expected_object,
dummy->GetDocument().IsUseCounted( dummy->GetDocument().IsUseCounted(
...@@ -1462,7 +1463,7 @@ TEST_F(ContentSecurityPolicyTest, ReasonableRestrictionMetrics) { ...@@ -1462,7 +1463,7 @@ TEST_F(ContentSecurityPolicyTest, ReasonableRestrictionMetrics) {
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
auto dummy = std::make_unique<DummyPageHolder>(); auto dummy = std::make_unique<DummyPageHolder>();
csp->BindToDelegate( csp->BindToDelegate(
dummy->GetDocument().GetContentSecurityPolicyDelegate()); dummy->GetFrame().DomWindow()->GetContentSecurityPolicyDelegate());
EXPECT_EQ(test.expected_object, EXPECT_EQ(test.expected_object,
dummy->GetDocument().IsUseCounted( dummy->GetDocument().IsUseCounted(
...@@ -1512,7 +1513,7 @@ TEST_F(ContentSecurityPolicyTest, BetterThanReasonableRestrictionMetrics) { ...@@ -1512,7 +1513,7 @@ TEST_F(ContentSecurityPolicyTest, BetterThanReasonableRestrictionMetrics) {
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
auto dummy = std::make_unique<DummyPageHolder>(); auto dummy = std::make_unique<DummyPageHolder>();
csp->BindToDelegate( csp->BindToDelegate(
dummy->GetDocument().GetContentSecurityPolicyDelegate()); dummy->GetFrame().DomWindow()->GetContentSecurityPolicyDelegate());
EXPECT_EQ(test.expected, EXPECT_EQ(test.expected,
dummy->GetDocument().IsUseCounted( dummy->GetDocument().IsUseCounted(
...@@ -1528,7 +1529,7 @@ TEST_F(ContentSecurityPolicyTest, BetterThanReasonableRestrictionMetrics) { ...@@ -1528,7 +1529,7 @@ TEST_F(ContentSecurityPolicyTest, BetterThanReasonableRestrictionMetrics) {
ContentSecurityPolicySource::kHTTP); ContentSecurityPolicySource::kHTTP);
auto dummy = std::make_unique<DummyPageHolder>(); auto dummy = std::make_unique<DummyPageHolder>();
csp->BindToDelegate( csp->BindToDelegate(
dummy->GetDocument().GetContentSecurityPolicyDelegate()); dummy->GetFrame().DomWindow()->GetContentSecurityPolicyDelegate());
EXPECT_EQ(test.expected, EXPECT_EQ(test.expected,
dummy->GetDocument().IsUseCounted( dummy->GetDocument().IsUseCounted(
......
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