Bug 842948 - Patch 6: Implement dictionaries, r=echou

This commit is contained in:
Gina Yeh 2013-07-29 17:32:35 +08:00
Родитель 088093d5d4
Коммит d62aa07a21
13 изменённых файлов: 279 добавлений и 55 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
};

Просмотреть файл

@ -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;
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();

Просмотреть файл

@ -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;

Просмотреть файл

@ -42,6 +42,8 @@ if CONFIG['MOZ_B2G_BT']:
'ObexBase.cpp',
'BluetoothUuid.cpp',
'BluetoothSocket.cpp',
'MediaMetaData.cpp',
'MediaPlayStatus.cpp'
]
if CONFIG['MOZ_B2G_RIL']:

Просмотреть файл

@ -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