mirror of
https://github.com/servo/servo.git
synced 2025-06-18 22:34:30 +01:00
Make sandboxed iframes run with different script tasks.
This commit is contained in:
parent
25a3d4a93f
commit
9640324721
9 changed files with 123 additions and 22 deletions
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use dom::bindings::utils::{DOMString, null_string, ErrorResult};
|
||||
use dom::bindings::utils::{DOMString, null_string, ErrorResult, str};
|
||||
use dom::document::AbstractDocument;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::windowproxy::WindowProxy;
|
||||
|
@ -11,14 +11,26 @@ use geom::rect::Rect;
|
|||
|
||||
use servo_msg::constellation_msg::{ConstellationChan, FrameRectMsg, PipelineId, SubpageId};
|
||||
|
||||
use std::ascii::StrAsciiExt;
|
||||
use std::comm::ChanOne;
|
||||
use extra::url::Url;
|
||||
use std::util::replace;
|
||||
|
||||
enum SandboxAllowance {
|
||||
AllowNothing = 0x00,
|
||||
AllowSameOrigin = 0x01,
|
||||
AllowTopNavigation = 0x02,
|
||||
AllowForms = 0x04,
|
||||
AllowScripts = 0x08,
|
||||
AllowPointerLock = 0x10,
|
||||
AllowPopups = 0x20
|
||||
}
|
||||
|
||||
pub struct HTMLIFrameElement {
|
||||
parent: HTMLElement,
|
||||
frame: Option<Url>,
|
||||
size: Option<IFrameSize>,
|
||||
sandbox: Option<u8>
|
||||
}
|
||||
|
||||
struct IFrameSize {
|
||||
|
@ -39,6 +51,11 @@ impl IFrameSize {
|
|||
}
|
||||
}
|
||||
|
||||
impl HTMLIFrameElement {
|
||||
pub fn is_sandboxed(&self) -> bool {
|
||||
self.sandbox.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLIFrameElement {
|
||||
pub fn Src(&self) -> DOMString {
|
||||
|
@ -63,10 +80,32 @@ impl HTMLIFrameElement {
|
|||
}
|
||||
|
||||
pub fn Sandbox(&self) -> DOMString {
|
||||
null_string
|
||||
self.parent.parent.GetAttribute(&str(~"sandbox"))
|
||||
}
|
||||
|
||||
pub fn SetSandbox(&self, _sandbox: &DOMString) {
|
||||
pub fn SetSandbox(&mut self, sandbox: &DOMString) {
|
||||
let mut rv = Ok(());
|
||||
self.parent.parent.SetAttribute(&str(~"sandbox"), sandbox, &mut rv);
|
||||
}
|
||||
|
||||
pub fn AfterSetAttr(&mut self, name: &DOMString, value: &DOMString) {
|
||||
let name = name.to_str();
|
||||
if "sandbox" == name {
|
||||
let mut modes = AllowNothing as u8;
|
||||
let words = value.to_str();
|
||||
for word in words.split_iter(' ') {
|
||||
modes |= match word.to_ascii_lower().as_slice() {
|
||||
"allow-same-origin" => AllowSameOrigin,
|
||||
"allow-forms" => AllowForms,
|
||||
"allow-pointer-lock" => AllowPointerLock,
|
||||
"allow-popups" => AllowPopups,
|
||||
"allow-scripts" => AllowScripts,
|
||||
"allow-top-navigation" => AllowTopNavigation,
|
||||
_ => AllowNothing
|
||||
} as u8;
|
||||
}
|
||||
self.sandbox = Some(modes);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn AllowFullscreen(&self) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue