Bug 1346872 - part2 : only access agent related codes in nsNPAPIPluginInstance. r=Ehsan

nsNPAPIPlugin doesn't need to know about agent, nsNPAPIPluginInstance should wrap
all of the details in its memeber function.

MozReview-Commit-ID: 3LqTlH2flbt
This commit is contained in:
Alastor Wu
2017-03-30 14:27:42 +08:00
parent faa8fd6585
commit 5a0c4fae9a
3 changed files with 76 additions and 61 deletions

View File

@@ -1713,33 +1713,79 @@ nsNPAPIPluginInstance::GetRunID(uint32_t* aRunID)
}
nsresult
nsNPAPIPluginInstance::GetOrCreateAudioChannelAgent(nsIAudioChannelAgent** aAgent)
nsNPAPIPluginInstance::CreateAudioChannelAgentIfNeeded()
{
if (!mAudioChannelAgent) {
nsresult rv;
mAudioChannelAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1", &rv);
if (NS_WARN_IF(!mAudioChannelAgent)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsPIDOMWindowOuter> window = GetDOMWindow();
if (NS_WARN_IF(!window)) {
return NS_ERROR_FAILURE;
}
rv = mAudioChannelAgent->Init(window->GetCurrentInnerWindow(),
(int32_t)AudioChannelService::GetDefaultAudioChannel(),
this);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (mAudioChannelAgent) {
return NS_OK;
}
nsCOMPtr<nsIAudioChannelAgent> agent = mAudioChannelAgent;
agent.forget(aAgent);
nsresult rv;
mAudioChannelAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1", &rv);
if (NS_WARN_IF(!mAudioChannelAgent)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsPIDOMWindowOuter> window = GetDOMWindow();
if (NS_WARN_IF(!window)) {
return NS_ERROR_FAILURE;
}
rv = mAudioChannelAgent->Init(window->GetCurrentInnerWindow(),
(int32_t)AudioChannelService::GetDefaultAudioChannel(),
this);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
void
nsNPAPIPluginInstance::NotifyStartedPlaying()
{
nsresult rv = CreateAudioChannelAgentIfNeeded();
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
MOZ_ASSERT(mAudioChannelAgent);
dom::AudioPlaybackConfig config;
rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
dom::AudioChannelService::AudibleState::eAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
rv = WindowVolumeChanged(config.mVolume, config.mMuted);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
// Since we only support muting for now, the implementation of suspend
// is equal to muting. Therefore, if we have already muted the plugin,
// then we don't need to call WindowSuspendChanged() again.
if (config.mMuted) {
return;
}
rv = WindowSuspendChanged(config.mSuspend);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
}
void
nsNPAPIPluginInstance::NotifyStoppedPlaying()
{
MOZ_ASSERT(mAudioChannelAgent);
// Reset the attribute.
mMuted = false;
nsresult rv = mAudioChannelAgent->NotifyStoppedPlaying();
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
}
NS_IMETHODIMP
nsNPAPIPluginInstance::WindowVolumeChanged(float aVolume, bool aMuted)
{