Bug 888595: Converted BluetoothDevice to WebIDL, r=bzbarsky,echou
☠☠ backed out by cc21c678172d ☠ ☠
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 12 Aug 2013 10:34:28 +0200
changeset 142310 6855c55668a70054129d6d61e77f41f0a5f37a25
parent 142309 4ce3e048289cb3640577e5d43841ef8b2270c61d
child 142311 e999ab01a7eb434c9906b8a220b349d8e40ac5ea
push id32372
push userryanvm@gmail.com
push dateTue, 13 Aug 2013 01:59:20 +0000
treeherdermozilla-inbound@86b6480829c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, echou
bugs888595
milestone26.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 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.
dom/bindings/Bindings.conf
dom/bindings/Makefile.in
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothAdapter.h
dom/bluetooth/BluetoothDevice.cpp
dom/bluetooth/BluetoothDevice.h
dom/bluetooth/nsIDOMBluetoothDevice.idl
dom/webidl/BluetoothDevice.webidl
dom/webidl/BluetoothDeviceEvent.webidl
dom/webidl/WebIDL.mk
js/xpconnect/src/Makefile.in
js/xpconnect/src/event_impl_gen.conf.in
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -150,16 +150,21 @@ DOMInterfaces = {
     'headerFile': 'BatteryManager.h'
 },
 
 'BluetoothAdapter': {
     'nativeType': 'mozilla::dom::bluetooth::BluetoothAdapter',
     'headerFile': 'BluetoothAdapter.h'
 },
 
+'BluetoothDevice': {
+    'nativeType': 'mozilla::dom::bluetooth::BluetoothDevice',
+    'headerFile': 'BluetoothDevice.h'
+},
+
 'BluetoothManager': {
     'nativeType': 'mozilla::dom::bluetooth::BluetoothManager',
     'headerFile': 'BluetoothManager.h'
 },
 
 'CallEvent': {
     'nativeType': 'mozilla::dom::telephony::CallEvent',
     'headerFile': 'CallEvent.h',
@@ -1727,18 +1732,16 @@ def addExternalIface(iface, nativeType=N
         domInterface['nativeType'] = nativeType
     if not headerFile is None:
         domInterface['headerFile'] = headerFile
     domInterface['notflattened'] = notflattened
     DOMInterfaces[iface] = domInterface
 
 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)
 addExternalIface('DeviceRotationRate', headerFile='nsIDOMDeviceMotionEvent.h', notflattened=True)
 addExternalIface('mozIDOMApplication', nativeType='mozIDOMApplication', headerFile='nsIDOMApplicationRegistry.h')
 addExternalIface('CSSRuleList')
 addExternalIface('DOMStringList')
 addExternalIface('RTCDataChannel', nativeType='nsIDOMDataChannel')
--- a/dom/bindings/Makefile.in
+++ b/dom/bindings/Makefile.in
@@ -200,17 +200,17 @@ globalgen_dependencies := \
 # Running GlobalGen.py updates ParserResults.pkl as a side-effect
 ParserResults.pkl: $(globalgen_dependencies)
 	PYTHONDONTWRITEBYTECODE=1 $(PYTHON) $(topsrcdir)/config/pythonpath.py \
 	  $(PLY_INCLUDE) -I$(srcdir)/parser \
 	  $(srcdir)/GlobalGen.py $(srcdir)/Bindings.conf . \
 	  --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
 # command line.
 # Next, BindingGen.py will examine the changed dependency list to figure out
 # what it really needs to regenerate.
 # Finally, touch the .BindingGen file so that we don't have to keep redoing
 # all that until something else actually changes.
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -514,31 +514,31 @@ BluetoothAdapter::GetPairedDevices(Error
     aRv.Throw(rv);
     return nullptr;
   }
 
   return request.forget();
 }
 
 already_AddRefed<DOMRequest>
-BluetoothAdapter::PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice,
+BluetoothAdapter::PairUnpair(bool aPair, BluetoothDevice& aDevice,
                              ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindow> win = GetOwner();
   if (!win) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
     new BluetoothVoidReplyRunnable(request);
 
   nsAutoString addr;
-  aDevice->GetAddress(addr);
+  aDevice.GetAddress(addr);
 
   BluetoothService* bs = BluetoothService::Get();
   if (!bs) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
   nsresult rv;
   if (aPair) {
@@ -553,23 +553,23 @@ BluetoothAdapter::PairUnpair(bool aPair,
     aRv.Throw(rv);
     return nullptr;
   }
 
   return request.forget();
 }
 
 already_AddRefed<DOMRequest>
-BluetoothAdapter::Pair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv)
+BluetoothAdapter::Pair(BluetoothDevice& aDevice, ErrorResult& aRv)
 {
   return PairUnpair(true, aDevice, aRv);
 }
 
 already_AddRefed<DOMRequest>
-BluetoothAdapter::Unpair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv)
+BluetoothAdapter::Unpair(BluetoothDevice& aDevice, ErrorResult& aRv)
 {
   return PairUnpair(false, aDevice, aRv);
 }
 
 already_AddRefed<DOMRequest>
 BluetoothAdapter::SetPinCode(const nsAString& aDeviceAddress,
                              const nsAString& aPinCode, ErrorResult& aRv)
 {
--- a/dom/bluetooth/BluetoothAdapter.h
+++ b/dom/bluetooth/BluetoothAdapter.h
@@ -19,16 +19,17 @@ namespace dom {
 class DOMRequest;
 struct MediaMetaData;
 struct MediaPlayStatus;
 }
 }
 
 BEGIN_BLUETOOTH_NAMESPACE
 
+class BluetoothDevice;
 class BluetoothSignal;
 class BluetoothNamedValue;
 class BluetoothValue;
 
 class BluetoothAdapter : public nsDOMEventTargetHelper
                        , public BluetoothSignalObserver
                        , public BluetoothPropertyContainer
 {
@@ -90,19 +91,19 @@ public:
   already_AddRefed<DOMRequest>
     SetDiscoverable(bool aDiscoverable, ErrorResult& aRv);
   already_AddRefed<DOMRequest>
     SetDiscoverableTimeout(uint32_t aTimeout, ErrorResult& aRv);
   already_AddRefed<DOMRequest> StartDiscovery(ErrorResult& aRv);
   already_AddRefed<DOMRequest> StopDiscovery(ErrorResult& aRv);
 
   already_AddRefed<DOMRequest>
-    Pair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv);
+    Pair(BluetoothDevice& aDevice, ErrorResult& aRv);
   already_AddRefed<DOMRequest>
-    Unpair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv);
+    Unpair(BluetoothDevice& aDevice, ErrorResult& aRv);
   already_AddRefed<DOMRequest>
     GetPairedDevices(ErrorResult& aRv);
   already_AddRefed<DOMRequest>
     SetPinCode(const nsAString& aDeviceAddress, const nsAString& aPinCode,
                ErrorResult& aRv);
   already_AddRefed<DOMRequest>
     SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
                ErrorResult& aRv);
@@ -157,17 +158,17 @@ private:
   BluetoothAdapter(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
   ~BluetoothAdapter();
 
   void Root();
 
   already_AddRefed<mozilla::dom::DOMRequest>
     StartStopDiscovery(bool aStart, ErrorResult& aRv);
   already_AddRefed<mozilla::dom::DOMRequest>
-    PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv);
+    PairUnpair(bool aPair, BluetoothDevice& aDevice, ErrorResult& aRv);
 
   JS::Heap<JSObject*> mJsUuids;
   JS::Heap<JSObject*> mJsDeviceAddresses;
   nsString mAddress;
   nsString mName;
   bool mDiscoverable;
   bool mDiscovering;
   bool mPairable;
--- a/dom/bluetooth/BluetoothDevice.cpp
+++ b/dom/bluetooth/BluetoothDevice.cpp
@@ -10,16 +10,17 @@
 #include "BluetoothService.h"
 #include "BluetoothUtils.h"
 
 #include "nsDOMClassInfo.h"
 #include "nsContentUtils.h"
 #include "nsTArrayHelpers.h"
 
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
+#include "mozilla/dom/BluetoothDeviceBinding.h"
 
 USING_BLUETOOTH_NAMESPACE
 
 DOMCI_DATA(BluetoothDevice, BluetoothDevice)
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothDevice)
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothDevice,
@@ -43,24 +44,26 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothDevice)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(BluetoothDevice, nsDOMEventTargetHelper)
 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<BluetoothNamedValue>& values =
     aValue.get_ArrayOfBluetoothNamedValue();
   for (uint32_t i = 0; i < values.Length(); ++i) {
     SetPropertyByValue(values[i]);
   }
 
@@ -190,73 +193,37 @@ BluetoothDevice::Notify(const BluetoothS
     nsCString warningMsg;
     warningMsg.AssignLiteral("Not handling device signal: ");
     warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
     NS_WARNING(warningMsg.get());
 #endif
   }
 }
 
-NS_IMETHODIMP
-BluetoothDevice::GetAddress(nsAString& aAddress)
-{
-  aAddress = mAddress;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothDevice::GetName(nsAString& aName)
+JS::Value
+BluetoothDevice::GetUuids(JSContext* aCx, ErrorResult& aRv)
 {
-  aName = mName;
-  return NS_OK;
-}
+  if (!mJsUuids) {
+    NS_WARNING("UUIDs not yet set!\n");
+    aRv.Throw(NS_ERROR_FAILURE);
+    return JS::NullValue();
+  }
 
-NS_IMETHODIMP
-BluetoothDevice::GetIcon(nsAString& aIcon)
-{
-  aIcon = mIcon;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothDevice::GetDeviceClass(uint32_t* aClass)
-{
-  *aClass = mClass;
-  return NS_OK;
+  return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsUuids));
 }
 
