Backed out changeset 50896498013c (bug 1242874)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 28 Apr 2016 13:59:06 +0200
changeset 357365 3851fea9fc4b2a25b116b7825b78024124df4180
parent 357364 977dedde75b1f7cecdaddc44cba167aa2b09c354
child 357366 426e559fd65614c145603572474f9f6f0d70fa4a
push id16755
push useryura.zenevich@gmail.com
push dateThu, 28 Apr 2016 15:12:20 +0000
bugs1242874
milestone49.0a1
backs out50896498013c2500ab0176e2219b7fcf096435aa
Backed out changeset 50896498013c (bug 1242874)
dom/base/nsDOMWindowUtils.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsPIDOMWindow.h
dom/interfaces/base/nsIDOMWindowUtils.idl
mobile/android/base/java/org/mozilla/gecko/media/AudioFocusAgent.java
mobile/android/installer/package-manifest.in
toolkit/content/browser-content.js
toolkit/content/widgets/browser.xml
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3672,32 +3672,32 @@ nsDOMWindowUtils::PostRestyleSelfEvent(n
     return NS_ERROR_INVALID_ARG;
   }
 
   nsLayoutUtils::PostRestyleEvent(element, eRestyle_Self, nsChangeHint(0));
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMWindowUtils::GetMediaSuspend(uint32_t* aSuspend)
+nsDOMWindowUtils::GetMediaSuspended(bool* aSuspended)
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
   NS_ENSURE_STATE(window);
 
-  *aSuspend = window->GetMediaSuspend();
+  *aSuspended = window->GetMediaSuspended();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMWindowUtils::SetMediaSuspend(uint32_t aSuspend)
+nsDOMWindowUtils::SetMediaSuspended(bool aSuspended)
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
   NS_ENSURE_STATE(window);
 
-  window->SetMediaSuspend(aSuspend);
+  window->SetMediaSuspended(aSuspended);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetAudioMuted(bool* aMuted)
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
   NS_ENSURE_STATE(window);
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -609,18 +609,17 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMW
 : mFrameElement(nullptr), mDocShell(nullptr), mModalStateDepth(0),
   mRunningTimeout(nullptr), mMutationBits(0), mIsDocumentLoaded(false),
   mIsHandlingResizeEvent(false), mIsInnerWindow(aOuterWindow != nullptr),
   mMayHavePaintEventListener(false), mMayHaveTouchEventListener(false),
   mMayHaveMouseEnterLeaveEventListener(false),
   mMayHavePointerEnterLeaveEventListener(false),
   mInnerObjectsFreed(false),
   mIsModalContentWindow(false),
-  mIsActive(false), mIsBackground(false),
-  mMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED),
+  mIsActive(false), mIsBackground(false), mMediaSuspended(false),
   mAudioMuted(false), mAudioVolume(1.0), mAudioCaptured(false),
   mDesktopModeViewport(false), mInnerWindow(nullptr),
   mOuterWindow(aOuterWindow),
   // Make sure no actual window ends up with mWindowID == 0
   mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false),
   mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false)
  {}
 
@@ -3696,39 +3695,40 @@ nsPIDOMWindowInner::CreatePerformanceObj
         parentPerformance = parentInnerWindow->GetPerformance();
       }
     }
     mPerformance =
       new nsPerformance(this, timing, timedChannel, parentPerformance);
   }
 }
 
