Skip to content

Commit

Permalink
Defined new trait ParseErrorReporter and added error_reporter member …
Browse files Browse the repository at this point in the history
…to ParserContext
  • Loading branch information
GauriGNaik committed Nov 7, 2015
1 parent 285e29c commit f8cda20
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 63 deletions.
3 changes: 3 additions & 0 deletions components/layout/Cargo.toml
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
10 changes: 6 additions & 4 deletions components/layout/css/matching.rs
Expand Up @@ -12,6 +12,7 @@ use data::LayoutDataWrapper;
use incremental::{self, RestyleDamage};
use script::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId};
use script::layout_interface::Animation;
use script::reporter::CSSErrorReporter;
use selectors::bloom::BloomFilter;
use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes};
use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
Expand All @@ -27,6 +28,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 @@ -453,7 +455,7 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
}
}
}

let error_reporter = CSSErrorReporter;
let mut this_style;
let cacheable;
match parent_style {
Expand All @@ -467,16 +469,16 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
applicable_declarations,
shareable,
Some(&***parent_style),
cached_computed_values);
cached_computed_values, error_reporter.clone());
cacheable = is_cacheable;
this_style = the_style
}
None => {
let (the_style, is_cacheable) = cascade(layout_context.screen_size,
let (the_style, is_cacheable) = cascade(layout_context.screen_size,
applicable_declarations,
shareable,
None,
None);
None, error_reporter.clone());
cacheable = is_cacheable;
this_style = the_style
}
Expand Down
14 changes: 10 additions & 4 deletions components/layout/layout_task.rs
Expand Up @@ -58,6 +58,7 @@ use script::layout_interface::Animation;
use script::layout_interface::{LayoutChan, LayoutRPC, OffsetParentResponse};
use script::layout_interface::{Msg, NewLayoutTaskInfo, Reflow, ReflowGoal, ReflowQueryType};
use script::layout_interface::{ScriptLayoutChan, ScriptReflow, TrustedNodeAddress};
use script::reporter::CSSErrorReporter;
use script_traits::StylesheetLoadResponder;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, OpaqueScriptLayoutChannel};
use selectors::parser::PseudoElement;
Expand All @@ -81,6 +82,7 @@ use style::selector_matching::Stylist;
use style::stylesheets::{CSSRule, CSSRuleIteratorExt, Origin, Stylesheet};
use style::values::AuExtensionMethods;
use style::viewport::ViewportRule;
use style_traits::ParseErrorReporter;
use url::Url;
use util::geometry::{MAX_RECT, ZERO_POINT};
use util::ipc::OptionalIpcSender;
Expand Down Expand Up @@ -237,6 +239,7 @@ pub struct LayoutTask {
///
/// All the other elements of this struct are read-only.
pub rw_data: Arc<Mutex<LayoutTaskData>>,
pub error_reporter: CSSErrorReporter,
}

impl LayoutTaskFactory for LayoutTask {
Expand Down Expand Up @@ -372,8 +375,8 @@ impl LayoutTask {
ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_image_cache_receiver);

let (font_cache_sender, font_cache_receiver) = channel();

let stylist = box Stylist::new(device);
let error_reporter = CSSErrorReporter;
let stylist = box Stylist::new(device, error_reporter.clone());
let outstanding_web_fonts_counter = Arc::new(AtomicUsize::new(0));
for user_or_user_agent_stylesheet in stylist.stylesheets() {
add_font_face_rules(user_or_user_agent_stylesheet,
Expand Down Expand Up @@ -426,6 +429,7 @@ impl LayoutTask {
epoch: Epoch(0),
outstanding_web_fonts: outstanding_web_fonts_counter,
})),
error_reporter: CSSErrorReporter,
}
}

Expand Down Expand Up @@ -760,11 +764,12 @@ impl LayoutTask {
let protocol_encoding_label = metadata.charset.as_ref().map(|s| &**s);
let final_url = metadata.final_url;

let error_reporter = CSSErrorReporter;
let sheet = Stylesheet::from_bytes_iter(iter,
final_url,
protocol_encoding_label,
Some(environment_encoding),
Origin::Author);
Origin::Author, error_reporter.clone());

