Bug 715814 - Implement Web Activities : Activity Object [r=mounir]

This commit is contained in:
Fabrice Desré 2012-07-20 17:41:30 +02:00
parent 5141476eeb
commit e67e7c886a
16 changed files with 301 additions and 1 deletions

View File

@ -153,6 +153,7 @@
@BINPATH@/components/directory.xpt
@BINPATH@/components/docshell.xpt
@BINPATH@/components/dom.xpt
@BINPATH@/components/dom_activities.xpt
@BINPATH@/components/dom_apps.xpt
@BINPATH@/components/dom_base.xpt
#ifdef MOZ_B2G_RIL
@ -476,6 +477,9 @@
@BINPATH@/components/SystemMessageManager.js
@BINPATH@/components/SystemMessageManager.manifest
@BINPATH@/components/ActivityProxy.js
@BINPATH@/components/Activities.manifest
@BINPATH@/components/AppProtocolHandler.js
@BINPATH@/components/AppProtocolHandler.manifest

View File

@ -9,6 +9,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
PARALLEL_DIRS = interfaces
PARALLEL_DIRS = interfaces src
include $(topsrcdir)/config/rules.mk

View File

@ -16,6 +16,7 @@ XPIDLSRCS = nsIDOMActivity.idl \
nsIDOMActivityHandlerDescription.idl \
nsIDOMActivityRequestHandler.idl \
nsIDOMNavigatorActivities.idl \
nsIActivityProxy.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,18 @@
/* 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 nsIDOMMozActivity;
interface nsIDOMMozActivityOptions;
/**
* Implemented by @mozilla.org/dom/activities/proxy;1
*/
[scriptable, uuid(2241faf9-6219-4bc0-95f3-18651ac8a18b)]
interface nsIActivityProxy : nsISupports
{
void startActivity(in nsIDOMMozActivity activity, in nsIDOMMozActivityOptions options);
void cleanup();
};

View File

@ -0,0 +1,2 @@
component {ba9bd5cb-76a0-4ecf-a7b3-d2f7c43c5949} ActivityProxy.js
contract @mozilla.org/dom/activities/proxy;1 {ba9bd5cb-76a0-4ecf-a7b3-d2f7c43c5949}

View File

