From ab94506215ece63a5996b196a2e59967e3c78538 Mon Sep 17 00:00:00 2001 From: Gina Yeh Date: Wed, 4 Sep 2013 10:40:01 +0800 Subject: [PATCH] Bug 910974 - Patch 1: Dispatch events when remote device queries current play status, r=echou, sr=mrbkap --- content/base/src/nsGkAtomList.h | 1 + dom/bluetooth/BluetoothAdapter.cpp | 9 +++++++++ dom/bluetooth/BluetoothAdapter.h | 1 + dom/bluetooth/BluetoothCommon.h | 10 ++++++++-- dom/bluetooth/linux/BluetoothDBusService.cpp | 15 +++++++-------- dom/webidl/BluetoothAdapter.webidl | 4 ++++ 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index f678982df5dc..26620fea9247 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -773,6 +773,7 @@ GK_ATOM(onremoteheld, "onremoteheld") GK_ATOM(onremoteresumed, "onremoteresumed") GK_ATOM(onretrieving, "onretrieving") GK_ATOM(onRequest, "onRequest") +GK_ATOM(onrequestmediaplaystatus, "onrequestmediaplaystatus") GK_ATOM(onreset, "onreset") GK_ATOM(onresuming, "onresuming") GK_ATOM(onMozBeforeResize, "onMozBeforeResize") diff --git a/dom/bluetooth/BluetoothAdapter.cpp b/dom/bluetooth/BluetoothAdapter.cpp index cdf52d45770d..42e97f3aec9c 100644 --- a/dom/bluetooth/BluetoothAdapter.cpp +++ b/dom/bluetooth/BluetoothAdapter.cpp @@ -346,6 +346,15 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData) e->InitBluetoothStatusChangedEvent(aData.name(), false, false, address, status); DispatchTrustedEvent(event); + } else if (aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) { + nsCOMPtr event; + nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); + NS_ENSURE_SUCCESS_VOID(rv); + + rv = event->InitEvent(aData.name(), false, false); + NS_ENSURE_SUCCESS_VOID(rv); + + DispatchTrustedEvent(event); } else { #ifdef DEBUG nsCString warningMsg; diff --git a/dom/bluetooth/BluetoothAdapter.h b/dom/bluetooth/BluetoothAdapter.h index 6cbae3096014..48a58c435a0a 100644 --- a/dom/bluetooth/BluetoothAdapter.h +++ b/dom/bluetooth/BluetoothAdapter.h @@ -144,6 +144,7 @@ public: IMPL_EVENT_HANDLER(a2dpstatuschanged); IMPL_EVENT_HANDLER(hfpstatuschanged); IMPL_EVENT_HANDLER(pairedstatuschanged); + IMPL_EVENT_HANDLER(requestmediaplaystatus); IMPL_EVENT_HANDLER(scostatuschanged); nsPIDOMWindow* GetParentObject() const diff --git a/dom/bluetooth/BluetoothCommon.h b/dom/bluetooth/BluetoothCommon.h index 0fd4100dfc40..02cfc4d115b6 100644 --- a/dom/bluetooth/BluetoothCommon.h +++ b/dom/bluetooth/BluetoothCommon.h @@ -62,18 +62,24 @@ extern bool gBluetoothDebugFlag; /** * When the connection status of a Bluetooth profile is changed, we'll - * distribute one of the following events. + * dispatch one of the following events. */ #define A2DP_STATUS_CHANGED_ID "a2dpstatuschanged" #define HFP_STATUS_CHANGED_ID "hfpstatuschanged" #define SCO_STATUS_CHANGED_ID "scostatuschanged" /** - * When the pair status of a Bluetooth device is changed, we'll distribute an + * When the pair status of a Bluetooth device is changed, we'll dispatch an * event. */ #define PAIRED_STATUS_CHANGED_ID "pairedstatuschanged" +/** + * When receiving a query about current play status from remote device, we'll + * dispatch an event. + */ +#define REQUEST_MEDIA_PLAYSTATUS_ID "requestmediaplaystatus" + // Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx) #define BLUETOOTH_ADDRESS_LENGTH 17 #define BLUETOOTH_ADDRESS_NONE "00:00:00:00:00:00" diff --git a/dom/bluetooth/linux/BluetoothDBusService.cpp b/dom/bluetooth/linux/BluetoothDBusService.cpp index 5f38bd6baff5..75044c0363e7 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.cpp +++ b/dom/bluetooth/linux/BluetoothDBusService.cpp @@ -1298,10 +1298,10 @@ private: nsString mAdapterPath; }; -class SendPlayStatusTask : public nsRunnable +class RequestPlayStatusTask : public nsRunnable { public: - SendPlayStatusTask() + RequestPlayStatusTask() { MOZ_ASSERT(!NS_IsMainThread()); } @@ -1310,15 +1310,14 @@ public: { MOZ_ASSERT(NS_IsMainThread()); - BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get(); - NS_ENSURE_TRUE(a2dp, NS_ERROR_FAILURE); + BluetoothSignal signal(NS_LITERAL_STRING(REQUEST_MEDIA_PLAYSTATUS_ID), + NS_LITERAL_STRING(KEY_ADAPTER), + InfallibleTArray()); BluetoothService* bs = BluetoothService::Get(); NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE); + bs->DistributeSignal(signal); - bs->UpdatePlayStatus(a2dp->GetDuration(), - a2dp->GetPosition(), - a2dp->GetPlayStatus()); return NS_OK; } }; @@ -1533,7 +1532,7 @@ EventFilter(DBusConnection* aConn, DBusMessage* aMsg, void* aData) sSinkProperties, ArrayLength(sSinkProperties)); } else if (dbus_message_is_signal(aMsg, DBUS_CTL_IFACE, "GetPlayStatus")) { - NS_DispatchToMainThread(new SendPlayStatusTask()); + NS_DispatchToMainThread(new RequestPlayStatusTask()); return DBUS_HANDLER_RESULT_HANDLED; } else if (dbus_message_is_signal(aMsg, DBUS_CTL_IFACE, "PropertyChanged")) { ParsePropertyChange(aMsg, diff --git a/dom/webidl/BluetoothAdapter.webidl b/dom/webidl/BluetoothAdapter.webidl index 0db789f52267..3c98d08a4449 100644 --- a/dom/webidl/BluetoothAdapter.webidl +++ b/dom/webidl/BluetoothAdapter.webidl @@ -67,6 +67,10 @@ interface BluetoothAdapter : EventTarget { [SetterThrows] attribute EventHandler onscostatuschanged; + // Fired when remote devices query current media play status + [SetterThrows] + attribute EventHandler onrequestmediaplaystatus; + [Creator, Throws] DOMRequest setName(DOMString name); [Creator, Throws]