Auto merge of #14646 - canaltinova:origin-clean, r=jdm

Support origins in CSSOM stylesheets

<!-- Please describe your changes on the following line: -->
I still need to pass the origin clean flag to constructors. `style::stylesheets::Stylesheet` has an origin field but I don't think that's relevant.
I can get href in htmllinkelement.rs like this:
```rust
let element = self.upcast::<Element>();
let href = element.get_string_attribute(&local_name!("href"));
```
But I'm not sure how to proceed after here.
@Manishearth any opinions?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14327 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14646)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-20 11:12:59 -08:00 committed by GitHub
commit 15c542d3a1
8 changed files with 103 additions and 9 deletions

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::Bindings::CSSStyleSheetBinding;
use dom::bindings::codegen::Bindings::CSSStyleSheetBinding::CSSStyleSheetMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::js::{JS, MutNullableJS, Root};
use dom::bindings::reflector::{reflect_dom_object, DomObject};
use dom::bindings::str::DOMString;
@ -13,6 +13,7 @@ use dom::cssrulelist::{CSSRuleList, RulesSource};
use dom::element::Element;
use dom::stylesheet::StyleSheet;
use dom::window::Window;
use std::cell::Cell;
use std::sync::Arc;
use style::stylesheets::Stylesheet as StyleStyleSheet;
@ -23,6 +24,7 @@ pub struct CSSStyleSheet {
rulelist: MutNullableJS<CSSRuleList>,
#[ignore_heap_size_of = "Arc"]
style_stylesheet: Arc<StyleStyleSheet>,
origin_clean: Cell<bool>,
}
impl CSSStyleSheet {
@ -36,6 +38,7 @@ impl CSSStyleSheet {
owner: JS::from_ref(owner),
rulelist: MutNullableJS::new(None),
style_stylesheet: stylesheet,
origin_clean: Cell::new(true),
}
}
@ -71,25 +74,34 @@ impl CSSStyleSheet {
pub fn style_stylesheet(&self) -> &StyleStyleSheet {
&self.style_stylesheet
}
pub fn set_origin_clean(&self, origin_clean: bool) {
self.origin_clean.set(origin_clean);
}
}
impl CSSStyleSheetMethods for CSSStyleSheet {
// https://drafts.csswg.org/cssom/#dom-cssstylesheet-cssrules
fn CssRules(&self) -> Root<CSSRuleList> {
// XXXManishearth check origin clean flag
// https://github.com/servo/servo/issues/14327
self.rulelist()
fn GetCssRules(&self) -> Fallible<Root<CSSRuleList>> {
if !self.origin_clean.get() {
return Err(Error::Security);
}
Ok(self.rulelist())
}
// https://drafts.csswg.org/cssom/#dom-cssstylesheet-insertrule
fn InsertRule(&self, rule: DOMString, index: u32) -> Fallible<u32> {
// XXXManishearth check origin clean flag
if !self.origin_clean.get() {
return Err(Error::Security);
}
self.rulelist().insert_rule(&rule, index, /* nested */ false)
}
// https://drafts.csswg.org/cssom/#dom-cssstylesheet-deleterule
fn DeleteRule(&self, index: u32) -> ErrorResult {
// XXXManishearth check origin clean flag
if !self.origin_clean.get() {
return Err(Error::Security);
}
self.rulelist().remove_rule(index)
}
}

View file

@ -319,6 +319,12 @@ impl StylesheetOwner for HTMLLinkElement {
None
}
fn set_origin_clean(&self, origin_clean: bool) {
if let Some(stylesheet) = self.get_cssom_stylesheet() {
stylesheet.set_origin_clean(origin_clean);
}
}
}
impl HTMLLinkElementMethods for HTMLLinkElement {

View file

@ -191,6 +191,12 @@ impl StylesheetOwner for HTMLStyleElement {
fn referrer_policy(&self) -> Option<ReferrerPolicy> {
None
}
fn set_origin_clean(&self, origin_clean: bool) {
if let Some(stylesheet) = self.get_cssom_stylesheet() {
stylesheet.set_origin_clean(origin_clean);
}
}
}

View file

@ -6,7 +6,7 @@
[Exposed=Window]
interface CSSStyleSheet : StyleSheet {
// readonly attribute CSSRule? ownerRule;
[SameObject] readonly attribute CSSRuleList cssRules;
[Throws, SameObject] readonly attribute CSSRuleList cssRules;
[Throws] unsigned long insertRule(DOMString rule, unsigned long index);
[Throws] void deleteRule(unsigned long index);
};