From 9f4ce1bc22cf54dc9bb68e30b3c84878399d4ed5 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Wed, 15 Feb 2012 15:34:24 -0500 Subject: [PATCH] Bug 726741 - Don't leak nsPluginInstanceOwner on Android --- dom/plugins/base/android/ANPNativeWindow.cpp | 19 +++++++++---------- dom/plugins/base/android/ANPVideo.cpp | 19 ++++++++++--------- dom/plugins/base/android/ANPWindow.cpp | 10 ++++++++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/dom/plugins/base/android/ANPNativeWindow.cpp b/dom/plugins/base/android/ANPNativeWindow.cpp index 4359688a859..b693284f3d5 100644 --- a/dom/plugins/base/android/ANPNativeWindow.cpp +++ b/dom/plugins/base/android/ANPNativeWindow.cpp @@ -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(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 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(instance->ndata); - - nsPluginInstanceOwner* owner; - if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) { + nsRefPtr owner; + if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner)))) return; - } owner->Layer()->SetInverted(isContentInverted); } diff --git a/dom/plugins/base/android/ANPVideo.cpp b/dom/plugins/base/android/ANPVideo.cpp index 6b75425a046..9f49c5f1909 100644 --- a/dom/plugins/base/android/ANPVideo.cpp +++ b/dom/plugins/base/android/ANPVideo.cpp @@ -35,22 +35,23 @@ using namespace mozilla; -static AndroidMediaLayer* GetLayerForInstance(NPP instance) { +static nsresult GetOwner(NPP instance, nsPluginInstanceOwner** owner) { nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); - nsPluginInstanceOwner* owner; - if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) { - return NULL; - } + return pinst->GetOwner((nsIPluginInstanceOwner**)owner); +} +static AndroidMediaLayer* GetLayerForInstance(NPP instance) { + nsRefPtr owner; + if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner)))) + return NULL; + return owner->Layer(); } static void Invalidate(NPP instance) { - nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); - - nsPluginInstanceOwner* owner; - if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) + nsRefPtr owner; + if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner)))) return; owner->Invalidate(); diff --git a/dom/plugins/base/android/ANPWindow.cpp b/dom/plugins/base/android/ANPWindow.cpp index 75b643df386..ca9c202a33d 100644 --- a/dom/plugins/base/android/ANPWindow.cpp +++ b/dom/plugins/base/android/ANPWindow.cpp @@ -85,6 +85,12 @@ anp_window_requestCenterFitZoom(NPP instance) NOT_IMPLEMENTED(); } +static nsresult GetOwner(NPP instance, nsPluginInstanceOwner** owner) { + nsNPAPIPluginInstance* pinst = static_cast(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(instance->ndata); - nsPluginInstanceOwner* owner; - if (NS_FAILED(pinst->GetOwner((nsIPluginInstanceOwner**)&owner))) { + nsRefPtr owner; + if (NS_FAILED(GetOwner(instance, getter_AddRefs(owner)))) { return rect; }