Bug 862182 - Hold references to MediaResource in nsRefPtrs (content/media/plugins). r=doublec

This commit is contained in:
Chris Pearce 2013-05-01 11:23:46 +12:00
parent f7895b7d0b
commit b5a5314926

View File

@ -273,15 +273,16 @@ bool MediaPluginHost::FindDecoder(const nsACString& aMimeType, const char* const
MPAPI::Decoder *MediaPluginHost::CreateDecoder(MediaResource *aResource, const nsACString& aMimeType)
{
const char *chars;
size_t len = NS_CStringGetData(aMimeType, &chars, nullptr);
NS_ENSURE_TRUE(aResource, nullptr);
Decoder *decoder = new Decoder();
nsAutoPtr<Decoder> decoder(new Decoder());
if (!decoder) {
return nullptr;
}
decoder->mResource = aResource;
const char *chars;
size_t len = NS_CStringGetData(aMimeType, &chars, nullptr);
for (size_t n = 0; n < mPlugins.Length(); ++n) {
Manifest *plugin = mPlugins[n];
const char* const *codecs;
@ -289,7 +290,8 @@ MPAPI::Decoder *MediaPluginHost::CreateDecoder(MediaResource *aResource, const n
continue;
}
if (plugin->CreateDecoder(&sPluginHost, decoder, chars, len)) {
return decoder;
aResource->AddRef();
return decoder.forget();
}
}
@ -299,6 +301,12 @@ MPAPI::Decoder *MediaPluginHost::CreateDecoder(MediaResource *aResource, const n
void MediaPluginHost::DestroyDecoder(Decoder *aDecoder)
{
aDecoder->DestroyDecoder(aDecoder);
MediaResource* resource = GetResource(aDecoder);
if (resource) {
// resource *shouldn't* be null, but check anyway just in case the plugin
// decoder does something stupid.
resource->Release();
}
delete aDecoder;
}