From 7d8fc38a205b2ef9d351fae0a833c47ecff1dc8f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 27 Jul 2012 16:19:38 -0700 Subject: [PATCH] servo: Begin threading the ResourceTask through the engine Source-Repo: https://github.com/servo/servo Source-Revision: f48309739f780103f875b8d0cba2079f76ad588c --- servo/src/servo/content.rs | 15 +++++++++++---- servo/src/servo/engine.rs | 9 ++++++++- servo/src/servo/parser/html_lexer.rs | 4 +++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/servo/src/servo/content.rs b/servo/src/servo/content.rs index c5d03b73bed0..a20d36e5f79c 100644 --- a/servo/src/servo/content.rs +++ b/servo/src/servo/content.rs @@ -35,6 +35,9 @@ import result::extensions; import dom::bindings::utils::rust_box; import js::rust::compartment; +import resource::resource_task; +import resource_task::{ResourceTask}; + type Content = chan; enum ControlMsg { @@ -81,7 +84,9 @@ class Content { let mut document: option<@Document>; - new(layout: Layout, sink: S, from_master: port) { + let resource_task: ResourceTask; + + new(layout: Layout, sink: S, from_master: port, resource_task: ResourceTask) { self.layout = layout; self.sink = sink; self.from_master = from_master; @@ -93,6 +98,8 @@ class Content { self.document = none; self.sink.add_event_listener(self.event_port.chan()); + + self.resource_task = resource_task; } fn start() { @@ -119,7 +126,7 @@ class Content { // Note: we can parse the next document in parallel // with any previous documents. - let stream = spawn_html_lexer_task(copy filename); + let stream = spawn_html_lexer_task(copy filename, self.resource_task); let (root, style_port, js_port) = build_dom(self.scope, stream); let css_rules = style_port.recv(); let js_scripts = js_port.recv(); @@ -210,9 +217,9 @@ class Content { } } -fn create_content(layout: Layout, sink: S) -> chan { +fn create_content(layout: Layout, sink: S, resource_task: ResourceTask) -> chan { do spawn_listener:: |from_master| { - Content(layout, sink, from_master).start(); + Content(layout, sink, from_master, resource_task).start(); } } diff --git a/servo/src/servo/engine.rs b/servo/src/servo/engine.rs index 8cc97b83e3c8..f248ac1b27bb 100644 --- a/servo/src/servo/engine.rs +++ b/servo/src/servo/engine.rs @@ -4,6 +4,8 @@ import comm::chan; import layout::layout_task; import layout_task::Layout; import content::{Content, ExecuteMsg, ParseMsg, ExitMsg, create_content}; +import resource::resource_task; +import resource::resource_task::{ResourceTask}; import pipes::{port, chan}; @@ -12,6 +14,7 @@ class Engine { let renderer: Renderer; let layout: Layout; + let resource_task: ResourceTask; let content: comm::chan; new(+sink: S) { @@ -19,10 +22,12 @@ class Engine { let renderer = Renderer(sink); let layout = Layout(renderer); - let content = create_content(layout, sink); + let resource_task = ResourceTask(); + let content = create_content(layout, sink, resource_task); self.renderer = renderer; self.layout = layout; + self.resource_task = resource_task; self.content = content; } @@ -55,6 +60,8 @@ class Engine { self.renderer.send(renderer::ExitMsg(response_chan)); response_port.recv(); + self.resource_task.send(resource_task::Exit); + sender.send(()); ret false; } diff --git a/servo/src/servo/parser/html_lexer.rs b/servo/src/servo/parser/html_lexer.rs index 895b23c07667..e52ee298317e 100644 --- a/servo/src/servo/parser/html_lexer.rs +++ b/servo/src/servo/parser/html_lexer.rs @@ -4,6 +4,8 @@ import option::is_none; import str::from_bytes; import vec::push; import lexer_util::*; +import resource::resource_task; +import resource_task::{ResourceTask}; enum Token { StartOpeningTag(~str), @@ -168,7 +170,7 @@ fn lexer(reader: io::reader, state : ParseState) -> HtmlLexer { } #[warn(no_non_implicitly_copyable_typarams)] -fn spawn_html_lexer_task(-filename: ~str) -> port { +fn spawn_html_lexer_task(-filename: ~str, resource_task: ResourceTask) -> port { let html_port = port(); let html_chan = chan(html_port); let html_file = copy filename;