Bug 1180940 - Changed return type of AudioDestinationNode::CreateAudioChannelAgent method to return errors, if any methods that it calls fail. Added code to handle the return value in AudioContext::Init(), and its callers. r=baku

This commit is contained in:
sajitk 2015-09-30 17:51:00 +02:00
parent 69ac071e6d
commit 6862ae67d8
5 changed files with 40 additions and 13 deletions

View File

@ -104,7 +104,7 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType,
}
if (NS_WARN_IF(!aWindow)) {
return NS_ERROR_FAILURE;
return NS_OK;
}
nsCOMPtr<nsPIDOMWindow> pInnerWindow = do_QueryInterface(aWindow);
@ -113,6 +113,10 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType,
nsCOMPtr<nsIDOMWindow> topWindow;
aWindow->GetScriptableTop(getter_AddRefs(topWindow));
if (NS_WARN_IF(!topWindow)) {
return NS_OK;
}
mWindow = do_QueryInterface(topWindow);
if (mWindow) {
mWindow = mWindow->GetOuterWindow();

View File

@ -117,14 +117,21 @@ AudioContext::AudioContext(nsPIDOMWindow* aWindow,
}
}
void
nsresult
AudioContext::Init()
{
// We skip calling SetIsOnlyNodeForContext and the creation of the
// audioChannelAgent during mDestination's constructor, because we can only
// call them after mDestination has been set up.
mDestination->CreateAudioChannelAgent();
mDestination->SetIsOnlyNodeForContext(true);
if (!mIsOffline) {
nsresult rv = mDestination->CreateAudioChannelAgent();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mDestination->SetIsOnlyNodeForContext(true);
}
return NS_OK;
}
AudioContext::~AudioContext()
@ -160,7 +167,10 @@ AudioContext::Constructor(const GlobalObject& aGlobal,
nsRefPtr<AudioContext> object =
new AudioContext(window, false,
AudioChannelService::GetDefaultAudioChannel());
object->Init();
aRv = object->Init();
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RegisterWeakMemoryReporter(object);
@ -179,7 +189,10 @@ AudioContext::Constructor(const GlobalObject& aGlobal,
}
nsRefPtr<AudioContext> object = new AudioContext(window, false, aChannel);
object->Init();
aRv = object->Init();
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RegisterWeakMemoryReporter(object);

View File

@ -124,7 +124,7 @@ class AudioContext final : public DOMEventTargetHelper,
float aSampleRate = 0.0f);
~AudioContext();
void Init();
nsresult Init();
public:
typedef uint64_t AudioContextId;

View File

@ -629,23 +629,33 @@ AudioDestinationNode::CheckAudioChannelPermissions(AudioChannel aValue)
return perm == nsIPermissionManager::ALLOW_ACTION;
}
void
nsresult
AudioDestinationNode::CreateAudioChannelAgent()
{
if (mIsOffline) {
return;
return NS_OK;
}
nsresult rv = NS_OK;
if (mAudioChannelAgent) {
mAudioChannelAgent->NotifyStoppedPlaying(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY);
rv = mAudioChannelAgent->NotifyStoppedPlaying(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
mAudioChannelAgent = new AudioChannelAgent();
mAudioChannelAgent->InitWithWeakCallback(GetOwner(),
rv = mAudioChannelAgent->InitWithWeakCallback(GetOwner(),
static_cast<int32_t>(mAudioChannel),
this);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = WindowAudioCaptureChanged();
NS_WARN_IF(NS_FAILED(rv));
return rv;
WindowAudioCaptureChanged();
}
void

View File

@ -73,7 +73,7 @@ public:
// When aIsOnlyNode is true, this is the only node for the AudioContext.
void SetIsOnlyNodeForContext(bool aIsOnlyNode);
void CreateAudioChannelAgent();
nsresult CreateAudioChannelAgent();
void DestroyAudioChannelAgent();
virtual const char* NodeType() const override