//TODO: mark critical subresources as blocking load as well (#5974)
self.script_chan.send(ConstellationControlMsg::StylesheetLoadComplete(self.id,
Expand Down Expand Up @@ -813,7 +818,8 @@ impl LayoutTask {
possibly_locked_rw_data:
&mut Option<MutexGuard<'a, LayoutTaskData>>) {
let mut rw_data = self.lock_rw_data(possibly_locked_rw_data);
rw_data.stylist.add_quirks_mode_stylesheet();
let error_reporter = CSSErrorReporter;
rw_data.stylist.add_quirks_mode_stylesheet(error_reporter.clone());
LayoutTask::return_rw_data(possibly_locked_rw_data, rw_data);
}

Expand Down
1 change: 1 addition & 0 deletions components/layout/lib.rs
Expand Up @@ -53,6 +53,7 @@ extern crate serde_json;
extern crate smallvec;
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
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
4 changes: 3 additions & 1 deletion components/script/dom/cssstyledeclaration.rs
Expand Up @@ -18,6 +18,7 @@ use std::cell::Ref;
use string_cache::Atom;
use style::properties::PropertyDeclaration;
use style::properties::{is_supported_property, longhands_from_shorthand, 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 @@ -216,7 +217,8 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {

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

// Step 7
let declarations = if let Ok(declarations) = declarations {
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/element.rs
Expand Up @@ -1494,12 +1494,14 @@ impl VirtualMethods for Element {
self.super_type().unwrap().attribute_mutated(attr, mutation);
let node = self.upcast::<Node>();
let doc = node.owner_doc();
let win = window_from_node(self);
let error_reporter = win.css_error_reporter();
let damage = match attr.local_name() {
&atom!(style) => {
// 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())
parse_style_attribute(&value, &doc.base_url(), error_reporter)
});
NodeDamage::NodeStyleDamaged
},
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/htmlstyleelement.rs
Expand Up @@ -47,6 +47,7 @@ impl HTMLStyleElement {
let win = window_from_node(node);
let win = win.r();
let url = win.get_url();
let error_reporter = win.css_error_reporter();

let mq_attribute = element.get_attribute(&ns!(""), &atom!("media"));
let mq_str = match mq_attribute {
Expand All @@ -57,7 +58,7 @@ impl HTMLStyleElement {
let media = parse_media_query_list(&mut css_parser);

let data = node.GetTextContent().expect("Element.textContent must be a string");
let sheet = Stylesheet::from_str(&data, url, Origin::Author);
let sheet = Stylesheet::from_str(&data, url, Origin::Author, error_reporter);
let LayoutChan(ref layout_chan) = win.layout_chan();
layout_chan.send(Msg::AddStylesheet(sheet, media)).unwrap();
}
Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/window.rs
Expand Up @@ -51,6 +51,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};
use script_task::{SendableMainThreadScriptChan, MainThreadScriptChan, MainThreadTimerEventChan};
Expand All @@ -68,6 +69,7 @@ use std::sync::Arc;
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, TimerCallback};
use url::Url;
Expand Down Expand Up @@ -1284,6 +1286,10 @@ impl Window {

WindowBinding::Wrap(runtime.cx(), win)
}
pub fn css_error_reporter(&self) -> Box<ParseErrorReporter + Send> {
let error_reporter = Box::new(CSSErrorReporter);
return error_reporter;
}
}

fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions components/script/lib.rs
Expand Up @@ -44,6 +44,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 @@ -92,6 +93,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
23 changes: 23 additions & 0 deletions components/script/reporter.rs
@@ -0,0 +1,23 @@
/* 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;

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> {
let error_reporter = Box::new(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.

22 changes: 13 additions & 9 deletions components/style/parser.rs
Expand Up @@ -6,25 +6,29 @@
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> {
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,
}
}
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 f8cda20

Please sign in to comment.