Add-webgl-site-setting.patch 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. From: uazo <uazo@users.noreply.github.com>
  2. Date: Tue, 3 May 2022 14:44:11 +0000
  3. Subject: Add webgl site settings
  4. Require: Content-settings-infrastructure.patch
  5. ---
  6. .../browser_ui/site_settings/android/BUILD.gn | 3 +
  7. .../BromiteCustomContentSettingImpl.java | 1 +
  8. .../BromiteWebGLContentSetting.java | 85 +++++++++++++++++++
  9. .../site_settings/SiteSettingsCategory.java | 5 +-
  10. .../strings/android/browser_ui_strings.grd | 1 +
  11. .../browser_ui/strings/android/webgl.grdp | 18 ++++
  12. components/components_strings.grd | 1 +
  13. .../core/browser/content_settings_registry.cc | 14 +++
  14. .../core/browser/content_settings_utils.cc | 2 +
  15. .../core/common/content_settings.cc | 3 +-
  16. .../core/common/content_settings.h | 1 +
  17. .../core/common/content_settings.mojom | 1 +
  18. .../common/content_settings_mojom_traits.cc | 3 +-
  19. .../common/content_settings_mojom_traits.h | 5 ++
  20. .../core/common/content_settings_types.h | 2 +
  21. .../renderer/content_settings_agent_impl.cc | 9 ++
  22. .../renderer/content_settings_agent_impl.h | 1 +
  23. .../platform/web_content_settings_client.h | 2 +
  24. .../execution_context/execution_context.cc | 23 +++++
  25. .../execution_context/execution_context.h | 5 ++
  26. .../webgl/webgl_rendering_context_base.cc | 32 +++----
  27. .../webgl/webgl_rendering_context_base.h | 2 +
  28. 22 files changed, 196 insertions(+), 23 deletions(-)
  29. create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteWebGLContentSetting.java
  30. create mode 100644 components/browser_ui/strings/android/webgl.grdp
  31. diff --git a/components/browser_ui/site_settings/android/BUILD.gn b/components/browser_ui/site_settings/android/BUILD.gn
  32. --- a/components/browser_ui/site_settings/android/BUILD.gn
  33. +++ b/components/browser_ui/site_settings/android/BUILD.gn
  34. @@ -72,6 +72,9 @@ android_library("java") {
  35. "java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java",
  36. "java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSetting.java",
  37. ]
  38. + sources += [
  39. + "java/src/org/chromium/components/browser_ui/site_settings/BromiteWebGLContentSetting.java",
  40. + ]
  41. annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
  42. resources_package = "org.chromium.components.browser_ui.site_settings"
  43. deps = [
  44. diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java
  45. --- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java
  46. +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteCustomContentSettingImpl.java
  47. @@ -43,6 +43,7 @@ public abstract class BromiteCustomContentSettingImpl {
  48. static {
  49. mItemList = new ArrayList<BromiteCustomContentSetting>();
  50. + mItemList.add(new BromiteWebGLContentSetting());
  51. }
  52. public static SiteSettingsCategory createFromType(
  53. diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteWebGLContentSetting.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteWebGLContentSetting.java
  54. new file mode 100644
  55. --- /dev/null
  56. +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/BromiteWebGLContentSetting.java
  57. @@ -0,0 +1,85 @@
  58. +/*
  59. + This file is part of Bromite.
  60. +
  61. + Bromite is free software: you can redistribute it and/or modify
  62. + it under the terms of the GNU General Public License as published by
  63. + the Free Software Foundation, either version 3 of the License, or
  64. + (at your option) any later version.
  65. +
  66. + Bromite is distributed in the hope that it will be useful,
  67. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  68. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  69. + GNU General Public License for more details.
  70. +
  71. + You should have received a copy of the GNU General Public License
  72. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  73. +*/
  74. +
  75. +package org.chromium.components.browser_ui.site_settings;
  76. +
  77. +import org.chromium.components.browser_ui.site_settings.ContentSettingsResources;
  78. +import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory;
  79. +import org.chromium.components.content_settings.ContentSettingValues;
  80. +import org.chromium.components.content_settings.ContentSettingsType;
  81. +import org.chromium.content_public.browser.BrowserContextHandle;
  82. +
  83. +import androidx.annotation.Nullable;
  84. +import androidx.preference.Preference;
  85. +import androidx.preference.PreferenceScreen;
  86. +
  87. +import java.util.ArrayList;
  88. +
  89. +public class BromiteWebGLContentSetting extends BromiteCustomContentSetting {
  90. + public BromiteWebGLContentSetting() {
  91. + super(/*contentSettingsType*/ ContentSettingsType.WEBGL,
  92. + /*siteSettingsCategory*/ SiteSettingsCategory.Type.WEBGL,
  93. + /*initialDefaultValue*/ ContentSettingValues.BLOCK,
  94. + /*defaultDisabledValue*/ ContentSettingValues.BLOCK,
  95. + /*allowException*/ true,
  96. + /*preferenceKey*/ "webgl",
  97. + /*profilePrefKey*/ "webgl");
  98. + }
  99. +
  100. + @Override
  101. + public ContentSettingsResources.ResourceItem getResourceItem() {
  102. + return new ContentSettingsResources.ResourceItem(
  103. + /*icon*/ R.drawable.web_asset,
  104. + /*title*/ R.string.webgl_permission_title,
  105. + /*defaultEnabledValue*/ getInitialDefaultValue(),
  106. + /*defaultDisabledValue*/ getDefaultDisabledValue(),
  107. + /*enabledSummary*/ R.string.website_settings_category_webgl_enabled,
  108. + /*disabledSummary*/ R.string.website_settings_category_webgl_disabled);
  109. + }
  110. +
  111. + @Override
  112. + public int getCategorySummary(@Nullable @ContentSettingValues int value) {
  113. + switch (value) {
  114. + case ContentSettingValues.ALLOW:
  115. + return R.string.website_settings_category_webgl_enabled;
  116. + case ContentSettingValues.BLOCK:
  117. + return R.string.website_settings_category_webgl_disabled;
  118. + default:
  119. + return 0;
  120. + }
  121. + }
  122. +
  123. + @Override
  124. + public boolean requiresTriStateContentSetting() {
  125. + return false;
  126. + }
  127. +
  128. + @Override
  129. + public boolean showOnlyDescriptions() {
  130. + return true;
  131. + }
  132. +
  133. + @Override
  134. + public int getAddExceptionDialogMessage() {
  135. + return R.string.website_settings_category_webgl_enabled;
  136. + }
  137. +
  138. + @Override
  139. + public @Nullable Boolean considerException(SiteSettingsCategory category, @ContentSettingValues int value) {
  140. + return value != ContentSettingValues.BLOCK;
  141. + }
  142. +}
  143. diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
  144. --- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
  145. +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
  146. @@ -44,7 +44,7 @@ public class SiteSettingsCategory {
  147. Type.PROTECTED_MEDIA, Type.SENSORS, Type.SOUND, Type.USB, Type.VIRTUAL_REALITY,
  148. Type.USE_STORAGE, Type.AUTO_DARK_WEB_CONTENT, Type.REQUEST_DESKTOP_SITE,
  149. Type.FEDERATED_IDENTITY_API, Type.TIMEZONE_OVERRIDE, Type.AUTOPLAY, Type.JAVASCRIPT_JIT,
  150. - Type.IMAGES})
  151. + Type.IMAGES, Type.WEBGL})
  152. @Retention(RetentionPolicy.SOURCE)
  153. public @interface Type {
  154. // All updates here must also be reflected in {@link #preferenceKey(int)
  155. @@ -79,10 +79,11 @@ public class SiteSettingsCategory {
  156. int AUTOPLAY = 27;
  157. int JAVASCRIPT_JIT = 28;
  158. int IMAGES = 29;
  159. + int WEBGL = 30;
  160. /**
  161. * Number of handled categories used for calculating array sizes.
  162. */
  163. - int NUM_ENTRIES = 30;
  164. + int NUM_ENTRIES = 31;
  165. }
  166. private final BrowserContextHandle mBrowserContextHandle;
  167. diff --git a/components/browser_ui/strings/android/browser_ui_strings.grd b/components/browser_ui/strings/android/browser_ui_strings.grd
  168. --- a/components/browser_ui/strings/android/browser_ui_strings.grd
  169. +++ b/components/browser_ui/strings/android/browser_ui_strings.grd
  170. @@ -173,6 +173,7 @@
  171. <release seq="1">
  172. <messages fallback_to_english="true">
  173. <part file="site_settings.grdp" />
  174. + <part file="webgl.grdp" />
  175. <message name="IDS_GOT_IT" desc="Button for the user to accept a disclosure/message">
  176. Got it
  177. diff --git a/components/browser_ui/strings/android/webgl.grdp b/components/browser_ui/strings/android/webgl.grdp
  178. new file mode 100644
  179. --- /dev/null
  180. +++ b/components/browser_ui/strings/android/webgl.grdp
  181. @@ -0,0 +1,18 @@
  182. +<?xml version="1.0" encoding="utf-8"?>
  183. +<grit-part>
  184. + <message name="IDS_SITE_SETTINGS_TYPE_WEBGL" desc="The label used for webgl site settings controls.">
  185. + Webgl
  186. + </message>
  187. + <message name="IDS_SITE_SETTINGS_TYPE_WEBGL_MID_SENTENCE" desc="The label used for webgl site settings controls when used mid-sentence.">
  188. + webgl
  189. + </message>
  190. + <message name="IDS_WEBGL_PERMISSION_TITLE" desc="Title of the permission to use webgl [CHAR-LIMIT=32]">
  191. + Webgl
  192. + </message>
  193. + <message name="IDS_WEBSITE_SETTINGS_CATEGORY_WEBGL_ENABLED" desc="Summary text explaining that webgl is full enabled.">
  194. + Enabled
  195. + </message>
  196. + <message name="IDS_WEBSITE_SETTINGS_CATEGORY_WEBGL_DISABLED" desc="Summary text explaining that webgl is full disabled.">
  197. + Disabled
  198. + </message>
  199. +</grit-part>
  200. diff --git a/components/components_strings.grd b/components/components_strings.grd
  201. --- a/components/components_strings.grd
  202. +++ b/components/components_strings.grd
  203. @@ -334,6 +334,7 @@
  204. <part file="version_ui_strings.grdp" />
  205. <part file="webapps_strings.grdp" />
  206. <part file="user_scripts/strings/userscripts_strings.grdp" />
  207. + <part file="browser_ui/strings/android/webgl.grdp" />
  208. <if expr="not is_ios">
  209. <part file="management_strings.grdp" />
  210. diff --git a/components/content_settings/core/browser/content_settings_registry.cc b/components/content_settings/core/browser/content_settings_registry.cc
  211. --- a/components/content_settings/core/browser/content_settings_registry.cc
  212. +++ b/components/content_settings/core/browser/content_settings_registry.cc
  213. @@ -667,6 +667,20 @@ void ContentSettingsRegistry::Init() {
  214. ContentSettingsInfo::INHERIT_IN_INCOGNITO,
  215. ContentSettingsInfo::PERSISTENT,
  216. ContentSettingsInfo::EXCEPTIONS_ON_SECURE_ORIGINS_ONLY);
  217. +
  218. + Register(ContentSettingsType::WEBGL, "webgl", CONTENT_SETTING_BLOCK,
  219. + WebsiteSettingsInfo::SYNCABLE,
  220. + AllowlistedSchemes(),
  221. + ValidSettings(CONTENT_SETTING_ALLOW,
  222. + CONTENT_SETTING_BLOCK),
  223. + WebsiteSettingsInfo::SINGLE_ORIGIN_WITH_EMBEDDED_EXCEPTIONS_SCOPE,
  224. + WebsiteSettingsRegistry::PLATFORM_ANDROID,
  225. + ContentSettingsInfo::INHERIT_IN_INCOGNITO,
  226. + ContentSettingsInfo::PERSISTENT,
  227. + ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS,
  228. + /*show_into_info_page*/ true,
  229. + /*permission_type_ui*/ IDS_SITE_SETTINGS_TYPE_WEBGL,
  230. + /*permission_type_ui_mid_sentence*/ IDS_SITE_SETTINGS_TYPE_WEBGL_MID_SENTENCE);
  231. }
  232. void ContentSettingsRegistry::Register(
  233. diff --git a/components/content_settings/core/browser/content_settings_utils.cc b/components/content_settings/core/browser/content_settings_utils.cc
  234. --- a/components/content_settings/core/browser/content_settings_utils.cc
  235. +++ b/components/content_settings/core/browser/content_settings_utils.cc
  236. @@ -155,6 +155,8 @@ void GetRendererContentSettingRules(const HostContentSettingsMap* map,
  237. std::string timezone;
  238. map->GetTimezoneOverrideValue(timezone);
  239. rules->timezone_override_value = timezone;
  240. + map->GetSettingsForOneType(ContentSettingsType::WEBGL,
  241. + &(rules->webgl_rules));
  242. }
  243. bool IsMorePermissive(ContentSetting a, ContentSetting b) {
  244. diff --git a/components/content_settings/core/common/content_settings.cc b/components/content_settings/core/common/content_settings.cc
  245. --- a/components/content_settings/core/common/content_settings.cc
  246. +++ b/components/content_settings/core/common/content_settings.cc
  247. @@ -195,7 +195,8 @@ bool RendererContentSettingRules::IsRendererContentSetting(
  248. content_type == ContentSettingsType::POPUPS ||
  249. content_type == ContentSettingsType::MIXEDSCRIPT ||
  250. content_type == ContentSettingsType::AUTO_DARK_WEB_CONTENT ||
  251. - content_type == ContentSettingsType::TIMEZONE_OVERRIDE;
  252. + content_type == ContentSettingsType::TIMEZONE_OVERRIDE ||
  253. + content_type == ContentSettingsType::WEBGL;
  254. }
  255. RendererContentSettingRules::RendererContentSettingRules() {}
  256. diff --git a/components/content_settings/core/common/content_settings.h b/components/content_settings/core/common/content_settings.h
  257. --- a/components/content_settings/core/common/content_settings.h
  258. +++ b/components/content_settings/core/common/content_settings.h
  259. @@ -85,6 +85,7 @@ struct RendererContentSettingRules {
  260. ContentSettingsForOneType auto_dark_content_rules;
  261. ContentSettingsForOneType timezone_override_rules;
  262. std::string timezone_override_value;
  263. + ContentSettingsForOneType webgl_rules;
  264. };
  265. namespace content_settings {
  266. diff --git a/components/content_settings/core/common/content_settings.mojom b/components/content_settings/core/common/content_settings.mojom
  267. --- a/components/content_settings/core/common/content_settings.mojom
  268. +++ b/components/content_settings/core/common/content_settings.mojom
  269. @@ -81,4 +81,5 @@ struct RendererContentSettingRules {
  270. array<ContentSettingPatternSource> auto_dark_content_rules;
  271. array<ContentSettingPatternSource> timezone_override_rules;
  272. string timezone_override_value;
  273. + array<ContentSettingPatternSource> webgl_rules;
  274. };
  275. diff --git a/components/content_settings/core/common/content_settings_mojom_traits.cc b/components/content_settings/core/common/content_settings_mojom_traits.cc
  276. --- a/components/content_settings/core/common/content_settings_mojom_traits.cc
  277. +++ b/components/content_settings/core/common/content_settings_mojom_traits.cc
  278. @@ -104,7 +104,8 @@ bool StructTraits<content_settings::mojom::RendererContentSettingRulesDataView,
  279. data.ReadMixedContentRules(&out->mixed_content_rules) &&
  280. data.ReadAutoDarkContentRules(&out->auto_dark_content_rules) &&
  281. data.ReadTimezoneOverrideRules(&out->timezone_override_rules) &&
  282. - data.ReadTimezoneOverrideValue(&out->timezone_override_value);
  283. + data.ReadTimezoneOverrideValue(&out->timezone_override_value) &&
  284. + data.ReadWebglRules(&out->webgl_rules);
  285. }
  286. } // namespace mojo
  287. diff --git a/components/content_settings/core/common/content_settings_mojom_traits.h b/components/content_settings/core/common/content_settings_mojom_traits.h
  288. --- a/components/content_settings/core/common/content_settings_mojom_traits.h
  289. +++ b/components/content_settings/core/common/content_settings_mojom_traits.h
  290. @@ -165,6 +165,11 @@ struct StructTraits<
  291. return r.timezone_override_value;
  292. }
  293. + static const std::vector<ContentSettingPatternSource>& webgl_rules(
  294. + const RendererContentSettingRules& r) {
  295. + return r.webgl_rules;
  296. + }
  297. +
  298. static bool Read(
  299. content_settings::mojom::RendererContentSettingRulesDataView data,
  300. RendererContentSettingRules* out);
  301. diff --git a/components/content_settings/core/common/content_settings_types.h b/components/content_settings/core/common/content_settings_types.h
  302. --- a/components/content_settings/core/common/content_settings_types.h
  303. +++ b/components/content_settings/core/common/content_settings_types.h
  304. @@ -284,6 +284,8 @@ enum class ContentSettingsType : int32_t {
  305. // site instead of the mobile one.
  306. REQUEST_DESKTOP_SITE,
  307. + WEBGL,
  308. +
  309. // Setting to indicate whether browser should allow signing into a website via
  310. // the browser FedCM API.
  311. FEDERATED_IDENTITY_API,
  312. diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc
  313. --- a/components/content_settings/renderer/content_settings_agent_impl.cc
  314. +++ b/components/content_settings/renderer/content_settings_agent_impl.cc
  315. @@ -477,6 +477,15 @@ void ContentSettingsAgentImpl::ClearBlockedContentSettings() {
  316. cached_script_permissions_.clear();
  317. }
  318. +bool ContentSettingsAgentImpl::AllowWebgl(bool enabled_per_settings) {
  319. + if (!content_setting_rules_)
  320. + return false;
  321. + blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
  322. + return CONTENT_SETTING_ALLOW == GetContentSettingFromRules(
  323. + content_setting_rules_->webgl_rules, frame,
  324. + url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL());
  325. +}
  326. +
  327. bool ContentSettingsAgentImpl::IsAllowlistedForContentSettings() const {
  328. if (should_allowlist_)
  329. return true;
  330. diff --git a/components/content_settings/renderer/content_settings_agent_impl.h b/components/content_settings/renderer/content_settings_agent_impl.h
  331. --- a/components/content_settings/renderer/content_settings_agent_impl.h
  332. +++ b/components/content_settings/renderer/content_settings_agent_impl.h
  333. @@ -101,6 +101,7 @@ class ContentSettingsAgentImpl
  334. bool AllowAutoplay(bool default_value) override;
  335. bool AllowPopupsAndRedirects(bool default_value) override;
  336. bool ShouldAutoupgradeMixedContent() override;
  337. + bool AllowWebgl(bool enabled_per_settings) override;
  338. bool allow_running_insecure_content() const {
  339. return allow_running_insecure_content_;
  340. diff --git a/third_party/blink/public/platform/web_content_settings_client.h b/third_party/blink/public/platform/web_content_settings_client.h
  341. --- a/third_party/blink/public/platform/web_content_settings_client.h
  342. +++ b/third_party/blink/public/platform/web_content_settings_client.h
  343. @@ -99,6 +99,8 @@ class WebContentSettingsClient {
  344. return default_value;
  345. }
  346. + virtual bool AllowWebgl(bool default_value) { return default_value; }
  347. +
  348. // Reports that passive mixed content was found at the provided URL.
  349. virtual void PassiveInsecureContentFound(const WebURL&) {}
  350. diff --git a/third_party/blink/renderer/core/execution_context/execution_context.cc b/third_party/blink/renderer/core/execution_context/execution_context.cc
  351. --- a/third_party/blink/renderer/core/execution_context/execution_context.cc
  352. +++ b/third_party/blink/renderer/core/execution_context/execution_context.cc
  353. @@ -64,6 +64,29 @@
  354. namespace blink {
  355. +blink::WebContentSettingsClient* GetContentSettingsClientFor(
  356. + ExecutionContext* context) {
  357. + blink::WebContentSettingsClient* settings = nullptr;
  358. + if (!context)
  359. + return settings;
  360. + if (auto* window = blink::DynamicTo<blink::LocalDOMWindow>(context)) {
  361. + auto* frame = window->GetFrame();
  362. + if (frame)
  363. + settings = frame->GetContentSettingsClient();
  364. + } else if (context->IsWorkerGlobalScope()) {
  365. + settings =
  366. + blink::To<blink::WorkerGlobalScope>(context)->ContentSettingsClient();
  367. + }
  368. + return settings;
  369. +}
  370. +
  371. +bool AllowWebgl(ExecutionContext* context) {
  372. + blink::WebContentSettingsClient* settings = GetContentSettingsClientFor(context);
  373. + if (settings)
  374. + return settings->AllowWebgl(false);
  375. + return false;
  376. +}
  377. +
  378. ExecutionContext::ExecutionContext(v8::Isolate* isolate, Agent* agent)
  379. : isolate_(isolate),
  380. security_context_(this),
  381. diff --git a/third_party/blink/renderer/core/execution_context/execution_context.h b/third_party/blink/renderer/core/execution_context/execution_context.h
  382. --- a/third_party/blink/renderer/core/execution_context/execution_context.h
  383. +++ b/third_party/blink/renderer/core/execution_context/execution_context.h
  384. @@ -96,6 +96,7 @@ class SecurityOrigin;
  385. class ScriptState;
  386. class ScriptWrappable;
  387. class TrustedTypePolicyFactory;
  388. +class WebContentSettingsClient;
  389. enum ReasonForCallingCanExecuteScripts {
  390. kAboutToExecuteScript,
  391. @@ -104,6 +105,10 @@ enum ReasonForCallingCanExecuteScripts {
  392. enum ReferrerPolicySource { kPolicySourceHttpHeader, kPolicySourceMetaTag };
  393. +CORE_EXPORT bool AllowWebgl(ExecutionContext* context);
  394. +CORE_EXPORT WebContentSettingsClient* GetContentSettingsClientFor(
  395. + ExecutionContext* context);
  396. +
  397. // An environment in which script can execute. This class exposes the common
  398. // properties of script execution environments on the web (i.e, common between
  399. // script executing in a window and script executing in a worker), such as:
  400. 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
  401. --- a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
  402. +++ b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
  403. @@ -216,6 +216,13 @@ void WebGLRenderingContextBase::InitializeWebGLContextLimits(
  404. }
  405. }
  406. +bool WebGLRenderingContextBase::AllowWebglForHost(blink::CanvasRenderingContextHost* host) {
  407. + if (!host)
  408. + return false;
  409. + blink::ExecutionContext* context = host->GetTopExecutionContext();
  410. + return blink::AllowWebgl(context);
  411. +}
  412. +
  413. unsigned WebGLRenderingContextBase::CurrentMaxGLContexts() {
  414. MutexLocker locker(WebGLContextLimitMutex());
  415. DCHECK(webgl_context_limits_initialized_);
  416. @@ -462,25 +469,6 @@ static String ExtractWebGLContextCreationError(
  417. const Platform::GraphicsInfo& info) {
  418. StringBuilder builder;
  419. builder.Append("Could not create a WebGL context");
  420. - FormatWebGLStatusString(
  421. - "VENDOR",
  422. - info.vendor_id ? String::Format("0x%04x", info.vendor_id) : "0xffff",
  423. - builder);
  424. - FormatWebGLStatusString(
  425. - "DEVICE",
  426. - info.device_id ? String::Format("0x%04x", info.device_id) : "0xffff",
  427. - builder);
  428. - FormatWebGLStatusString("GL_VENDOR", info.vendor_info, builder);
  429. - FormatWebGLStatusString("GL_RENDERER", info.renderer_info, builder);
  430. - FormatWebGLStatusString("GL_VERSION", info.driver_version, builder);
  431. - FormatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", builder);
  432. - FormatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", builder);
  433. - FormatWebGLStatusString("AMD switchable", info.amd_switchable ? "yes" : "no",
  434. - builder);
  435. - FormatWebGLStatusString(
  436. - "Reset notification strategy",
  437. - String::Format("0x%04x", info.reset_notification_strategy).Utf8().c_str(),
  438. - builder);
  439. FormatWebGLStatusString("ErrorMessage", info.error_message.Utf8().c_str(),
  440. builder);
  441. builder.Append('.');
  442. @@ -548,6 +536,12 @@ WebGLRenderingContextBase::CreateWebGraphicsContext3DProvider(
  443. const CanvasContextCreationAttributesCore& attributes,
  444. Platform::ContextType context_type,
  445. Platform::GraphicsInfo* graphics_info) {
  446. + if (!AllowWebglForHost(host)) {
  447. + host->HostDispatchEvent(WebGLContextEvent::Create(
  448. + event_type_names::kWebglcontextcreationerror,
  449. + "disabled by site settings policy."));
  450. + return nullptr;
  451. + }
  452. if ((context_type == Platform::kWebGL1ContextType &&
  453. !host->IsWebGL1Enabled()) ||
  454. (context_type == Platform::kWebGL2ContextType &&
  455. 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
  456. --- a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h
  457. +++ b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h
  458. @@ -1826,6 +1826,8 @@ class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext,
  459. DOMArrayBufferView* pixels,
  460. int64_t offset);
  461. + static bool AllowWebglForHost(blink::CanvasRenderingContextHost* host);
  462. +
  463. // Record Canvas/OffscreenCanvas.RenderingContextDrawnTo at the first draw
  464. // call.
  465. void RecordUKMCanvasDrawnToAtFirstDrawCall();
  466. --
  467. 2.25.1