Skip to content

Commit

Permalink
Auto merge of #8682 - jdm:css-error-reporter, r=jdm
Browse files Browse the repository at this point in the history
Defined new trait ParseErrorReporter and added error_reporter member …

…to ParserContext.

Rebase of #8210.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8682)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Nov 26, 2015
2 parents 3614ed7 + 996e9e0 commit f5ef2f4
Show file tree
Hide file tree
Showing 24 changed files with 194 additions and 69 deletions.
3 changes: 3 additions & 0 deletions components/layout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ path = "../script_traits"
[dependencies.style]
path = "../style"

[dependencies.style_traits]
path = "../style_traits"

[dependencies.plugins]
path = "../plugins"

Expand Down
4 changes: 4 additions & 0 deletions components/layout/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::rc::Rc;
use std::sync::mpsc::{Sender, channel};
use std::sync::{Arc, Mutex, RwLock};
use style::selector_matching::Stylist;
use style_traits::ParseErrorReporter;
use url::Url;
use util::mem::HeapSizeOf;
use util::opts;
Expand Down Expand Up @@ -127,6 +128,9 @@ pub struct SharedLayoutContext {

/// Why is this reflow occurring
pub goal: ReflowGoal,

///The CSS error reporter for all CSS loaded in this layout thread
pub error_reporter: Box<ParseErrorReporter + Sync>
}

pub struct LayoutContext<'a> {
Expand Down
7 changes: 5 additions & 2 deletions components/layout/css/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use string_cache::{Atom, Namespace};
use style::node::TElementAttributes;
use style::properties::{ComputedValues, PropertyDeclaration, cascade};
use style::selector_matching::{DeclarationBlock, Stylist};
use style_traits::ParseErrorReporter;
use util::arc_ptr_eq;
use util::cache::{LRUCache, SimpleHashCache};
use util::opts;
Expand Down Expand Up @@ -456,7 +457,8 @@ impl<'ln> PrivateMatchMethods for ServoLayoutNode<'ln> {
applicable_declarations,
shareable,
Some(&***parent_style),
cached_computed_values);
cached_computed_values,
layout_context.error_reporter.clone());
cacheable = cacheable && is_cacheable;
this_style = the_style
}
Expand All @@ -465,7 +467,8 @@ impl<'ln> PrivateMatchMethods for ServoLayoutNode<'ln> {
applicable_declarations,
shareable,
None,
None);
None,
layout_context.error_reporter.clone());
cacheable = cacheable && is_cacheable;
this_style = the_style
}
Expand Down
9 changes: 8 additions & 1 deletion components/layout/layout_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use script::layout_interface::Animation;
use script::layout_interface::{LayoutRPC, OffsetParentResponse};
use script::layout_interface::{Msg, NewLayoutTaskInfo, Reflow, ReflowGoal, ReflowQueryType};
use script::layout_interface::{ScriptLayoutChan, ScriptReflow};
use script::reporter::CSSErrorReporter;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, OpaqueScriptLayoutChannel};
use sequential;
use serde_json;
Expand All @@ -64,6 +65,7 @@ use style::computed_values::{filter, mix_blend_mode};
use style::media_queries::{Device, MediaType};
use style::selector_matching::{Stylist, USER_OR_USER_AGENT_STYLESHEETS};
use style::stylesheets::{CSSRuleIteratorExt, Stylesheet};
use style_traits::ParseErrorReporter;
use url::Url;
use util::geometry::MAX_RECT;
use util::ipc::OptionalIpcSender;
Expand Down Expand Up @@ -211,6 +213,10 @@ pub struct LayoutTask {
///
/// All the other elements of this struct are read-only.
rw_data: Arc<Mutex<LayoutTaskData>>,

/// The CSS error reporter for all CSS loaded in this layout thread
error_reporter: CSSErrorReporter,

}

impl LayoutTaskFactory for LayoutTask {
Expand Down Expand Up @@ -438,6 +444,7 @@ impl LayoutTask {
resolved_style_response: None,
offset_parent_response: OffsetParentResponse::empty(),
})),
error_reporter: CSSErrorReporter,
}
}

