Bug 1033898 - Patch1: Add BluetoothPairingEvent and BluetoothPairingHandlewebidls and their class implementations. r=btian, r=bz

This commit is contained in:
Jocelyn Liu 2014-07-28 22:09:00 +02:00
parent 3a08dbaaeb
commit ce11b55a6f
21 changed files with 330 additions and 192 deletions

View File

@ -166,20 +166,24 @@ DOMInterfaces = {
'nativeType': 'mozilla::dom::bluetooth::BluetoothAdapter',
},
'BluetoothDevice': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothDevice',
'BluetoothClassOfDevice': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothClassOfDevice',
},
'BluetoothManager': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothManager',
'BluetoothDevice': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothDevice',
},
'BluetoothDiscoveryHandle': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothDiscoveryHandle',
},
'BluetoothClassOfDevice': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothClassOfDevice',
'BluetoothManager': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothManager',
},
'BluetoothPairingHandle': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothPairingHandle',
},
'CameraCapabilities': {

View File

@ -407,10 +407,9 @@ BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
/**
* Ensure
@ -451,10 +450,9 @@ BluetoothAdapter::StopDiscovery(ErrorResult& aRv)
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
/**
* Ensure
@ -484,14 +482,13 @@ already_AddRefed<Promise>
BluetoothAdapter::SetName(const nsAString& aName, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if(!global) {
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
/**
* Ensure
@ -525,14 +522,13 @@ already_AddRefed<Promise>
BluetoothAdapter::SetDiscoverable(bool aDiscoverable, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if(!global) {
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
/**
* Ensure
@ -646,104 +642,17 @@ BluetoothAdapter::Unpair(const nsAString& aDeviceAddress, ErrorResult& aRv)
return PairUnpair(false, aDeviceAddress, aRv);
}
already_AddRefed<DOMRequest>
BluetoothAdapter::SetPinCode(const nsAString& aDeviceAddress,
const nsAString& aPinCode, 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(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
if (!bs->SetPinCodeInternal(aDeviceAddress, aPinCode, results)) {
BT_WARNING("SetPinCode failed!");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::SetPasskey(const nsAString& aDeviceAddress, uint32_t aPasskey,
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(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
if (bs->SetPasskeyInternal(aDeviceAddress, aPasskey, results)) {
BT_WARNING("SetPasskeyInternal failed!");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::SetPairingConfirmation(const nsAString& aDeviceAddress,
bool aConfirmation, 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(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
if (!bs->SetPairingConfirmationInternal(aDeviceAddress,
aConfirmation,
results)) {
BT_WARNING("SetPairingConfirmation failed!");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return request.forget();
}
already_AddRefed<Promise>
BluetoothAdapter::EnableDisable(bool aEnable, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if(!global) {
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
// Ensure BluetoothService is available before modifying adapter state
BluetoothService* bs = BluetoothService::Get();

View File

@ -99,18 +99,6 @@ public:
Unpair(const nsAString& aDeviceAddress, 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<Promise> EnableDisable(bool aEnable, ErrorResult& aRv);
already_AddRefed<Promise> Enable(ErrorResult& aRv);

View File

@ -148,6 +148,15 @@ extern bool gBluetoothDebugFlag;
#define HFP_STATUS_CHANGED_ID "hfpstatuschanged"
#define SCO_STATUS_CHANGED_ID "scostatuschanged"
/**
* Types of pairing requests for constructing BluetoothPairingEvent and
* BluetoothPairingHandle.
*/
#define PAIRING_REQ_TYPE_DISPLAYPASSKEY "displaypasskeyreq"
#define PAIRING_REQ_TYPE_ENTERPINCODE "enterpincodereq"
#define PAIRING_REQ_TYPE_CONFIRMATION "pairingconfirmationreq"
#define PAIRING_REQ_TYPE_CONSENT "pairingconsentreq"
/**
* When the pair status of a Bluetooth device is changed, we'll dispatch an
* event.

View File

@ -144,9 +144,7 @@ BluetoothDevice::FetchUuids(ErrorResult& aRv)
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, NS_ERROR_NOT_AVAILABLE);

View File

@ -0,0 +1,129 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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 "BluetoothDevice.h"
#include "BluetoothPairingHandle.h"
#include "BluetoothReplyRunnable.h"
#include "BluetoothService.h"
#include "mozilla/dom/BluetoothPairingHandleBinding.h"
#include "mozilla/dom/Promise.h"
using namespace mozilla;
using namespace dom;
USING_BLUETOOTH_NAMESPACE
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BluetoothPairingHandle, mOwner)
NS_IMPL_CYCLE_COLLECTING_ADDREF(BluetoothPairingHandle)
NS_IMPL_CYCLE_COLLECTING_RELEASE(BluetoothPairingHandle)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BluetoothPairingHandle)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
BluetoothPairingHandle::BluetoothPairingHandle(nsPIDOMWindow* aOwner,
const nsAString& aDeviceAddress,
const nsAString& aType,
const nsAString& aPasskey)
: mOwner(aOwner)
, mDeviceAddress(aDeviceAddress)
, mType(aType)
, mPasskey(aPasskey)
{
MOZ_ASSERT(aOwner && !aDeviceAddress.IsEmpty() && !aType.IsEmpty());
if (aType.EqualsLiteral(PAIRING_REQ_TYPE_DISPLAYPASSKEY) ||
aType.EqualsLiteral(PAIRING_REQ_TYPE_CONFIRMATION)) {
MOZ_ASSERT(!aPasskey.IsEmpty());
} else {
MOZ_ASSERT(aPasskey.IsEmpty());
}
SetIsDOMBinding();
}
BluetoothPairingHandle::~BluetoothPairingHandle()
{
}
already_AddRefed<BluetoothPairingHandle>
BluetoothPairingHandle::Create(nsPIDOMWindow* aOwner,
const nsAString& aDeviceAddress,
const nsAString& aType,
const nsAString& aPasskey)
{
MOZ_ASSERT(aOwner && !aDeviceAddress.IsEmpty() && !aType.IsEmpty());
nsRefPtr<BluetoothPairingHandle> handle =
new BluetoothPairingHandle(aOwner, aDeviceAddress, aType, aPasskey);
return handle.forget();
}
already_AddRefed<Promise>
BluetoothPairingHandle::SetPinCode(const nsAString& aPinCode, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral("enterpincodereq"),
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, NS_ERROR_NOT_AVAILABLE);
nsRefPtr<BluetoothReplyRunnable> result =
new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */,
promise,
NS_LITERAL_STRING("SetPinCode"));
bs->SetPinCodeInternal(mDeviceAddress, aPinCode, result);
return promise.forget();
}
already_AddRefed<Promise>
BluetoothPairingHandle::SetPairingConfirmation(bool aConfirm, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral("pairingconfirmationreq"),
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, NS_ERROR_NOT_AVAILABLE);
nsRefPtr<BluetoothReplyRunnable> result =
new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */,
promise,
NS_LITERAL_STRING(
"SetPairingConfirmation"));
bs->SetPairingConfirmationInternal(mDeviceAddress,
aConfirm,
result);
return promise.forget();
}
JSObject*
BluetoothPairingHandle::WrapObject(JSContext* aCx)
{
return BluetoothPairingHandleBinding::Wrap(aCx, this);
}

