Skip to content

Commit

Permalink
Auto merge of #16241 - upsuper:bug1352763-bug1352025, r=Manishearth,e…
Browse files Browse the repository at this point in the history
…milio

Stop passing url as string into Servo side

This is the Servo side changes of [bug 1352763](https://bugzilla.mozilla.org/show_bug.cgi?id=1352763) and [bug 1352025](https://bugzilla.mozilla.org/show_bug.cgi?id=1352025) which have been reviewed on Bugzilla.
  • Loading branch information
bors-servo committed Apr 3, 2017
2 parents a5a5abd + 35b638e commit 679b418
Show file tree
Hide file tree
Showing 32 changed files with 269 additions and 308 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions components/layout_thread/lib.rs
Expand Up @@ -113,7 +113,6 @@ use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode};
use style::error_reporting::StdoutErrorReporter;
use style::logical_geometry::LogicalPoint;
use style::media_queries::{Device, MediaType};
use style::parser::ParserContextExtraData;
use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW};
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards};
use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets};
Expand Down Expand Up @@ -1586,8 +1585,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
Default::default(),
shared_lock.clone(),
None,
&StdoutErrorReporter,
ParserContextExtraData::default()))
&StdoutErrorReporter))
}

let shared_lock = SharedRwLock::new();
Expand All @@ -1600,7 +1598,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
for &(ref contents, ref url) in &opts::get().user_stylesheets {
user_or_user_agent_stylesheets.push(Stylesheet::from_bytes(
&contents, url.clone(), None, None, Origin::User, Default::default(),
shared_lock.clone(), None, &StdoutErrorReporter, ParserContextExtraData::default()));
shared_lock.clone(), None, &StdoutErrorReporter));
}

let quirks_mode_stylesheet = try!(parse_ua_stylesheet(&shared_lock, "quirks-mode.css"));
Expand Down
4 changes: 1 addition & 3 deletions components/script/dom/csskeyframesrule.rs
Expand Up @@ -19,7 +19,6 @@ use dom_struct::dom_struct;
use servo_atoms::Atom;
use std::sync::Arc;
use style::keyframes::{Keyframe, KeyframeSelector};
use style::parser::ParserContextExtraData;
use style::shared_lock::{Locked, ToCssWithGuard};
use style::stylesheets::KeyframesRule;

Expand Down Expand Up @@ -83,8 +82,7 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {

// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-appendrule
fn AppendRule(&self, rule: DOMString) {
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet(),
ParserContextExtraData::default());
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet());
if let Ok(rule) = rule {
let mut guard = self.cssrule.shared_lock().write();
self.keyframesrule.write_with(&mut guard).keyframes.push(rule);
Expand Down
5 changes: 4 additions & 1 deletion components/script/dom/cssrulelist.rs
Expand Up @@ -92,7 +92,10 @@ impl CSSRuleList {
let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
let new_rule = {
let mut guard = parent_stylesheet.shared_lock.write();
css_rules.write_with(&mut guard).insert_rule(rule, parent_stylesheet, index, nested)?
// FIXME We should probably pass in a proper StylesheetLoader.
// See servo/servo#16240
css_rules.write_with(&mut guard).insert_rule(rule, parent_stylesheet,
index, nested, None)?
// Drop `guard` here,
// CSSRule::new_specific re-acquires the lock for @support and @media.
};
Expand Down
9 changes: 3 additions & 6 deletions components/script/dom/cssstyledeclaration.rs
Expand Up @@ -18,7 +18,6 @@ use servo_url::ServoUrl;
use std::ascii::AsciiExt;
use std::sync::Arc;
use style::attr::AttrValue;
use style::parser::ParserContextExtraData;
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
use style::properties::{parse_one_declaration, parse_style_attribute};
use style::selector_parser::PseudoElement;
Expand Down Expand Up @@ -147,7 +146,7 @@ impl CSSStyleOwner {
match *self {
CSSStyleOwner::Element(ref el) => window_from_node(&**el).Document().base_url(),
CSSStyleOwner::CSSRule(ref rule, _) => {
rule.parent_stylesheet().style_stylesheet().base_url.clone()
rule.parent_stylesheet().style_stylesheet().url_data.clone()
}
}
}
Expand Down Expand Up @@ -258,8 +257,7 @@ impl CSSStyleDeclaration {
let window = self.owner.window();
let result =
parse_one_declaration(id, &value, &self.owner.base_url(),
window.css_error_reporter(),
ParserContextExtraData::default());
window.css_error_reporter());

// Step 7
let parsed = match result {
Expand Down Expand Up @@ -439,8 +437,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
// Step 3
*pdb = parse_style_attribute(&value,
&self.owner.base_url(),
window.css_error_reporter(),
ParserContextExtraData::default());
window.css_error_reporter());
});

