Bug 835143: Implement StkCommandEvent using event generator. f=vyang. r=smaug
authorVicamo Yang <vyang@mozilla.com>
Thu, 18 Jul 2013 07:18:00 +0800
changeset 169323 207fc4458209fa241d1b30281b3ed9736e9bc7ed
parent 169322 687a71e66137353642398095d9e7358f12d9ca0b
child 169324 1f63888d6959b33fec2f088e7026415e960d412a
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs835143
milestone28.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 835143: Implement StkCommandEvent using event generator. f=vyang. r=smaug
content/events/test/test_all_synthetic_events.html
dom/bindings/Bindings.conf
dom/icc/interfaces/SimToolKit.idl
dom/icc/src/IccManager.cpp
dom/icc/src/StkCommandEvent.cpp
dom/icc/src/StkCommandEvent.h
dom/icc/src/moz.build
dom/webidl/MozStkCommandEvent.webidl
dom/webidl/moz.build
--- a/content/events/test/test_all_synthetic_events.html
+++ b/content/events/test/test_all_synthetic_events.html
@@ -245,17 +245,19 @@ const kEventConstructors = {
   MozSettingsEvent:                          { create: function (aName, aProps) {
                                                          return new MozSettingsEvent(aName, aProps);
                                                        },
                                              },
   MozSmsEvent:                               { create: function (aName, aProps) {
                                                          return new MozSmsEvent(aName, aProps);
                                                        },
                                              },
-  MozStkCommandEvent:                        { create: null, // Cannot create untrusted event from JS.
+  MozStkCommandEvent:                        { create: function (aName, aProps) {
+                                                          return new MozStkCommandEvent(aName, aProps);
+                                                       },
                                              },
   MozVoicemailEvent:                         { create: function (aName, aProps) {
                                                           return new MozVoicemailEvent(aName, aProps);
                                                        },
                                              },
   MozWifiConnectionInfoEvent:                { create: function (aName, aProps) {
                                                          return new MozWifiConnectionInfoEvent(aName, aProps);
                                                        },
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -787,20 +787,16 @@ DOMInterfaces = {
 'MozNamedAttrMap': {
     'nativeType': 'nsDOMAttributeMap',
 },
 
 'MozPowerManager': {
     'nativeType': 'mozilla::dom::PowerManager',
 },
 
-'MozStkCommandEvent' : {
-    'nativeType': 'mozilla::dom::StkCommandEvent',
-},
-
 'MozTimeManager': {
     'nativeType': 'mozilla::dom::time::TimeManager',
 },
 
 'MozVoicemail': {
     'nativeType': 'mozilla::dom::Voicemail',
 },
 
--- a/dom/icc/interfaces/SimToolKit.idl
+++ b/dom/icc/interfaces/SimToolKit.idl
@@ -489,26 +489,16 @@ dictionary MozStkCommand
    *
    * When typeOfCommand is
    * - STK_CMD_REFRESH
    * options is null.
    */
   jsval options;
 };
 
-[scriptable, builtinclass, uuid(21cd2f25-ebea-43f8-8255-eaa4e1182858)]
-interface nsIDOMMozStkCommandEvent : nsIDOMEvent
-{
-  /**
-   * See nsIDOMMozStkCommand for the detail of command.
-   */
-  [implicit_jscontext]
-  readonly attribute jsval command;
-};
-
 dictionary MozStkResponse
 {
   /**
    * One of RESULT_*
    */
   unsigned short resultCode;
 
   /**
--- a/dom/icc/src/IccManager.cpp
+++ b/dom/icc/src/IccManager.cpp
@@ -1,19 +1,20 @@
 /* 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 "mozilla/dom/IccManager.h"
 
 #include "GeneratedEvents.h"
-#include "mozilla/dom/StkCommandEvent.h"
+#include "mozilla/dom/MozStkCommandEvent.h"
 #include "mozilla/Services.h"
 #include "nsIDOMClassInfo.h"
 #include "nsIDOMIccInfo.h"
+#include "nsJSON.h"
 #include "SimToolKit.h"
 
 #define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
 
 using namespace mozilla::dom;
 
 class IccManager::Listener : public nsIIccListener
 {
@@ -259,20 +260,40 @@ NS_IMPL_EVENT_HANDLER(IccManager, stkses
 NS_IMPL_EVENT_HANDLER(IccManager, cardstatechange)
 NS_IMPL_EVENT_HANDLER(IccManager, iccinfochange)
 
 // nsIIccListener
 
 NS_IMETHODIMP
 IccManager::NotifyStkCommand(const nsAString& aMessage)
 {
-  nsRefPtr<StkCommandEvent> event = StkCommandEvent::Create(this, aMessage);
-  NS_ASSERTION(event, "This should never fail!");
+  nsresult rv;
+  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  AutoPushJSContext cx(sc->GetNativeContext());
+  JS::Rooted<JS::Value> value(cx);
 
-  return event->Dispatch(this, NS_LITERAL_STRING("stkcommand"));
+  if (!aMessage.IsEmpty()) {
+    nsCOMPtr<nsIJSON> json(new nsJSON());
+    nsresult rv = json->DecodeToJSVal(aMessage, cx, value.address());
+    NS_ENSURE_SUCCESS(rv, rv);
+  } else {
+    value = JSVAL_VOID;
+  }
+
+  MozStkCommandEventInit init;
+  init.mBubbles = false;
+  init.mCancelable = false;
+  init.mCommand = value;
+
+  nsRefPtr<MozStkCommandEvent> event =
+    MozStkCommandEvent::Constructor(this, NS_LITERAL_STRING("stkcommand"), init);
+
+  return DispatchTrustedEvent(event);
 }
 
 NS_IMETHODIMP
 IccManager::NotifyStkSessionEnd()
 {
   return DispatchTrustedEvent(NS_LITERAL_STRING("stksessionend"));
 }
 
deleted file mode 100644
--- a/dom/icc/src/StkCommandEvent.cpp
+++ /dev/null
@@ -1,47 +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 "mozilla/dom/StkCommandEvent.h"
-
-#include "jsfriendapi.h"
-#include "nsJSON.h"
-#include "SimToolKit.h"
-
-namespace mozilla {
-namespace dom {
-
-already_AddRefed<StkCommandEvent>
-StkCommandEvent::Create(EventTarget* aOwner,
-                        const nsAString& aMessage)
-{
-  nsRefPtr<StkCommandEvent> event = new StkCommandEvent(aOwner);
-  event->mCommand = aMessage;
-  return event.forget();
-}
-
-NS_IMPL_ADDREF_INHERITED(StkCommandEvent, nsDOMEvent)
-NS_IMPL_RELEASE_INHERITED(StkCommandEvent, nsDOMEvent)
-
-NS_INTERFACE_MAP_BEGIN(StkCommandEvent)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMMozStkCommandEvent)
-NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
-
-NS_IMETHODIMP
-StkCommandEvent::GetCommand(JSContext* aCx, JS::Value* aCommand)
-
-{
-  nsCOMPtr<nsIJSON> json(new nsJSON());
-
-  if (!mCommand.IsEmpty()) {
-    nsresult rv = json->DecodeToJSVal(mCommand, aCx, aCommand);
-    NS_ENSURE_SUCCESS(rv, rv);
-  } else {
-    *aCommand = JSVAL_VOID;
-  }
-
-  return NS_OK;
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/icc/src/StkCommandEvent.h
+++ /dev/null
@@ -1,75 +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/. */
-
-#ifndef mozilla_dom_StkCommandEvent_h
-#define mozilla_dom_StkCommandEvent_h
-
-#include "mozilla/dom/MozStkCommandEventBinding.h"
-#include "nsDOMEvent.h"
-#include "SimToolKit.h"
-
-namespace mozilla {
-namespace dom {
-
-class StkCommandEvent : public nsDOMEvent,
-                        public nsIDOMMozStkCommandEvent
-{
-  nsString mCommand;
-
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_FORWARD_TO_NSDOMEVENT
-  NS_DECL_NSIDOMMOZSTKCOMMANDEVENT
-
-  static already_AddRefed<StkCommandEvent>
-  Create(EventTarget* aOwner, const nsAString& aMessage);
-
-  nsresult
-  Dispatch(EventTarget* aTarget, const nsAString& aEventType)
-  {
-    NS_ASSERTION(aTarget, "Null pointer!");
-    NS_ASSERTION(!aEventType.IsEmpty(), "Empty event type!");
-
-    nsresult rv = InitEvent(aEventType, false, false);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    SetTrusted(true);
-
-    nsDOMEvent* thisEvent = this;
-
-    bool dummy;
-    rv = aTarget->DispatchEvent(thisEvent, &dummy);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    return NS_OK;
-  }
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
-  {
-    return MozStkCommandEventBinding::Wrap(aCx, aScope, this);
-  }
-
-  JS::Value GetCommand(JSContext* aCx, ErrorResult& aRv)
-  {
-    JS::Rooted<JS::Value> retVal(aCx);
-    aRv = GetCommand(aCx, retVal.address());
-    return retVal;
-  }
-
-private:
-  StkCommandEvent(EventTarget* aOwner)
-  : nsDOMEvent(aOwner, nullptr, nullptr)
-  {
-    SetIsDOMBinding();
-  }
-
-  ~StkCommandEvent()
-  { }
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_StkCommandEvent_h
--- a/dom/icc/src/moz.build
+++ b/dom/icc/src/moz.build
@@ -1,22 +1,20 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # 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/.
 
 EXPORTS.mozilla.dom += [
     'IccManager.h',
-    'StkCommandEvent.h',
 ]
 
 SOURCES += [
     'IccManager.cpp',
-    'StkCommandEvent.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 LIBXUL_LIBRARY = True
 
 LIBRARY_NAME = 'dom_icc_s'
 
--- a/dom/webidl/MozStkCommandEvent.webidl
+++ b/dom/webidl/MozStkCommandEvent.webidl
@@ -1,11 +1,17 @@
 /* -*- 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/.
  */
 
+[Pref="dom.icc.enabled",
+ Constructor(DOMString type, optional MozStkCommandEventInit eventInitDict)]
 interface MozStkCommandEvent : Event
 {
-  [Throws]
   readonly attribute any command;
 };
+
+dictionary MozStkCommandEventInit : EventInit
+{
+  any command = null;
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -510,17 +510,16 @@ if CONFIG['MOZ_B2G_RIL']:
     WEBIDL_FILES += [
         'CFStateChangeEvent.webidl',
         'DataErrorEvent.webidl',
         'IccCardLockError.webidl',
         'MozCellBroadcast.webidl',
         'MozCellBroadcastEvent.webidl',
         'MozEmergencyCbModeEvent.webidl',
         'MozOtaStatusEvent.webidl',
-        'MozStkCommandEvent.webidl',
         'MozVoicemail.webidl',
         'MozVoicemailEvent.webidl',
         'USSDReceivedEvent.webidl',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     WEBIDL_FILES += [
         'MozWifiConnectionInfoEvent.webidl',
@@ -555,21 +554,21 @@ GENERATED_EVENTS_WEBIDL_FILES = [
     'CallGroupErrorEvent.webidl',
     'DataStoreChangeEvent.webidl',
     'DeviceLightEvent.webidl',
     'DeviceProximityEvent.webidl',
     'ErrorEvent.webidl',
     'MediaStreamEvent.webidl',
     'MozContactChangeEvent.webidl',
     'MozInterAppMessageEvent.webidl',
+    'MozStkCommandEvent.webidl',
     'RTCDataChannelEvent.webidl',
     'RTCPeerConnectionIceEvent.webidl',
     'TrackEvent.webidl',
     'UserProximityEvent.webidl',
 ]
 
 if CONFIG['MOZ_GAMEPAD']:
     GENERATED_EVENTS_WEBIDL_FILES += [
         'GamepadAxisMoveEvent.webidl',
         'GamepadButtonEvent.webidl',
         'GamepadEvent.webidl',
     ]
-