View File

@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_bluetoothpairinghandle_h
#define mozilla_dom_bluetooth_bluetoothpairinghandle_h
#include "nsWrapperCache.h"
namespace mozilla {
class ErrorResult;
namespace dom {
class Promise;
}
}
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothDevice;
class BluetoothPairingHandle MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BluetoothPairingHandle)
static already_AddRefed<BluetoothPairingHandle>
Create(nsPIDOMWindow* aOwner,
const nsAString& aDeviceAddress,
const nsAString& aType,
const nsAString& aPasskey);
nsPIDOMWindow* GetParentObject() const
{
return mOwner;
}
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
void GetPasskey(nsString& aPasskey) const
{
aPasskey = mPasskey;
}
already_AddRefed<Promise>
SetPinCode(const nsAString& aPinCode, ErrorResult& aRv);
already_AddRefed<Promise>
SetPairingConfirmation(bool aConfirm, ErrorResult& aRv);
private:
BluetoothPairingHandle(nsPIDOMWindow* aOwner,
const nsAString& aDeviceAddress,
const nsAString& aType,
const nsAString& aPasskey);
~BluetoothPairingHandle();
nsCOMPtr<nsPIDOMWindow> mOwner;
nsString mDeviceAddress;
nsString mType;
nsString mPasskey;
};
END_BLUETOOTH_NAMESPACE
#endif // mozilla_dom_bluetooth_bluetoothpairinghandle_h

