Bug 888595: Converted BluetoothAdapter to WebIDL, r=bzbarsky,echou
☠☠ backed out by d978e68acda4 ☠ ☠
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 12 Aug 2013 10:32:53 +0200
changeset 142309 4ce3e048289cb3640577e5d43841ef8b2270c61d
parent 142308 3e6be7551207a0bd4c515c60e6e21621e4984853
child 142310 6855c55668a70054129d6d61e77f41f0a5f37a25
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 BluetoothAdapter to WebIDL, r=bzbarsky,echou In addition to converting BluetoothAdapter, this patch also converts MediaMetaData and MediaPlayStatus to WebIDL. The old XPIDL-based bindings have been removed.
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/bindings/Bindings.conf
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothAdapter.h
dom/bluetooth/BluetoothManager.cpp
dom/bluetooth/BluetoothPropertyContainer.cpp
dom/bluetooth/BluetoothPropertyContainer.h
dom/bluetooth/MediaMetaData.cpp
dom/bluetooth/MediaMetaData.h
dom/bluetooth/MediaPlayStatus.cpp
dom/bluetooth/MediaPlayStatus.h
dom/bluetooth/moz.build
dom/bluetooth/nsIDOMBluetoothAdapter.idl
dom/webidl/BluetoothAdapter.webidl
dom/webidl/WebIDL.mk
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -231,17 +231,16 @@ using mozilla::dom::workers::ResolveWork
 #include "nsIDOMMobileConnection.h"
 #endif // MOZ_B2G_RIL
 
 #ifdef MOZ_B2G_FM
 #include "FMRadio.h"
 #endif
 
 #ifdef MOZ_B2G_BT
-#include "BluetoothAdapter.h"
 #include "BluetoothDevice.h"
 #endif
 
 #include "DOMCameraManager.h"
 #include "DOMCameraControl.h"
 #include "DOMCameraCapabilities.h"
 #include "nsIOpenWindowEventDetail.h"
 #include "nsIAsyncScrollEventDetail.h"
@@ -633,18 +632,16 @@ static nsDOMClassInfoData sClassInfoData
 #endif
 
 #ifdef MOZ_B2G_FM
   NS_DEFINE_CLASSINFO_DATA(FMRadio, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
 #endif
 
 #ifdef MOZ_B2G_BT
-  NS_DEFINE_CLASSINFO_DATA(BluetoothAdapter, nsEventTargetSH,
-                           EVENTTARGET_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
 #endif
 
   NS_DEFINE_CLASSINFO_DATA(CameraControl, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CameraCapabilities, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
@@ -1529,20 +1526,16 @@ nsDOMClassInfo::Init()
 #ifdef MOZ_B2G_FM
   DOM_CLASSINFO_MAP_BEGIN(FMRadio, nsIFMRadio)
     DOM_CLASSINFO_MAP_ENTRY(nsIFMRadio)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
   DOM_CLASSINFO_MAP_END
 #endif
 
 #ifdef MOZ_B2G_BT
-  DOM_CLASSINFO_MAP_BEGIN(BluetoothAdapter, nsIDOMBluetoothAdapter)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothAdapter)
-  DOM_CLASSINFO_MAP_END
-
   DOM_CLASSINFO_MAP_BEGIN(BluetoothDevice, nsIDOMBluetoothDevice)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothDevice)
   DOM_CLASSINFO_MAP_END
 #endif
 
   DOM_CLASSINFO_MAP_BEGIN(CameraControl, nsICameraControl)
     DOM_CLASSINFO_MAP_ENTRY(nsICameraControl)
   DOM_CLASSINFO_MAP_END
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -132,17 +132,16 @@ DOMCI_CLASS(MozVoicemail)
 DOMCI_CLASS(MozIccManager)
 #endif
 
 #ifdef MOZ_B2G_FM
 DOMCI_CLASS(FMRadio)
 #endif
 
 #ifdef MOZ_B2G_BT
-DOMCI_CLASS(BluetoothAdapter)
 DOMCI_CLASS(BluetoothDevice)
 #endif
 
 DOMCI_CLASS(CameraControl)
 DOMCI_CLASS(CameraCapabilities)
 
 DOMCI_CLASS(OpenWindowEventDetail)
 DOMCI_CLASS(AsyncScrollEventDetail)
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -145,16 +145,21 @@ DOMInterfaces = {
     'workers': True,
 }],
 
 'BatteryManager': {
     'nativeType': 'mozilla::dom::battery::BatteryManager',
     'headerFile': 'BatteryManager.h'
 },
 
+'BluetoothAdapter': {
+    'nativeType': 'mozilla::dom::bluetooth::BluetoothAdapter',
+    'headerFile': 'BluetoothAdapter.h'
+},
+
 'BluetoothManager': {
     'nativeType': 'mozilla::dom::bluetooth::BluetoothManager',
     'headerFile': 'BluetoothManager.h'
 },
 
 'CallEvent': {
     'nativeType': 'mozilla::dom::telephony::CallEvent',
     'headerFile': 'CallEvent.h',
@@ -1722,16 +1727,18 @@ 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/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -11,55 +11,52 @@
 #include "nsDOMClassInfo.h"
 #include "nsIDOMBluetoothDeviceEvent.h"
 #include "nsIDOMBluetoothStatusChangedEvent.h"
 #include "nsTArrayHelpers.h"
 #include "DOMRequest.h"
 #include "nsThreadUtils.h"
 
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
+#include "mozilla/dom/BluetoothAdapterBinding.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/LazyIdleThread.h"
 #include "mozilla/Util.h"
 
 #include "BluetoothAdapter.h"
 #include "BluetoothDevice.h"
 #include "BluetoothReplyRunnable.h"
 #include "BluetoothService.h"
 #include "BluetoothUtils.h"
-#include "MediaMetaData.h"
-#include "MediaPlayStatus.h"
 
 using namespace mozilla;
+using namespace mozilla::dom;
 
 USING_BLUETOOTH_NAMESPACE
 
-DOMCI_DATA(BluetoothAdapter, BluetoothAdapter)
-
 NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothAdapter)
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothAdapter,
                                                nsDOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mJsUuids)
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mJsDeviceAddresses)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothAdapter, 
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothAdapter,
                                                   nsDOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothAdapter, 
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothAdapter,
                                                 nsDOMEventTargetHelper)
   tmp->Unroot();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
+// QueryInterface implementation for BluetoothAdapter
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothAdapter)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothAdapter)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothAdapter)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
 
 class GetDevicesTask : public BluetoothReplyRunnable
 {
 public:
@@ -159,43 +156,30 @@ public:
   ReleaseMembers()
   {
     BluetoothReplyRunnable::ReleaseMembers();
   }
 };
 
 static int kCreatePairedDeviceTimeout = 50000; // unit: msec
 
-nsresult
-PrepareDOMRequest(nsIDOMWindow* aWindow, nsIDOMDOMRequest** aRequest)
-{
-  MOZ_ASSERT(aWindow);
-
-  nsCOMPtr<nsIDOMRequestService> rs =
-    do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
-
-  nsresult rv = rs->CreateRequest(aWindow, aRequest);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
-}
-
 BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aWindow,
                                    const BluetoothValue& aValue)
-  : BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
+  : nsDOMEventTargetHelper(aWindow)
+  , BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
+  , mJsUuids(nullptr)
+  , mJsDeviceAddresses(nullptr)
   , mDiscoverable(false)
   , mDiscovering(false)
   , mPairable(false)
   , mPowered(false)
-  , mJsUuids(nullptr)
-  , mJsDeviceAddresses(nullptr)
   , 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]);
   }
 
@@ -367,566 +351,590 @@ BluetoothAdapter::Notify(const Bluetooth
     nsCString warningMsg;
     warningMsg.AssignLiteral("Not handling adapter signal: ");
     warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
     NS_WARNING(warningMsg.get());
 #endif
   }
 }
 
