2012-02-20 07:15:19 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-16 19:53:45 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-02-20 07:15:19 -08:00
|
|
|
/* 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/. */
|
|
|
|
|
2012-07-17 20:41:54 -07:00
|
|
|
#include "base/basictypes.h"
|
2013-05-23 07:10:00 -07:00
|
|
|
#include "nsCxPusher.h"
|
2012-02-20 07:15:19 -08:00
|
|
|
#include "nsDOMClassInfo.h"
|
2012-10-18 06:20:54 -07:00
|
|
|
#include "nsTArrayHelpers.h"
|
2013-01-28 22:52:39 -08:00
|
|
|
#include "DOMRequest.h"
|
2012-08-22 03:37:08 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2012-07-17 20:41:54 -07:00
|
|
|
|
2012-09-29 03:26:46 -07:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2013-08-12 01:32:53 -07:00
|
|
|
#include "mozilla/dom/BluetoothAdapterBinding.h"
|
2014-01-21 22:26:29 -08:00
|
|
|
#include "mozilla/dom/BluetoothDeviceEvent.h"
|
|
|
|
#include "mozilla/dom/BluetoothStatusChangedEvent.h"
|
2012-09-28 03:59:12 -07:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2012-02-23 07:55:48 -08:00
|
|
|
#include "mozilla/LazyIdleThread.h"
|
2012-03-27 16:17:35 -07:00
|
|
|
|
2013-07-29 02:32:35 -07:00
|
|
|
#include "BluetoothAdapter.h"
|
|
|
|
#include "BluetoothDevice.h"
|
|
|
|
#include "BluetoothReplyRunnable.h"
|
|
|
|
#include "BluetoothService.h"
|
|
|
|
#include "BluetoothUtils.h"
|
|
|
|
|
2012-07-17 20:41:54 -07:00
|
|
|
using namespace mozilla;
|
2013-08-12 01:32:53 -07:00
|
|
|
using namespace mozilla::dom;
|
2012-07-17 20:41:54 -07:00
|
|
|
|
2012-03-04 19:54:01 -08:00
|
|
|
USING_BLUETOOTH_NAMESPACE
|
2012-02-23 07:55:48 -08:00
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothAdapter)
|
|
|
|
|
2012-07-31 21:53:04 -07:00
|
|
|
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
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothAdapter,
|
2012-03-04 19:54:01 -08:00
|
|
|
nsDOMEventTargetHelper)
|
2012-07-31 21:53:04 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2012-03-04 19:54:01 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-02-20 07:15:19 -08:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothAdapter,
|
2012-03-04 19:54:01 -08:00
|
|
|
nsDOMEventTargetHelper)
|
2012-07-31 21:53:04 -07:00
|
|
|
tmp->Unroot();
|
2012-03-04 19:54:01 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-02-23 07:55:48 -08:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
// QueryInterface implementation for BluetoothAdapter
|
2012-03-04 19:54:01 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothAdapter)
|
2012-02-23 07:55:48 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
|
|
|
|
|
2013-04-26 03:48:21 -07:00
|
|
|
class GetDevicesTask : public BluetoothReplyRunnable
|
2012-08-16 19:53:45 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-04-26 03:48:21 -07:00
|
|
|
GetDevicesTask(BluetoothAdapter* aAdapterPtr,
|
2012-08-16 19:53:45 -07:00
|
|
|
nsIDOMDOMRequest* aReq) :
|
2012-09-19 16:37:42 -07:00
|
|
|
BluetoothReplyRunnable(aReq),
|
|
|
|
mAdapterPtr(aAdapterPtr)
|
2012-08-16 19:53:45 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aReq && aAdapterPtr);
|
|
|
|
}
|
|
|
|
|
2013-10-16 10:44:50 -07:00
|
|
|
virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
|
2012-08-16 19:53:45 -07:00
|
|
|
{
|
2013-10-16 10:44:50 -07:00
|
|
|
aValue.setUndefined();
|
2013-01-28 22:52:48 -08:00
|
|
|
|
|
|
|
const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
|
2012-08-16 19:53:45 -07:00
|
|
|
if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Not a BluetoothNamedValue array!");
|
2013-01-28 22:52:48 -08:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
|
2012-08-16 19:53:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
const InfallibleTArray<BluetoothNamedValue>& values =
|
|
|
|
v.get_ArrayOfBluetoothNamedValue();
|
|
|
|
|
2012-08-16 19:53:45 -07:00
|
|
|
nsTArray<nsRefPtr<BluetoothDevice> > devices;
|
2013-01-28 22:52:48 -08:00
|
|
|
for (uint32_t i = 0; i < values.Length(); i++) {
|
|
|
|
const BluetoothValue properties = values[i].value();
|
|
|
|
if (properties.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Not a BluetoothNamedValue array!");
|
2013-01-28 22:52:48 -08:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
|
2012-08-16 19:53:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothDevice> d =
|
|
|
|
BluetoothDevice::Create(mAdapterPtr->GetOwner(),
|
|
|
|
mAdapterPtr->GetPath(),
|
|
|
|
properties);
|
2012-08-16 19:53:45 -07:00
|
|
|
devices.AppendElement(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsIScriptContext* sc = mAdapterPtr->GetContextForEventHandlers(&rv);
|
|
|
|
if (!sc) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Cannot create script context!");
|
2013-01-28 22:52:48 -08:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothScriptContextError"));
|
2012-08-16 19:53:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-23 07:10:00 -07:00
|
|
|
AutoPushJSContext cx(sc->GetNativeContext());
|
2013-11-14 01:45:26 -08:00
|
|
|
JSObject* JsDevices = nullptr;
|
2013-05-23 07:10:00 -07:00
|
|
|
rv = nsTArrayToJSArray(cx, devices, &JsDevices);
|
2013-01-28 22:52:48 -08:00
|
|
|
if (!JsDevices) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Cannot create JS array!");
|
2013-01-28 22:52:48 -08:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothError"));
|
2012-08-16 19:53:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-28 22:52:48 -08:00
|
|
|
|
2013-10-16 10:44:50 -07:00
|
|
|
aValue.setObject(*JsDevices);
|
2012-08-16 19:53:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseMembers()
|
|
|
|
{
|
|
|
|
BluetoothReplyRunnable::ReleaseMembers();
|
|
|
|
mAdapterPtr = nullptr;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsRefPtr<BluetoothAdapter> mAdapterPtr;
|
|
|
|
};
|
|
|
|
|
2013-05-10 03:58:59 -07:00
|
|
|
class GetScoConnectionStatusTask : public BluetoothReplyRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GetScoConnectionStatusTask(nsIDOMDOMRequest* aReq) :
|
|
|
|
BluetoothReplyRunnable(aReq)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aReq);
|
|
|
|
}
|
|
|
|
|
2013-10-16 10:44:50 -07:00
|
|
|
virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
|
2013-05-10 03:58:59 -07:00
|
|
|
{
|
2013-10-16 10:44:50 -07:00
|
|
|
aValue.setUndefined();
|
2013-05-10 03:58:59 -07:00
|
|
|
|
|
|
|
const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
|
|
|
|
if (v.type() != BluetoothValue::Tbool) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Not a boolean!");
|
2013-05-10 03:58:59 -07:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-16 10:44:50 -07:00
|
|
|
aValue.setBoolean(v.get_bool());
|
2013-05-10 03:58:59 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseMembers()
|
|
|
|
{
|
|
|
|
BluetoothReplyRunnable::ReleaseMembers();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-17 03:35:59 -07:00
|
|
|
static int kCreatePairedDeviceTimeout = 50000; // unit: msec
|
|
|
|
|
2013-01-28 22:52:39 -08:00
|
|
|
BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aWindow,
|
|
|
|
const BluetoothValue& aValue)
|
2013-08-12 01:32:53 -07:00
|
|
|
: nsDOMEventTargetHelper(aWindow)
|
|
|
|
, BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
|
|
|
|
, mJsUuids(nullptr)
|
|
|
|
, mJsDeviceAddresses(nullptr)
|
2013-01-28 22:52:39 -08:00
|
|
|
, mDiscoverable(false)
|
|
|
|
, mDiscovering(false)
|
|
|
|
, mPairable(false)
|
|
|
|
, mPowered(false)
|
|
|
|
, mIsRooted(false)
|
2012-06-02 11:23:16 -07:00
|
|
|
{
|
2013-01-28 22:52:39 -08:00
|
|
|
MOZ_ASSERT(aWindow);
|
2013-08-12 01:32:53 -07:00
|
|
|
MOZ_ASSERT(IsDOMBinding());
|
2013-01-28 22:52:39 -08:00
|
|
|
|
|
|
|
BindToOwner(aWindow);
|
2012-08-08 10:47:09 -07:00
|
|
|
const InfallibleTArray<BluetoothNamedValue>& values =
|
|
|
|
aValue.get_ArrayOfBluetoothNamedValue();
|
|
|
|
for (uint32_t i = 0; i < values.Length(); ++i) {
|
|
|
|
SetPropertyByValue(values[i]);
|
|
|
|
}
|
2013-02-08 02:03:09 -08:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
NS_ENSURE_TRUE_VOID(bs);
|
2013-03-15 00:15:47 -07:00
|
|
|
bs->RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
2012-06-02 11:23:16 -07:00
|
|
|
|
|
|
|
BluetoothAdapter::~BluetoothAdapter()
|
|
|
|
{
|
2013-04-16 14:54:00 -07:00
|
|
|
Unroot();
|
2012-07-17 20:41:54 -07:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
// We can be null on shutdown, where this might happen
|
2013-02-08 02:03:09 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(bs);
|
2013-03-15 00:15:47 -07:00
|
|
|
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothAdapter::Unroot()
|
|
|
|
{
|
|
|
|
if (!mIsRooted) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-27 17:37:57 -08:00
|
|
|
mJsUuids = nullptr;
|
|
|
|
mJsDeviceAddresses = nullptr;
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-07-31 21:53:04 -07:00
|
|
|
mIsRooted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothAdapter::Root()
|
|
|
|
{
|
|
|
|
if (mIsRooted) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(this);
|
2012-07-31 21:53:04 -07:00
|
|
|
mIsRooted = true;
|
2012-07-17 20:41:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothAdapter::SetPropertyByValue(const BluetoothNamedValue& aValue)
|
|
|
|
{
|
|
|
|
const nsString& name = aValue.name();
|
|
|
|
const BluetoothValue& value = aValue.value();
|
|
|
|
if (name.EqualsLiteral("Name")) {
|
|
|
|
mName = value.get_nsString();
|
|
|
|
} else if (name.EqualsLiteral("Address")) {
|
|
|
|
mAddress = value.get_nsString();
|
2012-07-31 21:53:04 -07:00
|
|
|
} else if (name.EqualsLiteral("Path")) {
|
|
|
|
mPath = value.get_nsString();
|
2012-07-17 20:41:54 -07:00
|
|
|
} else if (name.EqualsLiteral("Discoverable")) {
|
|
|
|
mDiscoverable = value.get_bool();
|
2012-07-31 21:53:04 -07:00
|
|
|
} else if (name.EqualsLiteral("Discovering")) {
|
|
|
|
mDiscovering = value.get_bool();
|
2012-07-17 20:41:54 -07:00
|
|
|
} else if (name.EqualsLiteral("Pairable")) {
|
|
|
|
mPairable = value.get_bool();
|
|
|
|
} else if (name.EqualsLiteral("Powered")) {
|
|
|
|
mPowered = value.get_bool();
|
|
|
|
} else if (name.EqualsLiteral("PairableTimeout")) {
|
|
|
|
mPairableTimeout = value.get_uint32_t();
|
|
|
|
} else if (name.EqualsLiteral("DiscoverableTimeout")) {
|
|
|
|
mDiscoverableTimeout = value.get_uint32_t();
|
|
|
|
} else if (name.EqualsLiteral("Class")) {
|
|
|
|
mClass = value.get_uint32_t();
|
|
|
|
} else if (name.EqualsLiteral("UUIDs")) {
|
|
|
|
mUuids = value.get_ArrayOfnsString();
|
2012-07-31 21:53:04 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
2013-01-28 22:52:39 -08:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2013-11-05 22:26:46 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(sc);
|
2013-01-28 22:52:39 -08:00
|
|
|
|
2013-05-23 07:10:00 -07:00
|
|
|
AutoPushJSContext cx(sc->GetNativeContext());
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Rooted<JSObject*> uuids(cx);
|
|
|
|
if (NS_FAILED(nsTArrayToJSArray(cx, mUuids, uuids.address()))) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Cannot set JS UUIDs object!");
|
2013-01-28 22:52:39 -08:00
|
|
|
return;
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
2013-06-18 03:00:38 -07:00
|
|
|
mJsUuids = uuids;
|
2013-01-28 22:52:39 -08:00
|
|
|
Root();
|
2012-07-31 21:53:04 -07:00
|
|
|
} else if (name.EqualsLiteral("Devices")) {
|
|
|
|
mDeviceAddresses = value.get_ArrayOfnsString();
|
2013-04-26 03:48:21 -07:00
|
|
|
|
2012-07-31 21:53:04 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
2013-01-28 22:52:39 -08:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2013-11-05 22:26:46 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(sc);
|
2013-01-28 22:52:39 -08:00
|
|
|
|
2013-05-23 07:10:00 -07:00
|
|
|
AutoPushJSContext cx(sc->GetNativeContext());
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Rooted<JSObject*> deviceAddresses(cx);
|
2013-05-23 07:10:00 -07:00
|
|
|
if (NS_FAILED(nsTArrayToJSArray(cx, mDeviceAddresses,
|
2013-06-18 03:00:38 -07:00
|
|
|
deviceAddresses.address()))) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Cannot set JS Devices object!");
|
2013-01-28 22:52:39 -08:00
|
|
|
return;
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
2013-06-18 03:00:38 -07:00
|
|
|
mJsDeviceAddresses = deviceAddresses;
|
2013-01-28 22:52:39 -08:00
|
|
|
Root();
|
2012-07-17 20:41:54 -07:00
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCString warningMsg;
|
|
|
|
warningMsg.AssignLiteral("Not handling adapter property: ");
|
|
|
|
warningMsg.Append(NS_ConvertUTF16toUTF8(name));
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING(warningMsg.get());
|
2012-07-17 20:41:54 -07:00
|
|
|
#endif
|
2012-06-02 11:23:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<BluetoothAdapter>
|
2013-01-28 22:52:39 -08:00
|
|
|
BluetoothAdapter::Create(nsPIDOMWindow* aWindow, const BluetoothValue& aValue)
|
2012-07-17 20:41:54 -07:00
|
|
|
{
|
2013-01-28 22:52:39 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aWindow);
|
2012-07-17 20:41:54 -07:00
|
|
|
|
2013-01-28 22:52:39 -08:00
|
|
|
nsRefPtr<BluetoothAdapter> adapter = new BluetoothAdapter(aWindow, aValue);
|
2012-06-02 11:23:16 -07:00
|
|
|
return adapter.forget();
|
|
|
|
}
|
|
|
|
|
2012-07-17 20:41:54 -07:00
|
|
|
void
|
|
|
|
BluetoothAdapter::Notify(const BluetoothSignal& aData)
|
|
|
|
{
|
2012-08-17 03:35:59 -07:00
|
|
|
InfallibleTArray<BluetoothNamedValue> arr;
|
|
|
|
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_LOGD("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get());
|
2013-01-29 02:37:51 -08:00
|
|
|
|
2013-01-28 22:52:30 -08:00
|
|
|
BluetoothValue v = aData.value();
|
2012-07-17 20:41:54 -07:00
|
|
|
if (aData.name().EqualsLiteral("DeviceFound")) {
|
2012-08-20 19:54:28 -07:00
|
|
|
nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value());
|
|
|
|
|
2014-01-21 22:26:29 -08:00
|
|
|
BluetoothDeviceEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mDevice = device;
|
|
|
|
nsRefPtr<BluetoothDeviceEvent> event =
|
|
|
|
BluetoothDeviceEvent::Constructor(this, NS_LITERAL_STRING("devicefound"), init);
|
2012-09-27 13:11:31 -07:00
|
|
|
DispatchTrustedEvent(event);
|
2012-07-31 21:53:04 -07:00
|
|
|
} else if (aData.name().EqualsLiteral("PropertyChanged")) {
|
2013-08-02 03:33:15 -07:00
|
|
|
MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
|
2013-12-18 02:21:05 -08:00
|
|
|
|
2013-01-28 22:52:30 -08:00
|
|
|
const InfallibleTArray<BluetoothNamedValue>& arr =
|
|
|
|
v.get_ArrayOfBluetoothNamedValue();
|
2012-09-18 20:19:45 -07:00
|
|
|
|
2013-12-18 02:21:05 -08:00
|
|
|
for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
|
|
|
|
SetPropertyByValue(arr[i]);
|
|
|
|
}
|
2013-08-02 03:33:15 -07:00
|
|
|
} else if (aData.name().EqualsLiteral(PAIRED_STATUS_CHANGED_ID) ||
|
|
|
|
aData.name().EqualsLiteral(HFP_STATUS_CHANGED_ID) ||
|
|
|
|
aData.name().EqualsLiteral(SCO_STATUS_CHANGED_ID) ||
|
|
|
|
aData.name().EqualsLiteral(A2DP_STATUS_CHANGED_ID)) {
|
|
|
|
MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
|
|
|
|
const InfallibleTArray<BluetoothNamedValue>& arr =
|
|
|
|
v.get_ArrayOfBluetoothNamedValue();
|
|
|
|
|
|
|
|
MOZ_ASSERT(arr.Length() == 2 &&
|
|
|
|
arr[0].value().type() == BluetoothValue::TnsString &&
|
|
|
|
arr[1].value().type() == BluetoothValue::Tbool);
|
|
|
|
nsString address = arr[0].value().get_nsString();
|
|
|
|
bool status = arr[1].value().get_bool();
|
|
|
|
|
2014-01-21 22:26:29 -08:00
|
|
|
BluetoothStatusChangedEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mAddress = address;
|
|
|
|
init.mStatus = status;
|
|
|
|
nsRefPtr<BluetoothStatusChangedEvent> event =
|
|
|
|
BluetoothStatusChangedEvent::Constructor(this, aData.name(), init);
|
2013-08-02 03:33:15 -07:00
|
|
|
DispatchTrustedEvent(event);
|
2013-09-03 19:40:01 -07:00
|
|
|
} else if (aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) {
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
|
|
|
|
rv = event->InitEvent(aData.name(), false, false);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
|
|
|
|
DispatchTrustedEvent(event);
|
2012-07-17 20:41:54 -07:00
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCString warningMsg;
|
2012-09-05 20:06:20 -07:00
|
|
|
warningMsg.AssignLiteral("Not handling adapter signal: ");
|
2012-07-17 20:41:54 -07:00
|
|
|
warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING(warningMsg.get());
|
2012-07-17 20:41:54 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StartStopDiscovery(bool aStart, ErrorResult& aRv)
|
2012-07-17 20:41:54 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-17 20:41:54 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-07-17 20:41:54 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsresult rv;
|
2012-07-17 20:41:54 -07:00
|
|
|
if (aStart) {
|
2013-03-15 00:15:47 -07:00
|
|
|
rv = bs->StartDiscoveryInternal(results);
|
2012-07-17 20:41:54 -07:00
|
|
|
} else {
|
2013-03-15 00:15:47 -07:00
|
|
|
rv = bs->StopDiscoveryInternal(results);
|
2012-07-17 20:41:54 -07:00
|
|
|
}
|
2013-08-12 01:32:53 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Start/Stop Discovery failed!");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-07-17 20:41:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// mDiscovering is not set here, we'll get a Property update from our external
|
|
|
|
// protocol to tell us that it's been set.
|
2013-01-28 22:52:48 -08:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2013-08-12 09:08:03 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
|
2013-08-12 09:08:03 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
return StartStopDiscovery(true, aRv);
|
2013-08-12 09:08:03 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StopDiscovery(ErrorResult& aRv)
|
2013-08-12 09:08:03 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
return StartStopDiscovery(false, aRv);
|
2013-08-12 09:08:03 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
JS::Value
|
|
|
|
BluetoothAdapter::GetDevices(JSContext* aContext, ErrorResult& aRv)
|
2013-08-12 09:08:03 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!mJsDeviceAddresses) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Devices not yet set!\n");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return JS::NullValue();
|
2013-08-12 01:32:53 -07:00
|
|
|
}
|
2013-08-12 01:32:53 -07:00
|
|
|
|
2013-09-08 20:28:48 -07:00
|
|
|
JS::ExposeObjectToActiveJS(mJsDeviceAddresses);
|
|
|
|
return JS::ObjectValue(*mJsDeviceAddresses);
|
2013-08-12 09:08:03 -07:00
|
|
|
}
|
2013-08-12 01:32:53 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
JS::Value
|
|
|
|
BluetoothAdapter::GetUuids(JSContext* aContext, ErrorResult& aRv)
|
2013-08-12 09:08:03 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!mJsUuids) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("UUIDs not yet set!\n");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
2013-09-08 20:28:48 -07:00
|
|
|
JS::ExposeObjectToActiveJS(mJsUuids);
|
|
|
|
return JS::ObjectValue(*mJsUuids);
|
2012-07-17 20:41:54 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SetName(const nsAString& aName, ErrorResult& aRv)
|
2012-07-31 21:53:04 -07:00
|
|
|
{
|
|
|
|
if (mName.Equals(aName)) {
|
2013-08-12 01:32:53 -07:00
|
|
|
return FirePropertyAlreadySet(GetOwner(), aRv);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
|
|
|
nsString name(aName);
|
|
|
|
BluetoothValue value(name);
|
|
|
|
BluetoothNamedValue property(NS_LITERAL_STRING("Name"), value);
|
2013-08-12 01:32:53 -07:00
|
|
|
return SetProperty(GetOwner(), property, aRv);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
2013-03-15 00:15:47 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SetDiscoverable(bool aDiscoverable, ErrorResult& aRv)
|
2012-07-31 21:53:04 -07:00
|
|
|
{
|
|
|
|
if (aDiscoverable == mDiscoverable) {
|
2013-08-12 01:32:53 -07:00
|
|
|
return FirePropertyAlreadySet(GetOwner(), aRv);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
|
|
|
BluetoothValue value(aDiscoverable);
|
|
|
|
BluetoothNamedValue property(NS_LITERAL_STRING("Discoverable"), value);
|
2013-08-12 01:32:53 -07:00
|
|
|
return SetProperty(GetOwner(), property, aRv);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
2013-08-12 01:32:53 -07:00
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SetDiscoverableTimeout(uint32_t aDiscoverableTimeout, ErrorResult& aRv)
|
2012-07-31 21:53:04 -07:00
|
|
|
{
|
|
|
|
if (aDiscoverableTimeout == mDiscoverableTimeout) {
|
2013-08-12 01:32:53 -07:00
|
|
|
return FirePropertyAlreadySet(GetOwner(), aRv);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
|
|
|
BluetoothValue value(aDiscoverableTimeout);
|
|
|
|
BluetoothNamedValue property(NS_LITERAL_STRING("DiscoverableTimeout"), value);
|
2013-08-12 01:32:53 -07:00
|
|
|
return SetProperty(GetOwner(), property, aRv);
|
2012-07-31 21:53:04 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-09-06 04:19:46 -07:00
|
|
|
BluetoothAdapter::GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv)
|
2013-04-26 03:48:21 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-04-26 03:48:21 -07:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new GetDevicesTask(this, request);
|
2013-04-26 03:48:21 -07:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-06 04:19:46 -07:00
|
|
|
nsresult rv = bs->GetConnectedDevicePropertiesInternal(aServiceUuid, results);
|
2013-08-12 01:32:53 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-04-26 03:48:21 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2013-04-26 03:48:21 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::GetPairedDevices(ErrorResult& aRv)
|
2012-08-16 19:53:45 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-16 19:53:45 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new GetDevicesTask(this, request);
|
2012-08-16 19:53:45 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsresult rv = bs->GetPairedDevicePropertiesInternal(mDeviceAddresses, results);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-16 19:53:45 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-08-16 19:53:45 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-11-15 01:19:31 -08:00
|
|
|
BluetoothAdapter::PairUnpair(bool aPair, const nsAString& aDeviceAddress,
|
2013-08-12 01:32:53 -07:00
|
|
|
ErrorResult& aRv)
|
2012-08-17 03:35:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-17 03:35:59 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-08-17 03:35:59 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsresult rv;
|
2012-08-17 03:35:59 -07:00
|
|
|
if (aPair) {
|
2013-11-15 01:19:31 -08:00
|
|
|
rv = bs->CreatePairedDeviceInternal(aDeviceAddress,
|
2012-08-17 03:35:59 -07:00
|
|
|
kCreatePairedDeviceTimeout,
|
|
|
|
results);
|
|
|
|
} else {
|
2013-11-15 01:19:31 -08:00
|
|
|
rv = bs->RemoveDeviceInternal(aDeviceAddress, results);
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Pair/Unpair failed!");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-11-15 01:19:31 -08:00
|
|
|
BluetoothAdapter::Pair(const nsAString& aDeviceAddress, ErrorResult& aRv)
|
2012-08-17 03:35:59 -07:00
|
|
|
{
|
2013-11-15 01:19:31 -08:00
|
|
|
return PairUnpair(true, aDeviceAddress, aRv);
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-11-15 01:19:31 -08:00
|
|
|
BluetoothAdapter::Unpair(const nsAString& aDeviceAddress, ErrorResult& aRv)
|
2012-08-17 03:35:59 -07:00
|
|
|
{
|
2013-11-15 01:19:31 -08:00
|
|
|
return PairUnpair(false, aDeviceAddress, aRv);
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-19 16:37:42 -07:00
|
|
|
BluetoothAdapter::SetPinCode(const nsAString& aDeviceAddress,
|
2013-08-12 01:32:53 -07:00
|
|
|
const nsAString& aPinCode, ErrorResult& aRv)
|
2012-08-17 03:35:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-19 16:37:42 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-19 16:37:42 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!bs->SetPinCodeInternal(aDeviceAddress, aPinCode, results)) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("SetPinCode failed!");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-09-19 16:37:42 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-19 16:37:42 -07:00
|
|
|
BluetoothAdapter::SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
|
2013-08-12 01:32:53 -07:00
|
|
|
ErrorResult& aRv)
|
2012-08-17 03:35:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-19 16:37:42 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-19 16:37:42 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (bs->SetPasskeyInternal(aDeviceAddress, aPasskey, results)) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("SetPasskeyInternal failed!");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-09-19 16:37:42 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-19 16:37:42 -07:00
|
|
|
BluetoothAdapter::SetPairingConfirmation(const nsAString& aDeviceAddress,
|
2013-08-12 01:32:53 -07:00
|
|
|
bool aConfirmation, ErrorResult& aRv)
|
2012-08-17 03:35:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-19 16:37:42 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-19 16:37:42 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!bs->SetPairingConfirmationInternal(aDeviceAddress,
|
|
|
|
aConfirmation,
|
|
|
|
results)) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("SetPairingConfirmation failed!");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-09-19 16:37:42 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-08-17 03:35:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-09-06 04:19:46 -07:00
|
|
|
BluetoothAdapter::Connect(BluetoothDevice& aDevice,
|
|
|
|
const Optional<short unsigned int>& aServiceUuid,
|
|
|
|
ErrorResult& aRv)
|
2012-09-29 03:26:46 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-12 09:08:03 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-08-12 09:08:03 -07:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
|
|
|
|
2013-09-06 04:19:46 -07:00
|
|
|
nsAutoString address;
|
|
|
|
aDevice.GetAddress(address);
|
|
|
|
uint32_t deviceClass = aDevice.Class();
|
|
|
|
uint16_t serviceUuid = 0;
|
|
|
|
if (aServiceUuid.WasPassed()) {
|
|
|
|
serviceUuid = aServiceUuid.Value();
|
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-06 04:19:46 -07:00
|
|
|
bs->Connect(address, deviceClass, serviceUuid, results);
|
2012-09-29 03:26:46 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-09-29 03:26:46 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-09-06 04:19:46 -07:00
|
|
|
BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
|
|
|
|
const Optional<short unsigned int>& aServiceUuid,
|
|
|
|
ErrorResult& aRv)
|
2012-09-29 03:26:46 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-29 03:26:46 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-01-28 22:52:48 -08:00
|
|
|
|
2013-09-06 04:19:46 -07:00
|
|
|
nsAutoString address;
|
|
|
|
aDevice.GetAddress(address);
|
|
|
|
uint16_t serviceUuid = 0;
|
|
|
|
if (aServiceUuid.WasPassed()) {
|
|
|
|
serviceUuid = aServiceUuid.Value();
|
|
|
|
}
|
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-06 04:19:46 -07:00
|
|
|
bs->Disconnect(address, serviceUuid, results);
|
2012-09-29 03:26:46 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-09-29 03:26:46 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-29 03:26:46 -07:00
|
|
|
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
|
2013-08-12 01:32:53 -07:00
|
|
|
nsIDOMBlob* aBlob, ErrorResult& aRv)
|
2012-09-29 03:26:46 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-28 03:59:12 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-28 03:59:12 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BlobChild* actor =
|
2013-08-12 01:32:53 -07:00
|
|
|
ContentChild::GetSingleton()->GetOrCreateActorForBlob(aBlob);
|
2012-09-28 03:59:12 -07:00
|
|
|
if (!actor) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Can't create actor");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-09-28 03:59:12 -07:00
|
|
|
}
|
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-01-28 22:52:48 -08:00
|
|
|
bs->SendFile(aDeviceAddress, nullptr, actor, results);
|
2012-09-28 03:59:12 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-09-29 03:26:46 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv)
|
2012-09-29 03:26:46 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-10-03 00:09:27 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-10-03 00:09:27 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-01-28 22:52:48 -08:00
|
|
|
bs->StopSendingFile(aDeviceAddress, results);
|
2012-10-03 00:09:27 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-09-29 03:26:46 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-10-18 23:16:13 -07:00
|
|
|
BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
|
2013-08-12 01:32:53 -07:00
|
|
|
bool aConfirmation, ErrorResult& aRv)
|
2012-10-18 23:16:13 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-10-18 23:16:13 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-28 22:52:48 -08:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-10-18 23:16:13 -07:00
|
|
|
|
2013-01-28 22:52:48 -08:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-01-28 22:52:48 -08:00
|
|
|
bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, results);
|
2012-10-18 23:16:13 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-10-18 23:16:13 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::ConnectSco(ErrorResult& aRv)
|
2013-05-10 03:58:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 03:58:59 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-05-10 03:58:59 -07:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-05-10 03:58:59 -07:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 03:58:59 -07:00
|
|
|
bs->ConnectSco(results);
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2013-05-10 03:58:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::DisconnectSco(ErrorResult& aRv)
|
2013-05-10 03:58:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 03:58:59 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-05-10 03:58:59 -07:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-05-10 03:58:59 -07:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 03:58:59 -07:00
|
|
|
bs->DisconnectSco(results);
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2013-05-10 03:58:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::IsScoConnected(ErrorResult& aRv)
|
2013-05-10 03:58:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 03:58:59 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-05-10 03:58:59 -07:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new GetScoConnectionStatusTask(request);
|
2013-05-10 03:58:59 -07:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 03:58:59 -07:00
|
|
|
bs->IsScoConnected(results);
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2013-05-10 03:58:59 -07:00
|
|
|
}
|
|
|
|
|
2013-10-15 19:38:13 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::AnswerWaitingCall(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-15 19:38:13 -07:00
|
|
|
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->AnswerWaitingCall(results);
|
|
|
|
|
|
|
|
return request.forget();
|
2013-10-29 01:12:46 -07:00
|
|
|
#else
|
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-15 19:38:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::IgnoreWaitingCall(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-15 19:38:13 -07:00
|
|
|
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->IgnoreWaitingCall(results);
|
|
|
|
|
|
|
|
return request.forget();
|
2013-10-29 01:12:46 -07:00
|
|
|
#else
|
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-15 19:38:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::ToggleCalls(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-29 01:12:46 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-15 19:38:13 -07:00
|
|
|
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->ToggleCalls(results);
|
|
|
|
|
|
|
|
return request.forget();
|
2013-10-29 01:12:46 -07:00
|
|
|
#else
|
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-15 19:38:13 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv)
|
2013-07-29 02:32:34 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-29 02:32:34 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-07-29 02:32:34 -07:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-07-29 02:32:34 -07:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bs->SendMetaData(aMediaMetaData.mTitle,
|
|
|
|
aMediaMetaData.mArtist,
|
|
|
|
aMediaMetaData.mAlbum,
|
|
|
|
aMediaMetaData.mMediaNumber,
|
|
|
|
aMediaMetaData.mTotalMediaCount,
|
|
|
|
aMediaMetaData.mDuration,
|
2013-07-29 02:32:34 -07:00
|
|
|
results);
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2013-07-29 02:32:34 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv)
|
2013-07-29 02:32:34 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-29 02:32:34 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-07-29 02:32:34 -07:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 01:32:53 -07:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-07-29 02:32:34 -07:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bs->SendPlayStatus(aMediaPlayStatus.mDuration,
|
|
|
|
aMediaPlayStatus.mPosition,
|
|
|
|
aMediaPlayStatus.mPlayStatus,
|
2013-07-29 02:32:34 -07:00
|
|
|
results);
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2013-07-29 02:32:34 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
JSObject*
|
|
|
|
BluetoothAdapter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
|
|
|
{
|
|
|
|
return BluetoothAdapterBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|