aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2020-04-15 11:42:02 -0400
committerJosh Matthews <josh@joshmatthews.net>2020-04-15 17:26:42 -0400
commite2845a69391e434fb6a4a9cdf18349dcb92f63e2 (patch)
tree994d45b3ee8bedbf5b012afa2e00f40f8a5133fc /components/script
parent7d1f968d529e9bd96f19ce9e478be2163c79a7a2 (diff)
downloadservo-e2845a69391e434fb6a4a9cdf18349dcb92f63e2.tar.gz
servo-e2845a69391e434fb6a4a9cdf18349dcb92f63e2.zip
Automatically enable WebGL 2 for specific domains.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/htmlcanvaselement.rs4
-rw-r--r--components/script/dom/webgl2renderingcontext.rs23
-rw-r--r--components/script/dom/webidls/WebGL2RenderingContext.webidl2
3 files changed, 25 insertions, 4 deletions
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs
index a4b628383d7..d5327e27dea 100644
--- a/components/script/dom/htmlcanvaselement.rs
+++ b/components/script/dom/htmlcanvaselement.rs
@@ -41,7 +41,6 @@ use js::error::throw_type_error;
use js::rust::HandleValue;
use profile_traits::ipc;
use script_layout_interface::{HTMLCanvasData, HTMLCanvasDataSource};
-use servo_config::pref;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
const DEFAULT_WIDTH: u32 = 300;
@@ -222,7 +221,8 @@ impl HTMLCanvasElement {
cx: JSContext,
options: HandleValue,
) -> Option<DomRoot<WebGL2RenderingContext>> {
- if !pref!(dom.webgl2.enabled) {
+ if !WebGL2RenderingContext::is_webgl2_enabled(cx, self.global().reflector().get_jsobject())
+ {
return None;
}
if let Some(ctx) = self.context() {
diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs
index 62af18d1002..8e967fbcb86 100644
--- a/components/script/dom/webgl2renderingcontext.rs
+++ b/components/script/dom/webgl2renderingcontext.rs
@@ -16,6 +16,7 @@ use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::DOMString;
+use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::htmliframeelement::HTMLIFrameElement;
use crate::dom::webglactiveinfo::WebGLActiveInfo;
@@ -50,12 +51,14 @@ use ipc_channel::ipc;
use js::jsapi::{JSObject, Type};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, UInt32Value};
use js::jsval::{JSVal, NullValue, ObjectValue, UndefinedValue};
-use js::rust::CustomAutoRooterGuard;
+use js::rust::{CustomAutoRooterGuard, HandleObject};
use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array};
use script_layout_interface::HTMLCanvasDataSource;
+use servo_config::pref;
use std::cell::Cell;
use std::cmp;
use std::ptr::{self, NonNull};
+use url::Host;
#[unrooted_must_root_lint::must_root]
#[derive(JSTraceable, MallocSizeOf)]
@@ -178,8 +181,26 @@ impl WebGL2RenderingContext {
WebGL2RenderingContext::new_inherited(window, canvas, size, attrs)
.map(|ctx| reflect_dom_object(Box::new(ctx), window))
}
+
+ #[allow(unsafe_code)]
+ pub fn is_webgl2_enabled(_cx: JSContext, global: HandleObject) -> bool {
+ if pref!(dom.webgl2.enabled) {
+ return true;
+ }
+
+ let global = unsafe { GlobalScope::from_object(global.get()) };
+ let origin = global.origin();
+ let host = origin.host();
+ WEBGL2_ORIGINS
+ .iter()
+ .any(|origin| host == Host::parse(origin).ok().as_ref())
+ }
}
+/// List of domains for which WebGL 2 is enabled automatically, regardless
+/// of the status of the dom.webgl2.enabled preference.
+static WEBGL2_ORIGINS: &[&str] = &["www.servoexperiments.com"];
+
impl WebGL2RenderingContext {
pub fn recreate(&self, size: Size2D<u32>) {
self.base.recreate(size)
diff --git a/components/script/dom/webidls/WebGL2RenderingContext.webidl b/components/script/dom/webidls/WebGL2RenderingContext.webidl
index e7f94cb9a3c..f6278370cce 100644
--- a/components/script/dom/webidls/WebGL2RenderingContext.webidl
+++ b/components/script/dom/webidls/WebGL2RenderingContext.webidl
@@ -542,7 +542,7 @@ interface mixin WebGL2RenderingContextBase
void bindVertexArray(WebGLVertexArrayObject? array);
};
-[Exposed=Window, Pref="dom.webgl2.enabled"]
+[Exposed=Window, Func="WebGL2RenderingContext::is_webgl2_enabled"]
interface WebGL2RenderingContext
{
};