Skip to content

Commit

Permalink
Auto merge of #11214 - farodin91:windowproxy, r=jdm
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Jun 10, 2016
2 parents 2fb8525 + fda0119 commit 08a55e2
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 61 deletions.
6 changes: 6 additions & 0 deletions components/script/dom/bindings/codegen/Bindings.conf
Expand Up @@ -23,6 +23,12 @@ DOMInterfaces = {

'URL': {
'weakReferenceable': True,
},

'WindowProxy' : {
'nativeType': 'BrowsingContext',
'path': 'dom::browsingcontext::BrowsingContext',
'register': False,
}

}
18 changes: 12 additions & 6 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -1695,7 +1695,7 @@ class CGImports(CGWrapper):
"""
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.
"""
Expand Down Expand Up @@ -1756,7 +1756,11 @@ def getIdentifier(t):
for c in callbacks:
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 = []
if len(ignored_warnings) > 0:
Expand Down Expand Up @@ -2090,7 +2094,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
# Sort unionStructs by key, retrieve value
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():
Expand Down Expand Up @@ -5460,7 +5464,8 @@ def __init__(self, config, prefix, webIDLFile):
# (hence hasInterfaceObject=False).
descriptors.extend(config.getDescriptors(webIDLFile=webIDLFile,
hasInterfaceObject=False,
isCallback=False))
isCallback=False,
register=True))

dictionaries = config.getDictionaries(webIDLFile=webIDLFile)

Expand Down Expand Up @@ -5588,6 +5593,7 @@ def __init__(self, config, prefix, webIDLFile):
'dom::bindings::str::{ByteString, DOMString, USVString}',
'dom::bindings::trace::RootedVec',
'dom::bindings::weakref::{DOM_WEAK_SLOT, WeakBox, WeakReferenceable}',
'dom::browsingcontext::BrowsingContext',
'mem::heap_size_of_raw_self_and_children',
'libc',
'util::prefs',
Expand All @@ -5602,7 +5608,7 @@ def __init__(self, config, prefix, webIDLFile):
'std::rc::Rc',
'std::default::Default',
'std::ffi::CString',
])
], config)

# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
Expand Down Expand Up @@ -6278,7 +6284,7 @@ def RegisterBindings(config):
'dom::bindings::codegen',
'dom::bindings::codegen::PrototypeList::Proxies',
'libc',
], ignored_warnings=[])
], config, ignored_warnings=[])

@staticmethod
def InterfaceTypes(config):
Expand Down
10 changes: 6 additions & 4 deletions components/script/dom/bindings/codegen/Configuration.py
Expand Up @@ -173,6 +173,7 @@ def __init__(self, config, interface, desc):

# Read the desc, and fill in the relevant defaults.
ifaceName = self.interface.identifier.name
typeName = desc.get('nativeType', ifaceName)

# Callback types do not use JS smart pointers, so we should not use the
# built-in rooting mechanisms for them.
Expand All @@ -184,12 +185,13 @@ def __init__(self, config, interface, desc):
self.nativeType = ty
else:
self.needsRooting = True
self.returnType = "Root<%s>" % ifaceName
self.argumentType = "&%s" % ifaceName
self.nativeType = "*const %s" % ifaceName
self.returnType = "Root<%s>" % typeName
self.argumentType = "&%s" % typeName
self.nativeType = "*const %s" % typeName

self.concreteType = ifaceName
self.concreteType = typeName
self.register = desc.get('register', True)
self.path = desc.get('path', 'dom::types::%s' % typeName)
self.outerObjectHook = desc.get('outerObjectHook', 'None')
self.proxy = False
self.weakReferenceable = desc.get('weakReferenceable', False)
Expand Down
24 changes: 16 additions & 8 deletions components/script/dom/htmliframeelement.rs
Expand Up @@ -22,6 +22,7 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::js::{Root, LayoutJS};
use dom::bindings::reflector::Reflectable;
use dom::bindings::str::DOMString;
use dom::browsingcontext::BrowsingContext;
use dom::customevent::CustomEvent;
use dom::document::Document;
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -422,18 +432,16 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
}

// https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow
fn GetContentWindow(&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)
})
fn GetContentWindow(&self) -> Option<Root<BrowsingContext>> {
match self.get_content_window() {
Some(ref window) => Some(window.browsing_context()),
None => None
}
}

