diff options
author | Alan Jeffrey <ajeffrey@mozilla.com> | 2017-03-01 12:00:33 -0600 |
---|---|---|
committer | Alan Jeffrey <ajeffrey@mozilla.com> | 2017-03-17 10:53:20 -0500 |
commit | 6bcb5f68be752d5439a4e5a899c5a72016b626df (patch) | |
tree | 24e8b34f3c78173465098e083a9982becf332756 /components/script/dom/dissimilaroriginwindow.rs | |
parent | 0b590aeed73df3c1f1891fbb276010b29a8d7051 (diff) | |
download | servo-6bcb5f68be752d5439a4e5a899c5a72016b626df.tar.gz servo-6bcb5f68be752d5439a4e5a899c5a72016b626df.zip |
Implement dissimilar-origin window.parent and window.top.
Diffstat (limited to 'components/script/dom/dissimilaroriginwindow.rs')
-rw-r--r-- | components/script/dom/dissimilaroriginwindow.rs | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/components/script/dom/dissimilaroriginwindow.rs b/components/script/dom/dissimilaroriginwindow.rs index 96171ef3bf1..0f3cbd06df0 100644 --- a/components/script/dom/dissimilaroriginwindow.rs +++ b/components/script/dom/dissimilaroriginwindow.rs @@ -7,7 +7,6 @@ use dom::bindings::codegen::Bindings::DissimilarOriginWindowBinding::DissimilarO use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableJS, Root}; -use dom::bindings::reflector::DomObject; use dom::bindings::str::DOMString; use dom::bindings::structuredclone::StructuredCloneData; use dom::browsingcontext::BrowsingContext; @@ -45,19 +44,18 @@ pub struct DissimilarOriginWindow { impl DissimilarOriginWindow { #[allow(unsafe_code)] - pub fn new(browsing_context: &BrowsingContext) -> Root<DissimilarOriginWindow> { - let globalscope = browsing_context.global(); - let cx = globalscope.get_cx(); + pub fn new(global_to_clone_from: &GlobalScope, browsing_context: &BrowsingContext) -> Root<DissimilarOriginWindow> { + let cx = global_to_clone_from.get_cx(); // Any timer events fired on this window are ignored. let (timer_event_chan, _) = ipc::channel().unwrap(); let win = box DissimilarOriginWindow { globalscope: GlobalScope::new_inherited(PipelineId::new(), - globalscope.devtools_chan().cloned(), - globalscope.mem_profiler_chan().clone(), - globalscope.time_profiler_chan().clone(), - globalscope.constellation_chan().clone(), - globalscope.scheduler_chan().clone(), - globalscope.resource_threads().clone(), + global_to_clone_from.devtools_chan().cloned(), + global_to_clone_from.mem_profiler_chan().clone(), + global_to_clone_from.time_profiler_chan().clone(), + global_to_clone_from.constellation_chan().clone(), + global_to_clone_from.scheduler_chan().clone(), + global_to_clone_from.resource_threads().clone(), timer_event_chan), browsing_context: JS::from_ref(browsing_context), location: MutNullableJS::new(None), @@ -84,14 +82,26 @@ impl DissimilarOriginWindowMethods for DissimilarOriginWindow { // https://html.spec.whatwg.org/multipage/#dom-parent fn GetParent(&self) -> Option<Root<BrowsingContext>> { - // TODO: implement window.parent correctly for x-origin windows. + // Steps 1-3. + if self.browsing_context.is_discarded() { + return None; + } + // Step 4. + if let Some(parent) = self.browsing_context.parent() { + return Some(Root::from_ref(parent)); + } + // Step 5. Some(Root::from_ref(&*self.browsing_context)) } // https://html.spec.whatwg.org/multipage/#dom-top fn GetTop(&self) -> Option<Root<BrowsingContext>> { - // TODO: implement window.top correctly for x-origin windows. - Some(Root::from_ref(&*self.browsing_context)) + // Steps 1-3. + if self.browsing_context.is_discarded() { + return None; + } + // Steps 4-5. + Some(Root::from_ref(self.browsing_context.top())) } // https://html.spec.whatwg.org/multipage/#dom-length |