Skip to content

Commit

Permalink
Replace WorkerContentSettingsClient patches with subclass.
Browse files Browse the repository at this point in the history
  • Loading branch information
goodov committed Sep 17, 2024
1 parent dfe38fa commit 818fbe0
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 69 deletions.
68 changes: 44 additions & 24 deletions chromium_src/chrome/renderer/worker_content_settings_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,43 @@
#include "net/base/features.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"

#define WorkerContentSettingsClient WorkerContentSettingsClient_ChromiumImpl

#include "src/chrome/renderer/worker_content_settings_client.cc"

#undef WorkerContentSettingsClient

WorkerContentSettingsClient_BraveImpl::WorkerContentSettingsClient_BraveImpl(
content::RenderFrame* render_frame)
: WorkerContentSettingsClient_ChromiumImpl(render_frame) {
content_settings::ContentSettingsAgentImpl* agent =
content_settings::ContentSettingsAgentImpl::Get(render_frame);

if (const auto& shields_settings =
static_cast<content_settings::BraveContentSettingsAgentImpl*>(agent)
->shields_settings()) {
shields_settings_ = shields_settings->Clone();
}
}

WorkerContentSettingsClient_BraveImpl::
~WorkerContentSettingsClient_BraveImpl() = default;

WorkerContentSettingsClient_BraveImpl::WorkerContentSettingsClient_BraveImpl(
const WorkerContentSettingsClient_BraveImpl& other)
: WorkerContentSettingsClient_ChromiumImpl(other) {
if (other.shields_settings_) {
shields_settings_ = other.shields_settings_->Clone();
}
}

std::unique_ptr<blink::WebContentSettingsClient>
WorkerContentSettingsClient_BraveImpl::Clone() {
return base::WrapUnique(new WorkerContentSettingsClient_BraveImpl(*this));
}

brave_shields::mojom::ShieldsSettingsPtr
WorkerContentSettingsClient::GetBraveShieldsSettings(
WorkerContentSettingsClient_BraveImpl::GetBraveShieldsSettings(
ContentSettingsType webcompat_settings_type) {
ContentSetting setting = CONTENT_SETTING_DEFAULT;
if (content_setting_rules_) {
Expand Down Expand Up @@ -66,12 +101,14 @@ WorkerContentSettingsClient::GetBraveShieldsSettings(
}

blink::WebSecurityOrigin
WorkerContentSettingsClient::GetEphemeralStorageOriginSync() {
if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage))
WorkerContentSettingsClient_BraveImpl::GetEphemeralStorageOriginSync() {
if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage)) {
return {};
}

if (is_unique_origin_)
if (is_unique_origin_) {
return {};
}

// If first party ephemeral storage is enabled, we should always ask the
// browser if a worker should use ephemeral storage or not.
Expand All @@ -89,31 +126,14 @@ WorkerContentSettingsClient::GetEphemeralStorageOriginSync() {
content_settings_manager_->AllowEphemeralStorageAccess(
frame_token_, document_origin_, site_for_cookies_, top_frame_origin_,
&optional_ephemeral_storage_origin);
// Don't cache the value intentionally as other WorkerContentSettingsClient
// methods do.
// Don't cache the value intentionally as other
// WorkerContentSettingsClient_BraveImpl methods do.
return blink::WebSecurityOrigin(
optional_ephemeral_storage_origin
? blink::WebSecurityOrigin(*optional_ephemeral_storage_origin)
: blink::WebSecurityOrigin());
}

bool WorkerContentSettingsClient::HasContentSettingsRules() const {
bool WorkerContentSettingsClient_BraveImpl::HasContentSettingsRules() const {
return content_setting_rules_.get();
}

#define BRAVE_WORKER_CONTENT_SETTINGS_CLIENT \
if (const auto& shields_settings = \
static_cast<content_settings::BraveContentSettingsAgentImpl*>(agent) \
->shields_settings()) { \
shields_settings_ = shields_settings->Clone(); \
}

#define BRAVE_WORKER_CONTENT_SETTINGS_CLIENT_COPY_CTOR \
if (other.shields_settings_) { \
shields_settings_ = other.shields_settings_->Clone(); \
}

#include "src/chrome/renderer/worker_content_settings_client.cc"

#undef BRAVE_WORKER_CONTENT_SETTINGS_CLIENT
#undef BRAVE_WORKER_CONTENT_SETTINGS_CLIENT_COPY_CTOR
46 changes: 35 additions & 11 deletions chromium_src/chrome/renderer/worker_content_settings_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,43 @@
#ifndef BRAVE_CHROMIUM_SRC_CHROME_RENDERER_WORKER_CONTENT_SETTINGS_CLIENT_H_
#define BRAVE_CHROMIUM_SRC_CHROME_RENDERER_WORKER_CONTENT_SETTINGS_CLIENT_H_

#define BRAVE_WORKER_CONTENT_SETTINGS_CLIENT_H \
brave_shields::mojom::ShieldsSettingsPtr GetBraveShieldsSettings( \
ContentSettingsType webcompat_settings_type) override; \
blink::WebSecurityOrigin GetEphemeralStorageOriginSync() override; \
bool HasContentSettingsRules() const override; \
\
private: \
brave_shields::mojom::ShieldsSettingsPtr shields_settings_; \
\
public:
#include "third_party/blink/public/platform/web_content_settings_client.h"

class WorkerContentSettingsClient_BraveImpl;

#define EnsureContentSettingsManager() \
EnsureContentSettingsManager_NotUsed(); \
friend WorkerContentSettingsClient_BraveImpl; \
void EnsureContentSettingsManager()

#define WorkerContentSettingsClient WorkerContentSettingsClient_ChromiumImpl

#include "src/chrome/renderer/worker_content_settings_client.h" // IWYU pragma: export

#undef BRAVE_WORKER_CONTENT_SETTINGS_CLIENT_H
#undef EnsureContentSettingsManager
#undef WorkerContentSettingsClient

class WorkerContentSettingsClient_BraveImpl
: public WorkerContentSettingsClient_ChromiumImpl {
public:
explicit WorkerContentSettingsClient_BraveImpl(
content::RenderFrame* render_frame);
~WorkerContentSettingsClient_BraveImpl() override;

// WebContentSettingsClient:
std::unique_ptr<blink::WebContentSettingsClient> Clone() override;
brave_shields::mojom::ShieldsSettingsPtr GetBraveShieldsSettings(
ContentSettingsType webcompat_settings_type) override;
blink::WebSecurityOrigin GetEphemeralStorageOriginSync() override;
bool HasContentSettingsRules() const override;

private:
WorkerContentSettingsClient_BraveImpl(
const WorkerContentSettingsClient_BraveImpl& other);

brave_shields::mojom::ShieldsSettingsPtr shields_settings_;
};

using WorkerContentSettingsClient = WorkerContentSettingsClient_BraveImpl;

#endif // BRAVE_CHROMIUM_SRC_CHROME_RENDERER_WORKER_CONTENT_SETTINGS_CLIENT_H_
20 changes: 0 additions & 20 deletions patches/chrome-renderer-worker_content_settings_client.cc.patch

This file was deleted.

12 changes: 0 additions & 12 deletions patches/chrome-renderer-worker_content_settings_client.h.patch

This file was deleted.

4 changes: 2 additions & 2 deletions patches/third_party-blink-public-mojom-BUILD.gn.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/third_party/blink/public/mojom/BUILD.gn b/third_party/blink/public/mojom/BUILD.gn
index 7a1ef0b32d99da3beac8a0a9e3191999046e0fc2..d8c6bc25d2e4795b8cc27b677006cdd517552536 100644
index e166d3dc94fbbcb36bd0a2fdb0888e3d3b2bbb5a..aa08dfb1c071e5e882dcc26cf9611b8715d3524f 100644
--- a/third_party/blink/public/mojom/BUILD.gn
+++ b/third_party/blink/public/mojom/BUILD.gn
@@ -1135,6 +1135,7 @@ mojom("mojom_platform") {
@@ -1140,6 +1140,7 @@ mojom("mojom_platform") {
]
cpp_typemaps += shared_cpp_typemaps
blink_cpp_typemaps += shared_cpp_typemaps
Expand Down

0 comments on commit 818fbe0

Please sign in to comment.