mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Return window proxy properly for indexed window getter
This commit is contained in:
parent
4383b3053b
commit
080600003c
3 changed files with 46 additions and 18 deletions
|
@ -77,22 +77,26 @@ impl DissimilarOriginWindow {
|
||||||
pub fn origin(&self) -> &MutableOrigin {
|
pub fn origin(&self) -> &MutableOrigin {
|
||||||
self.upcast::<GlobalScope>().origin()
|
self.upcast::<GlobalScope>().origin()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn window_proxy(&self) -> DomRoot<WindowProxy> {
|
||||||
|
DomRoot::from_ref(&*self.window_proxy)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DissimilarOriginWindowMethods for DissimilarOriginWindow {
|
impl DissimilarOriginWindowMethods for DissimilarOriginWindow {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-window
|
// https://html.spec.whatwg.org/multipage/#dom-window
|
||||||
fn Window(&self) -> DomRoot<WindowProxy> {
|
fn Window(&self) -> DomRoot<WindowProxy> {
|
||||||
DomRoot::from_ref(&*self.window_proxy)
|
self.window_proxy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-self
|
// https://html.spec.whatwg.org/multipage/#dom-self
|
||||||
fn Self_(&self) -> DomRoot<WindowProxy> {
|
fn Self_(&self) -> DomRoot<WindowProxy> {
|
||||||
DomRoot::from_ref(&*self.window_proxy)
|
self.window_proxy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-frames
|
// https://html.spec.whatwg.org/multipage/#dom-frames
|
||||||
fn Frames(&self) -> DomRoot<WindowProxy> {
|
fn Frames(&self) -> DomRoot<WindowProxy> {
|
||||||
DomRoot::from_ref(&*self.window_proxy)
|
self.window_proxy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-parent
|
// https://html.spec.whatwg.org/multipage/#dom-parent
|
||||||
|
|
|
@ -1634,11 +1634,6 @@ impl Window {
|
||||||
had_clip_rect
|
had_clip_rect
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#accessing-other-browsing-contexts
|
|
||||||
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<DomRoot<Window>> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn suspend(&self) {
|
pub fn suspend(&self) {
|
||||||
// Suspend timer events.
|
// Suspend timer events.
|
||||||
self.upcast::<GlobalScope>().suspend();
|
self.upcast::<GlobalScope>().suspend();
|
||||||
|
|
|
@ -17,6 +17,7 @@ use dom::element::Element;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use ipc_channel::ipc;
|
||||||
use js::JSCLASS_IS_GLOBAL;
|
use js::JSCLASS_IS_GLOBAL;
|
||||||
use js::glue::{CreateWrapperProxyHandler, ProxyTraps};
|
use js::glue::{CreateWrapperProxyHandler, ProxyTraps};
|
||||||
use js::glue::{GetProxyPrivate, SetProxyExtra, GetProxyExtra};
|
use js::glue::{GetProxyPrivate, SetProxyExtra, GetProxyExtra};
|
||||||
|
@ -40,6 +41,8 @@ use js::rust::wrappers::{NewWindowProxy, SetWindowProxy, JS_TransplantObject};
|
||||||
use msg::constellation_msg::BrowsingContextId;
|
use msg::constellation_msg::BrowsingContextId;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||||
|
use script_thread::ScriptThread;
|
||||||
|
use script_traits::ScriptMsg;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
@ -301,17 +304,43 @@ impl WindowProxy {
|
||||||
|
|
||||||
// This is only called from extern functions,
|
// This is only called from extern functions,
|
||||||
// there's no use using the lifetimed handles here.
|
// there's no use using the lifetimed handles here.
|
||||||
|
// https://html.spec.whatwg.org/multipage/#accessing-other-browsing-contexts
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn GetSubframeWindow(cx: *mut JSContext,
|
unsafe fn GetSubframeWindowProxy(
|
||||||
proxy: RawHandleObject,
|
cx: *mut JSContext,
|
||||||
id: RawHandleId)
|
proxy: RawHandleObject,
|
||||||
-> Option<DomRoot<Window>> {
|
id: RawHandleId
|
||||||
|
) -> Option<DomRoot<WindowProxy>> {
|
||||||
let index = get_array_index_from_id(cx, Handle::from_raw(id));
|
let index = get_array_index_from_id(cx, Handle::from_raw(id));
|
||||||
if let Some(index) = index {
|
if let Some(index) = index {
|
||||||
rooted!(in(cx) let target = GetProxyPrivate(*proxy).to_object());
|
rooted!(in(cx) let target = GetProxyPrivate(*proxy).to_object());
|
||||||
let win = root_from_handleobject::<Window>(target.handle()).unwrap();
|
if let Ok(win) = root_from_handleobject::<Window>(target.handle()) {
|
||||||
let mut found = false;
|
let browsing_context_id = win.window_proxy().browsing_context_id();
|
||||||
return win.IndexedGetter(index, &mut found);
|
let (result_sender, result_receiver) = ipc::channel().unwrap();
|
||||||
|
|
||||||
|
let _ = win.upcast::<GlobalScope>().script_to_constellation_chan().send(
|
||||||
|
ScriptMsg::GetChildBrowsingContextId(
|
||||||
|
browsing_context_id,
|
||||||
|
index as usize,
|
||||||
|
result_sender
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return result_receiver.recv().ok()
|
||||||
|
.and_then(|maybe_bcid| maybe_bcid)
|
||||||
|
.and_then(ScriptThread::find_window_proxy);
|
||||||
|
} else if let Ok(win) = root_from_handleobject::<DissimilarOriginWindow>(target.handle()) {
|
||||||
|
let browsing_context_id = win.window_proxy().browsing_context_id();
|
||||||
|
let (result_sender, result_receiver) = ipc::channel().unwrap();
|
||||||
|
|
||||||
|
let _ = win.global().script_to_constellation_chan().send(ScriptMsg::GetChildBrowsingContextId(
|
||||||
|
browsing_context_id,
|
||||||
|
index as usize,
|
||||||
|
result_sender
|
||||||
|
));
|
||||||
|
return result_receiver.recv().ok()
|
||||||
|
.and_then(|maybe_bcid| maybe_bcid)
|
||||||
|
.and_then(ScriptThread::find_window_proxy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -323,7 +352,7 @@ unsafe extern "C" fn getOwnPropertyDescriptor(cx: *mut JSContext,
|
||||||
id: RawHandleId,
|
id: RawHandleId,
|
||||||
mut desc: RawMutableHandle<PropertyDescriptor>)
|
mut desc: RawMutableHandle<PropertyDescriptor>)
|
||||||
-> bool {
|
-> bool {
|
||||||
let window = GetSubframeWindow(cx, proxy, id);
|
let window = GetSubframeWindowProxy(cx, proxy, id);
|
||||||
if let Some(window) = window {
|
if let Some(window) = window {
|
||||||
rooted!(in(cx) let mut val = UndefinedValue());
|
rooted!(in(cx) let mut val = UndefinedValue());
|
||||||
window.to_jsval(cx, val.handle_mut());
|
window.to_jsval(cx, val.handle_mut());
|
||||||
|
@ -372,7 +401,7 @@ unsafe extern "C" fn has(cx: *mut JSContext,
|
||||||
id: RawHandleId,
|
id: RawHandleId,
|
||||||
bp: *mut bool)
|
bp: *mut bool)
|
||||||
-> bool {
|
-> bool {
|
||||||
let window = GetSubframeWindow(cx, proxy, id);
|
let window = GetSubframeWindowProxy(cx, proxy, id);
|
||||||
if window.is_some() {
|
if window.is_some() {
|
||||||
*bp = true;
|
*bp = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -395,7 +424,7 @@ unsafe extern "C" fn get(cx: *mut JSContext,
|
||||||
id: RawHandleId,
|
id: RawHandleId,
|
||||||
vp: RawMutableHandleValue)
|
vp: RawMutableHandleValue)
|
||||||
-> bool {
|
-> bool {
|
||||||
let window = GetSubframeWindow(cx, proxy, id);
|
let window = GetSubframeWindowProxy(cx, proxy, id);
|
||||||
if let Some(window) = window {
|
if let Some(window) = window {
|
||||||
window.to_jsval(cx, MutableHandle::from_raw(vp));
|
window.to_jsval(cx, MutableHandle::from_raw(vp));
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue