dom/system/gonk/AudioChannelManager.cpp
author Andrea Marchesini <amarchesini@mozilla.com>
Fri, 08 Feb 2013 11:34:47 -0500
changeset 131213 92f93ab32aec0dc915ee206ee27825aeeb15d82a
parent 128960 e270f015e0e1e6881119675bd5b1c9be0b4720f2
child 134837 43128c241d3e0a95200703f9168d4fdf039d7ae7
permissions -rw-r--r--
Bug 838172 - Convert AudioChannelManager to WebIDL. r=peterv

/* 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"
#include "mozilla/dom/AudioChannelManagerBinding.h"

using namespace mozilla::hal;

namespace mozilla {
namespace dom {
namespace system {

AudioChannelManager::AudioChannelManager()
  : mState(SWITCH_STATE_UNKNOWN)
{
  RegisterSwitchObserver(SWITCH_HEADPHONES, this);
  mState = GetCurrentSwitchState(SWITCH_HEADPHONES);
  SetIsDOMBinding();
}

AudioChannelManager::~AudioChannelManager()
{
  UnregisterSwitchObserver(SWITCH_HEADPHONES, this);
}

void
AudioChannelManager::Init(nsPIDOMWindow* aWindow)
{
  BindToOwner(aWindow->IsOuterWindow() ?
    aWindow->GetCurrentInnerWindow() : aWindow);
}

JSObject*
AudioChannelManager::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
  return AudioChannelManagerBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}

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