diff --git a/dom/bluetooth/BluetoothAdapter.cpp b/dom/bluetooth/BluetoothAdapter.cpp index 545055c2f6dd..5f33a587490f 100644 --- a/dom/bluetooth/BluetoothAdapter.cpp +++ b/dom/bluetooth/BluetoothAdapter.cpp @@ -14,11 +14,13 @@ #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" @@ -272,6 +274,19 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData) nsRefPtr d = BluetoothDevice::Create(GetOwner(), mPath, aData.value()); nsRefPtr 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 event; + NS_NewDOMBluetoothDeviceAddressEvent(getter_AddRefs(event), nullptr, nullptr); + + nsCOMPtr 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 arr = aData.value().get_ArrayOfBluetoothNamedValue(); diff --git a/dom/bluetooth/Makefile.in b/dom/bluetooth/Makefile.in index 097a79cf8c25..e5659abd7980 100644 --- a/dom/bluetooth/Makefile.in +++ b/dom/bluetooth/Makefile.in @@ -45,6 +45,7 @@ XPIDLSRCS = \ nsIDOMBluetoothAdapter.idl \ nsIDOMBluetoothDevice.idl \ nsIDOMBluetoothDeviceEvent.idl \ + nsIDOMBluetoothDeviceAddressEvent.idl \ nsIDOMBluetoothPropertyEvent.idl \ $(NULL) diff --git a/dom/bluetooth/nsIDOMBluetoothDeviceAddressEvent.idl b/dom/bluetooth/nsIDOMBluetoothDeviceAddressEvent.idl new file mode 100644 index 000000000000..f89783e4f3ed --- /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; +}; diff --git a/js/xpconnect/src/event_impl_gen.conf.in b/js/xpconnect/src/event_impl_gen.conf.in index 72ea8454445d..54d706483145 100644 --- a/js/xpconnect/src/event_impl_gen.conf.in +++ b/js/xpconnect/src/event_impl_gen.conf.in @@ -21,7 +21,8 @@ simple_events = [ 'DeviceOrientationEvent', 'DeviceLightEvent', 'MozApplicationEvent', - 'DeviceStorageChangeEvent' + 'DeviceStorageChangeEvent', + 'BluetoothDeviceAddressEvent' ] """ include file names """