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