Bug 906901 - Use webIDL dictionaries for BrowerElementParent's event details r=bz

This commit is contained in:
David Zbarsky 2013-08-24 10:08:55 -04:00
parent dc8a4ca944
commit 0126553574
17 changed files with 89 additions and 267 deletions

View File

@ -196,7 +196,6 @@
@BINPATH@/components/dom_offline.xpt
@BINPATH@/components/dom_payment.xpt
@BINPATH@/components/dom_json.xpt
@BINPATH@/components/dom_browserelement.xpt
@BINPATH@/components/dom_messages.xpt
@BINPATH@/components/dom_power.xpt
@BINPATH@/components/dom_quota.xpt

View File

@ -203,7 +203,6 @@
@BINPATH@/components/dom_indexeddb.xpt
@BINPATH@/components/dom_offline.xpt
@BINPATH@/components/dom_json.xpt
@BINPATH@/components/dom_browserelement.xpt
@BINPATH@/components/dom_power.xpt
@BINPATH@/components/dom_quota.xpt
@BINPATH@/components/dom_range.xpt

View File

@ -185,8 +185,6 @@
#endif
#include "nsIDOMCameraManager.h"
#include "nsIOpenWindowEventDetail.h"
#include "nsIAsyncScrollEventDetail.h"
#include "nsIDOMGlobalObjectConstructor.h"
#include "nsIDOMLockedFile.h"
#include "nsDebug.h"
@ -561,11 +559,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(CameraCapabilities, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(OpenWindowEventDetail, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(AsyncScrollEventDetail, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(LockedFile, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH,
@ -1447,14 +1440,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsICameraCapabilities)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(OpenWindowEventDetail, nsIOpenWindowEventDetail)
DOM_CLASSINFO_MAP_ENTRY(nsIOpenWindowEventDetail)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(AsyncScrollEventDetail, nsIAsyncScrollEventDetail)
DOM_CLASSINFO_MAP_ENTRY(nsIAsyncScrollEventDetail)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(LockedFile, nsIDOMLockedFile)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLockedFile)
DOM_CLASSINFO_MAP_END

View File

@ -143,9 +143,6 @@ DOMCI_CLASS(BluetoothDevice)
DOMCI_CLASS(CameraControl)
DOMCI_CLASS(CameraCapabilities)
DOMCI_CLASS(OpenWindowEventDetail)
DOMCI_CLASS(AsyncScrollEventDetail)
DOMCI_CLASS(LockedFile)
DOMCI_CLASS(CSSFontFeatureValuesRule)

View File

@ -14,16 +14,16 @@
#include "BrowserElementParent.h"
#include "mozilla/dom/HTMLIFrameElement.h"
#include "nsOpenWindowEventDetail.h"
#include "nsEventDispatcher.h"
#include "nsIDOMCustomEvent.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsVariant.h"
#include "nsAsyncScrollEventDetail.h"
#include "mozilla/dom/BrowserElementDictionariesBinding.h"
#include "nsCxPusher.h"
#include "GeneratedEventClasses.h"
using mozilla::dom::Element;
using mozilla::dom::HTMLIFrameElement;
using mozilla::dom::TabParent;
using namespace mozilla;
using namespace mozilla::dom;
namespace {
@ -72,7 +72,7 @@ CreateIframe(Element* aOpenerFrameElement, const nsAString& aName, bool aRemote)
bool
DispatchCustomDOMEvent(Element* aFrameElement, const nsAString& aEventName,
nsISupports *aDetailValue)
JSContext* cx, JS::Handle<JS::Value> aDetailValue)
{
NS_ENSURE_TRUE(aFrameElement, false);
nsIPresShell *shell = aFrameElement->OwnerDoc()->GetShell();
@ -87,20 +87,24 @@ DispatchCustomDOMEvent(Element* aFrameElement, const nsAString& aEventName,
getter_AddRefs(domEvent));
NS_ENSURE_TRUE(domEvent, false);
nsCOMPtr<nsIWritableVariant> detailVariant = new nsVariant();
nsresult rv = detailVariant->SetAsISupports(aDetailValue);
NS_ENSURE_SUCCESS(rv, false);
nsCOMPtr<nsIDOMCustomEvent> customEvent = do_QueryInterface(domEvent);
NS_ENSURE_TRUE(customEvent, false);
customEvent->InitCustomEvent(aEventName,
/* bubbles = */ true,
/* cancelable = */ false,
detailVariant);
ErrorResult res;
CustomEvent* event = static_cast<CustomEvent*>(customEvent.get());
event->InitCustomEvent(cx,
aEventName,
/* bubbles = */ true,
/* cancelable = */ false,
aDetailValue,
res);
if (res.Failed()) {
return false;
}
customEvent->SetTrusted(true);
// Dispatch the event.
nsEventStatus status = nsEventStatus_eIgnore;
rv = nsEventDispatcher::DispatchDOMEvent(aFrameElement, nullptr,
domEvent, presContext, &status);
nsresult rv = nsEventDispatcher::DispatchDOMEvent(aFrameElement, nullptr,
domEvent, presContext, &status);
return NS_SUCCEEDED(rv);
}
@ -119,18 +123,36 @@ DispatchOpenWindowEvent(Element* aOpenerFrameElement,
const nsAString& aFeatures)
{
// Dispatch a CustomEvent at aOpenerFrameElement with a detail object
// (nsIOpenWindowEventDetail) containing aPopupFrameElement, aURL, aName, and
// (OpenWindowEventDetail) containing aPopupFrameElement, aURL, aName, and
// aFeatures.
// Create the event's detail object.
nsRefPtr<nsOpenWindowEventDetail> detail =
new nsOpenWindowEventDetail(aURL, aName, aFeatures,
aPopupFrameElement->AsDOMNode());
OpenWindowEventDetailInitializer detail;
detail.mUrl = aURL;
detail.mName = aName;
detail.mFeatures = aFeatures;
detail.mFrameElement = aPopupFrameElement;
AutoJSContext cx;
JS::Rooted<JS::Value> val(cx);
nsIGlobalObject* sgo = aPopupFrameElement->OwnerDoc()->GetScopeObject();
if (!sgo) {
return false;
}
JS::Rooted<JSObject*> global(cx, sgo->GetGlobalJSObject());
JSAutoCompartment ac(cx, global);
if (!detail.ToObject(cx, global, &val)) {
MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM.");
return false;
}
bool dispatchSucceeded =
DispatchCustomDOMEvent(aOpenerFrameElement,
NS_LITERAL_STRING("mozbrowseropenwindow"),
detail);
cx,
val);
// If the iframe is not in some document's DOM at this point, the embedder
// has "blocked" the popup.
@ -263,13 +285,27 @@ NS_IMETHODIMP DispatchAsyncScrollEventRunnable::Run()
{
nsCOMPtr<Element> frameElement = mTabParent->GetOwnerElement();
// Create the event's detail object.
nsRefPtr<nsAsyncScrollEventDetail> detail =
new nsAsyncScrollEventDetail(mContentRect.x, mContentRect.y,
mContentRect.width, mContentRect.height,
mContentSize.width, mContentSize.height);
AsyncScrollEventDetailInitializer detail;
detail.mLeft = mContentRect.x;
detail.mTop = mContentRect.y;
detail.mWidth = mContentRect.width;
detail.mHeight = mContentRect.height;
detail.mScrollWidth = mContentRect.width;
detail.mScrollHeight = mContentRect.height;
AutoSafeJSContext cx;
JS::Rooted<JS::Value> val(cx);
// We can get away with a null global here because
// AsyncScrollEventDetail only contains numeric values.
if (!detail.ToObject(cx, JS::NullPtr(), &val)) {
MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM.");
return NS_ERROR_FAILURE;
}
DispatchCustomDOMEvent(frameElement,
NS_LITERAL_STRING("mozbrowserasyncscroll"),
detail);
cx,
val);
return NS_OK;
}

View File

@ -46,7 +46,7 @@ public:
*
* 1) We fire a mozbrowseropenwindow CustomEvent on the opener
* iframe element. This event's detail is an instance of
* nsIOpenWindowEventDetail.
* OpenWindowEventDetail.
*
* 2) The embedder (the document which contains the opener iframe) can accept
* the window.open request by inserting event.detail.frameElement (an iframe

View File

@ -6,28 +6,16 @@
TEST_DIRS += ['mochitest']
XPIDL_SOURCES += [
'nsIAsyncScrollEventDetail.idl',
'nsIOpenWindowEventDetail.idl',
]
XPIDL_MODULE = 'dom_browserelement'
MODULE = 'dom'
EXPORTS += [
'nsAsyncScrollEventDetail.h',
'nsOpenWindowEventDetail.h',
]
EXPORTS.mozilla += [
'BrowserElementParent.h',
]
CPP_SOURCES += [
'BrowserElementParent.cpp',
'nsAsyncScrollEventDetail.cpp',
'nsOpenWindowEventDetail.cpp',
]
EXTRA_COMPONENTS += [

View File

@ -1,62 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#include "nsAsyncScrollEventDetail.h"
#include "nsDOMClassInfoID.h"
#include "nsIDOMClassInfo.h"
#include "nsIClassInfo.h"
#include "nsDOMClassInfo.h"
NS_IMPL_ADDREF(nsAsyncScrollEventDetail)
NS_IMPL_RELEASE(nsAsyncScrollEventDetail)
NS_INTERFACE_MAP_BEGIN(nsAsyncScrollEventDetail)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIAsyncScrollEventDetail)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(AsyncScrollEventDetail)
NS_INTERFACE_MAP_END
DOMCI_DATA(AsyncScrollEventDetail, nsAsyncScrollEventDetail)
/* readonly attribute float top; */
NS_IMETHODIMP nsAsyncScrollEventDetail::GetTop(float *aTop)
{
*aTop = mTop;
return NS_OK;
}
/* readonly attribute float left; */
NS_IMETHODIMP nsAsyncScrollEventDetail::GetLeft(float *aLeft)
{
*aLeft = mLeft;
return NS_OK;
}
/* readonly attribute float width; */
NS_IMETHODIMP nsAsyncScrollEventDetail::GetWidth(float *aWidth)
{
*aWidth = mWidth;
return NS_OK;
}
/* readonly attribute float height; */
NS_IMETHODIMP nsAsyncScrollEventDetail::GetHeight(float *aHeight)
{
*aHeight = mHeight;
return NS_OK;
}
/* readonly attribute float scrollWidth; */
NS_IMETHODIMP nsAsyncScrollEventDetail::GetScrollWidth(float *aScrollWidth)
{
*aScrollWidth = mScrollWidth;
return NS_OK;
}
/* readonly attribute float scrollHeight; */
NS_IMETHODIMP nsAsyncScrollEventDetail::GetScrollHeight(float *aScrollHeight)
{
*aScrollHeight = mScrollHeight;
return NS_OK;
}

View File

@ -1,36 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#include "nsIAsyncScrollEventDetail.h"
/**
* When we send a mozbrowserasyncscroll event (an instance of CustomEvent), we
* use an instance of this class as the event's detail.
*/
class nsAsyncScrollEventDetail : public nsIAsyncScrollEventDetail
{
public:
nsAsyncScrollEventDetail(const float left, const float top,
const float width, const float height,
const float contentWidth, const float contentHeigh)
: mTop(top)
, mLeft(left)
, mWidth(width)
, mHeight(height)
, mScrollWidth(contentWidth)
, mScrollHeight(contentHeigh)
{}
NS_DECL_ISUPPORTS
NS_DECL_NSIASYNCSCROLLEVENTDETAIL
private:
virtual ~nsAsyncScrollEventDetail() {}
const float mTop;
const float mLeft;
const float mWidth;
const float mHeight;
const float mScrollWidth;
const float mScrollHeight;
};

View File

@ -1,20 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#include "nsISupports.idl"
interface nsIDOMNode;
/**
* When we send a mozbrowseropenwindow event (an instance of CustomEvent), we
* use an instance of this interface as the event's detail.
*/
[scriptable, uuid(94377af6-956a-4adf-908b-363f7023ae1a)]
interface nsIOpenWindowEventDetail : nsISupports
{
readonly attribute AString url;
readonly attribute AString name;
readonly attribute AString features;
readonly attribute nsIDOMNode frameElement;
};

View File

@ -1,49 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#include "nsOpenWindowEventDetail.h"
#include "nsDOMClassInfoID.h"
#include "nsIDOMClassInfo.h"
#include "nsIClassInfo.h"
#include "nsDOMClassInfo.h"
NS_IMPL_CYCLE_COLLECTION_1(nsOpenWindowEventDetail, mFrameElement)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsOpenWindowEventDetail)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsOpenWindowEventDetail)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsOpenWindowEventDetail)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIOpenWindowEventDetail)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(OpenWindowEventDetail)
NS_INTERFACE_MAP_END
DOMCI_DATA(OpenWindowEventDetail, nsOpenWindowEventDetail)
NS_IMETHODIMP
nsOpenWindowEventDetail::GetUrl(nsAString& aOut)
{
aOut.Assign(mURL);
return NS_OK;
}
NS_IMETHODIMP
nsOpenWindowEventDetail::GetName(nsAString& aOut)
{
aOut.Assign(mName);
return NS_OK;
}
NS_IMETHODIMP
nsOpenWindowEventDetail::GetFeatures(nsAString& aOut)
{
aOut.Assign(mFeatures);
return NS_OK;
}
NS_IMETHODIMP
nsOpenWindowEventDetail::GetFrameElement(nsIDOMNode** aOut)
{
nsCOMPtr<nsIDOMNode> out = mFrameElement;
out.forget(aOut);
return NS_OK;
}

