servo: Merge #11720 - Fix the type of HTMLIFrameElement.sandbox (from canaltinova:sandbox); r=nox
authorNazım Can Altınova <canaltinova@gmail.com>
Sat, 11 Jun 2016 23:40:11 -0500
changeset 339066 27025784b670960b6673e82bd5f21ecddad57f9a
parent 339065 291f43a19a85aa92d5a3bbb452ee7ac8013a915a
child 339067 a3f72bb20af7b58e2014e03e190d627ec916ec40
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
servo: Merge #11720 - Fix the type of HTMLIFrameElement.sandbox (from canaltinova:sandbox); r=nox <!-- Please describe your changes on the following line: --> --- <!-- 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 #11598 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 278c1a7da7626054be5899a6227c16f745f2d1a5
servo/components/script/dom/htmliframeelement.rs
servo/components/script/dom/webidls/HTMLIFrameElement.webidl
--- a/servo/components/script/dom/htmliframeelement.rs
+++ b/servo/components/script/dom/htmliframeelement.rs
@@ -14,22 +14,23 @@ use dom::bindings::codegen::Bindings::Br
 use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserShowModalPromptEventDetail;
 use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
 use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
 use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
 use dom::bindings::conversions::ToJSValConvertible;
 use dom::bindings::error::{Error, ErrorResult};
 use dom::bindings::global::GlobalRef;
 use dom::bindings::inheritance::Castable;
-use dom::bindings::js::{Root, LayoutJS};
+use dom::bindings::js::{JS, MutNullableHeap, Root, LayoutJS};
 use dom::bindings::reflector::Reflectable;
 use dom::bindings::str::DOMString;
 use dom::browsingcontext::BrowsingContext;
 use dom::customevent::CustomEvent;
 use dom::document::Document;
+use dom::domtokenlist::DOMTokenList;
 use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
 use dom::event::Event;
 use dom::eventtarget::EventTarget;
 use dom::htmlelement::HTMLElement;
 use dom::node::{Node, NodeDamage, UnbindContext, window_from_node, document_from_node};
 use dom::urlhelper::UrlHelper;
 use dom::virtualmethods::VirtualMethods;
 use dom::window::{ReflowReason, Window};
@@ -59,23 +60,24 @@ enum SandboxAllowance {
     AllowPopups = 0x20
 }
 
 #[dom_struct]
 pub struct HTMLIFrameElement {
     htmlelement: HTMLElement,
     pipeline_id: Cell<Option<PipelineId>>,
     subpage_id: Cell<Option<SubpageId>>,
-    sandbox: Cell<Option<u8>>,
+    sandbox: MutNullableHeap<JS<DOMTokenList>>,
+    sandbox_allowance: Cell<Option<u8>>,
     load_blocker: DOMRefCell<Option<LoadBlocker>>,
 }
 
 impl HTMLIFrameElement {
     pub fn is_sandboxed(&self) -> bool {
-        self.sandbox.get().is_some()
+        self.sandbox_allowance.get().is_some()
     }
 
     /// <https://html.spec.whatwg.org/multipage/#otherwise-steps-for-iframe-or-frame-elements>,
     /// step 1.
     fn get_url(&self) -> Url {
         let element = self.upcast::<Element>();
         element.get_attribute(&ns!(), &atom!("src")).and_then(|src| {
             let url = src.value();
@@ -189,17 +191,18 @@ impl HTMLIFrameElement {
 
     fn new_inherited(localName: Atom,
                      prefix: Option<DOMString>,
                      document: &Document) -> HTMLIFrameElement {
         HTMLIFrameElement {
             htmlelement: HTMLElement::new_inherited(localName, prefix, document),
             pipeline_id: Cell::new(None),
             subpage_id: Cell::new(None),
-            sandbox: Cell::new(None),
+            sandbox: Default::default(),
+            sandbox_allowance: Cell::new(None),
             load_blocker: DOMRefCell::new(None),
         }
     }
 
     #[allow(unrooted_must_root)]
     pub fn new(localName: Atom,
                prefix: Option<DOMString>,
                document: &Document) -> Root<HTMLIFrameElement> {
@@ -417,23 +420,18 @@ impl HTMLIFrameElementMethods for HTMLIF
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-iframe-src
     fn SetSrc(&self, src: DOMString) {
         self.upcast::<Element>().set_url_attribute(&atom!("src"), src)
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
-    fn Sandbox(&self) -> DOMString {
-        self.upcast::<Element>().get_string_attribute(&atom!("sandbox"))
-    }
-
-    // https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
-    fn SetSandbox(&self, sandbox: DOMString) {
-        self.upcast::<Element>().set_tokenlist_attribute(&atom!("sandbox"), sandbox);
+    fn Sandbox(&self) -> Root<DOMTokenList> {
+        self.sandbox.or_init(|| DOMTokenList::new(self.upcast::<Element>(), &atom!("sandbox")))
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow
     fn GetContentWindow(&self) -> Option<Root<BrowsingContext>> {
         match self.get_content_window() {
             Some(ref window) => Some(window.browsing_context()),
             None => None
         }
@@ -518,17 +516,17 @@ impl VirtualMethods for HTMLIFrameElemen
     fn super_type(&self) -> Option<&VirtualMethods> {
         Some(self.upcast::<HTMLElement>() as &VirtualMethods)
     }
 
     fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
         self.super_type().unwrap().attribute_mutated(attr, mutation);
         match attr.local_name() {
             &atom!("sandbox") => {
-                self.sandbox.set(mutation.new_value(attr).map(|value| {
+                self.sandbox_allowance.set(mutation.new_value(attr).map(|value| {
                     let mut modes = SandboxAllowance::AllowNothing as u8;
                     for token in value.as_tokens() {
                         modes |= match &*token.to_ascii_lowercase() {
                             "allow-same-origin" => SandboxAllowance::AllowSameOrigin,
                             "allow-forms" => SandboxAllowance::AllowForms,
                             "allow-pointer-lock" => SandboxAllowance::AllowPointerLock,
                             "allow-popups" => SandboxAllowance::AllowPopups,
                             "allow-scripts" => SandboxAllowance::AllowScripts,
--- a/servo/components/script/dom/webidls/HTMLIFrameElement.webidl
+++ b/servo/components/script/dom/webidls/HTMLIFrameElement.webidl
@@ -2,17 +2,18 @@
  * 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/. */
 
 // https://html.spec.whatwg.org/multipage/#htmliframeelement
 interface HTMLIFrameElement : HTMLElement {
            attribute DOMString src;
   //         attribute DOMString srcdoc;
   //         attribute DOMString name;
-           attribute DOMString sandbox;
+           [SameObject, PutForwards=value]
+           readonly attribute DOMTokenList sandbox;
   //         attribute boolean seamless;
   //         attribute boolean allowFullscreen;
            attribute DOMString width;
            attribute DOMString height;
   readonly attribute Document? contentDocument;
   readonly attribute WindowProxy? contentWindow;
 
   // also has obsolete members