Expand Down Expand Up @@ -476,6 +483,7 @@ impl LayoutTask {
goal: goal,
running_animations: self.running_animations.clone(),
expired_animations: self.expired_animations.clone(),
error_reporter: self.error_reporter.clone(),
}
}

Expand Down Expand Up @@ -557,7 +565,6 @@ impl LayoutTask {
goal: ReflowGoal::ForDisplay,
page_clip_rect: MAX_RECT,
};

let mut layout_context = self.build_shared_layout_context(&*rw_data,
false,
&self.url,
Expand Down
1 change: 1 addition & 0 deletions components/layout/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern crate serde_json;
extern crate smallvec;
#[macro_use(atom, ns)] extern crate string_cache;
extern crate style;
extern crate style_traits;
extern crate unicode_bidi;
extern crate unicode_script;
extern crate url;
Expand Down
3 changes: 3 additions & 0 deletions components/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ path = "../devtools_traits"
[dependencies.style]
path = "../style"

[dependencies.style_traits]
path = "../style_traits"

[dependencies.canvas]
path = "../canvas"

Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/cssstyledeclaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::cell::Ref;
use string_cache::Atom;
use style::properties::{PropertyDeclaration, Shorthand};
use style::properties::{is_supported_property, parse_one_declaration};
use style_traits::ParseErrorReporter;
use util::str::{DOMString, str_join};

// http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
Expand Down Expand Up @@ -240,7 +241,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {

// Step 6
let window = window_from_node(&*self.owner);
let declarations = parse_one_declaration(&property, &value, &window.get_url());
let declarations = parse_one_declaration(&property, &value, &window.get_url(), window.css_error_reporter());

// Step 7
let declarations = if let Ok(declarations) = declarations {
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ use style::properties::longhands::{self, background_image, border_spacing, font_
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
use style_traits::ParseErrorReporter;
use url::UrlParser;
use util::mem::HeapSizeOf;
use util::str::{DOMString, LengthOrPercentageOrAuto};
Expand Down Expand Up @@ -1514,7 +1515,8 @@ impl VirtualMethods for Element {
// Modifying the `style` attribute might change style.
*self.style_attribute.borrow_mut() =
mutation.new_value(attr).map(|value| {
parse_style_attribute(&value, &doc.base_url())
let win = window_from_node(self);
parse_style_attribute(&value, &doc.base_url(), win.css_error_reporter())
});
if node.is_in_doc() {
doc.content_changed(node, NodeDamage::NodeStyleDamaged);
Expand Down
8 changes: 6 additions & 2 deletions components/script/dom/htmllinkelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,17 @@ impl AsyncResponseListener for StylesheetContext {
let environment_encoding = UTF_8 as EncodingRef;
let protocol_encoding_label = metadata.charset.as_ref().map(|s| &**s);
let final_url = metadata.final_url;

let elem = self.elem.root();
let win = window_from_node(&*elem);

let mut sheet = Stylesheet::from_bytes(&data, final_url, protocol_encoding_label,
Some(environment_encoding), Origin::Author);
Some(environment_encoding), Origin::Author,
win.css_error_reporter());
let media = self.media.take().unwrap();
sheet.set_media(Some(media));
let sheet = Arc::new(sheet);

let elem = self.elem.root();
let elem = elem.r();
let document = document_from_node(elem);
let document = document.r();
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlstyleelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl HTMLStyleElement {
};

let data = node.GetTextContent().expect("Element.textContent must be a string");
let mut sheet = Stylesheet::from_str(&data, url, Origin::Author);
let mut sheet = Stylesheet::from_str(&data, url, Origin::Author, win.css_error_reporter());
let mut css_parser = CssParser::new(&mq_str);
let media = parse_media_query_list(&mut css_parser);
sheet.set_media(Some(media));
Expand Down
12 changes: 10 additions & 2 deletions components/script/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use net_traits::storage_task::{StorageTask, StorageType};
use num::traits::ToPrimitive;
use page::Page;
use profile_traits::mem;
use reporter::CSSErrorReporter;
use rustc_serialize::base64::{FromBase64, STANDARD, ToBase64};
use script_task::{ScriptChan, ScriptPort, MainThreadScriptMsg, RunnableWrapper};
use script_task::{SendableMainThreadScriptChan, MainThreadScriptChan};
Expand All @@ -70,6 +71,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::TryRecvError::{Disconnected, Empty};
use std::sync::mpsc::{Sender, channel};
use string_cache::Atom;
use style_traits::ParseErrorReporter;
use time;
use timers::{ActiveTimers, IsInterval, ScheduledCallback, TimerCallback, TimerHandle};
use url::Url;
Expand Down Expand Up @@ -216,6 +218,8 @@ pub struct Window {
/// A flag to prevent async events from attempting to interact with this window.
#[ignore_heap_size_of = "defined in std"]
ignore_further_async_events: Arc<AtomicBool>,

error_reporter: CSSErrorReporter,
}

impl Window {
Expand Down Expand Up @@ -289,6 +293,10 @@ impl Window {
pub fn storage_task(&self) -> StorageTask {
self.storage_task.clone()
}

pub fn css_error_reporter(&self) -> Box<ParseErrorReporter + Send> {
return self.error_reporter.clone();
}
}

// https://html.spec.whatwg.org/multipage/#atob
Expand Down Expand Up @@ -1243,7 +1251,7 @@ impl Window {
lchan.send(Msg::GetRPC(rpc_send)).unwrap();
rpc_recv.recv().unwrap()
};

let error_reporter = CSSErrorReporter;
let win = box Window {
eventtarget: EventTarget::new_inherited(),
script_chan: script_chan,
Expand Down Expand Up @@ -1288,8 +1296,8 @@ impl Window {
devtools_markers: DOMRefCell::new(HashSet::new()),
devtools_wants_updates: Cell::new(false),
webdriver_script_chan: DOMRefCell::new(None),

ignore_further_async_events: Arc::new(AtomicBool::new(false)),
error_reporter: error_reporter
};

WindowBinding::Wrap(runtime.cx(), win)
Expand Down
2 changes: 2 additions & 0 deletions components/script/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern crate log;
extern crate profile_traits;
#[macro_use]
extern crate style;
extern crate style_traits;
#[macro_use]
extern crate util;
extern crate angle;
Expand Down Expand Up @@ -90,6 +91,7 @@ mod mem;
mod network_listener;
pub mod page;
pub mod parse;
pub mod reporter;
#[allow(unsafe_code)]
pub mod script_task;
pub mod textinput;
Expand Down
25 changes: 25 additions & 0 deletions components/script/reporter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use cssparser::{Parser, SourcePosition};
use log;
use style_traits::ParseErrorReporter;

#[derive(JSTraceable, HeapSizeOf)]
pub struct CSSErrorReporter;

impl ParseErrorReporter for CSSErrorReporter {
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str) {
if log_enabled!(log::LogLevel::Info) {
let location = input.source_location(position);
// TODO eventually this will got into a "web console" or something.
info!("{}:{} {}", location.line, location.column, message)
}
}

fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
let error_reporter = box CSSErrorReporter;
return error_reporter;
}
}
2 changes: 2 additions & 0 deletions components/servo/Cargo.lock

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

6 changes: 5 additions & 1 deletion components/style/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@
use cssparser::{Parser, SourcePosition};
use log;
use selectors::parser::ParserContext as SelectorParserContext;
use style_traits::ParseErrorReporter;
use stylesheets::Origin;
use url::{Url, UrlParser};

pub struct ParserContext<'a> {
pub stylesheet_origin: Origin,
pub base_url: &'a Url,
pub selector_context: SelectorParserContext,
pub error_reporter: Box<ParseErrorReporter + Send>
}

impl<'a> ParserContext<'a> {
pub fn new(stylesheet_origin: Origin, base_url: &'a Url) -> ParserContext<'a> {
pub fn new(stylesheet_origin: Origin, base_url: &'a Url, error_reporter: Box<ParseErrorReporter + Send>)
-> ParserContext<'a> {
let mut selector_context = SelectorParserContext::new();
selector_context.in_user_agent_stylesheet = stylesheet_origin == Origin::UserAgent;
ParserContext {
stylesheet_origin: stylesheet_origin,
base_url: base_url,
selector_context: selector_context,
error_reporter: error_reporter,
}
}
}
Expand Down

0 comments on commit f5ef2f4

Please sign in to comment.