Bug 866528 - Make nsIDOMActivityOptions a dictionary; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 18 Mar 2014 00:38:36 -0400
changeset 174325 1a7c8da31646
parent 174324 4ec8338518fe
child 174326 e9ea1662020a
push id26451
push usercbook@mozilla.com
push dateThu, 20 Mar 2014 12:56:37 +0000
treeherdermozilla-central@358d369c8388 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs866528
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 866528 - Make nsIDOMActivityOptions a dictionary; r=bzbarsky
b2g/installer/package-manifest.in
browser/installer/package-manifest.in
dom/activities/interfaces/moz.build
dom/activities/interfaces/nsIActivityProxy.idl
dom/activities/interfaces/nsIDOMActivityOptions.idl
dom/activities/interfaces/nsIDOMActivityRequestHandler.idl
dom/activities/src/Activities.manifest
dom/activities/src/Activity.cpp
dom/activities/src/Activity.h
dom/activities/src/ActivityOptions.js
dom/activities/src/ActivityRequestHandler.js
dom/activities/src/ActivityWrapper.js
dom/activities/src/moz.build
dom/bindings/Bindings.conf
dom/webidl/MozActivity.webidl
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -538,17 +538,16 @@
 @BINPATH@/components/nsIDService.js
 @BINPATH@/components/Identity.manifest
 
 @BINPATH@/components/SystemMessageInternal.js
 @BINPATH@/components/SystemMessageManager.js
 @BINPATH@/components/SystemMessageManager.manifest
 
 @BINPATH@/components/Activities.manifest
-@BINPATH@/components/ActivityOptions.js
 @BINPATH@/components/ActivityProxy.js
 @BINPATH@/components/ActivityRequestHandler.js
 @BINPATH@/components/ActivityWrapper.js
 @BINPATH@/components/ActivityMessageConfigurator.js
 
 @BINPATH@/components/TCPSocket.js
 @BINPATH@/components/TCPServerSocket.js
 @BINPATH@/components/TCPSocketParentIntermediary.js
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -539,17 +539,16 @@
 @BINPATH@/components/TCPSocket.manifest
 
 #ifdef MOZ_ACTIVITIES
 @BINPATH@/components/SystemMessageInternal.js
 @BINPATH@/components/SystemMessageManager.js
 @BINPATH@/components/SystemMessageManager.manifest
 
 @BINPATH@/components/Activities.manifest
-@BINPATH@/components/ActivityOptions.js
 @BINPATH@/components/ActivityProxy.js
 @BINPATH@/components/ActivityRequestHandler.js
 @BINPATH@/components/ActivityWrapper.js
 @BINPATH@/components/ActivityMessageConfigurator.js
 #endif
 
 @BINPATH@/components/Payment.js
 @BINPATH@/components/PaymentFlowInfo.js
--- a/dom/activities/interfaces/moz.build
+++ b/dom/activities/interfaces/moz.build
@@ -2,14 +2,13 @@
 # vim: set filetype=python:
 # 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/.
 
 XPIDL_SOURCES += [
     'nsIActivityProxy.idl',
     'nsIActivityUIGlue.idl',
-    'nsIDOMActivityOptions.idl',
     'nsIDOMActivityRequestHandler.idl',
 ]
 
 XPIDL_MODULE = 'dom_activities'
 
--- a/dom/activities/interfaces/nsIActivityProxy.idl
+++ b/dom/activities/interfaces/nsIActivityProxy.idl
@@ -1,20 +1,19 @@
 /* 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 nsIDOMMozActivityOptions;
 interface nsIDOMWindow;
 
 /**
   * Implemented by @mozilla.org/dom/activities/proxy;1
   */
-[scriptable, uuid(c7a258f7-26a6-46c6-a887-a6c936034f98)]
+[scriptable, uuid(60adef0f-c1a7-4dc5-bc0d-4b879f1e59ca)]
 interface nsIActivityProxy : nsISupports
 {
     void startActivity(in nsISupports /* MozActivity */ activity,
-                       in nsIDOMMozActivityOptions options,
+                       in jsval options,
                        in nsIDOMWindow window);
     void cleanup();
 };
