Skip to content

Commit 3f49255

Browse files
committed
Simplify the iframe content getters.
1 parent 3b6d7db commit 3f49255

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

components/script/dom/browsercontext.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ impl<'a> DocumentRef<'a> {
148148
}
149149
}
150150

151+
pub fn is_local(&self) -> bool {
152+
match *self {
153+
DocumentRef::Local(_) => true,
154+
DocumentRef::Remote(_) => false,
155+
}
156+
}
157+
151158
pub fn window(&self) -> WindowRef<'a> {
152159
match *self {
153160
DocumentRef::Local(ref document) => WindowRef::Local(document.window()),
@@ -174,6 +181,13 @@ impl<'a> WindowRef<'a> {
174181
WindowRef::Remote(_) => panic!("unexpected remote window"),
175182
}
176183
}
184+
185+
pub fn is_local(&self) -> bool {
186+
match *self {
187+
WindowRef::Local(_) => true,
188+
WindowRef::Remote(_) => false,
189+
}
190+
}
177191
}
178192

179193
// This isn't a DOM struct, just a convenience struct

components/script/dom/htmliframeelement.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use dom::attr::{Attr, AttrValue};
66
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementIconChangeEventDetail;
77
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
88
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
9-
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
109
use dom::bindings::conversions::{ToJSValConvertible};
1110
use dom::bindings::error::{Error, ErrorResult, Fallible};
1211
use dom::bindings::global::GlobalRef;
@@ -21,7 +20,6 @@ use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
2120
use dom::event::{Event, EventBubbles, EventCancelable};
2221
use dom::htmlelement::HTMLElement;
2322
use dom::node::{Node, window_from_node};
24-
use dom::urlhelper::UrlHelper;
2523
use dom::virtualmethods::VirtualMethods;
2624
use dom::window::Window;
2725
use ipc_channel::ipc;
@@ -32,7 +30,6 @@ use msg::constellation_msg::ScriptMsg as ConstellationMsg;
3230
use msg::constellation_msg::{ConstellationChan, IframeLoadInfo, MozBrowserEvent};
3331
use msg::constellation_msg::{IFrameLoadType, AsyncIFrameLoad};
3432
use msg::constellation_msg::{NavigationDirection, PipelineId, SubpageId};
35-
use page::IterablePage;
3633
use script_task::{ScriptTaskEventCategory, CommonScriptMsg, ScriptTask, Runnable};
3734
use script_traits::ConstellationControlMsg;
3835
use std::ascii::AsciiExt;
@@ -391,28 +388,22 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
391388

392389
// https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow
393390
fn GetContentWindow(&self) -> Option<Root<Window>> {
394-
self.subpage_id.get().and_then(|subpage_id| {
395-
let window = window_from_node(self);
396-
let window = window.r();
397-
let children = window.page().children.borrow();
398-
children.iter().find(|page| {
399-
let window = page.window();
400-
window.subpage() == Some(subpage_id)
401-
}).map(|page| page.window())
391+
self.nested_browsing_context.get().and_then(|context| {
392+
let window = context.active_window();
393+
if window.is_local() {
394+
Some(Root::from_ref(window.as_local()))
395+
} else {
396+
None
397+
}
402398
})
403399
}
404400

405401
// https://html.spec.whatwg.org/multipage/#dom-iframe-contentdocument
406402
fn GetContentDocument(&self) -> Option<Root<Document>> {
407-
self.GetContentWindow().and_then(|window| {
408-
let self_url = match self.get_url() {
409-
Some(self_url) => self_url,
410-
None => return None,
411-
};
412-
let win_url = window_from_node(self).get_url();
413-
414-
if UrlHelper::SameOrigin(&self_url, &win_url) {
415-
Some(window.Document())
403+
self.nested_browsing_context.get().map(|context| {
404+
let document = context.active_document();
405+
if document.is_local() {
406+
Some(Root::from_ref(document.as_local()))
416407
} else {
417408
None
418409
}

0 commit comments

Comments
 (0)