View File

@ -219,15 +219,15 @@ public:
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager) = 0;
virtual bool
virtual void
SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0;
virtual bool
virtual void
SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) = 0;
virtual bool
virtual void
SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) = 0;

View File

@ -45,6 +45,15 @@
} \
} while(0)
#define ENSURE_BLUETOOTH_IS_READY_VOID(runnable) \
do { \
if (!sBtInterface || !IsEnabled()) { \
NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth is not ready"); \
DispatchBluetoothReply(runnable, BluetoothValue(), errorStr); \
return; \
} \
} while(0)
using namespace mozilla;
using namespace mozilla::ipc;
USING_BLUETOOTH_NAMESPACE
@ -1492,14 +1501,14 @@ private:
BluetoothReplyRunnable* mRunnable;
};
bool
void
BluetoothServiceBluedroid::SetPinCodeInternal(
const nsAString& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY(aRunnable, false);
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
bt_bdaddr_t remoteAddress;
StringToBdAddressType(aDeviceAddress, &remoteAddress);
@ -1508,16 +1517,14 @@ BluetoothServiceBluedroid::SetPinCodeInternal(
&remoteAddress, true, aPinCode.Length(),
(bt_pin_code_t*)NS_ConvertUTF16toUTF8(aPinCode).get(),
new PinReplyResultHandler(aRunnable));
return true;
}
bool
void
BluetoothServiceBluedroid::SetPasskeyInternal(
const nsAString& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable)
{
return true;
return;
}
class SspReplyResultHandler MOZ_FINAL : public BluetoothResultHandler
@ -1542,21 +1549,23 @@ private:
BluetoothReplyRunnable* mRunnable;
};
bool
void
BluetoothServiceBluedroid::SetPairingConfirmationInternal(
const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY(aRunnable, false);
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
bt_bdaddr_t remoteAddress;
StringToBdAddressType(aDeviceAddress, &remoteAddress);
sBtInterface->SspReply(&remoteAddress, (bt_ssp_variant_t)0, aConfirm, 0,
sBtInterface->SspReply(&remoteAddress,
BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
aConfirm,
0, /* aPasskey */
new SspReplyResultHandler(aRunnable));
return true;
}
static void

View File

@ -66,15 +66,15 @@ public:
RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
BluetoothReplyRunnable* aRunnable);
virtual bool
virtual void
SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable);
virtual bool
virtual void
SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable);
virtual bool
virtual void
SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable);

View File

