Bug 952907 - Patch 1: Use WebIDL codegen to implement Bluetooth events, r=smaug
authorGina Yeh <gyeh@mozilla.com>
Wed, 22 Jan 2014 14:26:29 +0800
changeset 164985 7f40e1e33096288a97be7f3029fa35e8ad07570e
parent 164984 13f7cafee6456dc8e8832c7e0b2f5d3fce46c7fb
child 164986 866ec12529e8ed6849b37266e57f234dd1a8157d
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerssmaug
bugs952907
milestone29.0a1
Bug 952907 - Patch 1: Use WebIDL codegen to implement Bluetooth events, r=smaug
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothAdapter.h
dom/bluetooth/BluetoothDevice.cpp
dom/bluetooth/BluetoothDevice.h
dom/bluetooth/interfaces/moz.build
dom/bluetooth/interfaces/nsIDOMBluetoothDevice.idl
dom/bluetooth/interfaces/nsIDOMBluetoothDeviceEvent.idl
dom/bluetooth/interfaces/nsIDOMBluetoothStatusChangedEvent.idl
dom/bluetooth/moz.build
dom/webidl/BluetoothDeviceEvent.webidl
dom/webidl/BluetoothStatusChangedEvent.webidl
dom/webidl/moz.build
js/xpconnect/src/event_impl_gen.conf.in
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -159,20 +159,16 @@
 #include "nsIDOMIccManager.h"
 #include "nsIDOMMobileConnection.h"
 #endif // MOZ_B2G_RIL
 
 #ifdef MOZ_B2G_FM
 #include "FMRadio.h"
 #endif
 
-#ifdef MOZ_B2G_BT
-#include "BluetoothDevice.h"
-#endif
-
 #include "nsIDOMCameraManager.h"
 #include "nsIDOMGlobalObjectConstructor.h"
 #include "nsIDOMLockedFile.h"
 #include "nsDebug.h"
 
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/Likely.h"
 #include "WindowNamedPropertiesHandler.h"
@@ -483,21 +479,16 @@ static nsDOMClassInfoData sClassInfoData
   NS_DEFINE_CLASSINFO_DATA(CSSPageRule, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
 #ifdef MOZ_B2G_RIL
   NS_DEFINE_CLASSINFO_DATA(MozIccManager, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 #endif
 
-#ifdef MOZ_B2G_BT
-  NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH,
-                           EVENTTARGET_SCRIPTABLE_FLAGS)
-#endif
-
   NS_DEFINE_CLASSINFO_DATA(CameraCapabilities, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(LockedFile, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
@@ -1198,22 +1189,16 @@ nsDOMClassInfo::Init()
 #ifdef MOZ_B2G_RIL
   DOM_CLASSINFO_MAP_BEGIN(MozIccManager, nsIDOMMozIccManager)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozIccManager)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
   DOM_CLASSINFO_MAP_END
 
 #endif
 
-#ifdef MOZ_B2G_BT
-  DOM_CLASSINFO_MAP_BEGIN(BluetoothDevice, nsIDOMBluetoothDevice)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothDevice)
-  DOM_CLASSINFO_MAP_END
-#endif
-
   DOM_CLASSINFO_MAP_BEGIN(CameraCapabilities, nsICameraCapabilities)
     DOM_CLASSINFO_MAP_ENTRY(nsICameraCapabilities)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(LockedFile, nsIDOMLockedFile)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMLockedFile)
   DOM_CLASSINFO_MAP_END
 
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -103,20 +103,16 @@ DOMCI_CLASS(MozCSSKeyframeRule)
 DOMCI_CLASS(MozCSSKeyframesRule)
 
 DOMCI_CLASS(CSSPageRule)
 
 #ifdef MOZ_B2G_RIL
 DOMCI_CLASS(MozIccManager)
 #endif
 
-#ifdef MOZ_B2G_BT
-DOMCI_CLASS(BluetoothDevice)
-#endif
-
 DOMCI_CLASS(CameraCapabilities)
 
 DOMCI_CLASS(LockedFile)
 
 DOMCI_CLASS(CSSFontFeatureValuesRule)
 
 DOMCI_CLASS(UserDataHandler)
 DOMCI_CLASS(XPathNamespace)
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -1,26 +1,25 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* 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/. */
 
 #include "base/basictypes.h"
-#include "GeneratedEvents.h"
 #include "nsCxPusher.h"
 #include "nsDOMClassInfo.h"
