Bug 838172 - Convert AudioChannelManager to WebIDL. r=peterv
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 08 Feb 2013 11:34:47 -0500
changeset 131213 92f93ab32aec0dc915ee206ee27825aeeb15d82a
parent 131212 272789a888359ef27d625e15162d159b666452fd
child 131214 afeaf8f42c099a9a747d0133bbf27b997c2072b9
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs838172
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 838172 - Convert AudioChannelManager to WebIDL. r=peterv
dom/base/Navigator.cpp
dom/base/nsDOMClassInfo.cpp
dom/bindings/Bindings.conf
dom/bindings/Makefile.in
dom/system/gonk/AudioChannelManager.cpp
dom/system/gonk/AudioChannelManager.h
dom/system/gonk/Makefile.in
dom/system/gonk/nsIAudioChannelManager.idl
dom/system/gonk/nsINavigatorAudioChannelManager.idl
dom/webidl/AudioChannelManager.webidl
dom/webidl/WebIDL.mk
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1511,17 +1511,17 @@ Navigator::CheckPermission(const char* t
   return permission == nsIPermissionManager::ALLOW_ACTION;
 }
 
 //*****************************************************************************
 //    Navigator::nsINavigatorAudioChannelManager
 //*****************************************************************************
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
 NS_IMETHODIMP
-Navigator::GetMozAudioChannelManager(nsIAudioChannelManager** aAudioChannelManager)
+Navigator::GetMozAudioChannelManager(nsISupports** aAudioChannelManager)
 {
   *aAudioChannelManager = nullptr;
 
   if (!mAudioChannelManager) {
     nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
     NS_ENSURE_TRUE(window, NS_OK);
     mAudioChannelManager = new system::AudioChannelManager();
     mAudioChannelManager->Init(window);
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -475,21 +475,16 @@ using mozilla::dom::workers::ResolveWork
 #ifdef MOZ_TIME_MANAGER
 #include "TimeManager.h"
 #endif
 
 #ifdef MOZ_WEBRTC
 #include "nsIDOMDataChannel.h"
 #endif
 
-#ifdef MOZ_AUDIO_CHANNEL_MANAGER
-#include "nsIAudioChannelManager.h"
-#include "AudioChannelManager.h"
-#endif
-
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
 
 static const char kDOMStringBundleURL[] =
   "chrome://global/locale/dom/dom.properties";
 
@@ -1451,21 +1446,16 @@ static nsDOMClassInfoData sClassInfoData
   NS_DEFINE_CLASSINFO_DATA(MozTimeManager, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 #endif
 
 #ifdef MOZ_WEBRTC
   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
 };
 
 #define NS_DEFINE_CONTRACT_CTOR(_class, _contract_id)                           \
   static nsresult                                                               \
   _class##Ctor(nsISupports** aInstancePtrResult)                                \
   {                                                                             \
     nsresult rv = NS_OK;                                                        \
     nsCOMPtr<nsISupports> native = do_CreateInstance(_contract_id, &rv);        \
@@ -3723,23 +3713,16 @@ nsDOMClassInfo::Init()
 
 #ifdef MOZ_WEBRTC
   DOM_CLASSINFO_MAP_BEGIN(DataChannel, nsIDOMDataChannel)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMDataChannel)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
   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);
 
     if (i != eDOMClassInfoIDCount) {
       MOZ_NOT_REACHED("The number of items in sClassInfoData doesn't match the "
                       "number of nsIDOMClassInfo ID's, this is bad! Fix it!");
 
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -86,16 +86,21 @@
 #
 # A descriptor can also have 'skipGen': True specified if it should be skipped
 # when deciding what header includes to generate and should never have an
 # implementation generated for it.  This is only needed in special cases like
 # worker descriptors for objects that will never actually appear in workers.
 
 DOMInterfaces = {
 
+'AudioChannelManager': {
+    'nativeType': 'mozilla::dom::system::AudioChannelManager',
+    'headerFile': 'AudioChannelManager.h'
+},
+
 'AudioContext': {
     'implicitJSContext': [ 'createBuffer' ],
     'nativeOwnership': 'refcounted',
     'resultNotAddRefed': [ 'destination', 'listener' ],
 },
 
 'AudioBufferSourceNode': {
     'implicitJSContext': [ 'start' ],
--- a/dom/bindings/Makefile.in
+++ b/dom/bindings/Makefile.in
@@ -86,16 +86,22 @@ LOCAL_INCLUDES += -I$(topsrcdir)/js/xpco
   -I$(topsrcdir)/dom/base \
   -I$(topsrcdir)/dom/battery \
   -I$(topsrcdir)/content/xslt/src/base \
   -I$(topsrcdir)/content/xslt/src/xpath \
   -I$(topsrcdir)/content/xml/content/src \
   -I$(topsrcdir)/content/xul/content/src \
   $(NULL)
 
+ifdef MOZ_AUDIO_CHANNEL_MANAGER
+LOCAL_INCLUDES += \
+  -I$(topsrcdir)/dom/system/gonk \
+  $(NULL)
+endif
+
 include $(topsrcdir)/config/rules.mk
 
 # If you change bindinggen_dependencies here, change it in
 # dom/bindings/test/Makefile.in too.
 bindinggen_dependencies := \
   BindingGen.py \
   Bindings.conf \
   Configuration.py \
--- a/dom/system/gonk/AudioChannelManager.cpp
+++ b/dom/system/gonk/AudioChannelManager.cpp
@@ -1,72 +1,48 @@
 /* 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"
+#include "mozilla/dom/AudioChannelManagerBinding.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_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);
+  SetIsDOMBinding();
 }
 
 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)
+JSObject*
+AudioChannelManager::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
 {
-  *aHeadphones = mState == SWITCH_STATE_ON ? true : false;
-  return NS_OK;
+  return AudioChannelManagerBinding::Wrap(aCx, aScope, this, aTriedToWrap);
 }
 
-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 {
--- a/dom/system/gonk/AudioChannelManager.h
+++ b/dom/system/gonk/AudioChannelManager.h
@@ -1,45 +1,58 @@
 /* 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/Hal.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);
+
+  /**
+   * WebIDL Interface
+   */
+
+  nsPIDOMWindow* GetParentObject() const
+  {
+     return GetOwner();
+  }
+
+  virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
+                               bool* aTriedToWrap);
+
+  bool Headphones() const
+  {
+    return mState == hal::SWITCH_STATE_ON;
+  }
+
+  IMPL_EVENT_HANDLER(headphoneschange)
+
 private:
   hal::SwitchState mState;
 };
 
 } // namespace system
 } // namespace dom
 } // namespace mozilla
 
