Defined new trait ParseErrorReporter and added error_reporter member to ParserContext

This commit is contained in:
GauriGNaik 2015-10-26 11:31:28 -04:00 committed by Josh Matthews
parent 8efc954531
commit 996e9e06b2
24 changed files with 194 additions and 69 deletions

View file

@ -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
@ -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 {

View file

@ -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};
@ -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);

View file

@ -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();

View file

@ -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));

View file

@ -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};
@ -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;
@ -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 {
@ -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
@ -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,
@ -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)