aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/htmliframeelement.rs
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-05-11 22:34:03 +0200
committerMs2ger <ms2ger@gmail.com>2014-05-12 21:21:03 +0200
commitd095c42eaf4b18be93f199ed886f93e5657234d7 (patch)
tree202dcf68f3c0897224b6f35a45c6c262e20e980f /src/components/script/dom/htmliframeelement.rs
parentc6274f9793cf3bab74b58a697961680567dea97b (diff)
downloadservo-d095c42eaf4b18be93f199ed886f93e5657234d7.tar.gz
servo-d095c42eaf4b18be93f199ed886f93e5657234d7.zip
Move the loading of documents in iframes into HTMLIFrameElement.
Right now, the load is kicked off inside the parser glue. This is unfortunate for several reasons: 1) we'd like to replace the current parser (libhubbub) by our own parser, written in Rust, so code intertwined with the parser will have to be rewritten; 2) it is impossible to support dynamically (i.e. from script) created iframes in this way; 3) the code flow around loading subdocuments is complicated needlessly. This commit adds the constellation channel (on which the message to actually load the document is sent) as a field on the Page, to allow HTMLIFrameElement to access it. In rewriting the code, support for dynamically created iframes is added, and a task failure is avoided when the value of the src attribute can not be parsed.
Diffstat (limited to 'src/components/script/dom/htmliframeelement.rs')
-rw-r--r--src/components/script/dom/htmliframeelement.rs52
1 files changed, 49 insertions, 3 deletions
diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs
index 9f77cda6829..f92fddabdaa 100644
--- a/src/components/script/dom/htmliframeelement.rs
+++ b/src/components/script/dom/htmliframeelement.rs
@@ -5,19 +5,24 @@
use dom::bindings::codegen::BindingDeclarations::HTMLIFrameElementBinding;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementDerived, HTMLElementCast};
use dom::bindings::error::ErrorResult;
-use dom::bindings::js::{JSRef, Temporary};
+use dom::bindings::js::{JSRef, Temporary, OptionalRootable};
use dom::document::Document;
use dom::element::{HTMLIFrameElementTypeId, Element};
use dom::element::AttributeHandlers;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
-use dom::node::{Node, ElementNodeTypeId};
+use dom::node::{Node, ElementNodeTypeId, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom::window::Window;
+use servo_msg::constellation_msg::{PipelineId, SubpageId};
+use servo_msg::constellation_msg::{IFrameSandboxed, IFrameUnsandboxed};
+use servo_msg::constellation_msg::{ConstellationChan, LoadIframeUrlMsg};
+use servo_util::namespace::Null;
use servo_util::str::DOMString;
+use servo_util::url::try_parse_url;
-use servo_msg::constellation_msg::{PipelineId, SubpageId};
use std::ascii::StrAsciiExt;
+use url::Url;
enum SandboxAllowance {
AllowNothing = 0x00,
@@ -50,12 +55,22 @@ pub struct IFrameSize {
pub trait HTMLIFrameElementHelpers {
fn is_sandboxed(&self) -> bool;
+ fn get_url(&self) -> Option<Url>;
}
impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> {
fn is_sandboxed(&self) -> bool {
self.sandbox.is_some()
}
+
+ fn get_url(&self) -> Option<Url> {
+ let element: &JSRef<Element> = ElementCast::from_ref(self);
+ element.get_attribute(Null, "src").root().and_then(|src| {
+ let window = window_from_node(self).root();
+ try_parse_url(src.deref().value_ref(),
+ Some(window.deref().page().get_url())).ok()
+ })
+ }
}
impl HTMLIFrameElement {
@@ -266,4 +281,35 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
self.deref_mut().sandbox = None;
}
}
+
+ fn bind_to_tree(&mut self) {
+ match self.super_type() {
+ Some(ref mut s) => s.bind_to_tree(),
+ _ => (),
+ }
+
+ match self.get_url() {
+ Some(url) => {
+ let sandboxed = if self.is_sandboxed() {
+ IFrameSandboxed
+ } else {
+ IFrameUnsandboxed
+ };
+
+ // Subpage Id
+ let window = window_from_node(self).root();
+ let page = window.deref().page();
+ let subpage_id = page.get_next_subpage_id();
+
+ self.deref_mut().size = Some(IFrameSize {
+ pipeline_id: page.id,
+ subpage_id: subpage_id,
+ });
+
+ let ConstellationChan(ref chan) = *page.constellation_chan.deref();
+ chan.send(LoadIframeUrlMsg(url, page.id, subpage_id, sandboxed));
+ }
+ _ => ()
+ }
+ }
}