diff options
author | bors-servo <release+servo@mozilla.com> | 2013-08-15 11:44:39 -0700 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2013-08-15 11:44:39 -0700 |
commit | 693bbaf095e3db607ab12b9217be2a7fd9e6350b (patch) | |
tree | 547d43a15e8c5aad93138ffd504ac1e1ba8f5334 /src | |
parent | d1bee3fe3d8fcf023d2648b285362cb293c27d39 (diff) | |
parent | a875b12c2245b09382800156073797194297973d (diff) | |
download | servo-693bbaf095e3db607ab12b9217be2a7fd9e6350b.tar.gz servo-693bbaf095e3db607ab12b9217be2a7fd9e6350b.zip |
auto merge of #731 : metajack/servo/noselect, r=pcwalton
The new runtime isn't quite mature enough to deal with it, and this
is faster anyway.
Rebased to land #728.
Diffstat (limited to 'src')
-rw-r--r-- | src/components/script/html/hubbub_html_parser.rs | 37 | ||||
-rw-r--r-- | src/components/script/script_task.rs | 45 |
2 files changed, 33 insertions, 49 deletions
diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 779cd85a71e..fd89d71da96 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -108,11 +108,16 @@ enum JSMessage { JSTaskExit } +/// Messages generated by the HTML parser upon discovery of additional resources +pub enum HtmlDiscoveryMessage { + HtmlDiscoveredStyle(Stylesheet), + HtmlDiscoveredIFrame((Url, SubpageId, Future<Size2D<uint>>)), + HtmlDiscoveredScript(JSResult) +} + pub struct HtmlParserResult { root: AbstractNode<ScriptView>, - style_port: Port<Stylesheet>, - iframe_port: Port<(Url, SubpageId, Future<Size2D<uint>>)>, - js_port: Port<JSResult>, + discovery_port: Port<HtmlDiscoveryMessage>, } trait NodeWrapping { @@ -144,7 +149,7 @@ spawned, collates them, and sends them to the given result channel. * `from_parent` - A port on which to receive new links. */ -fn css_link_listener(to_parent: Chan<Stylesheet>, +fn css_link_listener(to_parent: SharedChan<HtmlDiscoveryMessage>, from_parent: Port<CSSMessage>, resource_task: ResourceTask) { let mut result_vec = ~[]; @@ -163,11 +168,11 @@ fn css_link_listener(to_parent: Chan<Stylesheet>, // Send the sheets back in order // FIXME: Shouldn't wait until after we've recieved CSSTaskExit to start sending these for result_vec.iter().advance |port| { - to_parent.send(port.recv()); + to_parent.send(HtmlDiscoveredStyle(port.recv())); } } -fn js_script_listener(to_parent: Chan<~[~[u8]]>, +fn js_script_listener(to_parent: SharedChan<HtmlDiscoveryMessage>, from_parent: Port<JSMessage>, resource_task: ResourceTask) { let mut result_vec = ~[]; @@ -209,7 +214,7 @@ fn js_script_listener(to_parent: Chan<~[~[u8]]>, } let js_scripts = result_vec.iter().filter_map(|result_port| result_port.recv()).collect(); - to_parent.send(js_scripts); + to_parent.send(HtmlDiscoveredScript(js_scripts)); } // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized @@ -278,8 +283,10 @@ pub fn parse_html(cx: *JSContext, // Spawn a CSS parser to receive links to CSS style sheets. let resource_task2 = resource_task.clone(); - let (stylesheet_port, stylesheet_chan) = comm::stream(); - let stylesheet_chan = Cell::new(stylesheet_chan); + let (discovery_port, discovery_chan) = comm::stream(); + let discovery_chan = SharedChan::new(discovery_chan); + + let stylesheet_chan = Cell::new(discovery_chan.clone()); let (css_msg_port, css_msg_chan) = comm::stream(); let css_msg_port = Cell::new(css_msg_port); do spawn { @@ -290,8 +297,7 @@ pub fn parse_html(cx: *JSContext, // Spawn a JS parser to receive JavaScript. let resource_task2 = resource_task.clone(); - let (js_result_port, js_result_chan) = comm::stream(); - let js_result_chan = Cell::new(js_result_chan); + let js_result_chan = Cell::new(discovery_chan.clone()); let (js_msg_port, js_msg_chan) = comm::stream(); let js_msg_port = Cell::new(js_msg_port); do spawn { @@ -313,7 +319,6 @@ pub fn parse_html(cx: *JSContext, parser.enable_styling(true); let (css_chan2, css_chan3, js_chan2) = (css_chan.clone(), css_chan.clone(), js_chan.clone()); - let (iframe_port, iframe_chan) = comm::stream(); let next_subpage_id = Cell::new(next_subpage_id); parser.set_tree_handler(~hubbub::TreeHandler { @@ -367,7 +372,9 @@ pub fn parse_html(cx: *JSContext, } ElementNodeTypeId(HTMLIframeElementTypeId) => { + let iframe_chan = Cell::new(discovery_chan.clone()); do node.with_mut_iframe_element |iframe_element| { + let iframe_chan = iframe_chan.take(); let elem = &mut iframe_element.parent.parent; let src_opt = elem.get_attr("src").map(|x| x.to_str()); for src_opt.iter().advance |src| { @@ -384,7 +391,7 @@ pub fn parse_html(cx: *JSContext, iframe_element.subpage_id = Some(subpage_id); next_subpage_id.put_back(SubpageId(*subpage_id + 1)); - iframe_chan.send((iframe_url, subpage_id, size_future)); + iframe_chan.send(HtmlDiscoveredIFrame((iframe_url, subpage_id, size_future))); } } } @@ -536,9 +543,7 @@ pub fn parse_html(cx: *JSContext, HtmlParserResult { root: root, - style_port: stylesheet_port, - iframe_port: iframe_port, - js_port: js_result_port, + discovery_port: discovery_port, } } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 33c99683a03..3386f058b08 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -37,6 +37,7 @@ use std::util::replace; use dom::window::TimerData; use geom::size::Size2D; use html::hubbub_html_parser::HtmlParserResult; +use html::hubbub_html_parser::{HtmlDiscoveredStyle, HtmlDiscoveredIFrame, HtmlDiscoveredScript}; use html::hubbub_html_parser; use js::JSVAL_NULL; use js::global::{global_class, debug_fns}; @@ -605,7 +606,7 @@ impl ScriptTask { self.image_cache_task.clone(), page.next_subpage_id.clone()); - let HtmlParserResult {root, js_port, style_port, iframe_port} = html_parsing_result; + let HtmlParserResult {root, discovery_port} = html_parsing_result; // Create the window and document objects. let window = { @@ -637,52 +638,30 @@ impl ScriptTask { // FIXME: These should be streamed to layout as they're parsed. We don't need to stop here // in the script task. - let get_iframes = |iframe_port: &Port<(Url, SubpageId, Future<Size2D<uint>>)>| loop { - match iframe_port.try_recv() { - None => break, - Some((iframe_url, subpage_id, size_future)) => { - page.next_subpage_id = SubpageId(*subpage_id + 1); - self.constellation_chan.send(LoadIframeUrlMsg(iframe_url, - pipeline_id, - subpage_id, - size_future)); - } - } - }; - - let get_stylesheets = |style_port: &Port<Stylesheet>| loop { - match style_port.try_recv() { - None => break, - Some(sheet) => page.layout_chan.send(AddStylesheetMsg(sheet)), - } - }; - - let mut select_ports = (style_port, iframe_port); + let mut js_scripts = None; loop { - match select_ports.try_select() { - Left(None) => { - get_iframes(select_ports.second_ref()); - break; + match discovery_port.try_recv() { + Some(HtmlDiscoveredScript(scripts)) => { + assert!(js_scripts.is_none()); + js_scripts = Some(scripts); } - Left(Some(sheet)) => { + Some(HtmlDiscoveredStyle(sheet)) => { page.layout_chan.send(AddStylesheetMsg(sheet)); } - Right(Some((iframe_url, subpage_id, size_future))) => { + Some(HtmlDiscoveredIFrame((iframe_url, subpage_id, size_future))) => { page.next_subpage_id = SubpageId(*subpage_id + 1); self.constellation_chan.send(LoadIframeUrlMsg(iframe_url, pipeline_id, subpage_id, size_future)); } - Right(None) => { - get_stylesheets(select_ports.first_ref()); - break; - } + None => break } } // Receive the JavaScript scripts. - let js_scripts = js_port.recv(); + assert!(js_scripts.is_some()); + let js_scripts = js_scripts.swap_unwrap(); debug!("js_scripts: %?", js_scripts); // Perform the initial reflow. |