--- a/dom/system/gonk/Makefile.in
+++ b/dom/system/gonk/Makefile.in
@@ -38,17 +38,16 @@ XPIDLSRCS = \
   nsIAudioManager.idl \
   nsINetworkManager.idl \
   nsIRadioInterfaceLayer.idl \
   nsIVolume.idl \
   nsIVolumeMountLock.idl \
   nsIVolumeService.idl \
   nsIVolumeStat.idl \
   nsIWorkerHolder.idl \
-  nsIAudioChannelManager.idl \
   nsINavigatorAudioChannelManager.idl \
   nsISystemWorkerManager.idl \
   $(NULL)
 
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/dom/base \
   -I$(topsrcdir)/dom/src/geolocation \
   -I$(topsrcdir)/dom/telephony \
deleted file mode 100644
--- a/dom/system/gonk/nsIAudioChannelManager.idl
+++ /dev/null
@@ -1,27 +0,0 @@
-/* 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 "nsIDOMEventTarget.idl"
-
-[scriptable, builtinclass, uuid(06a6893d-1c0d-4ad7-93fd-bc479b44d55b)]
-interface nsIAudioChannelManager : nsIDOMEventTarget {
-  /**
-   * Indicates whether the headphones are plugged in or not.
-   */
-  readonly attribute boolean headphones;
-
-  /**
-   * Fired when the headphones are plugged or unplugged.
-   *
-   * When the headphones are unplugged, we may start playing audio through the
-   * system's speakers.  Similarly, when headphones are plugged in, we may
-   * switch audio from speakers to headphones.
-   *
-   * If audio is currently playing in this window or in one of its children, we
-   * will fire this event before we switch the audio output from headphones to
-   * speakers (or vice versa).  This allows you to, for example, pause your
-   * window's audio when the headphones are unplugged.
-   */
-  [implicit_jscontext] attribute jsval onheadphoneschange;
-};
--- a/dom/system/gonk/nsINavigatorAudioChannelManager.idl
+++ b/dom/system/gonk/nsINavigatorAudioChannelManager.idl
@@ -1,13 +1,11 @@
 /* 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)]
+[scriptable, uuid(5d5e6687-2eb0-4992-98c7-ec79eab9e0b1)]
 interface nsIMozNavigatorAudioChannelManager : nsISupports
 {
-  readonly attribute nsIAudioChannelManager mozAudioChannelManager;
+  readonly attribute nsISupports mozAudioChannelManager;
 };
new file mode 100644
--- /dev/null
+++ b/dom/webidl/AudioChannelManager.webidl
@@ -0,0 +1,27 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/.
+ */
+
+interface AudioChannelManager : EventTarget {
+  /**
+   * Indicates whether the headphones are plugged in or not.
+   */
+  readonly attribute boolean headphones;
+
+  /**
+   * Fired when the headphones are plugged or unplugged.
+   *
+   * When the headphones are unplugged, we may start playing audio through the
+   * system's speakers.  Similarly, when headphones are plugged in, we may
+   * switch audio from speakers to headphones.
+   *
+   * If audio is currently playing in this window or in one of its children, we
+   * will fire this event before we switch the audio output from headphones to
+   * speakers (or vice versa).  This allows you to, for example, pause your
+   * window's audio when the headphones are unplugged.
+   */
+  [SetterThrows]
+  attribute EventHandler onheadphoneschange;
+};
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -199,16 +199,22 @@ webidl_files = \
   XMLHttpRequestEventTarget.webidl \
   XMLHttpRequestUpload.webidl \
   XMLSerializer.webidl \
   XMLStylesheetProcessingInstruction.webidl \
   XPathEvaluator.webidl \
   XULElement.webidl \
   $(NULL)
 
+ifdef MOZ_AUDIO_CHANNEL_MANAGER
+webidl_files += \
+  AudioChannelManager.webidl \
+  $(NULL)
+endif
+
 ifdef MOZ_MEDIA
 webidl_files += \
   HTMLSourceElement.webidl \
   $(NULL)
 endif
 
 ifdef MOZ_WEBGL
 webidl_files += \