Ok(())
Expand Down
4 changes: 1 addition & 3 deletions components/script/dom/element.rs
Expand Up @@ -101,7 +101,6 @@ use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::context::{QuirksMode, ReflowGoal};
use style::element_state::*;
use style::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
use style::parser::ParserContextExtraData;
use style::properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size, overflow_x};
use style::restyle_hints::RESTYLE_SELF;
Expand Down Expand Up @@ -2197,8 +2196,7 @@ impl VirtualMethods for Element {
Arc::new(doc.style_shared_lock().wrap(parse_style_attribute(
&attr.value(),
&doc.base_url(),
win.css_error_reporter(),
ParserContextExtraData::default())))
win.css_error_reporter())))
};

Some(block)
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlmetaelement.rs
Expand Up @@ -105,7 +105,7 @@ impl HTMLMetaElement {
rules: CssRules::new(vec![rule], shared_lock),
origin: Origin::Author,
shared_lock: shared_lock.clone(),
base_url: window_from_node(self).get_url(),
url_data: window_from_node(self).get_url(),
namespaces: Default::default(),
media: Arc::new(shared_lock.wrap(Default::default())),
// Viewport constraints are always recomputed on resize; they don't need to
Expand Down
4 changes: 1 addition & 3 deletions components/script/dom/htmlstyleelement.rs
Expand Up @@ -25,7 +25,6 @@ use script_layout_interface::message::Msg;
use std::cell::Cell;
use std::sync::Arc;
use style::media_queries::parse_media_query_list;
use style::parser::ParserContextExtraData;
use style::stylesheets::{Stylesheet, Origin};
use stylesheet_loader::{StylesheetLoader, StylesheetOwner};

Expand Down Expand Up @@ -88,8 +87,7 @@ impl HTMLStyleElement {
let loader = StylesheetLoader::for_element(self.upcast());
let sheet = Stylesheet::from_str(&data, url, Origin::Author, mq,
shared_lock, Some(&loader),
win.css_error_reporter(),
ParserContextExtraData::default());
win.css_error_reporter());

let sheet = Arc::new(sheet);

Expand Down
8 changes: 3 additions & 5 deletions components/script/stylesheet_loader.rs
Expand Up @@ -27,7 +27,6 @@ use servo_url::ServoUrl;
use std::mem;
use std::sync::{Arc, Mutex};
use style::media_queries::MediaList;
use style::parser::ParserContextExtraData;
use style::shared_lock::Locked as StyleLocked;
use style::stylesheets::{ImportRule, Stylesheet, Origin};
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
Expand Down Expand Up @@ -146,8 +145,7 @@ impl FetchResponseListener for StylesheetContext {
media.take().unwrap(),
shared_lock,
Some(&loader),
win.css_error_reporter(),
ParserContextExtraData::default()));
win.css_error_reporter()));

if link.is_alternate() {
sheet.set_disabled(true);
Expand All @@ -163,9 +161,9 @@ impl FetchResponseListener for StylesheetContext {
&data,
protocol_encoding_label,
Some(environment_encoding),
&final_url,
Some(&loader),
win.css_error_reporter(),
ParserContextExtraData::default());
win.css_error_reporter());
}
}

Expand Down
22 changes: 9 additions & 13 deletions components/style/encoding_support.rs
Expand Up @@ -9,12 +9,10 @@ extern crate encoding;
use cssparser::{stylesheet_encoding, EncodingSupport};
use error_reporting::ParseErrorReporter;
use media_queries::MediaList;
use parser::ParserContextExtraData;
use self::encoding::{EncodingRef, DecoderTrap};
use servo_url::ServoUrl;
use shared_lock::SharedRwLock;
use std::str;
use stylesheets::{Stylesheet, StylesheetLoader, Origin};
use stylesheets::{Stylesheet, StylesheetLoader, Origin, UrlExtraData};

struct RustEncoding;

Expand Down Expand Up @@ -50,26 +48,24 @@ impl Stylesheet {
/// Takes care of decoding the network bytes and forwards the resulting
/// string to `Stylesheet::from_str`.
pub fn from_bytes(bytes: &[u8],
base_url: ServoUrl,
url_data: UrlExtraData,
protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>,
origin: Origin,
media: MediaList,
shared_lock: SharedRwLock,
stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter,
extra_data: ParserContextExtraData)
error_reporter: &ParseErrorReporter)
-> Stylesheet {
let (string, _) = decode_stylesheet_bytes(
bytes, protocol_encoding_label, environment_encoding);
Stylesheet::from_str(&string,
base_url,
url_data,
origin,
media,
shared_lock,
stylesheet_loader,
error_reporter,
extra_data)
error_reporter)
}