View File

@ -1,39 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#include "nsIOpenWindowEventDetail.h"
#include "nsIDOMNode.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h"
#include "nsString.h"
/**
* When we send a mozbrowseropenwindow event (an instance of CustomEvent), we
* use an instance of this class as the event's detail.
*/
class nsOpenWindowEventDetail : public nsIOpenWindowEventDetail
{
public:
nsOpenWindowEventDetail(const nsAString& aURL,
const nsAString& aName,
const nsAString& aFeatures,
nsIDOMNode* aFrameElement)
: mURL(aURL)
, mName(aName)
, mFeatures(aFeatures)
, mFrameElement(aFrameElement)
{}
virtual ~nsOpenWindowEventDetail() {}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(nsOpenWindowEventDetail)
NS_DECL_NSIOPENWINDOWEVENTDETAIL
private:
const nsString mURL;
const nsString mName;
const nsString mFeatures;
nsCOMPtr<nsIDOMNode> mFrameElement;
};

View File

@ -73,7 +73,6 @@ var interfaceNamesInGlobalScope =
"AnalyserNode",
"AnimationEvent",
"ArchiveRequest",
"AsyncScrollEventDetail",
"Attr",
"Audio",
"AudioBuffer",
@ -335,7 +334,6 @@ var interfaceNamesInGlobalScope =
"OfflineAudioCompletionEvent",
"OfflineAudioContext",
"OfflineResourceList",
"OpenWindowEventDetail",
"Option",
"OscillatorNode",
"PageTransitionEvent",

