mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Represent URLs as url objects, not strings
This commit is contained in:
parent
1d7e37e299
commit
633c013567
6 changed files with 42 additions and 34 deletions
|
@ -38,11 +38,15 @@ import js::rust::compartment;
|
|||
import resource::resource_task;
|
||||
import resource_task::{ResourceTask};
|
||||
|
||||
import std::net::url::url;
|
||||
import url_to_str = std::net::url::to_str;
|
||||
import util::url::make_url;
|
||||
|
||||
type Content = chan<ControlMsg>;
|
||||
|
||||
enum ControlMsg {
|
||||
ParseMsg(~str),
|
||||
ExecuteMsg(~str),
|
||||
ParseMsg(url),
|
||||
ExecuteMsg(url),
|
||||
ExitMsg
|
||||
}
|
||||
|
||||
|
@ -121,12 +125,12 @@ class Content<S:Sink send copy> {
|
|||
|
||||
fn handle_control_msg(control_msg: ControlMsg) -> bool {
|
||||
alt control_msg {
|
||||
ParseMsg(filename) {
|
||||
#debug["content: Received filename `%s` to parse", filename];
|
||||
ParseMsg(url) {
|
||||
#debug["content: Received url `%s` to parse", url_to_str(url)];
|
||||
|
||||
// Note: we can parse the next document in parallel
|
||||
// with any previous documents.
|
||||
let stream = spawn_html_lexer_task(copy filename, self.resource_task);
|
||||
let stream = spawn_html_lexer_task(copy url, 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();
|
||||
|
@ -156,12 +160,12 @@ class Content<S:Sink send copy> {
|
|||
ret true;
|
||||
}
|
||||
|
||||
ExecuteMsg(filename) {
|
||||
#debug["content: Received filename `%s` to execute", filename];
|
||||
ExecuteMsg(url) {
|
||||
#debug["content: Received url `%s` to execute", url_to_str(url)];
|
||||
|
||||
alt read_whole_file(filename) {
|
||||
alt read_whole_file(url.path) {
|
||||
err(msg) {
|
||||
println(#fmt["Error opening %s: %s", filename, msg]);
|
||||
println(#fmt["Error opening %s: %s", url_to_str(url), msg]);
|
||||
}
|
||||
ok(bytes) {
|
||||
let cx = self.jsrt.cx();
|
||||
|
@ -169,7 +173,7 @@ class Content<S:Sink send copy> {
|
|||
cx.set_logging_error_reporter();
|
||||
cx.new_compartment(global_class).chain(|compartment| {
|
||||
compartment.define_functions(debug_fns);
|
||||
cx.evaluate_script(compartment.global_obj, bytes, filename, 1u)
|
||||
cx.evaluate_script(compartment.global_obj, bytes, url.path, 1u)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import layout_task::Layout;
|
|||
import content::{Content, ExecuteMsg, ParseMsg, ExitMsg, create_content};
|
||||
import resource::resource_task;
|
||||
import resource::resource_task::{ResourceTask};
|
||||
import std::net::url::url;
|
||||
|
||||
import pipes::{port, chan};
|
||||
|
||||
|
@ -42,8 +43,7 @@ class Engine<S:Sink send copy> {
|
|||
fn handle_request(request: Msg) -> bool {
|
||||
alt request {
|
||||
LoadURLMsg(url) {
|
||||
let url = copy url;
|
||||
if url.ends_with(".js") {
|
||||
if url.path.ends_with(".js") {
|
||||
self.content.send(ExecuteMsg(url))
|
||||
} else {
|
||||
self.content.send(ParseMsg(url))
|
||||
|
@ -70,7 +70,7 @@ class Engine<S:Sink send copy> {
|
|||
}
|
||||
|
||||
enum Msg {
|
||||
LoadURLMsg(~str),
|
||||
LoadURLMsg(url),
|
||||
ExitMsg(chan<()>)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ import pipes::{port, chan};
|
|||
|
||||
import lexer_util::*;
|
||||
|
||||
import std::net::url::url;
|
||||
|
||||
enum ParserState {
|
||||
CssElement,
|
||||
CssRelation,
|
||||
|
@ -252,21 +254,21 @@ fn spawn_css_lexer_from_string(-content : ~str) -> port<Token> {
|
|||
}
|
||||
|
||||
#[warn(no_non_implicitly_copyable_typarams)]
|
||||
fn spawn_css_lexer_task(-filename: ~str) -> pipes::port<Token> {
|
||||
fn spawn_css_lexer_task(-url: url) -> pipes::port<Token> {
|
||||
let (result_chan, result_port) = pipes::stream();
|
||||
|
||||
task::spawn(|| {
|
||||
assert filename.ends_with(".css");
|
||||
let file_try = io::read_whole_file(filename);
|
||||
assert url.path.ends_with(".css");
|
||||
let file_try = io::read_whole_file(url.path);
|
||||
|
||||
// Check if the given css file existed, if it does, parse it,
|
||||
// otherwise just send an eof.
|
||||
if file_try.is_ok() {
|
||||
#debug["Lexing css sheet %?", filename];
|
||||
#debug["Lexing css sheet %?", url.path];
|
||||
let file_data = file_try.get();
|
||||
lex_css_from_bytes(file_data, result_chan);
|
||||
} else {
|
||||
#debug["Failed to open css sheet %?", filename];
|
||||
#debug["Failed to open css sheet %?", url.path];
|
||||
result_chan.send(Eof);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,11 +12,12 @@ import parser = parser::html_lexer;
|
|||
import parser::Token;
|
||||
import dom::style::Stylesheet;
|
||||
import vec::{push, push_all_move, flat_map};
|
||||
import std::net::url::url;
|
||||
|
||||
import dvec::extensions;
|
||||
|
||||
enum CSSMessage {
|
||||
File(~str),
|
||||
File(url),
|
||||
Exit
|
||||
}
|
||||
|
||||
|
@ -99,14 +100,11 @@ fn css_link_listener(to_parent : comm::chan<Stylesheet>, from_parent : comm::por
|
|||
|
||||
loop {
|
||||
alt from_parent.recv() {
|
||||
File(filename) {
|
||||
File(url) {
|
||||
let result_port = comm::port();
|
||||
let result_chan = comm::chan(result_port);
|
||||
let filename = copy filename;
|
||||
task::spawn(|| {
|
||||
//TODO: deal with extraneous copies
|
||||
let filename <- copy filename;
|
||||
let css_stream = css_lexer::spawn_css_lexer_task(filename);
|
||||
let css_stream = css_lexer::spawn_css_lexer_task(copy url);
|
||||
let mut css_rules = css_builder::build_stylesheet(css_stream);
|
||||
result_chan.send(css_rules);
|
||||
});
|
||||
|
@ -205,7 +203,9 @@ fn build_dom(scope: NodeScope, stream: comm::port<Token>) -> (Node, comm::port<S
|
|||
alt elmt.get_attr(~"href") {
|
||||
some(filename) {
|
||||
#debug["Linking to a css sheet named: %s", filename];
|
||||
style_chan.send(File(copy filename));
|
||||
// FIXME: Need to base the new url on the current url
|
||||
let url = make_url(filename, none);
|
||||
style_chan.send(File(url));
|
||||
}
|
||||
none { /* fall through*/ }
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import vec::push;
|
|||
import lexer_util::*;
|
||||
import resource::resource_task;
|
||||
import resource_task::{ResourceTask};
|
||||
import std::net::url::url;
|
||||
|
||||
enum Token {
|
||||
StartOpeningTag(~str),
|
||||
|
@ -170,15 +171,13 @@ fn lexer(reader: io::reader, state : ParseState) -> HtmlLexer {
|
|||
}
|
||||
|
||||
#[warn(no_non_implicitly_copyable_typarams)]
|
||||
fn spawn_html_lexer_task(-filename: ~str, resource_task: ResourceTask) -> port<Token> {
|
||||
fn spawn_html_lexer_task(-url: url, resource_task: ResourceTask) -> port<Token> {
|
||||
let html_port = port();
|
||||
let html_chan = chan(html_port);
|
||||
let html_file = copy filename;
|
||||
|
||||
task::spawn(|| {
|
||||
let filename = copy html_file;
|
||||
assert (copy filename).ends_with(~".html");
|
||||
let file_data = io::read_whole_file(filename).get();
|
||||
assert url.path.ends_with(~".html");
|
||||
let file_data = io::read_whole_file(url.path).get();
|
||||
let reader = io::bytes_reader(file_data);
|
||||
|
||||
let lexer = lexer(reader, NormalHtml);
|
||||
|
|
|
@ -5,6 +5,9 @@ import osmain::{OSMain, AddKeyHandler};
|
|||
import opts::{Opts, Screen, Png};
|
||||
import engine::{Engine, LoadURLMsg};
|
||||
|
||||
import url_to_str = std::net::url::to_str;
|
||||
import util::url::make_url;
|
||||
|
||||
import pipes::{port, chan};
|
||||
|
||||
fn main(args: ~[~str]) {
|
||||
|
@ -41,8 +44,9 @@ fn run_pipeline_screen(urls: ~[~str]) {
|
|||
let engine_chan = engine.start();
|
||||
|
||||
for urls.each |filename| {
|
||||
#debug["master: Sending filename `%s`", filename];
|
||||
engine_chan.send(LoadURLMsg(copy filename));
|
||||
let url = make_url(filename, none);
|
||||
#debug["master: Sending url `%s`", url_to_str(url)];
|
||||
engine_chan.send(LoadURLMsg(url));
|
||||
#debug["master: Waiting for keypress"];
|
||||
alt keypress_from_osmain.try_recv() {
|
||||
some(*) { }
|
||||
|
@ -71,8 +75,7 @@ fn run_pipeline_png(-url: ~str, outfile: ~str) {
|
|||
let sink = PngSink(pngdata_from_sink);
|
||||
let engine = Engine(sink);
|
||||
let engine_chan = engine.start();
|
||||
let url = copy url;
|
||||
engine_chan.send(LoadURLMsg(url));
|
||||
engine_chan.send(LoadURLMsg(make_url(url, none)));
|
||||
alt buffered_file_writer(outfile) {
|
||||
ok(writer) {
|
||||
writer.write(pngdata_from_sink.recv())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue