diff options
author | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-11-16 11:57:39 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-11-17 18:34:23 +0100 |
commit | 913c874cb55fd0fdc9e8f3a4c34624cd015fac8a (patch) | |
tree | 4526ecefafe0cde2f56cb1e2a4ebffd372e1f70a /components/script/dom | |
parent | f14e7339b5ff95fce0127dce4fe87ce082ab7259 (diff) | |
download | servo-913c874cb55fd0fdc9e8f3a4c34624cd015fac8a.tar.gz servo-913c874cb55fd0fdc9e8f3a4c34624cd015fac8a.zip |
Urlmageddon: Use refcounted urls more often.
Diffstat (limited to 'components/script/dom')
38 files changed, 259 insertions, 191 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index b38d5d4ec91..7b0a14d91e5 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -79,6 +79,7 @@ use script_traits::{TimerEventId, TimerSource, TouchpadPressurePhase}; use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType}; use serde::{Deserialize, Serialize}; use servo_atoms::Atom; +use servo_url::ServoUrl; use smallvec::SmallVec; use std::boxed::FnBox; use std::cell::{Cell, UnsafeCell}; @@ -99,7 +100,6 @@ use style::selector_impl::{PseudoElement, Snapshot}; use style::values::specified::Length; use time::Duration; use url::Origin as UrlOrigin; -use url::Url; use uuid::Uuid; use webrender_traits::{WebGLBufferId, WebGLError, WebGLFramebufferId, WebGLProgramId}; use webrender_traits::{WebGLRenderbufferId, WebGLShaderId, WebGLTextureId}; @@ -301,7 +301,7 @@ impl<A: JSTraceable, B: JSTraceable, C: JSTraceable> JSTraceable for (A, B, C) { } } -no_jsmanaged_fields!(bool, f32, f64, String, Url, AtomicBool, AtomicUsize, UrlOrigin, Uuid, char); +no_jsmanaged_fields!(bool, f32, f64, String, ServoUrl, AtomicBool, AtomicUsize, UrlOrigin, Uuid, char); no_jsmanaged_fields!(usize, u8, u16, u32, u64); no_jsmanaged_fields!(isize, i8, i16, i32, i64); no_jsmanaged_fields!(Sender<T>); diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 5b36249be59..390a321fe5e 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -42,11 +42,11 @@ use net_traits::image::base::PixelFormat; use net_traits::image_cache_thread::ImageResponse; use num_traits::ToPrimitive; use script_traits::ScriptMsg as ConstellationMsg; +use servo_url::ServoUrl; use std::{cmp, fmt}; use std::cell::Cell; use std::str::FromStr; use unpremultiplytable::UNPREMULTIPLY_TABLE; -use url::Url; #[must_root] #[derive(JSTraceable, Clone, HeapSizeOf)] @@ -451,7 +451,7 @@ impl CanvasRenderingContext2D { } #[inline] - fn request_image_from_cache(&self, url: Url) -> ImageResponse { + fn request_image_from_cache(&self, url: ServoUrl) -> ImageResponse { let window = window_from_node(&*self.canvas); canvas_utils::request_image_from_cache(&window, url) } diff --git a/components/script/dom/client.rs b/components/script/dom/client.rs index 7f51b251627..bc763d41ea9 100644 --- a/components/script/dom/client.rs +++ b/components/script/dom/client.rs @@ -10,7 +10,7 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString}; use dom::serviceworker::ServiceWorker; use dom::window::Window; -use url::Url; +use servo_url::ServoUrl; use uuid::Uuid; #[dom_struct] @@ -24,7 +24,7 @@ pub struct Client { } impl Client { - fn new_inherited(url: Url) -> Client { + fn new_inherited(url: ServoUrl) -> Client { Client { reflector_: Reflector::new(), active_worker: None, diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 86aac32df1b..3be8f989cfd 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -33,12 +33,12 @@ use rand::random; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, get_reports, new_rt_and_cx}; use script_runtime::ScriptThreadEventCategory::WorkerEvent; use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin}; +use servo_url::ServoUrl; use std::mem::replace; use std::sync::{Arc, Mutex}; use std::sync::atomic::AtomicBool; use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel}; use style::thread_state; -use url::Url; use util::thread::spawn_named; /// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular @@ -92,7 +92,7 @@ pub struct DedicatedWorkerGlobalScope { impl DedicatedWorkerGlobalScope { fn new_inherited(init: WorkerGlobalScopeInit, - worker_url: Url, + worker_url: ServoUrl, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, runtime: Runtime, parent_sender: Box<ScriptChan + Send>, @@ -118,7 +118,7 @@ impl DedicatedWorkerGlobalScope { } pub fn new(init: WorkerGlobalScopeInit, - worker_url: Url, + worker_url: ServoUrl, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, runtime: Runtime, parent_sender: Box<ScriptChan + Send>, @@ -144,7 +144,7 @@ impl DedicatedWorkerGlobalScope { #[allow(unsafe_code)] pub fn run_worker_scope(init: WorkerGlobalScopeInit, - worker_url: Url, + worker_url: ServoUrl, from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>, worker_rt_for_mainthread: Arc<Mutex<Option<SharedRt>>>, worker: TrustedWorkerAddress, diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 56b7b17b0ca..a3263dbbc67 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -108,6 +108,7 @@ use script_traits::{ScriptMsg as ConstellationMsg, TouchpadPressurePhase}; use script_traits::{TouchEventType, TouchId}; use script_traits::UntrustedNodeAddress; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::boxed::FnBox; @@ -126,7 +127,6 @@ use style::selector_impl::Snapshot; use style::str::{split_html_space_chars, str_join}; use style::stylesheets::Stylesheet; use time; -use url::Url; use url::percent_encoding::percent_decode; use util::prefs::PREFS; @@ -168,7 +168,7 @@ pub struct Document { last_modified: Option<String>, encoding: Cell<EncodingRef>, is_html_document: bool, - url: Url, + url: ServoUrl, quirks_mode: Cell<QuirksMode>, /// Caches for the getElement methods id_map: DOMRefCell<HashMap<Atom, Vec<JS<Element>>>>, @@ -374,12 +374,12 @@ impl Document { } // https://dom.spec.whatwg.org/#concept-document-url - pub fn url(&self) -> &Url { + pub fn url(&self) -> &ServoUrl { &self.url } // https://html.spec.whatwg.org/multipage/#fallback-base-url - pub fn fallback_base_url(&self) -> Url { + pub fn fallback_base_url(&self) -> ServoUrl { // Step 1: iframe srcdoc (#4767). // Step 2: about:blank with a creator browsing context. // Step 3. @@ -387,7 +387,7 @@ impl Document { } // https://html.spec.whatwg.org/multipage/#document-base-url - pub fn base_url(&self) -> Url { + pub fn base_url(&self) -> ServoUrl { match self.base_element() { // Step 1. None => self.fallback_base_url(), @@ -1738,7 +1738,7 @@ impl LayoutDocumentHelpers for LayoutJS<Document> { } /// https://url.spec.whatwg.org/#network-scheme -fn url_has_network_scheme(url: &Url) -> bool { +fn url_has_network_scheme(url: &ServoUrl) -> bool { match url.scheme() { "ftp" | "http" | "https" => true, _ => false, @@ -1748,7 +1748,7 @@ fn url_has_network_scheme(url: &Url) -> bool { impl Document { pub fn new_inherited(window: &Window, browsing_context: Option<&BrowsingContext>, - url: Option<Url>, + url: Option<ServoUrl>, is_html_document: IsHTMLDocument, content_type: Option<DOMString>, last_modified: Option<String>, @@ -1757,7 +1757,7 @@ impl Document { referrer: Option<String>, referrer_policy: Option<ReferrerPolicy>) -> Document { - let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap()); + let url = url.unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap()); let (ready_state, domcontentloaded_dispatched) = if source == DocumentSource::FromParser { (DocumentReadyState::Loading, false) @@ -1868,7 +1868,7 @@ impl Document { pub fn new(window: &Window, browsing_context: Option<&BrowsingContext>, - url: Option<Url>, + url: Option<ServoUrl>, doctype: IsHTMLDocument, content_type: Option<DOMString>, last_modified: Option<String>, diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ac65c01e24c..bcad336f57b 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -368,7 +368,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { PropertyDeclaration::BackgroundImage(DeclaredValue::Value( background_image::SpecifiedValue(vec![ background_image::single_value::SpecifiedValue(Some( - specified::Image::for_cascade(Some(Arc::new(url)), specified::url::UrlExtraData { }) + specified::Image::for_cascade(Some(url.into()), specified::url::UrlExtraData { }) )) ]))))); } diff --git a/components/script/dom/eventsource.rs b/components/script/dom/eventsource.rs index 2eabfcbc8b0..c667267cd83 100644 --- a/components/script/dom/eventsource.rs +++ b/components/script/dom/eventsource.rs @@ -31,13 +31,13 @@ use net_traits::request::{RequestInit, RequestMode}; use network_listener::{NetworkListener, PreInvoke}; use script_thread::Runnable; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::cell::Cell; use std::mem; use std::str::{Chars, FromStr}; use std::sync::{Arc, Mutex}; use task_source::TaskSource; use timers::OneshotTimerCallback; -use url::Url; header! { (LastEventId, "Last-Event-ID") => [String] } @@ -57,7 +57,7 @@ enum ReadyState { #[dom_struct] pub struct EventSource { eventtarget: EventTarget, - url: Url, + url: ServoUrl, request: DOMRefCell<Option<RequestInit>>, last_event_id: DOMRefCell<DOMString>, reconnection_time: Cell<u64>, @@ -309,7 +309,7 @@ impl PreInvoke for EventSourceContext { } impl EventSource { - fn new_inherited(url: Url, with_credentials: bool) -> EventSource { + fn new_inherited(url: ServoUrl, with_credentials: bool) -> EventSource { EventSource { eventtarget: EventTarget::new_inherited(), url: url, @@ -323,7 +323,7 @@ impl EventSource { } } - fn new(global: &GlobalScope, url: Url, with_credentials: bool) -> Root<EventSource> { + fn new(global: &GlobalScope, url: ServoUrl, with_credentials: bool) -> Root<EventSource> { reflect_dom_object(box EventSource::new_inherited(url, with_credentials), global, Wrap) diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 48ba920ad60..e24e5c0e933 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -33,6 +33,7 @@ use js::jsapi::{CompileFunction, JS_GetFunctionObject, JSAutoCompartment}; use js::rust::{AutoObjectVectorWrapper, CompileOptionsWrapper}; use libc::{c_char, size_t}; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::default::Default; @@ -42,7 +43,6 @@ use std::mem; use std::ops::{Deref, DerefMut}; use std::ptr; use std::rc::Rc; -use url::Url; #[derive(PartialEq, Clone, JSTraceable)] pub enum CommonEventHandler { @@ -71,7 +71,7 @@ pub enum ListenerPhase { #[derive(JSTraceable, Clone, PartialEq)] pub struct InternalRawUncompiledHandler { source: DOMString, - url: Url, + url: ServoUrl, line: usize, } @@ -347,7 +347,7 @@ impl EventTarget { /// Store the raw uncompiled event handler for on-demand compilation later. /// https://html.spec.whatwg.org/multipage/#event-handler-attributes:event-handler-content-attributes-3 pub fn set_event_handler_uncompiled(&self, - url: Url, + url: ServoUrl, line: usize, ty: &str, source: DOMString) { diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 2338dcf32e7..0251bd8143e 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -36,6 +36,7 @@ use script_runtime::{ScriptPort, maybe_take_panic_result}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent}; use script_traits::{TimerEventId, TimerEventRequest, TimerSource}; +use servo_url::ServoUrl; use std::cell::Cell; use std::collections::HashMap; use std::collections::hash_map::Entry; @@ -46,7 +47,6 @@ use task_source::networking::NetworkingTaskSource; use time::{Timespec, get_time}; use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle}; use timers::{OneshotTimers, TimerCallback}; -use url::Url; #[dom_struct] pub struct GlobalScope { @@ -239,7 +239,7 @@ impl GlobalScope { /// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url) /// for this global scope. - pub fn api_base_url(&self) -> Url { + pub fn api_base_url(&self) -> ServoUrl { if let Some(window) = self.downcast::<Window>() { // https://html.spec.whatwg.org/multipage/#script-settings-for-browsing-contexts:api-base-url return window.Document().base_url(); @@ -252,7 +252,7 @@ impl GlobalScope { } /// Get the URL for this global scope. - pub fn get_url(&self) -> Url { + pub fn get_url(&self) -> ServoUrl { if let Some(window) = self.downcast::<Window>() { return window.get_url(); } diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 24d86df0cc0..a983c75bf91 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -28,16 +28,16 @@ use html5ever_atoms::LocalName; use net_traits::ReferrerPolicy; use num_traits::ToPrimitive; use script_traits::MozBrowserEvent; +use servo_url::ServoUrl; use std::default::Default; use style::attr::AttrValue; -use url::Url; use util::prefs::PREFS; #[dom_struct] pub struct HTMLAnchorElement { htmlelement: HTMLElement, rel_list: MutNullableHeap<JS<DOMTokenList>>, - url: DOMRefCell<Option<Url>>, + url: DOMRefCell<Option<ServoUrl>>, } impl HTMLAnchorElement { diff --git a/components/script/dom/htmlbaseelement.rs b/components/script/dom/htmlbaseelement.rs index 9fd34768b36..0db9b5398dd 100644 --- a/components/script/dom/htmlbaseelement.rs +++ b/components/script/dom/htmlbaseelement.rs @@ -14,8 +14,8 @@ use dom::htmlelement::HTMLElement; use dom::node::{Node, UnbindContext, document_from_node}; use dom::virtualmethods::VirtualMethods; use html5ever_atoms::LocalName; +use servo_url::ServoUrl; use style::attr::AttrValue; -use url::Url; #[dom_struct] pub struct HTMLBaseElement { @@ -39,7 +39,7 @@ impl HTMLBaseElement { } /// https://html.spec.whatwg.org/multipage/#frozen-base-url - pub fn frozen_base_url(&self) -> Url { + pub fn frozen_base_url(&self) -> ServoUrl { let href = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")) .expect("The frozen base url is only defined for base elements \ that have a base url."); diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index e89dc21f3da..ea9b1775787 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -19,9 +19,9 @@ use dom::node::{Node, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; use html5ever_atoms::LocalName; use script_traits::ScriptMsg as ConstellationMsg; +use servo_url::ServoUrl; use style::attr::AttrValue; use time; -use url::Url; /// How long we should wait before performing the initial reflow after `<body>` is parsed, in /// nanoseconds. @@ -85,7 +85,7 @@ impl HTMLBodyElementMethods for HTMLBodyElement { pub trait HTMLBodyElementLayoutHelpers { fn get_background_color(&self) -> Option<RGBA>; fn get_color(&self) -> Option<RGBA>; - fn get_background(&self) -> Option<Url>; + fn get_background(&self) -> Option<ServoUrl>; } impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> { @@ -110,7 +110,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> { } #[allow(unsafe_code)] - fn get_background(&self) -> Option<Url> { + fn get_background(&self) -> Option<ServoUrl> { unsafe { (*self.upcast::<Element>().unsafe_get()) .get_attr_for_layout(&ns!(), &local_name!("background")) diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 326b1804ddf..554b029152c 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -339,12 +339,12 @@ pub mod utils { use dom::window::Window; use ipc_channel::ipc; use net_traits::image_cache_thread::{ImageCacheChan, ImageResponse}; - use url::Url; + use servo_url::ServoUrl; - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + pub fn request_image_from_cache(window: &Window, url: ServoUrl) -> ImageResponse { let image_cache = window.image_cache_thread(); let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); + image_cache.request_image(url.into(), ImageCacheChan(response_chan), None); let result = response_port.recv().unwrap(); result.image_response } diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 4ecc6a44fa0..cbf32ef9aab 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -380,10 +380,12 @@ impl HTMLFormElement { fn mutate_action_url(&self, form_data: &mut Vec<FormDatum>, mut load_data: LoadData, encoding: EncodingRef) { let charset = &*encoding.whatwg_name().unwrap(); - load_data.url.query_pairs_mut().clear() - .encoding_override(Some(self.pick_encoding())) - .extend_pairs(form_data.into_iter() - .map(|field| (field.name.clone(), field.replace_value(charset)))); + if let Some(ref mut url) = load_data.url.as_mut_url() { + url.query_pairs_mut().clear() + .encoding_override(Some(self.pick_encoding())) + .extend_pairs(form_data.into_iter() + .map(|field| (field.name.clone(), field.replace_value(charset)))); + } self.plan_to_navigate(load_data); } @@ -394,16 +396,18 @@ impl HTMLFormElement { let boundary = generate_boundary(); let bytes = match enctype { FormEncType::UrlEncoded => { - let mut url = load_data.url.clone(); let charset = &*encoding.whatwg_name().unwrap(); load_data.headers.set(ContentType::form_url_encoded()); - url.query_pairs_mut().clear() - .encoding_override(Some(self.pick_encoding())) - .extend_pairs(form_data.into_iter() - .map(|field| (field.name.clone(), field.replace_value(charset)))); - url.query().unwrap_or("").to_string().into_bytes() + if let Some(ref mut url) = load_data.url.as_mut_url() { + url.query_pairs_mut().clear() + .encoding_override(Some(self.pick_encoding())) + .extend_pairs(form_data.into_iter() + .map(|field| (field.name.clone(), field.replace_value(charset)))); + } + + load_data.url.query().unwrap_or("").to_string().into_bytes() } FormEncType::FormDataEncoded => { let mime = mime!(Multipart / FormData; Boundary =(&boundary)); diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 0430a0f7d26..311cc80aa8c 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -46,10 +46,10 @@ use script_thread::ScriptThread; use script_traits::{IFrameLoadInfo, LoadData, MozBrowserEvent, ScriptMsg as ConstellationMsg}; use script_traits::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandboxed}; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::cell::Cell; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use style::context::ReflowGoal; -use url::Url; use util::prefs::PREFS; use util::servo_version; @@ -84,7 +84,7 @@ impl HTMLIFrameElement { /// <https://html.spec.whatwg.org/multipage/#otherwise-steps-for-iframe-or-frame-elements>, /// step 1. - fn get_url(&self) -> Url { + fn get_url(&self) -> ServoUrl { let element = self.upcast::<Element>(); element.get_attribute(&ns!(), &local_name!("src")).and_then(|src| { let url = src.value(); @@ -93,7 +93,7 @@ impl HTMLIFrameElement { } else { document_from_node(self).base_url().join(&url).ok() } - }).unwrap_or_else(|| Url::parse("about:blank").unwrap()) + }).unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap()) } pub fn generate_new_pipeline_id(&self) -> (Option<PipelineId>, PipelineId) { diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index d8ecda30943..3b58b383bf4 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -27,11 +27,11 @@ use ipc_channel::router::ROUTER; use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image_cache_thread::{ImageResponder, ImageResponse}; use script_thread::Runnable; +use servo_url::ServoUrl; use std::i32; use std::sync::Arc; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use task_source::TaskSource; -use url::Url; #[derive(JSTraceable, HeapSizeOf)] #[allow(dead_code)] @@ -44,7 +44,7 @@ enum State { #[derive(JSTraceable, HeapSizeOf)] struct ImageRequest { state: State, - parsed_url: Option<Url>, + parsed_url: Option<ServoUrl>, source_url: Option<DOMString>, #[ignore_heap_size_of = "Arc"] image: Option<Arc<Image>>, @@ -58,7 +58,7 @@ pub struct HTMLImageElement { } impl HTMLImageElement { - pub fn get_url(&self) -> Option<Url> { + pub fn get_url(&self) -> Option<ServoUrl> { self.current_request.borrow().parsed_url.clone() } } @@ -120,7 +120,7 @@ impl Runnable for ImageResponseHandlerRunnable { impl HTMLImageElement { /// Makes the local `image` member match the status of the `src` attribute and starts /// prefetching the image. This method must be called after `src` is changed. - fn update_image(&self, value: Option<(DOMString, Url)>) { + fn update_image(&self, value: Option<(DOMString, ServoUrl)>) { let document = document_from_node(self); let window = document.window(); let image_cache = window.image_cache_thread(); @@ -149,7 +149,7 @@ impl HTMLImageElement { let _ = task_source.queue_with_wrapper(runnable, &wrapper); }); - image_cache.request_image_and_metadata(img_url, + image_cache.request_image_and_metadata(img_url.into(), window.image_cache_chan(), Some(ImageResponder::new(responder_sender))); } else { @@ -241,7 +241,7 @@ pub trait LayoutHTMLImageElementHelpers { unsafe fn image(&self) -> Option<Arc<Image>>; #[allow(unsafe_code)] - unsafe fn image_url(&self) -> Option<Url>; + unsafe fn image_url(&self) -> Option<ServoUrl>; fn get_width(&self) -> LengthOrPercentageOrAuto; fn get_height(&self) -> LengthOrPercentageOrAuto; @@ -254,7 +254,7 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> { } #[allow(unsafe_code)] - unsafe fn image_url(&self) -> Option<Url> { + unsafe fn image_url(&self) -> Option<ServoUrl> { (*self.unsafe_get()).current_request.borrow_for_layout().parsed_url.clone() } diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 17c9514287e..f670d8757e3 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -36,6 +36,7 @@ use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as Req use network_listener::{NetworkListener, PreInvoke}; use script_layout_interface::message::Msg; use script_traits::{MozBrowserEvent, ScriptMsg as ConstellationMsg}; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; @@ -47,7 +48,6 @@ use style::media_queries::{MediaList, parse_media_query_list}; use style::parser::ParserContextExtraData; use style::str::HTML_SPACE_CHARACTERS; use style::stylesheets::{Stylesheet, Origin}; -use url::Url; no_jsmanaged_fields!(Stylesheet); @@ -318,7 +318,7 @@ struct StylesheetContext { /// The response metadata received to date. metadata: Option<Metadata>, /// The initial URL requested. - url: Url, + url: ServoUrl, } impl PreInvoke for StylesheetContext {} diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 09a1b7cc438..b1480391223 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -35,11 +35,11 @@ use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as Req use network_listener::{NetworkListener, PreInvoke}; use script_thread::{Runnable, ScriptThread}; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::cell::Cell; use std::sync::{Arc, Mutex}; use task_source::TaskSource; use time::{self, Timespec, Duration}; -use url::Url; struct HTMLMediaElementContext { /// The element that initiated the request. @@ -53,7 +53,7 @@ struct HTMLMediaElementContext { /// Time of last progress notification. next_progress_event: Timespec, /// Url of resource requested. - url: Url, + url: ServoUrl, /// Whether the media metadata has been completely received. have_metadata: bool, /// True if this response is invalid and should be ignored. @@ -164,7 +164,7 @@ impl PreInvoke for HTMLMediaElementContext { } impl HTMLMediaElementContext { - fn new(elem: &HTMLMediaElement, url: Url) -> HTMLMediaElementContext { + fn new(elem: &HTMLMediaElement, url: ServoUrl) -> HTMLMediaElementContext { HTMLMediaElementContext { elem: Trusted::new(elem), data: vec![], @@ -437,7 +437,7 @@ impl HTMLMediaElement { } // https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm - fn resource_selection_algorithm_sync(&self, base_url: Url) { + fn resource_selection_algorithm_sync(&self, base_url: ServoUrl) { // TODO step 5 (populate pending text tracks) // Step 6 @@ -814,11 +814,11 @@ impl Runnable for FireSimpleEventTask { struct ResourceSelectionTask { elem: Trusted<HTMLMediaElement>, - base_url: Url, + base_url: ServoUrl, } impl ResourceSelectionTask { - fn new(elem: &HTMLMediaElement, url: Url) -> ResourceSelectionTask { + fn new(elem: &HTMLMediaElement, url: ServoUrl) -> ResourceSelectionTask { ResourceSelectionTask { elem: Trusted::new(elem), base_url: url, @@ -885,5 +885,5 @@ enum ResourceSelectionMode { enum Resource { Object, - Url(Url), + Url(ServoUrl), } diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 68b65f93142..50c7658daab 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -35,11 +35,11 @@ use net_traits::{FetchMetadata, FetchResponseListener, Metadata, NetworkError}; use net_traits::request::{CorsSettings, CredentialsMode, Destination, RequestInit, RequestMode, Type as RequestType}; use network_listener::{NetworkListener, PreInvoke}; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::cell::Cell; use std::sync::{Arc, Mutex}; use style::str::{HTML_SPACE_CHARACTERS, StaticStringVec}; -use url::Url; #[dom_struct] pub struct HTMLScriptElement { @@ -115,12 +115,12 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[ #[derive(HeapSizeOf, JSTraceable)] pub struct ScriptOrigin { text: DOMString, - url: Url, + url: ServoUrl, external: bool, } impl ScriptOrigin { - fn internal(text: DOMString, url: Url) -> ScriptOrigin { + fn internal(text: DOMString, url: ServoUrl) -> ScriptOrigin { ScriptOrigin { text: text, url: url, @@ -128,7 +128,7 @@ impl ScriptOrigin { } } - fn external(text: DOMString, url: Url) -> ScriptOrigin { + fn external(text: DOMString, url: ServoUrl) -> ScriptOrigin { ScriptOrigin { text: text, url: url, @@ -149,7 +149,7 @@ struct ScriptContext { /// The response metadata received to date. metadata: Option<Metadata>, /// The initial URL requested. - url: Url, + url: ServoUrl, /// Indicates whether the request failed, and why status: Result<(), NetworkError> } @@ -219,7 +219,7 @@ impl PreInvoke for ScriptContext {} /// https://html.spec.whatwg.org/multipage/#fetch-a-classic-script fn fetch_a_classic_script(script: &HTMLScriptElement, - url: Url, + url: ServoUrl, cors_setting: Option<CorsSettings>, character_encoding: EncodingRef) { let doc = document_from_node(script); diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index cf91c683f2f..c992486b8d1 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -10,7 +10,7 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString}; use dom::urlhelper::UrlHelper; use dom::window::Window; -use url::Url; +use servo_url::ServoUrl; #[dom_struct] pub struct Location { @@ -32,12 +32,12 @@ impl Location { LocationBinding::Wrap) } - fn get_url(&self) -> Url { + fn get_url(&self) -> ServoUrl { self.window.get_url() } fn set_url_component(&self, value: USVString, - setter: fn(&mut Url, USVString)) { + setter: fn(&mut ServoUrl, USVString)) { let mut url = self.window.get_url(); setter(&mut url, value); self.window.load_url(url, false, None); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 37e0548fa13..79208d82b48 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -73,6 +73,7 @@ use script_traits::UntrustedNodeAddress; use selectors::matching::{MatchingReason, matches}; use selectors::parser::Selector; use selectors::parser::parse_author_origin_selector_list_from_str; +use servo_url::ServoUrl; use std::borrow::ToOwned; use std::cell::{Cell, UnsafeCell}; use std::cmp::max; @@ -85,7 +86,6 @@ use style::dom::OpaqueNode; use style::selector_impl::ServoSelectorImpl; use style::stylesheets::Stylesheet; use style::thread_state; -use url::Url; use uuid::Uuid; // @@ -991,7 +991,7 @@ pub trait LayoutNodeHelpers { fn text_content(&self) -> String; fn selection(&self) -> Option<Range<usize>>; - fn image_url(&self) -> Option<Url>; + fn image_url(&self) -> Option<ServoUrl>; fn canvas_data(&self) -> Option<HTMLCanvasData>; fn svg_data(&self) -> Option<SVGSVGData>; fn iframe_pipeline_id(&self) -> PipelineId; @@ -1126,7 +1126,7 @@ impl LayoutNodeHelpers for LayoutJS<Node> { } #[allow(unsafe_code)] - fn image_url(&self) -> Option<Url> { + fn image_url(&self) -> Option<ServoUrl> { unsafe { self.downcast::<HTMLImageElement>() .expect("not an image!") diff --git a/components/script/dom/request.rs b/components/script/dom/request.rs index 614c51398e8..33a28da99ea 100644 --- a/components/script/dom/request.rs +++ b/components/script/dom/request.rs @@ -35,10 +35,10 @@ use net_traits::request::Referrer as NetTraitsRequestReferrer; use net_traits::request::Request as NetTraitsRequest; use net_traits::request::RequestMode as NetTraitsRequestMode; use net_traits::request::Type as NetTraitsRequestType; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::cell::{Cell, Ref}; use std::rc::Rc; -use url::Url; #[dom_struct] pub struct Request { @@ -53,7 +53,7 @@ pub struct Request { impl Request { fn new_inherited(global: &GlobalScope, - url: Url, + url: ServoUrl, is_service_worker_global_scope: bool) -> Request { Request { reflector_: Reflector::new(), @@ -69,7 +69,7 @@ impl Request { } pub fn new(global: &GlobalScope, - url: Url, + url: ServoUrl, is_service_worker_global_scope: bool) -> Root<Request> { reflect_dom_object(box Request::new_inherited(global, url, @@ -468,7 +468,7 @@ impl Request { } fn net_request_from_global(global: &GlobalScope, - url: Url, + url: ServoUrl, is_service_worker_global_scope: bool) -> NetTraitsRequest { let origin = Origin::Origin(global.get_url().origin()); let pipeline_id = global.pipeline_id(); @@ -524,7 +524,7 @@ fn is_cors_safelisted_method(m: &HttpMethod) -> bool { } // https://url.spec.whatwg.org/#include-credentials -fn includes_credentials(input: &Url) -> bool { +fn includes_credentials(input: &ServoUrl) -> bool { !input.username().is_empty() || input.password().is_some() } diff --git a/components/script/dom/response.rs b/components/script/dom/response.rs index 7607cacc972..484a1d0beee 100644 --- a/components/script/dom/response.rs +++ b/components/script/dom/response.rs @@ -22,12 +22,12 @@ use hyper::header::Headers as HyperHeaders; use hyper::status::StatusCode; use hyper_serde::Serde; use net_traits::response::{ResponseBody as NetTraitsResponseBody}; +use servo_url::ServoUrl; use std::cell::Ref; use std::mem; use std::rc::Rc; use std::str::FromStr; use url::Position; -use url::Url; #[dom_struct] pub struct Response { @@ -40,8 +40,8 @@ pub struct Response { status: DOMRefCell<Option<StatusCode>>, raw_status: DOMRefCell<Option<(u16, Vec<u8>)>>, response_type: DOMRefCell<DOMResponseType>, - url: DOMRefCell<Option<Url>>, - url_list: DOMRefCell<Vec<Url>>, + url: DOMRefCell<Option<ServoUrl>>, + url_list: DOMRefCell<Vec<ServoUrl>>, // For now use the existing NetTraitsResponseBody enum body: DOMRefCell<NetTraitsResponseBody>, #[ignore_heap_size_of = "Rc"] @@ -156,7 +156,7 @@ impl Response { // Step 2 let url = match parsed_url { Ok(url) => url, - Err(_) => return Err(Error::Type("Url could not be parsed".to_string())), + Err(_) => return Err(Error::Type("ServoUrl could not be parsed".to_string())), }; // Step 3 @@ -357,8 +357,8 @@ impl ResponseMethods for Response { } } -fn serialize_without_fragment(url: &Url) -> &str { - &url[..Position::AfterQuery] +fn serialize_without_fragment(url: &ServoUrl) -> &str { + &url.as_url().unwrap()[..Position::AfterQuery] } impl Response { @@ -377,7 +377,7 @@ impl Response { *self.raw_status.borrow_mut() = status; } - pub fn set_final_url(&self, final_url: Url) { + pub fn set_final_url(&self, final_url: ServoUrl) { *self.url.borrow_mut() = Some(final_url); } diff --git a/components/script/dom/serviceworker.rs b/components/script/dom/serviceworker.rs index f61dcc4e41c..a3e5713a22e 100644 --- a/components/script/dom/serviceworker.rs +++ b/components/script/dom/serviceworker.rs @@ -18,8 +18,8 @@ use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, JSContext}; use script_thread::Runnable; use script_traits::{ScriptMsg, DOMMessage}; +use servo_url::ServoUrl; use std::cell::Cell; -use url::Url; pub type TrustedServiceWorkerAddress = Trusted<ServiceWorker>; @@ -27,7 +27,7 @@ pub type TrustedServiceWorkerAddress = Trusted<ServiceWorker>; pub struct ServiceWorker { eventtarget: EventTarget, script_url: DOMRefCell<String>, - scope_url: Url, + scope_url: ServoUrl, state: Cell<ServiceWorkerState>, skip_waiting: Cell<bool> } @@ -35,7 +35,7 @@ pub struct ServiceWorker { impl ServiceWorker { fn new_inherited(script_url: &str, skip_waiting: bool, - scope_url: Url) -> ServiceWorker { + scope_url: ServoUrl) -> ServiceWorker { ServiceWorker { eventtarget: EventTarget::new_inherited(), script_url: DOMRefCell::new(String::from(script_url)), @@ -46,8 +46,8 @@ impl ServiceWorker { } pub fn install_serviceworker(global: &GlobalScope, - script_url: Url, - scope_url: Url, + script_url: ServoUrl, + scope_url: ServoUrl, skip_waiting: bool) -> Root<ServiceWorker> { reflect_dom_object(box ServiceWorker::new_inherited(script_url.as_str(), skip_waiting, @@ -64,8 +64,8 @@ impl ServiceWorker { self.upcast::<EventTarget>().fire_event(atom!("statechange")); } - pub fn get_script_url(&self) -> Url { - Url::parse(&self.script_url.borrow().clone()).unwrap() + pub fn get_script_url(&self) -> ServoUrl { + ServoUrl::parse(&self.script_url.borrow().clone()).unwrap() } } diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index 6a39aad418f..44dc9aafde3 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -28,11 +28,11 @@ use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as Req use rand::random; use script_runtime::{CommonScriptMsg, StackRootTLS, get_reports, new_rt_and_cx, ScriptChan}; use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin}; +use servo_url::ServoUrl; use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel}; use std::thread; use std::time::Duration; use style::thread_state::{self, IN_WORKER, SCRIPT}; -use url::Url; use util::prefs::PREFS; use util::thread::spawn_named; @@ -80,12 +80,12 @@ pub struct ServiceWorkerGlobalScope { timer_event_port: Receiver<()>, #[ignore_heap_size_of = "Defined in std"] swmanager_sender: IpcSender<ServiceWorkerMsg>, - scope_url: Url, + scope_url: ServoUrl, } impl ServiceWorkerGlobalScope { fn new_inherited(init: WorkerGlobalScopeInit, - worker_url: Url, + worker_url: ServoUrl, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, runtime: Runtime, own_sender: Sender<ServiceWorkerScriptMsg>, @@ -93,7 +93,7 @@ impl ServiceWorkerGlobalScope { timer_event_chan: IpcSender<TimerEvent>, timer_event_port: Receiver<()>, swmanager_sender: IpcSender<ServiceWorkerMsg>, - scope_url: Url) + scope_url: ServoUrl) -> ServiceWorkerGlobalScope { ServiceWorkerGlobalScope { workerglobalscope: WorkerGlobalScope::new_inherited(init, @@ -111,7 +111,7 @@ impl ServiceWorkerGlobalScope { } pub fn new(init: WorkerGlobalScopeInit, - worker_url: Url, + worker_url: ServoUrl, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, runtime: Runtime, own_sender: Sender<ServiceWorkerScriptMsg>, @@ -119,7 +119,7 @@ impl ServiceWorkerGlobalScope { timer_event_chan: IpcSender<TimerEvent>, timer_event_port: Receiver<()>, swmanager_sender: IpcSender<ServiceWorkerMsg>, - scope_url: Url) + scope_url: ServoUrl) -> Root<ServiceWorkerGlobalScope> { let cx = runtime.cx(); let scope = box ServiceWorkerGlobalScope::new_inherited(init, @@ -141,7 +141,7 @@ impl ServiceWorkerGlobalScope { receiver: Receiver<ServiceWorkerScriptMsg>, devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>, swmanager_sender: IpcSender<ServiceWorkerMsg>, - scope_url: Url) { + scope_url: ServoUrl) { let ScopeThings { script_url, init, worker_load_origin, diff --git a/components/script/dom/serviceworkerregistration.rs b/components/script/dom/serviceworkerregistration.rs index c3a08e514e4..58ca0933d69 100644 --- a/components/script/dom/serviceworkerregistration.rs +++ b/components/script/dom/serviceworkerregistration.rs @@ -13,7 +13,7 @@ use dom::serviceworker::ServiceWorker; use dom::serviceworkercontainer::Controllable; use dom::workerglobalscope::prepare_workerscope_init; use script_traits::{WorkerScriptLoadOrigin, ScopeThings}; -use url::Url; +use servo_url::ServoUrl; #[dom_struct] pub struct ServiceWorkerRegistration { @@ -25,7 +25,7 @@ pub struct ServiceWorkerRegistration { } impl ServiceWorkerRegistration { - fn new_inherited(active_sw: &ServiceWorker, scope: Url) -> ServiceWorkerRegistration { + fn new_inherited(active_sw: &ServiceWorker, scope: ServoUrl) -> ServiceWorkerRegistration { ServiceWorkerRegistration { eventtarget: EventTarget::new_inherited(), active: Some(JS::from_ref(active_sw)), @@ -36,8 +36,8 @@ impl ServiceWorkerRegistration { } #[allow(unrooted_must_root)] pub fn new(global: &GlobalScope, - script_url: Url, - scope: Url, + script_url: ServoUrl, + scope: ServoUrl, container: &Controllable) -> Root<ServiceWorkerRegistration> { let active_worker = ServiceWorker::install_serviceworker(global, script_url.clone(), scope.clone(), true); active_worker.set_transition_state(ServiceWorkerState::Installed); @@ -49,7 +49,7 @@ impl ServiceWorkerRegistration { self.active.as_ref().unwrap() } - pub fn create_scope_things(global: &GlobalScope, script_url: Url) -> ScopeThings { + pub fn create_scope_things(global: &GlobalScope, script_url: ServoUrl) -> ScopeThings { let worker_load_origin = WorkerScriptLoadOrigin { referrer_url: None, referrer_policy: None, @@ -69,7 +69,7 @@ impl ServiceWorkerRegistration { } } -pub fn longest_prefix_match(stored_scope: &Url, potential_match: &Url) -> bool { +pub fn longest_prefix_match(stored_scope: &ServoUrl, potential_match: &ServoUrl) -> bool { if stored_scope.origin() != potential_match.origin() { return false; } diff --git a/components/script/dom/servoparser/html.rs b/components/script/dom/servoparser/html.rs index a2d636da6f3..ab5af05a18d 100644 --- a/components/script/dom/servoparser/html.rs +++ b/components/script/dom/servoparser/html.rs @@ -31,10 +31,10 @@ use html5ever::tree_builder::{NodeOrText, QuirksMode}; use html5ever::tree_builder::{Tracer as HtmlTracer, TreeBuilder, TreeBuilderOpts, TreeSink}; use html5ever_atoms::QualName; use js::jsapi::JSTracer; +use servo_url::ServoUrl; use std::borrow::Cow; use std::io::{self, Write}; use super::{FragmentContext, Sink}; -use url::Url; #[derive(HeapSizeOf, JSTraceable)] #[must_root] @@ -48,7 +48,7 @@ pub struct Tokenizer { impl Tokenizer { pub fn new( document: &Document, - url: Url, + url: ServoUrl, fragment_context: Option<FragmentContext>) -> Self { let sink = Sink { diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs index 7b5c5c7f4ab..31ae5d4961a 100644 --- a/components/script/dom/servoparser/mod.rs +++ b/components/script/dom/servoparser/mod.rs @@ -29,9 +29,9 @@ use network_listener::PreInvoke; use profile_traits::time::{TimerMetadata, TimerMetadataFrameType}; use profile_traits::time::{TimerMetadataReflowType, ProfilerCategory, profile}; use script_thread::ScriptThread; +use servo_url::ServoUrl; use std::cell::Cell; use std::collections::VecDeque; -use url::Url; use util::resource_files::read_resource_file; mod html; @@ -65,7 +65,7 @@ impl ServoParser { pub fn parse_html_document( document: &Document, input: DOMString, - url: Url, + url: ServoUrl, owner: Option<PipelineId>) { let parser = ServoParser::new( document, @@ -122,7 +122,7 @@ impl ServoParser { pub fn parse_xml_document( document: &Document, input: DOMString, - url: Url, + url: ServoUrl, owner: Option<PipelineId>) { let parser = ServoParser::new( document, @@ -287,7 +287,7 @@ enum Tokenizer { #[derive(JSTraceable, HeapSizeOf)] #[must_root] struct Sink { - pub base_url: Url, + pub base_url: ServoUrl, pub document: JS<Document>, } @@ -338,11 +338,11 @@ pub struct ParserContext { /// The pipeline associated with this document. id: PipelineId, /// The URL for this document. - url: Url, + url: ServoUrl, } impl ParserContext { - pub fn new(id: PipelineId, url: Url) -> ParserContext { + pub fn new(id: PipelineId, url: ServoUrl) -> ParserContext { ParserContext { parser: None, is_synthesized_document: false, diff --git a/components/script/dom/servoparser/xml.rs b/components/script/dom/servoparser/xml.rs index 6f87d6a389c..3ce3fb69ca4 100644 --- a/components/script/dom/servoparser/xml.rs +++ b/components/script/dom/servoparser/xml.rs @@ -19,9 +19,9 @@ use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; use html5ever_atoms::{Prefix, QualName}; use js::jsapi::JSTracer; +use servo_url::ServoUrl; use std::borrow::Cow; use super::Sink; -use url::Url; use xml5ever::tendril::StrTendril; use xml5ever::tokenizer::{Attribute, QName, XmlTokenizer}; use xml5ever::tree_builder::{NextParserState, NodeOrText}; @@ -35,7 +35,7 @@ pub struct Tokenizer { } impl Tokenizer { - pub fn new(document: &Document, url: Url) -> Self { + pub fn new(document: &Document, url: ServoUrl) -> Self { let sink = Sink { base_url: url, document: JS::from_ref(document), diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index 3eb2b1ca844..6b85241e04f 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -18,8 +18,8 @@ use net_traits::IpcSend; use net_traits::storage_thread::{StorageThreadMsg, StorageType}; use script_thread::{Runnable, ScriptThread}; use script_traits::ScriptMsg; +use servo_url::ServoUrl; use task_source::TaskSource; -use url::Url; #[dom_struct] pub struct Storage { @@ -39,7 +39,7 @@ impl Storage { reflect_dom_object(box Storage::new_inherited(storage_type), global, StorageBinding::Wrap) } - fn get_url(&self) -> Url { + fn get_url(&self) -> ServoUrl { self.global().get_url() } @@ -158,7 +158,7 @@ impl Storage { } /// https://html.spec.whatwg.org/multipage/#send-a-storage-notification - pub fn queue_storage_event(&self, url: Url, + pub fn queue_storage_event(&self, url: ServoUrl, key: Option<String>, old_value: Option<String>, new_value: Option<String>) { let global = self.global(); let window = global.as_window(); @@ -173,14 +173,14 @@ impl Storage { pub struct StorageEventRunnable { element: Trusted<Storage>, - url: Url, + url: ServoUrl, key: Option<String>, old_value: Option<String>, new_value: Option<String> } impl StorageEventRunnable { - fn new(storage: Trusted<Storage>, url: Url, + fn new(storage: Trusted<Storage>, url: ServoUrl, key: Option<String>, old_value: Option<String>, new_value: Option<String>) -> StorageEventRunnable { StorageEventRunnable { element: storage, url: url, key: key, old_value: old_value, new_value: new_value } } diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs index dbcefe48e53..50fe85a507b 100644 --- a/components/script/dom/url.rs +++ b/components/script/dom/url.rs @@ -17,8 +17,8 @@ use ipc_channel::ipc; use net_traits::{CoreResourceMsg, IpcSend}; use net_traits::blob_url_store::{get_blob_origin, parse_blob_url}; use net_traits::filemanager_thread::FileManagerThreadMsg; +use servo_url::ServoUrl; use std::default::Default; -use url::Url; use uuid::Uuid; // https://url.spec.whatwg.org/#url @@ -27,14 +27,14 @@ pub struct URL { reflector_: Reflector, // https://url.spec.whatwg.org/#concept-url-url - url: DOMRefCell<Url>, + url: DOMRefCell<ServoUrl>, // https://url.spec.whatwg.org/#dom-url-searchparams search_params: MutNullableHeap<JS<URLSearchParams>>, } impl URL { - fn new_inherited(url: Url) -> URL { + fn new_inherited(url: ServoUrl) -> URL { URL { reflector_: Reflector::new(), url: DOMRefCell::new(url), @@ -42,18 +42,19 @@ impl URL { } } - pub fn new(global: &GlobalScope, url: Url) -> Root<URL> { + pub fn new(global: &GlobalScope, url: ServoUrl) -> Root<URL> { reflect_dom_object(box URL::new_inherited(url), global, URLBinding::Wrap) } pub fn query_pairs(&self) -> Vec<(String, String)> { - self.url.borrow().query_pairs().into_owned().collect() + self.url.borrow().as_url().unwrap().query_pairs().into_owned().collect() } pub fn set_query_pairs(&self, pairs: &[(String, String)]) { - let mut url = self.url.borrow_mut(); - url.query_pairs_mut().clear().extend_pairs(pairs); + if let Some(ref mut url) = self.url.borrow_mut().as_mut_url() { + url.query_pairs_mut().clear().extend_pairs(pairs); + } } } @@ -69,7 +70,7 @@ impl URL { }, Some(base) => // Step 2.1. - match Url::parse(&base.0) { + match ServoUrl::parse(&base.0) { Ok(base) => Some(base), Err(error) => { // Step 2.2. @@ -78,7 +79,7 @@ impl URL { } }; // Step 3. - let parsed_url = match Url::options().base_url(parsed_base.as_ref()).parse(&url.0) { + let parsed_url = match ServoUrl::parse_with_base(parsed_base.as_ref(), &url.0) { Ok(url) => url, Err(error) => { // Step 4. @@ -124,7 +125,7 @@ impl URL { */ let origin = get_blob_origin(&global.get_url()); - if let Ok(url) = Url::parse(&url) { + if let Ok(url) = ServoUrl::parse(&url) { if let Ok((id, _, _)) = parse_blob_url(&url) { let resource_threads = global.resource_threads(); let (tx, rx) = ipc::channel().unwrap(); @@ -192,7 +193,7 @@ impl URLMethods for URL { // https://url.spec.whatwg.org/#dom-url-href fn SetHref(&self, value: USVString) -> ErrorResult { - match Url::parse(&value.0) { + match ServoUrl::parse(&value.0) { Ok(url) => { *self.url.borrow_mut() = url; self.search_params.set(None); // To be re-initialized in the SearchParams getter. @@ -258,7 +259,7 @@ impl URLMethods for URL { fn SetSearch(&self, value: USVString) { UrlHelper::SetSearch(&mut self.url.borrow_mut(), value); if let Some(search_params) = self.search_params.get() { - search_params.set_list(self.url.borrow().query_pairs().into_owned().collect()); + search_params.set_list(self.query_pairs()); } } diff --git a/components/script/dom/urlhelper.rs b/components/script/dom/urlhelper.rs index cd58612a6c1..dd22e16f551 100644 --- a/components/script/dom/urlhelper.rs +++ b/components/script/dom/urlhelper.rs @@ -3,32 +3,93 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::str::USVString; +use servo_url::ServoUrl; use std::borrow::ToOwned; -use url::{Url, quirks}; +use url::quirks; #[derive(HeapSizeOf)] pub struct UrlHelper; impl UrlHelper { - pub fn SameOrigin(url_a: &Url, url_b: &Url) -> bool { url_a.origin() == url_b.origin() } - pub fn Origin(url: &Url) -> USVString { USVString(quirks::origin(url)) } - pub fn Href(url: &Url) -> USVString { USVString(quirks::href(url).to_owned()) } - pub fn Hash(url: &Url) -> USVString { USVString(quirks::hash(url).to_owned()) } - pub fn Host(url: &Url) -> USVString { USVString(quirks::host(url).to_owned()) } - pub fn Port(url: &Url) -> USVString { USVString(quirks::port(url).to_owned()) } - pub fn Search(url: &Url) -> USVString { USVString(quirks::search(url).to_owned()) } - pub fn Hostname(url: &Url) -> USVString { USVString(quirks::hostname(url).to_owned()) } - pub fn Password(url: &Url) -> USVString { USVString(quirks::password(url).to_owned()) } - pub fn Pathname(url: &Url) -> USVString { USVString(quirks::pathname(url).to_owned()) } - pub fn Protocol(url: &Url) -> USVString { USVString(quirks::protocol(url).to_owned()) } - pub fn Username(url: &Url) -> USVString { USVString(quirks::username(url).to_owned()) } - pub fn SetHash(url: &mut Url, value: USVString) { quirks::set_hash(url, &value.0) } - pub fn SetHost(url: &mut Url, value: USVString) { let _ = quirks::set_host(url, &value.0); } - pub fn SetPort(url: &mut Url, value: USVString) { let _ = quirks::set_port(url, &value.0); } - pub fn SetSearch(url: &mut Url, value: USVString) { quirks::set_search(url, &value.0) } - pub fn SetPathname(url: &mut Url, value: USVString) { quirks::set_pathname(url, &value.0) } - pub fn SetHostname(url: &mut Url, value: USVString) { let _ = quirks::set_hostname(url, &value.0); } - pub fn SetPassword(url: &mut Url, value: USVString) { let _ = quirks::set_password(url, &value.0); } - pub fn SetProtocol(url: &mut Url, value: USVString) { let _ = quirks::set_protocol(url, &value.0); } - pub fn SetUsername(url: &mut Url, value: USVString) { let _ = quirks::set_username(url, &value.0); } + pub fn SameOrigin(url_a: &ServoUrl, url_b: &ServoUrl) -> bool { + url_a.origin() == url_b.origin() + } + pub fn Origin(url: &ServoUrl) -> USVString { + USVString(quirks::origin(url.as_url().unwrap()).to_owned()) + } + pub fn Href(url: &ServoUrl) -> USVString { + USVString(quirks::href(url.as_url().unwrap()).to_owned()) + } + pub fn Hash(url: &ServoUrl) -> USVString { + USVString(quirks::hash(url.as_url().unwrap()).to_owned()) + } + pub fn Host(url: &ServoUrl) -> USVString { + USVString(quirks::host(url.as_url().unwrap()).to_owned()) + } + pub fn Port(url: &ServoUrl) -> USVString { + USVString(quirks::port(url.as_url().unwrap()).to_owned()) + } + pub fn Search(url: &ServoUrl) -> USVString { + USVString(quirks::search(url.as_url().unwrap()).to_owned()) + } + pub fn Hostname(url: &ServoUrl) -> USVString { + USVString(quirks::hostname(url.as_url().unwrap()).to_owned()) + } + pub fn Password(url: &ServoUrl) -> USVString { + USVString(quirks::password(url.as_url().unwrap()).to_owned()) + } + pub fn Pathname(url: &ServoUrl) -> USVString { + USVString(quirks::pathname(url.as_url().unwrap()).to_owned()) + } + pub fn Protocol(url: &ServoUrl) -> USVString { + USVString(quirks::protocol(url.as_url().unwrap()).to_owned()) + } + pub fn Username(url: &ServoUrl) -> USVString { + USVString(quirks::username(url.as_url().unwrap()).to_owned()) + } + pub fn SetHash(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + quirks::set_hash(url, &value.0) + } + } + pub fn SetHost(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + let _ = quirks::set_host(url, &value.0); + } + } + pub fn SetPort(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + let _ = quirks::set_port(url, &value.0); + } + } + pub fn SetSearch(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + quirks::set_search(url, &value.0) + } + } + pub fn SetPathname(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + quirks::set_pathname(url, &value.0) + } + } + pub fn SetHostname(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + let _ = quirks::set_hostname(url, &value.0); + } + } + pub fn SetPassword(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + let _ = quirks::set_password(url, &value.0); + } + } + pub fn SetProtocol(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + let _ = quirks::set_protocol(url, &value.0); + } + } + pub fn SetUsername(url: &mut ServoUrl, value: USVString) { + if let Some(ref mut url) = url.as_mut_url() { + let _ = quirks::set_username(url, &value.0); + } + } } diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 1764db20764..d3486b7ad22 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -36,6 +36,7 @@ use net_traits::unwrap_websocket_protocol; use script_runtime::CommonScriptMsg; use script_runtime::ScriptThreadEventCategory::WebSocketEvent; use script_thread::{Runnable, RunnableWrapper}; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; @@ -43,7 +44,6 @@ use std::ptr; use std::thread; use task_source::TaskSource; use task_source::networking::NetworkingTaskSource; -use websocket::client::request::Url; use websocket::header::{Headers, WebSocketProtocol}; use websocket::ws::util::url::parse_url; @@ -171,7 +171,7 @@ pub fn fail_the_websocket_connection(address: Trusted<WebSocket>, #[dom_struct] pub struct WebSocket { eventtarget: EventTarget, - url: Url, + url: ServoUrl, ready_state: Cell<WebSocketRequestState>, buffered_amount: Cell<u64>, clearing_buffer: Cell<bool>, //Flag to tell if there is a running thread to clear buffered_amount @@ -182,7 +182,7 @@ pub struct WebSocket { } impl WebSocket { - fn new_inherited(url: Url) -> WebSocket { + fn new_inherited(url: ServoUrl) -> WebSocket { WebSocket { eventtarget: EventTarget::new_inherited(), url: url, @@ -195,7 +195,7 @@ impl WebSocket { } } - fn new(global: &GlobalScope, url: Url) -> Root<WebSocket> { + fn new(global: &GlobalScope, url: ServoUrl) -> Root<WebSocket> { reflect_dom_object(box WebSocket::new_inherited(url), global, WebSocketBinding::Wrap) } @@ -205,10 +205,10 @@ impl WebSocket { protocols: Option<StringOrStringSequence>) -> Fallible<Root<WebSocket>> { // Step 1. - let resource_url = try!(Url::parse(&url).map_err(|_| Error::Syntax)); + let resource_url = try!(ServoUrl::parse(&url).map_err(|_| Error::Syntax)); // Although we do this replace and parse operation again in the resource thread, // we try here to be able to immediately throw a syntax error on failure. - let _ = try!(parse_url(&replace_hosts(&resource_url)).map_err(|_| Error::Syntax)); + let _ = try!(parse_url(&replace_hosts(&resource_url).as_url().unwrap()).map_err(|_| Error::Syntax)); // Step 2: Disallow https -> ws connections. // Step 3: Potentially block access to some ports. diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 63485e45dfc..f2e56fcff36 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -76,6 +76,7 @@ use script_traits::{DocumentState, TimerEvent, TimerEventId}; use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest, WindowSizeData, WindowSizeType}; use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; @@ -102,7 +103,6 @@ use time; use timers::{IsInterval, TimerCallback}; #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] use tinyfiledialogs::{self, MessageBoxIcon}; -use url::Url; use util::geometry::{self, max_rect}; use util::opts; use util::prefs::PREFS; @@ -624,7 +624,7 @@ impl WindowMethods for Window { // object, not self's. Some(self.Document().origin().copy()) }, - url => match Url::parse(&url) { + url => match ServoUrl::parse(&url) { Ok(url) => Some(Origin::new(&url)), Err(_) => return Err(Error::Syntax), } @@ -860,7 +860,7 @@ impl WindowMethods for Window { // check-tidy: no specs after this line fn OpenURLInDefaultBrowser(&self, href: DOMString) -> ErrorResult { - let url = try!(Url::parse(&href).map_err(|e| { + let url = try!(ServoUrl::parse(&href).map_err(|e| { Error::Type(format!("Couldn't parse URL: {}", e)) })); match open::that(url.as_str()) { @@ -1322,7 +1322,7 @@ impl Window { } /// Commence a new URL load which will either replace this window or scroll to a fragment. - pub fn load_url(&self, url: Url, replace: bool, referrer_policy: Option<ReferrerPolicy>) { + pub fn load_url(&self, url: ServoUrl, replace: bool, referrer_policy: Option<ReferrerPolicy>) { let doc = self.Document(); let referrer_policy = referrer_policy.or(doc.get_referrer_policy()); @@ -1355,7 +1355,7 @@ impl Window { self.window_size.get() } - pub fn get_url(&self) -> Url { + pub fn get_url(&self) -> ServoUrl { (*self.Document().url()).clone() } diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 041ce8448de..6adb9ff7b60 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -34,6 +34,7 @@ use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromise use script_thread::{Runnable, RunnableWrapper}; use script_traits::{TimerEvent, TimerEventId}; use script_traits::WorkerGlobalScopeInit; +use servo_url::ServoUrl; use std::default::Default; use std::panic; use std::rc::Rc; @@ -43,7 +44,6 @@ use std::sync::mpsc::Receiver; use task_source::file_reading::FileReadingTaskSource; use task_source::networking::NetworkingTaskSource; use timers::{IsInterval, TimerCallback}; -use url::Url; pub fn prepare_workerscope_init(global: &GlobalScope, devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>) -> WorkerGlobalScopeInit { @@ -68,7 +68,7 @@ pub struct WorkerGlobalScope { globalscope: GlobalScope, worker_id: WorkerId, - worker_url: Url, + worker_url: ServoUrl, #[ignore_heap_size_of = "Arc"] closing: Option<Arc<AtomicBool>>, #[ignore_heap_size_of = "Defined in js"] @@ -91,7 +91,7 @@ pub struct WorkerGlobalScope { impl WorkerGlobalScope { pub fn new_inherited(init: WorkerGlobalScopeInit, - worker_url: Url, + worker_url: ServoUrl, runtime: Runtime, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, timer_event_chan: IpcSender<TimerEvent>, @@ -144,7 +144,7 @@ impl WorkerGlobalScope { } } - pub fn get_url(&self) -> &Url { + pub fn get_url(&self) -> &ServoUrl { &self.worker_url } diff --git a/components/script/dom/workerlocation.rs b/components/script/dom/workerlocation.rs index 287a803a612..aee42330463 100644 --- a/components/script/dom/workerlocation.rs +++ b/components/script/dom/workerlocation.rs @@ -9,24 +9,24 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString}; use dom::urlhelper::UrlHelper; use dom::workerglobalscope::WorkerGlobalScope; -use url::Url; +use servo_url::ServoUrl; // https://html.spec.whatwg.org/multipage/#worker-locations #[dom_struct] pub struct WorkerLocation { reflector_: Reflector, - url: Url, + url: ServoUrl, } impl WorkerLocation { - fn new_inherited(url: Url) -> WorkerLocation { + fn new_inherited(url: ServoUrl) -> WorkerLocation { WorkerLocation { reflector_: Reflector::new(), url: url, } } - pub fn new(global: &WorkerGlobalScope, url: Url) -> Root<WorkerLocation> { + pub fn new(global: &WorkerGlobalScope, url: ServoUrl) -> Root<WorkerLocation> { reflect_dom_object(box WorkerLocation::new_inherited(url), global, WorkerLocationBinding::Wrap) diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 87038d3aa45..bca9f6a65e3 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -16,7 +16,7 @@ use dom::location::Location; use dom::node::Node; use dom::window::Window; use js::jsapi::{JSContext, JSObject}; -use url::Url; +use servo_url::ServoUrl; // https://dom.spec.whatwg.org/#xmldocument #[dom_struct] @@ -27,7 +27,7 @@ pub struct XMLDocument { impl XMLDocument { fn new_inherited(window: &Window, browsing_context: Option<&BrowsingContext>, - url: Option<Url>, + url: Option<ServoUrl>, is_html_document: IsHTMLDocument, content_type: Option<DOMString>, last_modified: Option<String>, @@ -49,7 +49,7 @@ impl XMLDocument { pub fn new(window: &Window, browsing_context: Option<&BrowsingContext>, - url: Option<Url>, + url: Option<ServoUrl>, doctype: IsHTMLDocument, content_type: Option<DOMString>, last_modified: Option<String>, diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 57191d1d4e9..de4350c5307 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -55,6 +55,7 @@ use net_traits::request::{CredentialsMode, Destination, RequestInit, RequestMode use net_traits::trim_http_whitespace; use network_listener::{NetworkListener, PreInvoke}; use servo_atoms::Atom; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; @@ -64,7 +65,7 @@ use std::sync::{Arc, Mutex}; use task_source::networking::NetworkingTaskSource; use time; use timers::{OneshotTimerCallback, OneshotTimerHandle}; -use url::{Position, Url}; +use url::Position; use util::prefs::PREFS; #[derive(JSTraceable, PartialEq, Copy, Clone, HeapSizeOf)] @@ -137,7 +138,7 @@ pub struct XMLHttpRequest { // Associated concepts #[ignore_heap_size_of = "Defined in hyper"] request_method: DOMRefCell<Method>, - request_url: DOMRefCell<Option<Url>>, + request_url: DOMRefCell<Option<ServoUrl>>, #[ignore_heap_size_of = "Defined in hyper"] request_headers: DOMRefCell<Headers>, request_body_len: Cell<usize>, @@ -149,7 +150,7 @@ pub struct XMLHttpRequest { fetch_time: Cell<i64>, generation_id: Cell<GenerationId>, response_status: Cell<Result<(), ()>>, - referrer_url: Option<Url>, + referrer_url: Option<ServoUrl>, referrer_policy: Option<ReferrerPolicy>, } @@ -169,7 +170,7 @@ impl XMLHttpRequest { timeout: Cell::new(0u32), with_credentials: Cell::new(false), upload: JS::from_ref(&*XMLHttpRequestUpload::new(global)), - response_url: DOMRefCell::new(String::from("")), + response_url: DOMRefCell::new(String::new()), status: Cell::new(0), status_text: DOMRefCell::new(ByteString::new(vec!())), response: DOMRefCell::new(ByteString::new(vec!())), @@ -272,7 +273,7 @@ impl XMLHttpRequest { } impl LoadOrigin for XMLHttpRequest { - fn referrer_url(&self) -> Option<Url> { + fn referrer_url(&self) -> Option<ServoUrl> { return self.referrer_url.clone(); } @@ -862,7 +863,8 @@ impl XMLHttpRequest { } fn process_headers_available(&self, - gen_id: GenerationId, metadata: Result<FetchMetadata, NetworkError>) + gen_id: GenerationId, + metadata: Result<FetchMetadata, NetworkError>) -> Result<(), Error> { let metadata = match metadata { Ok(meta) => match meta { @@ -878,7 +880,7 @@ impl XMLHttpRequest { }, }; - *self.response_url.borrow_mut() = metadata.final_url[..Position::AfterQuery].to_owned(); + *self.response_url.borrow_mut() = metadata.final_url.as_url().unwrap()[..Position::AfterQuery].to_owned(); // XXXManishearth Clear cache entries in case of a network error self.process_partial_response(XHRProgress::HeadersReceived( |