// https://html.spec.whatwg.org/multipage/#dom-iframe-contentdocument
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
// origin of the incumbent settings object.
let self_url = self.get_url();
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/webidls/BrowserElement.webidl
Expand Up @@ -159,16 +159,16 @@ interface BrowserElementPrivileged {
// unsigned long count,
// unsigned long modifiers);

[Func="Window::global_is_mozbrowser", Throws]
[Func="::dom::window::Window::global_is_mozbrowser", Throws]
void goBack();

[Func="Window::global_is_mozbrowser", Throws]
[Func="::dom::window::Window::global_is_mozbrowser", Throws]
void goForward();

[Func="Window::global_is_mozbrowser", Throws]
[Func="::dom::window::Window::global_is_mozbrowser", Throws]
void reload(optional boolean hardReload = false);

[Func="Window::global_is_mozbrowser", Throws]
[Func="::dom::window::Window::global_is_mozbrowser", Throws]
void stop();

//[Throws,
Expand Down
5 changes: 2 additions & 3 deletions components/script/dom/webidls/HTMLIFrameElement.webidl
Expand Up @@ -13,8 +13,7 @@ interface HTMLIFrameElement : HTMLElement {
attribute DOMString width;
attribute DOMString height;
readonly attribute Document? contentDocument;
//readonly attribute WindowProxy? contentWindow;
readonly attribute Window? contentWindow;
readonly attribute WindowProxy? contentWindow;

// also has obsolete members
};
Expand All @@ -31,7 +30,7 @@ partial interface HTMLIFrameElement {
};

partial interface HTMLIFrameElement {
[Func="Window::global_is_mozbrowser"]
[Func="::dom::window::Window::global_is_mozbrowser"]
attribute boolean mozbrowser;
};

Expand Down
18 changes: 8 additions & 10 deletions components/script/dom/webidls/Window.webidl
Expand Up @@ -6,10 +6,8 @@
[PrimaryGlobal]
/*sealed*/ interface Window : EventTarget {
// the current browsing context
//[Unforgeable] readonly attribute WindowProxy window;
//[Replaceable] readonly attribute WindowProxy self;
readonly attribute Window window;
[BinaryName="Self_"] readonly attribute Window self;
[Unforgeable] readonly attribute WindowProxy window;
[BinaryName="Self_", Replaceable] readonly attribute WindowProxy self;
[Unforgeable] readonly attribute Document document;
// attribute DOMString name;
[/*PutForwards=href, */Unforgeable] readonly attribute Location location;
Expand All @@ -28,14 +26,11 @@
//void blur();

// other browsing contexts
//[Replaceable] readonly attribute WindowProxy frames;
readonly attribute Window frames;
[Replaceable] readonly attribute WindowProxy frames;
//[Replaceable] readonly attribute unsigned long length;
//[Unforgeable] readonly attribute WindowProxy top;
readonly attribute Window top;
[Unforgeable] readonly attribute WindowProxy top;
// attribute any opener;
//readonly attribute WindowProxy parent;
readonly attribute Window parent;
readonly attribute WindowProxy parent;
readonly attribute Element? frameElement;
//WindowProxy open(optional DOMString url = "about:blank", optional DOMString target = "_blank",
// optional DOMString features = "", optional boolean replace = false);
Expand Down Expand Up @@ -65,6 +60,9 @@
Window implements GlobalEventHandlers;
Window implements WindowEventHandlers;

[NoInterfaceObject]
interface WindowProxy {};

// https://html.spec.whatwg.org/multipage/#timers
[NoInterfaceObject/*, Exposed=Window,Worker*/]
interface WindowTimers {
Expand Down
25 changes: 14 additions & 11 deletions components/script/dom/window.rs
Expand Up @@ -558,32 +558,35 @@ impl WindowMethods for Window {
}

// https://html.spec.whatwg.org/multipage/#dom-window
fn Window(&self) -> Root<Window> {
Root::from_ref(self)
fn Window(&self) -> Root<BrowsingContext> {
self.browsing_context()
}

// https://html.spec.whatwg.org/multipage/#dom-self
fn Self_(&self) -> Root<Window> {
self.Window()
fn Self_(&self) -> Root<BrowsingContext> {
self.browsing_context()
}

// https://html.spec.whatwg.org/multipage/#dom-frames
fn Frames(&self) -> Root<Window> {
self.Window()
fn Frames(&self) -> Root<BrowsingContext> {
self.browsing_context()
}

// https://html.spec.whatwg.org/multipage/#dom-parent
fn Parent(&self) -> Root<Window> {
self.parent().unwrap_or(self.Window())
fn Parent(&self) -> Root<BrowsingContext> {
match self.parent() {
Some(window) => window.browsing_context(),
None => self.Window()
}
}

// https://html.spec.whatwg.org/multipage/#dom-top
fn Top(&self) -> Root<Window> {
let mut window = self.Window();
fn Top(&self) -> Root<BrowsingContext> {
let mut window = Root::from_ref(self);
while let Some(parent) = window.parent() {
window = parent;
}
window
window.browsing_context()
}

// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/
Expand Down
3 changes: 1 addition & 2 deletions components/script/webdriver_handlers.rs
Expand Up @@ -6,7 +6,6 @@ use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclar
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
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::HTMLOptionElementBinding::HTMLOptionElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
Expand Down Expand Up @@ -105,7 +104,7 @@ pub fn handle_get_frame_id(context: &BrowsingContext,
match find_node_by_unique_id(context, pipeline, x) {
Some(ref node) => {
match node.downcast::<HTMLIFrameElement>() {
Some(ref elem) => Ok(elem.GetContentWindow()),
Some(ref elem) => Ok(elem.get_content_window()),
None => Err(())
}
},
Expand Down
Expand Up @@ -297,15 +297,9 @@
[Window attribute: onwaiting]
expected: FAIL

[Window unforgeable attribute: window]
expected: FAIL

[Window unforgeable attribute: location]
expected: FAIL

[Window unforgeable attribute: top]
expected: FAIL

[Window replaceable attribute: self]
expected: FAIL

Expand Down
7 changes: 0 additions & 7 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Expand Up @@ -5304,9 +5304,6 @@
[Window interface: attribute localStorage]
expected: FAIL

[Window interface: window must have own property "window"]
expected: FAIL

[Window interface: window must inherit property "self" with the proper type (1)]
expected: FAIL

Expand Down Expand Up @@ -5358,9 +5355,6 @@
[Window interface: window must inherit property "length" with the proper type (19)]
expected: FAIL

[Window interface: window must have own property "top"]
expected: FAIL

[Window interface: window must inherit property "opener" with the proper type (21)]
expected: FAIL

Expand Down Expand Up @@ -9581,4 +9575,3 @@
[HTMLInputElement interface: createInput("button") must inherit property "useMap" with the proper type (57)]
expected: FAIL

0 comments on commit 08a55e2

Please sign in to comment.