mirror of
https://github.com/servo/servo.git
synced 2025-06-10 17:43:16 +00:00
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.
This commit is contained in:
commit
693bbaf095
2 changed files with 33 additions and 49 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue