mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Automatically enable WebGL 2 for specific domains.
This commit is contained in:
parent
7d1f968d52
commit
e2845a6939
3 changed files with 25 additions and 4 deletions
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
{
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue