Bug 809106 - [music] Unplugging headphones while playing music should pause it. Part2-AudioChannelManager implemenentation. r=jlebar, r=sicking

This commit is contained in:
Steven Lee 2012-11-29 17:52:03 -05:00
Родитель 1defdd0e1c
Коммит c4ba48ecb6
11 изменённых файлов: 232 добавлений и 0 удалений

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

@ -45,6 +45,8 @@ MOZ_EXTENSION_MANAGER=1
MOZ_SYS_MSG=1
MOZ_TIME_MANAGER=1
MOZ_AUDIO_CHANNEL_MANAGER=1
MOZ_PAY=1
MOZ_TOOLKIT_SEARCH=
MOZ_PLACES=

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

@ -4263,6 +4263,7 @@ ACCESSIBILITY=1
MOZ_SYS_MSG=
MOZ_TIME_MANAGER=
MOZ_PAY=
MOZ_AUDIO_CHANNEL_MANAGER=
case "$target_os" in
mingw*)
@ -7451,6 +7452,14 @@ if test -n "$MOZ_PAY"; then
fi
AC_SUBST(MOZ_PAY)
dnl ========================================================
dnl = Enable Support for AudioChannelManager API
dnl ========================================================
if test -n "$MOZ_AUDIO_CHANNEL_MANAGER"; then
AC_DEFINE(MOZ_AUDIO_CHANNEL_MANAGER)
fi
AC_SUBST(MOZ_AUDIO_CHANNEL_MANAGER)
dnl ========================================================
dnl = Support for demangling undefined symbols
dnl ========================================================

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

@ -701,6 +701,7 @@ GK_ATOM(onerror, "onerror")
GK_ATOM(onfocus, "onfocus")
GK_ATOM(onget, "onget")
GK_ATOM(onhashchange, "onhashchange")
GK_ATOM(onheadphoneschange, "onheadphoneschange")
GK_ATOM(onheld, "onheld")
GK_ATOM(onholding, "onholding")
GK_ATOM(oniccinfochange, "oniccinfochange")

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

@ -59,6 +59,10 @@
#include "nsIDOMCameraManager.h"
#include "DOMCameraManager.h"
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
#include "AudioChannelManager.h"
#endif
#include "nsIDOMGlobalPropertyInitializer.h"
using namespace mozilla::dom::power;
@ -131,6 +135,9 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorSystemMessages)
#ifdef MOZ_TIME_MANAGER
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorTime)
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorAudioChannelManager)
#endif
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Navigator)
NS_INTERFACE_MAP_END
@ -210,6 +217,12 @@ Navigator::Invalidate()
}
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
if (mAudioChannelManager) {
mAudioChannelManager = nullptr;
}
#endif
uint32_t len = mDeviceStorageStores.Length();
for (uint32_t i = 0; i < len; ++i) {
mDeviceStorageStores[i]->Shutdown();
@ -1434,6 +1447,27 @@ Navigator::CheckPermission(const char* type)
return permission == nsIPermissionManager::ALLOW_ACTION;
}
//*****************************************************************************
// Navigator::nsINavigatorAudioChannelManager
//*****************************************************************************
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
NS_IMETHODIMP
Navigator::GetMozAudioChannelManager(nsIAudioChannelManager** aAudioChannelManager)
{
*aAudioChannelManager = nullptr;
if (!mAudioChannelManager) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window, NS_OK);
mAudioChannelManager = new system::AudioChannelManager();
mAudioChannelManager->Init(window);
}
NS_ADDREF(*aAudioChannelManager = mAudioChannelManager);
return NS_OK;
}
#endif
} // namespace dom
} // namespace mozilla

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

