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
--- 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