Bug 778640 - Final version: Firing devicedisappeared event, create nsIDOMBluetoothDeviceAddressEvent by event generator, r=qdot, r=smaug
authorGina Yeh <gyeh@mozilla.com>
Fri, 17 Aug 2012 12:02:52 +0800
changeset 108077 26ae4450ab79d1a4b0cf4dd2be81775b79aa284b
parent 108076 016e279674347ecd82b1ae1c23b96954e8fdeb52
child 108078 7fe1c2d3d1f41e90160ea520d45eafb9bcf90523
push id1490
push userakeybl@mozilla.com
push dateMon, 08 Oct 2012 18:29:50 +0000
treeherdermozilla-beta@f335e7dacdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot, smaug
bugs778640, 100644
milestone17.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 778640 - Final version: Firing devicedisappeared event, create nsIDOMBluetoothDeviceAddressEvent by event generator, r=qdot, r=smaug --- dom/bluetooth/BluetoothAdapter.cpp | 17 +++++++++++++++- dom/bluetooth/Makefile.in | 1 + .../nsIDOMBluetoothDeviceAddressEvent.idl | 21 ++++++++++++++++++++ js/xpconnect/src/event_impl_gen.conf.in | 3 ++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 dom/bluetooth/nsIDOMBluetoothDeviceAddressEvent.idl
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/Makefile.in
dom/bluetooth/nsIDOMBluetoothDeviceAddressEvent.idl
js/xpconnect/src/event_impl_gen.conf.in
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -9,21 +9,23 @@
 #include "BluetoothDevice.h"
 #include "BluetoothDeviceEvent.h"
 #include "BluetoothPropertyEvent.h"
 #include "BluetoothService.h"
 #include "BluetoothTypes.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothUtils.h"
 
+#include "GeneratedEvents.h"
 #include "nsDOMClassInfo.h"
 #include "nsDOMEvent.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsIDOMDOMRequest.h"
+#include "nsIDOMBluetoothDeviceAddressEvent.h"
 #include "nsContentUtils.h"
 
 #include "mozilla/LazyIdleThread.h"
 #include "mozilla/Util.h"
 
 using namespace mozilla;
 
 USING_BLUETOOTH_NAMESPACE
@@ -267,16 +269,29 @@ BluetoothAdapter::Create(nsPIDOMWindow* 
 
 void
 BluetoothAdapter::Notify(const BluetoothSignal& aData)
 {
   if (aData.name().EqualsLiteral("DeviceFound")) {
     nsRefPtr<BluetoothDevice> d = BluetoothDevice::Create(GetOwner(), mPath, aData.value());
     nsRefPtr<BluetoothDeviceEvent> e = BluetoothDeviceEvent::Create(d);
     e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("devicefound"));
+  } else if (aData.name().EqualsLiteral("DeviceDisappeared")) {
+    const nsAString& deviceAddress = aData.value().get_nsString();
+
+    nsCOMPtr<nsIDOMEvent> event;
+    NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr);
+
+    nsCOMPtr<nsIDOMBluetoothDeviceAddressEvent> e = do_QueryInterface(event);
+    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
     InfallibleTArray<BluetoothNamedValue> 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;
     }
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -40,16 +40,17 @@ CPPSRCS += \
   $(NULL)
 
 XPIDLSRCS = \
   nsIDOMNavigatorBluetooth.idl \
   nsIDOMBluetoothManager.idl \
   nsIDOMBluetoothAdapter.idl \
   nsIDOMBluetoothDevice.idl \
   nsIDOMBluetoothDeviceEvent.idl \
+  nsIDOMBluetoothDeviceAddressEvent.idl \
   nsIDOMBluetoothPropertyEvent.idl \
   $(NULL)
 
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 VPATH += \
 	$(srcdir)/linux \
 	$(srcdir)/gonk \
 	$(NULL)
new file mode 100644
--- /dev/null
+++ b/dom/bluetooth/nsIDOMBluetoothDeviceAddressEvent.idl
@@ -0,0 +1,21 @@
+/* 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(afcb832f-bbb5-45fa-b703-f8185bd2d26d)]
+interface nsIDOMBluetoothDeviceAddressEvent : nsIDOMEvent
+{
+  readonly attribute DOMString  deviceAddress;
+
+  [noscript] void initBluetoothDeviceAddressEvent(in DOMString aType,
+                                                  in boolean aCanBubble,
+                                                  in boolean aCancelable,
+                                                  in DOMString aDeviceAddress);
+};
+
+dictionary BluetoothDeviceAddressEventInit : EventInit
+{
+  DOMString  deviceAddress;
+};
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -16,17 +16,18 @@ simple_events = [
     'PageTransitionEvent',
     'PopStateEvent',
     'HashChangeEvent',
     'CloseEvent',
     'MozContactChangeEvent',
     'DeviceOrientationEvent',
     'DeviceLightEvent',
     'MozApplicationEvent',
-    'DeviceStorageChangeEvent'
+    'DeviceStorageChangeEvent',
+    'BluetoothDeviceAddressEvent'
   ]
 
 """ include file names """
 special_includes = [
     'DictionaryHelpers.h',
     'nsContentUtils.h',
     'nsIDOMApplicationRegistry.h'
   ]