Skip to content

Commit

Permalink
Bug 1127670 - Replace device property of BluetoothPairingEvent with d…
Browse files Browse the repository at this point in the history
…evice name. r=btian, r=bz
  • Loading branch information
rmottola committed Jul 24, 2019
1 parent 8843467 commit 2765ed7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
25 changes: 8 additions & 17 deletions dom/bluetooth2/BluetoothPairingListener.cpp
Expand Up @@ -50,23 +50,21 @@ BluetoothPairingListener::~BluetoothPairingListener()
}

void
BluetoothPairingListener::DispatchPairingEvent(BluetoothDevice* aDevice,
BluetoothPairingListener::DispatchPairingEvent(const nsAString& aName,
const nsAString& aAddress,
const nsAString& aPasskey,
const nsAString& aType)
{
MOZ_ASSERT(aDevice && !aType.IsEmpty());

nsString address;
aDevice->GetAddress(address);
MOZ_ASSERT(!aName.IsEmpty() && !aAddress.IsEmpty() && !aType.IsEmpty());

nsRefPtr<BluetoothPairingHandle> handle =
BluetoothPairingHandle::Create(GetOwner(),
address,
aAddress,
aType,
aPasskey);

BluetoothPairingEventInit init;
init.mDevice = aDevice;
init.mDeviceName = aName;
init.mHandle = handle;

nsRefPtr<BluetoothPairingEvent> event =
Expand Down Expand Up @@ -96,20 +94,13 @@ BluetoothPairingListener::Notify(const BluetoothSignal& aData)
arr[2].value().type() == BluetoothValue::TnsString && // passkey
arr[3].value().type() == BluetoothValue::TnsString); // type

nsString deviceAddress = arr[0].value().get_nsString();
nsString deviceName = arr[1].value().get_nsString();
nsString address = arr[0].value().get_nsString();
nsString name = arr[1].value().get_nsString();
nsString passkey = arr[2].value().get_nsString();
nsString type = arr[3].value().get_nsString();

// Create a temporary device with deviceAddress and deviceName
InfallibleTArray<BluetoothNamedValue> props;
BT_APPEND_NAMED_VALUE(props, "Address", deviceAddress);
BT_APPEND_NAMED_VALUE(props, "Name", deviceName);
nsRefPtr<BluetoothDevice> device =
BluetoothDevice::Create(GetOwner(), props);

// Notify pairing listener of pairing requests
DispatchPairingEvent(device, passkey, type);
DispatchPairingEvent(name, address, passkey, type);
} else {
BT_WARNING("Not handling pairing listener signal: %s",
NS_ConvertUTF16toUTF8(aData.name()).get());
Expand Down
3 changes: 2 additions & 1 deletion dom/bluetooth2/BluetoothPairingListener.h
Expand Up @@ -25,7 +25,8 @@ class BluetoothPairingListener final : public DOMEventTargetHelper
static already_AddRefed<BluetoothPairingListener>
Create(nsPIDOMWindow* aWindow);

void DispatchPairingEvent(BluetoothDevice* aDevice,
void DispatchPairingEvent(const nsAString& aName,
const nsAString& aAddress,
const nsAString& aPasskey,
const nsAString& aType);

Expand Down
4 changes: 2 additions & 2 deletions dom/webidl/BluetoothPairingEvent.webidl
Expand Up @@ -9,12 +9,12 @@
optional BluetoothPairingEventInit eventInitDict)]
interface BluetoothPairingEvent : Event
{
readonly attribute BluetoothDevice device;
readonly attribute DOMString deviceName;
readonly attribute BluetoothPairingHandle handle;
};

dictionary BluetoothPairingEventInit : EventInit
{
required BluetoothDevice device;
required DOMString deviceName;
required BluetoothPairingHandle handle;
};

0 comments on commit 2765ed7

Please sign in to comment.