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-10-05 04:35:00 +02:00
parent 7314c116b2
commit e881742ef0
5 changed files with 41 additions and 28 deletions

View File

@ -98,13 +98,13 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType,
"Enum of channel on nsIAudioChannelAgent.idl should be the same with AudioChannelBinding.h");
if (mAudioChannelType != AUDIO_AGENT_CHANNEL_ERROR ||
aChannelType > AUDIO_AGENT_CHANNEL_PUBLICNOTIFICATION ||
aChannelType > AUDIO_AGENT_CHANNEL_SYSTEM ||
aChannelType < AUDIO_AGENT_CHANNEL_NORMAL) {
return NS_ERROR_FAILURE;
}
if (NS_WARN_IF(!aWindow)) {
return NS_ERROR_FAILURE;
return NS_OK;
}
nsCOMPtr<nsPIDOMWindow> pInnerWindow = do_QueryInterface(aWindow);
@ -113,12 +113,16 @@ 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();
}
if (!mWindow) {
if (NS_WARN_IF(!mWindow)) {
return NS_ERROR_FAILURE;
}

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()
@ -151,20 +158,9 @@ AudioContext::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
AudioContext::Constructor(const GlobalObject& aGlobal,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<AudioContext> object =
new AudioContext(window, false,
AudioChannelService::GetDefaultAudioChannel());
object->Init();
RegisterWeakMemoryReporter(object);
return object.forget();
return AudioContext::Constructor(aGlobal,
AudioChannelService::GetDefaultAudioChannel(),
aRv);
}
/* static */ already_AddRefed<AudioContext>
@ -179,7 +175,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