Bug 866528 - Make nsIDOMActivityOptions a dictionary; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2014-03-18 00:38:36 -04:00
parent 0c8a4684ea
commit a1a1f54752
15 changed files with 32 additions and 100 deletions

View File

@ -543,7 +543,6 @@
@BINPATH@/components/SystemMessageManager.manifest
@BINPATH@/components/Activities.manifest
@BINPATH@/components/ActivityOptions.js
@BINPATH@/components/ActivityProxy.js
@BINPATH@/components/ActivityRequestHandler.js
@BINPATH@/components/ActivityWrapper.js

View File

@ -544,7 +544,6 @@
@BINPATH@/components/SystemMessageManager.manifest
@BINPATH@/components/Activities.manifest
@BINPATH@/components/ActivityOptions.js
@BINPATH@/components/ActivityProxy.js
@BINPATH@/components/ActivityRequestHandler.js
@BINPATH@/components/ActivityWrapper.js

View File

@ -7,7 +7,6 @@
XPIDL_SOURCES += [
'nsIActivityProxy.idl',
'nsIActivityUIGlue.idl',
'nsIDOMActivityOptions.idl',
'nsIDOMActivityRequestHandler.idl',
]

View File

@ -4,7 +4,6 @@
#include "nsISupports.idl"
interface nsIDOMMozActivityOptions;
interface nsIDOMWindow;
/**
@ -14,7 +13,7 @@ interface nsIDOMWindow;
interface nsIActivityProxy : nsISupports
{
void startActivity(in nsISupports /* MozActivity */ activity,
in nsIDOMMozActivityOptions options,
in jsval options,
in nsIDOMWindow window);
void cleanup();
};

View File

@ -1,13 +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 "domstubs.idl"
[scriptable, uuid(f5bf5e9b-f53f-470f-b560-0d6f4c1c98ad)]
interface nsIDOMMozActivityOptions : nsISupports
{
readonly attribute DOMString name;
// The |data| field can be null.
readonly attribute jsval data;
};

View File

@ -4,12 +4,10 @@
#include "domstubs.idl"
interface nsIDOMMozActivityOptions;
[scriptable, uuid(e70c4181-ea3f-4aa5-a2f7-af910dc65e45)]
interface nsIDOMMozActivityRequestHandler : nsISupports
{
void postResult(in jsval result);
void postError(in DOMString error);
readonly attribute nsIDOMMozActivityOptions source;
readonly attribute jsval source;
};

View File

@ -9,6 +9,3 @@ contract @mozilla.org/dom/system-messages/configurator/activity;1 {d2296daa-c406
component {9326952a-dbe3-4d81-a51f-d9c160d96d6b} ActivityRequestHandler.js
contract @mozilla.org/dom/activities/request-handler;1 {9326952a-dbe3-4d81-a51f-d9c160d96d6b}
component {ee983dbb-d5ea-4c5b-be98-10a13cac9f9d} ActivityOptions.js
contract @mozilla.org/dom/activities/options;1 {ee983dbb-d5ea-4c5b-be98-10a13cac9f9d}

View File

@ -4,7 +4,6 @@
#include "Activity.h"
#include "mozilla/dom/MozActivityBinding.h"
#include "nsContentUtils.h"
#include "nsDOMClassInfo.h"
#include "nsIConsoleService.h"
@ -33,9 +32,9 @@ Activity::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
nsresult
Activity::Initialize(nsPIDOMWindow* aWindow,
nsIDOMMozActivityOptions* aOptions)
JSContext* aCx,
const ActivityOptions& aOptions)
{
MOZ_ASSERT(aOptions);
MOZ_ASSERT(aWindow);
nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc();
@ -67,7 +66,12 @@ Activity::Initialize(nsPIDOMWindow* aWindow,
mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), aOptions, aWindow);
JS::Rooted<JS::Value> optionsValue(aCx);
if (!aOptions.ToObject(aCx, JS::NullPtr(), &optionsValue)) {
return NS_ERROR_FAILURE;
}
mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue, aWindow);
return NS_OK;
}

View File

@ -7,6 +7,7 @@
#include "DOMRequest.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/MozActivityBinding.h"
#include "nsIActivityProxy.h"
#include "mozilla/Preferences.h"
#include "nsPIDOMWindow.h"
@ -25,7 +26,8 @@ public:
static already_AddRefed<Activity>
Constructor(const GlobalObject& aOwner,
nsIDOMMozActivityOptions* aOptions,
JSContext* aCx,
const ActivityOptions& aOptions,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aOwner.GetAsSupports());
@ -35,7 +37,7 @@ public:
}
nsRefPtr<Activity> activity = new Activity(window);
aRv = activity->Initialize(window, aOptions);
aRv = activity->Initialize(window, aCx, aOptions);
return activity.forget();
}
@ -43,7 +45,8 @@ public:
protected:
nsresult Initialize(nsPIDOMWindow* aWindow,
nsIDOMMozActivityOptions* aOptions);
JSContext* aCx,
const ActivityOptions& aOptions);
nsCOMPtr<nsIActivityProxy> mProxy;

