-
Notifications
You must be signed in to change notification settings - Fork 883
/
brave_content_renderer_client.cc
147 lines (125 loc) · 6.14 KB
/
brave_content_renderer_client.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/renderer/brave_content_renderer_client.h"
#include "base/feature_list.h"
#include "brave/components/brave_ads/common/features.h"
#include "brave/components/brave_ads/renderer/brave_ads_render_frame_observer.h"
#include "brave/components/brave_search/common/brave_search_utils.h"
#include "brave/components/brave_search/renderer/brave_search_render_frame_observer.h"
#include "brave/components/brave_shields/common/features.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/cosmetic_filters/renderer/cosmetic_filters_js_render_frame_observer.h"
#include "brave/components/skus/common/features.h"
#include "brave/components/skus/renderer/skus_render_frame_observer.h"
#include "brave/components/speedreader/common/buildflags.h"
#include "brave/renderer/brave_render_thread_observer.h"
#include "brave/renderer/brave_wallet/brave_wallet_render_frame_observer.h"
#include "chrome/common/chrome_isolated_world_ids.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/web_runtime_features.h"
#include "third_party/blink/public/web/modules/service_worker/web_service_worker_context_proxy.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_SPEEDREADER)
#include "brave/components/speedreader/common/features.h"
#include "brave/components/speedreader/renderer/speedreader_render_frame_observer.h"
#endif
BraveContentRendererClient::BraveContentRendererClient()
: ChromeContentRendererClient() {}
void BraveContentRendererClient::
SetRuntimeFeaturesDefaultsBeforeBlinkInitialization() {
ChromeContentRendererClient::
SetRuntimeFeaturesDefaultsBeforeBlinkInitialization();
blink::WebRuntimeFeatures::EnableWebNfc(false);
// These features don't have dedicated WebRuntimeFeatures wrappers.
blink::WebRuntimeFeatures::EnableFeatureFromString("DigitalGoods", false);
if (!base::FeatureList::IsEnabled(blink::features::kFileSystemAccessAPI)) {
blink::WebRuntimeFeatures::EnableFeatureFromString("FileSystemAccess",
false);
blink::WebRuntimeFeatures::EnableFeatureFromString(
"FileSystemAccessAPIExperimental", false);
}
blink::WebRuntimeFeatures::EnableFeatureFromString("Serial", false);
blink::WebRuntimeFeatures::EnableFeatureFromString(
"SpeculationRulesPrefetchProxy", false);
}
BraveContentRendererClient::~BraveContentRendererClient() = default;
void BraveContentRendererClient::RenderThreadStarted() {
ChromeContentRendererClient::RenderThreadStarted();
brave_observer_ = std::make_unique<BraveRenderThreadObserver>();
content::RenderThread::Get()->AddObserver(brave_observer_.get());
brave_search_service_worker_holder_.SetBrowserInterfaceBrokerProxy(
browser_interface_broker_.get());
}
void BraveContentRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
ChromeContentRendererClient::RenderFrameCreated(render_frame);
if (base::FeatureList::IsEnabled(
brave_shields::features::kBraveAdblockCosmeticFiltering)) {
auto dynamic_params_closure = base::BindRepeating([]() {
auto dynamic_params = BraveRenderThreadObserver::GetDynamicParams();
return dynamic_params.de_amp_enabled;
});
new cosmetic_filters::CosmeticFiltersJsRenderFrameObserver(
render_frame, ISOLATED_WORLD_ID_BRAVE_INTERNAL, dynamic_params_closure);
}
if (base::FeatureList::IsEnabled(
brave_wallet::features::kNativeBraveWalletFeature)) {
new brave_wallet::BraveWalletRenderFrameObserver(
render_frame,
base::BindRepeating(&BraveRenderThreadObserver::GetDynamicParams));
}
if (brave_search::IsDefaultAPIEnabled()) {
new brave_search::BraveSearchRenderFrameObserver(
render_frame, content::ISOLATED_WORLD_ID_GLOBAL);
}
if (brave_ads::features::IsRequestAdsEnabledApiEnabled()) {
new brave_ads::BraveAdsRenderFrameObserver(
render_frame, content::ISOLATED_WORLD_ID_GLOBAL);
}
if (base::FeatureList::IsEnabled(skus::features::kSkusFeature)) {
new skus::SkusRenderFrameObserver(render_frame,
content::ISOLATED_WORLD_ID_GLOBAL);
}
#if BUILDFLAG(ENABLE_SPEEDREADER)
if (base::FeatureList::IsEnabled(speedreader::kSpeedreaderFeature)) {
new speedreader::SpeedreaderRenderFrameObserver(render_frame);
}
#endif
}
void BraveContentRendererClient::RunScriptsAtDocumentStart(
content::RenderFrame* render_frame) {
auto* observer =
cosmetic_filters::CosmeticFiltersJsRenderFrameObserver::Get(render_frame);
// Run this before any extensions
if (observer)
observer->RunScriptsAtDocumentStart();
ChromeContentRendererClient::RunScriptsAtDocumentStart(render_frame);
}
void BraveContentRendererClient::WillEvaluateServiceWorkerOnWorkerThread(
blink::WebServiceWorkerContextProxy* context_proxy,
v8::Local<v8::Context> v8_context,
int64_t service_worker_version_id,
const GURL& service_worker_scope,
const GURL& script_url) {
brave_search_service_worker_holder_.WillEvaluateServiceWorkerOnWorkerThread(
context_proxy, v8_context, service_worker_version_id,
service_worker_scope, script_url);
ChromeContentRendererClient::WillEvaluateServiceWorkerOnWorkerThread(
context_proxy, v8_context, service_worker_version_id,
service_worker_scope, script_url);
}
void BraveContentRendererClient::WillDestroyServiceWorkerContextOnWorkerThread(
v8::Local<v8::Context> v8_context,
int64_t service_worker_version_id,
const GURL& service_worker_scope,
const GURL& script_url) {
brave_search_service_worker_holder_
.WillDestroyServiceWorkerContextOnWorkerThread(
v8_context, service_worker_version_id, service_worker_scope,
script_url);
ChromeContentRendererClient::WillDestroyServiceWorkerContextOnWorkerThread(
v8_context, service_worker_version_id, service_worker_scope, script_url);
}