@ -0,0 +1,78 @@
/* 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 "Activity.h"
#include "nsDOMClassInfo.h"
#include "nsContentUtils.h"
#include "nsIDOMActivityOptions.h"
using namespace mozilla::dom;
DOMCI_DATA(MozActivity, Activity)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Activity)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozActivity)
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozActivity)
NS_INTERFACE_MAP_END_INHERITING(DOMRequest)
NS_IMPL_ADDREF_INHERITED(Activity, DOMRequest)
NS_IMPL_RELEASE_INHERITED(Activity, DOMRequest)
NS_IMPL_CYCLE_COLLECTION_CLASS(Activity)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Activity,
DOMRequest)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mProxy)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Activity,
DOMRequest)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mProxy)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMETHODIMP
Activity::Initialize(nsISupports* aOwner,
JSContext* aContext,
JSObject* aObject,
PRUint32 aArgc,
JS::Value* aArgv)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aOwner);
NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED);
Init(window);
// We expect a single argument, which is a nsIDOMMozActivityOptions.
if (aArgc != 1 || !aArgv[0].isObject()) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsISupports> tmp;
nsContentUtils::XPConnect()->WrapJS(aContext, aArgv[0].toObjectOrNull(),
NS_GET_IID(nsIDOMMozActivityOptions),
getter_AddRefs(tmp));
nsCOMPtr<nsIDOMMozActivityOptions> options = do_QueryInterface(tmp);
if (!options) {
return NS_ERROR_INVALID_ARG;
}
// Instantiate a JS proxy that will do the child <-> parent communication
// with the JS implementation of the backend.
nsresult rv;
mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
mProxy->StartActivity(this, options);
return NS_OK;
}
Activity::~Activity() {
if (mProxy) {
mProxy->Cleanup();
}
}

View File

@ -0,0 +1,45 @@
/* 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 mozilla_dom_activities_Activity_h
#define mozilla_dom_activities_Activity_h
#include "nsIDOMActivity.h"
#include "nsIActivityProxy.h"
#include "DOMRequest.h"
#include "nsIJSNativeInitializer.h"
#define NS_DOMACTIVITY_CID \
{0x1c5b0930, 0xc90c, 0x4e9c, {0xaf, 0x4e, 0xb0, 0xb7, 0xa6, 0x59, 0xb4, 0xed}}
#define NS_DOMACTIVITY_CONTRACTID "@mozilla.org/dom/activity;1"
namespace mozilla {
namespace dom {
class Activity : public nsIDOMMozActivity
, public nsIJSNativeInitializer // In order to get a window for the DOMRequest
, public DOMRequest
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMMOZACTIVITY
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
NS_FORWARD_NSIDOMDOMREQUEST(DOMRequest::)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Activity, DOMRequest)
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
JSObject* aObject, PRUint32 aArgc, jsval* aArgv);
protected:
nsCOMPtr<nsIActivityProxy> mProxy;
~Activity();
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_activities_Activity_h

View File

@ -0,0 +1,78 @@
/* 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/. */
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
return Cc["@mozilla.org/childprocessmessagemanager;1"]
.getService(Ci.nsIFrameMessageManager)
.QueryInterface(Ci.nsISyncMessageSender);
});
function debug(aMsg) {
//dump("-- ActivityProxy " + Date.now() + " : " + aMsg + "\n");
}
/**
* nsIActivityProxy implementation
* We keep a reference to the C++ Activity object, and
* communicate with the Message Manager to know when to
* fire events on it.
*/
function ActivityProxy() {
debug("ActivityProxy");
this.activity = null;
}
ActivityProxy.prototype = {
startActivity: function actProxy_startActivity(aActivity, aOptions) {
debug("startActivity");
this.activity = aActivity;
this.id = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator)
.generateUUID().toString();
cpmm.sendAsyncMessage("Activity:Start", { id: this.id, options: aOptions });
cpmm.addMessageListener("Activity:FireSuccess", this);
cpmm.addMessageListener("Activity:FireError", this);
},
receiveMessage: function actProxy_receiveMessage(aMessage) {
debug("Got message: " + aMessage.name);
let msg = aMessage.json;
if (msg.id != this.id)
return;
debug("msg=" + JSON.stringify(msg));
switch(aMessage.name) {
case "Activity:FireSuccess":
debug("FireSuccess");
Services.DOMRequest.fireSuccess(this.activity, msg.result);
break;
case "Activity:FireError":
debug("FireError");
Services.DOMRequest.fireError(this.activity, msg.error);
break;
}
},
cleanup: function actProxy_cleanup() {
debug("cleanup");
cpmm.removeMessageListener("Activity:FireSuccess", this);
cpmm.removeMessageListener("Activity:FireError", this);
},
classID: Components.ID("{ba9bd5cb-76a0-4ecf-a7b3-d2f7c43c5949}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIActivityProxy])
}
const NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityProxy]);

View File