@ -15,6 +15,9 @@
#include "nsINavigatorBattery.h"
#include "nsIDOMNavigatorSms.h"
#include "nsIDOMNavigatorNetwork.h"
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
#include "nsINavigatorAudioChannelManager.h"
#endif
#ifdef MOZ_B2G_RIL
#include "nsINavigatorMobileConnection.h"
#endif
@ -79,6 +82,12 @@ namespace time {
class TimeManager;
} // namespace time
namespace system {
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
class AudioChannelManager;
#endif
} // namespace system
class Navigator : public nsIDOMNavigator
, public nsIDOMClientInformation
, public nsIDOMNavigatorDeviceStorage
@ -105,6 +114,9 @@ class Navigator : public nsIDOMNavigator
#ifdef MOZ_TIME_MANAGER
, public nsIDOMMozNavigatorTime
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
, public nsIMozNavigatorAudioChannelManager
#endif
{
public:
Navigator(nsPIDOMWindow *aInnerWindow);
@ -138,6 +150,9 @@ public:
NS_DECL_NSIDOMMOZNAVIGATORTIME
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
NS_DECL_NSIMOZNAVIGATORAUDIOCHANNELMANAGER
#endif
static void Init();
void Invalidate();
@ -185,6 +200,9 @@ private:
#endif
#ifdef MOZ_B2G_BT
nsCOMPtr<nsIDOMBluetoothManager> mBluetooth;
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
nsRefPtr<system::AudioChannelManager> mAudioChannelManager;
#endif
nsRefPtr<nsDOMCameraManager> mCameraManager;
nsCOMPtr<nsIDOMNavigatorSystemMessages> mMessagesManager;

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

@ -552,6 +552,11 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#include "mozilla/dom/HTMLCollectionBinding.h"
#include "mozilla/Likely.h"
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
#include "nsIAudioChannelManager.h"
#include "AudioChannelManager.h"
#endif
using namespace mozilla;
using namespace mozilla::dom;
@ -1696,6 +1701,11 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(DataChannel, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
NS_DEFINE_CLASSINFO_DATA(AudioChannelManager, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
#endif
};
// Objects that should be constructable through |new Name();|
@ -2488,6 +2498,9 @@ nsDOMClassInfo::Init()
#ifdef MOZ_TIME_MANAGER
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozNavigatorTime)
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
DOM_CLASSINFO_MAP_ENTRY(nsIMozNavigatorAudioChannelManager)
#endif
DOM_CLASSINFO_MAP_END
@ -4479,6 +4492,13 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
DOM_CLASSINFO_MAP_BEGIN(AudioChannelManager, nsIAudioChannelManager)
DOM_CLASSINFO_MAP_ENTRY(nsIAudioChannelManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
#endif
#ifdef DEBUG
{
uint32_t i = ArrayLength(sClassInfoData);

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

@ -529,3 +529,7 @@ DOMCI_CLASS(MozTimeManager)
#ifdef MOZ_WEBRTC
DOMCI_CLASS(DataChannel)
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
DOMCI_CLASS(AudioChannelManager)
#endif

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

@ -0,0 +1,83 @@
/* 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 "mozilla/Hal.h"
#include "mozilla/HalTypes.h"
#include "AudioChannelManager.h"
#include "nsIDOMClassInfo.h"
using namespace mozilla::hal;
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
DOMCI_DATA(AudioChannelManager, mozilla::dom::system::AudioChannelManager)
#endif
namespace mozilla {
namespace dom {
namespace system {
NS_IMPL_CYCLE_COLLECTION_CLASS(AudioChannelManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AudioChannelManager,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AudioChannelManager,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(AudioChannelManager, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(AudioChannelManager, nsDOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AudioChannelManager)
NS_INTERFACE_MAP_ENTRY(nsIAudioChannelManager)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(AudioChannelManager)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
AudioChannelManager::AudioChannelManager()
: mState(SWITCH_STATE_UNKNOWN)
{
RegisterSwitchObserver(SWITCH_HEADPHONES, this);
mState = GetCurrentSwitchState(SWITCH_HEADPHONES);
}
AudioChannelManager::~AudioChannelManager()
{
UnregisterSwitchObserver(SWITCH_HEADPHONES, this);
}
void
AudioChannelManager::Init(nsPIDOMWindow* aWindow)
{
BindToOwner(aWindow->IsOuterWindow() ?
aWindow->GetCurrentInnerWindow() : aWindow);
}
/* readonly attribute boolean headphones; */
NS_IMETHODIMP
AudioChannelManager::GetHeadphones(bool *aHeadphones)
{
*aHeadphones = mState == SWITCH_STATE_ON ? true : false;
return NS_OK;
}
NS_IMPL_EVENT_HANDLER(AudioChannelManager, headphoneschange)
void
AudioChannelManager::Notify(const SwitchEvent& aEvent)
{
if (aEvent.status() == SWITCH_STATE_ON ||
aEvent.status() == SWITCH_STATE_HEADSET ||
aEvent.status() == SWITCH_STATE_HEADPHONE) {
mState = SWITCH_STATE_ON;
} else {
mState = SWITCH_STATE_OFF;
}
DispatchTrustedEvent(NS_LITERAL_STRING("headphoneschange"));
}
} // namespace system
} // namespace dom
} // namespace mozilla

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

@ -0,0 +1,46 @@
/* 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_system_AudioChannelManager_h
#define mozilla_dom_system_AudioChannelManager_h
#include "mozilla/HalTypes.h"
#include "nsIAudioChannelManager.h"
#include "nsDOMEventTargetHelper.h"
namespace mozilla {
namespace hal {
class SwitchEvent;
typedef Observer<SwitchEvent> SwitchObserver;
} // namespace hal
namespace dom {
namespace system {
class AudioChannelManager : public nsDOMEventTargetHelper
, public nsIAudioChannelManager
, public hal::SwitchObserver
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIAUDIOCHANNELMANAGER
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
AudioChannelManager();
virtual ~AudioChannelManager();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioChannelManager,
nsDOMEventTargetHelper)
void Notify(const hal::SwitchEvent& aEvent);
void Init(nsPIDOMWindow* aWindow);
private:
hal::SwitchState mState;
};
} // namespace system
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_system_AudioChannelManager_h

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

@ -43,6 +43,7 @@ XPIDLSRCS = \
nsIVolumeStat.idl \
nsIWorkerHolder.idl \
nsIAudioChannelManager.idl \
nsINavigatorAudioChannelManager.idl \
$(NULL)
LOCAL_INCLUDES = \
@ -60,6 +61,7 @@ CPPSRCS += \
AutoMounter.cpp \
AutoMounterSetting.cpp \
GonkGPSGeolocationProvider.cpp \
AudioChannelManager.cpp \
nsVolume.cpp \
nsVolumeService.cpp \
nsVolumeStat.cpp \

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

@ -0,0 +1,13 @@
/* 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 "nsISupports.idl"
interface nsIAudioChannelManager;
[scriptable, uuid(4f94f833-6ab4-4c45-aecc-ebe0e100194c)]
interface nsIMozNavigatorAudioChannelManager : nsISupports
{
readonly attribute nsIAudioChannelManager mozAudioChannelManager;
};