Commit 2e82b231 authored by andersca@apple.com's avatar andersca@apple.com

Reuse initialized NetscapePluginModules, pass parameters to NPP_New

https://bugs.webkit.org/show_bug.cgi?id=42028

Reviewed by Dan Bernstein.

* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::NetscapePlugin):
Let the plug-in module know that a plug-in has been created.

(WebKit::NetscapePlugin::~NetscapePlugin):
Let the plug-in module know that a plug-in has been destroyed.

(WebKit::NetscapePlugin::initialize):
Pass the MIME type and parameters to the plug-in.

* WebProcess/Plugins/Netscape/NetscapePluginModule.cpp:
(WebKit::initializedNetscapePluginModules):
Add list of initialized plug-in modules.

(WebKit::NetscapePluginModule::NetscapePluginModule):
Initialize m_pluginCount to 0.

(WebKit::NetscapePluginModule::~NetscapePluginModule):
Assert that we're not in the list of initialized plug-ins.

(WebKit::NetscapePluginModule::pluginCreated):
Increment the plug-in count.

(WebKit::NetscapePluginModule::pluginDestroyed):
Decrement the plug-in count and call shutdown if it's 0.

(WebKit::NetscapePluginModule::shutdown):
Call NP_Shutdown and remove the plug-in from the list of initialized plug-ins.

(WebKit::NetscapePluginModule::getOrCreate):
Look for an already initialized plug-in module before creating one.

(WebKit::NetscapePluginModule::load):
Set m_isInitialized to true.