@ -0,0 +1,34 @@
# 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/.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
LIBRARY_NAME = dom_activities_s
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
include $(topsrcdir)/dom/dom-config.mk
CPPSRCS = \
Activity.cpp \
$(NULL)
EXPORTS_NAMESPACES = mozilla/dom
EXPORTS_mozilla/dom = \
Activity.h \
$(NULL)
EXTRA_COMPONENTS = \
ActivityProxy.js \
Activities.manifest \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@ -20,6 +20,21 @@ DOMRequest::DOMRequest(nsIDOMWindow* aWindow)
: mResult(JSVAL_VOID)
, mDone(false)
, mRooted(false)
{
Init(aWindow);
}
// We need this constructor for dom::Activity that inherits from DOMRequest
// but has no window available from the constructor.
DOMRequest::DOMRequest()
: mResult(JSVAL_VOID)
, mDone(false)
, mRooted(false)
{
}
void
DOMRequest::Init(nsIDOMWindow* aWindow)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
BindToOwner(window->IsInnerWindow() ? window.get() :

View File

@ -42,6 +42,7 @@ public:
void FireError(nsresult aError);
DOMRequest(nsIDOMWindow* aWindow);
DOMRequest();
virtual ~DOMRequest()
{
@ -55,6 +56,8 @@ protected:
virtual void RootResultVal();
virtual void UnrootResultVal();
void Init(nsIDOMWindow* aWindow);
};
class DOMRequestService MOZ_FINAL : public nsIDOMRequestService

View File

@ -524,6 +524,8 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#include "nsIDOMNavigatorSystemMessages.h"
#include "mozilla/dom/Activity.h"
#include "DOMError.h"
#include "DOMRequest.h"
#include "nsIOpenWindowEventDetail.h"
@ -1699,6 +1701,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(LockedFile, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozActivity, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
};
// Objects that should be constructable through |new Name();|
@ -1723,6 +1727,7 @@ static const nsContractIDMapData kConstructorMap[] =
"@mozilla.org/document-transformer;1?type=xslt")
NS_DEFINE_CONSTRUCTOR_DATA(EventSource, NS_EVENTSOURCE_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(MutationObserver, NS_DOMMUTATIONOBSERVER_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(MozActivity, NS_DOMACTIVITY_CONTRACTID)
};
#define NS_DEFINE_EVENT_CTOR(_class) \
@ -2490,6 +2495,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorBluetooth)
#endif
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorSystemMessages)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Plugin, nsIDOMPlugin)
@ -4543,6 +4549,12 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLockedFile)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozActivity, nsIDOMMozActivity)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozActivity)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMRequest)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
#ifdef DEBUG
{
PRUint32 i = ArrayLength(sClassInfoData);

View File

@ -541,3 +541,5 @@ DOMCI_CLASS(OpenWindowEventDetail)
DOMCI_CLASS(DOMFileHandle)
DOMCI_CLASS(FileRequest)
DOMCI_CLASS(LockedFile)
DOMCI_CLASS(MozActivity)

View File

@ -59,6 +59,7 @@ SHARED_LIBRARY_LIBS = \
$(DEPTH)/content/xbl/src/$(LIB_PREFIX)gkconxbl_s.$(LIB_SUFFIX) \
$(DEPTH)/content/xul/document/src/$(LIB_PREFIX)gkconxuldoc_s.$(LIB_SUFFIX) \
$(DEPTH)/view/src/$(LIB_PREFIX)gkview_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/activities/src/$(LIB_PREFIX)dom_activities_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/base/$(LIB_PREFIX)jsdombase_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/battery/$(LIB_PREFIX)dom_battery_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/contacts/$(LIB_PREFIX)jsdomcontacts_s.$(LIB_SUFFIX) \

View File

@ -90,9 +90,11 @@
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/DOMRequest.h"
#include "mozilla/OSFileConstants.h"
#include "mozilla/dom/Activity.h"
using mozilla::dom::indexedDB::IndexedDatabaseManager;
using mozilla::dom::DOMRequestService;
using mozilla::dom::Activity;
#ifdef MOZ_B2G_RIL
#include "SystemWorkerManager.h"
@ -248,6 +250,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsXMLHttpRequest, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEventSource)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebSocket)
NS_GENERIC_FACTORY_CONSTRUCTOR(Activity)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDOMFileReader, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormData)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlobProtocolHandler)
@ -733,6 +736,7 @@ NS_DEFINE_NAMED_CID(NS_BLOBPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_XMLHTTPREQUEST_CID);
NS_DEFINE_NAMED_CID(NS_EVENTSOURCE_CID);
NS_DEFINE_NAMED_CID(NS_WEBSOCKET_CID);
NS_DEFINE_NAMED_CID(NS_DOMACTIVITY_CID);
NS_DEFINE_NAMED_CID(NS_DOMPARSER_CID);
NS_DEFINE_NAMED_CID(NS_DOMSTORAGE2_CID);
NS_DEFINE_NAMED_CID(NS_DOMSTORAGEMANAGER_CID);
@ -1004,6 +1008,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_XMLHTTPREQUEST_CID, false, NULL, nsXMLHttpRequestConstructor },
{ &kNS_EVENTSOURCE_CID, false, NULL, nsEventSourceConstructor },
{ &kNS_WEBSOCKET_CID, false, NULL, nsWebSocketConstructor },
{ &kNS_DOMACTIVITY_CID, false, NULL, ActivityConstructor },
{ &kNS_DOMPARSER_CID, false, NULL, nsDOMParserConstructor },
{ &kNS_DOMSTORAGE2_CID, false, NULL, NS_NewDOMStorage2 },
{ &kNS_DOMSTORAGEMANAGER_CID, false, NULL, nsDOMStorageManagerConstructor },
@ -1140,6 +1145,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ NS_XMLHTTPREQUEST_CONTRACTID, &kNS_XMLHTTPREQUEST_CID },
{ NS_EVENTSOURCE_CONTRACTID, &kNS_EVENTSOURCE_CID },
{ NS_WEBSOCKET_CONTRACTID, &kNS_WEBSOCKET_CID },
{ NS_DOMACTIVITY_CONTRACTID, &kNS_DOMACTIVITY_CID },
{ NS_DOMPARSER_CONTRACTID, &kNS_DOMPARSER_CID },
{ "@mozilla.org/dom/storage;2", &kNS_DOMSTORAGE2_CID },
{ "@mozilla.org/dom/storagemanager;1", &kNS_DOMSTORAGEMANAGER_CID },

View File

@ -37,6 +37,7 @@ MAKEFILES_dom="
dom/interfaces/xul/Makefile
dom/activities/Makefile
dom/activities/interfaces/Makefile
dom/activities/src/Makefile
dom/alarm/Makefile
dom/base/Makefile
dom/battery/Makefile