Auto merge of #14246 - emilio:servo-url, r=SimonSapin

Urlmageddon

<!-- Please describe your changes on the following line: -->

Still needs a bunch of code in net to be converted in order to get more
advantage of this for images and stuff, but meanwhile this should help quite a
bit with #13778.

Still wanted to get this in.

r? @SimonSapin

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14246)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-17 15:34:47 -06:00 committed by GitHub
commit 22aebdf5d4
161 changed files with 1044 additions and 718 deletions

View file

@ -17,7 +17,7 @@ gecko = ["nsstring_vendor", "num_cpus", "rayon/unstable"]
servo = ["serde/unstable", "serde", "serde_derive", "heapsize_derive",
"style_traits/servo", "app_units/plugins", "servo_atoms", "html5ever-atoms",
"cssparser/heap_size", "cssparser/serde-serialization",
"url/heap_size", "plugins", "rayon/unstable"]
"plugins", "rayon/unstable", "servo_url/servo"]
testing = []
[dependencies]
@ -50,9 +50,9 @@ serde_derive = {version = "0.8", optional = true}
servo_atoms = {path = "../atoms", optional = true}
smallvec = "0.1"
style_traits = {path = "../style_traits"}
servo_url = {path = "../url"}
time = "0.1"
unicode-segmentation = "0.1.2"
url = "1.2"
util = {path = "../util"}
plugins = {path = "../plugins", optional = true}

View file