-NS_IMETHODIMP
-BluetoothDevice::GetPaired(bool* aPaired)
+JS::Value
+BluetoothDevice::GetServices(JSContext* aCx, ErrorResult& aRv)
 {
-  *aPaired = mPaired;
-  return NS_OK;
-}
+  if (!mJsServices) {
+    NS_WARNING("Services not yet set!\n");
+    aRv.Throw(NS_ERROR_FAILURE);
+    return JS::Value(JSVAL_NULL);
+  }
 
-NS_IMETHODIMP
-BluetoothDevice::GetConnected(bool* aConnected)
-{
-  *aConnected = mConnected;
-  return NS_OK;
+  return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsServices));
 }
 
-NS_IMETHODIMP
-BluetoothDevice::GetUuids(JSContext* aCx, JS::Value* aUuids)
+JSObject*
+BluetoothDevice::WrapObject(JSContext* aContext, JS::Handle<JSObject*> aScope)
 {
-  if (mJsUuids) {
-    aUuids->setObject(*mJsUuids);
-  } else {
-    NS_WARNING("UUIDs not yet set!\n");
-    return NS_ERROR_FAILURE;
-  }
-  return NS_OK;
+  return BluetoothDeviceBinding::Wrap(aContext, aScope, this);
 }
-
-NS_IMETHODIMP
-BluetoothDevice::GetServices(JSContext* aCx, JS::Value* aServices)
-{
-  if (mJsServices) {
-    aServices->setObject(*mJsServices);
-  } else {
-    NS_WARNING("Services not yet set!\n");
-  }
-  return NS_OK;
-}
-
--- a/dom/bluetooth/BluetoothDevice.h
+++ b/dom/bluetooth/BluetoothDevice.h
@@ -38,25 +38,67 @@ public:
                                                          nsDOMEventTargetHelper)
 
   static already_AddRefed<BluetoothDevice>
   Create(nsPIDOMWindow* aOwner, const nsAString& aAdapterPath,
          const BluetoothValue& aValue);
 
   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()
   {
     return static_cast<EventTarget*>(this);
   }
 
   void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;
 
   void Unroot();
+
+  nsPIDOMWindow* GetParentObject() const
+  {
+     return GetOwner();
+  }
+
+  virtual JSObject*
+    WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+
 private:
   BluetoothDevice(nsPIDOMWindow* aOwner, const nsAString& aAdapterPath,
                   const BluetoothValue& aValue);
   ~BluetoothDevice();
   void Root();
 
   JS::Heap<JSObject*> mJsUuids;
   JS::Heap<JSObject*> mJsServices;
--- a/dom/bluetooth/nsIDOMBluetoothDevice.idl
+++ b/dom/bluetooth/nsIDOMBluetoothDevice.idl
@@ -1,20 +1,14 @@
 /* -*- 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 "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;
 };
new file mode 100644
--- /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;
+};
--- a/dom/webidl/BluetoothDeviceEvent.webidl
+++ b/dom/webidl/BluetoothDeviceEvent.webidl
@@ -1,14 +1,13 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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;
 
 [Constructor(DOMString type, optional BluetoothDeviceEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
 interface BluetoothDeviceEvent : Event
 {
   readonly attribute BluetoothDevice? device;
 };
 
 dictionary BluetoothDeviceEventInit : EventInit
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -471,16 +471,17 @@ webidl_files += \
   StyleSheetApplicableStateChangeEvent.webidl \
   StyleSheetChangeEvent.webidl \
   UserProximityEvent.webidl \
   $(NULL)
 
 ifdef MOZ_B2G_BT
 webidl_files += \
   BluetoothAdapter.webidl \
+  BluetoothDevice.webidl \
   BluetoothDeviceEvent.webidl \
   BluetoothManager.webidl \
   BluetoothStatusChangedEvent.webidl \
   $(NULL)
 endif
 
 ifdef MOZ_B2G_RIL
 webidl_files += \
--- a/js/xpconnect/src/Makefile.in
+++ b/js/xpconnect/src/Makefile.in
@@ -29,16 +29,22 @@ LOCAL_INCLUDES = \
 		-I$(topsrcdir)/content/svg/content/src \
 		-I$(topsrcdir)/layout/style \
 		-I$(topsrcdir)/layout/base \
 		-I$(topsrcdir)/dom/base \
 		-I$(topsrcdir)/xpcom/ds \
 		-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) \
   $(NULL)
 
 EXTRA_MDDEPEND_FILES = dom_qsgen.pp dictionary_helper_gen.pp event_impl_gen.pp
 
 include $(topsrcdir)/config/rules.mk
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -72,14 +72,15 @@ special_includes = [
 exclude_automatic_type_include = [
     'nsISupports',
     'mozIDOMApplication',
     'nsIDOMBlob'
   ]
 
 """ 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'],
     ['nsIDOMGamepad', 'Gamepad', 'nsIDOMGamepad']
   ]