Bug 783520 - [b2g-bluetooth] follow-up to bug 730992, r=qdot
authorEric Chou <echou@mozilla.com>
Wed, 22 Aug 2012 18:37:08 +0800
changeset 105059 e8e54b17e6f2dfd69a91db0d0276e49c22248034
parent 105058 a8785c8a603a156de71d42cc11d861fd95c409e3
child 105060 93d2b46f35f183e2328c86b87a19c8b05a8a402d
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersqdot
bugs783520, 730992
milestone17.0a1
Bug 783520 - [b2g-bluetooth] follow-up to bug 730992, r=qdot
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/Makefile.in
dom/bluetooth/nsIDOMBluetoothAuthorizeEvent.idl
dom/bluetooth/nsIDOMBluetoothPairingEvent.idl
js/xpconnect/src/event_impl_gen.conf.in
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -513,17 +513,16 @@ using mozilla::dom::indexedDB::IDBWrappe
 #include "nsIDOMVoicemailEvent.h"
 #endif
 
 #ifdef MOZ_B2G_BT
 #include "BluetoothManager.h"
 #include "BluetoothAdapter.h"
 #include "BluetoothDevice.h"
 #include "BluetoothPropertyEvent.h"
-#include "BluetoothPairingEvent.h"
 #endif
 
 #include "nsIDOMNavigatorSystemMessages.h"
 
 #include "mozilla/dom/Activity.h"
 
 #include "DOMCameraManager.h"
 #include "CameraControl.h"
@@ -1674,18 +1673,16 @@ static nsDOMClassInfoData sClassInfoData
   NS_DEFINE_CLASSINFO_DATA(BluetoothManager, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(BluetoothAdapter, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)  
   NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(BluetoothPropertyEvent, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
-  NS_DEFINE_CLASSINFO_DATA(BluetoothPairingEvent, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
 #endif
 
   NS_DEFINE_CLASSINFO_DATA(CameraManager, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CameraControl, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CameraCapabilities, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
@@ -4470,22 +4467,16 @@ nsDOMClassInfo::Init()
   DOM_CLASSINFO_MAP_BEGIN(BluetoothDevice, nsIDOMBluetoothDevice)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothDevice)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(BluetoothPropertyEvent, nsIDOMBluetoothPropertyEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothPropertyEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
   DOM_CLASSINFO_MAP_END
-
-  DOM_CLASSINFO_MAP_BEGIN(BluetoothPairingEvent, nsIDOMBluetoothPairingEvent)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothPairingEvent)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
-  DOM_CLASSINFO_MAP_END
-
 #endif
 
   DOM_CLASSINFO_MAP_BEGIN(CameraManager, nsIDOMCameraManager)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMCameraManager)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(CameraControl, nsICameraControl)
     DOM_CLASSINFO_MAP_ENTRY(nsICameraControl)
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -519,17 +519,16 @@ DOMCI_CLASS(MozVoicemail)
 DOMCI_CLASS(MozVoicemailEvent)
 #endif
 
 #ifdef MOZ_B2G_BT
 DOMCI_CLASS(BluetoothManager)
 DOMCI_CLASS(BluetoothAdapter)
 DOMCI_CLASS(BluetoothDevice)
 DOMCI_CLASS(BluetoothPropertyEvent)
-DOMCI_CLASS(BluetoothPairingEvent)
 #endif
 
 DOMCI_CLASS(CameraManager)
 DOMCI_CLASS(CameraControl)
 DOMCI_CLASS(CameraCapabilities)
 
 DOMCI_CLASS(DOMError)
 DOMCI_CLASS(DOMRequest)
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -3,31 +3,32 @@
 /* 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 "BluetoothAdapter.h"
 #include "BluetoothDevice.h"
 #include "BluetoothPropertyEvent.h"
-#include "BluetoothPairingEvent.h"
 #include "BluetoothService.h"
 #include "BluetoothTypes.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothUtils.h"
 #include "GeneratedEvents.h"
 
+#include "nsContentUtils.h"
 #include "nsDOMClassInfo.h"
 #include "nsDOMEvent.h"
+#include "nsIDOMBluetoothAuthorizeEvent.h"
+#include "nsIDOMBluetoothDeviceEvent.h"
+#include "nsIDOMBluetoothDeviceAddressEvent.h"
+#include "nsIDOMBluetoothPairingEvent.h"
+#include "nsIDOMDOMRequest.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOMCIDInternal.h"
-#include "nsIDOMDOMRequest.h"
-#include "nsIDOMBluetoothDeviceEvent.h"
-#include "nsIDOMBluetoothDeviceAddressEvent.h"
-#include "nsContentUtils.h"
 
 #include "mozilla/LazyIdleThread.h"
 #include "mozilla/Util.h"
 
 using namespace mozilla;
 
 USING_BLUETOOTH_NAMESPACE
 
@@ -317,76 +318,110 @@ BluetoothAdapter::Notify(const Bluetooth
     e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("devicedisappeared"),
                                        false, false, deviceAddress);
     e->SetTrusted(true);
     bool dummy;
     DispatchEvent(event, &dummy);
   } else if (aData.name().EqualsLiteral("PropertyChanged")) {
     // Get BluetoothNamedValue, make sure array length is 1
     arr = aData.value().get_ArrayOfBluetoothNamedValue();
-    if(arr.Length() != 1) {
-      // This really should not happen
-      NS_ERROR("Got more than one property in a change message!");
-      return;
-    }
+
+    NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!");
+    NS_ASSERTION(arr[0].value().type() == BluetoothValue::TArrayOfBluetoothNamedValue,
+                 "PropertyChanged: Invalid value type");
+
     BluetoothNamedValue v = arr[0];
     SetPropertyByValue(v);
     nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(v.name());
     e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged"));
   } else if (aData.name().EqualsLiteral("RequestConfirmation")) {
     arr = aData.value().get_ArrayOfBluetoothNamedValue();
-    if(arr.Length() != 2) {
-      NS_ERROR("RequestConfirmation: Length of parameters is wrong");
-      return;
-    }
+
+    NS_ASSERTION(arr.Length() == 2, "RequestConfirmation: Wrong length of parameters");
+    NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString,
+                 "RequestConfirmation: Invalid value type");
+    NS_ASSERTION(arr[1].value().type() == BluetoothValue::Tuint32_t,
+                 "RequestConfirmation: Invalid value type");
+
+    nsCOMPtr<nsIDOMEvent> event;
+    NS_NewDOMBluetoothPairingEvent(getter_AddRefs(event), nullptr, nullptr);
 
-    nsString deviceAddress = arr[0].value().get_nsString();
-    uint32_t passkey = arr[1].value().get_uint32_t();
-
-    nsRefPtr<BluetoothPairingEvent> e = BluetoothPairingEvent::Create(deviceAddress, passkey);
-    e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("requestconfirmation"));
+    nsCOMPtr<nsIDOMBluetoothPairingEvent> e = do_QueryInterface(event);
+    e->InitBluetoothPairingEvent(NS_LITERAL_STRING("requestconfirmation"),
+                                 false,
+                                 false,
+                                 arr[0].value().get_nsString(),
+                                 arr[1].value().get_uint32_t());
+    e->SetTrusted(true);
+    bool dummy;
+    DispatchEvent(event, &dummy);
   } else if (aData.name().EqualsLiteral("RequestPinCode")) {
     arr = aData.value().get_ArrayOfBluetoothNamedValue();
-    if(arr.Length() != 1) {
-      NS_ERROR("RequestPinCode: Length of parameters is wrong");
-      return;
-    }
+
+    NS_ASSERTION(arr.Length() == 1, "RequestPinCode: Wrong length of parameters");
+    NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString,
+                 "RequestPinCode: Invalid value type");
 
-    nsString deviceAddress = arr[0].value().get_nsString();
+    nsCOMPtr<nsIDOMEvent> event;
+    NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr);
 
-    nsRefPtr<BluetoothPairingEvent> e = BluetoothPairingEvent::Create(deviceAddress, 0);
-    e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("requestpincode"));
+    nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event);
+    e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("requestpincode"),
+                                       false, false, arr[0].value().get_nsString());
+    e->SetTrusted(true);
+    bool dummy;
+    DispatchEvent(event, &dummy);
   } else if (aData.name().EqualsLiteral("RequestPasskey")) {
     arr = aData.value().get_ArrayOfBluetoothNamedValue();
-    if(arr.Length() != 1) {
-      NS_ERROR("RequestPasskey: Length of parameters is wrong");
-      return;
-    }
+
+    NS_ASSERTION(arr.Length() == 1, "RequestPasskey: Wrong length of parameters");
+    NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString,
+                 "RequestPasskey: Invalid value type");
 
-    nsString deviceAddress = arr[0].value().get_nsString();
+    nsCOMPtr<nsIDOMEvent> event;
+    NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr);
 
-    nsRefPtr<BluetoothPairingEvent> e = BluetoothPairingEvent::Create(deviceAddress, 0);
-    e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("requestpasskey"));
+    nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event);
+    e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("requestpasskey"),
+                                       false, false, arr[0].value().get_nsString());
+    e->SetTrusted(true);
+    bool dummy;
+    DispatchEvent(event, &dummy);
   } else if (aData.name().EqualsLiteral("Authorize")) {
     arr = aData.value().get_ArrayOfBluetoothNamedValue();
-    if(arr.Length() != 2) {
-      NS_ERROR("Authorize: Length of parameters is wrong");
-      return;
-    }
 
-    nsString deviceAddress = arr[0].value().get_nsString();
-    nsString serviceUuid = arr[1].value().get_nsString();
+    NS_ASSERTION(arr.Length() == 2, "Authorize: Wrong length of parameters");
+    NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString,
+                 "Authorize: Invalid value type");
+    NS_ASSERTION(arr[1].value().type() == BluetoothValue::TnsString,
+                 "Authorize: Invalid value type");
+
+    nsCOMPtr<nsIDOMEvent> event;
+    NS_NewDOMBluetoothAuthorizeEvent(getter_AddRefs(event), nullptr, nullptr);
 
-    nsRefPtr<BluetoothPairingEvent> e = BluetoothPairingEvent::Create(deviceAddress, serviceUuid);
-    e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("authorize"));
+    nsCOMPtr<nsIDOMBluetoothAuthorizeEvent> e = do_QueryInterface(event);
+    e->InitBluetoothAuthorizeEvent(NS_LITERAL_STRING("authorize"),
+                                   false,
+                                   false,
+                                   arr[0].value().get_nsString(),
+                                   arr[1].value().get_nsString());
+    e->SetTrusted(true);
+    bool dummy;
+    DispatchEvent(event, &dummy);
   } else if (aData.name().EqualsLiteral("Cancel")) {
+    nsCOMPtr<nsIDOMEvent> event;
+    NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr);
+
+    nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event);
     // Just send a null nsString, won't be used
-    nsString deviceObjectPath = EmptyString();
-    nsRefPtr<BluetoothPairingEvent> e = BluetoothPairingEvent::Create(deviceObjectPath, 0);
-    e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("cancel"));
+    e->InitBluetoothDeviceAddressEvent(NS_LITERAL_STRING("cancel"),
+                                       false, false, EmptyString());
+    e->SetTrusted(true);
+    bool dummy;
+    DispatchEvent(event, &dummy);
   } else {
 #ifdef DEBUG
     nsCString warningMsg;
     warningMsg.AssignLiteral("Not handling manager signal: ");
     warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
     NS_WARNING(warningMsg.get());
 #endif
   }
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -28,31 +28,31 @@ FORCE_STATIC_LIB = 1
 include $(topsrcdir)/dom/dom-config.mk
 
 CPPSRCS += \
   BluetoothService.cpp \
   BluetoothManager.cpp \
   BluetoothAdapter.cpp \
   BluetoothDevice.cpp \
   BluetoothPropertyEvent.cpp \
-  BluetoothPairingEvent.cpp \
   BluetoothReplyRunnable.cpp \
   BluetoothPropertyContainer.cpp \
   BluetoothUtils.cpp \
   $(NULL)
 
 XPIDLSRCS = \
   nsIDOMNavigatorBluetooth.idl \
   nsIDOMBluetoothManager.idl \
   nsIDOMBluetoothAdapter.idl \
   nsIDOMBluetoothDevice.idl \
   nsIDOMBluetoothDeviceEvent.idl \
   nsIDOMBluetoothDeviceAddressEvent.idl \
   nsIDOMBluetoothPropertyEvent.idl \
   nsIDOMBluetoothPairingEvent.idl \
+  nsIDOMBluetoothAuthorizeEvent.idl \
   $(NULL)
 
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 VPATH += \
 	$(srcdir)/linux \
 	$(srcdir)/gonk \
 	$(NULL)
 LOCAL_INCLUDES += $(MOZ_DBUS_CFLAGS)
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/nsIDOMBluetoothAuthorizeEvent.idl
@@ -0,0 +1,26 @@
+/* -*- 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"
+
+[scriptable, builtinclass, uuid(1cfe7854-31a6-4a41-add6-b4ed35869a6d)]
+interface nsIDOMBluetoothAuthorizeEvent : nsIDOMEvent
+{
+  readonly attribute DOMString deviceAddress;
+  readonly attribute DOMString uuid;
+
+  [noscript] void initBluetoothAuthorizeEvent(in DOMString aType,
+                                              in boolean aCanBubble,
+                                              in boolean aCancelable,
+                                              in DOMString aDeviceAddress,
+                                              in DOMString aUuid);
+};
+
+dictionary BluetoothAuthorizeEventInit : EventInit
+{
+  DOMString deviceAddress;
+  DOMString uuid;
+};
--- a/dom/bluetooth/nsIDOMBluetoothPairingEvent.idl
+++ b/dom/bluetooth/nsIDOMBluetoothPairingEvent.idl
@@ -1,15 +1,26 @@
 /* -*- 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"
 
-[scriptable, builtinclass, uuid(b905b05e-2141-444c-a90d-525b6c0daff1)]
+[scriptable, builtinclass, uuid(333022b8-a7e5-4fff-8588-36f2eedff17e)]
 interface nsIDOMBluetoothPairingEvent : nsIDOMEvent
 {
   readonly attribute DOMString deviceAddress;
-  readonly attribute DOMString uuid;
   readonly attribute unsigned long passkey;
+
+  [noscript] void initBluetoothPairingEvent(in DOMString aType,
+                                            in boolean aCanBubble,
+                                            in boolean aCancelable,
+                                            in DOMString aDeviceAddress,
+                                            in unsigned long aPasskey);
 };
+
+dictionary BluetoothPairingEventInit : EventInit
+{
+  DOMString deviceAddress;
+  unsigned long passkey;
+};
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -17,18 +17,20 @@ simple_events = [
     'PopStateEvent',
     'HashChangeEvent',
     'CloseEvent',
     'MozContactChangeEvent',
     'DeviceOrientationEvent',
     'DeviceLightEvent',
     'MozApplicationEvent',
 #ifdef MOZ_B2G_BT
+    'BluetoothAuthorizeEvent',
+    'BluetoothDeviceEvent',
     'BluetoothDeviceAddressEvent',
-    'BluetoothDeviceEvent',
+    'BluetoothPairingEvent',
 #endif
     'DeviceStorageChangeEvent',
     'PopupBlockedEvent'
   ]
 
 """ include file names """
 special_includes = [
     'DictionaryHelpers.h',