mirror of
https://github.com/servo/servo.git
synced 2025-06-11 10:00:18 +00:00
Add contentDocument support for HTMLIFrameElement. Fixes #3808.
This commit is contained in:
parent
8cb2b922ef
commit
af30484f2a
5 changed files with 61 additions and 1 deletions
|
@ -6,6 +6,7 @@ use dom::attr::Attr;
|
|||
use dom::attr::AttrHelpers;
|
||||
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLIFrameElementDerived};
|
||||
use dom::bindings::js::{JSRef, Temporary, OptionalRootable};
|
||||
|
@ -16,6 +17,7 @@ use dom::element::AttributeHandlers;
|
|||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, NodeHelpers, ElementNodeTypeId, window_from_node};
|
||||
use dom::urlhelper::UrlHelper;
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom::window::Window;
|
||||
use page::IterablePage;
|
||||
|
@ -180,6 +182,22 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn GetContentDocument(self) -> Option<Temporary<Document>> {
|
||||
self.GetContentWindow().root().and_then(|window| {
|
||||
let self_url = match self.get_url() {
|
||||
Some(self_url) => self_url,
|
||||
None => return None,
|
||||
};
|
||||
let win_url = window_from_node(self).root().page().get_url();
|
||||
|
||||
if UrlHelper::SameOrigin(&self_url, &win_url) {
|
||||
Some(window.Document())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
||||
|
|
|
@ -27,4 +27,18 @@ impl UrlHelper {
|
|||
Some(ref hash) => format!("#{}", hash)
|
||||
}
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/browsers.html#same-origin
|
||||
pub fn SameOrigin(urlA: &Url, urlB: &Url) -> bool {
|
||||
if urlA.host() != urlB.host() {
|
||||
return false
|
||||
}
|
||||
if urlA.scheme != urlB.scheme {
|
||||
return false
|
||||
}
|
||||
if urlA.port() != urlB.port() {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ interface HTMLIFrameElement : HTMLElement {
|
|||
// attribute boolean allowFullscreen;
|
||||
// attribute DOMString width;
|
||||
// attribute DOMString height;
|
||||
//readonly attribute Document? contentDocument;
|
||||
readonly attribute Document? contentDocument;
|
||||
//readonly attribute WindowProxy? contentWindow;
|
||||
readonly attribute Window? contentWindow;
|
||||
|
||||
|
|
27
tests/content/test_iframe_contentDocument.html
Normal file
27
tests/content/test_iframe_contentDocument.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<script src="harness.js"></script>
|
||||
<title>Iframe contentDocument test.</title>
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="test_iframe_contentDocument_inner.html" id="iframe"></iframe>
|
||||
<script>
|
||||
waitForExplicitFinish();
|
||||
|
||||
var timeout = 100;
|
||||
var iframe = document.getElementById('iframe');
|
||||
function test_contentWindow() {
|
||||
if (!iframe.contentWindow) {
|
||||
// Iframe not loaded yet, try again.
|
||||
// No load event for iframe, insert bug number here.
|
||||
setTimeout(test_contentWindow, timeout);
|
||||
return;
|
||||
}
|
||||
is(iframe.contentDocument.getElementById('test').textContent, 'value');
|
||||
finish();
|
||||
}
|
||||
test_contentWindow();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
1
tests/content/test_iframe_contentDocument_inner.html
Normal file
1
tests/content/test_iframe_contentDocument_inner.html
Normal file
|
@ -0,0 +1 @@
|
|||
<html><body><div id="test">value</div></body></html>
|
Loading…
Add table
Add a link
Reference in a new issue