2012-11-29 22:52:03 +00:00
|
|
|
/* 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 "AudioChannelManager.h"
|
|
|
|
#include "nsIDOMClassInfo.h"
|
2013-02-08 16:34:47 +00:00
|
|
|
#include "mozilla/dom/AudioChannelManagerBinding.h"
|
2012-11-29 22:52:03 +00:00
|
|
|
|
|
|
|
using namespace mozilla::hal;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace system {
|
|
|
|
|
|
|
|
AudioChannelManager::AudioChannelManager()
|
|
|
|
: mState(SWITCH_STATE_UNKNOWN)
|
|
|
|
{
|
|
|
|
RegisterSwitchObserver(SWITCH_HEADPHONES, this);
|
|
|
|
mState = GetCurrentSwitchState(SWITCH_HEADPHONES);
|
2013-02-08 16:34:47 +00:00
|
|
|
SetIsDOMBinding();
|
2012-11-29 22:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioChannelManager::~AudioChannelManager()
|
|
|
|
{
|
|
|
|
UnregisterSwitchObserver(SWITCH_HEADPHONES, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioChannelManager::Init(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
BindToOwner(aWindow->IsOuterWindow() ?
|
|
|
|
aWindow->GetCurrentInnerWindow() : aWindow);
|
|
|
|
}
|
|
|
|
|
2013-02-08 16:34:47 +00:00
|
|
|
JSObject*
|
|
|
|
AudioChannelManager::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
|
2012-11-29 22:52:03 +00:00
|
|
|
{
|
2013-02-08 16:34:47 +00:00
|
|
|
return AudioChannelManagerBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
2012-11-29 22:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|