Bug 910974 - Patch 1: Dispatch events when remote device queries current play status, r=echou, sr=mrbkap
authorGina Yeh <gyeh@mozilla.com>
Wed, 04 Sep 2013 10:40:01 +0800
changeset 153365 97fff387fda98d4054575250ef18fe2010905871
parent 153364 3ec404b808b22d091431f7a8aa26ae5d997dd6e0
child 153366 437a36f4be9252dc453f4219cfde9f99b592250b
push idunknown
push userunknown
push dateunknown
reviewersechou, mrbkap
bugs910974
milestone26.0a1
Bug 910974 - Patch 1: Dispatch events when remote device queries current play status, r=echou, sr=mrbkap
content/base/src/nsGkAtomList.h
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothAdapter.h
dom/bluetooth/BluetoothCommon.h
dom/bluetooth/linux/BluetoothDBusService.cpp
dom/webidl/BluetoothAdapter.webidl
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -768,16 +768,17 @@ GK_ATOM(onpopuphiding, "onpopuphiding")
 GK_ATOM(onpopupshowing, "onpopupshowing")
 GK_ATOM(onpopupshown, "onpopupshown")
 GK_ATOM(onreadystatechange, "onreadystatechange")
 GK_ATOM(onreceived, "onreceived")
 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")
 GK_ATOM(onresize, "onresize")
 GK_ATOM(onscostatuschanged, "onscostatuschanged")
 GK_ATOM(onscroll, "onscroll")
 GK_ATOM(onselect, "onselect")
 GK_ATOM(onsending, "onsending")
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -341,16 +341,25 @@ BluetoothAdapter::Notify(const Bluetooth
     nsCOMPtr<nsIDOMEvent> event;
     NS_NewDOMBluetoothStatusChangedEvent(
       getter_AddRefs(event), this, nullptr, nullptr);
 
     nsCOMPtr<nsIDOMBluetoothStatusChangedEvent> e = do_QueryInterface(event);
     e->InitBluetoothStatusChangedEvent(aData.name(), false, false,
                                        address, status);
     DispatchTrustedEvent(event);
+  } else if (aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) {
+    nsCOMPtr<nsIDOMEvent> 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;
     warningMsg.AssignLiteral("Not handling adapter signal: ");
     warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
     NS_WARNING(warningMsg.get());
 #endif
   }
--- a/dom/bluetooth/BluetoothAdapter.h
+++ b/dom/bluetooth/BluetoothAdapter.h
@@ -139,16 +139,17 @@ public:
     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(requestmediaplaystatus);
   IMPL_EVENT_HANDLER(scostatuschanged);
 
   nsPIDOMWindow* GetParentObject() const
   {
      return GetOwner();
   }
 
   virtual JSObject*
--- a/dom/bluetooth/BluetoothCommon.h
+++ b/dom/bluetooth/BluetoothCommon.h
@@ -57,28 +57,34 @@ extern bool gBluetoothDebugFlag;
  */
 #define BLUETOOTH_A2DP_STATUS_CHANGED_ID "bluetooth-a2dp-status-changed"
 #define BLUETOOTH_HFP_STATUS_CHANGED_ID  "bluetooth-hfp-status-changed"
 #define BLUETOOTH_HID_STATUS_CHANGED_ID  "bluetooth-hid-status-changed"
 #define BLUETOOTH_SCO_STATUS_CHANGED_ID  "bluetooth-sco-status-changed"
 
 /**
  * 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"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 enum BluetoothSocketType {
   RFCOMM = 1,
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -1293,37 +1293,36 @@ public:
 
     return NS_OK;
   }
 
 private:
   nsString mAdapterPath;
 };
 
-class SendPlayStatusTask : public nsRunnable
+class RequestPlayStatusTask : public nsRunnable
 {
 public:
-  SendPlayStatusTask()
+  RequestPlayStatusTask()
   {
     MOZ_ASSERT(!NS_IsMainThread());
   }
 
   nsresult Run()
   {
     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<BluetoothNamedValue>());
 
     BluetoothService* bs = BluetoothService::Get();
     NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-
-    bs->UpdatePlayStatus(a2dp->GetDuration(),
-                         a2dp->GetPosition(),
-                         a2dp->GetPlayStatus());
+    bs->DistributeSignal(signal);
+
     return NS_OK;
   }
 };
 
 // Called by dbus during WaitForAndDispatchEventNative()
 // This function is called on the IOThread
 static DBusHandlerResult
 EventFilter(DBusConnection* aConn, DBusMessage* aMsg, void* aData)
@@ -1528,17 +1527,17 @@ EventFilter(DBusConnection* aConn, DBusM
   } else if (dbus_message_is_signal(aMsg, DBUS_SINK_IFACE,
                                     "PropertyChanged")) {
     ParsePropertyChange(aMsg,
                         v,
                         errorStr,
                         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,
                         v,
                         errorStr,
                         sControlProperties,
                         ArrayLength(sControlProperties));
   } else if (dbus_message_is_signal(aMsg, DBUS_INPUT_IFACE,
--- a/dom/webidl/BluetoothAdapter.webidl
+++ b/dom/webidl/BluetoothAdapter.webidl
@@ -62,16 +62,20 @@ interface BluetoothAdapter : EventTarget
   // Fired when handsfree connection status changed
   [SetterThrows]
            attribute EventHandler   onhfpstatuschanged;
 
   // Fired when sco connection status changed
   [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]
   DOMRequest setDiscoverable(boolean discoverable);
   [Creator, Throws]
   DOMRequest setDiscoverableTimeout(unsigned long timeout);
   [Creator, Throws]
   DOMRequest startDiscovery();