-nsresult
-BluetoothAdapter::StartStopDiscovery(bool aStart, nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::StartStopDiscovery(bool aStart, ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv;
-  rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  nsresult rv;
   if (aStart) {
     rv = bs->StartDiscoveryInternal(results);
   } else {
     rv = bs->StopDiscoveryInternal(results);
   }
-  if(NS_FAILED(rv)) {
+  if (NS_FAILED(rv)) {
     NS_WARNING("Start/Stop Discovery failed!");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(rv);
+    return nullptr;
   }
 
   // mDiscovering is not set here, we'll get a Property update from our external
   // protocol to tell us that it's been set.
 
-  req.forget(aRequest);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothAdapter::StartDiscovery(nsIDOMDOMRequest** aRequest)
-{
-  return StartStopDiscovery(true, aRequest);
-}
-
-NS_IMETHODIMP
-BluetoothAdapter::StopDiscovery(nsIDOMDOMRequest** aRequest)
-{
-  return StartStopDiscovery(false, aRequest);
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetAddress(nsAString& aAddress)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
 {
-  aAddress = mAddress;
-  return NS_OK;
+  return StartStopDiscovery(true, aRv);
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetAdapterClass(uint32_t* aClass)
-{
-  *aClass = mClass;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothAdapter::GetDiscovering(bool* aDiscovering)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::StopDiscovery(ErrorResult& aRv)
 {
-  *aDiscovering = mDiscovering;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothAdapter::GetName(nsAString& aName)
-{
-  aName = mName;
-  return NS_OK;
+  return StartStopDiscovery(false, aRv);
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetDiscoverable(bool* aDiscoverable)
+JS::Value
+BluetoothAdapter::GetDevices(JSContext* aContext, ErrorResult& aRv)
 {
-  *aDiscoverable = mDiscoverable;
-  return NS_OK;
-}
+  if (!mJsDeviceAddresses) {
+    NS_WARNING("Devices not yet set!\n");
+    aRv.Throw(NS_ERROR_FAILURE);
+    return JS::NullValue();
+  }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetDiscoverableTimeout(uint32_t* aDiscoverableTimeout)
-{
-  *aDiscoverableTimeout = mDiscoverableTimeout;
-  return NS_OK;
+  return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsDeviceAddresses));
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetDevices(JSContext* aCx, JS::Value* aDevices)
+JS::Value
+BluetoothAdapter::GetUuids(JSContext* aContext, ErrorResult& aRv)
 {
-  if (mJsDeviceAddresses) {
-    aDevices->setObject(*mJsDeviceAddresses);
+  if (!mJsUuids) {
+    NS_WARNING("UUIDs not yet set!\n");
+    aRv.Throw(NS_ERROR_FAILURE);
+    return JS::NullValue();
   }
-  else {
-    NS_WARNING("Devices not yet set!\n");
-    return NS_ERROR_FAILURE;
-  }
-  return NS_OK;
+
+  return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsUuids));
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetUuids(JSContext* aCx, JS::Value* aValue)
-{
-  if (mJsUuids) {
-    aValue->setObject(*mJsUuids);
-  }
-  else {
-    NS_WARNING("UUIDs not yet set!\n");
-    return NS_ERROR_FAILURE;
-  }    
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothAdapter::SetName(const nsAString& aName,
-                          nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::SetName(const nsAString& aName, ErrorResult& aRv)
 {
   if (mName.Equals(aName)) {
-    return FirePropertyAlreadySet(GetOwner(), aRequest);
+    return FirePropertyAlreadySet(GetOwner(), aRv);
   }
   nsString name(aName);
   BluetoothValue value(name);
   BluetoothNamedValue property(NS_LITERAL_STRING("Name"), value);
-  return SetProperty(GetOwner(), property, aRequest);
+  return SetProperty(GetOwner(), property, aRv);
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::SetDiscoverable(const bool aDiscoverable,
-                                  nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::SetDiscoverable(bool aDiscoverable, ErrorResult& aRv)
 {
   if (aDiscoverable == mDiscoverable) {
-    return FirePropertyAlreadySet(GetOwner(), aRequest);
+    return FirePropertyAlreadySet(GetOwner(), aRv);
   }
   BluetoothValue value(aDiscoverable);
   BluetoothNamedValue property(NS_LITERAL_STRING("Discoverable"), value);
-  return SetProperty(GetOwner(), property, aRequest);
+  return SetProperty(GetOwner(), property, aRv);
 }
- 
-NS_IMETHODIMP
-BluetoothAdapter::SetDiscoverableTimeout(const uint32_t aDiscoverableTimeout,
-                                         nsIDOMDOMRequest** aRequest)
+
+already_AddRefed<DOMRequest>
+BluetoothAdapter::SetDiscoverableTimeout(uint32_t aDiscoverableTimeout, ErrorResult& aRv)
 {
   if (aDiscoverableTimeout == mDiscoverableTimeout) {
-    return FirePropertyAlreadySet(GetOwner(), aRequest);
+    return FirePropertyAlreadySet(GetOwner(), aRv);
   }
   BluetoothValue value(aDiscoverableTimeout);
   BluetoothNamedValue property(NS_LITERAL_STRING("DiscoverableTimeout"), value);
-  return SetProperty(GetOwner(), property, aRequest);
+  return SetProperty(GetOwner(), property, aRv);
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetConnectedDevices(uint16_t aProfileId,
-                                      nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::GetConnectedDevices(uint16_t aProfileId, ErrorResult& aRv)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothReplyRunnable> results =
-    new GetDevicesTask(this, req);
+    new GetDevicesTask(this, request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  rv = bs->GetConnectedDevicePropertiesInternal(aProfileId, results);
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  nsresult rv = bs->GetConnectedDevicePropertiesInternal(aProfileId, results);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+    return nullptr;
+  }
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::GetPairedDevices(nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::GetPairedDevices(ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothReplyRunnable> results =
-    new GetDevicesTask(this, req);
+    new GetDevicesTask(this, request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  rv = bs->GetPairedDevicePropertiesInternal(mDeviceAddresses, results);
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  nsresult rv = bs->GetPairedDevicePropertiesInternal(mDeviceAddresses, results);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+    return nullptr;
+  }
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-nsresult
-BluetoothAdapter::PairUnpair(bool aPair,
-                             nsIDOMBluetoothDevice* aDevice,
-                             nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice,
+                             ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   nsAutoString addr;
   aDevice->GetAddress(addr);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  nsresult rv;
   if (aPair) {
     rv = bs->CreatePairedDeviceInternal(addr,
                                         kCreatePairedDeviceTimeout,
                                         results);
   } else {
     rv = bs->RemoveDeviceInternal(addr, results);
   }
-
   if (NS_FAILED(rv)) {
     NS_WARNING("Pair/Unpair failed!");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(rv);
+    return nullptr;
   }
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-nsresult
-BluetoothAdapter::Pair(nsIDOMBluetoothDevice* aDevice,
-                       nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::Pair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv)
 {
-  return PairUnpair(true, aDevice, aRequest);
+  return PairUnpair(true, aDevice, aRv);
 }
 
-nsresult
-BluetoothAdapter::Unpair(nsIDOMBluetoothDevice* aDevice,
-                         nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::Unpair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv)
 {
-  return PairUnpair(false, aDevice, aRequest);
+  return PairUnpair(false, aDevice, aRv);
 }
 
-nsresult
+already_AddRefed<DOMRequest>
 BluetoothAdapter::SetPinCode(const nsAString& aDeviceAddress,
-                             const nsAString& aPinCode,
-                             nsIDOMDOMRequest** aRequest)
+                             const nsAString& aPinCode, ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  if(!bs->SetPinCodeInternal(aDeviceAddress, aPinCode, results)) {
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  if (!bs->SetPinCodeInternal(aDeviceAddress, aPinCode, results)) {
     NS_WARNING("SetPinCode failed!");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
   }
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-nsresult
+already_AddRefed<DOMRequest>
 BluetoothAdapter::SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
-                             nsIDOMDOMRequest** aRequest)
+                             ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  if(bs->SetPasskeyInternal(aDeviceAddress, aPasskey, results)) {
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  if (bs->SetPasskeyInternal(aDeviceAddress, aPasskey, results)) {
     NS_WARNING("SetPasskeyInternal failed!");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
   }
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-nsresult
+already_AddRefed<DOMRequest>
 BluetoothAdapter::SetPairingConfirmation(const nsAString& aDeviceAddress,
-                                         bool aConfirmation,
-                                         nsIDOMDOMRequest** aRequest)
+                                         bool aConfirmation, ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  if(!bs->SetPairingConfirmationInternal(aDeviceAddress,
-                                         aConfirmation,
-                                         results)) {
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  if (!bs->SetPairingConfirmationInternal(aDeviceAddress,
+                                          aConfirmation,
+                                          results)) {
     NS_WARNING("SetPairingConfirmation failed!");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
   }
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-nsresult
+already_AddRefed<DOMRequest>
 BluetoothAdapter::SetAuthorization(const nsAString& aDeviceAddress, bool aAllow,
-                                   nsIDOMDOMRequest** aRequest)
+                                   ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
-
-  nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  if(!bs->SetAuthorizationInternal(aDeviceAddress, aAllow, results)) {
-    NS_WARNING("SetAuthorization failed!");
-    return NS_ERROR_FAILURE;
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
   }
 
-  req.forget(aRequest);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
-                          uint16_t aProfileId,
-                          nsIDOMDOMRequest** aRequest)
-{
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
+  nsRefPtr<BluetoothVoidReplyRunnable> results =
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  if (!bs->SetAuthorizationInternal(aDeviceAddress, aAllow, results)) {
+    NS_WARNING("SetAuthorization failed!");
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
-  nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
-  bs->Connect(aDeviceAddress, aProfileId, results);
-
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::Disconnect(uint16_t aProfileId,
-                             nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
+                          uint16_t aProfileId, ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  bs->Disconnect(aProfileId, results);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->Connect(aDeviceAddress, aProfileId, results);
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
-                           nsIDOMBlob* aBlob,
-                           nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::Disconnect(uint16_t aProfileId, ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  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);
+
+  BluetoothService* bs = BluetoothService::Get();
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->Disconnect(aProfileId, results);
 
+  return request.forget();
+}
+
+already_AddRefed<DOMRequest>
+BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
+                           nsIDOMBlob* aBlob, 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(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BlobChild* actor =
-    mozilla::dom::ContentChild::GetSingleton()->GetOrCreateActorForBlob(aBlob);
+    ContentChild::GetSingleton()->GetOrCreateActorForBlob(aBlob);
   if (!actor) {
     NS_WARNING("Can't create actor");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
   }
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
   bs->SendFile(aDeviceAddress, nullptr, actor, results);
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::StopSendingFile(const nsAString& aDeviceAddress,
-                                  nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
-
-  nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  bs->StopSendingFile(aDeviceAddress, results);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
-  req.forget(aRequest);
-  return NS_OK;
-}
-
-nsresult
-BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
-                                       bool aConfirmation,
-                                       nsIDOMDOMRequest** aRequest)
-{
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
-
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, results);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->StopSendingFile(aDeviceAddress, results);
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::ConnectSco(nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
+                                       bool aConfirmation, ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, results);
+
+  return request.forget();
+}
+
+already_AddRefed<DOMRequest>
+BluetoothAdapter::ConnectSco(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);
+
+  BluetoothService* bs = BluetoothService::Get();
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
   bs->ConnectSco(results);
 
-  req.forget(aRequest);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-BluetoothAdapter::DisconnectSco(nsIDOMDOMRequest** aRequest)
-{
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
-
-  nsRefPtr<BluetoothVoidReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  bs->DisconnectSco(results);
-
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::IsScoConnected(nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::DisconnectSco(ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
-  nsRefPtr<BluetoothReplyRunnable> results =
-    new GetScoConnectionStatusTask(req);
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
+  nsRefPtr<BluetoothVoidReplyRunnable> results =
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  bs->IsScoConnected(results);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->DisconnectSco(results);
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::SendMediaMetaData(const JS::Value& aOptions,
-                                    nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::IsScoConnected(ErrorResult& aRv)
 {
-  MediaMetaData metadata;
-
-  nsresult rv;
-  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
-  AutoPushJSContext cx(sc->GetNativeContext());
-  rv = metadata.Init(cx, &aOptions);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, rv);
-
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new GetScoConnectionStatusTask(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  bs->SendMetaData(metadata.mTitle,
-                   metadata.mArtist,
-                   metadata.mAlbum,
-                   metadata.mMediaNumber,
-                   metadata.mTotalMediaCount,
-                   metadata.mDuration,
-                   results);
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->IsScoConnected(results);
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMETHODIMP
-BluetoothAdapter::SendMediaPlayStatus(const JS::Value& aOptions,
-                                      nsIDOMDOMRequest** aRequest)
+already_AddRefed<DOMRequest>
+BluetoothAdapter::SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv)
 {
-  MediaPlayStatus status;
-
-  nsresult rv;
-  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
-  AutoPushJSContext cx(sc->GetNativeContext());
-  rv = status.Init(cx, &aOptions);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
-  NS_ENSURE_SUCCESS(rv, rv);
-
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
   nsRefPtr<BluetoothReplyRunnable> results =
-    new BluetoothVoidReplyRunnable(req);
+    new BluetoothVoidReplyRunnable(request);
 
   BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-  bs->SendPlayStatus(status.mDuration,
-                     status.mPosition,
-                     status.mPlayStatus,
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->SendMetaData(aMediaMetaData.mTitle,
+                   aMediaMetaData.mArtist,
+                   aMediaMetaData.mAlbum,
+                   aMediaMetaData.mMediaNumber,
+                   aMediaMetaData.mTotalMediaCount,
+                   aMediaMetaData.mDuration,
+                   results);
+
+  return request.forget();
+}
+
+already_AddRefed<DOMRequest>
+BluetoothAdapter::SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv)
+{
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
+  if (!win) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  nsRefPtr<DOMRequest> request = new DOMRequest(win);
+  nsRefPtr<BluetoothReplyRunnable> results =
+    new BluetoothVoidReplyRunnable(request);
+
+  BluetoothService* bs = BluetoothService::Get();
+  if (!bs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+  bs->SendPlayStatus(aMediaPlayStatus.mDuration,
+                     aMediaPlayStatus.mPosition,
+                     aMediaPlayStatus.mPlayStatus,
                      results);
 
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
 
-NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicefound)
-NS_IMPL_EVENT_HANDLER(BluetoothAdapter, a2dpstatuschanged)
-NS_IMPL_EVENT_HANDLER(BluetoothAdapter, hfpstatuschanged)
-NS_IMPL_EVENT_HANDLER(BluetoothAdapter, pairedstatuschanged)
-NS_IMPL_EVENT_HANDLER(BluetoothAdapter, scostatuschanged)
+JSObject*
+BluetoothAdapter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
+{
+  return BluetoothAdapterBinding::Wrap(aCx, aScope, this);
+}
--- a/dom/bluetooth/BluetoothAdapter.h
+++ b/dom/bluetooth/BluetoothAdapter.h
@@ -7,76 +7,179 @@
 #ifndef mozilla_dom_bluetooth_bluetoothadapter_h__
 #define mozilla_dom_bluetooth_bluetoothadapter_h__
 
 #include "mozilla/Attributes.h"
 #include "BluetoothCommon.h"
 #include "BluetoothPropertyContainer.h"
 #include "nsCOMPtr.h"
 #include "nsDOMEventTargetHelper.h"
-#include "nsIDOMBluetoothAdapter.h"
+#include "nsIDOMBluetoothDevice.h"
 
-class nsIEventTarget;
-class nsIDOMDOMRequest;
+namespace mozilla {
+namespace dom {
+class DOMRequest;
+struct MediaMetaData;
+struct MediaPlayStatus;
+}
+}
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothSignal;
 class BluetoothNamedValue;
 class BluetoothValue;
 
 class BluetoothAdapter : public nsDOMEventTargetHelper
-                       , public nsIDOMBluetoothAdapter
                        , public BluetoothSignalObserver
                        , public BluetoothPropertyContainer
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_NSIDOMBLUETOOTHADAPTER
-
-  NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper)
 
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(BluetoothAdapter,
                                                          nsDOMEventTargetHelper)
 
   static already_AddRefed<BluetoothAdapter>
   Create(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
 
   void Notify(const BluetoothSignal& aParam);
 
-  nsISupports*
-  ToISupports()
+  void Unroot();
+  virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;
+
+  void GetAddress(nsString& aAddress) const
+  {
+    aAddress = mAddress;
+  }
+
+  uint32_t
+  Class() const
+  {
+    return mClass;
+  }
+
+  void
+  GetName(nsString& aName) const
   {
-    return static_cast<EventTarget*>(this);
+    aName = mName;
+  }
+
+  bool
+  Discovering() const
+  {
+    return mDiscovering;
+  }
+
+  bool
+  Discoverable() const
+  {
+    return mDiscoverable;
+  }
+
+  uint32_t
+  DiscoverableTimeout() const
+  {
+    return mDiscoverableTimeout;
   }
 
-  void Unroot();
-  virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;  
+  JS::Value GetDevices(JSContext* aContext, ErrorResult& aRv);
+  JS::Value GetUuids(JSContext* aContext, ErrorResult& aRv);
+
+  already_AddRefed<mozilla::dom::DOMRequest>
+    SetName(const nsAString& aName, ErrorResult& aRv);
+
+  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);
+  already_AddRefed<DOMRequest>
+    Unpair(nsIDOMBluetoothDevice* 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);
+  already_AddRefed<DOMRequest>
+    SetPairingConfirmation(const nsAString& aDeviceAddress, bool aConfirmation,
+                           ErrorResult& aRv);
+  already_AddRefed<DOMRequest>
+    SetAuthorization(const nsAString& aDeviceAddress, bool aAllow,
+                     ErrorResult& aRv);
+
+  already_AddRefed<DOMRequest>
+    Connect(const nsAString& aDeviceAddress, uint16_t aProfile,
+            ErrorResult& aRv);
+  already_AddRefed<DOMRequest>
+    Disconnect(uint16_t aProfile, ErrorResult& aRv);
+  already_AddRefed<DOMRequest>
+    GetConnectedDevices(uint16_t aProfile, ErrorResult& aRv);
+
+  already_AddRefed<DOMRequest>
+    SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob,
+             ErrorResult& aRv);
+  already_AddRefed<DOMRequest>
+    StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv);
+  already_AddRefed<DOMRequest>
+    ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirmation,
+                         ErrorResult& aRv);
+
+  already_AddRefed<DOMRequest> ConnectSco(ErrorResult& aRv);
+  already_AddRefed<DOMRequest> DisconnectSco(ErrorResult& aRv);
+  already_AddRefed<DOMRequest> IsScoConnected(ErrorResult& aRv);
+
+  already_AddRefed<DOMRequest>
+    SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv);
+  already_AddRefed<DOMRequest>
+    SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv);
+
+  IMPL_EVENT_HANDLER(devicefound);
+  IMPL_EVENT_HANDLER(a2dpstatuschanged);
+  IMPL_EVENT_HANDLER(hfpstatuschanged);
+  IMPL_EVENT_HANDLER(pairedstatuschanged);
+  IMPL_EVENT_HANDLER(scostatuschanged);
+
+  nsPIDOMWindow* GetParentObject() const
+  {
+     return GetOwner();
+  }
+
+  virtual JSObject*
+    WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+
 private:
-
   BluetoothAdapter(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
   ~BluetoothAdapter();
 
   void Root();
-  nsresult StartStopDiscovery(bool aStart, nsIDOMDOMRequest** aRequest);
-  nsresult PairUnpair(bool aPair,
-                      nsIDOMBluetoothDevice* aDevice,
-                      nsIDOMDOMRequest** aRequest);
-  
+
+  already_AddRefed<mozilla::dom::DOMRequest>
+    StartStopDiscovery(bool aStart, ErrorResult& aRv);
+  already_AddRefed<mozilla::dom::DOMRequest>
+    PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv);
+
+  JS::Heap<JSObject*> mJsUuids;
+  JS::Heap<JSObject*> mJsDeviceAddresses;
   nsString mAddress;
   nsString mName;
   bool mDiscoverable;
   bool mDiscovering;
   bool mPairable;
   bool mPowered;
   uint32_t mPairableTimeout;
   uint32_t mDiscoverableTimeout;
   uint32_t mClass;
   nsTArray<nsString> mDeviceAddresses;
   nsTArray<nsString> mUuids;
-  JS::Heap<JSObject*> mJsUuids;
-  JS::Heap<JSObject*> mJsDeviceAddresses;
   bool mIsRooted;
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif
--- a/dom/bluetooth/BluetoothManager.cpp
+++ b/dom/bluetooth/BluetoothManager.cpp
@@ -50,18 +50,18 @@ public:
     if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
       NS_WARNING("Not a BluetoothNamedValue array!");
       SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
       return false;
     }
 
     const InfallibleTArray<BluetoothNamedValue>& values =
       v.get_ArrayOfBluetoothNamedValue();
-    nsCOMPtr<nsIDOMBluetoothAdapter> adapter;
-    adapter = BluetoothAdapter::Create(mManagerPtr->GetOwner(), values);
+    nsRefPtr<BluetoothAdapter> adapter =
+      BluetoothAdapter::Create(mManagerPtr->GetOwner(), values);
 
     nsresult rv;
     nsIScriptContext* sc = mManagerPtr->GetContextForEventHandlers(&rv);
     if (!sc) {
       NS_WARNING("Cannot create script context!");
       SetError(NS_LITERAL_STRING("BluetoothScriptContextError"));
       return false;
     }
--- a/dom/bluetooth/BluetoothPropertyContainer.cpp
+++ b/dom/bluetooth/BluetoothPropertyContainer.cpp
@@ -3,62 +3,54 @@
 /* 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 "BluetoothPropertyContainer.h"
 #include "BluetoothService.h"
 #include "DOMRequest.h"
+#include "mozilla/ErrorResult.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 
 USING_BLUETOOTH_NAMESPACE
 
-nsresult
+already_AddRefed<mozilla::dom::DOMRequest>
 BluetoothPropertyContainer::FirePropertyAlreadySet(nsIDOMWindow* aOwner,
-                                                   nsIDOMDOMRequest** aRequest)
+                                                   ErrorResult& aRv)
 {
   nsCOMPtr<nsIDOMRequestService> rs =
     do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
+  if (!rs) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = rs->CreateRequest(aOwner, getter_AddRefs(req));
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Can't create DOMRequest!");
-    return NS_ERROR_FAILURE;
-  }
-  rs->FireSuccess(req, JSVAL_VOID);
-  req.forget(aRequest);
+  nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
+  rs->FireSuccess(request, JS::UndefinedValue());
 
-  return NS_OK;
+  return request.forget();
 }
 
-nsresult
+already_AddRefed<mozilla::dom::DOMRequest>
 BluetoothPropertyContainer::SetProperty(nsIDOMWindow* aOwner,
                                         const BluetoothNamedValue& aProperty,
-                                        nsIDOMDOMRequest** aRequest)
+                                        ErrorResult& aRv)
 {
+  nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
+  nsRefPtr<BluetoothReplyRunnable> task =
+    new BluetoothVoidReplyRunnable(request);
+
   BluetoothService* bs = BluetoothService::Get();
   if (!bs) {
     NS_WARNING("Bluetooth service not available!");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
   }
 
-  nsCOMPtr<nsIDOMRequestService> rs =
-    do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIDOMDOMRequest> req;
-  nsresult rv = rs->CreateRequest(aOwner, getter_AddRefs(req));
+  nsresult rv = bs->SetProperty(mObjectType, aProperty, task);
   if (NS_FAILED(rv)) {
-    NS_WARNING("Can't create DOMRequest!");
-    return NS_ERROR_FAILURE;
+    aRv.Throw(rv);
+    return nullptr;
   }
 
-  nsRefPtr<BluetoothReplyRunnable> task = new BluetoothVoidReplyRunnable(req);
-
-  rv = bs->SetProperty(mObjectType, aProperty, task);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  req.forget(aRequest);
-  return NS_OK;
+  return request.forget();
 }
--- a/dom/bluetooth/BluetoothPropertyContainer.h
+++ b/dom/bluetooth/BluetoothPropertyContainer.h
@@ -8,28 +8,35 @@
 #define mozilla_dom_bluetooth_bluetoothpropertyobject_h__
 
 #include "BluetoothCommon.h"
 #include "BluetoothReplyRunnable.h"
 
 class nsIDOMDOMRequest;
 class nsIDOMWindow;
 
+namespace mozilla {
+class ErrorResult;
+namespace dom {
+class DOMRequest;
+}
+}
+
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothNamedValue;
 
 class BluetoothPropertyContainer
 {
 public:
-  nsresult FirePropertyAlreadySet(nsIDOMWindow* aOwner,
-                                  nsIDOMDOMRequest** aRequest);
-  nsresult SetProperty(nsIDOMWindow* aOwner,
-                       const BluetoothNamedValue& aProperty,
-                       nsIDOMDOMRequest** aRequest);
+  already_AddRefed<mozilla::dom::DOMRequest>
+    FirePropertyAlreadySet(nsIDOMWindow* aOwner, ErrorResult& aRv);
+  already_AddRefed<mozilla::dom::DOMRequest>
+    SetProperty(nsIDOMWindow* aOwner, const BluetoothNamedValue& aProperty,
+                ErrorResult& aRv);
   virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) = 0;
   nsString GetPath()
   {
     return mPath;
   }
 
   // Compatibility with nsRefPtr to make sure we don't hold a weakptr to
   // ourselves
deleted file mode 100644
--- a/dom/bluetooth/MediaMetaData.cpp
+++ /dev/null
@@ -1,83 +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 "BluetoothCommon.h"
-#include "MediaMetaData.h"
-
-#include "nsCxPusher.h"
-#include "nsContentUtils.h"
-#include "nsJSUtils.h"
-#include "nsThreadUtils.h"
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-MediaMetaData::MediaMetaData() : mDuration(-1)
-                               , mMediaNumber(-1)
-                               , mTotalMediaCount(-1)
-{
-}
-
-nsresult
-MediaMetaData::Init(JSContext* aCx, const jsval* aVal)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!aCx || !aVal) {
-    return NS_OK;
-  }
-
-  if (!aVal->isObject()) {
-    return aVal->isNullOrUndefined() ? NS_OK : NS_ERROR_TYPE_ERR;
-  }
-
-  JS::RootedObject obj(aCx, &aVal->toObject());
-  nsCxPusher pusher;
-  pusher.Push(aCx);
-  JSAutoCompartment ac(aCx, obj);
-
-  JS::Rooted<JS::Value> value(aCx);
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mAlbum", &value));
-  if (JSVAL_IS_STRING(value)) {
-    nsDependentJSString jsString;
-    NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
-    mAlbum = jsString;
-  }
-
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mArtist", &value));
-  if (JSVAL_IS_STRING(value)) {
-    nsDependentJSString jsString;
-    NS_ENSURE_STATE(JSVAL_IS_STRING(value));
-    NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
-    mArtist = jsString;
-  }
-
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mDuration", &value));
-  if (JSVAL_IS_INT(value)) {
-    NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mDuration));
-  }
-
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mMediaNumber", &value));
-  if (JSVAL_IS_INT(value)) {
-    NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mMediaNumber));
-  }
-
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mTitle", &value));
-  if (JSVAL_IS_STRING(value)) {
-    nsDependentJSString jsString;
-    NS_ENSURE_STATE(JSVAL_IS_STRING(value));
-    NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
-    mTitle = jsString;
-  }
-
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mTotalMediaCount", &value));
-  if (JSVAL_IS_INT(value)) {
-    NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mTotalMediaCount));
-  }
-
-  return NS_OK;
-}
-
deleted file mode 100644
--- a/dom/bluetooth/MediaMetaData.h
+++ /dev/null
@@ -1,32 +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_mediametadata_h__
-#define mozilla_dom_bluetooth_mediametadata_h__
-
-#include "jsapi.h"
-#include "nsString.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class MediaMetaData
-{
-public:
-  MediaMetaData();
-
-  nsresult Init(JSContext* aCx, const jsval* aVal);
-
-  nsString mAlbum;
-  nsString mArtist;
-  int64_t mDuration;
-  int64_t mMediaNumber;
-  nsString mTitle;
-  int64_t mTotalMediaCount;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
deleted file mode 100644
--- a/dom/bluetooth/MediaPlayStatus.cpp
+++ /dev/null
@@ -1,62 +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 "BluetoothCommon.h"
-#include "MediaPlayStatus.h"
-
-#include "nsContentUtils.h"
-#include "nsCxPusher.h"
-#include "nsJSUtils.h"
-#include "nsThreadUtils.h"
-
-using namespace mozilla;
-USING_BLUETOOTH_NAMESPACE
-
-MediaPlayStatus::MediaPlayStatus() : mDuration(-1)
-                                     , mPosition(-1)
-{
-}
-
-nsresult
-MediaPlayStatus::Init(JSContext* aCx, const jsval* aVal)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!aCx || !aVal) {
-    return NS_OK;
-  }
-
-  if (!aVal->isObject()) {
-    return aVal->isNullOrUndefined() ? NS_OK : NS_ERROR_TYPE_ERR;
-  }
-
-  JS::RootedObject obj(aCx, &aVal->toObject());
-  nsCxPusher pusher;
-  pusher.Push(aCx);
-  JSAutoCompartment ac(aCx, obj);
-
-  JS::Rooted<JS::Value> value(aCx);
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mDuration", &value));
-  if (JSVAL_IS_INT(value)) {
-    NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mDuration));
-  }
-
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mPlayStatus", &value));
-  if (JSVAL_IS_STRING(value)) {
-    nsDependentJSString jsString;
-    NS_ENSURE_STATE(JSVAL_IS_STRING(value));
-    NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
-    mPlayStatus = jsString;
-  }
-
-  NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mPosition", &value));
-  if (JSVAL_IS_INT(value)) {
-    NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mPosition));
-  }
-
-  return NS_OK;
-}
-
deleted file mode 100644
--- a/dom/bluetooth/MediaPlayStatus.h
+++ /dev/null
@@ -1,29 +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_mediaplaystatus_h__
-#define mozilla_dom_bluetooth_mediaplaystatus_h__
-
-#include "jsapi.h"
-#include "nsString.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class MediaPlayStatus
-{
-public:
-  MediaPlayStatus();
-
-  nsresult Init(JSContext* aCx, const jsval* aVal);
-
-  int64_t mDuration;
-  nsString mPlayStatus;
-  int64_t mPosition;
-};
-
-END_BLUETOOTH_NAMESPACE
-
-#endif
--- a/dom/bluetooth/moz.build
+++ b/dom/bluetooth/moz.build
@@ -13,17 +13,16 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
 if CONFIG['MOZ_B2G_BT']:
     MODULE = 'dom'
     XPIDL_MODULE = 'dom_bluetooth'
     XPIDL_SOURCES += [
-        'nsIDOMBluetoothAdapter.idl',
         'nsIDOMBluetoothDevice.idl',
         'nsIDOMBluetoothDeviceEvent.idl',
         'nsIDOMBluetoothStatusChangedEvent.idl',
     ]
 
     CPP_SOURCES += [
         'BluetoothService.cpp',
         'BluetoothManager.cpp',
@@ -37,18 +36,16 @@ if CONFIG['MOZ_B2G_BT']:
         'BluetoothServiceChildProcess.cpp',
         'BluetoothUnixSocketConnector.cpp',
         'BluetoothA2dpManager.cpp',
         'BluetoothHfpManager.cpp',
         'BluetoothOppManager.cpp',
         'ObexBase.cpp',
         'BluetoothUuid.cpp',
         'BluetoothSocket.cpp',
-        'MediaMetaData.cpp',
-        'MediaPlayStatus.cpp'
     ]
 
     if CONFIG['MOZ_B2G_RIL']:
         CPP_SOURCES += [
             'BluetoothTelephonyListener.cpp',
         ]
 
     if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
deleted file mode 100644
--- a/dom/bluetooth/nsIDOMBluetoothAdapter.idl
+++ /dev/null
@@ -1,117 +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 "nsIDOMEventTarget.idl"
-
-/**
- * MediaMetadata and MediaPlayStatus are used to keep data from Applications.
- * Please see specification of AVRCP 1.3 for more details.
- *
- * @title:           track title
- * @artist:          artist name
- * @album:           album name
- * @mediaNumber:     track number
- * @totalMediaCount: number of tracks in the album
- * @duration:        playing time (ms)
- */
-dictionary MediaMetaData
-{
-  DOMString  title;
-  DOMString  artist;
-  DOMString  album;
-  unsigned long  mediaNumber;
-  unsigned long  totalMediaCount;
-  unsigned long  duration;
-};
-
-/**
- * @duration:   current track length (ms)
- * @position:   playing time (ms)
- * @playStatus: STOPPED/PLAYING/PAUSED/FWD_SEEK/REV_SEEK/ERROR
- */
-dictionary MediaPlayStatus
-{
-  unsigned long  duration;
-  unsigned long  position;
-  DOMString  playStatus;
-};
-
-interface nsIDOMDOMRequest;
-interface nsIDOMBlob;
-interface nsIDOMBluetoothDevice;
-
-[scriptable, builtinclass, uuid(54bf9aa2-1208-47ab-ac96-c7df349fcf0e)]
-interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
-{
-  readonly attribute DOMString address;
-  [binaryname(AdapterClass)] readonly attribute unsigned long class;
-  readonly attribute bool discovering;
-
-  [implicit_jscontext]
-  readonly attribute jsval devices;
-
-  [implicit_jscontext]
-  readonly attribute jsval uuids;
-  
-  readonly attribute DOMString name;
-  readonly attribute bool discoverable;
-  // Unit: sec
-  readonly attribute unsigned long discoverableTimeout;
-
-  nsIDOMDOMRequest setName(in DOMString name);
-  nsIDOMDOMRequest setDiscoverable(in bool discoverable);
-  nsIDOMDOMRequest setDiscoverableTimeout(in unsigned long timeout);
-  nsIDOMDOMRequest startDiscovery();
-  nsIDOMDOMRequest stopDiscovery();
-  nsIDOMDOMRequest pair(in nsIDOMBluetoothDevice aDevice);
-  nsIDOMDOMRequest unpair(in nsIDOMBluetoothDevice aDevice);
-  nsIDOMDOMRequest getPairedDevices();
-  nsIDOMDOMRequest getConnectedDevices(in unsigned short aProfile);
-  nsIDOMDOMRequest setPinCode(in DOMString aDeviceAddress, in DOMString aPinCode);
-  nsIDOMDOMRequest setPasskey(in DOMString aDeviceAddress, in unsigned long aPasskey);
-  nsIDOMDOMRequest setPairingConfirmation(in DOMString aDeviceAddress, in bool aConfirmation);
-  nsIDOMDOMRequest setAuthorization(in DOMString aDeviceAddress, in bool aAllow);
-
-  /** 
-   * Connect/Disconnect to a specific service of a target remote device. 
-   * To check the value of service UUIDs, please check "Bluetooth Assigned 
-   * Numbers" / "Service Discovery Protocol" for more information.
-   *  
-   * @param aDeviceAddress Remote device address
-   * @param aProfile 2-octets service UUID
-   */
-  nsIDOMDOMRequest connect(in DOMString aDeviceAddress, in unsigned short aProfile);
-  nsIDOMDOMRequest disconnect(in unsigned short aProfile);
-
-  // One device can only send one file at a time
-  nsIDOMDOMRequest sendFile(in DOMString aDeviceAddress, in nsIDOMBlob aBlob);
-  nsIDOMDOMRequest stopSendingFile(in DOMString aDeviceAddress);
-  nsIDOMDOMRequest confirmReceivingFile(in DOMString aDeviceAddress, in bool aConfirmation);
-
-  // AVRCP 1.3 methods
-  nsIDOMDOMRequest sendMediaMetaData(in jsval aOptions);
-  nsIDOMDOMRequest sendMediaPlayStatus(in jsval aOptions);
-
-  // Connect/Disconnect SCO (audio) connection
-  nsIDOMDOMRequest connectSco();
-  nsIDOMDOMRequest disconnectSco();
-  nsIDOMDOMRequest isScoConnected();
-
-  // Fired when discoverying and any device is discovered.
-  [implicit_jscontext] attribute jsval ondevicefound;
-
-  // Fired when pairing process is completed
-  [implicit_jscontext] attribute jsval onpairedstatuschanged;
-
-  // Fired when a2dp connection status changed
-  [implicit_jscontext] attribute jsval ona2dpstatuschanged;
-
-  // Fired when handsfree connection status changed
-  [implicit_jscontext] attribute jsval onhfpstatuschanged;
-
-  // Fired when sco connection status changed
-  [implicit_jscontext] attribute jsval onscostatuschanged;
-};
new file mode 100644
--- /dev/null
+++ b/dom/webidl/BluetoothAdapter.webidl
@@ -0,0 +1,131 @@
+/* -*- 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/. */
+
+// MediaMetadata and MediaPlayStatus are used to keep data from Applications.
+// Please see specification of AVRCP 1.3 for more details.
+dictionary MediaMetaData
+{
+  // track title
+  DOMString   title = "";
+  // artist name
+  DOMString   artist = "";
+  // album name
+  DOMString   album = "";
+  // track number
+  long long   mediaNumber = -1;
+  // number of tracks in the album
+  long long   totalMediaCount = -1;
+  // playing time (ms)
+  long long   duration = -1;
+};
+
+dictionary MediaPlayStatus
+{
+  // current track length (ms)
+  long long   duration = -1;
+  // playing time (ms)
+  long long   position = -1;
+  // one of 'STOPPED'/'PLAYING'/'PAUSED'/'FWD_SEEK'/'REV_SEEK'/'ERROR'
+  DOMString   playStatus = "";
+};
+
+interface BluetoothAdapter : EventTarget {
+  readonly attribute DOMString      address;
+  readonly attribute unsigned long  class;
+  readonly attribute boolean        discovering;
+  readonly attribute DOMString      name;
+  readonly attribute boolean        discoverable;
+  readonly attribute unsigned long  discoverableTimeout; // in seconds
+
+  // array of type BluetoothDevice[]
+  [GetterThrows]
+  readonly attribute any            devices;
+
+  // array of type DOMString[]
+  [GetterThrows]
+  readonly attribute any            uuids;
+
+  [SetterThrows]
+           attribute EventHandler   ondevicefound;
+
+  // Fired when pairing process is completed
+  [SetterThrows]
+           attribute EventHandler   onpairedstatuschanged;
+
+  // Fired when a2dp connection status changed
+  [SetterThrows]
+           attribute EventHandler   ona2dpstatuschanged;
+
+  // Fired when handsfree connection status changed
+  [SetterThrows]
+           attribute EventHandler   onhfpstatuschanged;
+
+  // Fired when sco connection status changed
+  [SetterThrows]
+           attribute EventHandler   onscostatuschanged;
+
+  [Creator, Throws]
+  DOMRequest setName(DOMString name);
+  [Creator, Throws]
+  DOMRequest setDiscoverable(boolean discoverable);
+  [Creator, Throws]
+  DOMRequest setDiscoverableTimeout(unsigned long timeout);
+  [Creator, Throws]
+  DOMRequest startDiscovery();
+  [Creator, Throws]
+  DOMRequest stopDiscovery();
+  [Creator, Throws]
+  DOMRequest pair(BluetoothDevice device);
+  [Creator, Throws]
+  DOMRequest unpair(BluetoothDevice device);
+  [Creator, Throws]
+  DOMRequest getPairedDevices();
+  [Creator, Throws]
+  DOMRequest getConnectedDevices(unsigned short profile);
+  [Creator, Throws]
+  DOMRequest setPinCode(DOMString deviceAddress, DOMString pinCode);
+  [Creator, Throws]
+  DOMRequest setPasskey(DOMString deviceAddress, unsigned long passkey);
+  [Creator, Throws]
+  DOMRequest setPairingConfirmation(DOMString deviceAddress, boolean confirmation);
+  [Creator, Throws]
+  DOMRequest setAuthorization(DOMString deviceAddress, boolean allow);
+
+  /**
+   * Connect/Disconnect to a specific service of a target remote device.
+   * To check the value of service UUIDs, please check "Bluetooth Assigned
+   * Numbers" / "Service Discovery Protocol" for more information.
+   *
+   * @param deviceAddress Remote device address
+   * @param profile 2-octets service UUID
+   */
+  [Creator, Throws]
+  DOMRequest connect(DOMString deviceAddress, unsigned short profile);
+  [Creator, Throws]
+  DOMRequest disconnect(unsigned short profile);
+
+  // One device can only send one file at a time
+  [Creator, Throws]
+  DOMRequest sendFile(DOMString deviceAddress, Blob blob);
+  [Creator, Throws]
+  DOMRequest stopSendingFile(DOMString deviceAddress);
+  [Creator, Throws]
+  DOMRequest confirmReceivingFile(DOMString deviceAddress, boolean confirmation);
+
+  // Connect/Disconnect SCO (audio) connection
+  [Creator, Throws]
+  DOMRequest connectSco();
+  [Creator, Throws]
+  DOMRequest disconnectSco();
+  [Creator, Throws]
+  DOMRequest isScoConnected();
+
+  // AVRCP 1.3 methods
+  [Creator,Throws]
+  DOMRequest sendMediaMetaData(optional MediaMetaData mediaMetaData);
+  [Creator,Throws]
+  DOMRequest sendMediaPlayStatus(optional MediaPlayStatus mediaPlayStatus);
+};
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -470,16 +470,17 @@ webidl_files += \
   StyleRuleChangeEvent.webidl \
   StyleSheetApplicableStateChangeEvent.webidl \
   StyleSheetChangeEvent.webidl \
   UserProximityEvent.webidl \
   $(NULL)
 
 ifdef MOZ_B2G_BT
 webidl_files += \
+  BluetoothAdapter.webidl \
   BluetoothDeviceEvent.webidl \
   BluetoothManager.webidl \
   BluetoothStatusChangedEvent.webidl \
   $(NULL)
 endif
 
 ifdef MOZ_B2G_RIL
 webidl_files += \