Bug 761729 - Either implement mozIDOMApplicationEvent in C++, or make WebApps use CustomEvent [r=smaug]

This commit is contained in:
Fabrice Desré 2012-06-14 16:03:55 -07:00
Родитель 84b5bd6f23
Коммит b0c52f22b3
9 изменённых файлов: 143 добавлений и 39 удалений

Просмотреть файл

@ -70,6 +70,7 @@ CPPSRCS = \
nsDOMTouchEvent.cpp \
nsDOMCustomEvent.cpp \
nsDOMCompositionEvent.cpp \
nsDOMApplicationEvent.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

Просмотреть файл

@ -0,0 +1,67 @@
/* -*- Mode: C++; 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/. */
#include "nsDOMApplicationEvent.h"
#include "nsContentUtils.h"
#include "DictionaryHelpers.h"
DOMCI_DATA(MozApplicationEvent, nsDOMMozApplicationEvent)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMMozApplicationEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMMozApplicationEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mApplication)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMMozApplicationEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mApplication)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMMozApplicationEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozApplicationEvent)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozApplicationEvent)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
NS_IMPL_ADDREF_INHERITED(nsDOMMozApplicationEvent, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(nsDOMMozApplicationEvent, nsDOMEvent)
NS_IMETHODIMP
nsDOMMozApplicationEvent::GetApplication(mozIDOMApplication** aApplication)
{
NS_IF_ADDREF(*aApplication = mApplication);
return NS_OK;
}
NS_IMETHODIMP
nsDOMMozApplicationEvent::InitMozApplicationEvent(const nsAString& aType,
bool aCanBubble,
bool aCancelable,
mozIDOMApplication* aApplication)
{
nsresult rv = nsDOMEvent::InitEvent(aType, aCanBubble, aCancelable);
NS_ENSURE_SUCCESS(rv, rv);
mApplication = aApplication;
return NS_OK;
}
nsresult
nsDOMMozApplicationEvent::InitFromCtor(const nsAString& aType, JSContext* aCx, jsval* aVal)
{
mozilla::dom::MozApplicationEventInit d;
nsresult rv = d.Init(aCx, aVal);
NS_ENSURE_SUCCESS(rv, rv);
return InitMozApplicationEvent(aType, d.bubbles, d.cancelable, d.application);
}
nsresult
NS_NewDOMMozApplicationEvent(nsIDOMEvent** aInstancePtrResult,
nsPresContext* aPresContext,
nsEvent* aEvent)
{
nsDOMMozApplicationEvent* e = new nsDOMMozApplicationEvent(aPresContext, aEvent);
return CallQueryInterface(e, aInstancePtrResult);
}

Просмотреть файл

@ -0,0 +1,32 @@
/* -*- Mode: C++; 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/. */
#ifndef nsDOMApplicationEvent_h__
#define nsDOMApplicationEvent_h__
#include "nsIDOMApplicationRegistry.h"
#include "nsDOMEvent.h"
class nsDOMMozApplicationEvent : public nsDOMEvent,
public nsIDOMMozApplicationEvent
{
public:
nsDOMMozApplicationEvent(nsPresContext* aPresContext, nsEvent* aEvent)
: nsDOMEvent(aPresContext, aEvent) {}
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMMozApplicationEvent, nsDOMEvent)
// Forward to base class
NS_FORWARD_TO_NSDOMEVENT
NS_DECL_NSIDOMMOZAPPLICATIONEVENT
virtual nsresult InitFromCtor(const nsAString& aType, JSContext* aCx, jsval* aVal);
private:
nsCOMPtr<mozIDOMApplication> mApplication;
};
#endif // nsDOMContactChangeEvent_h__

Просмотреть файл

@ -356,14 +356,16 @@ WebappsApplicationMgmt.prototype = {
case "Webapps:Install:Return:OK":
if (this._oninstall) {
let app = msg.app;
let event = new WebappsApplicationEvent(new WebappsApplication(this._window, app.origin, app.manifest, app.manifestURL, app.receipts,
app.installOrigin, app.installTime));
let event = new this._window.MozApplicationEvent("applicationinstall",
{ application : new WebappsApplication(this._window, app.origin, app.manifest, app.manifestURL, app.receipts,
app.installOrigin, app.installTime) });
this._oninstall.handleEvent(event);
}
break;
case "Webapps:Uninstall:Return:OK":
if (this._onuninstall) {
let event = new WebappsApplicationEvent(new WebappsApplication(this._window, msg.origin, null, null, null, null, 0));
let event = new this._window.MozApplicationEvent("applicationuninstall",
{ application : new WebappsApplication(this._window, msg.origin, null, null, null, null, 0) });
this._onuninstall.handleEvent(event);
}
break;
@ -382,27 +384,4 @@ WebappsApplicationMgmt.prototype = {
classDescription: "Webapps Application Mgmt"})
}
/**
* mozIDOMApplicationEvent object
*/
function WebappsApplicationEvent(aApp) {
this._app = aApp;
}
WebappsApplicationEvent.prototype = {
get application() {
return this._app;
},
classID: Components.ID("{5bc42b2a-9acc-49d5-a336-c353c8125e48}"),
QueryInterface: XPCOMUtils.generateQI([Ci.mozIDOMApplicationEvent]),
classInfo: XPCOMUtils.generateCI({classID: Components.ID("{8c1bca96-266f-493a-8d57-ec7a95098c15}"),
contractID: "@mozilla.org/webapps/application-event;1",
interfaces: [Ci.mozIDOMApplicationEvent],
flags: Ci.nsIClassInfo.DOM_OBJECT,
classDescription: "Webapps Application Event"})
}
const NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsRegistry, WebappsApplication]);

Просмотреть файл

