Bug 726741 - Don't leak nsPluginInstanceOwner on Android

This commit is contained in:
James Willcox 2012-02-15 15:34:24 -05:00
parent 382e0e9734
commit 9f4ce1bc22
3 changed files with 27 additions and 21 deletions

View File

@ -52,14 +52,16 @@ using namespace mozilla;
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
#define ASSIGN(obj, name) (obj)->name = anp_native_window_##name
static ANPNativeWindow anp_native_window_acquireNativeWindow(NPP instance) {
static nsresult GetOwner(NPP instance, nsPluginInstanceOwner** owner) {
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
nsPluginInstanceOwner* owner;
if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) {
return NULL;
}
return pinst->GetOwner((nsIPluginInstanceOwner**)owner);
}
static ANPNativeWindow anp_native_window_acquireNativeWindow(NPP instance) {
nsRefPtr<nsPluginInstanceOwner> owner;
if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner))))
return NULL;
ANPNativeWindow window = owner->Layer()->GetNativeWindowForContent();
owner->Invalidate();
@ -68,12 +70,9 @@ static ANPNativeWindow anp_native_window_acquireNativeWindow(NPP instance) {
}
static void anp_native_window_invertPluginContent(NPP instance, bool isContentInverted) {
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
nsPluginInstanceOwner* owner;
if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) {
nsRefPtr<nsPluginInstanceOwner> owner;
if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner))))
return;
}
owner->Layer()->SetInverted(isContentInverted);
}

View File

@ -35,22 +35,23 @@
using namespace mozilla;
static AndroidMediaLayer* GetLayerForInstance(NPP instance) {
static nsresult GetOwner(NPP instance, nsPluginInstanceOwner** owner) {
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
nsPluginInstanceOwner* owner;
if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) {
return NULL;
}
return pinst->GetOwner((nsIPluginInstanceOwner**)owner);
}
static AndroidMediaLayer* GetLayerForInstance(NPP instance) {
nsRefPtr<nsPluginInstanceOwner> owner;
if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner))))
return NULL;
return owner->Layer();
}
static void Invalidate(NPP instance) {
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
nsPluginInstanceOwner* owner;
if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner)))
nsRefPtr<nsPluginInstanceOwner> owner;
if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner))))
return;
owner->Invalidate();

View File

@ -85,6 +85,12 @@ anp_window_requestCenterFitZoom(NPP instance)
NOT_IMPLEMENTED();
}
static nsresult GetOwner(NPP instance, nsPluginInstanceOwner** owner) {
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
return pinst->GetOwner((nsIPluginInstanceOwner**)owner);
}
ANPRectI
anp_window_visibleRect(NPP instance)
{
@ -92,8 +98,8 @@ anp_window_visibleRect(NPP instance)
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
nsPluginInstanceOwner* owner;
if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) {
nsRefPtr<nsPluginInstanceOwner> owner;
if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner)))) {
return rect;
}