Use [Func] on HTMLIFrameElement.mozbrowser

This commit is contained in:
Anthony Ramine 2016-05-24 00:56:48 +02:00
parent 34dfc28e98
commit 694deabcd5
3 changed files with 24 additions and 24 deletions

View file

@ -433,29 +433,16 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
// Experimental mozbrowser implementation is based on the webidl // Experimental mozbrowser implementation is based on the webidl
// present in the gecko source tree, and the documentation here: // present in the gecko source tree, and the documentation here:
// https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API // https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API
// TODO(gw): Use experimental codegen when it is available to avoid
// exposing these APIs. See https://github.com/servo/servo/issues/5264.
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
fn Mozbrowser(&self) -> bool { fn Mozbrowser(&self) -> bool {
// We don't want to allow mozbrowser iframes within iframes let element = self.upcast::<Element>();
let is_root_pipeline = window_from_node(self).parent_info().is_none(); element.has_attribute(&atom!("mozbrowser"))
if mozbrowser_enabled() && is_root_pipeline {
let element = self.upcast::<Element>();
element.has_attribute(&atom!("mozbrowser"))
} else {
false
}
} }
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
fn SetMozbrowser(&self, value: bool) -> ErrorResult { fn SetMozbrowser(&self, value: bool) {
if mozbrowser_enabled() { let element = self.upcast::<Element>();
let element = self.upcast::<Element>(); element.set_bool_attribute(&atom!("mozbrowser"), value);
element.set_bool_attribute(&atom!("mozbrowser"), value);
}
Ok(())
} }
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack

View file

@ -32,8 +32,8 @@ partial interface HTMLIFrameElement {
}; };
partial interface HTMLIFrameElement { partial interface HTMLIFrameElement {
[ChromeOnly,SetterThrows,Pref="dom.mozbrowser.enabled"] [Func="Window::global_is_mozbrowser"]
attribute boolean mozbrowser; attribute boolean mozbrowser;
}; };
HTMLIFrameElement implements BrowserElement; HTMLIFrameElement implements BrowserElement;

View file

@ -14,7 +14,7 @@ use dom::bindings::codegen::Bindings::FunctionBinding::Function;
use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions}; use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods}; use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods};
use dom::bindings::error::{Error, Fallible, report_pending_exception}; use dom::bindings::error::{Error, Fallible, report_pending_exception};
use dom::bindings::global::GlobalRef; use dom::bindings::global::{GlobalRef, global_root_from_object};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{JS, MutNullableHeap, Root};
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
@ -37,9 +37,8 @@ use dom::storage::Storage;
use euclid::{Point2D, Rect, Size2D}; use euclid::{Point2D, Rect, Size2D};
use gfx_traits::LayerId; use gfx_traits::LayerId;
use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{Evaluate2, MutableHandleValue}; use js::jsapi::{Evaluate2, HandleObject, HandleValue, JSAutoCompartment, JSContext};
use js::jsapi::{HandleValue, JSContext}; use js::jsapi::{JS_GetRuntime, JS_GC, MutableHandleValue, SetWindowProxy};
use js::jsapi::{JSAutoCompartment, JS_GC, JS_GetRuntime, SetWindowProxy};
use js::rust::CompileOptionsWrapper; use js::rust::CompileOptionsWrapper;
use js::rust::Runtime; use js::rust::Runtime;
use layout_interface::{ContentBoxResponse, ContentBoxesResponse, ResolvedStyleResponse, ScriptReflow}; use layout_interface::{ContentBoxResponse, ContentBoxesResponse, ResolvedStyleResponse, ScriptReflow};
@ -93,6 +92,7 @@ use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle, OneshotTimers
use tinyfiledialogs::{self, MessageBoxIcon}; use tinyfiledialogs::{self, MessageBoxIcon};
use url::Url; use url::Url;
use util::geometry::{self, MAX_RECT}; use util::geometry::{self, MAX_RECT};
use util::prefs::mozbrowser_enabled;
use util::str::HTML_SPACE_CHARACTERS; use util::str::HTML_SPACE_CHARACTERS;
use util::{breakpoint, opts}; use util::{breakpoint, opts};
use webdriver_handlers::jsval_to_webdriver; use webdriver_handlers::jsval_to_webdriver;
@ -1432,6 +1432,19 @@ impl Window {
context.active_window() context.active_window()
}) })
} }
/// Returns whether mozbrowser is enabled and `obj` has been created
/// in a top-level `Window` global.
#[allow(unsafe_code)]
pub unsafe fn global_is_mozbrowser(_: *mut JSContext, obj: HandleObject) -> bool {
if !mozbrowser_enabled() {
return false;
}
match global_root_from_object(obj.get()).r() {
GlobalRef::Window(window) => window.parent_info().is_none(),
_ => false,
}
}
} }
impl Window { impl Window {