@ -11,12 +11,12 @@ use app_units::Au;
use cssparser::{self, Color, RGBA};
use euclid::num::Zero;
use num_traits::ToPrimitive;
use servo_url::ServoUrl;
use std::ascii::AsciiExt;
use std::str::FromStr;
use str::{HTML_SPACE_CHARACTERS, read_exponent, read_fraction};
use str::{read_numbers, split_commas, split_html_space_chars};
#[cfg(not(feature = "gecko"))] use str::str_join;
use url::Url;
use values::specified::Length;
// Duplicated from script::dom::values.
@ -42,7 +42,7 @@ pub enum AttrValue {
Length(String, Option<Length>),
Color(String, Option<RGBA>),
Dimension(String, LengthOrPercentageOrAuto),
Url(String, Option<Url>),
Url(String, Option<ServoUrl>),
}
/// Shared implementation to parse an integer according to
@ -208,7 +208,7 @@ impl AttrValue {
AttrValue::Atom(value)
}
pub fn from_url(base: &Url, url: String) -> AttrValue {
pub fn from_url(base: &ServoUrl, url: String) -> AttrValue {
let joined = base.join(&url).ok();
AttrValue::Url(url, joined)
}
@ -293,7 +293,7 @@ impl AttrValue {
/// ## Panics
///
/// Panics if the `AttrValue` is not a `Url`
pub fn as_url(&self) -> Option<&Url> {
pub fn as_url(&self) -> Option<&ServoUrl> {
match *self {
AttrValue::Url(_, ref url) => url.as_ref(),
_ => panic!("Url not found"),

View file

@ -11,7 +11,7 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use parser::{ParserContext, log_css_error};
use properties::longhands::font_family::parse_one_family;
use std::iter;
use url::Url;
use values::specified::url::SpecifiedUrl;
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
@ -23,7 +23,7 @@ pub enum Source {
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub struct UrlSource {
pub url: Url,
pub url: SpecifiedUrl,
pub format_hints: Vec<String>,
}
@ -139,9 +139,8 @@ fn parse_one_src(context: &ParserContext, input: &mut Parser) -> Result<Source,
if input.try(|input| input.expect_function_matching("local")).is_ok() {
return Ok(Source::Local(try!(input.parse_nested_block(parse_one_family))))
}
let url = try!(input.expect_url());
let url = context.base_url.join(&url).unwrap_or_else(
|_error| Url::parse("about:invalid").unwrap());
let url = try!(SpecifiedUrl::parse(context, input));
// Parsing optional format()
let format_hints = if input.try(|input| input.expect_function_matching("format")).is_ok() {

View file

@ -36,12 +36,12 @@ use selector_impl::ElementExt;
use selector_matching::ApplicableDeclarationBlock;
use selectors::Element;
use selectors::parser::{AttrSelector, NamespaceConstraint};
use servo_url::ServoUrl;
use sink::Push;
use std::fmt;
use std::ptr;
use std::sync::Arc;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use url::Url;
// Important: We don't currently refcount the DOM, because the wrapper lifetime
// magic guarantees that our LayoutFoo references won't outlive the root, and
@ -281,8 +281,8 @@ impl<'le> GeckoElement<'le> {
}
lazy_static! {
pub static ref DUMMY_BASE_URL: Url = {
Url::parse("http://www.example.org").unwrap()
pub static ref DUMMY_BASE_URL: ServoUrl = {
ServoUrl::parse("http://www.example.org").unwrap()
};
}

View file

@ -79,13 +79,13 @@ extern crate selectors;
extern crate serde;
#[cfg(feature = "servo")] #[macro_use] extern crate serde_derive;
#[cfg(feature = "servo")] #[macro_use] extern crate servo_atoms;
extern crate servo_url;
extern crate smallvec;
#[macro_use]
extern crate style_traits;
extern crate time;
#[allow(unused_extern_crates)]
extern crate unicode_segmentation;
extern crate url;
extern crate util;
pub mod animation;

View file

@ -10,8 +10,8 @@ use error_reporting::ParseErrorReporter;
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
use selector_impl::TheSelectorImpl;
use selectors::parser::ParserContext as SelectorParserContext;
use servo_url::ServoUrl;
use stylesheets::Origin;
use url::Url;
#[cfg(not(feature = "gecko"))]
pub struct ParserContextExtraData;
@ -37,14 +37,14 @@ impl ParserContextExtraData {
pub struct ParserContext<'a> {
pub stylesheet_origin: Origin,
pub base_url: &'a Url,
pub base_url: &'a ServoUrl,
pub selector_context: SelectorParserContext<TheSelectorImpl>,
pub error_reporter: Box<ParseErrorReporter + Send>,
pub extra_data: ParserContextExtraData,
}
impl<'a> ParserContext<'a> {
pub fn new_with_extra_data(stylesheet_origin: Origin, base_url: &'a Url,
pub fn new_with_extra_data(stylesheet_origin: Origin, base_url: &'a ServoUrl,
error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData)
-> ParserContext<'a> {
@ -59,7 +59,7 @@ impl<'a> ParserContext<'a> {
}
}
pub fn new(stylesheet_origin: Origin, base_url: &'a Url, error_reporter: Box<ParseErrorReporter + Send>)
pub fn new(stylesheet_origin: Origin, base_url: &'a ServoUrl, error_reporter: Box<ParseErrorReporter + Send>)
-> ParserContext<'a> {
let extra_data = ParserContextExtraData::default();
ParserContext::new_with_extra_data(stylesheet_origin, base_url, error_reporter, extra_data)

View file

@ -6,13 +6,13 @@ use cssparser::{DeclarationListParser, parse_important};
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
use error_reporting::ParseErrorReporter;
use parser::{ParserContext, ParserContextExtraData, log_css_error};
use servo_url::ServoUrl;
use std::ascii::AsciiExt;
use std::boxed::Box as StdBox;
use std::fmt;
use style_traits::ToCss;
use stylesheets::Origin;
use super::*;
use url::Url;
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
@ -423,14 +423,19 @@ pub fn append_serialization<'a, W, I>(dest: &mut W,
write!(dest, ";")
}
pub fn parse_style_attribute(input: &str, base_url: &Url, error_reporter: StdBox<ParseErrorReporter + Send>,
pub fn parse_style_attribute(input: &str,
base_url: &ServoUrl,
error_reporter: StdBox<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData)
-> PropertyDeclarationBlock {
let context = ParserContext::new_with_extra_data(Origin::Author, base_url, error_reporter, extra_data);
parse_property_declaration_list(&context, &mut Parser::new(input))
}
pub fn parse_one_declaration(name: &str, input: &str, base_url: &Url, error_reporter: StdBox<ParseErrorReporter + Send>,
pub fn parse_one_declaration(name: &str,
input: &str,
base_url: &ServoUrl,
error_reporter: StdBox<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData)
-> Result<Vec<PropertyDeclaration>, ()> {
let context = ParserContext::new_with_extra_data(Origin::Author, base_url, error_reporter, extra_data);

View file

@ -21,7 +21,6 @@ use app_units::Au;
#[cfg(feature = "servo")] use cssparser::{Color as CSSParserColor, RGBA};
use cssparser::{Parser, TokenSerializationType};
use error_reporting::ParseErrorReporter;
use url::Url;
#[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D;
use euclid::size::Size2D;
use computed_values;
@ -29,6 +28,7 @@ use font_metrics::FontMetricsProvider;
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
use logical_geometry::WritingMode;
use parser::{Parse, ParserContext, ParserContextExtraData};
use servo_url::ServoUrl;
use style_traits::ToCss;
use stylesheets::Origin;
#[cfg(feature = "servo")] use values::Either;
@ -240,7 +240,7 @@ mod property_bit_field {
fn substitute_variables_${property.ident}_slow<F>(
css: &String,
first_token_type: TokenSerializationType,
base_url: &Url,
base_url: &ServoUrl,
from_shorthand: Option<Shorthand>,
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
f: F,
@ -493,7 +493,7 @@ pub enum DeclaredValue<T> {
WithVariables {
css: String,
first_token_type: TokenSerializationType,
base_url: Url,
base_url: ServoUrl,
from_shorthand: Option<Shorthand>,
},
Initial,

View file

@ -18,11 +18,11 @@ use parser::{ParserContext, ParserContextExtraData, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
use selector_impl::TheSelectorImpl;
use selectors::parser::{Selector, parse_selector_list};
use servo_url::ServoUrl;
use std::cell::Cell;
use std::fmt;
use std::sync::Arc;
use style_traits::ToCss;
use url::Url;
use viewport::ViewportRule;
@ -171,7 +171,7 @@ impl ToCss for StyleRule {
impl Stylesheet {
pub fn from_bytes_iter<I: Iterator<Item=Vec<u8>>>(
input: I, base_url: Url, protocol_encoding_label: Option<&str>,
input: I, base_url: ServoUrl, protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>, origin: Origin,
error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData) -> Stylesheet {
@ -186,7 +186,7 @@ impl Stylesheet {
}
pub fn from_bytes(bytes: &[u8],
base_url: Url,
base_url: ServoUrl,
protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>,
origin: Origin, error_reporter: Box<ParseErrorReporter + Send>,
@ -198,7 +198,7 @@ impl Stylesheet {
Stylesheet::from_str(&string, base_url, origin, error_reporter, extra_data)
}
pub fn from_str(css: &str, base_url: Url, origin: Origin,
pub fn from_str(css: &str, base_url: ServoUrl, origin: Origin,
error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData) -> Stylesheet {
let rule_parser = TopLevelRuleParser {

View file

@ -9,11 +9,10 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use servo_url::ServoUrl;
use std::f32::consts::PI;
use std::fmt;
use std::sync::Arc;
use style_traits::ToCss;
use url::Url;
use values::computed::ComputedValueAsSpecified;
use values::specified::{Angle, CSSColor, Length, LengthOrPercentage};
use values::specified::position::Position;
@ -48,7 +47,7 @@ impl Image {
/// Creates an already specified image value from an already resolved URL
/// for insertion in the cascade.
pub fn for_cascade(url: Option<Arc<Url>>, extra_data: UrlExtraData) -> Self {
pub fn for_cascade(url: Option<ServoUrl>, extra_data: UrlExtraData) -> Self {
Image::Url(SpecifiedUrl::for_cascade(url, extra_data))
}
}

View file

@ -10,15 +10,15 @@ use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
use parser::ParserContext;
#[cfg(feature = "gecko")]
use parser::ParserContextExtraData;
use servo_url::ServoUrl;
use std::fmt::{self, Write};
use std::ptr;
use std::sync::Arc;
use style_traits::ToCss;
use url::Url;
use values::computed::ComputedValueAsSpecified;
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Serialize, Deserialize, Eq))]
pub struct UrlExtraData {
#[cfg(feature = "gecko")]
pub base: GeckoArcURI,
@ -55,7 +55,7 @@ impl UrlExtraData {
/// A specified url() value.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Serialize, Deserialize))]
pub struct SpecifiedUrl {
/// The original URI. This might be optional since we may insert computed
/// values of images into the cascade directly, and we don't bother to
@ -66,7 +66,7 @@ pub struct SpecifiedUrl {
original: Option<Arc<String>>,
/// The resolved value for the url, if valid.
resolved: Option<Arc<Url>>,
resolved: Option<ServoUrl>,
/// Extra data used for Stylo.
extra_data: UrlExtraData,
@ -88,7 +88,7 @@ impl SpecifiedUrl {
};
let serialization = Arc::new(url.into_owned());
let resolved = context.base_url.join(&serialization).ok().map(Arc::new);
let resolved = context.base_url.join(&serialization).ok();
Ok(SpecifiedUrl {
original: Some(serialization),
resolved: resolved,
@ -100,7 +100,7 @@ impl SpecifiedUrl {
&self.extra_data
}
pub fn url(&self) -> Option<&Arc<Url>> {
pub fn url(&self) -> Option<&ServoUrl> {
self.resolved.as_ref()
}
@ -114,7 +114,7 @@ impl SpecifiedUrl {
/// Creates an already specified url value from an already resolved URL
/// for insertion in the cascade.
pub fn for_cascade(url: Option<Arc<Url>>, extra_data: UrlExtraData) -> Self {
pub fn for_cascade(url: Option<ServoUrl>, extra_data: UrlExtraData) -> Self {
SpecifiedUrl {
original: None,
resolved: url,
@ -122,12 +122,11 @@ impl SpecifiedUrl {
}
}
// Just for unit tests, don't use outside of them!
#[cfg(feature = "servo")]
pub fn new_for_testing(url: &str) -> Self {
SpecifiedUrl {
original: Some(Arc::new(url.into())),
resolved: Url::parse(url).ok().map(Arc::new),
resolved: ServoUrl::parse(url).ok(),
extra_data: UrlExtraData {}
}
}
@ -142,6 +141,8 @@ impl PartialEq for SpecifiedUrl {
}
}
impl Eq for SpecifiedUrl {}
impl ToCss for SpecifiedUrl {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(dest.write_str("url(\""));