@ -3195,7 +3195,7 @@ private:
nsRefPtr<BluetoothReplyRunnable> mRunnable;
};
bool
void
BluetoothDBusService::SetPinCodeInternal(const nsAString& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable)
@ -3204,8 +3204,6 @@ BluetoothDBusService::SetPinCodeInternal(const nsAString& aDeviceAddress,
NS_ConvertUTF16toUTF8(aPinCode),
aRunnable);
DispatchToDBusThread(task);
return true;
}
class SetPasskeyTask : public Task
@ -3271,7 +3269,7 @@ private:
nsRefPtr<BluetoothReplyRunnable> mRunnable;
};
bool
void
BluetoothDBusService::SetPasskeyInternal(const nsAString& aDeviceAddress,
uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable)
@ -3280,12 +3278,10 @@ BluetoothDBusService::SetPasskeyInternal(const nsAString& aDeviceAddress,
aPasskey,
aRunnable);
DispatchToDBusThread(task);
return true;
}
bool
void
BluetoothDBusService::SetPairingConfirmationInternal(
const nsAString& aDeviceAddress,
bool aConfirm,
@ -3297,8 +3293,6 @@ BluetoothDBusService::SetPairingConfirmationInternal(
aConfirm,
aRunnable);
DispatchToDBusThread(task);
return true;
}
static void

View File

@ -93,15 +93,15 @@ public:
RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
virtual nsresult
SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
virtual nsresult
SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
virtual nsresult
SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;

View File

@ -466,12 +466,9 @@ BluetoothRequestParent::DoRequest(const SetPinCodeRequest& aRequest)
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TSetPinCodeRequest);
bool result =
mService->SetPinCodeInternal(aRequest.path(),
aRequest.pincode(),
mReplyRunnable.get());
NS_ENSURE_TRUE(result, false);
mService->SetPinCodeInternal(aRequest.path(),
aRequest.pincode(),
mReplyRunnable.get());
return true;
}
@ -482,12 +479,9 @@ BluetoothRequestParent::DoRequest(const SetPasskeyRequest& aRequest)
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TSetPasskeyRequest);
bool result =
mService->SetPasskeyInternal(aRequest.path(),
aRequest.passkey(),
mReplyRunnable.get());
NS_ENSURE_TRUE(result, false);
mService->SetPasskeyInternal(aRequest.path(),
aRequest.passkey(),
mReplyRunnable.get());
return true;
}
@ -499,12 +493,9 @@ BluetoothRequestParent::DoRequest(const ConfirmPairingConfirmationRequest&
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConfirmPairingConfirmationRequest);
bool result =
mService->SetPairingConfirmationInternal(aRequest.path(),
true,
mReplyRunnable.get());
NS_ENSURE_TRUE(result, false);
mService->SetPairingConfirmationInternal(aRequest.path(),
true,
mReplyRunnable.get());
return true;
}
@ -516,12 +507,9 @@ BluetoothRequestParent::DoRequest(const DenyPairingConfirmationRequest&
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDenyPairingConfirmationRequest);
bool result =
mService->SetPairingConfirmationInternal(aRequest.path(),
false,
mReplyRunnable.get());
NS_ENSURE_TRUE(result, false);
mService->SetPairingConfirmationInternal(aRequest.path(),
false,
mReplyRunnable.get());
return true;
}

View File