* WebProcess/Plugins/Netscape/mac/NetscapePluginModuleMac.cpp:
(WebKit::NetscapePluginModule::unload):
Leak the CFBundleRef to avoid possible crashes.

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::createPlugin):
Call getOrCreate instead of create.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63047 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ea43d9a6
2010-07-10 Anders Carlsson <andersca@apple.com>
Reviewed by Dan Bernstein.
Reuse initialized NetscapePluginModules, pass parameters to NPP_New
https://bugs.webkit.org/show_bug.cgi?id=42028
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::NetscapePlugin):
Let the plug-in module know that a plug-in has been created.
(WebKit::NetscapePlugin::~NetscapePlugin):
Let the plug-in module know that a plug-in has been destroyed.
(WebKit::NetscapePlugin::initialize):
Pass the MIME type and parameters to the plug-in.
* WebProcess/Plugins/Netscape/NetscapePluginModule.cpp:
(WebKit::initializedNetscapePluginModules):
Add list of initialized plug-in modules.
(WebKit::NetscapePluginModule::NetscapePluginModule):
Initialize m_pluginCount to 0.
(WebKit::NetscapePluginModule::~NetscapePluginModule):
Assert that we're not in the list of initialized plug-ins.
(WebKit::NetscapePluginModule::pluginCreated):
Increment the plug-in count.
(WebKit::NetscapePluginModule::pluginDestroyed):
Decrement the plug-in count and call shutdown if it's 0.
(WebKit::NetscapePluginModule::shutdown):
Call NP_Shutdown and remove the plug-in from the list of initialized plug-ins.
(WebKit::NetscapePluginModule::getOrCreate):
Look for an already initialized plug-in module before creating one.
(WebKit::NetscapePluginModule::load):
Set m_isInitialized to true.
* WebProcess/Plugins/Netscape/mac/NetscapePluginModuleMac.cpp:
(WebKit::NetscapePluginModule::unload):
Leak the CFBundleRef to avoid possible crashes.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::createPlugin):
Call getOrCreate instead of create.
2010-07-09 Leon Clarke <leonclarke@google.com>
Reviewed by Adam Barth.
......
......@@ -27,6 +27,8 @@
#include <WebCore/GraphicsContext.h>
#include <WebCore/IntRect.h>
#include <WebCore/KURL.h>
#include <wtf/text/CString.h>
using namespace WebCore;
......@@ -44,11 +46,15 @@ NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
{
m_npp.ndata = this;
m_npp.pdata = 0;
m_pluginModule->pluginCreated();
}
NetscapePlugin::~NetscapePlugin()
{
ASSERT(!m_isStarted);
m_pluginModule->pluginDestroyed();
}
PassRefPtr<NetscapePlugin> NetscapePlugin::fromNPP(NPP npp)
......@@ -79,15 +85,34 @@ void NetscapePlugin::callSetWindow()
m_pluginModule->pluginFuncs().setwindow(&m_npp, &m_npWindow);
}
bool NetscapePlugin::initialize(const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
bool NetscapePlugin::initialize(const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
{
uint16_t mode = loadManually ? NP_FULL : NP_EMBED;
m_inNPPNew = true;
// FIXME: Pass arguments to NPP_New.
NPError error = m_pluginModule->pluginFuncs().newp(0, &m_npp, mode, 0, 0, 0, 0);
CString mimeTypeCString = mimeType.utf8();
ASSERT(paramNames.size() == paramValues.size());
Vector<CString> utf8ParamNames;
Vector<CString> utf8ParamValues;
for (size_t i = 0; i < paramNames.size(); ++i) {
utf8ParamNames.append(paramNames[i].utf8());
utf8ParamValues.append(paramValues[i].utf8());
}
// The strings that these pointers point to are kept alive by utf8ParamNames and utf8ParamValues.
Vector<const char*> names;
Vector<const char*> values;
for (size_t i = 0; i < paramNames.size(); ++i) {
names.append(utf8ParamNames[i].data());
values.append(utf8ParamValues[i].data());
}
// FIXME: Pass arguments to NPP_New.
NPError error = m_pluginModule->pluginFuncs().newp(const_cast<char*>(mimeTypeCString.data()), &m_npp, mode,
names.size(), const_cast<char**>(names.data()), const_cast<char**>(values.data()), 0);
m_inNPPNew = false;
if (error != NPERR_NO_ERROR)
......
......@@ -29,16 +29,62 @@ using namespace WebCore;
namespace WebKit {
static Vector<NetscapePluginModule*>& initializedNetscapePluginModules()
{
DEFINE_STATIC_LOCAL(Vector<NetscapePluginModule*>, initializedNetscapePluginModules, ());
return initializedNetscapePluginModules;
}
NetscapePluginModule::NetscapePluginModule(const String& pluginPath)
: m_pluginPath(pluginPath)
, m_isInitialized(false)
, m_pluginCount(0)
, m_shutdownProcPtr(0)
, m_pluginFuncs()
{
}
PassRefPtr<NetscapePluginModule> NetscapePluginModule::create(const String& pluginPath)
NetscapePluginModule::~NetscapePluginModule()
{
ASSERT(initializedNetscapePluginModules().find(this) == notFound);
}
void NetscapePluginModule::pluginCreated()
{
m_pluginCount++;
}
void NetscapePluginModule::pluginDestroyed()
{
ASSERT(m_pluginCount > 0);
m_pluginCount--;
if (!m_pluginCount)
shutdown();
}
void NetscapePluginModule::shutdown()
{
ASSERT(m_isInitialized);
m_shutdownProcPtr();
size_t pluginModuleIndex = initializedNetscapePluginModules().find(this);
ASSERT(pluginModuleIndex != notFound);
initializedNetscapePluginModules().remove(pluginModuleIndex);
}
PassRefPtr<NetscapePluginModule> NetscapePluginModule::getOrCreate(const String& pluginPath)
{
// First, see if we already have a module with this plug-in path.
for (size_t i = 0; i < initializedNetscapePluginModules().size(); ++i) {
NetscapePluginModule* pluginModule = initializedNetscapePluginModules()[i];
if (pluginModule->m_pluginPath == pluginPath)
return pluginModule;
}
RefPtr<NetscapePluginModule> pluginModule(adoptRef(new NetscapePluginModule(pluginPath)));
// Try to load and initialize the plug-in module.
......@@ -55,6 +101,11 @@ bool NetscapePluginModule::load()
return false;
}
m_isInitialized = true;
ASSERT(initializedNetscapePluginModules().find(this) == notFound);
initializedNetscapePluginModules().append(this);
return true;
}
......
......@@ -38,10 +38,14 @@ namespace WebKit {
class NetscapePluginModule : public RefCounted<NetscapePluginModule> {
public:
static PassRefPtr<NetscapePluginModule> create(const WebCore::String& pluginPath);
static PassRefPtr<NetscapePluginModule> getOrCreate(const WebCore::String& pluginPath);
~NetscapePluginModule();
const NPPluginFuncs& pluginFuncs() const { return m_pluginFuncs; }
void pluginCreated();
void pluginDestroyed();
private:
explicit NetscapePluginModule(const WebCore::String& pluginPath);
......@@ -49,9 +53,12 @@ private:
bool load();
void unload();
void shutdown();
WebCore::String m_pluginPath;
bool m_isInitialized;
unsigned m_pluginCount;
NPP_ShutdownProcPtr m_shutdownProcPtr;
NPPluginFuncs m_pluginFuncs;
......
......@@ -31,8 +31,9 @@ namespace WebKit {
void NetscapePluginModule::unload()
{
if (m_bundle) {
CFBundleUnloadExecutable(m_bundle.get());
m_bundle = 0;
// We explicitly leak the bundle here, to avoid crashes when a bundle is unloaded and there are live Objective-C objects
// whose methods come from that bundle.
m_bundle.releaseRef();
}
}
......
......@@ -784,7 +784,7 @@ PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize&, HTMLPlugIn
// FIXME: This is Mac specific now because Windows doesn't have the necessary parts of NetscapePluginModule implemented.
#if PLATFORM(MAC)
RefPtr<NetscapePluginModule> pluginModule = NetscapePluginModule::create(pluginPath);
RefPtr<NetscapePluginModule> pluginModule = NetscapePluginModule::getOrCreate(pluginPath);
if (!pluginModule)
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment