Auto merge of #11214 - farodin91:windowproxy, r=jdm

Support WindowProxy return values in bindings

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 --faster` does not report any errors
- [x] These changes fix #10965 (github issue number if applicable).

Either:
- [ ] 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.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11214)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-10 10:53:35 -05:00 committed by GitHub
commit 08a55e2951
11 changed files with 69 additions and 61 deletions

View file

@ -23,6 +23,12 @@ DOMInterfaces = {
'URL': { 'URL': {
'weakReferenceable': True, 'weakReferenceable': True,
},
'WindowProxy' : {
'nativeType': 'BrowsingContext',
'path': 'dom::browsingcontext::BrowsingContext',
'register': False,
} }
} }

View file

@ -1695,7 +1695,7 @@ class CGImports(CGWrapper):
""" """
Generates the appropriate import/use statements. Generates the appropriate import/use statements.
""" """
def __init__(self, child, descriptors, callbacks, imports, ignored_warnings=None): def __init__(self, child, descriptors, callbacks, imports, config, ignored_warnings=None):
""" """
Adds a set of imports. Adds a set of imports.
""" """
@ -1756,7 +1756,11 @@ class CGImports(CGWrapper):
for c in callbacks: for c in callbacks:
types += relatedTypesForSignatures(c) types += relatedTypesForSignatures(c)
imports += ['dom::types::%s' % getIdentifier(t).name for t in types if isImportable(t)] descriptorProvider = config.getDescriptorProvider()
for t in types:
if isImportable(t):
descriptor = descriptorProvider.getDescriptor(getIdentifier(t).name)
imports += ['%s' % descriptor.path]
statements = [] statements = []
if len(ignored_warnings) > 0: if len(ignored_warnings) > 0:
@ -2090,7 +2094,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
# Sort unionStructs by key, retrieve value # Sort unionStructs by key, retrieve value
unionStructs = (i[1] for i in sorted(unionStructs.items(), key=operator.itemgetter(0))) unionStructs = (i[1] for i in sorted(unionStructs.items(), key=operator.itemgetter(0)))
return CGImports(CGList(unionStructs, "\n\n"), [], [], imports, ignored_warnings=[]) return CGImports(CGList(unionStructs, "\n\n"), [], [], imports, config, ignored_warnings=[])
class Argument(): class Argument():
@ -5460,7 +5464,8 @@ class CGBindingRoot(CGThing):
# (hence hasInterfaceObject=False). # (hence hasInterfaceObject=False).
descriptors.extend(config.getDescriptors(webIDLFile=webIDLFile, descriptors.extend(config.getDescriptors(webIDLFile=webIDLFile,
hasInterfaceObject=False, hasInterfaceObject=False,
isCallback=False)) isCallback=False,
register=True))
dictionaries = config.getDictionaries(webIDLFile=webIDLFile) dictionaries = config.getDictionaries(webIDLFile=webIDLFile)
@ -5588,6 +5593,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::str::{ByteString, DOMString, USVString}', 'dom::bindings::str::{ByteString, DOMString, USVString}',
'dom::bindings::trace::RootedVec', 'dom::bindings::trace::RootedVec',
'dom::bindings::weakref::{DOM_WEAK_SLOT, WeakBox, WeakReferenceable}', 'dom::bindings::weakref::{DOM_WEAK_SLOT, WeakBox, WeakReferenceable}',
'dom::browsingcontext::BrowsingContext',
'mem::heap_size_of_raw_self_and_children', 'mem::heap_size_of_raw_self_and_children',
'libc', 'libc',
'util::prefs', 'util::prefs',
@ -5602,7 +5608,7 @@ class CGBindingRoot(CGThing):
'std::rc::Rc', 'std::rc::Rc',
'std::default::Default', 'std::default::Default',
'std::ffi::CString', 'std::ffi::CString',
]) ], config)
# Add the auto-generated comment. # Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@ -6278,7 +6284,7 @@ class GlobalGenRoots():
'dom::bindings::codegen', 'dom::bindings::codegen',
'dom::bindings::codegen::PrototypeList::Proxies', 'dom::bindings::codegen::PrototypeList::Proxies',
'libc', 'libc',
], ignored_warnings=[]) ], config, ignored_warnings=[])
@staticmethod @staticmethod
def InterfaceTypes(config): def InterfaceTypes(config):

View file

@ -173,6 +173,7 @@ class Descriptor(DescriptorProvider):
# Read the desc, and fill in the relevant defaults. # Read the desc, and fill in the relevant defaults.
ifaceName = self.interface.identifier.name ifaceName = self.interface.identifier.name
typeName = desc.get('nativeType', ifaceName)
# Callback types do not use JS smart pointers, so we should not use the # Callback types do not use JS smart pointers, so we should not use the
# built-in rooting mechanisms for them. # built-in rooting mechanisms for them.
@ -184,12 +185,13 @@ class Descriptor(DescriptorProvider):
self.nativeType = ty self.nativeType = ty
else: else:
self.needsRooting = True self.needsRooting = True
self.returnType = "Root<%s>" % ifaceName self.returnType = "Root<%s>" % typeName
self.argumentType = "&%s" % ifaceName self.argumentType = "&%s" % typeName
self.nativeType = "*const %s" % ifaceName self.nativeType = "*const %s" % typeName
self.concreteType = ifaceName self.concreteType = typeName
self.register = desc.get('register', True) self.register = desc.get('register', True)
self.path = desc.get('path', 'dom::types::%s' % typeName)
self.outerObjectHook = desc.get('outerObjectHook', 'None') self.outerObjectHook = desc.get('outerObjectHook', 'None')
self.proxy = False self.proxy = False
self.weakReferenceable = desc.get('weakReferenceable', False) self.weakReferenceable = desc.get('weakReferenceable', False)

View file

@ -22,6 +22,7 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::js::{Root, LayoutJS}; use dom::bindings::js::{Root, LayoutJS};
use dom::bindings::reflector::Reflectable; use dom::bindings::reflector::Reflectable;
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::browsingcontext::BrowsingContext;
use dom::customevent::CustomEvent; use dom::customevent::CustomEvent;
use dom::document::Document; use dom::document::Document;
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers}; use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
@ -256,6 +257,15 @@ impl HTMLIFrameElement {
} }
} }
pub fn get_content_window(&self) -> Option<Root<Window>> {
self.subpage_id.get().and_then(|subpage_id| {
let window = window_from_node(self);
let window = window.r();
let browsing_context = window.browsing_context();
browsing_context.find_child_by_subpage(subpage_id)
})
}
} }
pub trait HTMLIFrameElementLayoutMethods { pub trait HTMLIFrameElementLayoutMethods {
@ -422,18 +432,16 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
} }
// https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow // https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow
fn GetContentWindow(&self) -> Option<Root<Window>> { fn GetContentWindow(&self) -> Option<Root<BrowsingContext>> {
self.subpage_id.get().and_then(|subpage_id| { match self.get_content_window() {
let window = window_from_node(self); Some(ref window) => Some(window.browsing_context()),
let window = window.r(); None => None
let browsing_context = window.browsing_context(); }
browsing_context.find_child_by_subpage(subpage_id)
})
} }
// https://html.spec.whatwg.org/multipage/#dom-iframe-contentdocument // https://html.spec.whatwg.org/multipage/#dom-iframe-contentdocument
fn GetContentDocument(&self) -> Option<Root<Document>> { fn GetContentDocument(&self) -> Option<Root<Document>> {
self.GetContentWindow().and_then(|window| { self.get_content_window().and_then(|window| {
// FIXME(#10964): this should use the Document's origin and the // FIXME(#10964): this should use the Document's origin and the
// origin of the incumbent settings object. // origin of the incumbent settings object.
let self_url = self.get_url(); let self_url = self.get_url();

View file

@ -159,16 +159,16 @@ interface BrowserElementPrivileged {
// unsigned long count, // unsigned long count,
// unsigned long modifiers); // unsigned long modifiers);
[Func="Window::global_is_mozbrowser", Throws] [Func="::dom::window::Window::global_is_mozbrowser", Throws]
void goBack(); void goBack();
[Func="Window::global_is_mozbrowser", Throws] [Func="::dom::window::Window::global_is_mozbrowser", Throws]
void goForward(); void goForward();
[Func="Window::global_is_mozbrowser", Throws] [Func="::dom::window::Window::global_is_mozbrowser", Throws]
void reload(optional boolean hardReload = false); void reload(optional boolean hardReload = false);
[Func="Window::global_is_mozbrowser", Throws] [Func="::dom::window::Window::global_is_mozbrowser", Throws]
void stop(); void stop();
//[Throws, //[Throws,

View file

@ -13,8 +13,7 @@ interface HTMLIFrameElement : HTMLElement {
attribute DOMString width; attribute DOMString width;
attribute DOMString height; attribute DOMString height;
readonly attribute Document? contentDocument; readonly attribute Document? contentDocument;
//readonly attribute WindowProxy? contentWindow; readonly attribute WindowProxy? contentWindow;
readonly attribute Window? contentWindow;
// also has obsolete members // also has obsolete members
}; };
@ -31,7 +30,7 @@ partial interface HTMLIFrameElement {
}; };
partial interface HTMLIFrameElement { partial interface HTMLIFrameElement {
[Func="Window::global_is_mozbrowser"] [Func="::dom::window::Window::global_is_mozbrowser"]
attribute boolean mozbrowser; attribute boolean mozbrowser;
}; };

View file

@ -6,10 +6,8 @@
[PrimaryGlobal] [PrimaryGlobal]
/*sealed*/ interface Window : EventTarget { /*sealed*/ interface Window : EventTarget {
// the current browsing context // the current browsing context
//[Unforgeable] readonly attribute WindowProxy window; [Unforgeable] readonly attribute WindowProxy window;
//[Replaceable] readonly attribute WindowProxy self; [BinaryName="Self_", Replaceable] readonly attribute WindowProxy self;
readonly attribute Window window;
[BinaryName="Self_"] readonly attribute Window self;
[Unforgeable] readonly attribute Document document; [Unforgeable] readonly attribute Document document;
// attribute DOMString name; // attribute DOMString name;
[/*PutForwards=href, */Unforgeable] readonly attribute Location location; [/*PutForwards=href, */Unforgeable] readonly attribute Location location;
@ -28,14 +26,11 @@
//void blur(); //void blur();
// other browsing contexts // other browsing contexts
//[Replaceable] readonly attribute WindowProxy frames; [Replaceable] readonly attribute WindowProxy frames;
readonly attribute Window frames;
//[Replaceable] readonly attribute unsigned long length; //[Replaceable] readonly attribute unsigned long length;
//[Unforgeable] readonly attribute WindowProxy top; [Unforgeable] readonly attribute WindowProxy top;
readonly attribute Window top;
// attribute any opener; // attribute any opener;
//readonly attribute WindowProxy parent; readonly attribute WindowProxy parent;
readonly attribute Window parent;
readonly attribute Element? frameElement; readonly attribute Element? frameElement;
//WindowProxy open(optional DOMString url = "about:blank", optional DOMString target = "_blank", //WindowProxy open(optional DOMString url = "about:blank", optional DOMString target = "_blank",
// optional DOMString features = "", optional boolean replace = false); // optional DOMString features = "", optional boolean replace = false);
@ -65,6 +60,9 @@
Window implements GlobalEventHandlers; Window implements GlobalEventHandlers;
Window implements WindowEventHandlers; Window implements WindowEventHandlers;
[NoInterfaceObject]
interface WindowProxy {};
// https://html.spec.whatwg.org/multipage/#timers // https://html.spec.whatwg.org/multipage/#timers
[NoInterfaceObject/*, Exposed=Window,Worker*/] [NoInterfaceObject/*, Exposed=Window,Worker*/]
interface WindowTimers { interface WindowTimers {

View file

@ -558,32 +558,35 @@ impl WindowMethods for Window {
} }
// https://html.spec.whatwg.org/multipage/#dom-window // https://html.spec.whatwg.org/multipage/#dom-window
fn Window(&self) -> Root<Window> { fn Window(&self) -> Root<BrowsingContext> {
Root::from_ref(self) self.browsing_context()
} }
// https://html.spec.whatwg.org/multipage/#dom-self // https://html.spec.whatwg.org/multipage/#dom-self
fn Self_(&self) -> Root<Window> { fn Self_(&self) -> Root<BrowsingContext> {
self.Window() self.browsing_context()
} }
// https://html.spec.whatwg.org/multipage/#dom-frames // https://html.spec.whatwg.org/multipage/#dom-frames
fn Frames(&self) -> Root<Window> { fn Frames(&self) -> Root<BrowsingContext> {
self.Window() self.browsing_context()
} }
// https://html.spec.whatwg.org/multipage/#dom-parent // https://html.spec.whatwg.org/multipage/#dom-parent
fn Parent(&self) -> Root<Window> { fn Parent(&self) -> Root<BrowsingContext> {
self.parent().unwrap_or(self.Window()) match self.parent() {
Some(window) => window.browsing_context(),
None => self.Window()
}
} }
// https://html.spec.whatwg.org/multipage/#dom-top // https://html.spec.whatwg.org/multipage/#dom-top
fn Top(&self) -> Root<Window> { fn Top(&self) -> Root<BrowsingContext> {
let mut window = self.Window(); let mut window = Root::from_ref(self);
while let Some(parent) = window.parent() { while let Some(parent) = window.parent() {
window = parent; window = parent;
} }
window window.browsing_context()
} }
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/ // https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/

View file

@ -6,7 +6,6 @@ use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclar
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods; use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
@ -105,7 +104,7 @@ pub fn handle_get_frame_id(context: &BrowsingContext,
match find_node_by_unique_id(context, pipeline, x) { match find_node_by_unique_id(context, pipeline, x) {
Some(ref node) => { Some(ref node) => {
match node.downcast::<HTMLIFrameElement>() { match node.downcast::<HTMLIFrameElement>() {
Some(ref elem) => Ok(elem.GetContentWindow()), Some(ref elem) => Ok(elem.get_content_window()),
None => Err(()) None => Err(())
} }
}, },

View file

@ -297,15 +297,9 @@
[Window attribute: onwaiting] [Window attribute: onwaiting]
expected: FAIL expected: FAIL
[Window unforgeable attribute: window]
expected: FAIL
[Window unforgeable attribute: location] [Window unforgeable attribute: location]
expected: FAIL expected: FAIL
[Window unforgeable attribute: top]
expected: FAIL
[Window replaceable attribute: self] [Window replaceable attribute: self]
expected: FAIL expected: FAIL

View file

@ -5304,9 +5304,6 @@
[Window interface: attribute localStorage] [Window interface: attribute localStorage]
expected: FAIL expected: FAIL
[Window interface: window must have own property "window"]
expected: FAIL
[Window interface: window must inherit property "self" with the proper type (1)] [Window interface: window must inherit property "self" with the proper type (1)]
expected: FAIL expected: FAIL
@ -5358,9 +5355,6 @@
[Window interface: window must inherit property "length" with the proper type (19)] [Window interface: window must inherit property "length" with the proper type (19)]
expected: FAIL expected: FAIL
[Window interface: window must have own property "top"]
expected: FAIL
[Window interface: window must inherit property "opener" with the proper type (21)] [Window interface: window must inherit property "opener" with the proper type (21)]
expected: FAIL expected: FAIL
@ -9581,4 +9575,3 @@
[HTMLInputElement interface: createInput("button") must inherit property "useMap" with the proper type (57)] [HTMLInputElement interface: createInput("button") must inherit property "useMap" with the proper type (57)]
expected: FAIL expected: FAIL