-#include "nsIDOMBluetoothDeviceEvent.h"
-#include "nsIDOMBluetoothStatusChangedEvent.h"
 #include "nsTArrayHelpers.h"
 #include "DOMRequest.h"
 #include "nsThreadUtils.h"
 
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/dom/BluetoothAdapterBinding.h"
+#include "mozilla/dom/BluetoothDeviceEvent.h"
+#include "mozilla/dom/BluetoothStatusChangedEvent.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/LazyIdleThread.h"
 
 #include "BluetoothAdapter.h"
 #include "BluetoothDevice.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothService.h"
 #include "BluetoothUtils.h"
@@ -300,22 +299,23 @@ BluetoothAdapter::Notify(const Bluetooth
 {
   InfallibleTArray<BluetoothNamedValue> arr;
 
   BT_LOGD("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get());
 
   BluetoothValue v = aData.value();
   if (aData.name().EqualsLiteral("DeviceFound")) {
     nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value());
-    nsCOMPtr<nsIDOMEvent> event;
-    NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), this, nullptr, nullptr);
 
-    nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event);
-    e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicefound"),
-                                false, false, device);
+    BluetoothDeviceEventInit init;
+    init.mBubbles = false;
+    init.mCancelable = false;
+    init.mDevice = device;
+    nsRefPtr<BluetoothDeviceEvent> event =
+      BluetoothDeviceEvent::Constructor(this, NS_LITERAL_STRING("devicefound"), init);
     DispatchTrustedEvent(event);
   } else if (aData.name().EqualsLiteral("PropertyChanged")) {
     MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
 
     const InfallibleTArray<BluetoothNamedValue>& arr =
       v.get_ArrayOfBluetoothNamedValue();
 
     for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
@@ -330,23 +330,23 @@ BluetoothAdapter::Notify(const Bluetooth
       v.get_ArrayOfBluetoothNamedValue();
 
     MOZ_ASSERT(arr.Length() == 2 &&
                arr[0].value().type() == BluetoothValue::TnsString &&
                arr[1].value().type() == BluetoothValue::Tbool);
     nsString address = arr[0].value().get_nsString();
     bool status = arr[1].value().get_bool();
 
-    nsCOMPtr<nsIDOMEvent> event;
-    NS_NewDOMBluetoothStatusChangedEvent(
-      getter_AddRefs(event), this, nullptr, nullptr);
-
-    nsCOMPtr<nsIDOMBluetoothStatusChangedEvent> e = do_QueryInterface(event);
-    e->InitBluetoothStatusChangedEvent(aData.name(), false, false,
-                                       address, status);
+    BluetoothStatusChangedEventInit init;
+    init.mBubbles = false;
+    init.mCancelable = false;
+    init.mAddress = address;
+    init.mStatus = status;
+    nsRefPtr<BluetoothStatusChangedEvent> event =
+      BluetoothStatusChangedEvent::Constructor(this, aData.name(), init);
     DispatchTrustedEvent(event);
   } else if (aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) {
     nsCOMPtr<nsIDOMEvent> event;
     nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
     NS_ENSURE_SUCCESS_VOID(rv);
 
     rv = event->InitEvent(aData.name(), false, false);
     NS_ENSURE_SUCCESS_VOID(rv);
--- a/dom/bluetooth/BluetoothAdapter.h
+++ b/dom/bluetooth/BluetoothAdapter.h
@@ -7,17 +7,16 @@
 #ifndef mozilla_dom_bluetooth_bluetoothadapter_h__
 #define mozilla_dom_bluetooth_bluetoothadapter_h__
 
 #include "mozilla/Attributes.h"
 #include "BluetoothCommon.h"
 #include "BluetoothPropertyContainer.h"
 #include "nsCOMPtr.h"
 #include "nsDOMEventTargetHelper.h"
-#include "nsIDOMBluetoothDevice.h"
 
 namespace mozilla {
 namespace dom {
 class DOMRequest;
 struct MediaMetaData;
 struct MediaPlayStatus;
 }
 }
--- a/dom/bluetooth/BluetoothDevice.cpp
+++ b/dom/bluetooth/BluetoothDevice.cpp
@@ -34,18 +34,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothDevice,
                                                 nsDOMEventTargetHelper)
   tmp->Unroot();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothDevice)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothDevice)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothDevice)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(BluetoothDevice, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(BluetoothDevice, nsDOMEventTargetHelper)
 
 BluetoothDevice::BluetoothDevice(nsPIDOMWindow* aWindow,
                                  const nsAString& aAdapterPath,
                                  const BluetoothValue& aValue)
--- a/dom/bluetooth/BluetoothDevice.h
+++ b/dom/bluetooth/BluetoothDevice.h
@@ -6,38 +6,31 @@
 
 #ifndef mozilla_dom_bluetooth_bluetoothdevice_h__
 #define mozilla_dom_bluetooth_bluetoothdevice_h__
 
 #include "mozilla/Attributes.h"
 #include "BluetoothCommon.h"
 #include "BluetoothPropertyContainer.h"
 #include "nsDOMEventTargetHelper.h"
-#include "nsIDOMBluetoothDevice.h"
 #include "nsString.h"
 
-class nsIDOMDOMRequest;
-
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothNamedValue;
 class BluetoothValue;
 class BluetoothSignal;
 class BluetoothSocket;
 
 class BluetoothDevice : public nsDOMEventTargetHelper
-                      , public nsIDOMBluetoothDevice
                       , public BluetoothSignalObserver
                       , public BluetoothPropertyContainer
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_NSIDOMBLUETOOTHDEVICE
-
-  NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper)
 
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(BluetoothDevice,
                                                          nsDOMEventTargetHelper)
 
   static already_AddRefed<BluetoothDevice>
   Create(nsPIDOMWindow* aOwner, const nsAString& aAdapterPath,
          const BluetoothValue& aValue);
 
deleted file mode 100644
--- a/dom/bluetooth/interfaces/moz.build
+++ /dev/null
@@ -1,14 +0,0 @@
-# -*- 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/.
-
-if CONFIG['MOZ_B2G_BT']:
-    XPIDL_SOURCES += [
-        'nsIDOMBluetoothDevice.idl',
-        'nsIDOMBluetoothDeviceEvent.idl',
-        'nsIDOMBluetoothStatusChangedEvent.idl',
-    ]
-    XPIDL_MODULE = 'dom_bluetooth'
-
deleted file mode 100644
--- a/dom/bluetooth/interfaces/nsIDOMBluetoothDevice.idl
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* 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/. */
-
-#include "nsIDOMEventTarget.idl"
-
-// XPIDL interfaces might need this definition; so we keep it in place
-// until we completely switched to WebIDL. See bug 900904.
-[scriptable, builtinclass, uuid(291fdda9-4f96-4f2f-857f-900f89fb0412)]
-interface nsIDOMBluetoothDevice : nsIDOMEventTarget
-{
-};
deleted file mode 100644
--- a/dom/bluetooth/interfaces/nsIDOMBluetoothDeviceEvent.idl
+++ /dev/null
@@ -1,25 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
-/* 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/. */
-
-#include "nsIDOMEvent.idl"
-
-interface nsIDOMBluetoothDevice;
-
-[scriptable, builtinclass, uuid(e53dd06e-acd7-444a-914a-5fb60df0ad5b)]
-interface nsIDOMBluetoothDeviceEvent : nsIDOMEvent
-{
-  readonly attribute nsIDOMBluetoothDevice device;
-
-  [noscript] void initBluetoothDeviceEvent(in DOMString aType,
-                                           in boolean aCanBubble,
-                                           in boolean aCancelable,
-                                           in nsIDOMBluetoothDevice aDevice);
-};
-
-dictionary BluetoothDeviceEventInit : EventInit
-{
-  nsIDOMBluetoothDevice  device;
-};
deleted file mode 100644
--- a/dom/bluetooth/interfaces/nsIDOMBluetoothStatusChangedEvent.idl
+++ /dev/null
@@ -1,24 +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 "nsIDOMEvent.idl"
-
-[scriptable, builtinclass, uuid(07f6d8d0-d364-4033-92e2-d69de323d7b7)]
-interface nsIDOMBluetoothStatusChangedEvent : nsIDOMEvent
-{
-  readonly attribute DOMString address;
-  readonly attribute boolean status;
-
-  [noscript] void initBluetoothStatusChangedEvent(in DOMString aType,
-                                                  in boolean aCanBubble,
-                                                  in boolean aCancelable,
-                                                  in DOMString aAddress,
-                                                  in boolean aStatus);
-};
-
-dictionary BluetoothStatusChangedEventInit : EventInit
-{
-  DOMString address;
-  bool status;
-};
--- a/dom/bluetooth/moz.build
+++ b/dom/bluetooth/moz.build
@@ -1,17 +1,15 @@
 # -*- 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/.
 
 if CONFIG['MOZ_B2G_BT']:
