From ef157dd2744c230b9e99f2152a70fed4464fc73d Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Tue, 14 Feb 2017 09:10:31 -0500 Subject: [PATCH] Bug 1333887 - Hold nsNPAPIPlugin alive for active nsNPAPIPluginInstance objects. This should happen through the plugin tag, but apparently that isn't always working. r=qdot --HG-- extra : rebase_source : 79750e208d0d7dad50ee6711491222143618fb8d --- dom/plugins/base/nsNPAPIPlugin.cpp | 2 -- dom/plugins/base/nsNPAPIPlugin.h | 11 +++++++---- dom/plugins/base/nsNPAPIPluginInstance.h | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dom/plugins/base/nsNPAPIPlugin.cpp b/dom/plugins/base/nsNPAPIPlugin.cpp index a85b02edcd59..1f2e16867258 100644 --- a/dom/plugins/base/nsNPAPIPlugin.cpp +++ b/dom/plugins/base/nsNPAPIPlugin.cpp @@ -210,8 +210,6 @@ static void CheckClassInitialized() NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,("NPN callbacks initialized\n")); } -NS_IMPL_ISUPPORTS0(nsNPAPIPlugin) - nsNPAPIPlugin::nsNPAPIPlugin() { memset((void*)&mPluginFuncs, 0, sizeof(mPluginFuncs)); diff --git a/dom/plugins/base/nsNPAPIPlugin.h b/dom/plugins/base/nsNPAPIPlugin.h index 5725492a5093..96e630b629cc 100644 --- a/dom/plugins/base/nsNPAPIPlugin.h +++ b/dom/plugins/base/nsNPAPIPlugin.h @@ -12,6 +12,7 @@ #include "mozilla/dom/ScriptSettings.h" #include "mozilla/PluginLibrary.h" +#include "mozilla/RefCounted.h" #if defined(XP_WIN) #define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (__stdcall * _name) @@ -24,7 +25,9 @@ typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGININIT) (const NPNetscapeFuncs* typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINUNIXINIT) (const NPNetscapeFuncs* pCallbacks, NPPluginFuncs* fCallbacks); typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN) (); -class nsNPAPIPlugin : public nsISupports +// nsNPAPIPlugin is held alive both by active nsPluginTag instances and +// by active nsNPAPIPluginInstance. +class nsNPAPIPlugin final { private: typedef mozilla::PluginLibrary PluginLibrary; @@ -32,7 +35,7 @@ private: public: nsNPAPIPlugin(); - NS_DECL_ISUPPORTS + NS_INLINE_DECL_REFCOUNTING(nsNPAPIPlugin) // Constructs and initializes an nsNPAPIPlugin object. A nullptr file path // will prevent this from calling NP_Initialize. @@ -59,8 +62,8 @@ public: static nsresult RetainStream(NPStream *pstream, nsISupports **aRetainedPeer); -protected: - virtual ~nsNPAPIPlugin(); +private: + ~nsNPAPIPlugin(); NPPluginFuncs mPluginFuncs; PluginLibrary* mLibrary; diff --git a/dom/plugins/base/nsNPAPIPluginInstance.h b/dom/plugins/base/nsNPAPIPluginInstance.h index 39a0a7325050..5f0375637570 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.h +++ b/dom/plugins/base/nsNPAPIPluginInstance.h @@ -30,6 +30,7 @@ class PluginEventRunnable; #include "mozilla/EventForwards.h" #include "mozilla/TimeStamp.h" #include "mozilla/PluginLibrary.h" +#include "mozilla/RefPtr.h" #include "mozilla/WeakPtr.h" class nsPluginStreamListenerPeer; // browser-initiated stream class @@ -384,7 +385,7 @@ public: nsXPIDLCString mFakeURL; private: - nsNPAPIPlugin* mPlugin; + RefPtr mPlugin; nsTArray mStreamListeners;