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.
This commit is contained in:
Ms2ger 2014-05-11 22:34:03 +02:00
parent c6274f9793
commit d095c42eaf
3 changed files with 70 additions and 60 deletions

View file

@ -4,14 +4,12 @@
use dom::attr::AttrMethods;
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast};
use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, Root};
use dom::bindings::utils::Reflectable;
use dom::document::{Document, DocumentHelpers};
use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId};
use dom::element::{AttributeHandlers, HTMLLinkElementTypeId};
use dom::htmlelement::HTMLElement;
use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6};
use dom::htmliframeelement::{IFrameSize, HTMLIFrameElementHelpers};
use dom::htmlformelement::HTMLFormElement;
use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods};
use dom::types::*;
@ -19,7 +17,6 @@ use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
use script_task::Page;
use hubbub::hubbub;
use servo_msg::constellation_msg::SubpageId;
use servo_net::resource_task::{Load, Payload, Done, ResourceTask, load_whole_resource};
use servo_util::namespace::Null;
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
@ -67,7 +64,6 @@ enum JSMessage {
/// Messages generated by the HTML parser upon discovery of additional resources
pub enum HtmlDiscoveryMessage {
HtmlDiscoveredStyle(Stylesheet),
HtmlDiscoveredIFrame((Url, SubpageId, bool)),
HtmlDiscoveredScript(JSResult)
}
@ -252,7 +248,6 @@ pub fn parse_html(page: &Page,
resource_task: ResourceTask)
-> HtmlParserResult {
debug!("Hubbub: parsing {:?}", url);
let next_subpage_id: SubpageId = page.next_subpage_id.deref().get();
// Spawn a CSS parser to receive links to CSS style sheets.
let (discovery_chan, discovery_port) = channel();
@ -288,8 +283,6 @@ pub fn parse_html(page: &Page,
*page.mut_url() = Some((url2.clone(), true));
}
let pipeline_id = page.id;
let mut parser = hubbub::Parser("UTF-8", false);
debug!("created parser");
@ -299,8 +292,6 @@ pub fn parse_html(page: &Page,
let (css_chan2, js_chan2) = (css_chan.clone(), js_chan.clone());
let next_subpage_id = RefCell::new(next_subpage_id);
let doc_cell = RefCell::new(document);
let tree_handler = hubbub::TreeHandler {
@ -352,10 +343,6 @@ pub fn parse_html(page: &Page,
let href= element.get_attribute(Null, "href").root();
href.map(|a| a.deref().Value())
};
let src_opt = {
let src_opt = element.get_attribute(Null, "src").root();
src_opt.map(|a| a.deref().Value())
};
// Spawn additional parsing, network loads, etc. from tag and attrs
let type_id = {
@ -377,29 +364,6 @@ pub fn parse_html(page: &Page,
_ => {}
}
}
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
let iframe_chan = discovery_chan.clone();
let iframe_element: &mut JSRef<HTMLIFrameElement> =
HTMLIFrameElementCast::to_mut_ref(&mut *element).unwrap();
let sandboxed = iframe_element.is_sandboxed();
for src in src_opt.iter() {
let iframe_url = parse_url(*src, Some(url2.clone()));
// Subpage Id
let subpage_id = *next_subpage_id.borrow();
let SubpageId(id_num) = subpage_id;
*next_subpage_id.borrow_mut() = SubpageId(id_num + 1);
iframe_element.deref_mut().size = Some(IFrameSize {
pipeline_id: pipeline_id,
subpage_id: subpage_id,
});
iframe_chan.send(HtmlDiscoveredIFrame((iframe_url,
subpage_id,
sandboxed)));
}
}
_ => {}
}