Bug 789014 - Final version: Broadcast bonding-related events via system message, r=qdot, r=mrbkap
authorGina Yeh <gyeh@mozilla.com>
Wed, 12 Sep 2012 22:03:42 +0800
changeset 113198 7666b019c7ef6f5e40b2af08a0bb57f140757ee6
parent 113197 9374b6502e7a2ddd78acc3c7cc50abe2caf286a9
child 113199 b0a40832407b6ecabe5d23948922cd8c9207d8c2
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot, mrbkap
bugs789014
milestone18.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 789014 - Final version: Broadcast bonding-related events via system message, r=qdot, r=mrbkap
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothPairingEvent.cpp
dom/bluetooth/BluetoothPairingEvent.h
dom/bluetooth/BluetoothService.cpp
dom/bluetooth/BluetoothService.h
dom/bluetooth/Makefile.in
dom/bluetooth/linux/BluetoothDBusService.cpp
dom/bluetooth/nsIDOMBluetoothAuthorizeEvent.idl
dom/bluetooth/nsIDOMBluetoothPairingEvent.idl
js/xpconnect/src/event_impl_gen.conf.in
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -12,20 +12,18 @@
 #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 "mozilla/LazyIdleThread.h"
 #include "mozilla/Util.h"
 
 using namespace mozilla;
@@ -258,21 +256,16 @@ BluetoothAdapter::Create(nsPIDOMWindow* 
   }
 
   nsRefPtr<BluetoothAdapter> adapter = new BluetoothAdapter(aOwner, aValue);
   if (NS_FAILED(bs->RegisterBluetoothSignalHandler(adapter->GetPath(), adapter))) {
     NS_WARNING("Failed to register object with observer!");
     return nullptr;
   }
 
-  if (NS_FAILED(bs->RegisterBluetoothSignalHandler(NS_LITERAL_STRING(LOCAL_AGENT_PATH), adapter))) {
-    NS_WARNING("Failed to register local agent object with observer!");
-    return nullptr;
-  }
-
   if (NS_FAILED(bs->RegisterBluetoothSignalHandler(NS_LITERAL_STRING(REMOTE_AGENT_PATH), adapter))) {
     NS_WARNING("Failed to register remote agent object with observer!");
     return nullptr;
   }
 
   return adapter.forget();
 }
 
@@ -311,101 +304,16 @@ BluetoothAdapter::Notify(const Bluetooth
     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();
-
-    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);
-
-    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();
-
-    NS_ASSERTION(arr.Length() == 1, "RequestPinCode: Wrong length of parameters");
-    NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString,
-                 "RequestPinCode: Invalid value type");
-
-    nsCOMPtr<nsIDOMEvent> event;
-    NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr);
-
-    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();
-
-    NS_ASSERTION(arr.Length() == 1, "RequestPasskey: Wrong length of parameters");
-    NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString,
-                 "RequestPasskey: Invalid value type");
-
-    nsCOMPtr<nsIDOMEvent> event;
-    NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr);
-
-    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();
-
-    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);
-
-    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
-    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 adapter signal: ");
     warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
     NS_WARNING(warningMsg.get());
 #endif
   }