deleted file mode 100644
--- a/dom/activities/interfaces/nsIDOMActivityOptions.idl
+++ /dev/null
@@ -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;
-};
--- a/dom/activities/interfaces/nsIDOMActivityRequestHandler.idl
+++ b/dom/activities/interfaces/nsIDOMActivityRequestHandler.idl
@@ -1,15 +1,13 @@
 /* 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"
 
-interface nsIDOMMozActivityOptions;
-
-[scriptable, uuid(e70c4181-ea3f-4aa5-a2f7-af910dc65e45)]
+[scriptable, uuid(e93c4df2-af49-4421-8d75-1237b51c555b)]
 interface nsIDOMMozActivityRequestHandler : nsISupports
 {
     void postResult(in jsval result);
     void postError(in DOMString error);
-    readonly attribute nsIDOMMozActivityOptions source;
+    readonly attribute jsval source;
 };
--- a/dom/activities/src/Activities.manifest
+++ b/dom/activities/src/Activities.manifest
@@ -4,11 +4,8 @@ contract @mozilla.org/dom/activities/pro
 component {5430d6f9-32d6-4924-ba39-6b6d1b093cd6} ActivityWrapper.js
 contract @mozilla.org/dom/system-messages/wrapper/activity;1 {5430d6f9-32d6-4924-ba39-6b6d1b093cd6}
 
 component {d2296daa-c406-4c5e-b698-e5f2c1715798} ActivityMessageConfigurator.js
 contract @mozilla.org/dom/system-messages/configurator/activity;1 {d2296daa-c406-4c5e-b698-e5f2c1715798}
 
 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}
--- a/dom/activities/src/Activity.cpp
+++ b/dom/activities/src/Activity.cpp
@@ -1,15 +1,14 @@
 /* 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 "mozilla/dom/MozActivityBinding.h"
 #include "nsContentUtils.h"
 #include "nsDOMClassInfo.h"
 #include "nsIConsoleService.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 
 using namespace mozilla::dom;
 
@@ -28,19 +27,19 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
 /* virtual */ JSObject*
 Activity::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return MozActivityBinding::Wrap(aCx, aScope, this);
 }
 
 nsresult
 Activity::Initialize(nsPIDOMWindow* aWindow,
-                     nsIDOMMozActivityOptions* aOptions)
+                     JSContext* aCx,
+                     const ActivityOptions& aOptions)
 {
-  MOZ_ASSERT(aOptions);
   MOZ_ASSERT(aWindow);
 
   nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc();
 
   bool isActive;
   aWindow->GetDocShell()->GetIsActive(&isActive);
 
   if (!isActive &&
@@ -62,17 +61,22 @@ Activity::Initialize(nsPIDOMWindow* aWin
   }
 
   // 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(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;
 }
 
 Activity::~Activity()
 {
   if (mProxy) {
     mProxy->Cleanup();
   }
--- a/dom/activities/src/Activity.h
+++ b/dom/activities/src/Activity.h
@@ -2,16 +2,17 @@
  * 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 "DOMRequest.h"
 #include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/dom/MozActivityBinding.h"
 #include "nsIActivityProxy.h"
 #include "mozilla/Preferences.h"
 #include "nsPIDOMWindow.h"
 
 namespace mozilla {
 namespace dom {
 
 class Activity : public DOMRequest
@@ -20,35 +21,37 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Activity, DOMRequest)
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   static already_AddRefed<Activity>
   Constructor(const GlobalObject& aOwner,
-              nsIDOMMozActivityOptions* aOptions,
+              JSContext* aCx,
+              const ActivityOptions& aOptions,
               ErrorResult& aRv)
   {
     nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aOwner.GetAsSupports());
     if (!window) {
       aRv.Throw(NS_ERROR_UNEXPECTED);
       return nullptr;
     }
 
     nsRefPtr<Activity> activity = new Activity(window);
-    aRv = activity->Initialize(window, aOptions);
+    aRv = activity->Initialize(window, aCx, aOptions);
     return activity.forget();
   }
 
   Activity(nsPIDOMWindow* aWindow);
 
 protected:
   nsresult Initialize(nsPIDOMWindow* aWindow,
-                      nsIDOMMozActivityOptions* aOptions);
+                      JSContext* aCx,
+                      const ActivityOptions& aOptions);
 
   nsCOMPtr<nsIActivityProxy> mProxy;
 
   ~Activity();
 };
 
 } // namespace dom
 } // namespace mozilla
