From 38795b8dfe43da3079ce6de72b353cedb830f163 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Mon, 12 Aug 2013 10:34:28 +0200 Subject: [PATCH] Bug 888595: Converted BluetoothDevice to WebIDL, r=bzbarsky,echou We keep the old XPIDL files in place to stay compatible with existing code. They can probably be removed when all bindings have been converted to WebIDL. --HG-- extra : rebase_source : b6612fbd237d89bd02a2fde34e121691be3c0f08 --- dom/bindings/Bindings.conf | 7 +- dom/bindings/Makefile.in | 2 +- dom/bluetooth/BluetoothAdapter.cpp | 8 +-- dom/bluetooth/BluetoothAdapter.h | 7 +- dom/bluetooth/BluetoothDevice.cpp | 89 ++++++++----------------- dom/bluetooth/BluetoothDevice.h | 42 ++++++++++++ dom/bluetooth/nsIDOMBluetoothDevice.idl | 12 +--- dom/webidl/BluetoothDevice.webidl | 22 ++++++ dom/webidl/BluetoothDeviceEvent.webidl | 1 - dom/webidl/WebIDL.mk | 1 + js/xpconnect/src/Makefile.in | 6 ++ js/xpconnect/src/event_impl_gen.conf.in | 1 + 12 files changed, 117 insertions(+), 81 deletions(-) create mode 100644 dom/webidl/BluetoothDevice.webidl diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index fd3e0171ed1..c9d80b5e776 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -155,6 +155,11 @@ DOMInterfaces = { 'headerFile': 'BluetoothAdapter.h' }, +'BluetoothDevice': { + 'nativeType': 'mozilla::dom::bluetooth::BluetoothDevice', + 'headerFile': 'BluetoothDevice.h' +}, + 'BluetoothManager': { 'nativeType': 'mozilla::dom::bluetooth::BluetoothManager', 'headerFile': 'BluetoothManager.h' @@ -1732,8 +1737,6 @@ def addExternalIface(iface, nativeType=None, headerFile=None, addExternalIface('ActivityOptions', nativeType='nsIDOMMozActivityOptions', headerFile='nsIDOMActivityOptions.h') -addExternalIface('BluetoothDevice', nativeType='nsIDOMBluetoothDevice', - headerFile='nsIDOMBluetoothDevice.h') addExternalIface('Counter') addExternalIface('CSSRule') addExternalIface('DeviceAcceleration', headerFile='nsIDOMDeviceMotionEvent.h', notflattened=True) diff --git a/dom/bindings/Makefile.in b/dom/bindings/Makefile.in index 6e224087e6f..f19b20ce078 100644 --- a/dom/bindings/Makefile.in +++ b/dom/bindings/Makefile.in @@ -205,7 +205,7 @@ ParserResults.pkl: $(globalgen_dependencies) --cachedir=$(CACHE_DIR) \ $(all_webidl_files) -# Make sure .deps actually exists, since we'll try to write to it from +# Make sure .deps actually exists, since we'll try to write to it from # BindingGen.py but we're typically running in the export phase, which is # before anyone has bothered creating .deps. # Then, pass our long lists through files to try to avoid blowing out the diff --git a/dom/bluetooth/BluetoothAdapter.cpp b/dom/bluetooth/BluetoothAdapter.cpp index 1cb8100c099..209ba52fcbb 100644 --- a/dom/bluetooth/BluetoothAdapter.cpp +++ b/dom/bluetooth/BluetoothAdapter.cpp @@ -519,7 +519,7 @@ BluetoothAdapter::GetPairedDevices(ErrorResult& aRv) } already_AddRefed -BluetoothAdapter::PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice, +BluetoothAdapter::PairUnpair(bool aPair, BluetoothDevice& aDevice, ErrorResult& aRv) { nsCOMPtr win = GetOwner(); @@ -533,7 +533,7 @@ BluetoothAdapter::PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice, new BluetoothVoidReplyRunnable(request); nsAutoString addr; - aDevice->GetAddress(addr); + aDevice.GetAddress(addr); BluetoothService* bs = BluetoothService::Get(); if (!bs) { @@ -558,13 +558,13 @@ BluetoothAdapter::PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice, } already_AddRefed -BluetoothAdapter::Pair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv) +BluetoothAdapter::Pair(BluetoothDevice& aDevice, ErrorResult& aRv) { return PairUnpair(true, aDevice, aRv); } already_AddRefed -BluetoothAdapter::Unpair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv) +BluetoothAdapter::Unpair(BluetoothDevice& aDevice, ErrorResult& aRv) { return PairUnpair(false, aDevice, aRv); } diff --git a/dom/bluetooth/BluetoothAdapter.h b/dom/bluetooth/BluetoothAdapter.h index 216d93870a3..6cbae309601 100644 --- a/dom/bluetooth/BluetoothAdapter.h +++ b/dom/bluetooth/BluetoothAdapter.h @@ -24,6 +24,7 @@ struct MediaPlayStatus; BEGIN_BLUETOOTH_NAMESPACE +class BluetoothDevice; class BluetoothSignal; class BluetoothNamedValue; class BluetoothValue; @@ -95,9 +96,9 @@ public: already_AddRefed StopDiscovery(ErrorResult& aRv); already_AddRefed - Pair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv); + Pair(BluetoothDevice& aDevice, ErrorResult& aRv); already_AddRefed - Unpair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv); + Unpair(BluetoothDevice& aDevice, ErrorResult& aRv); already_AddRefed GetPairedDevices(ErrorResult& aRv); already_AddRefed @@ -162,7 +163,7 @@ private: already_AddRefed StartStopDiscovery(bool aStart, ErrorResult& aRv); already_AddRefed - PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv); + PairUnpair(bool aPair, BluetoothDevice& aDevice, ErrorResult& aRv); JS::Heap mJsUuids; JS::Heap mJsDeviceAddresses; diff --git a/dom/bluetooth/BluetoothDevice.cpp b/dom/bluetooth/BluetoothDevice.cpp index d623741c5eb..141fc0b9dc5 100644 --- a/dom/bluetooth/BluetoothDevice.cpp +++ b/dom/bluetooth/BluetoothDevice.cpp @@ -15,6 +15,7 @@ #include "nsTArrayHelpers.h" #include "mozilla/dom/bluetooth/BluetoothTypes.h" +#include "mozilla/dom/BluetoothDeviceBinding.h" USING_BLUETOOTH_NAMESPACE @@ -48,14 +49,16 @@ NS_IMPL_RELEASE_INHERITED(BluetoothDevice, nsDOMEventTargetHelper) BluetoothDevice::BluetoothDevice(nsPIDOMWindow* aWindow, const nsAString& aAdapterPath, - const BluetoothValue& aValue) : - BluetoothPropertyContainer(BluetoothObjectType::TYPE_DEVICE), - mJsUuids(nullptr), - mJsServices(nullptr), - mAdapterPath(aAdapterPath), - mIsRooted(false) + const BluetoothValue& aValue) + : nsDOMEventTargetHelper(aWindow) + , BluetoothPropertyContainer(BluetoothObjectType::TYPE_DEVICE) + , mJsUuids(nullptr) + , mJsServices(nullptr) + , mAdapterPath(aAdapterPath) + , mIsRooted(false) { MOZ_ASSERT(aWindow); + MOZ_ASSERT(IsDOMBinding()); BindToOwner(aWindow); const InfallibleTArray& values = @@ -195,68 +198,32 @@ BluetoothDevice::Notify(const BluetoothSignal& aData) } } -NS_IMETHODIMP -BluetoothDevice::GetAddress(nsAString& aAddress) +JS::Value +BluetoothDevice::GetUuids(JSContext* aCx, ErrorResult& aRv) { - aAddress = mAddress; - return NS_OK; -} - -NS_IMETHODIMP -BluetoothDevice::GetName(nsAString& aName) -{ - aName = mName; - return NS_OK; -} - -NS_IMETHODIMP -BluetoothDevice::GetIcon(nsAString& aIcon) -{ - aIcon = mIcon; - return NS_OK; -} - -NS_IMETHODIMP -BluetoothDevice::GetDeviceClass(uint32_t* aClass) -{ - *aClass = mClass; - return NS_OK; -} - -NS_IMETHODIMP -BluetoothDevice::GetPaired(bool* aPaired) -{ - *aPaired = mPaired; - return NS_OK; -} - -NS_IMETHODIMP -BluetoothDevice::GetConnected(bool* aConnected) -{ - *aConnected = mConnected; - return NS_OK; -} - -NS_IMETHODIMP -BluetoothDevice::GetUuids(JSContext* aCx, JS::Value* aUuids) -{ - if (mJsUuids) { - aUuids->setObject(*mJsUuids); - } else { + if (!mJsUuids) { NS_WARNING("UUIDs not yet set!\n"); - return NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); + return JS::NullValue(); } - return NS_OK; + + return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsUuids)); } -NS_IMETHODIMP -BluetoothDevice::GetServices(JSContext* aCx, JS::Value* aServices) +JS::Value +BluetoothDevice::GetServices(JSContext* aCx, ErrorResult& aRv) { - if (mJsServices) { - aServices->setObject(*mJsServices); - } else { + if (!mJsServices) { NS_WARNING("Services not yet set!\n"); + aRv.Throw(NS_ERROR_FAILURE); + return JS::Value(JSVAL_NULL); } - return NS_OK; + + return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsServices)); } +JSObject* +BluetoothDevice::WrapObject(JSContext* aContext, JS::Handle aScope) +{ + return BluetoothDeviceBinding::Wrap(aContext, aScope, this); +} diff --git a/dom/bluetooth/BluetoothDevice.h b/dom/bluetooth/BluetoothDevice.h index 7bba48c8350..4e872671fdc 100644 --- a/dom/bluetooth/BluetoothDevice.h +++ b/dom/bluetooth/BluetoothDevice.h @@ -43,6 +43,39 @@ public: void Notify(const BluetoothSignal& aParam); + void GetAddress(nsString& aAddress) const + { + aAddress = mAddress; + } + + void GetName(nsString& aName) const + { + aName = mName; + } + + void GetIcon(nsString& aIcon) const + { + aIcon = mIcon; + } + + uint32_t Class() const + { + return mClass; + } + + bool Paired() const + { + return mPaired; + } + + bool Connected() const + { + return mConnected; + } + + JS::Value GetUuids(JSContext* aContext, ErrorResult& aRv); + JS::Value GetServices(JSContext* aContext, ErrorResult& aRv); + nsISupports* ToISupports() { @@ -52,6 +85,15 @@ public: void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE; void Unroot(); + + nsPIDOMWindow* GetParentObject() const + { + return GetOwner(); + } + + virtual JSObject* + WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; + private: BluetoothDevice(nsPIDOMWindow* aOwner, const nsAString& aAdapterPath, const BluetoothValue& aValue); diff --git a/dom/bluetooth/nsIDOMBluetoothDevice.idl b/dom/bluetooth/nsIDOMBluetoothDevice.idl index 2444e1928ec..9e6fd48158e 100644 --- a/dom/bluetooth/nsIDOMBluetoothDevice.idl +++ b/dom/bluetooth/nsIDOMBluetoothDevice.idl @@ -6,15 +6,9 @@ #include "nsIDOMEventTarget.idl" -[scriptable, builtinclass, uuid(7297ef65-db38-45f1-a5dc-b7347aaa223d)] +// 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 { - readonly attribute DOMString address; - readonly attribute DOMString name; - readonly attribute DOMString icon; - [binaryname(DeviceClass)] readonly attribute unsigned long class; - [implicit_jscontext] readonly attribute jsval uuids; - [implicit_jscontext] readonly attribute jsval services; - readonly attribute bool connected; - readonly attribute bool paired; }; diff --git a/dom/webidl/BluetoothDevice.webidl b/dom/webidl/BluetoothDevice.webidl new file mode 100644 index 00000000000..808e1e342eb --- /dev/null +++ b/dom/webidl/BluetoothDevice.webidl @@ -0,0 +1,22 @@ +/* -*- 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/. */ + +interface BluetoothDevice : EventTarget { + readonly attribute DOMString address; + readonly attribute DOMString name; + readonly attribute DOMString icon; + readonly attribute boolean connected; + readonly attribute boolean paired; + readonly attribute unsigned long class; + + // array of type DOMString[] + [Throws] + readonly attribute any uuids; + + // array of type DOMString[] + [Throws] + readonly attribute any services; +}; diff --git a/dom/webidl/BluetoothDeviceEvent.webidl b/dom/webidl/BluetoothDeviceEvent.webidl index 744e0861e51..55b31a69261 100644 --- a/dom/webidl/BluetoothDeviceEvent.webidl +++ b/dom/webidl/BluetoothDeviceEvent.webidl @@ -3,7 +3,6 @@ * 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/. */ -interface BluetoothDevice; [Constructor(DOMString type, optional BluetoothDeviceEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"] interface BluetoothDeviceEvent : Event diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index f6833a6c7dc..e18d735113c 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -476,6 +476,7 @@ webidl_files += \ ifdef MOZ_B2G_BT webidl_files += \ BluetoothAdapter.webidl \ + BluetoothDevice.webidl \ BluetoothDeviceEvent.webidl \ BluetoothManager.webidl \ BluetoothStatusChangedEvent.webidl \ diff --git a/js/xpconnect/src/Makefile.in b/js/xpconnect/src/Makefile.in index 4867c7edfd1..31b690c6c22 100644 --- a/js/xpconnect/src/Makefile.in +++ b/js/xpconnect/src/Makefile.in @@ -34,6 +34,12 @@ LOCAL_INCLUDES = \ -I$(topsrcdir)/js/ipc \ $(NULL) +ifdef MOZ_B2G_BT +LOCAL_INCLUDES += \ + -I$(topsrcdir)/dom/bluetooth \ + $(NULL) +endif + SHARED_LIBRARY_LIBS = \ ../loader/$(LIB_PREFIX)jsloader_s.$(LIB_SUFFIX) \ ../wrappers/$(LIB_PREFIX)xpcwrappers_s.$(LIB_SUFFIX) \ diff --git a/js/xpconnect/src/event_impl_gen.conf.in b/js/xpconnect/src/event_impl_gen.conf.in index 7b88abfc650..44076e15b91 100644 --- a/js/xpconnect/src/event_impl_gen.conf.in +++ b/js/xpconnect/src/event_impl_gen.conf.in @@ -77,6 +77,7 @@ exclude_automatic_type_include = [ """ 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'],