-SuspendTypes
-nsPIDOMWindowOuter::GetMediaSuspend() const
+bool
+nsPIDOMWindowOuter::GetMediaSuspended() const
 {
   if (IsInnerWindow()) {
-    return mOuterWindow->GetMediaSuspend();
-  }
-
-  return mMediaSuspend;
-}
-
-void
-nsPIDOMWindowOuter::SetMediaSuspend(SuspendTypes aSuspend)
+    return mOuterWindow->GetMediaSuspended();
+  }
+
+  return mMediaSuspended;
+}
+
+void
+nsPIDOMWindowOuter::SetMediaSuspended(bool aSuspended)
 {
   if (IsInnerWindow()) {
-    mOuterWindow->SetMediaSuspend(aSuspend);
-    return;
-  }
-
-  if (!IsDisposableSuspend(aSuspend)) {
-    mMediaSuspend = aSuspend;
-  }
-
-  RefreshMediaElementsSuspend(aSuspend);
+    mOuterWindow->SetMediaSuspended(aSuspended);
+    return;
+  }
+
+  if (mMediaSuspended == aSuspended) {
+    return;
+  }
+
+  mMediaSuspended = aSuspended;
+  RefreshMediaElements();
 }
 
 bool
 nsPIDOMWindowOuter::GetAudioMuted() const
 {
   if (IsInnerWindow()) {
     return mOuterWindow->GetAudioMuted();
   }
@@ -3744,17 +3744,17 @@ nsPIDOMWindowOuter::SetAudioMuted(bool a
     return;
   }
 
   if (mAudioMuted == aMuted) {
     return;
   }
 
   mAudioMuted = aMuted;
-  RefreshMediaElementsVolume();
+  RefreshMediaElements();
 }
 
 float
 nsPIDOMWindowOuter::GetAudioVolume() const
 {
   if (IsInnerWindow()) {
     return mOuterWindow->GetAudioVolume();
   }
@@ -3773,46 +3773,30 @@ nsPIDOMWindowOuter::SetAudioVolume(float
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   if (mAudioVolume == aVolume) {
     return NS_OK;
   }
 
   mAudioVolume = aVolume;
-  RefreshMediaElementsVolume();
+  RefreshMediaElements();
   return NS_OK;
 }
 
 void
-nsPIDOMWindowOuter::RefreshMediaElementsVolume()
+nsPIDOMWindowOuter::RefreshMediaElements()
 {
   RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
   if (service) {
     service->RefreshAgentsVolume(GetOuterWindow());
   }
 }
 
 void
-nsPIDOMWindowOuter::RefreshMediaElementsSuspend(SuspendTypes aSuspend)
-{
-  RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
-  if (service) {
-    // TODO : Impelement in next patch.
-  }
-}
-
-bool
-nsPIDOMWindowOuter::IsDisposableSuspend(SuspendTypes aSuspend) const
-{
-  return (aSuspend == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE ||
-          aSuspend == nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE);
-}
-
-void
 nsPIDOMWindowOuter::SetServiceWorkersTestingEnabled(bool aEnabled)
 {
   // Devtools should only be setting this on the top level window.  Its
   // ok if devtools clears the flag on clean up of nested windows, though.
   // It will have no affect.
 #ifdef DEBUG
   nsCOMPtr<nsPIDOMWindowOuter> topWindow = GetScriptableTop();
   MOZ_ASSERT_IF(aEnabled, this == topWindow);
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -33,18 +33,16 @@ class nsIScriptTimeoutHandler;
 class nsIURI;
 class nsPerformance;
 class nsPIDOMWindowInner;
 class nsPIDOMWindowOuter;
 class nsPIWindowRoot;
 class nsXBLPrototypeHandler;
 struct nsTimeout;
 
-typedef uint32_t SuspendTypes;
-
 namespace mozilla {
 namespace dom {
 class AudioContext;
 class Element;
 class ServiceWorkerRegistrationMainThread;
 } // namespace dom
 namespace gfx {
 class VRDeviceProxy;
@@ -652,29 +650,17 @@ protected:
   // Only used on outer windows.
   bool                   mIsActive;
 
   // Tracks whether our docshell is active.  If it is, mIsBackground
   // is false.  Too bad we have so many different concepts of
   // "active".  Only used on outer windows.
   bool                   mIsBackground;
 
-  /**
-   * The suspended types can be "disposable" or "permanent". This varable only
-   * stores the value about permanent suspend.
-   * - disposable
-   * To pause all playing media in that window, but doesn't affect the media
-   * which starts after that.
-   *
-   * - permanent
-   * To pause all media in that window, and also affect the media which starts
-   * after that.
-   */
-  SuspendTypes       mMediaSuspend;
-
+  bool                   mMediaSuspended;
   bool                   mAudioMuted;
   float                  mAudioVolume;
 
   bool                   mAudioCaptured;
 
   // current desktop mode flag.
   bool                   mDesktopModeViewport;
 
@@ -820,19 +806,17 @@ protected:
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowInner, NS_PIDOMWINDOWINNER_IID)
 
 // NB: It's very very important that these two classes have identical vtables
 // and memory layout!
 class nsPIDOMWindowOuter : public nsPIDOMWindow<mozIDOMWindowProxy>
 {
 protected:
-  void RefreshMediaElementsVolume();
-  void RefreshMediaElementsSuspend(SuspendTypes aSuspend);
-  bool IsDisposableSuspend(SuspendTypes aSuspend) const;
+  void RefreshMediaElements();
 
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWOUTER_IID)
 
   static nsPIDOMWindowOuter* From(mozIDOMWindowProxy* aFrom) {
     return static_cast<nsPIDOMWindowOuter*>(aFrom);
   }
 
@@ -873,18 +857,18 @@ public:
     return mDesktopModeViewport;
   }
   bool IsBackground()
   {
     return mIsBackground;
   }
 
   // Audio API
-  SuspendTypes GetMediaSuspend() const;
-  void SetMediaSuspend(SuspendTypes aSuspend);
+  bool GetMediaSuspended() const;
+  void SetMediaSuspended(bool aSuspended);
 
   bool GetAudioMuted() const;
   void SetAudioMuted(bool aMuted);
 
   float GetAudioVolume() const;
   nsresult SetAudioVolume(float aVolume);
 
   void SetServiceWorkersTestingEnabled(bool aEnabled);
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -1746,20 +1746,20 @@ interface nsIDOMWindowUtils : nsISupport
   [implicit_jscontext] jsval getCompositorAPZTestData();
 
   /**
    * Posts an eRestyle_Self restyle event for the given element.
    */
   void postRestyleSelfEvent(in nsIDOMElement aElement);
 
   /**
-   * Used to pause or resume all media in this window. Use-cases are audio
-   * competing, remote media control and to prevent auto-playing media.
+   * Used to pause or resume all MediaElements in this window. Use-cases are
+   * audio competing and remote media control.
    */
-  attribute uint32_t mediaSuspend;
+  attribute boolean mediaSuspended;
 
   /**
    * With this it's possible to mute all the MediaElements in this window.
    * We have audioMuted and audioVolume to preserve the volume across
    * mute/umute.
    */
   attribute boolean audioMuted;
 
--- a/mobile/android/base/java/org/mozilla/gecko/media/AudioFocusAgent.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/AudioFocusAgent.java
@@ -44,26 +44,26 @@ public class AudioFocusAgent {
         mContext = context;
         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
 
         mAfChangeListener = new OnAudioFocusChangeListener() {
             public void onAudioFocusChange(int focusChange) {
                 switch (focusChange) {
                     case AudioManager.AUDIOFOCUS_LOSS:
                         Log.d(LOGTAG, "onAudioFocusChange, AUDIOFOCUS_LOSS");
-                        notifyObservers("AudioFocusChanged", "lostAudioFocus");
+                        notifyObservers("AudioFocusChanged", "Loss");
                         // TODO : to dispatch audio-stop from gecko to trigger abandonAudioFocusIfNeeded
                         break;
                     case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                         Log.d(LOGTAG, "onAudioFocusChange, AUDIOFOCUS_LOSS_TRANSIENT");
-                        notifyObservers("AudioFocusChanged", "lostAudioFocusTransiently");
+                        notifyObservers("AudioFocusChanged", "LossTransient");
                         break;
                     case AudioManager.AUDIOFOCUS_GAIN:
                         Log.d(LOGTAG, "onAudioFocusChange, AUDIOFOCUS_GAIN");
-                        notifyObservers("AudioFocusChanged", "gainAudioFocus");
+                        notifyObservers("AudioFocusChanged", "Gain");
                         break;
                     default:
                 }
             }
         };
     }
 
     @RobocopTarget
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -557,10 +557,8 @@
 
 @BINPATH@/components/DataStore.manifest
 @BINPATH@/components/DataStoreImpl.js
 @BINPATH@/components/dom_datastore.xpt
 
 #ifdef PKG_LOCALE_MANIFEST
 #include @PKG_LOCALE_MANIFEST@
 #endif
-
-@BINPATH@/components/dom_audiochannel.xpt
\ No newline at end of file
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -716,82 +716,59 @@ addMessageListener("WebChannelMessageToC
 
 var AudioPlaybackListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   init() {
     Services.obs.addObserver(this, "audio-playback", false);
     Services.obs.addObserver(this, "AudioFocusChanged", false);
 
-    addMessageListener("AudioPlayback", this);
+    addMessageListener("AudioPlaybackMute", this);
     addEventListener("unload", () => {
       AudioPlaybackListener.uninit();
     });
   },
 
   uninit() {
     Services.obs.removeObserver(this, "audio-playback");
     Services.obs.removeObserver(this, "AudioFocusChanged");
 
-    removeMessageListener("AudioPlayback", this);
-  },
-
-  handleMediaControlMessage(msg) {
-    let utils = global.content.QueryInterface(Ci.nsIInterfaceRequestor)
-                              .getInterface(Ci.nsIDOMWindowUtils);
-    let suspendTypes = Ci.nsISuspendedTypes;
-    switch (msg) {
-      case "mute":
-        utils.audioMuted = true;
-        break;
-      case "unmute":
-        utils.audioMuted = false;
-        break;
-      case "lostAudioFocus":
-        utils.mediaSuspend = suspendTypes.SUSPENDED_STOP_DISPOSABLE;
-        break;
-      case "lostAudioFocusTransiently":
-        utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE;
-        break;
-      case "gainAudioFocus":
-        utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
-        break;
-      case "mediaControlPaused":
-        utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
-        break;
-      case "mediaControlStopped":
-        utils.mediaSuspend = suspendTypes.SUSPENDED_STOP_DISPOSABLE;
-        break;
-      case "blockInactivePageMedia":
-        utils.mediaSuspend = suspendTypes.SUSPENDED_BLOCK;
-        break;
-      case "resumeMedia":
-        utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
-        break;
-      default:
-        dump("Error : wrong media control msg!\n");
-        break;
-    }
+    removeMessageListener("AudioPlaybackMute", this);
   },
 
   observe(subject, topic, data) {
     if (topic === "audio-playback") {
       if (subject && subject.top == global.content) {
         let name = "AudioPlayback:";
         name += (data === "active") ? "Start" : "Stop";
         sendAsyncMessage(name);
       }
     } else if (topic == "AudioFocusChanged") {
-      this.handleMediaControlMessage(data);
+      let utils = global.content.QueryInterface(Ci.nsIInterfaceRequestor)
+                                .getInterface(Ci.nsIDOMWindowUtils);
+      switch (data) {
+        // The AudioFocus:LossTransient means the media would be resumed after
+        // the interruption ended, but AudioFocus:Loss doesn't.
+        // TODO : distinguish these types, it would be done in bug1242874.
+        case "Loss":
+        case "LossTransient":
+          utils.mediaSuspended = true;
+          break;
+        case "Gain":
+          utils.mediaSuspended = false;
+          break;
+      }
     }
   },
 
   receiveMessage(msg) {
-    if (msg.name == "AudioPlayback") {
-      this.handleMediaControlMessage(msg.data.type);
+    if (msg.name == "AudioPlaybackMute") {
+      let utils = global.content.QueryInterface(Ci.nsIInterfaceRequestor)
+                                .getInterface(Ci.nsIDOMWindowUtils);
+      utils.audioMuted = msg.data.type === "mute";
     }
   },
 };
 AudioPlaybackListener.init();
 
 addMessageListener("Browser:PurgeSessionHistory", function BrowserPurgeHistory() {
   let sessionHistory = docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory;
   if (!sessionHistory) {
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -709,76 +709,32 @@
       <property name="audioMuted"
                 onget="return this._audioMuted;"
                 readonly="true"/>
 
       <method name="mute">
         <body>
           <![CDATA[
             this._audioMuted = true;
-            this.messageManager.sendAsyncMessage("AudioPlayback",
+            this.messageManager.sendAsyncMessage("AudioPlaybackMute",
                                                  {type: "mute"});
           ]]>
         </body>
       </method>
 
       <method name="unmute">
         <body>
           <![CDATA[
             this._audioMuted = false;
-            this.messageManager.sendAsyncMessage("AudioPlayback",
+            this.messageManager.sendAsyncMessage("AudioPlaybackMute",
                                                  {type: "unmute"});
           ]]>
         </body>
       </method>
 
-      <method name="pauseMedia">
-        <parameter name="disposable"/>
-        <body>
-          <![CDATA[
-            let suspendedReason;
-            if (disposable) {
-              suspendedReason = "mediaControlPaused";
-            } else {
-              suspendedReason = "lostAudioFocusTransiently";
-            }
-
-            this.messageManager.sendAsyncMessage("AudioPlayback",
-                                                 {type: suspendedReason});
-          ]]>
-        </body>
-      </method>
-
-      <method name="stopMedia">
-        <body>
-          <![CDATA[
-            this.messageManager.sendAsyncMessage("AudioPlayback",
-                                                 {type: "mediaControlStopped"});
-          ]]>
-        </body>
-      </method>
-
-      <method name="blockMedia">
-        <body>
-          <![CDATA[
-            this.messageManager.sendAsyncMessage("AudioPlayback",
-                                                 {type: "blockInactivePageMedia"});
-          ]]>
-        </body>
-      </method>
-
-      <method name="resumeMedia">
-        <body>
-          <![CDATA[
-            this.messageManager.sendAsyncMessage("AudioPlayback",
-                                                 {type: "resumeMedia"});
-          ]]>
-        </body>
-      </method>
-
       <property name="securityUI">
         <getter>
           <![CDATA[
             if (!this.docShell.securityUI) {
               const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
               if (!this.hasAttribute("disablesecurity") &&
                   SECUREBROWSERUI_CONTRACTID in Components.classes) {
                 var securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID]