mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out changeset 4ce3e048289c (bug 888595) for mochitest failure
This commit is contained in:
parent
3f2e1bc9c0
commit
5e3c55d3f4
@ -232,6 +232,7 @@ using mozilla::dom::workers::ResolveWorkerClasses;
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_BT
|
||||
#include "BluetoothAdapter.h"
|
||||
#include "BluetoothDevice.h"
|
||||
#endif
|
||||
|
||||
@ -631,6 +632,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_BT
|
||||
NS_DEFINE_CLASSINFO_DATA(BluetoothAdapter, nsEventTargetSH,
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH,
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
#endif
|
||||
@ -1521,6 +1524,10 @@ nsDOMClassInfo::Init()
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_BT
|
||||
DOM_CLASSINFO_MAP_BEGIN(BluetoothAdapter, nsIDOMBluetoothAdapter)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothAdapter)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(BluetoothDevice, nsIDOMBluetoothDevice)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothDevice)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
@ -136,6 +136,7 @@ DOMCI_CLASS(FMRadio)
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_BT
|
||||
DOMCI_CLASS(BluetoothAdapter)
|
||||
DOMCI_CLASS(BluetoothDevice)
|
||||
#endif
|
||||
|
||||
|
@ -150,11 +150,6 @@ DOMInterfaces = {
|
||||
'headerFile': 'BatteryManager.h'
|
||||
},
|
||||
|
||||
'BluetoothAdapter': {
|
||||
'nativeType': 'mozilla::dom::bluetooth::BluetoothAdapter',
|
||||
'headerFile': 'BluetoothAdapter.h'
|
||||
},
|
||||
|
||||
'BluetoothManager': {
|
||||
'nativeType': 'mozilla::dom::bluetooth::BluetoothManager',
|
||||
'headerFile': 'BluetoothManager.h'
|
||||
@ -1737,8 +1732,6 @@ def addExternalIface(iface, nativeType=None, headerFile=None,
|
||||
|
||||
addExternalIface('ActivityOptions', nativeType='nsIDOMMozActivityOptions',
|
||||
headerFile='nsIDOMActivityOptions.h')
|
||||
addExternalIface('BluetoothDevice', nativeType='nsIDOMBluetoothDevice',
|
||||
headerFile='nsIDOMBluetoothDevice.h')
|
||||
addExternalIface('Counter')
|
||||
addExternalIface('CSSRule')
|
||||
addExternalIface('DeviceAcceleration', headerFile='nsIDOMDeviceMotionEvent.h', notflattened=True)
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
#include "mozilla/dom/BluetoothAdapterBinding.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/LazyIdleThread.h"
|
||||
#include "mozilla/Util.h"
|
||||
@ -26,12 +25,15 @@
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothUtils.h"
|
||||
#include "MediaMetaData.h"
|
||||
#include "MediaPlayStatus.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
DOMCI_DATA(BluetoothAdapter, BluetoothAdapter)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothAdapter)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothAdapter,
|
||||
@ -40,18 +42,19 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothAdapter,
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mJsDeviceAddresses)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothAdapter,
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothAdapter,
|
||||
nsDOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothAdapter,
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothAdapter,
|
||||
nsDOMEventTargetHelper)
|
||||
tmp->Unroot();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
// QueryInterface implementation for BluetoothAdapter
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothAdapter)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothAdapter)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothAdapter)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
|
||||
@ -161,20 +164,33 @@ public:
|
||||
|
||||
static int kCreatePairedDeviceTimeout = 50000; // unit: msec
|
||||
|
||||
nsresult
|
||||
PrepareDOMRequest(nsIDOMWindow* aWindow, nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
MOZ_ASSERT(aWindow);
|
||||
|
||||
nsCOMPtr<nsIDOMRequestService> rs =
|
||||
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
nsresult rv = rs->CreateRequest(aWindow, aRequest);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aWindow,
|
||||
const BluetoothValue& aValue)
|
||||
: nsDOMEventTargetHelper(aWindow)
|
||||
, BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
|
||||
, mJsUuids(nullptr)
|
||||
, mJsDeviceAddresses(nullptr)
|
||||
: BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
|
||||
, mDiscoverable(false)
|
||||
, mDiscovering(false)
|
||||
, mPairable(false)
|
||||
, mPowered(false)
|
||||
, mJsUuids(nullptr)
|
||||
, mJsDeviceAddresses(nullptr)
|
||||
, mIsRooted(false)
|
||||
{
|
||||
MOZ_ASSERT(aWindow);
|
||||
MOZ_ASSERT(IsDOMBinding());
|
||||
|
||||
BindToOwner(aWindow);
|
||||
const InfallibleTArray<BluetoothNamedValue>& values =
|
||||
@ -356,191 +372,210 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData)
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::StartStopDiscovery(bool aStart, ErrorResult& aRv)
|
||||
nsresult
|
||||
BluetoothAdapter::StartStopDiscovery(bool aStart, nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsresult rv;
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
if (aStart) {
|
||||
rv = bs->StartDiscoveryInternal(results);
|
||||
} else {
|
||||
rv = bs->StopDiscoveryInternal(results);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
if(NS_FAILED(rv)) {
|
||||
NS_WARNING("Start/Stop Discovery failed!");
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// mDiscovering is not set here, we'll get a Property update from our external
|
||||
// protocol to tell us that it's been set.
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::StartDiscovery(nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
return StartStopDiscovery(true, aRv);
|
||||
return StartStopDiscovery(true, aRequest);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::StopDiscovery(ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::StopDiscovery(nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
return StartStopDiscovery(false, aRv);
|
||||
return StartStopDiscovery(false, aRequest);
|
||||
}
|
||||
|
||||
JS::Value
|
||||
BluetoothAdapter::GetDevices(JSContext* aContext, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetAddress(nsAString& aAddress)
|
||||
{
|
||||
if (!mJsDeviceAddresses) {
|
||||
aAddress = mAddress;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetAdapterClass(uint32_t* aClass)
|
||||
{
|
||||
*aClass = mClass;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetDiscovering(bool* aDiscovering)
|
||||
{
|
||||
*aDiscovering = mDiscovering;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetName(nsAString& aName)
|
||||
{
|
||||
aName = mName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetDiscoverable(bool* aDiscoverable)
|
||||
{
|
||||
*aDiscoverable = mDiscoverable;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetDiscoverableTimeout(uint32_t* aDiscoverableTimeout)
|
||||
{
|
||||
*aDiscoverableTimeout = mDiscoverableTimeout;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetDevices(JSContext* aCx, JS::Value* aDevices)
|
||||
{
|
||||
if (mJsDeviceAddresses) {
|
||||
aDevices->setObject(*mJsDeviceAddresses);
|
||||
}
|
||||
else {
|
||||
NS_WARNING("Devices not yet set!\n");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return JS::NullValue();
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsDeviceAddresses));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JS::Value
|
||||
BluetoothAdapter::GetUuids(JSContext* aContext, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetUuids(JSContext* aCx, JS::Value* aValue)
|
||||
{
|
||||
if (!mJsUuids) {
|
||||
NS_WARNING("UUIDs not yet set!\n");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return JS::NullValue();
|
||||
if (mJsUuids) {
|
||||
aValue->setObject(*mJsUuids);
|
||||
}
|
||||
|
||||
return JS::ObjectValue(*xpc_UnmarkGrayObject(mJsUuids));
|
||||
else {
|
||||
NS_WARNING("UUIDs not yet set!\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::SetName(const nsAString& aName, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::SetName(const nsAString& aName,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
if (mName.Equals(aName)) {
|
||||
return FirePropertyAlreadySet(GetOwner(), aRv);
|
||||
return FirePropertyAlreadySet(GetOwner(), aRequest);
|
||||
}
|
||||
nsString name(aName);
|
||||
BluetoothValue value(name);
|
||||
BluetoothNamedValue property(NS_LITERAL_STRING("Name"), value);
|
||||
return SetProperty(GetOwner(), property, aRv);
|
||||
return SetProperty(GetOwner(), property, aRequest);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::SetDiscoverable(bool aDiscoverable, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::SetDiscoverable(const bool aDiscoverable,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
if (aDiscoverable == mDiscoverable) {
|
||||
return FirePropertyAlreadySet(GetOwner(), aRv);
|
||||
return FirePropertyAlreadySet(GetOwner(), aRequest);
|
||||
}
|
||||
BluetoothValue value(aDiscoverable);
|
||||
BluetoothNamedValue property(NS_LITERAL_STRING("Discoverable"), value);
|
||||
return SetProperty(GetOwner(), property, aRv);
|
||||
return SetProperty(GetOwner(), property, aRequest);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::SetDiscoverableTimeout(uint32_t aDiscoverableTimeout, ErrorResult& aRv)
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::SetDiscoverableTimeout(const uint32_t aDiscoverableTimeout,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
if (aDiscoverableTimeout == mDiscoverableTimeout) {
|
||||
return FirePropertyAlreadySet(GetOwner(), aRv);
|
||||
return FirePropertyAlreadySet(GetOwner(), aRequest);
|
||||
}
|
||||
BluetoothValue value(aDiscoverableTimeout);
|
||||
BluetoothNamedValue property(NS_LITERAL_STRING("DiscoverableTimeout"), value);
|
||||
return SetProperty(GetOwner(), property, aRv);
|
||||
return SetProperty(GetOwner(), property, aRequest);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::GetConnectedDevices(uint16_t aProfileId, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetConnectedDevices(uint16_t aProfileId,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothReplyRunnable> results =
|
||||
new GetDevicesTask(this, request);
|
||||
new GetDevicesTask(this, req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsresult rv = bs->GetConnectedDevicePropertiesInternal(aProfileId, results);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
rv = bs->GetConnectedDevicePropertiesInternal(aProfileId, results);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::GetPairedDevices(ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::GetPairedDevices(nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothReplyRunnable> results =
|
||||
new GetDevicesTask(this, request);
|
||||
new GetDevicesTask(this, req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsresult rv = bs->GetPairedDevicePropertiesInternal(mDeviceAddresses, results);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
rv = bs->GetPairedDevicePropertiesInternal(mDeviceAddresses, results);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice,
|
||||
ErrorResult& aRv)
|
||||
nsresult
|
||||
BluetoothAdapter::PairUnpair(bool aPair,
|
||||
nsIDOMBluetoothDevice* aDevice,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
nsAutoString addr;
|
||||
aDevice->GetAddress(addr);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsresult rv;
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
if (aPair) {
|
||||
rv = bs->CreatePairedDeviceInternal(addr,
|
||||
kCreatePairedDeviceTimeout,
|
||||
@ -548,393 +583,350 @@ BluetoothAdapter::PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice,
|
||||
} else {
|
||||
rv = bs->RemoveDeviceInternal(addr, results);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Pair/Unpair failed!");
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::Pair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv)
|
||||
nsresult
|
||||
BluetoothAdapter::Pair(nsIDOMBluetoothDevice* aDevice,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
return PairUnpair(true, aDevice, aRv);
|
||||
return PairUnpair(true, aDevice, aRequest);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::Unpair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv)
|
||||
nsresult
|
||||
BluetoothAdapter::Unpair(nsIDOMBluetoothDevice* aDevice,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
return PairUnpair(false, aDevice, aRv);
|
||||
return PairUnpair(false, aDevice, aRequest);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsresult
|
||||
BluetoothAdapter::SetPinCode(const nsAString& aDeviceAddress,
|
||||
const nsAString& aPinCode, ErrorResult& aRv)
|
||||
const nsAString& aPinCode,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
if (!bs->SetPinCodeInternal(aDeviceAddress, aPinCode, results)) {
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
if(!bs->SetPinCodeInternal(aDeviceAddress, aPinCode, results)) {
|
||||
NS_WARNING("SetPinCode failed!");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsresult
|
||||
BluetoothAdapter::SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
|
||||
ErrorResult& aRv)
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
if (bs->SetPasskeyInternal(aDeviceAddress, aPasskey, results)) {
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
if(bs->SetPasskeyInternal(aDeviceAddress, aPasskey, results)) {
|
||||
NS_WARNING("SetPasskeyInternal failed!");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsresult
|
||||
BluetoothAdapter::SetPairingConfirmation(const nsAString& aDeviceAddress,
|
||||
bool aConfirmation, ErrorResult& aRv)
|
||||
bool aConfirmation,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
if (!bs->SetPairingConfirmationInternal(aDeviceAddress,
|
||||
aConfirmation,
|
||||
results)) {
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
if(!bs->SetPairingConfirmationInternal(aDeviceAddress,
|
||||
aConfirmation,
|
||||
results)) {
|
||||
NS_WARNING("SetPairingConfirmation failed!");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsresult
|
||||
BluetoothAdapter::SetAuthorization(const nsAString& aDeviceAddress, bool aAllow,
|
||||
ErrorResult& aRv)
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
if (!bs->SetAuthorizationInternal(aDeviceAddress, aAllow, results)) {
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
if(!bs->SetAuthorizationInternal(aDeviceAddress, aAllow, results)) {
|
||||
NS_WARNING("SetAuthorization failed!");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
|
||||
uint16_t aProfileId, ErrorResult& aRv)
|
||||
uint16_t aProfileId,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
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);
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
bs->Connect(aDeviceAddress, aProfileId, results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::Disconnect(uint16_t aProfileId, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::Disconnect(uint16_t aProfileId,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->Disconnect(aProfileId, results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMBlob* aBlob, ErrorResult& aRv)
|
||||
nsIDOMBlob* aBlob,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BlobChild* actor =
|
||||
ContentChild::GetSingleton()->GetOrCreateActorForBlob(aBlob);
|
||||
mozilla::dom::ContentChild::GetSingleton()->GetOrCreateActorForBlob(aBlob);
|
||||
if (!actor) {
|
||||
NS_WARNING("Can't create actor");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->SendFile(aDeviceAddress, nullptr, actor, results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::StopSendingFile(const nsAString& aDeviceAddress,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->StopSendingFile(aDeviceAddress, results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsresult
|
||||
BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
|
||||
bool aConfirmation, ErrorResult& aRv)
|
||||
bool aConfirmation,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::ConnectSco(ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::ConnectSco(nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->ConnectSco(results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::DisconnectSco(ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::DisconnectSco(nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothVoidReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->DisconnectSco(results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::IsScoConnected(ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::IsScoConnected(nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothReplyRunnable> results =
|
||||
new GetScoConnectionStatusTask(request);
|
||||
new GetScoConnectionStatusTask(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->IsScoConnected(results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::SendMediaMetaData(const JS::Value& aOptions,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
MediaMetaData metadata;
|
||||
|
||||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
AutoPushJSContext cx(sc->GetNativeContext());
|
||||
rv = metadata.Init(cx, &aOptions);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
bs->SendMetaData(aMediaMetaData.mTitle,
|
||||
aMediaMetaData.mArtist,
|
||||
aMediaMetaData.mAlbum,
|
||||
aMediaMetaData.mMediaNumber,
|
||||
aMediaMetaData.mTotalMediaCount,
|
||||
aMediaMetaData.mDuration,
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->SendMetaData(metadata.mTitle,
|
||||
metadata.mArtist,
|
||||
metadata.mAlbum,
|
||||
metadata.mMediaNumber,
|
||||
metadata.mTotalMediaCount,
|
||||
metadata.mDuration,
|
||||
results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
BluetoothAdapter::SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv)
|
||||
NS_IMETHODIMP
|
||||
BluetoothAdapter::SendMediaPlayStatus(const JS::Value& aOptions,
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
|
||||
if (!win) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
MediaPlayStatus status;
|
||||
|
||||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
AutoPushJSContext cx(sc->GetNativeContext());
|
||||
rv = status.Init(cx, &aOptions);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(win);
|
||||
nsRefPtr<BluetoothReplyRunnable> results =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
bs->SendPlayStatus(aMediaPlayStatus.mDuration,
|
||||
aMediaPlayStatus.mPosition,
|
||||
aMediaPlayStatus.mPlayStatus,
|
||||
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
|
||||
bs->SendPlayStatus(status.mDuration,
|
||||
status.mPosition,
|
||||
status.mPlayStatus,
|
||||
results);
|
||||
|
||||
return request.forget();
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JSObject*
|
||||
BluetoothAdapter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return BluetoothAdapterBinding::Wrap(aCx, aScope, this);
|
||||
}
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicefound)
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, a2dpstatuschanged)
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, hfpstatuschanged)
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, pairedstatuschanged)
|
||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, scostatuschanged)
|
||||
|
@ -12,15 +12,10 @@
|
||||
#include "BluetoothPropertyContainer.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsDOMEventTargetHelper.h"
|
||||
#include "nsIDOMBluetoothDevice.h"
|
||||
#include "nsIDOMBluetoothAdapter.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class DOMRequest;
|
||||
struct MediaMetaData;
|
||||
struct MediaPlayStatus;
|
||||
}
|
||||
}
|
||||
class nsIEventTarget;
|
||||
class nsIDOMDOMRequest;
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
@ -29,11 +24,15 @@ class BluetoothNamedValue;
|
||||
class BluetoothValue;
|
||||
|
||||
class BluetoothAdapter : public nsDOMEventTargetHelper
|
||||
, public nsIDOMBluetoothAdapter
|
||||
, public BluetoothSignalObserver
|
||||
, public BluetoothPropertyContainer
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIDOMBLUETOOTHADAPTER
|
||||
|
||||
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper)
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(BluetoothAdapter,
|
||||
nsDOMEventTargetHelper)
|
||||
@ -43,129 +42,25 @@ public:
|
||||
|
||||
void Notify(const BluetoothSignal& aParam);
|
||||
|
||||
nsISupports*
|
||||
ToISupports()
|
||||
{
|
||||
return static_cast<EventTarget*>(this);
|
||||
}
|
||||
|
||||
void Unroot();
|
||||
virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;
|
||||
|
||||
void GetAddress(nsString& aAddress) const
|
||||
{
|
||||
aAddress = mAddress;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Class() const
|
||||
{
|
||||
return mClass;
|
||||
}
|
||||
|
||||
void
|
||||
GetName(nsString& aName) const
|
||||
{
|
||||
aName = mName;
|
||||
}
|
||||
|
||||
bool
|
||||
Discovering() const
|
||||
{
|
||||
return mDiscovering;
|
||||
}
|
||||
|
||||
bool
|
||||
Discoverable() const
|
||||
{
|
||||
return mDiscoverable;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
DiscoverableTimeout() const
|
||||
{
|
||||
return mDiscoverableTimeout;
|
||||
}
|
||||
|
||||
JS::Value GetDevices(JSContext* aContext, ErrorResult& aRv);
|
||||
JS::Value GetUuids(JSContext* aContext, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
SetName(const nsAString& aName, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
SetDiscoverable(bool aDiscoverable, ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
SetDiscoverableTimeout(uint32_t aTimeout, ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest> StartDiscovery(ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest> StopDiscovery(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
Pair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
Unpair(nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
GetPairedDevices(ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
SetPinCode(const nsAString& aDeviceAddress, const nsAString& aPinCode,
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
SetPairingConfirmation(const nsAString& aDeviceAddress, bool aConfirmation,
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
SetAuthorization(const nsAString& aDeviceAddress, bool aAllow,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
Connect(const nsAString& aDeviceAddress, uint16_t aProfile,
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
Disconnect(uint16_t aProfile, ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
GetConnectedDevices(uint16_t aProfile, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob,
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirmation,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest> ConnectSco(ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest> DisconnectSco(ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest> IsScoConnected(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv);
|
||||
already_AddRefed<DOMRequest>
|
||||
SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv);
|
||||
|
||||
IMPL_EVENT_HANDLER(devicefound);
|
||||
IMPL_EVENT_HANDLER(a2dpstatuschanged);
|
||||
IMPL_EVENT_HANDLER(hfpstatuschanged);
|
||||
IMPL_EVENT_HANDLER(pairedstatuschanged);
|
||||
IMPL_EVENT_HANDLER(scostatuschanged);
|
||||
|
||||
nsPIDOMWindow* GetParentObject() const
|
||||
{
|
||||
return GetOwner();
|
||||
}
|
||||
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
||||
|
||||
virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;
|
||||
private:
|
||||
|
||||
BluetoothAdapter(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
|
||||
~BluetoothAdapter();
|
||||
|
||||
void Root();
|
||||
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
StartStopDiscovery(bool aStart, ErrorResult& aRv);
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
PairUnpair(bool aPair, nsIDOMBluetoothDevice* aDevice, ErrorResult& aRv);
|
||||
|
||||
JS::Heap<JSObject*> mJsUuids;
|
||||
JS::Heap<JSObject*> mJsDeviceAddresses;
|
||||
nsresult StartStopDiscovery(bool aStart, nsIDOMDOMRequest** aRequest);
|
||||
nsresult PairUnpair(bool aPair,
|
||||
nsIDOMBluetoothDevice* aDevice,
|
||||
nsIDOMDOMRequest** aRequest);
|
||||
|
||||
nsString mAddress;
|
||||
nsString mName;
|
||||
bool mDiscoverable;
|
||||
@ -177,6 +72,8 @@ private:
|
||||
uint32_t mClass;
|
||||
nsTArray<nsString> mDeviceAddresses;
|
||||
nsTArray<nsString> mUuids;
|
||||
JS::Heap<JSObject*> mJsUuids;
|
||||
JS::Heap<JSObject*> mJsDeviceAddresses;
|
||||
bool mIsRooted;
|
||||
};
|
||||
|
||||
|
@ -55,8 +55,8 @@ public:
|
||||
|
||||
const InfallibleTArray<BluetoothNamedValue>& values =
|
||||
v.get_ArrayOfBluetoothNamedValue();
|
||||
nsRefPtr<BluetoothAdapter> adapter =
|
||||
BluetoothAdapter::Create(mManagerPtr->GetOwner(), values);
|
||||
nsCOMPtr<nsIDOMBluetoothAdapter> adapter;
|
||||
adapter = BluetoothAdapter::Create(mManagerPtr->GetOwner(), values);
|
||||
|
||||
nsresult rv;
|
||||
nsIScriptContext* sc = mManagerPtr->GetContextForEventHandlers(&rv);
|
||||
|
@ -8,49 +8,57 @@
|
||||
#include "BluetoothPropertyContainer.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "DOMRequest.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
nsresult
|
||||
BluetoothPropertyContainer::FirePropertyAlreadySet(nsIDOMWindow* aOwner,
|
||||
ErrorResult& aRv)
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIDOMRequestService> rs =
|
||||
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
if (!rs) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = rs->CreateRequest(aOwner, getter_AddRefs(req));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Can't create DOMRequest!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
rs->FireSuccess(req, JSVAL_VOID);
|
||||
req.forget(aRequest);
|
||||
|
||||
nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
|
||||
rs->FireSuccess(request, JS::UndefinedValue());
|
||||
|
||||
return request.forget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
nsresult
|
||||
BluetoothPropertyContainer::SetProperty(nsIDOMWindow* aOwner,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
ErrorResult& aRv)
|
||||
nsIDOMDOMRequest** aRequest)
|
||||
{
|
||||
nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
|
||||
nsRefPtr<BluetoothReplyRunnable> task =
|
||||
new BluetoothVoidReplyRunnable(request);
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
NS_WARNING("Bluetooth service not available!");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult rv = bs->SetProperty(mObjectType, aProperty, task);
|
||||
nsCOMPtr<nsIDOMRequestService> rs =
|
||||
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMDOMRequest> req;
|
||||
nsresult rv = rs->CreateRequest(aOwner, getter_AddRefs(req));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
NS_WARNING("Can't create DOMRequest!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
nsRefPtr<BluetoothReplyRunnable> task = new BluetoothVoidReplyRunnable(req);
|
||||
|
||||
rv = bs->SetProperty(mObjectType, aProperty, task);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
req.forget(aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -13,13 +13,6 @@
|
||||
class nsIDOMDOMRequest;
|
||||
class nsIDOMWindow;
|
||||
|
||||
namespace mozilla {
|
||||
class ErrorResult;
|
||||
namespace dom {
|
||||
class DOMRequest;
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothNamedValue;
|
||||
@ -27,11 +20,11 @@ class BluetoothNamedValue;
|
||||
class BluetoothPropertyContainer
|
||||
{
|
||||
public:
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
FirePropertyAlreadySet(nsIDOMWindow* aOwner, ErrorResult& aRv);
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
SetProperty(nsIDOMWindow* aOwner, const BluetoothNamedValue& aProperty,
|
||||
ErrorResult& aRv);
|
||||
nsresult FirePropertyAlreadySet(nsIDOMWindow* aOwner,
|
||||
nsIDOMDOMRequest** aRequest);
|
||||
nsresult SetProperty(nsIDOMWindow* aOwner,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
nsIDOMDOMRequest** aRequest);
|
||||
virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) = 0;
|
||||
nsString GetPath()
|
||||
{
|
||||
|
83
dom/bluetooth/MediaMetaData.cpp
Normal file
83
dom/bluetooth/MediaMetaData.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/ */
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "MediaMetaData.h"
|
||||
|
||||
#include "nsCxPusher.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
MediaMetaData::MediaMetaData() : mDuration(-1)
|
||||
, mMediaNumber(-1)
|
||||
, mTotalMediaCount(-1)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
MediaMetaData::Init(JSContext* aCx, const jsval* aVal)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!aCx || !aVal) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!aVal->isObject()) {
|
||||
return aVal->isNullOrUndefined() ? NS_OK : NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
JS::RootedObject obj(aCx, &aVal->toObject());
|
||||
nsCxPusher pusher;
|
||||
pusher.Push(aCx);
|
||||
JSAutoCompartment ac(aCx, obj);
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mAlbum", &value));
|
||||
if (JSVAL_IS_STRING(value)) {
|
||||
nsDependentJSString jsString;
|
||||
NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
|
||||
mAlbum = jsString;
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mArtist", &value));
|
||||
if (JSVAL_IS_STRING(value)) {
|
||||
nsDependentJSString jsString;
|
||||
NS_ENSURE_STATE(JSVAL_IS_STRING(value));
|
||||
NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
|
||||
mArtist = jsString;
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mDuration", &value));
|
||||
if (JSVAL_IS_INT(value)) {
|
||||
NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mDuration));
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mMediaNumber", &value));
|
||||
if (JSVAL_IS_INT(value)) {
|
||||
NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mMediaNumber));
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mTitle", &value));
|
||||
if (JSVAL_IS_STRING(value)) {
|
||||
nsDependentJSString jsString;
|
||||
NS_ENSURE_STATE(JSVAL_IS_STRING(value));
|
||||
NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
|
||||
mTitle = jsString;
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mTotalMediaCount", &value));
|
||||
if (JSVAL_IS_INT(value)) {
|
||||
NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mTotalMediaCount));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
32
dom/bluetooth/MediaMetaData.h
Normal file
32
dom/bluetooth/MediaMetaData.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_mediametadata_h__
|
||||
#define mozilla_dom_bluetooth_mediametadata_h__
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsString.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class MediaMetaData
|
||||
{
|
||||
public:
|
||||
MediaMetaData();
|
||||
|
||||
nsresult Init(JSContext* aCx, const jsval* aVal);
|
||||
|
||||
nsString mAlbum;
|
||||
nsString mArtist;
|
||||
int64_t mDuration;
|
||||
int64_t mMediaNumber;
|
||||
nsString mTitle;
|
||||
int64_t mTotalMediaCount;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
62
dom/bluetooth/MediaPlayStatus.cpp
Normal file
62
dom/bluetooth/MediaPlayStatus.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/ */
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "MediaPlayStatus.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsCxPusher.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
MediaPlayStatus::MediaPlayStatus() : mDuration(-1)
|
||||
, mPosition(-1)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
MediaPlayStatus::Init(JSContext* aCx, const jsval* aVal)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!aCx || !aVal) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!aVal->isObject()) {
|
||||
return aVal->isNullOrUndefined() ? NS_OK : NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
JS::RootedObject obj(aCx, &aVal->toObject());
|
||||
nsCxPusher pusher;
|
||||
pusher.Push(aCx);
|
||||
JSAutoCompartment ac(aCx, obj);
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mDuration", &value));
|
||||
if (JSVAL_IS_INT(value)) {
|
||||
NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mDuration));
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mPlayStatus", &value));
|
||||
if (JSVAL_IS_STRING(value)) {
|
||||
nsDependentJSString jsString;
|
||||
NS_ENSURE_STATE(JSVAL_IS_STRING(value));
|
||||
NS_ENSURE_STATE(jsString.init(aCx, value.toString()));
|
||||
mPlayStatus = jsString;
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mPosition", &value));
|
||||
if (JSVAL_IS_INT(value)) {
|
||||
NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mPosition));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
29
dom/bluetooth/MediaPlayStatus.h
Normal file
29
dom/bluetooth/MediaPlayStatus.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_mediaplaystatus_h__
|
||||
#define mozilla_dom_bluetooth_mediaplaystatus_h__
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsString.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class MediaPlayStatus
|
||||
{
|
||||
public:
|
||||
MediaPlayStatus();
|
||||
|
||||
nsresult Init(JSContext* aCx, const jsval* aVal);
|
||||
|
||||
int64_t mDuration;
|
||||
nsString mPlayStatus;
|
||||
int64_t mPosition;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
@ -18,6 +18,7 @@ if CONFIG['MOZ_B2G_BT']:
|
||||
MODULE = 'dom'
|
||||
XPIDL_MODULE = 'dom_bluetooth'
|
||||
XPIDL_SOURCES += [
|
||||
'nsIDOMBluetoothAdapter.idl',
|
||||
'nsIDOMBluetoothDevice.idl',
|
||||
'nsIDOMBluetoothDeviceEvent.idl',
|
||||
'nsIDOMBluetoothStatusChangedEvent.idl',
|
||||
@ -41,6 +42,8 @@ if CONFIG['MOZ_B2G_BT']:
|
||||
'ObexBase.cpp',
|
||||
'BluetoothUuid.cpp',
|
||||
'BluetoothSocket.cpp',
|
||||
'MediaMetaData.cpp',
|
||||
'MediaPlayStatus.cpp'
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_RIL']:
|
||||
|
117
dom/bluetooth/nsIDOMBluetoothAdapter.idl
Normal file
117
dom/bluetooth/nsIDOMBluetoothAdapter.idl
Normal file
@ -0,0 +1,117 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsIDOMEventTarget.idl"
|
||||
|
||||
/**
|
||||
* MediaMetadata and MediaPlayStatus are used to keep data from Applications.
|
||||
* Please see specification of AVRCP 1.3 for more details.
|
||||
*
|
||||
* @title: track title
|
||||
* @artist: artist name
|
||||
* @album: album name
|
||||
* @mediaNumber: track number
|
||||
* @totalMediaCount: number of tracks in the album
|
||||
* @duration: playing time (ms)
|
||||
*/
|
||||
dictionary MediaMetaData
|
||||
{
|
||||
DOMString title;
|
||||
DOMString artist;
|
||||
DOMString album;
|
||||
unsigned long mediaNumber;
|
||||
unsigned long totalMediaCount;
|
||||
unsigned long duration;
|
||||
};
|
||||
|
||||
/**
|
||||
* @duration: current track length (ms)
|
||||
* @position: playing time (ms)
|
||||
* @playStatus: STOPPED/PLAYING/PAUSED/FWD_SEEK/REV_SEEK/ERROR
|
||||
*/
|
||||
dictionary MediaPlayStatus
|
||||
{
|
||||
unsigned long duration;
|
||||
unsigned long position;
|
||||
DOMString playStatus;
|
||||
};
|
||||
|
||||
interface nsIDOMDOMRequest;
|
||||
interface nsIDOMBlob;
|
||||
interface nsIDOMBluetoothDevice;
|
||||
|
||||
[scriptable, builtinclass, uuid(54bf9aa2-1208-47ab-ac96-c7df349fcf0e)]
|
||||
interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
|
||||
{
|
||||
readonly attribute DOMString address;
|
||||
[binaryname(AdapterClass)] readonly attribute unsigned long class;
|
||||
readonly attribute bool discovering;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval devices;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval uuids;
|
||||
|
||||
readonly attribute DOMString name;
|
||||
readonly attribute bool discoverable;
|
||||
// Unit: sec
|
||||
readonly attribute unsigned long discoverableTimeout;
|
||||
|
||||
nsIDOMDOMRequest setName(in DOMString name);
|
||||
nsIDOMDOMRequest setDiscoverable(in bool discoverable);
|
||||
nsIDOMDOMRequest setDiscoverableTimeout(in unsigned long timeout);
|
||||
nsIDOMDOMRequest startDiscovery();
|
||||
nsIDOMDOMRequest stopDiscovery();
|
||||
nsIDOMDOMRequest pair(in nsIDOMBluetoothDevice aDevice);
|
||||
nsIDOMDOMRequest unpair(in nsIDOMBluetoothDevice aDevice);
|
||||
nsIDOMDOMRequest getPairedDevices();
|
||||
nsIDOMDOMRequest getConnectedDevices(in unsigned short aProfile);
|
||||
nsIDOMDOMRequest setPinCode(in DOMString aDeviceAddress, in DOMString aPinCode);
|
||||
nsIDOMDOMRequest setPasskey(in DOMString aDeviceAddress, in unsigned long aPasskey);
|
||||
nsIDOMDOMRequest setPairingConfirmation(in DOMString aDeviceAddress, in bool aConfirmation);
|
||||
nsIDOMDOMRequest setAuthorization(in DOMString aDeviceAddress, in bool aAllow);
|
||||
|
||||
/**
|
||||
* Connect/Disconnect to a specific service of a target remote device.
|
||||
* To check the value of service UUIDs, please check "Bluetooth Assigned
|
||||
* Numbers" / "Service Discovery Protocol" for more information.
|
||||
*
|
||||
* @param aDeviceAddress Remote device address
|
||||
* @param aProfile 2-octets service UUID
|
||||
*/
|
||||
nsIDOMDOMRequest connect(in DOMString aDeviceAddress, in unsigned short aProfile);
|
||||
nsIDOMDOMRequest disconnect(in unsigned short aProfile);
|
||||
|
||||
// One device can only send one file at a time
|
||||
nsIDOMDOMRequest sendFile(in DOMString aDeviceAddress, in nsIDOMBlob aBlob);
|
||||
nsIDOMDOMRequest stopSendingFile(in DOMString aDeviceAddress);
|
||||
nsIDOMDOMRequest confirmReceivingFile(in DOMString aDeviceAddress, in bool aConfirmation);
|
||||
|
||||
// AVRCP 1.3 methods
|
||||
nsIDOMDOMRequest sendMediaMetaData(in jsval aOptions);
|
||||
nsIDOMDOMRequest sendMediaPlayStatus(in jsval aOptions);
|
||||
|
||||
// Connect/Disconnect SCO (audio) connection
|
||||
nsIDOMDOMRequest connectSco();
|
||||
nsIDOMDOMRequest disconnectSco();
|
||||
nsIDOMDOMRequest isScoConnected();
|
||||
|
||||
// Fired when discoverying and any device is discovered.
|
||||
[implicit_jscontext] attribute jsval ondevicefound;
|
||||
|
||||
// Fired when pairing process is completed
|
||||
[implicit_jscontext] attribute jsval onpairedstatuschanged;
|
||||
|
||||
// Fired when a2dp connection status changed
|
||||
[implicit_jscontext] attribute jsval ona2dpstatuschanged;
|
||||
|
||||
// Fired when handsfree connection status changed
|
||||
[implicit_jscontext] attribute jsval onhfpstatuschanged;
|
||||
|
||||
// Fired when sco connection status changed
|
||||
[implicit_jscontext] attribute jsval onscostatuschanged;
|
||||
};
|
@ -1,131 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// MediaMetadata and MediaPlayStatus are used to keep data from Applications.
|
||||
// Please see specification of AVRCP 1.3 for more details.
|
||||
dictionary MediaMetaData
|
||||
{
|
||||
// track title
|
||||
DOMString title = "";
|
||||
// artist name
|
||||
DOMString artist = "";
|
||||
// album name
|
||||
DOMString album = "";
|
||||
// track number
|
||||
long long mediaNumber = -1;
|
||||
// number of tracks in the album
|
||||
long long totalMediaCount = -1;
|
||||
// playing time (ms)
|
||||
long long duration = -1;
|
||||
};
|
||||
|
||||
dictionary MediaPlayStatus
|
||||
{
|
||||
// current track length (ms)
|
||||
long long duration = -1;
|
||||
// playing time (ms)
|
||||
long long position = -1;
|
||||
// one of 'STOPPED'/'PLAYING'/'PAUSED'/'FWD_SEEK'/'REV_SEEK'/'ERROR'
|
||||
DOMString playStatus = "";
|
||||
};
|
||||
|
||||
interface BluetoothAdapter : EventTarget {
|
||||
readonly attribute DOMString address;
|
||||
readonly attribute unsigned long class;
|
||||
readonly attribute boolean discovering;
|
||||
readonly attribute DOMString name;
|
||||
readonly attribute boolean discoverable;
|
||||
readonly attribute unsigned long discoverableTimeout; // in seconds
|
||||
|
||||
// array of type BluetoothDevice[]
|
||||
[GetterThrows]
|
||||
readonly attribute any devices;
|
||||
|
||||
// array of type DOMString[]
|
||||
[GetterThrows]
|
||||
readonly attribute any uuids;
|
||||
|
||||
[SetterThrows]
|
||||
attribute EventHandler ondevicefound;
|
||||
|
||||
// Fired when pairing process is completed
|
||||
[SetterThrows]
|
||||
attribute EventHandler onpairedstatuschanged;
|
||||
|
||||
// Fired when a2dp connection status changed
|
||||
[SetterThrows]
|
||||
attribute EventHandler ona2dpstatuschanged;
|
||||
|
||||
// Fired when handsfree connection status changed
|
||||
[SetterThrows]
|
||||
attribute EventHandler onhfpstatuschanged;
|
||||
|
||||
// Fired when sco connection status changed
|
||||
[SetterThrows]
|
||||
attribute EventHandler onscostatuschanged;
|
||||
|
||||
[Creator, Throws]
|
||||
DOMRequest setName(DOMString name);
|
||||
[Creator, Throws]
|
||||
DOMRequest setDiscoverable(boolean discoverable);
|
||||
[Creator, Throws]
|
||||
DOMRequest setDiscoverableTimeout(unsigned long timeout);
|
||||
[Creator, Throws]
|
||||
DOMRequest startDiscovery();
|
||||
[Creator, Throws]
|
||||
DOMRequest stopDiscovery();
|
||||
[Creator, Throws]
|
||||
DOMRequest pair(BluetoothDevice device);
|
||||
[Creator, Throws]
|
||||
DOMRequest unpair(BluetoothDevice device);
|
||||
[Creator, Throws]
|
||||
DOMRequest getPairedDevices();
|
||||
[Creator, Throws]
|
||||
DOMRequest getConnectedDevices(unsigned short profile);
|
||||
[Creator, Throws]
|
||||
DOMRequest setPinCode(DOMString deviceAddress, DOMString pinCode);
|
||||
[Creator, Throws]
|
||||
DOMRequest setPasskey(DOMString deviceAddress, unsigned long passkey);
|
||||
[Creator, Throws]
|
||||
DOMRequest setPairingConfirmation(DOMString deviceAddress, boolean confirmation);
|
||||
[Creator, Throws]
|
||||
DOMRequest setAuthorization(DOMString deviceAddress, boolean allow);
|
||||
|
||||
/**
|
||||
* Connect/Disconnect to a specific service of a target remote device.
|
||||
* To check the value of service UUIDs, please check "Bluetooth Assigned
|
||||
* Numbers" / "Service Discovery Protocol" for more information.
|
||||
*
|
||||
* @param deviceAddress Remote device address
|
||||
* @param profile 2-octets service UUID
|
||||
*/
|
||||
[Creator, Throws]
|
||||
DOMRequest connect(DOMString deviceAddress, unsigned short profile);
|
||||
[Creator, Throws]
|
||||
DOMRequest disconnect(unsigned short profile);
|
||||
|
||||
// One device can only send one file at a time
|
||||
[Creator, Throws]
|
||||
DOMRequest sendFile(DOMString deviceAddress, Blob blob);
|
||||
[Creator, Throws]
|
||||
DOMRequest stopSendingFile(DOMString deviceAddress);
|
||||
[Creator, Throws]
|
||||
DOMRequest confirmReceivingFile(DOMString deviceAddress, boolean confirmation);
|
||||
|
||||
// Connect/Disconnect SCO (audio) connection
|
||||
[Creator, Throws]
|
||||
DOMRequest connectSco();
|
||||
[Creator, Throws]
|
||||
DOMRequest disconnectSco();
|
||||
[Creator, Throws]
|
||||
DOMRequest isScoConnected();
|
||||
|
||||
// AVRCP 1.3 methods
|
||||
[Creator,Throws]
|
||||
DOMRequest sendMediaMetaData(optional MediaMetaData mediaMetaData);
|
||||
[Creator,Throws]
|
||||
DOMRequest sendMediaPlayStatus(optional MediaPlayStatus mediaPlayStatus);
|
||||
};
|
@ -476,7 +476,6 @@ webidl_files += \
|
||||
|
||||
ifdef MOZ_B2G_BT
|
||||
webidl_files += \
|
||||
BluetoothAdapter.webidl \
|
||||
BluetoothDeviceEvent.webidl \
|
||||
BluetoothManager.webidl \
|
||||
BluetoothStatusChangedEvent.webidl \
|
||||
|
Loading…
Reference in New Issue
Block a user