mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 790133 - Final version: Fire devicecreated event with a BluetoothDevice, r=qdot, sr=mrbkap
This commit is contained in:
parent
1180570856
commit
1110893113
@ -660,6 +660,7 @@ GK_ATOM(oncut, "oncut")
|
|||||||
GK_ATOM(ondatachange, "ondatachange")
|
GK_ATOM(ondatachange, "ondatachange")
|
||||||
GK_ATOM(ondblclick, "ondblclick")
|
GK_ATOM(ondblclick, "ondblclick")
|
||||||
GK_ATOM(ondelivered, "ondelivered")
|
GK_ATOM(ondelivered, "ondelivered")
|
||||||
|
GK_ATOM(ondevicecreated, "ondevicecreated")
|
||||||
GK_ATOM(ondevicedisappeared, "ondevicedisappeared")
|
GK_ATOM(ondevicedisappeared, "ondevicedisappeared")
|
||||||
GK_ATOM(ondevicefound, "ondevicefound")
|
GK_ATOM(ondevicefound, "ondevicefound")
|
||||||
GK_ATOM(ondialing, "ondialing")
|
GK_ATOM(ondialing, "ondialing")
|
||||||
|
@ -291,6 +291,22 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData)
|
|||||||
e->SetTrusted(true);
|
e->SetTrusted(true);
|
||||||
bool dummy;
|
bool dummy;
|
||||||
DispatchEvent(event, &dummy);
|
DispatchEvent(event, &dummy);
|
||||||
|
} else if (aData.name().EqualsLiteral("DeviceCreated")) {
|
||||||
|
NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue,
|
||||||
|
"DeviceCreated: Invalid value type");
|
||||||
|
|
||||||
|
nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(),
|
||||||
|
GetPath(),
|
||||||
|
aData.value());
|
||||||
|
nsCOMPtr<nsIDOMEvent> event;
|
||||||
|
NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), nullptr, nullptr);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event);
|
||||||
|
e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicecreated"),
|
||||||
|
false, false, device);
|
||||||
|
e->SetTrusted(true);
|
||||||
|
bool dummy;
|
||||||
|
DispatchEvent(event, &dummy);
|
||||||
} else if (aData.name().EqualsLiteral("PropertyChanged")) {
|
} else if (aData.name().EqualsLiteral("PropertyChanged")) {
|
||||||
// Get BluetoothNamedValue, make sure array length is 1
|
// Get BluetoothNamedValue, make sure array length is 1
|
||||||
arr = aData.value().get_ArrayOfBluetoothNamedValue();
|
arr = aData.value().get_ArrayOfBluetoothNamedValue();
|
||||||
@ -628,6 +644,7 @@ BluetoothAdapter::SetAuthorization(const nsAString& aDeviceAddress, bool aAllow)
|
|||||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, propertychanged)
|
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, propertychanged)
|
||||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicefound)
|
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicefound)
|
||||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicedisappeared)
|
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicedisappeared)
|
||||||
|
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicecreated)
|
||||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, requestconfirmation)
|
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, requestconfirmation)
|
||||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, requestpincode)
|
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, requestpincode)
|
||||||
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, requestpasskey)
|
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, requestpasskey)
|
||||||
|
@ -159,18 +159,16 @@ public:
|
|||||||
BluetoothReplyRunnable* aRunnable) = 0;
|
BluetoothReplyRunnable* aRunnable) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the propertes for the specified object
|
* Fetches the propertes for the specified device
|
||||||
*
|
*
|
||||||
* @param aType Type of the object (see BluetoothObjectType in BluetoothCommon.h)
|
* @param aDevicePath Path of the object
|
||||||
* @param aPath Path of the object
|
* @param aSignalPath Path to distrubute signal after receiving properties
|
||||||
* @param aRunnable Runnable to return to after receiving callback
|
|
||||||
*
|
*
|
||||||
* @return NS_OK on function run, NS_ERROR_FAILURE otherwise
|
* @return NS_OK on function run, NS_ERROR_FAILURE otherwise
|
||||||
*/
|
*/
|
||||||
virtual nsresult
|
virtual nsresult
|
||||||
GetProperties(BluetoothObjectType aType,
|
GetDevicePropertiesInternal(const nsAString& aDevicePath,
|
||||||
const nsAString& aPath,
|
const nsAString& aSignalPath) = 0;
|
||||||
BluetoothReplyRunnable* aRunnable) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a property for the specified object
|
* Set a property for the specified object
|
||||||
|
@ -949,6 +949,18 @@ EventFilter(DBusConnection* aConn, DBusMessage* aMsg, void* aData)
|
|||||||
} else {
|
} else {
|
||||||
v = NS_ConvertUTF8toUTF16(str);
|
v = NS_ConvertUTF8toUTF16(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get device properties and then send to BluetoothAdapter
|
||||||
|
BluetoothService* bs = BluetoothService::Get();
|
||||||
|
if (!bs) {
|
||||||
|
NS_WARNING("BluetoothService not available!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_FAILED(bs->GetDevicePropertiesInternal(v, signalPath))) {
|
||||||
|
NS_WARNING("get properties failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
return DBUS_HANDLER_RESULT_HANDLED;
|
||||||
} else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE, "DeviceRemoved")) {
|
} else if (dbus_message_is_signal(aMsg, DBUS_ADAPTER_IFACE, "DeviceRemoved")) {
|
||||||
const char* str;
|
const char* str;
|
||||||
if (!dbus_message_get_args(aMsg, &err,
|
if (!dbus_message_get_args(aMsg, &err,
|
||||||
@ -1258,6 +1270,66 @@ BluetoothDBusService::StartDiscoveryInternal(const nsAString& aAdapterPath,
|
|||||||
return SendDiscoveryMessage(aAdapterPath, "StartDiscovery", aRunnable);
|
return SendDiscoveryMessage(aAdapterPath, "StartDiscovery", aRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BluetoothDevicePropertiesRunnable : public nsRunnable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BluetoothDevicePropertiesRunnable(const nsAString& aDevicePath,
|
||||||
|
const nsAString& aSignalPath) :
|
||||||
|
mDevicePath(aDevicePath),
|
||||||
|
mSignalPath(aSignalPath)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
}
|
||||||
|
|
||||||
|
~BluetoothDevicePropertiesRunnable()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHOD Run()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(!NS_IsMainThread());
|
||||||
|
|
||||||
|
DBusError err;
|
||||||
|
dbus_error_init(&err);
|
||||||
|
|
||||||
|
BluetoothValue v = InfallibleTArray<BluetoothNamedValue>();
|
||||||
|
nsString replyError;
|
||||||
|
|
||||||
|
DBusMessage* msg = dbus_func_args_timeout(gThreadConnection->GetConnection(),
|
||||||
|
1000,
|
||||||
|
&err,
|
||||||
|
NS_ConvertUTF16toUTF8(mDevicePath).get(),
|
||||||
|
DBUS_DEVICE_IFACE,
|
||||||
|
"GetProperties",
|
||||||
|
DBUS_TYPE_INVALID);
|
||||||
|
UnpackDevicePropertiesMessage(msg, &err, v, replyError);
|
||||||
|
|
||||||
|
if (!replyError.IsEmpty()) {
|
||||||
|
NS_WARNING("Failed to get device properties");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
if (msg) {
|
||||||
|
dbus_message_unref(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluetoothSignal signal(NS_LITERAL_STRING("DeviceCreated"),
|
||||||
|
mSignalPath, v);
|
||||||
|
|
||||||
|
nsRefPtr<DistributeBluetoothSignalTask> t = new DistributeBluetoothSignalTask(signal);
|
||||||
|
|
||||||
|
if (NS_FAILED(NS_DispatchToMainThread(t))) {
|
||||||
|
NS_WARNING("Failed to dispatch to main thread!");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsString mDevicePath;
|
||||||
|
nsString mSignalPath;
|
||||||
|
};
|
||||||
|
|
||||||
class BluetoothPairedDevicePropertiesRunnable : public nsRunnable
|
class BluetoothPairedDevicePropertiesRunnable : public nsRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -1329,32 +1401,22 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
BluetoothDBusService::GetProperties(BluetoothObjectType aType,
|
BluetoothDBusService::GetDevicePropertiesInternal(const nsAString& aDevicePath,
|
||||||
const nsAString& aPath,
|
const nsAString& aSignalPath)
|
||||||
BluetoothReplyRunnable* aRunnable)
|
|
||||||
{
|
{
|
||||||
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
||||||
|
|
||||||
MOZ_ASSERT(aType < ArrayLength(sBluetoothDBusIfaces));
|
if (!mConnection || !gThreadConnection) {
|
||||||
MOZ_ASSERT(aType < ArrayLength(sBluetoothDBusPropCallbacks));
|
NS_ERROR("Bluetooth service not started yet!");
|
||||||
|
|
||||||
const char* interface = sBluetoothDBusIfaces[aType];
|
|
||||||
DBusCallback callback = sBluetoothDBusPropCallbacks[aType];
|
|
||||||
|
|
||||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
|
||||||
|
|
||||||
if (!dbus_func_args_async(mConnection,
|
|
||||||
1000,
|
|
||||||
callback,
|
|
||||||
(void*)aRunnable,
|
|
||||||
NS_ConvertUTF16toUTF8(aPath).get(),
|
|
||||||
interface,
|
|
||||||
"GetProperties",
|
|
||||||
DBUS_TYPE_INVALID)) {
|
|
||||||
NS_WARNING("Could not start async function!");
|
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
runnable.forget();
|
|
||||||
|
nsRefPtr<nsRunnable> func(new BluetoothDevicePropertiesRunnable(aDevicePath, aSignalPath));
|
||||||
|
if (NS_FAILED(mBluetoothCommandThread->Dispatch(func, NS_DISPATCH_NORMAL))) {
|
||||||
|
NS_WARNING("Cannot dispatch task!");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,15 +33,17 @@ public:
|
|||||||
BluetoothReplyRunnable* aRunnable);
|
BluetoothReplyRunnable* aRunnable);
|
||||||
virtual nsresult StopDiscoveryInternal(const nsAString& aAdapterPath,
|
virtual nsresult StopDiscoveryInternal(const nsAString& aAdapterPath,
|
||||||
BluetoothReplyRunnable* aRunnable);
|
BluetoothReplyRunnable* aRunnable);
|
||||||
|
|
||||||
virtual nsresult
|
virtual nsresult
|
||||||
GetProperties(BluetoothObjectType aType,
|
GetDevicePropertiesInternal(const nsAString& aDevicePath,
|
||||||
const nsAString& aPath,
|
const nsAString& aSignalPath);
|
||||||
BluetoothReplyRunnable* aRunnable);
|
|
||||||
virtual nsresult
|
virtual nsresult
|
||||||
SetProperty(BluetoothObjectType aType,
|
SetProperty(BluetoothObjectType aType,
|
||||||
const nsAString& aPath,
|
const nsAString& aPath,
|
||||||
const BluetoothNamedValue& aValue,
|
const BluetoothNamedValue& aValue,
|
||||||
BluetoothReplyRunnable* aRunnable);
|
BluetoothReplyRunnable* aRunnable);
|
||||||
|
|
||||||
virtual bool
|
virtual bool
|
||||||
GetDevicePath(const nsAString& aAdapterPath,
|
GetDevicePath(const nsAString& aAdapterPath,
|
||||||
const nsAString& aDeviceAddress,
|
const nsAString& aDeviceAddress,
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
interface nsIDOMDOMRequest;
|
interface nsIDOMDOMRequest;
|
||||||
interface nsIDOMBluetoothDevice;
|
interface nsIDOMBluetoothDevice;
|
||||||
|
|
||||||
[scriptable, builtinclass, uuid(4ea7d312-f37c-4777-8114-fc7312890199)]
|
[scriptable, builtinclass, uuid(df1465c6-00b7-49ab-bd20-1b63721d118f)]
|
||||||
interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
|
interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
|
||||||
{
|
{
|
||||||
readonly attribute DOMString address;
|
readonly attribute DOMString address;
|
||||||
@ -45,6 +45,8 @@ interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
|
|||||||
[implicit_jscontext] attribute jsval ondevicefound;
|
[implicit_jscontext] attribute jsval ondevicefound;
|
||||||
// Fired when any device is out of discoverable range.
|
// Fired when any device is out of discoverable range.
|
||||||
[implicit_jscontext] attribute jsval ondevicedisappeared;
|
[implicit_jscontext] attribute jsval ondevicedisappeared;
|
||||||
|
// Fired when any device is created.
|
||||||
|
[implicit_jscontext] attribute jsval ondevicecreated;
|
||||||
// Fired when a property of the adapter is changed
|
// Fired when a property of the adapter is changed
|
||||||
[implicit_jscontext] attribute jsval onpropertychanged;
|
[implicit_jscontext] attribute jsval onpropertychanged;
|
||||||
// Pairing related events
|
// Pairing related events
|
||||||
|
Loading…
Reference in New Issue
Block a user