From e8036accd6b4c2d5c3e94ca7e304492cc2ec23af Mon Sep 17 00:00:00 2001 From: Jim Hoskins Date: Fri, 9 Jan 2015 11:04:38 -0800 Subject: [PATCH] Store HTMLIFrameElement sandbox attr as TokenList Fixes #3758 Store the sandbox attribute of HTMLIFrameElement as a TokenList internally. Use .tokens() to iterate over the tokens instead of splitting on the string value. The external interface for sandbox remains a DOMString, which will need to be fixed when DOMSettableTokenList is implemented (#1717). --- components/script/dom/htmliframeelement.rs | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index aeb480bdfbf5f..683c18c678a36 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -167,7 +167,7 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { fn SetSandbox(self, sandbox: DOMString) { let element: JSRef = ElementCast::from_ref(self); - element.set_string_attribute(&atom!("sandbox"), sandbox); + element.set_tokenlist_attribute(&atom!("sandbox"), sandbox); } fn GetContentWindow(self) -> Option> { @@ -217,16 +217,18 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { match attr.local_name() { &atom!("sandbox") => { let mut modes = SandboxAllowance::AllowNothing as u8; - for word in attr.value().as_slice().split(' ') { - modes |= match word.to_ascii_lower().as_slice() { - "allow-same-origin" => SandboxAllowance::AllowSameOrigin, - "allow-forms" => SandboxAllowance::AllowForms, - "allow-pointer-lock" => SandboxAllowance::AllowPointerLock, - "allow-popups" => SandboxAllowance::AllowPopups, - "allow-scripts" => SandboxAllowance::AllowScripts, - "allow-top-navigation" => SandboxAllowance::AllowTopNavigation, - _ => SandboxAllowance::AllowNothing - } as u8; + if let Some(ref tokens) = attr.value().tokens() { + for token in tokens.iter() { + modes |= match token.as_slice().to_ascii_lower().as_slice() { + "allow-same-origin" => SandboxAllowance::AllowSameOrigin, + "allow-forms" => SandboxAllowance::AllowForms, + "allow-pointer-lock" => SandboxAllowance::AllowPointerLock, + "allow-popups" => SandboxAllowance::AllowPopups, + "allow-scripts" => SandboxAllowance::AllowScripts, + "allow-top-navigation" => SandboxAllowance::AllowTopNavigation, + _ => SandboxAllowance::AllowNothing + } as u8; + } } self.sandbox.set(Some(modes)); },