Skip to content

Commit

Permalink
Store HTMLIFrameElement sandbox attr as TokenList
Browse files Browse the repository at this point in the history
Fixes servo#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 (servo#1717).
  • Loading branch information
jimrhoskins committed Jan 9, 2015
1 parent 43e34d6 commit e8036ac
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions components/script/dom/htmliframeelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> {

fn SetSandbox(self, sandbox: DOMString) {
let element: JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute(&atom!("sandbox"), sandbox);
element.set_tokenlist_attribute(&atom!("sandbox"), sandbox);
}

fn GetContentWindow(self) -> Option<Temporary<Window>> {
Expand Down Expand Up @@ -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));
},
Expand Down

1 comment on commit e8036ac

@jdm
Copy link

@jdm jdm commented on e8036ac Jan 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+, looks good!

Please sign in to comment.