style: Better debugging for stylesheets and URLs.

Bug: 1470145
Reviewed-by: xidorn
MozReview-Commit-ID: FIcz2K1ZYX0
This commit is contained in:
Emilio Cobos Álvarez 2018-06-21 13:09:35 +02:00
parent 46e572a497
commit f564b32b75
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
6 changed files with 63 additions and 28 deletions

View file

@ -7,7 +7,6 @@
#![deny(missing_docs)]
use cssparser::{BasicParseErrorKind, ParseErrorKind, SourceLocation, Token};
use log;
use std::fmt;
use style_traits::ParseError;
use stylesheets::UrlExtraData;
@ -229,8 +228,10 @@ pub trait ParseErrorReporter {
/// This logging is silent by default, and can be enabled with a `RUST_LOG=style=info`
/// environment variable.
/// (See [`env_logger`](https://rust-lang-nursery.github.io/log/env_logger/).)
#[cfg(feature = "servo")]
pub struct RustLogReporter;
#[cfg(feature = "servo")]
impl ParseErrorReporter for RustLogReporter {
fn report_error(
&self,
@ -238,6 +239,7 @@ impl ParseErrorReporter for RustLogReporter {
location: SourceLocation,
error: ContextualParseError,
) {
use log;
if log_enabled!(log::Level::Info) {
info!(
"Url:\t{}\n{}:{} {}",

View file

@ -17,14 +17,25 @@ use media_queries::{Device, MediaList};
use properties::ComputedValues;
use selector_parser::SnapshotMap;
use servo_arc::Arc;
use std::fmt;
use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};
use stylesheets::{CssRule, Origin, StylesheetContents, StylesheetInDocument};
use stylist::Stylist;
/// Little wrapper to a Gecko style sheet.
#[derive(Debug, Eq, PartialEq)]
#[derive(Eq, PartialEq)]
pub struct GeckoStyleSheet(*const DomStyleSheet);
impl fmt::Debug for GeckoStyleSheet {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let contents = self.contents();
formatter.debug_struct("GeckoStyleSheet")
.field("origin", &contents.origin)
.field("url_data", &*contents.url_data.read())
.finish()
}
}
impl ToMediaListKey for ::gecko::data::GeckoStyleSheet {
fn to_media_list_key(&self) -> MediaListKey {
use std::mem;

View file

@ -6,7 +6,7 @@
use cssparser::Parser;
use gecko_bindings::bindings;
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
use gecko_bindings::structs::ServoBundledURI;
use gecko_bindings::structs::mozilla::css::URLValueData;
use gecko_bindings::structs::root::{RustString, nsStyleImageRequest};
use gecko_bindings::structs::root::mozilla::css::{ImageValue, URLValue};
@ -17,6 +17,7 @@ use parser::{Parse, ParserContext};
use servo_arc::{Arc, RawOffsetArc};
use std::fmt::{self, Write};
use std::mem;
use stylesheets::UrlExtraData;
use style_traits::{CssWriter, ParseError, ToCss};
use values::computed::{Context, ToComputedValue};
@ -32,7 +33,7 @@ pub struct CssUrl {
/// The URL extra data.
#[css(skip)]
pub extra_data: RefPtr<URLExtraData>,
pub extra_data: UrlExtraData,
}
impl CssUrl {
@ -58,7 +59,7 @@ impl CssUrl {
&url.mString as *const _ as *const RawOffsetArc<String>;
CssUrl {
serialization: Arc::from_raw_offset((*arc_type).clone()),
extra_data: url.mExtraData.to_safe(),
extra_data: UrlExtraData(url.mExtraData.to_safe()),
}
}
@ -88,7 +89,7 @@ impl CssUrl {
let arc_offset = Arc::into_raw_offset(self.serialization.clone());
ServoBundledURI {
mURLString: unsafe { mem::transmute::<_, RawOffsetArc<RustString>>(arc_offset) },
mExtraData: self.extra_data.get(),
mExtraData: self.extra_data.0.get(),
}
}
}

View file

@ -78,15 +78,6 @@ impl<T: RefCounted> RefPtr<T> {
ret
}
/// Create a reference to RefPtr from a reference to pointer.
///
/// The pointer must be valid and non null.
///
/// This method doesn't touch refcount.
pub unsafe fn from_ptr_ref(ptr: &*mut T) -> &Self {
mem::transmute(ptr)
}
/// Produces an FFI-compatible RefPtr that can be stored in style structs.
///
/// structs::RefPtr does not have a destructor, so this may leak

View file

@ -61,22 +61,52 @@ pub type UrlExtraData = ::servo_url::ServoUrl;
/// Extra data that the backend may need to resolve url values.
#[cfg(feature = "gecko")]
pub type UrlExtraData =
::gecko_bindings::sugar::refptr::RefPtr<::gecko_bindings::structs::URLExtraData>;
#[derive(Clone, PartialEq)]
pub struct UrlExtraData(
pub ::gecko_bindings::sugar::refptr::RefPtr<::gecko_bindings::structs::URLExtraData>
);
#[cfg(feature = "gecko")]
impl UrlExtraData {
/// Returns a string for the url.
///
/// Unimplemented currently.
pub fn as_str(&self) -> &str {
// TODO
"(stylo: not supported)"
/// True if this URL scheme is chrome.
#[inline]
pub fn is_chrome(&self) -> bool {
self.0.mIsChrome
}
/// True if this URL scheme is chrome.
pub fn is_chrome(&self) -> bool {
self.mIsChrome
/// Create a reference to this `UrlExtraData` from a reference to pointer.
///
/// The pointer must be valid and non null.
///
/// This method doesn't touch refcount.
#[inline]
pub unsafe fn from_ptr_ref(ptr: &*mut ::gecko_bindings::structs::URLExtraData) -> &Self {
::std::mem::transmute(ptr)
}
}
#[cfg(feature = "gecko")]
impl fmt::Debug for UrlExtraData {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use gecko_bindings::{structs, bindings};
struct DebugURI(*mut structs::nsIURI);
impl fmt::Debug for DebugURI {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use nsstring::nsCString;
let mut spec = nsCString::new();
unsafe {
bindings::Gecko_nsIURI_Debug(self.0, &mut spec);
}
spec.fmt(formatter)
}
}
formatter.debug_struct("URLExtraData")
.field("is_chrome", &self.is_chrome())
.field("base", &DebugURI(self.0.mBaseURI.raw::<structs::nsIURI>()))
.field("referrer", &DebugURI(self.0.mReferrer.raw::<structs::nsIURI>()))
.finish()
}
}

View file

@ -176,7 +176,7 @@ macro_rules! rule_filter {
}
/// A trait to represent a given stylesheet in a document.
pub trait StylesheetInDocument {
pub trait StylesheetInDocument : ::std::fmt::Debug {
/// Get the stylesheet origin.
fn origin(&self, guard: &SharedRwLockReadGuard) -> Origin;
@ -263,7 +263,7 @@ impl StylesheetInDocument for Stylesheet {
/// A simple wrapper over an `Arc<Stylesheet>`, with pointer comparison, and
/// suitable for its use in a `StylesheetSet`.
#[derive(Clone)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
pub struct DocumentStyleSheet(
#[cfg_attr(feature = "servo", ignore_malloc_size_of = "Arc")] pub Arc<Stylesheet>,