diff --git a/dom/bluetooth/BluetoothAdapter.cpp b/dom/bluetooth/BluetoothAdapter.cpp index a86b28b97a91..0f685119b25b 100644 --- a/dom/bluetooth/BluetoothAdapter.cpp +++ b/dom/bluetooth/BluetoothAdapter.cpp @@ -5,19 +5,12 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "base/basictypes.h" -#include "BluetoothAdapter.h" -#include "BluetoothDevice.h" -#include "BluetoothReplyRunnable.h" -#include "BluetoothService.h" -#include "BluetoothUtils.h" #include "GeneratedEvents.h" - #include "nsContentUtils.h" #include "nsCxPusher.h" #include "nsDOMClassInfo.h" #include "nsIDOMBluetoothDeviceEvent.h" #include "nsTArrayHelpers.h" -#include "DictionaryHelpers.h" #include "DOMRequest.h" #include "nsThreadUtils.h" @@ -26,6 +19,14 @@ #include "mozilla/LazyIdleThread.h" #include "mozilla/Util.h" +#include "BluetoothAdapter.h" +#include "BluetoothDevice.h" +#include "BluetoothReplyRunnable.h" +#include "BluetoothService.h" +#include "BluetoothUtils.h" +#include "MediaMetaData.h" +#include "MediaPlayStatus.h" + using namespace mozilla; USING_BLUETOOTH_NAMESPACE @@ -838,7 +839,7 @@ NS_IMETHODIMP BluetoothAdapter::SendMediaMetaData(const JS::Value& aOptions, nsIDOMDOMRequest** aRequest) { - idl::MediaMetaData metadata; + MediaMetaData metadata; nsresult rv; nsIScriptContext* sc = GetContextForEventHandlers(&rv); @@ -857,12 +858,12 @@ BluetoothAdapter::SendMediaMetaData(const JS::Value& aOptions, BluetoothService* bs = BluetoothService::Get(); NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE); - bs->SendMetaData(metadata.title, - metadata.artist, - metadata.album, - metadata.mediaNumber, - metadata.totalMediaCount, - metadata.duration, + bs->SendMetaData(metadata.mTitle, + metadata.mArtist, + metadata.mAlbum, + metadata.mMediaNumber, + metadata.mTotalMediaCount, + metadata.mDuration, results); req.forget(aRequest); @@ -873,7 +874,7 @@ NS_IMETHODIMP BluetoothAdapter::SendMediaPlayStatus(const JS::Value& aOptions, nsIDOMDOMRequest** aRequest) { - idl::MediaPlayStatus status; + MediaPlayStatus status; nsresult rv; nsIScriptContext* sc = GetContextForEventHandlers(&rv); @@ -892,9 +893,9 @@ BluetoothAdapter::SendMediaPlayStatus(const JS::Value& aOptions, BluetoothService* bs = BluetoothService::Get(); NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE); - bs->SendPlayStatus(status.duration, - status.position, - status.playStatus, + bs->SendPlayStatus(status.mDuration, + status.mPosition, + status.mPlayStatus, results); req.forget(aRequest); diff --git a/dom/bluetooth/BluetoothService.h b/dom/bluetooth/BluetoothService.h index d9f55c50155d..715440f34278 100644 --- a/dom/bluetooth/BluetoothService.h +++ b/dom/bluetooth/BluetoothService.h @@ -274,14 +274,14 @@ public: SendMetaData(const nsAString& aTitle, const nsAString& aArtist, const nsAString& aAlbum, - uint32_t aMediaNumber, - uint32_t aTotalMediaCount, - uint32_t aDuration, + int64_t aMediaNumber, + int64_t aTotalMediaCount, + int64_t aDuration, BluetoothReplyRunnable* aRunnable) = 0; virtual void - SendPlayStatus(uint32_t aDuration, - uint32_t aPosition, + SendPlayStatus(int64_t aDuration, + int64_t aPosition, const nsAString& aPlayStatus, BluetoothReplyRunnable* aRunnable) = 0; diff --git a/dom/bluetooth/MediaMetaData.cpp b/dom/bluetooth/MediaMetaData.cpp new file mode 100644 index 000000000000..f8af9de02e7c --- /dev/null +++ b/dom/bluetooth/MediaMetaData.cpp @@ -0,0 +1,83 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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 "MediaMetaData.h" + +#include "nsCxPusher.h" +#include "nsContentUtils.h" +#include "nsJSUtils.h" +#include "nsThreadUtils.h" + +using namespace mozilla; +USING_BLUETOOTH_NAMESPACE + +MediaMetaData::MediaMetaData() : mDuration(-1) + , mMediaNumber(-1) + , mTotalMediaCount(-1) +{ +} + +nsresult +MediaMetaData::Init(JSContext* aCx, const jsval* aVal) +{ + MOZ_ASSERT(NS_IsMainThread()); + + if (!aCx || !aVal) { + return NS_OK; + } + + if (!aVal->isObject()) { + return aVal->isNullOrUndefined() ? NS_OK : NS_ERROR_TYPE_ERR; + } + + JS::RootedObject obj(aCx, &aVal->toObject()); + nsCxPusher pusher; + pusher.Push(aCx); + JSAutoCompartment ac(aCx, obj); + + JS::Value value; + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mAlbum", &value)); + if (JSVAL_IS_STRING(value)) { + nsDependentJSString jsString; + NS_ENSURE_STATE(jsString.init(aCx, value.toString())); + mAlbum = jsString; + } + + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mArtist", &value)); + if (JSVAL_IS_STRING(value)) { + nsDependentJSString jsString; + NS_ENSURE_STATE(JSVAL_IS_STRING(value)); + NS_ENSURE_STATE(jsString.init(aCx, value.toString())); + mArtist = jsString; + } + + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mDuration", &value)); + if (JSVAL_IS_INT(value)) { + NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mDuration)); + } + + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mMediaNumber", &value)); + if (JSVAL_IS_INT(value)) { + NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mMediaNumber)); + } + + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mTitle", &value)); + if (JSVAL_IS_STRING(value)) { + nsDependentJSString jsString; + NS_ENSURE_STATE(JSVAL_IS_STRING(value)); + NS_ENSURE_STATE(jsString.init(aCx, value.toString())); + mTitle = jsString; + } + + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mTotalMediaCount", &value)); + if (JSVAL_IS_INT(value)) { + NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mTotalMediaCount)); + } + + return NS_OK; +} + diff --git a/dom/bluetooth/MediaMetaData.h b/dom/bluetooth/MediaMetaData.h new file mode 100644 index 000000000000..b59c11cb3282 --- /dev/null +++ b/dom/bluetooth/MediaMetaData.h @@ -0,0 +1,32 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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_mediametadata_h__ +#define mozilla_dom_bluetooth_mediametadata_h__ + +#include "jsapi.h" +#include "nsString.h" + +BEGIN_BLUETOOTH_NAMESPACE + +class MediaMetaData +{ +public: + MediaMetaData(); + + nsresult Init(JSContext* aCx, const jsval* aVal); + + nsString mAlbum; + nsString mArtist; + int64_t mDuration; + int64_t mMediaNumber; + nsString mTitle; + int64_t mTotalMediaCount; +}; + +END_BLUETOOTH_NAMESPACE + +#endif diff --git a/dom/bluetooth/MediaPlayStatus.cpp b/dom/bluetooth/MediaPlayStatus.cpp new file mode 100644 index 000000000000..9adbda906c3f --- /dev/null +++ b/dom/bluetooth/MediaPlayStatus.cpp @@ -0,0 +1,62 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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 "MediaPlayStatus.h" + +#include "nsContentUtils.h" +#include "nsCxPusher.h" +#include "nsJSUtils.h" +#include "nsThreadUtils.h" + +using namespace mozilla; +USING_BLUETOOTH_NAMESPACE + +MediaPlayStatus::MediaPlayStatus() : mDuration(-1) + , mPosition(-1) +{ +} + +nsresult +MediaPlayStatus::Init(JSContext* aCx, const jsval* aVal) +{ + MOZ_ASSERT(NS_IsMainThread()); + + if (!aCx || !aVal) { + return NS_OK; + } + + if (!aVal->isObject()) { + return aVal->isNullOrUndefined() ? NS_OK : NS_ERROR_TYPE_ERR; + } + + JS::RootedObject obj(aCx, &aVal->toObject()); + nsCxPusher pusher; + pusher.Push(aCx); + JSAutoCompartment ac(aCx, obj); + + JS::Value value; + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mDuration", &value)); + if (JSVAL_IS_INT(value)) { + NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mDuration)); + } + + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mPlayStatus", &value)); + if (JSVAL_IS_STRING(value)) { + nsDependentJSString jsString; + NS_ENSURE_STATE(JSVAL_IS_STRING(value)); + NS_ENSURE_STATE(jsString.init(aCx, value.toString())); + mPlayStatus = jsString; + } + + NS_ENSURE_STATE(JS_GetProperty(aCx, obj, "mPosition", &value)); + if (JSVAL_IS_INT(value)) { + NS_ENSURE_STATE(JS_ValueToInt64(aCx, value, &mPosition)); + } + + return NS_OK; +} + diff --git a/dom/bluetooth/MediaPlayStatus.h b/dom/bluetooth/MediaPlayStatus.h new file mode 100644 index 000000000000..c66870a37f0f --- /dev/null +++ b/dom/bluetooth/MediaPlayStatus.h @@ -0,0 +1,29 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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_mediaplaystatus_h__ +#define mozilla_dom_bluetooth_mediaplaystatus_h__ + +#include "jsapi.h" +#include "nsString.h" + +BEGIN_BLUETOOTH_NAMESPACE + +class MediaPlayStatus +{ +public: + MediaPlayStatus(); + + nsresult Init(JSContext* aCx, const jsval* aVal); + + int64_t mDuration; + nsString mPlayStatus; + int64_t mPosition; +}; + +END_BLUETOOTH_NAMESPACE + +#endif diff --git a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp index a61afd884f37..9184e84dc86d 100644 --- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp +++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp @@ -343,9 +343,9 @@ void BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle, const nsAString& aArtist, const nsAString& aAlbum, - uint32_t aMediaNumber, - uint32_t aTotalMediaCount, - uint32_t aDuration, + int64_t aMediaNumber, + int64_t aTotalMediaCount, + int64_t aDuration, BluetoothReplyRunnable* aRunnable) { SendRequest(aRunnable, @@ -355,8 +355,8 @@ BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle, } void -BluetoothServiceChildProcess::SendPlayStatus(uint32_t aDuration, - uint32_t aPosition, +BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration, + int64_t aPosition, const nsAString& aPlayStatus, BluetoothReplyRunnable* aRunnable) { diff --git a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h index e3936a9c8d06..e8af2460feda 100644 --- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h +++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h @@ -156,14 +156,14 @@ public: SendMetaData(const nsAString& aTitle, const nsAString& aArtist, const nsAString& aAlbum, - uint32_t aMediaNumber, - uint32_t aTotalMediaCount, - uint32_t aDuration, + int64_t aMediaNumber, + int64_t aTotalMediaCount, + int64_t aDuration, BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE; virtual void - SendPlayStatus(uint32_t aDuration, - uint32_t aPosition, + SendPlayStatus(int64_t aDuration, + int64_t aPosition, const nsAString& aPlayStatus, BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE; diff --git a/dom/bluetooth/ipc/PBluetooth.ipdl b/dom/bluetooth/ipc/PBluetooth.ipdl index ecf8bd506ef1..eb81f88a9716 100644 --- a/dom/bluetooth/ipc/PBluetooth.ipdl +++ b/dom/bluetooth/ipc/PBluetooth.ipdl @@ -146,15 +146,15 @@ struct SendMetaDataRequest nsString title; nsString artist; nsString album; - uint32_t mediaNumber; - uint32_t totalMediaCount; - uint32_t duration; + int64_t mediaNumber; + int64_t totalMediaCount; + int64_t duration; }; struct SendPlayStatusRequest { - uint32_t duration; - uint32_t position; + int64_t duration; + int64_t position; nsString playStatus; }; diff --git a/dom/bluetooth/linux/BluetoothDBusService.cpp b/dom/bluetooth/linux/BluetoothDBusService.cpp index ed1668339326..0d2926688408 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.cpp +++ b/dom/bluetooth/linux/BluetoothDBusService.cpp @@ -2882,9 +2882,9 @@ void BluetoothDBusService::SendMetaData(const nsAString& aTitle, const nsAString& aArtist, const nsAString& aAlbum, - uint32_t aMediaNumber, - uint32_t aTotalMediaCount, - uint32_t aDuration, + int64_t aMediaNumber, + int64_t aTotalMediaCount, + int64_t aDuration, BluetoothReplyRunnable* aRunnable) { MOZ_ASSERT(NS_IsMainThread()); @@ -2916,10 +2916,19 @@ BluetoothDBusService::SendMetaData(const nsAString& aTitle, nsCString tempTitle = NS_ConvertUTF16toUTF8(aTitle); nsCString tempArtist = NS_ConvertUTF16toUTF8(aArtist); nsCString tempAlbum = NS_ConvertUTF16toUTF8(aAlbum); - nsCString tempMediaNumber, tempTotalMediaCount, tempDuration; - tempMediaNumber.AppendInt(aMediaNumber); - tempTotalMediaCount.AppendInt(aTotalMediaCount); - tempDuration.AppendInt(aDuration); + + nsCString tempMediaNumber = EmptyCString(); + nsCString tempTotalMediaCount = EmptyCString(); + nsCString tempDuration = EmptyCString(); + if (aMediaNumber >= 0) { + tempMediaNumber.AppendInt(aMediaNumber); + } + if (aTotalMediaCount >= 0) { + tempTotalMediaCount.AppendInt(aTotalMediaCount); + } + if (aDuration >= 0) { + tempDuration.AppendInt(aDuration); + } const char* title = tempTitle.get(); const char* album = tempAlbum.get(); @@ -2984,8 +2993,8 @@ PlayStatusStringToControlPlayStatus(const nsAString& aPlayStatus) } void -BluetoothDBusService::SendPlayStatus(uint32_t aDuration, - uint32_t aPosition, +BluetoothDBusService::SendPlayStatus(int64_t aDuration, + int64_t aPosition, const nsAString& aPlayStatus, BluetoothReplyRunnable* aRunnable) { @@ -3003,6 +3012,14 @@ BluetoothDBusService::SendPlayStatus(uint32_t aDuration, DispatchBluetoothReply(aRunnable, BluetoothValue(), NS_LITERAL_STRING("Invalid play status")); return; + } else if (aDuration < 0) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING("Invalid duration")); + return; + } else if (aPosition < 0) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING("Invalid position")); + return; } BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get(); diff --git a/dom/bluetooth/linux/BluetoothDBusService.h b/dom/bluetooth/linux/BluetoothDBusService.h index b5853f66cd0a..5da45ecc60b3 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.h +++ b/dom/bluetooth/linux/BluetoothDBusService.h @@ -142,14 +142,14 @@ public: SendMetaData(const nsAString& aTitle, const nsAString& aArtist, const nsAString& aAlbum, - uint32_t aMediaNumber, - uint32_t aTotalMediaCount, - uint32_t aDuration, + int64_t aMediaNumber, + int64_t aTotalMediaCount, + int64_t aDuration, BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE; virtual void - SendPlayStatus(uint32_t aDuration, - uint32_t aPosition, + SendPlayStatus(int64_t aDuration, + int64_t aPosition, const nsAString& aPlayStatus, BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE; diff --git a/dom/bluetooth/moz.build b/dom/bluetooth/moz.build index 7a6c3ea5176c..20cb4cab26d4 100644 --- a/dom/bluetooth/moz.build +++ b/dom/bluetooth/moz.build @@ -42,6 +42,8 @@ if CONFIG['MOZ_B2G_BT']: 'ObexBase.cpp', 'BluetoothUuid.cpp', 'BluetoothSocket.cpp', + 'MediaMetaData.cpp', + 'MediaPlayStatus.cpp' ] if CONFIG['MOZ_B2G_RIL']: diff --git a/js/xpconnect/src/dictionary_helper_gen.conf b/js/xpconnect/src/dictionary_helper_gen.conf index 243705fdde15..fefb520e9393 100644 --- a/js/xpconnect/src/dictionary_helper_gen.conf +++ b/js/xpconnect/src/dictionary_helper_gen.conf @@ -13,9 +13,7 @@ dictionaries = [ [ 'CameraSelector', 'nsIDOMCameraManager.idl' ], [ 'CameraRecordingOptions', 'nsIDOMCameraManager.idl' ], [ 'SmsThreadListItem', 'nsIMobileMessageCallback.idl' ], - [ 'MmsAttachment', 'nsIDOMMozMmsMessage.idl' ], - [ 'MediaMetaData', 'nsIDOMBluetoothAdapter.idl'], - [ 'MediaPlayStatus', 'nsIDOMBluetoothAdapter.idl'] + [ 'MmsAttachment', 'nsIDOMMozMmsMessage.idl' ] ] # include file names