@ -207,7 +207,7 @@ BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress,
MOZ_CRASH("This should never be called!");
}
bool
void
BluetoothServiceChildProcess::SetPinCodeInternal(
const nsAString& aDeviceAddress,
const nsAString& aPinCode,
@ -215,10 +215,9 @@ BluetoothServiceChildProcess::SetPinCodeInternal(
{
SendRequest(aRunnable,
SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode)));
return true;
}
bool
void
BluetoothServiceChildProcess::SetPasskeyInternal(
const nsAString& aDeviceAddress,
uint32_t aPasskey,
@ -226,10 +225,9 @@ BluetoothServiceChildProcess::SetPasskeyInternal(
{
SendRequest(aRunnable,
SetPasskeyRequest(nsString(aDeviceAddress), aPasskey));
return true;
}
bool
void
BluetoothServiceChildProcess::SetPairingConfirmationInternal(
const nsAString& aDeviceAddress,
bool aConfirm,
@ -242,7 +240,6 @@ BluetoothServiceChildProcess::SetPairingConfirmationInternal(
SendRequest(aRunnable,
DenyPairingConfirmationRequest(nsString(aDeviceAddress)));
}
return true;
}
void

View File

@ -94,17 +94,17 @@ public:
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager) MOZ_OVERRIDE;
virtual bool
virtual void
SetPinCodeInternal(const nsAString& aDeviceAddress,
const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
virtual void
SetPasskeyInternal(const nsAString& aDeviceAddress,
uint32_t aPasskey,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
virtual void
SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)

View File

@ -12,6 +12,7 @@ if CONFIG['MOZ_B2G_BT']:
'BluetoothDiscoveryHandle.cpp',
'BluetoothHidManager.cpp',
'BluetoothManager.cpp',
'BluetoothPairingHandle.cpp',
'BluetoothProfileController.cpp',
'BluetoothReplyRunnable.cpp',
'BluetoothService.cpp',
@ -99,6 +100,7 @@ EXPORTS.mozilla.dom.bluetooth += [
'BluetoothDevice.h',
'BluetoothDiscoveryHandle.h',
'BluetoothManager.h',
'BluetoothPairingHandle.h',
]
IPDL_SOURCES += [

View File

@ -60,6 +60,10 @@ const kEventConstructors = {
return new BluetoothDiscoveryStateChangedEvent(aName, aProps);
},
},
BluetoothPairingEvent: { create: function (aName, aProps) {
return new BluetoothPairingEvent(aName, aProps);
},
},
BluetoothStatusChangedEvent: { create: function (aName, aProps) {
return new BluetoothStatusChangedEvent(aName, aProps);
},

View File

@ -113,12 +113,6 @@ interface BluetoothAdapter : EventTarget {
DOMRequest getPairedDevices();
[NewObject, Throws]
DOMRequest getConnectedDevices(unsigned short serviceUuid);
[NewObject, Throws]
DOMRequest setPinCode(DOMString deviceAddress, DOMString pinCode);
[NewObject, Throws]
DOMRequest setPasskey(DOMString deviceAddress, unsigned long passkey);
[NewObject, Throws]
DOMRequest setPairingConfirmation(DOMString deviceAddress, boolean confirmation);
/**
* Connect/Disconnect to a specific service of a target remote device.

View File

@ -0,0 +1,20 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
[CheckPermissions="bluetooth",
Constructor(DOMString type,
optional BluetoothPairingEventInit eventInitDict)]
interface BluetoothPairingEvent : Event
{
readonly attribute BluetoothDevice? device;
readonly attribute BluetoothPairingHandle? handle;
};
dictionary BluetoothPairingEventInit : EventInit
{
BluetoothDevice? device = null;
BluetoothPairingHandle? handle = null;
};

View File

@ -0,0 +1,22 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
[CheckPermissions="bluetooth"]
interface BluetoothPairingHandle
{
/**
* A 6-digit string ranging from decimal 000000 to 999999.
* This attribute is an empty string for enterpincodereq and
* pairingconsentreq.
*/
readonly attribute DOMString passkey;
// Promise<void>
[NewObject, Throws]
Promise setPinCode(DOMString aPinCode);
// Promise<void>
[NewObject, Throws]
Promise setPairingConfirmation(boolean aConfirm);
};

View File

@ -571,6 +571,7 @@ if CONFIG['MOZ_B2G_BT']:
'BluetoothDevice2.webidl',
'BluetoothDiscoveryHandle.webidl',
'BluetoothManager2.webidl',
'BluetoothPairingHandle.webidl',
]
else:
WEBIDL_FILES += [
@ -695,6 +696,7 @@ if CONFIG['MOZ_B2G_BT']:
GENERATED_EVENTS_WEBIDL_FILES += [
'BluetoothAdapterEvent.webidl',
'BluetoothAttributeEvent.webidl',
'BluetoothPairingEvent.webidl',
]
else:
GENERATED_EVENTS_WEBIDL_FILES += [