View File

@ -0,0 +1,24 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
dictionary AsyncScrollEventDetail {
float top = 0;
float left = 0;
float width = 0;
float height = 0;
float scrollWidth = 0;
float scrollHeight = 0;
};
dictionary OpenWindowEventDetail {
DOMString url = "";
DOMString name = "";
DOMString features = "";
Node? frameElement = null;
};

View File

@ -22,6 +22,8 @@ interface DummyInterface {
void CameraPictureOptions(optional CameraPictureOptions arg);
void MmsParameters(optional MmsParameters arg);
void MmsAttachment(optional MmsAttachment arg);
void AsyncScrollEventDetail(optional AsyncScrollEventDetail arg);
void OpenWindowEventDetail(optional OpenWindowEventDetail arg);
};
interface DummyInterfaceWorkers {

View File

@ -33,6 +33,7 @@ webidl_files = \
BeforeUnloadEvent.webidl \
BiquadFilterNode.webidl \
Blob.webidl \
BrowserElementDictionaries.webidl \
CameraManager.webidl \
CanvasRenderingContext2D.webidl \
CaretPosition.webidl \

View File

@ -150,7 +150,6 @@
@BINPATH@/components/dom_indexeddb.xpt
@BINPATH@/components/dom_offline.xpt
@BINPATH@/components/dom_json.xpt
@BINPATH@/components/dom_browserelement.xpt
@BINPATH@/components/dom_payment.xpt
@BINPATH@/components/dom_power.xpt
@BINPATH@/components/dom_quota.xpt