deleted file mode 100644
--- a/dom/bluetooth/BluetoothPairingEvent.cpp
+++ /dev/null
@@ -1,78 +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 "base/basictypes.h"
-#include "BluetoothPairingEvent.h"
-
-#include "nsDOMClassInfo.h"
-
-USING_BLUETOOTH_NAMESPACE
-
-// static
-already_AddRefed<BluetoothPairingEvent>
-BluetoothPairingEvent::Create(const nsAString& aDeviceAddress, const uint32_t& aPasskey)
-{
-  nsRefPtr<BluetoothPairingEvent> event = new BluetoothPairingEvent();
-
-  event->mPasskey = aPasskey;
-  event->mDeviceAddress = aDeviceAddress;
-
-  return event.forget();
-}
-
-// static
-already_AddRefed<BluetoothPairingEvent>
-BluetoothPairingEvent::Create(const nsAString& aDeviceAddress, const nsAString& aUuid)
-{
-  nsRefPtr<BluetoothPairingEvent> event = new BluetoothPairingEvent();
-
-  event->mUuid = aUuid;
-  event->mDeviceAddress = aDeviceAddress;
-
-  return event.forget();
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothPairingEvent)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothPairingEvent,
-                                                  nsDOMEvent)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothPairingEvent,
-                                                nsDOMEvent)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothPairingEvent)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothPairingEvent)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothPairingEvent)
-NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
-
-NS_IMPL_ADDREF_INHERITED(BluetoothPairingEvent, nsDOMEvent)
-NS_IMPL_RELEASE_INHERITED(BluetoothPairingEvent, nsDOMEvent)
-
-DOMCI_DATA(BluetoothPairingEvent, BluetoothPairingEvent)
-
-NS_IMETHODIMP
-BluetoothPairingEvent::GetPasskey(uint32_t* aPasskey)
-{
-  *aPasskey = mPasskey;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothPairingEvent::GetUuid(nsAString& aUuid)
-{
-  aUuid = mUuid;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothPairingEvent::GetDeviceAddress(nsAString& aDeviceAddress)
-{
-  aDeviceAddress = mDeviceAddress;
-  return NS_OK;
-}
-
deleted file mode 100644
--- a/dom/bluetooth/BluetoothPairingEvent.h
+++ /dev/null
@@ -1,70 +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/. */
-
-#ifndef mozilla_dom_bluetooth_requestpairingevent_h__
-#define mozilla_dom_bluetooth_requestpairingevent_h__
-
-#include "BluetoothCommon.h"
-
-#include "nsIDOMBluetoothPairingEvent.h"
-#include "nsIDOMEventTarget.h"
-
-#include "nsDOMEvent.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothPairingEvent : public nsDOMEvent
-                            , public nsIDOMBluetoothPairingEvent
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_FORWARD_TO_NSDOMEVENT
-  NS_DECL_NSIDOMBLUETOOTHPAIRINGEVENT
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothPairingEvent, nsDOMEvent)
-
-  static already_AddRefed<BluetoothPairingEvent>
-  Create(const nsAString& aDeviceAddress, const uint32_t& aPasskey);
-  
-  static already_AddRefed<BluetoothPairingEvent>
-  Create(const nsAString& aDeviceAddress, const nsAString& aUuid);
-
-  nsresult
-  Dispatch(nsIDOMEventTarget* 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);
-
-    rv = SetTrusted(true);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsIDOMEvent* thisEvent = static_cast<nsDOMEvent*>(this);
-
-    bool dummy;
-    rv = aTarget->DispatchEvent(thisEvent, &dummy);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    return NS_OK;
-  }
-
-private:
-  BluetoothPairingEvent()
-    : nsDOMEvent(nullptr, nullptr)
-  { }
-
-  ~BluetoothPairingEvent()
-  { }
-
-  uint32_t mPasskey;
-  nsString mUuid;
-  nsString mDeviceAddress;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
--- a/dom/bluetooth/BluetoothService.cpp
+++ b/dom/bluetooth/BluetoothService.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/Util.h"
 #include "nsContentUtils.h"
 #include "nsIDOMDOMRequest.h"
 #include "nsIObserverService.h"
 #include "nsISettingsService.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOM.h"
 #include "nsXPCOMCIDInternal.h"
+#include "nsISystemMessagesInternal.h"
 
 #define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
 #define BLUETOOTH_ENABLED_SETTING "bluetooth.enabled"
 
 using namespace mozilla;
 
 USING_BLUETOOTH_NAMESPACE
 
@@ -136,16 +137,28 @@ public:
   {
     NS_WARNING("Unable to get value for '" BLUETOOTH_ENABLED_SETTING "'");
     return NS_OK;
   }
 };
 
 NS_IMPL_ISUPPORTS1(BluetoothService::StartupTask, nsISettingsServiceCallback);
 
+BluetoothService::~BluetoothService()
+{
+  if (!gBluetoothService) {
+    return;
+  }
+
+  if (NS_FAILED(gBluetoothService->UnregisterBluetoothSignalHandler(
+      NS_LITERAL_STRING(LOCAL_AGENT_PATH), gBluetoothService))) {
+    NS_WARNING("Unresgister observer to register local agent failed!");
+  }
+}
+
 nsresult
 BluetoothService::RegisterBluetoothSignalHandler(const nsAString& aNodeName,
                                                  BluetoothSignalObserver* aHandler)
 {
   MOZ_ASSERT(NS_IsMainThread());
   BluetoothSignalObserverList* ol;
   if (!mBluetoothSignalObserverTable.Get(aNodeName, &ol)) {
     ol = new BluetoothSignalObserverList();
@@ -438,16 +451,23 @@ BluetoothService::Get()
   if (NS_FAILED(obs->AddObserver(service, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
                                  false)) ||
       NS_FAILED(obs->AddObserver(service, MOZSETTINGS_CHANGED_ID, false))) {
     NS_WARNING("AddObserver failed!");
     return nullptr;
   }
 
   gBluetoothService.swap(service);
+
+  if (NS_FAILED(gBluetoothService->RegisterBluetoothSignalHandler(
+    NS_LITERAL_STRING(LOCAL_AGENT_PATH), gBluetoothService))) {
+    NS_WARNING("Resgister observer to register local agent failed!");
+    return nullptr;
+  }
+
   return gBluetoothService;
 }
 
 nsresult
 BluetoothService::Observe(nsISupports* aSubject, const char* aTopic,
                           const PRUnichar* aData)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -462,8 +482,94 @@ BluetoothService::Observe(nsISupports* a
 
   if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
     return HandleShutdown();
   }
 
   MOZ_ASSERT(false, "BluetoothService got unexpected topic!");
   return NS_ERROR_UNEXPECTED;
 }
+
+bool
+SetJsObject(JSContext* aContext,
+            JSObject* aObj,
+            const InfallibleTArray<BluetoothNamedValue>& aData)
+{
+  for (int i = 0; i < aData.Length(); i++) {
+    jsval v;
+    if (aData[i].value().type() == BluetoothValue::TnsString) {
+      nsString data = aData[i].value().get_nsString();
+      JSString* JsData = JS_NewStringCopyN(aContext,
+                                           NS_ConvertUTF16toUTF8(data).get(),
+                                           data.Length());
+      NS_ENSURE_TRUE(JsData, NS_ERROR_OUT_OF_MEMORY);
+      v = STRING_TO_JSVAL(JsData);
+    } else if (aData[i].value().type() == BluetoothValue::Tuint32_t) {
+      int data = aData[i].value().get_uint32_t();
+      v = INT_TO_JSVAL(data);
+    } else {
+      NS_WARNING("SetJsObject: Parameter is not handled");
+    }
+
+    if (!JS_SetProperty(aContext, aObj,
+                        NS_ConvertUTF16toUTF8(aData[i].name()).get(),
+                        &v)) {
+      return false;
+    }
+  }
+  return true;
+}
+
+void
+BluetoothService::Notify(const BluetoothSignal& aData)
+{
+  InfallibleTArray<BluetoothNamedValue> arr = aData.value().get_ArrayOfBluetoothNamedValue();
+  nsString type;
+
+  JSContext* cx = nsContentUtils::GetSafeJSContext();
+  NS_ASSERTION(!::JS_IsExceptionPending(cx),
+               "Shouldn't get here when an exception is pending!");
+
+  JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
+  if (!obj) {
+    NS_WARNING("Failed to new JSObject for system message!");
+    return;
+  }
+
+  bool ok = SetJsObject(cx, obj, arr);
+  if (!ok) {
+    NS_WARNING("Failed to set properties of system message!");
+    return;
+  }
+
+  if (aData.name().EqualsLiteral("RequestConfirmation")) {
+    NS_ASSERTION(arr.Length() == 3, "RequestConfirmation: Wrong length of parameters");
+    type.AssignLiteral("bluetooth-requestconfirmation");
+  } else if (aData.name().EqualsLiteral("RequestPinCode")) {
+    NS_ASSERTION(arr.Length() == 2, "RequestPinCode: Wrong length of parameters");
+    type.AssignLiteral("bluetooth-requestpincode");
+  } else if (aData.name().EqualsLiteral("RequestPasskey")) {
+    NS_ASSERTION(arr.Length() == 2, "RequestPinCode: Wrong length of parameters");
+    type.AssignLiteral("bluetooth-requestpasskey");
+  } else if (aData.name().EqualsLiteral("Authorize")) {
+    NS_ASSERTION(arr.Length() == 2, "Authorize: Wrong length of parameters");
+    type.AssignLiteral("bluetooth-authorize");
+  } else if (aData.name().EqualsLiteral("Cancel")) {
+    NS_ASSERTION(arr.Length() == 0, "Cancel: Wrong length of parameters");
+    type.AssignLiteral("bluetooth-cancel");
+  } else {
+#ifdef DEBUG
+    nsCString warningMsg;
+    warningMsg.AssignLiteral("Not handling service signal: ");
+    warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
+    NS_WARNING(warningMsg.get());
+#endif
+  }
+
+  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
+    do_GetService("@mozilla.org/system-message-internal;1");
+
+  if (!systemMessenger) {
+    NS_WARNING("Failed to get SystemMessenger service!");
+    return;
+  }
+  systemMessenger->BroadcastMessage(type, OBJECT_TO_JSVAL(obj));
+}
--- a/dom/bluetooth/BluetoothService.h
+++ b/dom/bluetooth/BluetoothService.h
@@ -17,16 +17,17 @@
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothManager;
 class BluetoothNamedValue;
 class BluetoothReplyRunnable;
 class BluetoothSignal;
 
 class BluetoothService : public nsIObserver
+                       , public BluetoothSignalObserver
 {
   class ToggleBtAck;
   friend class ToggleBtAck;
 
   class ToggleBtTask;
   friend class ToggleBtTask;
 
   class StartupTask;
@@ -112,20 +113,26 @@ public:
    */
   void RegisterManager(BluetoothManager* aManager);
 
   /**
    * Called when a BluetoothManager is destroyed.
    */
   void UnregisterManager(BluetoothManager* aManager);
 
-  /** 
+  /**
+   * Called when get a Bluetooth Signal from BluetoothDBusService
+   *
+   */
+  void Notify(const BluetoothSignal& aParam);
+
+  /**
    * Returns the BluetoothService singleton. Only to be called from main thread.
    *
-   * @param aService Pointer to return singleton into. 
+   * @param aService Pointer to return singleton into.
    *
    * @return NS_OK on proper assignment, NS_ERROR_FAILURE otherwise (if service
    * has not yet been started, for instance)
    */
   static BluetoothService* Get();
 
   static already_AddRefed<BluetoothService> FactoryCreate()
   {
@@ -276,18 +283,17 @@ protected:
   : mEnabled(false)
 #ifdef DEBUG
     , mLastRequestedEnable(false)
 #endif
   {
     mBluetoothSignalObserverTable.Init();
   }
 
-  virtual ~BluetoothService()
-  { }
+  ~BluetoothService();
 
   nsresult StartStopBluetooth(bool aStart);
 
   // Called by ToggleBtAck.
   void SetEnabled(bool aEnabled);
 
   // This function is implemented in platform-specific BluetoothServiceFactory
   // files
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -41,18 +41,16 @@ CPPSRCS += \
 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)
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -332,36 +332,37 @@ AgentEventFilter(DBusConnection *conn, D
     // Return directly
     DBusMessage *reply = dbus_message_new_method_return(msg);
 
     if (!reply) {
       errorStr.AssignLiteral("Memory can't be allocated for the message.");
     } else {
       dbus_connection_send(conn, reply, NULL);
       dbus_message_unref(reply);
+      v = parameters;
     }
   } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE, "Authorize")) {
     // This method gets called when the service daemon needs to authorize a
     // connection/service request.
     char *objectPath;
     const char *uuid;
     if (!dbus_message_get_args(msg, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_STRING, &uuid,
                                DBUS_TYPE_INVALID)) {
       LOG("%s: Invalid arguments for Authorize() method", __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments for Authorize() method");
     } else {
       nsString deviceAddress = GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath));
 
-      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Device"), deviceAddress));
-      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("UUID"),
+      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("deviceAddress"), deviceAddress));
+      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("uuid"),
                                                    NS_ConvertUTF8toUTF16(uuid)));
 
-      // Because we may have authorization request and pairing request from the 
+      // Because we may have authorization request and pairing request from the
       // same remote device at the same time, we need two tables to keep these messages.
       sAuthorizeReqTable.Put(deviceAddress, msg);
 
       // Increase ref count here because we need this message later. 
       // It'll be unrefed when setAuthorizationInternal() is called.
       dbus_message_ref(msg);
 
       v = parameters;
@@ -374,56 +375,53 @@ AgentEventFilter(DBusConnection *conn, D
     if (!dbus_message_get_args(msg, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_UINT32, &passkey,
                                DBUS_TYPE_INVALID)) {
       LOG("%s: Invalid arguments for RequestConfirmation() method", __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments for RequestConfirmation() method");
     } else {
       nsString deviceAddress = GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath));
+      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("deviceAddress"), deviceAddress));
+      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("passkey"), passkey));
 
-      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Device"), deviceAddress));
-      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Passkey"), passkey));
-      
       KeepDBusPairingMessage(deviceAddress, msg);
 
       v = parameters;
     }
   } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE, "RequestPinCode")) {
     // This method gets called when the service daemon needs to get the passkey for an
     // authentication. The return value should be a string of 1-16 characters length.
     // The string can be alphanumeric.
     char *objectPath;
     if (!dbus_message_get_args(msg, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_INVALID)) {
       LOG("%s: Invalid arguments for RequestPinCode() method", __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments for RequestPinCode() method");
     } else {
       nsString deviceAddress = GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath));
-
-      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Device"), deviceAddress));
+      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("deviceAddress"), deviceAddress));
 
       KeepDBusPairingMessage(deviceAddress, msg);
 
       v = parameters;
     }
   } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE, "RequestPasskey")) {
     // This method gets called when the service daemon needs to get the passkey for an
     // authentication. The return value should be a numeric value between 0-999999.
     char *objectPath;
     if (!dbus_message_get_args(msg, NULL,
                                DBUS_TYPE_OBJECT_PATH, &objectPath,
                                DBUS_TYPE_INVALID)) {
       LOG("%s: Invalid arguments for RequestPasskey() method", __FUNCTION__);
       errorStr.AssignLiteral("Invalid arguments for RequestPasskey() method");
     } else {
       nsString deviceAddress = GetAddressFromObjectPath(NS_ConvertUTF8toUTF16(objectPath));
-
-      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Device"), deviceAddress));
+      parameters.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("deviceAddress"), deviceAddress));
 
       KeepDBusPairingMessage(deviceAddress, msg);
 
       v = parameters;
     }
   } else if (dbus_message_is_method_call(msg, DBUS_AGENT_IFACE, "Release")) {
     // This method gets called when the service daemon unregisters the agent. An agent
     // can use it to do cleanup tasks. There is no need to unregister the agent, because
deleted file mode 100644
--- a/dom/bluetooth/nsIDOMBluetoothAuthorizeEvent.idl
+++ /dev/null
@@ -1,26 +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"
-
-[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;
-};
deleted file mode 100644
--- a/dom/bluetooth/nsIDOMBluetoothPairingEvent.idl
+++ /dev/null
@@ -1,26 +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"
-
-[scriptable, builtinclass, uuid(333022b8-a7e5-4fff-8588-36f2eedff17e)]
-interface nsIDOMBluetoothPairingEvent : nsIDOMEvent
-{
-  readonly attribute DOMString deviceAddress;
-  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
@@ -18,20 +18,18 @@ simple_events = [
     'PopStateEvent',
     'HashChangeEvent',
     'CloseEvent',
     'MozContactChangeEvent',
     'DeviceOrientationEvent',
     'DeviceLightEvent',
     'MozApplicationEvent',
 #ifdef MOZ_B2G_BT
-    'BluetoothAuthorizeEvent',
     'BluetoothDeviceEvent',
     'BluetoothDeviceAddressEvent',
-    'BluetoothPairingEvent',
 #endif
     'DeviceStorageChangeEvent',
     'PopupBlockedEvent'
   ]
 
 """ include file names """
 special_includes = [
     'DictionaryHelpers.h',