deleted file mode 100644
--- a/dom/activities/src/ActivityOptions.js
+++ /dev/null
@@ -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]);
--- a/dom/activities/src/ActivityRequestHandler.js
+++ b/dom/activities/src/ActivityRequestHandler.js
@@ -26,31 +26,33 @@ function debug(aMsg) {
 function ActivityRequestHandler() {
   debug("ActivityRequestHandler");
   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 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 = {
   __exposedProps__: {
                       source: "r",
                       postResult: "r",
                       postError: "r"
                     },
 
   get source() {
+    if (this._options === null) {
+      Cu.reportError("ActivityRequestHandler._options must be initialized at this point");
+    }
     return this._options;
   },
 
   postResult: function arh_postResult(aResult) {
     cpmm.sendAsyncMessage("Activity:PostResult", {
       "id": this._id,
       "result": aResult
     });
--- a/dom/activities/src/ActivityWrapper.js
+++ b/dom/activities/src/ActivityWrapper.js
@@ -36,20 +36,21 @@ ActivityWrapper.prototype = {
     // ActivitiesService will be able to fire an error and complete the
     // Activity workflow.
     cpmm.sendAsyncMessage("Activity:Ready", { id: aMessage.id });
 
     let handler = Cc["@mozilla.org/dom/activities/request-handler;1"]
                     .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.
     // We don't need to check whether the activity itself already sent
     // back something since ActivitiesService.jsm takes care of that.
     let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                       .getInterface(Ci.nsIDOMWindowUtils);
     let innerWindowID = util.currentInnerWindowID;
--- a/dom/activities/src/moz.build
+++ b/dom/activities/src/moz.build
@@ -10,17 +10,16 @@ EXPORTS.mozilla.dom += [
 
 SOURCES += [
     'Activity.cpp',
 ]
 
 EXTRA_COMPONENTS += [
     'Activities.manifest',
     'ActivityMessageConfigurator.js',
-    'ActivityOptions.js',
     'ActivityProxy.js',
     'ActivityRequestHandler.js',
     'ActivityWrapper.js',
 ]
 
 EXTRA_JS_MODULES += [
     'ActivitiesService.jsm',
     'ActivitiesServiceFilter.jsm',
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1824,18 +1824,16 @@ def addExternalIface(iface, nativeType=N
     if not nativeType is None:
         domInterface['nativeType'] = nativeType
     if not headerFile is None:
         domInterface['headerFile'] = headerFile
     domInterface['notflattened'] = notflattened
     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')
 addExternalIface('CSSRuleList')
 addExternalIface('RTCDataChannel', nativeType='nsIDOMDataChannel')
 addExternalIface('File')
 addExternalIface('HitRegionOptions', nativeType='nsISupports')
 addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver')
--- a/dom/webidl/MozActivity.webidl
+++ b/dom/webidl/MozActivity.webidl
@@ -1,12 +1,15 @@
 /* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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/. */
 
-interface ActivityOptions;
+dictionary ActivityOptions {
+  DOMString name = "";
+  any data = null;
+};
 
 [Pref="dom.sysmsg.enabled",
- Constructor(ActivityOptions options)]
+ Constructor(optional ActivityOptions options)]
 interface MozActivity : DOMRequest {
 };