From c3d13fd34a3e9b866093d86b5cd900ac2b5138bd Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 4 Jun 2014 20:11:05 +0200 Subject: [PATCH] Bug 1015887 - Expose realFrameElement to Chrome JS. r=bholley --- dom/base/nsGlobalWindow.h | 3 +-- dom/webidl/Window.webidl | 2 ++ js/xpconnect/src/XPCJSRuntime.cpp | 1 + js/xpconnect/src/xpcprivate.h | 1 + js/xpconnect/wrappers/XrayWrapper.cpp | 23 +++++++++++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index c9c76fec401..314d2ca4435 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -967,6 +967,7 @@ public: void SizeToContent(mozilla::ErrorResult& aError); nsIDOMCrypto* GetCrypto(mozilla::ErrorResult& aError); nsIControllers* GetControllers(mozilla::ErrorResult& aError); + mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError); float GetMozInnerScreenX(mozilla::ErrorResult& aError); float GetMozInnerScreenY(mozilla::ErrorResult& aError); float GetDevicePixelRatio(mozilla::ErrorResult& aError); @@ -1374,8 +1375,6 @@ protected: nsGlobalWindow* InnerForSetTimeoutOrInterval(mozilla::ErrorResult& aError); - mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError); - void PostMessageMoz(JSContext* aCx, JS::Handle aMessage, const nsAString& aTargetOrigin, JS::Handle aTransfer, diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index cd3914bcb78..caec3bc67c9 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -285,6 +285,8 @@ partial interface Window { // XXX Shouldn't this be in nsIDOMChromeWindow? [ChromeOnly, Replaceable, Throws] readonly attribute MozControllers controllers; + [ChromeOnly, Throws] readonly attribute Element? realFrameElement; + [Throws] readonly attribute float mozInnerScreenX; [Throws] readonly attribute float mozInnerScreenY; [Throws] readonly attribute float devicePixelRatio; diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 4cc181d25ac..a3539ddee43 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -81,6 +81,7 @@ const char* const XPCJSRuntime::mStrings[] = { "__exposedProps__", // IDX_EXPOSEDPROPS "eval", // IDX_EVAL "controllers", // IDX_CONTROLLERS + "realFrameElement", // IDX_REALFRAMEELEMENT }; /***************************************************************************/ diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 16bf1f7e32f..8572014aced 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -479,6 +479,7 @@ public: IDX_EXPOSEDPROPS , IDX_EVAL , IDX_CONTROLLERS , + IDX_REALFRAMEELEMENT , IDX_TOTAL_COUNT // just a count of the above }; diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 952bbca67e6..a39fd0081fb 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -10,6 +10,7 @@ #include "nsIContent.h" #include "nsIControllers.h" +#include "mozilla/dom/Element.h" #include "nsContentUtils.h" #include "XPCWrapper.h" @@ -1090,6 +1091,28 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wr return true; } + // The |realFrameElement| property is accessible as a [ChromeOnly] property + // on Window.WebIDL, and [noscript] in XPIDL. Chrome needs to see this over + // Xray, so we need to special-case it until we move |Window| to WebIDL. + if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_REALFRAMEELEMENT) && + AccessCheck::isChrome(wrapper) && + (win = AsWindow(cx, wrapper))) + { + ErrorResult rv; + Element* f = win->GetRealFrameElement(rv); + if (!f) { + desc.object().set(nullptr); + return true; + } + + if (!WrapNewBindingObject(cx, f, desc.value())) { + return false; + } + + desc.object().set(wrapper); + return true; + } + XPCNativeInterface *iface; XPCNativeMember *member; XPCWrappedNative *wn = getWN(wrapper);