View File

@ -1,56 +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/. */
"use strict";
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function debug(aMsg) {
//dump("-- ActivityOptions.js " + Date.now() + " : " + aMsg + "\n");
}
/**
* nsIDOMMozActivityOptions implementation.
*/
function ActivityOptions() {
debug("ActivityOptions");
this.wrappedJSObject = this;
// When a system message of type 'activity' is emitted, it forces the
// creation of an ActivityWrapper which in turns replace the default
// system message callback. The newly created wrapper then create a
// nsIDOMActivityRequestHandler object and fills up the properties of
// this object as well as the properties of the nsIDOMActivityOptions
// object contains by the request handler.
this._name = null;
this._data = null;
}
ActivityOptions.prototype = {
get name() {
return this._name;
},
get data() {
return this._data;
},
classID: Components.ID("{ee983dbb-d5ea-4c5b-be98-10a13cac9f9d}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozActivityOptions]),
classInfo: XPCOMUtils.generateCI({
classID: Components.ID("{ee983dbb-d5ea-4c5b-be98-10a13cac9f9d}"),
contractID: "@mozilla.org/dom/activities/options;1",
interfaces: [Ci.nsIDOMMozActivityOptions],
flags: Ci.nsIClassInfo.DOM_OBJECT,
classDescription: "Activity Options"
})
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityOptions]);

View File

@ -31,11 +31,10 @@ function ActivityRequestHandler() {
// creation of an ActivityWrapper which in turns replace the default
// system message callback. The newly created wrapper then create a
// nsIDOMActivityRequestHandler object and fills up the properties of
// this object as well as the properties of the nsIDOMActivityOptions
// object contains by the request handler.
// this object as well as the properties of the ActivityOptions
// dictionary contained by the request handler.
this._id = null;
this._options = Cc["@mozilla.org/dom/activities/options;1"]
.createInstance(Ci.nsIDOMMozActivityOptions);
this._options = null;
}
ActivityRequestHandler.prototype = {
@ -46,6 +45,9 @@ ActivityRequestHandler.prototype = {
},
get source() {
if (this._options === null) {
Cu.reportError("ActivityRequestHandler._options must be initialized at this point");
}
return this._options;
},

View File

@ -41,10 +41,11 @@ ActivityWrapper.prototype = {
.createInstance(Ci.nsIDOMMozActivityRequestHandler);
handler.wrappedJSObject._id = aMessage.id;
// options is an nsIDOMActivityOptions object.
var options = handler.wrappedJSObject._options;
options.wrappedJSObject._name = aMessage.payload.name;
options.wrappedJSObject._data = Cu.cloneInto(aMessage.payload.data, aWindow);
// options is an ActivityOptions dictionary.
handler.wrappedJSObject._options = Cu.cloneInto({
name: aMessage.payload.name,
data: Cu.cloneInto(aMessage.payload.data, aWindow),
}, aWindow);
// When the activity window is closed, fire an error to notify the activity
// caller of the situation.

View File

@ -15,7 +15,6 @@ SOURCES += [
EXTRA_COMPONENTS += [
'Activities.manifest',
'ActivityMessageConfigurator.js',
'ActivityOptions.js',
'ActivityProxy.js',
'ActivityRequestHandler.js',
'ActivityWrapper.js',

View File

@ -1829,8 +1829,6 @@ def addExternalIface(iface, nativeType=None, headerFile=None,
DOMInterfaces[iface] = domInterface
addExternalIface('ApplicationCache', nativeType='nsIDOMOfflineResourceList')
addExternalIface('ActivityOptions', nativeType='nsIDOMMozActivityOptions',
headerFile='nsIDOMActivityOptions.h')
addExternalIface('Counter')
addExternalIface('CSSRule')
addExternalIface('mozIDOMApplication', nativeType='mozIDOMApplication', headerFile='nsIDOMApplicationRegistry.h')

View File

@ -4,9 +4,12 @@
* 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/. */
interface ActivityOptions;
dictionary ActivityOptions {
DOMString name = "";
any data = null;
};
[Pref="dom.sysmsg.enabled",
Constructor(ActivityOptions options)]
Constructor(optional ActivityOptions options)]
interface MozActivity : DOMRequest {
};