forked from bromite/bromite
-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathAdd-webGL-site-setting.patch
More file actions
286 lines (276 loc) · 13.6 KB
/
Add-webGL-site-setting.patch
File metadata and controls
286 lines (276 loc) · 13.6 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
From: uazo <uazo@users.noreply.github.com>
Date: Tue, 3 May 2022 14:44:11 +0000
Subject: Add webGL site setting
Do not provide any device information when serving context creation errors.
Requires patch: Content-settings-infrastructure.patch
Original License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
.../impl/BromiteWebGLContentSetting.java | 93 +++++++++++++++++++
.../bromite_content_settings/webgl.grdp | 27 ++++++
.../bromite_content_settings/webgl.inc | 22 +++++
.../common/bromite_content_settings/WEBGL.inc | 1 +
.../execution_context/execution_context.cc | 7 ++
.../execution_context/execution_context.h | 2 +
.../webgl/webgl_rendering_context_base.cc | 32 +++----
.../webgl/webgl_rendering_context_base.h | 2 +
8 files changed, 167 insertions(+), 19 deletions(-)
create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteWebGLContentSetting.java
create mode 100644 components/browser_ui/strings/bromite_content_settings/webgl.grdp
create mode 100644 components/content_settings/core/browser/bromite_content_settings/webgl.inc
create mode 100644 components/content_settings/core/common/bromite_content_settings/WEBGL.inc
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteWebGLContentSetting.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteWebGLContentSetting.java
new file mode 100644
--- /dev/null
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteWebGLContentSetting.java
@@ -0,0 +1,93 @@
+/*
+ This file is part of Bromite.
+
+ Bromite is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Bromite is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Bromite. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+package org.chromium.components.browser_ui.site_settings.impl;
+
+import org.chromium.components.browser_ui.site_settings.R;
+
+import org.chromium.components.browser_ui.site_settings.BromiteCustomContentSetting;
+import org.chromium.components.browser_ui.site_settings.ContentSettingsResources;
+import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory;
+import org.chromium.components.content_settings.ContentSetting;
+import org.chromium.components.content_settings.ContentSettingsType;
+import org.chromium.content_public.browser.BrowserContextHandle;
+
+import androidx.annotation.Nullable;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import java.util.ArrayList;
+
+public class BromiteWebGLContentSetting extends BromiteCustomContentSetting {
+ public BromiteWebGLContentSetting() {
+ super(/*contentSettingsType*/ ContentSettingsType.WEBGL,
+ /*defaultEnabledValue*/ ContentSetting.ALLOW,
+ /*defaultDisabledValue*/ ContentSetting.BLOCK,
+ /*allowException*/ true,
+ /*preferenceKey*/ "webgl",
+ /*profilePrefKey*/ "webgl");
+ }
+
+ @Override
+ public ContentSettingsResources.ResourceItem getResourceItem() {
+ return new ContentSettingsResources.ResourceItem(
+ /*icon*/ R.drawable.web_asset,
+ /*title*/ R.string.webgl_permission_title,
+ /*defaultEnabledValue*/ getDefaultEnabledValue(),
+ /*defaultDisabledValue*/ getDefaultDisabledValue(),
+ /*enabledSummary*/ R.string.website_settings_category_webgl_enabled,
+ /*disabledSummary*/ R.string.website_settings_category_webgl_disabled,
+ /*summaryOverrideForScreenReader*/ 0);
+ }
+
+ @Override
+ public int getCategorySummary(@Nullable @ContentSetting int value) {
+ switch (value) {
+ case ContentSetting.ALLOW:
+ return R.string.website_settings_category_webgl_enabled;
+ case ContentSetting.BLOCK:
+ return R.string.website_settings_category_webgl_disabled;
+ default:
+ return 0;
+ }
+ }
+
+ @Override
+ public int getCategoryDescription() {
+ return R.string.settings_site_settings_webgl_description;
+ }
+
+ @Override
+ public boolean requiresTriStateContentSetting() {
+ return false;
+ }
+
+ @Override
+ public boolean showOnlyDescriptions() {
+ return true;
+ }
+
+ @Override
+ public int getAddExceptionDialogMessage() {
+ return R.string.website_settings_category_webgl_enabled;
+ }
+
+ @Override
+ public @Nullable Boolean considerException(SiteSettingsCategory category, @ContentSetting int value) {
+ return value != ContentSetting.BLOCK;
+ }
+}
diff --git a/components/browser_ui/strings/bromite_content_settings/webgl.grdp b/components/browser_ui/strings/bromite_content_settings/webgl.grdp
new file mode 100644
--- /dev/null
+++ b/components/browser_ui/strings/bromite_content_settings/webgl.grdp
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<grit-part>
+ <message name="IDS_SITE_SETTINGS_TYPE_WEBGL" desc="The label used for webgl site settings controls." formatter_data="android_java">
+ Webgl
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_WEBGL_DESCRIPTION" desc="Description of the webgl content setting." formatter_data="android_java">
+ Enable Webgl, a JavaScript API for rendering high-performance interactive 3D and 2D graphics
+ </message>
+ <message name="IDS_SITE_SETTINGS_TYPE_WEBGL_MID_SENTENCE" desc="The label used for webgl site settings controls when used mid-sentence." formatter_data="android_java">
+ webgl
+ </message>
+ <message name="IDS_WEBGL_PERMISSION_TITLE" desc="Title of the permission to use webgl [CHAR-LIMIT=32]" formatter_data="android_java">
+ Webgl
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_WEBGL_ENABLED" desc="Summary text explaining that webgl is full enabled." formatter_data="android_java">
+ Enabled
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_WEBGL_DISABLED" desc="Summary text explaining that webgl is full disabled." formatter_data="android_java">
+ Disabled
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_WEBGL_ALLOWED_EXCEPTIONS" desc="Label for the allowed exceptions site list of the webgl setting.">
+ Allowed to use webgl
+ </message>
+ <message name="IDS_SETTINGS_SITE_SETTINGS_WEBGL_BLOCKED_EXCEPTIONS" desc="Label for the blocked exceptions site list of the webgl setting.">
+ Not allowed to use webgl
+ </message>
+</grit-part>
diff --git a/components/content_settings/core/browser/bromite_content_settings/webgl.inc b/components/content_settings/core/browser/bromite_content_settings/webgl.inc
new file mode 100644
--- /dev/null
+++ b/components/content_settings/core/browser/bromite_content_settings/webgl.inc
@@ -0,0 +1,22 @@
+ Register(ContentSettingsType::WEBGL, "webgl", CONTENT_SETTING_BLOCK,
+ WebsiteSettingsInfo::SYNCABLE,
+ /*allowlisted_schemes=*/{},
+ /*valid_settings=*/{CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_BLOCK},
+ WebsiteSettingsInfo::TOP_ORIGIN_ONLY_SCOPE,
+ WebsiteSettingsRegistry::ALL_PLATFORMS,
+ ContentSettingsInfo::INHERIT_IN_INCOGNITO,
+ PermissionSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS);
+
+ content_settings::WebsiteSettingsRegistry::GetInstance()
+ ->GetMutable(ContentSettingsType::WEBGL)
+ ->set_show_into_info_page()
+ .set_desktop_ui()
+ .set_is_renderer_content_setting()
+ .set_title_ui(IDS_SITE_SETTINGS_TYPE_WEBGL)
+ .set_description_ui(IDS_SETTINGS_SITE_SETTINGS_WEBGL_DESCRIPTION)
+ .set_allowed_ui(IDS_WEBSITE_SETTINGS_CATEGORY_WEBGL_ENABLED)
+ .set_blocked_ui(IDS_WEBSITE_SETTINGS_CATEGORY_WEBGL_DISABLED)
+ .set_allowed_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_WEBGL_ALLOWED_EXCEPTIONS)
+ .set_blocked_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_WEBGL_BLOCKED_EXCEPTIONS)
+ .set_mid_sentence_ui(IDS_SITE_SETTINGS_TYPE_WEBGL);
diff --git a/components/content_settings/core/common/bromite_content_settings/WEBGL.inc b/components/content_settings/core/common/bromite_content_settings/WEBGL.inc
new file mode 100644
--- /dev/null
+++ b/components/content_settings/core/common/bromite_content_settings/WEBGL.inc
@@ -0,0 +1 @@
+ WEBGL,
diff --git a/third_party/blink/renderer/core/execution_context/execution_context.cc b/third_party/blink/renderer/core/execution_context/execution_context.cc
--- a/third_party/blink/renderer/core/execution_context/execution_context.cc
+++ b/third_party/blink/renderer/core/execution_context/execution_context.cc
@@ -86,6 +86,13 @@ blink::WebContentSettingsClient* GetContentSettingsClientFor(
return settings;
}
+bool AllowWebgl(ExecutionContext* context) {
+ blink::WebContentSettingsClient* settings = GetContentSettingsClientFor(context);
+ if (settings)
+ return settings->AllowContentSetting(ContentSettingsType::WEBGL, false);
+ return false;
+}
+
ExecutionContext::ExecutionContext(v8::Isolate* isolate,
Agent* agent,
bool is_window)
diff --git a/third_party/blink/renderer/core/execution_context/execution_context.h b/third_party/blink/renderer/core/execution_context/execution_context.h
--- a/third_party/blink/renderer/core/execution_context/execution_context.h
+++ b/third_party/blink/renderer/core/execution_context/execution_context.h
@@ -111,6 +111,8 @@ enum ReasonForCallingCanExecuteScripts {
enum ReferrerPolicySource { kPolicySourceHttpHeader, kPolicySourceMetaTag };
+CORE_EXPORT bool AllowWebgl(ExecutionContext* context);
+
// An environment in which script can execute. This class exposes the common
// properties of script execution environments on the web (i.e, common between
// script executing in a window and script executing in a worker), such as:
diff --git a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
--- a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
+++ b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
@@ -342,6 +342,13 @@ void WebGLRenderingContextBase::InitializeWebGLContextLimits(
}
}
+bool WebGLRenderingContextBase::AllowWebglForHost(blink::CanvasRenderingContextHost* host) {
+ if (!host)
+ return false;
+ blink::ExecutionContext* context = host->GetTopExecutionContext();
+ return blink::AllowWebgl(context);
+}
+
unsigned WebGLRenderingContextBase::CurrentMaxGLContexts() {
base::AutoLock locker(WebGLContextLimitLock());
DCHECK(webgl_context_limits_initialized_);
@@ -612,25 +619,6 @@ static String ExtractWebGLContextCreationError(
const Platform::WebGLContextInfo& info) {
StringBuilder builder;
builder.Append("Could not create a WebGL context");
- FormatWebGLStatusString(
- "VENDOR",
- info.vendor_id ? String::Format("0x%04x", info.vendor_id) : "0xffff",
- builder);
- FormatWebGLStatusString(
- "DEVICE",
- info.device_id ? String::Format("0x%04x", info.device_id) : "0xffff",
- builder);
- FormatWebGLStatusString("GL_VENDOR", info.vendor_info, builder);
- FormatWebGLStatusString("GL_RENDERER", info.renderer_info, builder);
- FormatWebGLStatusString("GL_VERSION", info.driver_version, builder);
- FormatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", builder);
- FormatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", builder);
- FormatWebGLStatusString("AMD switchable", info.amd_switchable ? "yes" : "no",
- builder);
- FormatWebGLStatusString(
- "Reset notification strategy",
- String::Format("0x%04x", info.reset_notification_strategy).Utf8().c_str(),
- builder);
FormatWebGLStatusString("ErrorMessage", info.error_message.Utf8().c_str(),
builder);
builder.Append('.');
@@ -691,6 +679,12 @@ WebGLRenderingContextBase::CreateWebGraphicsContext3DProvider(
const CanvasContextCreationAttributesCore& attributes,
Platform::WebGLContextType context_type,
Platform::WebGLContextInfo* context_info) {
+ if (!AllowWebglForHost(host)) {
+ host->HostDispatchEvent(WebGLContextEvent::Create(
+ event_type_names::kWebglcontextcreationerror,
+ "disabled by site settings policy."));
+ return nullptr;
+ }
if ((context_type == Platform::kWebGL1ContextType &&
!host->IsWebGL1Enabled()) ||
(context_type == Platform::kWebGL2ContextType &&
diff --git a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h
--- a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h
+++ b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h
@@ -2009,6 +2009,8 @@ class MODULES_EXPORT WebGLRenderingContextBase
DOMArrayBufferView* pixels,
int64_t offset);
+ static bool AllowWebglForHost(blink::CanvasRenderingContextHost* host);
+
void RecordANGLEImplementation();
private:
--