/// Updates an empty stylesheet with a set of bytes that reached over the
Expand All @@ -78,15 +74,15 @@ impl Stylesheet {
bytes: &[u8],
protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>,
url_data: &UrlExtraData,
stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter,
extra_data: ParserContextExtraData) {
error_reporter: &ParseErrorReporter) {
let (string, _) = decode_stylesheet_bytes(
bytes, protocol_encoding_label, environment_encoding);
Self::update_from_str(existing,
&string,
url_data,
stylesheet_loader,
error_reporter,
extra_data)
error_reporter)
}
}
6 changes: 3 additions & 3 deletions components/style/error_reporting.rs
Expand Up @@ -8,7 +8,7 @@

use cssparser::{Parser, SourcePosition};
use log;
use servo_url::ServoUrl;
use stylesheets::UrlExtraData;

/// A generic trait for an error reporter.
pub trait ParseErrorReporter : Sync + Send {
Expand All @@ -20,7 +20,7 @@ pub trait ParseErrorReporter : Sync + Send {
input: &mut Parser,
position: SourcePosition,
message: &str,
url: &ServoUrl);
url: &UrlExtraData);
}

/// An error reporter that reports the errors to the `info` log channel.
Expand All @@ -32,7 +32,7 @@ impl ParseErrorReporter for StdoutErrorReporter {
input: &mut Parser,
position: SourcePosition,
message: &str,
url: &ServoUrl) {
url: &UrlExtraData) {
if log_enabled!(log::LogLevel::Info) {
let location = input.source_location(position);
info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, message)
Expand Down
11 changes: 1 addition & 10 deletions components/style/gecko/url.rs
Expand Up @@ -34,18 +34,9 @@ impl SpecifiedUrl {
pub fn parse_from_string<'a>(url: Cow<'a, str>,
context: &ParserContext)
-> Result<Self, ()> {
let extra = &context.extra_data;
if extra.data.is_none() {
// FIXME(heycam) should ensure we always have a principal, etc.,
// when parsing style attributes and re-parsing due to CSS
// Variables.
warn!("stylo: skipping declaration without ParserContextExtraData");
return Err(())
}

Ok(SpecifiedUrl {
serialization: Arc::new(url.into_owned()),
extra_data: extra.data.as_ref().unwrap().clone(),
extra_data: context.url_data.clone(),
})
}

Expand Down
17 changes: 3 additions & 14 deletions components/style/gecko/wrapper.rs
Expand Up @@ -50,7 +50,6 @@ use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE;
use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS;
use gecko_bindings::sugar::ownership::HasArcFFI;
use parking_lot::RwLock;
use parser::ParserContextExtraData;
use properties::{ComputedValues, parse_style_attribute};
use properties::PropertyDeclarationBlock;
use properties::animated_properties::AnimationValueMap;
Expand All @@ -59,13 +58,13 @@ use selector_parser::{ElementExt, Snapshot};
use selectors::Element;
use selectors::matching::{ElementSelectorFlags, StyleRelations};
use selectors::parser::{AttrSelector, NamespaceConstraint};
use servo_url::ServoUrl;
use shared_lock::Locked;
use sink::Push;
use std::fmt;
use std::ptr;
use std::sync::Arc;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use stylesheets::UrlExtraData;
use stylist::ApplicableDeclarationBlock;

/// A simple wrapper over a non-null Gecko node (`nsINode`) pointer.
Expand Down Expand Up @@ -315,9 +314,8 @@ impl<'le> fmt::Debug for GeckoElement<'le> {
impl<'le> GeckoElement<'le> {
/// Parse the style attribute of an element.
pub fn parse_style_attribute(value: &str,
base_url: &ServoUrl,
extra_data: ParserContextExtraData) -> PropertyDeclarationBlock {
parse_style_attribute(value, base_url, &StdoutErrorReporter, extra_data)
url_data: &UrlExtraData) -> PropertyDeclarationBlock {
parse_style_attribute(value, url_data, &StdoutErrorReporter)
}

fn flags(&self) -> u32 {
Expand Down Expand Up @@ -389,15 +387,6 @@ impl<'le> GeckoElement<'le> {
}
}

lazy_static! {
/// A dummy base url in order to get it where we don't have any available.
///
/// We need to get rid of this sooner than later.
pub static ref DUMMY_BASE_URL: ServoUrl = {
ServoUrl::parse("http://www.example.org").unwrap()
};
}

/// Converts flags from the layout used by rust-selectors to the layout used
/// by Gecko. We could align these and then do this without conditionals, but
/// it's probably not worth the trouble.
Expand Down

0 comments on commit 679b418

Please sign in to comment.