@ -178,6 +178,7 @@
#include "nsEventSource.h"
#include "nsIDOMSettingsManager.h"
#include "nsIDOMContactManager.h"
#include "nsIDOMApplicationRegistry.h"
// includes needed for the prototype chain interfaces
#include "nsIDOMNavigator.h"
@ -1638,7 +1639,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozContactChangeEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozApplicationEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#ifdef MOZ_B2G_RIL
NS_DEFINE_CLASSINFO_DATA(Telephony, nsEventTargetSH,
@ -1714,6 +1716,7 @@ NS_DEFINE_EVENT_CTOR(PageTransitionEvent)
NS_DEFINE_EVENT_CTOR(CloseEvent)
NS_DEFINE_EVENT_CTOR(MozSettingsEvent)
NS_DEFINE_EVENT_CTOR(MozContactChangeEvent)
NS_DEFINE_EVENT_CTOR(MozApplicationEvent)
NS_DEFINE_EVENT_CTOR(UIEvent)
NS_DEFINE_EVENT_CTOR(MouseEvent)
NS_DEFINE_EVENT_CTOR(DeviceLightEvent)
@ -1759,6 +1762,7 @@ static const nsConstructorFuncMapData kConstructorFuncMap[] =
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(CloseEvent)
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozSettingsEvent)
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozContactChangeEvent)
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozApplicationEvent)
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(UIEvent)
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MouseEvent)
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(DeviceProximityEvent)
@ -4480,12 +4484,17 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(MozSettingsEvent, nsIDOMMozSettingsEvent)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSettingsEvent)
DOM_CLASSINFO_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozContactChangeEvent, nsIDOMMozContactChangeEvent)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozContactChangeEvent)
DOM_CLASSINFO_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozContactChangeEvent, nsIDOMMozContactChangeEvent)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozContactChangeEvent)
DOM_CLASSINFO_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozApplicationEvent, nsIDOMMozApplicationEvent)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozApplicationEvent)
DOM_CLASSINFO_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
#ifdef MOZ_B2G_RIL
DOM_CLASSINFO_MAP_BEGIN(Telephony, nsIDOMTelephony)
@ -9116,7 +9125,7 @@ nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp)
JSObject *self;
JS::Value callee = JS_CALLEE(cx, vp);
if (callee.isObject() &&
JS_GetClass(&callee.toObject()) == &sHTMLDocumentAllClass) {
JS_GetClass(&callee.toObject()) == &sHTMLDocumentAllClass) {
self = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
} else {
self = JS_THIS_OBJECT(cx, vp);

Просмотреть файл

@ -518,6 +518,8 @@ DOMCI_CLASS(MutationRecord)
DOMCI_CLASS(MozSettingsEvent)
DOMCI_CLASS(MozContactChangeEvent)
DOMCI_CLASS(MozApplicationEvent)
#ifdef MOZ_B2G_RIL
DOMCI_CLASS(Telephony)
DOMCI_CLASS(TelephonyCall)

Просмотреть файл

@ -3,11 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "domstubs.idl"
#include "nsIArray.idl"
#include "nsIDOMEvent.idl"
#include "nsIDOMEventTarget.idl"
interface nsIDOMDOMRequest;
interface nsIArray;
[scriptable, uuid(b70b84f1-7ac9-4a92-bc32-8b6a7eb7879e)]
interface mozIDOMApplication : nsISupports
@ -18,16 +18,26 @@ interface mozIDOMApplication : nsISupports
readonly attribute DOMString origin;
readonly attribute DOMString installOrigin;
readonly attribute unsigned long installTime;
/* startPoint will be used when several launch_path exists for an app */
nsIDOMDOMRequest launch([optional] in DOMString startPoint);
nsIDOMDOMRequest uninstall();
nsIDOMDOMRequest uninstall();
};
[scriptable, uuid(f1dd58d8-5211-46ce-8470-d54dde596725)]
interface mozIDOMApplicationEvent : nsISupports
[scriptable, builtinclass, uuid(8f2bfba8-f10e-4f63-a5e0-7a7056e1dbe6)]
interface nsIDOMMozApplicationEvent : nsIDOMEvent
{
readonly attribute mozIDOMApplication application;
[noscript] void initMozApplicationEvent(in DOMString aType,
in boolean aCanBubble,
in boolean aCancelable,
in mozIDOMApplication aApplication);
};
dictionary MozApplicationEventInit : EventInit
{
mozIDOMApplication application;
};
[scriptable, uuid(bd304874-d532-4e13-8034-544211445583)]

Просмотреть файл

@ -272,4 +272,6 @@ nsresult
NS_NewDOMPopStateEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsEvent* aEvent);
nsresult
NS_NewDOMHashChangeEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsEvent* aEvent);
nsresult
NS_NewDOMMozApplicationEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsEvent* aEvent);
%}

Просмотреть файл

@ -23,6 +23,7 @@ dictionaries = [
[ 'DeviceProximityEventInit', 'nsIDOMDeviceProximityEvent.idl' ],
[ 'UserProximityEventInit', 'nsIDOMUserProximityEvent.idl' ],
[ 'DeviceLightEventInit', 'nsIDOMDeviceLightEvent.idl' ],
[ 'MozApplicationEventInit', 'nsIDOMApplicationRegistry.idl' ],
[ 'DOMFileMetadataParameters', 'nsIDOMLockedFile.idl' ],
[ 'XMLHttpRequestParameters', 'nsIXMLHttpRequest.idl' ],
[ 'DeviceStorageEnumerationParameters', 'nsIDOMDeviceStorage.idl' ]
@ -36,5 +37,6 @@ special_includes = [
# name of the type to not include using #include "typename.h"
exclude_automatic_type_include = [
'nsISupports'
'nsISupports',
'mozIDOMApplication'
]