-    PARALLEL_DIRS += ['interfaces']
-
     SOURCES += [
         'BluetoothAdapter.cpp',
         'BluetoothDevice.cpp',
         'BluetoothHidManager.cpp',
         'BluetoothManager.cpp',
         'BluetoothProfileController.cpp',
         'BluetoothPropertyContainer.cpp',
         'BluetoothReplyRunnable.cpp',
--- a/dom/webidl/BluetoothDeviceEvent.webidl
+++ b/dom/webidl/BluetoothDeviceEvent.webidl
@@ -1,15 +1,15 @@
 /* -*- 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/.
  */
 
-[Constructor(DOMString type, optional BluetoothDeviceEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
+[Constructor(DOMString type, optional BluetoothDeviceEventInit eventInitDict)]
 interface BluetoothDeviceEvent : Event
 {
   readonly attribute BluetoothDevice? device;
 };
 
 dictionary BluetoothDeviceEventInit : EventInit
 {
   BluetoothDevice? device = null;
--- a/dom/webidl/BluetoothStatusChangedEvent.webidl
+++ b/dom/webidl/BluetoothStatusChangedEvent.webidl
@@ -1,15 +1,15 @@
 /* -*- 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/.
  */
 
-[Constructor(DOMString type, optional BluetoothStatusChangedEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
+[Constructor(DOMString type, optional BluetoothStatusChangedEventInit eventInitDict)]
 interface BluetoothStatusChangedEvent : Event
 {
   readonly attribute DOMString address;
   readonly attribute boolean status;
 };
 
 dictionary BluetoothStatusChangedEventInit : EventInit
 {
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -506,19 +506,17 @@ WEBIDL_FILES += [
     'StyleSheetApplicableStateChangeEvent.webidl',
     'StyleSheetChangeEvent.webidl',
 ]
 
 if CONFIG['MOZ_B2G_BT']:
     WEBIDL_FILES += [
         'BluetoothAdapter.webidl',
         'BluetoothDevice.webidl',
-        'BluetoothDeviceEvent.webidl',
         'BluetoothManager.webidl',
-        'BluetoothStatusChangedEvent.webidl',
     ]
 
 if CONFIG['MOZ_B2G_RIL']:
     WEBIDL_FILES += [
         'IccCardLockError.webidl',
         'MozCellBroadcast.webidl',
         'MozCellBroadcastEvent.webidl',
         'MozIcc.webidl',
@@ -578,8 +576,15 @@ GENERATED_EVENTS_WEBIDL_FILES = [
 ]
 
 if CONFIG['MOZ_GAMEPAD']:
     GENERATED_EVENTS_WEBIDL_FILES += [
         'GamepadAxisMoveEvent.webidl',
         'GamepadButtonEvent.webidl',
         'GamepadEvent.webidl',
     ]
+
+if CONFIG['MOZ_B2G_BT']:
+    GENERATED_EVENTS_WEBIDL_FILES += [
+        'BluetoothDeviceEvent.webidl',
+        'BluetoothStatusChangedEvent.webidl',
+    ]
+
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -22,20 +22,16 @@ simple_events = [
     'SmartCardEvent',
     'StyleRuleChangeEvent',
     'StyleSheetChangeEvent',
     'StyleSheetApplicableStateChangeEvent',
 #ifdef MOZ_WIDGET_GONK
     'MozWifiStatusChangeEvent',
     'MozWifiConnectionInfoEvent',
 #endif
-#ifdef MOZ_B2G_BT
-    'BluetoothDeviceEvent',
-    'BluetoothStatusChangedEvent',
-#endif
 #ifdef MOZ_B2G_RIL
     'MozCellBroadcastEvent',
     'MozVoicemailEvent',
 #endif
     'ElementReplaceEvent',
     'MozSmsEvent',
     'MozMmsEvent',
 #ifdef MOZ_WEBSPEECH
@@ -60,15 +56,14 @@ special_includes = [
 exclude_automatic_type_include = [
     'nsISupports',
     'mozIDOMApplication',
     'nsIDOMBlob'
   ]
 
 """ Map xpidl interface names to implementation classes. The third column is the canonical interface. """
 xpidl_to_native = [
-    ['nsIDOMBluetoothDevice', 'bluetooth::BluetoothDevice', 'nsIDOMBluetoothDevice'],
     ['nsIDOMDocument', 'nsIDocument', 'nsIDocument'],
     ['nsIDOMElement', 'mozilla::dom::Element', 'mozilla::dom::Element'],
     ['nsIDOMCSSStyleSheet', 'nsCSSStyleSheet', 'nsIStyleSheet'],
     ['nsIDOMWindow', 'nsGlobalWindow', 'nsIDOMEventTarget']
   ]