2012-02-20 15:15:19 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-17 02:53:45 +00:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-02-20 15:15:19 +00: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 03:41:54 +00:00
|
|
|
#include "base/basictypes.h"
|
2012-02-20 15:15:19 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
2012-10-18 13:20:54 +00:00
|
|
|
#include "nsTArrayHelpers.h"
|
2013-01-29 06:52:39 +00:00
|
|
|
#include "DOMRequest.h"
|
2012-08-22 10:37:08 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2012-07-18 03:41:54 +00:00
|
|
|
|
2012-09-29 10:26:46 +00:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2013-08-12 08:32:53 +00:00
|
|
|
#include "mozilla/dom/BluetoothAdapterBinding.h"
|
2014-01-22 06:26:29 +00:00
|
|
|
#include "mozilla/dom/BluetoothDeviceEvent.h"
|
2014-05-23 06:00:25 +00:00
|
|
|
#include "mozilla/dom/BluetoothDiscoveryStateChangedEvent.h"
|
2014-01-22 06:26:29 +00:00
|
|
|
#include "mozilla/dom/BluetoothStatusChangedEvent.h"
|
2012-09-28 10:59:12 +00:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2014-10-08 16:15:23 +00:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-06-19 19:09:03 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2012-02-23 15:55:48 +00:00
|
|
|
#include "mozilla/LazyIdleThread.h"
|
2012-03-27 23:17:35 +00:00
|
|
|
|
2013-07-29 09:32:35 +00:00
|
|
|
#include "BluetoothAdapter.h"
|
|
|
|
#include "BluetoothDevice.h"
|
|
|
|
#include "BluetoothReplyRunnable.h"
|
|
|
|
#include "BluetoothService.h"
|
|
|
|
#include "BluetoothUtils.h"
|
|
|
|
|
2012-07-18 03:41:54 +00:00
|
|
|
using namespace mozilla;
|
2013-08-12 08:32:53 +00:00
|
|
|
using namespace mozilla::dom;
|
2012-07-18 03:41:54 +00:00
|
|
|
|
2012-03-05 03:54:01 +00:00
|
|
|
USING_BLUETOOTH_NAMESPACE
|
2012-02-23 15:55:48 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothAdapter)
|
|
|
|
|
2012-08-01 04:53:04 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothAdapter,
|
2014-04-01 06:13:50 +00:00
|
|
|
DOMEventTargetHelper)
|
2012-08-01 04:53:04 +00:00
|
|
|
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 08:32:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothAdapter,
|
2014-04-01 06:13:50 +00:00
|
|
|
DOMEventTargetHelper)
|
2012-08-01 04:53:04 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2012-03-05 03:54:01 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-02-20 15:15:19 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothAdapter,
|
2014-04-01 06:13:50 +00:00
|
|
|
DOMEventTargetHelper)
|
2012-08-01 04:53:04 +00:00
|
|
|
tmp->Unroot();
|
2012-03-05 03:54:01 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-02-23 15:55:48 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
// QueryInterface implementation for BluetoothAdapter
|
2012-03-05 03:54:01 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothAdapter)
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-02-23 15:55:48 +00:00
|
|
|
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(BluetoothAdapter, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(BluetoothAdapter, DOMEventTargetHelper)
|
2012-02-23 15:55:48 +00:00
|
|
|
|
2013-04-26 10:48:21 +00:00
|
|
|
class GetDevicesTask : public BluetoothReplyRunnable
|
2012-08-17 02:53:45 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-04-26 10:48:21 +00:00
|
|
|
GetDevicesTask(BluetoothAdapter* aAdapterPtr,
|
2012-08-17 02:53:45 +00:00
|
|
|
nsIDOMDOMRequest* aReq) :
|
2012-09-19 23:37:42 +00:00
|
|
|
BluetoothReplyRunnable(aReq),
|
|
|
|
mAdapterPtr(aAdapterPtr)
|
2012-08-17 02:53:45 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aReq && aAdapterPtr);
|
|
|
|
}
|
|
|
|
|
2013-10-16 17:44:50 +00:00
|
|
|
virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
|
2012-08-17 02:53:45 +00:00
|
|
|
{
|
2013-10-16 17:44:50 +00:00
|
|
|
aValue.setUndefined();
|
2013-01-29 06:52:48 +00:00
|
|
|
|
|
|
|
const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
|
2012-08-17 02:53:45 +00:00
|
|
|
if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Not a BluetoothNamedValue array!");
|
2013-01-29 06:52:48 +00:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
|
2012-08-17 02:53:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
const InfallibleTArray<BluetoothNamedValue>& values =
|
|
|
|
v.get_ArrayOfBluetoothNamedValue();
|
|
|
|
|
2012-08-17 02:53:45 +00:00
|
|
|
nsTArray<nsRefPtr<BluetoothDevice> > devices;
|
2013-01-29 06:52:48 +00:00
|
|
|
for (uint32_t i = 0; i < values.Length(); i++) {
|
|
|
|
const BluetoothValue properties = values[i].value();
|
|
|
|
if (properties.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Not a BluetoothNamedValue array!");
|
2013-01-29 06:52:48 +00:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
|
2012-08-17 02:53:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothDevice> d =
|
|
|
|
BluetoothDevice::Create(mAdapterPtr->GetOwner(),
|
|
|
|
mAdapterPtr->GetPath(),
|
|
|
|
properties);
|
2012-08-17 02:53:45 +00:00
|
|
|
devices.AppendElement(d);
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:09:03 +00:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 10:17:17 +00:00
|
|
|
if (!jsapi.Init(mAdapterPtr->GetOwner())) {
|
2014-06-19 19:09:03 +00:00
|
|
|
BT_WARNING("Failed to initialise AutoJSAPI!");
|
|
|
|
SetError(NS_LITERAL_STRING("BluetoothAutoJSAPIInitError"));
|
2012-08-17 02:53:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-06-19 19:09:03 +00:00
|
|
|
JSContext* cx = jsapi.cx();
|
2014-06-02 16:40:13 +00:00
|
|
|
JS::Rooted<JSObject*> JsDevices(cx);
|
2014-06-19 19:09:03 +00:00
|
|
|
if (NS_FAILED(nsTArrayToJSArray(cx, devices, &JsDevices))) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Cannot create JS array!");
|
2013-01-29 06:52:48 +00:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothError"));
|
2012-08-17 02:53:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-29 06:52:48 +00:00
|
|
|
|
2013-10-16 17:44:50 +00:00
|
|
|
aValue.setObject(*JsDevices);
|
2012-08-17 02:53:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseMembers()
|
|
|
|
{
|
|
|
|
BluetoothReplyRunnable::ReleaseMembers();
|
|
|
|
mAdapterPtr = nullptr;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsRefPtr<BluetoothAdapter> mAdapterPtr;
|
|
|
|
};
|
|
|
|
|
2014-08-26 10:50:35 +00:00
|
|
|
class GetConnectionStatusTask : public BluetoothReplyRunnable
|
2013-05-10 10:58:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-08-26 10:50:35 +00:00
|
|
|
GetConnectionStatusTask(nsIDOMDOMRequest* aReq) :
|
2013-05-10 10:58:59 +00:00
|
|
|
BluetoothReplyRunnable(aReq)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aReq);
|
|
|
|
}
|
|
|
|
|
2013-10-16 17:44:50 +00:00
|
|
|
virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
|
2013-05-10 10:58:59 +00:00
|
|
|
{
|
2013-10-16 17:44:50 +00:00
|
|
|
aValue.setUndefined();
|
2013-05-10 10:58:59 +00:00
|
|
|
|
|
|
|
const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
|
|
|
|
if (v.type() != BluetoothValue::Tbool) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Not a boolean!");
|
2013-05-10 10:58:59 +00:00
|
|
|
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-16 17:44:50 +00:00
|
|
|
aValue.setBoolean(v.get_bool());
|
2013-05-10 10:58:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseMembers()
|
|
|
|
{
|
|
|
|
BluetoothReplyRunnable::ReleaseMembers();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-17 10:35:59 +00:00
|
|
|
static int kCreatePairedDeviceTimeout = 50000; // unit: msec
|
|
|
|
|
2013-01-29 06:52:39 +00:00
|
|
|
BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aWindow,
|
|
|
|
const BluetoothValue& aValue)
|
2014-04-01 06:13:50 +00:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2013-08-12 08:32:53 +00:00
|
|
|
, BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
|
|
|
|
, mJsUuids(nullptr)
|
|
|
|
, mJsDeviceAddresses(nullptr)
|
2013-01-29 06:52:39 +00:00
|
|
|
, mDiscoverable(false)
|
|
|
|
, mDiscovering(false)
|
|
|
|
, mPairable(false)
|
|
|
|
, mPowered(false)
|
|
|
|
, mIsRooted(false)
|
2012-06-02 18:23:16 +00:00
|
|
|
{
|
2013-01-29 06:52:39 +00:00
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
2012-08-08 17:47:09 +00:00
|
|
|
const InfallibleTArray<BluetoothNamedValue>& values =
|
|
|
|
aValue.get_ArrayOfBluetoothNamedValue();
|
|
|
|
for (uint32_t i = 0; i < values.Length(); ++i) {
|
|
|
|
SetPropertyByValue(values[i]);
|
|
|
|
}
|
2013-02-08 10:03:09 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
NS_ENSURE_TRUE_VOID(bs);
|
2013-03-15 07:15:47 +00:00
|
|
|
bs->RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
2012-06-02 18:23:16 +00:00
|
|
|
|
|
|
|
BluetoothAdapter::~BluetoothAdapter()
|
|
|
|
{
|
2013-04-16 21:54:00 +00:00
|
|
|
Unroot();
|
2012-07-18 03:41:54 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
// We can be null on shutdown, where this might happen
|
2013-02-08 10:03:09 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(bs);
|
2013-03-15 07:15:47 +00:00
|
|
|
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
|
2014-04-01 12:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothAdapter::DisconnectFromOwner()
|
|
|
|
{
|
2014-04-01 22:10:06 +00:00
|
|
|
DOMEventTargetHelper::DisconnectFromOwner();
|
2014-04-01 12:58:56 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
NS_ENSURE_TRUE_VOID(bs);
|
|
|
|
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothAdapter::Unroot()
|
|
|
|
{
|
|
|
|
if (!mIsRooted) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 01:37:57 +00:00
|
|
|
mJsUuids = nullptr;
|
|
|
|
mJsDeviceAddresses = nullptr;
|
2013-08-16 20:10:17 +00:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-08-01 04:53:04 +00:00
|
|
|
mIsRooted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BluetoothAdapter::Root()
|
|
|
|
{
|
|
|
|
if (mIsRooted) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-16 20:10:17 +00:00
|
|
|
mozilla::HoldJSObjects(this);
|
2012-08-01 04:53:04 +00:00
|
|
|
mIsRooted = true;
|
2012-07-18 03:41:54 +00: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 04:53:04 +00:00
|
|
|
} else if (name.EqualsLiteral("Path")) {
|
|
|
|
mPath = value.get_nsString();
|
2012-07-18 03:41:54 +00:00
|
|
|
} else if (name.EqualsLiteral("Discoverable")) {
|
|
|
|
mDiscoverable = value.get_bool();
|
2012-08-01 04:53:04 +00:00
|
|
|
} else if (name.EqualsLiteral("Discovering")) {
|
|
|
|
mDiscovering = value.get_bool();
|
2012-07-18 03:41:54 +00: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();
|
2013-01-29 06:52:39 +00:00
|
|
|
|
2014-06-19 19:14:32 +00:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 10:17:17 +00:00
|
|
|
if (!jsapi.Init(GetOwner())) {
|
2014-06-19 19:14:32 +00:00
|
|
|
BT_WARNING("Failed to initialise AutoJSAPI!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSContext* cx = jsapi.cx();
|
2013-06-18 10:00:38 +00:00
|
|
|
JS::Rooted<JSObject*> uuids(cx);
|
2014-06-02 16:40:13 +00:00
|
|
|
if (NS_FAILED(nsTArrayToJSArray(cx, mUuids, &uuids))) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Cannot set JS UUIDs object!");
|
2013-01-29 06:52:39 +00:00
|
|
|
return;
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
2013-06-18 10:00:38 +00:00
|
|
|
mJsUuids = uuids;
|
2013-01-29 06:52:39 +00:00
|
|
|
Root();
|
2012-08-01 04:53:04 +00:00
|
|
|
} else if (name.EqualsLiteral("Devices")) {
|
|
|
|
mDeviceAddresses = value.get_ArrayOfnsString();
|
2013-04-26 10:48:21 +00:00
|
|
|
|
2014-06-19 19:14:32 +00:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 10:17:17 +00:00
|
|
|
if (!jsapi.Init(GetOwner())) {
|
2014-06-19 19:14:32 +00:00
|
|
|
BT_WARNING("Failed to initialise AutoJSAPI!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSContext* cx = jsapi.cx();
|
2013-06-18 10:00:38 +00:00
|
|
|
JS::Rooted<JSObject*> deviceAddresses(cx);
|
2014-06-02 16:40:13 +00:00
|
|
|
if (NS_FAILED(nsTArrayToJSArray(cx, mDeviceAddresses, &deviceAddresses))) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Cannot set JS Devices object!");
|
2013-01-29 06:52:39 +00:00
|
|
|
return;
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
2013-06-18 10:00:38 +00:00
|
|
|
mJsDeviceAddresses = deviceAddresses;
|
2013-01-29 06:52:39 +00:00
|
|
|
Root();
|
2012-07-18 03:41:54 +00:00
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCString warningMsg;
|
|
|
|
warningMsg.AssignLiteral("Not handling adapter property: ");
|
|
|
|
warningMsg.Append(NS_ConvertUTF16toUTF8(name));
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING(warningMsg.get());
|
2012-07-18 03:41:54 +00:00
|
|
|
#endif
|
2012-06-02 18:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<BluetoothAdapter>
|
2013-01-29 06:52:39 +00:00
|
|
|
BluetoothAdapter::Create(nsPIDOMWindow* aWindow, const BluetoothValue& aValue)
|
2012-07-18 03:41:54 +00:00
|
|
|
{
|
2013-01-29 06:52:39 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aWindow);
|
2012-07-18 03:41:54 +00:00
|
|
|
|
2013-01-29 06:52:39 +00:00
|
|
|
nsRefPtr<BluetoothAdapter> adapter = new BluetoothAdapter(aWindow, aValue);
|
2012-06-02 18:23:16 +00:00
|
|
|
return adapter.forget();
|
|
|
|
}
|
|
|
|
|
2012-07-18 03:41:54 +00:00
|
|
|
void
|
|
|
|
BluetoothAdapter::Notify(const BluetoothSignal& aData)
|
|
|
|
{
|
2012-08-17 10:35:59 +00:00
|
|
|
InfallibleTArray<BluetoothNamedValue> arr;
|
|
|
|
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_LOGD("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get());
|
2013-01-29 10:37:51 +00:00
|
|
|
|
2013-01-29 06:52:30 +00:00
|
|
|
BluetoothValue v = aData.value();
|
2012-07-18 03:41:54 +00:00
|
|
|
if (aData.name().EqualsLiteral("DeviceFound")) {
|
2012-08-21 02:54:28 +00:00
|
|
|
nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value());
|
|
|
|
|
2014-01-22 06:26:29 +00: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 20:11:31 +00:00
|
|
|
DispatchTrustedEvent(event);
|
2012-08-01 04:53:04 +00:00
|
|
|
} else if (aData.name().EqualsLiteral("PropertyChanged")) {
|
2013-08-02 10:33:15 +00:00
|
|
|
MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
|
2013-12-18 10:21:05 +00:00
|
|
|
|
2013-01-29 06:52:30 +00:00
|
|
|
const InfallibleTArray<BluetoothNamedValue>& arr =
|
|
|
|
v.get_ArrayOfBluetoothNamedValue();
|
2012-09-19 03:19:45 +00:00
|
|
|
|
2013-12-18 10:21:05 +00:00
|
|
|
for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
|
|
|
|
SetPropertyByValue(arr[i]);
|
|
|
|
}
|
2014-05-23 06:00:25 +00:00
|
|
|
} else if (aData.name().EqualsLiteral(DISCOVERY_STATE_CHANGED_ID)) {
|
|
|
|
MOZ_ASSERT(v.type() == BluetoothValue::Tbool);
|
|
|
|
|
|
|
|
BluetoothDiscoveryStateChangedEventInit init;
|
|
|
|
init.mDiscovering = v.get_bool();
|
|
|
|
|
|
|
|
nsRefPtr<BluetoothDiscoveryStateChangedEvent> event =
|
|
|
|
BluetoothDiscoveryStateChangedEvent::Constructor(
|
|
|
|
this, NS_LITERAL_STRING(DISCOVERY_STATE_CHANGED_ID), init);
|
|
|
|
DispatchTrustedEvent(event);
|
2013-08-02 10:33:15 +00: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-22 06:26:29 +00: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 10:33:15 +00:00
|
|
|
DispatchTrustedEvent(event);
|
2013-09-04 02:40:01 +00: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 03:41:54 +00:00
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCString warningMsg;
|
2012-09-06 03:06:20 +00:00
|
|
|
warningMsg.AssignLiteral("Not handling adapter signal: ");
|
2012-07-18 03:41:54 +00:00
|
|
|
warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING(warningMsg.get());
|
2012-07-18 03:41:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StartStopDiscovery(bool aStart, ErrorResult& aRv)
|
2012-07-18 03:41:54 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-18 03:41:54 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-07-18 03:41:54 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsresult rv;
|
2012-07-18 03:41:54 +00:00
|
|
|
if (aStart) {
|
2013-03-15 07:15:47 +00:00
|
|
|
rv = bs->StartDiscoveryInternal(results);
|
2012-07-18 03:41:54 +00:00
|
|
|
} else {
|
2013-03-15 07:15:47 +00:00
|
|
|
rv = bs->StopDiscoveryInternal(results);
|
2012-07-18 03:41:54 +00:00
|
|
|
}
|
2013-08-12 08:32:53 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Start/Stop Discovery failed!");
|
2013-08-12 08:32:53 +00:00
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-07-18 03:41:54 +00: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 06:52:48 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2013-08-12 16:08:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
|
2013-08-12 16:08:03 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
return StartStopDiscovery(true, aRv);
|
2013-08-12 16:08:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StopDiscovery(ErrorResult& aRv)
|
2013-08-12 16:08:03 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
return StartStopDiscovery(false, aRv);
|
2013-08-12 16:08:03 +00:00
|
|
|
}
|
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
|
|
|
BluetoothAdapter::GetDevices(JSContext* aContext,
|
|
|
|
JS::MutableHandle<JS::Value> aDevices,
|
|
|
|
ErrorResult& aRv)
|
2013-08-12 16:08:03 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!mJsDeviceAddresses) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Devices not yet set!\n");
|
2013-08-12 08:32:53 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2014-06-11 20:26:52 +00:00
|
|
|
return;
|
2013-08-12 08:32:53 +00:00
|
|
|
}
|
2013-08-12 08:32:53 +00:00
|
|
|
|
2013-09-09 03:28:48 +00:00
|
|
|
JS::ExposeObjectToActiveJS(mJsDeviceAddresses);
|
2014-06-11 20:26:52 +00:00
|
|
|
aDevices.setObject(*mJsDeviceAddresses);
|
2013-08-12 16:08:03 +00:00
|
|
|
}
|
2013-08-12 08:32:53 +00:00
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
|
|
|
BluetoothAdapter::GetUuids(JSContext* aContext,
|
|
|
|
JS::MutableHandle<JS::Value> aUuids,
|
|
|
|
ErrorResult& aRv)
|
2013-08-12 16:08:03 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!mJsUuids) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("UUIDs not yet set!\n");
|
2013-08-12 08:32:53 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2014-06-11 20:26:52 +00:00
|
|
|
return;
|
2013-08-12 08:32:53 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 03:28:48 +00:00
|
|
|
JS::ExposeObjectToActiveJS(mJsUuids);
|
2014-06-11 20:26:52 +00:00
|
|
|
aUuids.setObject(*mJsUuids);
|
2012-07-18 03:41:54 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SetName(const nsAString& aName, ErrorResult& aRv)
|
2012-08-01 04:53:04 +00:00
|
|
|
{
|
|
|
|
if (mName.Equals(aName)) {
|
2013-08-12 08:32:53 +00:00
|
|
|
return FirePropertyAlreadySet(GetOwner(), aRv);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
|
|
|
nsString name(aName);
|
|
|
|
BluetoothValue value(name);
|
|
|
|
BluetoothNamedValue property(NS_LITERAL_STRING("Name"), value);
|
2013-08-12 08:32:53 +00:00
|
|
|
return SetProperty(GetOwner(), property, aRv);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
2013-03-15 07:15:47 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SetDiscoverable(bool aDiscoverable, ErrorResult& aRv)
|
2012-08-01 04:53:04 +00:00
|
|
|
{
|
|
|
|
if (aDiscoverable == mDiscoverable) {
|
2013-08-12 08:32:53 +00:00
|
|
|
return FirePropertyAlreadySet(GetOwner(), aRv);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
|
|
|
BluetoothValue value(aDiscoverable);
|
|
|
|
BluetoothNamedValue property(NS_LITERAL_STRING("Discoverable"), value);
|
2013-08-12 08:32:53 +00:00
|
|
|
return SetProperty(GetOwner(), property, aRv);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
2013-08-12 08:32:53 +00:00
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SetDiscoverableTimeout(uint32_t aDiscoverableTimeout, ErrorResult& aRv)
|
2012-08-01 04:53:04 +00:00
|
|
|
{
|
|
|
|
if (aDiscoverableTimeout == mDiscoverableTimeout) {
|
2013-08-12 08:32:53 +00:00
|
|
|
return FirePropertyAlreadySet(GetOwner(), aRv);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
|
|
|
BluetoothValue value(aDiscoverableTimeout);
|
|
|
|
BluetoothNamedValue property(NS_LITERAL_STRING("DiscoverableTimeout"), value);
|
2013-08-12 08:32:53 +00:00
|
|
|
return SetProperty(GetOwner(), property, aRv);
|
2012-08-01 04:53:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-09-06 11:19:46 +00:00
|
|
|
BluetoothAdapter::GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv)
|
2013-04-26 10:48:21 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-04-26 10:48:21 +00:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new GetDevicesTask(this, request);
|
2013-04-26 10:48:21 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-06 11:19:46 +00:00
|
|
|
nsresult rv = bs->GetConnectedDevicePropertiesInternal(aServiceUuid, results);
|
2013-08-12 08:32:53 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-04-26 10:48:21 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2013-04-26 10:48:21 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::GetPairedDevices(ErrorResult& aRv)
|
2012-08-17 02:53:45 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-17 02:53:45 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new GetDevicesTask(this, request);
|
2012-08-17 02:53:45 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00: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 02:53:45 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-08-17 02:53:45 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-11-15 09:19:31 +00:00
|
|
|
BluetoothAdapter::PairUnpair(bool aPair, const nsAString& aDeviceAddress,
|
2013-08-12 08:32:53 +00:00
|
|
|
ErrorResult& aRv)
|
2012-08-17 10:35:59 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-17 10:35:59 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-08-17 10:35:59 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsresult rv;
|
2012-08-17 10:35:59 +00:00
|
|
|
if (aPair) {
|
2013-11-15 09:19:31 +00:00
|
|
|
rv = bs->CreatePairedDeviceInternal(aDeviceAddress,
|
2012-08-17 10:35:59 +00:00
|
|
|
kCreatePairedDeviceTimeout,
|
|
|
|
results);
|
|
|
|
} else {
|
2013-11-15 09:19:31 +00:00
|
|
|
rv = bs->RemoveDeviceInternal(aDeviceAddress, results);
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("Pair/Unpair failed!");
|
2013-08-12 08:32:53 +00:00
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-11-15 09:19:31 +00:00
|
|
|
BluetoothAdapter::Pair(const nsAString& aDeviceAddress, ErrorResult& aRv)
|
2012-08-17 10:35:59 +00:00
|
|
|
{
|
2013-11-15 09:19:31 +00:00
|
|
|
return PairUnpair(true, aDeviceAddress, aRv);
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-11-15 09:19:31 +00:00
|
|
|
BluetoothAdapter::Unpair(const nsAString& aDeviceAddress, ErrorResult& aRv)
|
2012-08-17 10:35:59 +00:00
|
|
|
{
|
2013-11-15 09:19:31 +00:00
|
|
|
return PairUnpair(false, aDeviceAddress, aRv);
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-19 23:37:42 +00:00
|
|
|
BluetoothAdapter::SetPinCode(const nsAString& aDeviceAddress,
|
2013-08-12 08:32:53 +00:00
|
|
|
const nsAString& aPinCode, ErrorResult& aRv)
|
2012-08-17 10:35:59 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-19 23:37:42 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-19 23:37:42 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!bs->SetPinCodeInternal(aDeviceAddress, aPinCode, results)) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("SetPinCode failed!");
|
2013-08-12 08:32:53 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-09-19 23:37:42 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-19 23:37:42 +00:00
|
|
|
BluetoothAdapter::SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
|
2013-08-12 08:32:53 +00:00
|
|
|
ErrorResult& aRv)
|
2012-08-17 10:35:59 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-19 23:37:42 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-19 23:37:42 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (bs->SetPasskeyInternal(aDeviceAddress, aPasskey, results)) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("SetPasskeyInternal failed!");
|
2013-08-12 08:32:53 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-09-19 23:37:42 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-19 23:37:42 +00:00
|
|
|
BluetoothAdapter::SetPairingConfirmation(const nsAString& aDeviceAddress,
|
2013-08-12 08:32:53 +00:00
|
|
|
bool aConfirmation, ErrorResult& aRv)
|
2012-08-17 10:35:59 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-19 23:37:42 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-19 23:37:42 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!bs->SetPairingConfirmationInternal(aDeviceAddress,
|
|
|
|
aConfirmation,
|
|
|
|
results)) {
|
2013-09-13 22:51:00 +00:00
|
|
|
BT_WARNING("SetPairingConfirmation failed!");
|
2013-08-12 08:32:53 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-09-19 23:37:42 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-08-17 10:35:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-09-06 11:19:46 +00:00
|
|
|
BluetoothAdapter::Connect(BluetoothDevice& aDevice,
|
2014-08-26 10:50:35 +00:00
|
|
|
const Optional<uint16_t>& aServiceUuid,
|
2013-09-06 11:19:46 +00:00
|
|
|
ErrorResult& aRv)
|
2012-09-29 10:26:46 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-12 16:08:03 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-08-12 16:08:03 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
|
|
|
|
2013-09-06 11:19:46 +00:00
|
|
|
nsAutoString address;
|
|
|
|
aDevice.GetAddress(address);
|
|
|
|
uint32_t deviceClass = aDevice.Class();
|
|
|
|
uint16_t serviceUuid = 0;
|
|
|
|
if (aServiceUuid.WasPassed()) {
|
|
|
|
serviceUuid = aServiceUuid.Value();
|
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-06 11:19:46 +00:00
|
|
|
bs->Connect(address, deviceClass, serviceUuid, results);
|
2012-09-29 10:26:46 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-09-29 10:26:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-09-06 11:19:46 +00:00
|
|
|
BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
|
2014-08-26 10:50:35 +00:00
|
|
|
const Optional<uint16_t>& aServiceUuid,
|
2013-09-06 11:19:46 +00:00
|
|
|
ErrorResult& aRv)
|
2012-09-29 10:26:46 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-29 10:26:46 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-01-29 06:52:48 +00:00
|
|
|
|
2013-09-06 11:19:46 +00:00
|
|
|
nsAutoString address;
|
|
|
|
aDevice.GetAddress(address);
|
|
|
|
uint16_t serviceUuid = 0;
|
|
|
|
if (aServiceUuid.WasPassed()) {
|
|
|
|
serviceUuid = aServiceUuid.Value();
|
|
|
|
}
|
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-06 11:19:46 +00:00
|
|
|
bs->Disconnect(address, serviceUuid, results);
|
2012-09-29 10:26:46 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-09-29 10:26:46 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 10:50:35 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::IsConnected(const uint16_t aServiceUuid, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
|
|
|
new GetConnectionStatusTask(request);
|
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bs->IsConnected(aServiceUuid, results);
|
|
|
|
|
|
|
|
return request.forget();
|
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-09-29 10:26:46 +00:00
|
|
|
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
|
2014-10-08 16:15:23 +00:00
|
|
|
File& aBlob, ErrorResult& aRv)
|
2012-09-29 10:26:46 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-28 10:59:12 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-09-28 10:59:12 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-02-11 02:07:23 +00:00
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
// In-process transfer
|
2014-10-08 16:15:22 +00:00
|
|
|
bs->SendFile(aDeviceAddress, &aBlob, results);
|
2014-02-11 02:07:23 +00:00
|
|
|
} else {
|
|
|
|
ContentChild *cc = ContentChild::GetSingleton();
|
|
|
|
if (!cc) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:15:22 +00:00
|
|
|
BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
|
2014-02-11 02:07:23 +00:00
|
|
|
if (!actor) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bs->SendFile(aDeviceAddress, nullptr, actor, results);
|
|
|
|
}
|
2012-09-28 10:59:12 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-09-29 10:26:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv)
|
2012-09-29 10:26:46 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-10-03 07:09:27 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-10-03 07:09:27 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-01-29 06:52:48 +00:00
|
|
|
bs->StopSendingFile(aDeviceAddress, results);
|
2012-10-03 07:09:27 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-09-29 10:26:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2012-10-19 06:16:13 +00:00
|
|
|
BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
|
2013-08-12 08:32:53 +00:00
|
|
|
bool aConfirmation, ErrorResult& aRv)
|
2012-10-19 06:16:13 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-10-19 06:16:13 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-01-29 06:52:48 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2012-10-19 06:16:13 +00:00
|
|
|
|
2013-01-29 06:52:48 +00:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-01-29 06:52:48 +00:00
|
|
|
bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, results);
|
2012-10-19 06:16:13 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2012-10-19 06:16:13 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::ConnectSco(ErrorResult& aRv)
|
2013-05-10 10:58:59 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 10:58:59 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-05-10 10:58:59 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-05-10 10:58:59 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 10:58:59 +00:00
|
|
|
bs->ConnectSco(results);
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2013-05-10 10:58:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::DisconnectSco(ErrorResult& aRv)
|
2013-05-10 10:58:59 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 10:58:59 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-05-10 10:58:59 +00:00
|
|
|
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-05-10 10:58:59 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 10:58:59 +00:00
|
|
|
bs->DisconnectSco(results);
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2013-05-10 10:58:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::IsScoConnected(ErrorResult& aRv)
|
2013-05-10 10:58:59 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 10:58:59 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-05-10 10:58:59 +00:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2014-08-26 10:50:35 +00:00
|
|
|
new GetConnectionStatusTask(request);
|
2013-05-10 10:58:59 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-10 10:58:59 +00:00
|
|
|
bs->IsScoConnected(results);
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2013-05-10 10:58:59 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 02:38:13 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::AnswerWaitingCall(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-16 02:38:13 +00: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 08:12:46 +00:00
|
|
|
#else
|
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-16 02:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::IgnoreWaitingCall(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-16 02:38:13 +00: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 08:12:46 +00:00
|
|
|
#else
|
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-16 02:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::ToggleCalls(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-29 08:12:46 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-16 02:38:13 +00: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 08:12:46 +00:00
|
|
|
#else
|
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
|
|
|
#endif // MOZ_B2G_RIL
|
2013-10-16 02:38:13 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv)
|
2013-07-29 09:32:34 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-29 09:32:34 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-07-29 09:32:34 +00:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-07-29 09:32:34 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00: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 09:32:34 +00:00
|
|
|
results);
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2013-07-29 09:32:34 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
BluetoothAdapter::SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv)
|
2013-07-29 09:32:34 +00:00
|
|
|
{
|
2013-08-12 08:32:53 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-29 09:32:34 +00:00
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
2013-07-29 09:32:34 +00:00
|
|
|
nsRefPtr<BluetoothReplyRunnable> results =
|
2013-08-12 08:32:53 +00:00
|
|
|
new BluetoothVoidReplyRunnable(request);
|
2013-07-29 09:32:34 +00:00
|
|
|
|
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
2013-08-12 08:32:53 +00:00
|
|
|
if (!bs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bs->SendPlayStatus(aMediaPlayStatus.mDuration,
|
|
|
|
aMediaPlayStatus.mPosition,
|
|
|
|
aMediaPlayStatus.mPlayStatus,
|
2013-07-29 09:32:34 +00:00
|
|
|
results);
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
return request.forget();
|
2013-07-29 09:32:34 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 08:32:53 +00:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
BluetoothAdapter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-08-12 08:32:53 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return BluetoothAdapterBinding::Wrap(aCx, this, aGivenProto);
|
2013-08-12 08:32:53 +00:00
|
|
|
}
|