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