Bug 1319529 - notify audible state changed for nsNPAPI. draft
authorAlastor Wu <alwu@mozilla.com>
Fri, 16 Dec 2016 17:12:41 +0800
changeset 450275 5f4ac9a7ec941e262e66524752b8873d48c9fc6b
parent 449758 b1ab720c6d3e412ede797b08dfe63dca170f6ee0
child 539722 cbac6e83f1c32db5fce347d02ecaf30be2b93e63
push id38822
push useralwu@mozilla.com
push dateFri, 16 Dec 2016 09:13:06 +0000
bugs1319529
milestone53.0a1
Bug 1319529 - notify audible state changed for nsNPAPI. When the nsNPAPI is muted by AudioChannelService, we should notify our audible state changed. MozReview-Commit-ID: 1YHGZiyIRvI
dom/base/test/test_pluginAudioNotification.html
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
--- a/dom/base/test/test_pluginAudioNotification.html
+++ b/dom/base/test/test_pluginAudioNotification.html
@@ -70,25 +70,33 @@ var tests = [
   },
 
   function() {
     expectedNotification = 'active';
     iframe.src = "file_pluginAudio.html";
   },
 
   function() {
+    info("=== Mute plugin ===");
     ok(!iframe.contentWindow.pluginMuted(), "Plugin should not be muted");
     iframe.contentWindow.toggleMuteState(true);
     ok(iframe.contentWindow.pluginMuted(), "Plugin should be muted");
+    expectedNotification = 'inactive-nonaudible';
+  },
+
+  function() {
+    info("=== unmute plugin ==");
+    ok(iframe.contentWindow.pluginMuted(), "Plugin should be muted");
     iframe.contentWindow.toggleMuteState(false);
     ok(!iframe.contentWindow.pluginMuted(), "Plugin should not be muted");
-    runTest();
+    expectedNotification = 'active';
   },
 
   function() {
+    info("=== stop audio ==");
     expectedNotification = 'inactive-pause';
     iframe.contentWindow.stopAudio();
   },
 
   function() {
     observerService.removeObserver(observer, "audio-playback");
     ok(true, "Observer removed");
     runTest();
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -134,16 +134,17 @@ nsNPAPIPluginInstance::nsNPAPIPluginInst
 #endif
 #ifdef MOZ_WIDGET_ANDROID
   , mOnScreen(true)
 #endif
   , mHaveJavaC2PJSObjectQuirk(false)
   , mCachedParamLength(0)
   , mCachedParamNames(nullptr)
   , mCachedParamValues(nullptr)
+  , mMuted(false)
 {
   mNPP.pdata = nullptr;
   mNPP.ndata = this;
 
   PLUGIN_LOG(PLUGIN_LOG_BASIC, ("nsNPAPIPluginInstance ctor: this=%p\n",this));
 
 #ifdef MOZ_WIDGET_ANDROID
   sPluginNPPMap[&mNPP] = this;
@@ -1789,16 +1790,24 @@ nsNPAPIPluginInstance::GetOrCreateAudioC
 }
 
 NS_IMETHODIMP
 nsNPAPIPluginInstance::WindowVolumeChanged(float aVolume, bool aMuted)
 {
   // We just support mute/unmute
   nsresult rv = SetMuted(aMuted);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetMuted failed");
+  if (mMuted != aMuted) {
+    mMuted = aMuted;
+    AudioChannelService::AudibleState audible = aMuted ?
+      AudioChannelService::AudibleState::eNotAudible :
+      AudioChannelService::AudibleState::eAudible;
+    mAudioChannelAgent->NotifyStartedAudible(audible,
+                                             AudioChannelService::AudibleChangedReasons::eVolumeChanged);
+  }
   return rv;
 }
 
 NS_IMETHODIMP
 nsNPAPIPluginInstance::WindowSuspendChanged(nsSuspendedTypes aSuspend)
 {
   // It doesn't support suspended, so we just do something like mute/unmute.
   WindowVolumeChanged(1.0, /* useless */
--- a/dom/plugins/base/nsNPAPIPluginInstance.h
+++ b/dom/plugins/base/nsNPAPIPluginInstance.h
@@ -425,16 +425,17 @@ private:
 
   // The arrays can only be released when the plugin instance is destroyed,
   // because the plugin, in in-process mode, might keep a reference to them.
   uint32_t mCachedParamLength;
   char **mCachedParamNames;
   char **mCachedParamValues;
 
   nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
+  bool mMuted;
 };
 
 // On Android, we need to guard against plugin code leaking entries in the local
 // JNI ref table. See https://bugzilla.mozilla.org/show_bug.cgi?id=780831#c21
 #ifdef MOZ_WIDGET_ANDROID
   #define MAIN_THREAD_JNI_REF_GUARD mozilla::AutoLocalJNIFrame jniFrame
 #else
   #define MAIN_THREAD_JNI_REF_GUARD