Skip to content
Permalink
Browse files
Move bundle-loading code from NetscapePluginModule to a new Module class
This allows more NetscapePluginModule code to be cross-platform.

Fixes <http://webkit.org/b/43497> NetscapePluginModule::try/unload
should be cross-platform

Reviewed by Anders Carlsson.

* Platform/Module.cpp: Added.
(WebKit::Module::Module): Store our path.
(WebKit::Module::~Module): Unload our native module.

* Platform/Module.h: Added.
(WebKit::Module::leakBundle): Does what it says.
(WebKit::Module::functionPointer): Returns a pointer to the named
function, with the right type.

* Platform/mac/ModuleMac.mm: Added.
(WebKit::Module::load): Code was moved here from
NetscapePluginModule::tryLoad.
(WebKit::Module::unload): Just clears our bundle.
(WebKit::Module::platformFunctionPointer): Code was moved here from
NetscapePluginModuleMac.cpp.

* Platform/qt/ModuleQt.cpp: Added.
(WebKit::Module::load):
(WebKit::Module::unload):
(WebKit::Module::platformFunctionPointer):
* Platform/win/ModuleWin.cpp: Added.
(WebKit::Module::load):
(WebKit::Module::unload):
(WebKit::Module::platformFunctionPointer):
Just stubbed out these functions.

* WebKit2.xcodeproj/project.pbxproj: Added Module.

* WebProcess/Plugins/Netscape/NetscapePluginModule.cpp:
(WebKit::NetscapePluginModule::tryLoad):
(WebKit::NetscapePluginModule::unload):
Moved here from NetscapePluginModuleMac.cpp. Now uses the
cross-platform m_module member.

* WebProcess/Plugins/Netscape/NetscapePluginModule.h: Replaced
m_bundle with m_module.

* WebProcess/Plugins/Netscape/mac/NetscapePluginModuleMac.cpp: Removed.

* win/WebKit2.vcproj: Added Module.

Canonical link: https://commits.webkit.org/55485@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@64663 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aroben committed Aug 4, 2010
1 parent 5b895ca commit 63a94295c5df4416b2328c2b77a3f28ea0a681ac
@@ -1,3 +1,56 @@
2010-08-04 Adam Roben <aroben@apple.com>

Move bundle-loading code from NetscapePluginModule to a new Module
class

This allows more NetscapePluginModule code to be cross-platform.

Fixes <http://webkit.org/b/43497> NetscapePluginModule::try/unload
should be cross-platform

Reviewed by Anders Carlsson.

* Platform/Module.cpp: Added.
(WebKit::Module::Module): Store our path.
(WebKit::Module::~Module): Unload our native module.

* Platform/Module.h: Added.
(WebKit::Module::leakBundle): Does what it says.
(WebKit::Module::functionPointer): Returns a pointer to the named
function, with the right type.

* Platform/mac/ModuleMac.mm: Added.
(WebKit::Module::load): Code was moved here from
NetscapePluginModule::tryLoad.
(WebKit::Module::unload): Just clears our bundle.
(WebKit::Module::platformFunctionPointer): Code was moved here from
NetscapePluginModuleMac.cpp.

* Platform/qt/ModuleQt.cpp: Added.
(WebKit::Module::load):
(WebKit::Module::unload):
(WebKit::Module::platformFunctionPointer):
* Platform/win/ModuleWin.cpp: Added.
(WebKit::Module::load):
(WebKit::Module::unload):
(WebKit::Module::platformFunctionPointer):
Just stubbed out these functions.

* WebKit2.xcodeproj/project.pbxproj: Added Module.

* WebProcess/Plugins/Netscape/NetscapePluginModule.cpp:
(WebKit::NetscapePluginModule::tryLoad):
(WebKit::NetscapePluginModule::unload):
Moved here from NetscapePluginModuleMac.cpp. Now uses the
cross-platform m_module member.

* WebProcess/Plugins/Netscape/NetscapePluginModule.h: Replaced
m_bundle with m_module.

* WebProcess/Plugins/Netscape/mac/NetscapePluginModuleMac.cpp: Removed.

* win/WebKit2.vcproj: Added Module.

2010-08-04 Brady Eidson <beidson@apple.com>

Reviewed by Sam Weinig.
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "Module.h"

using namespace WebCore;

namespace WebKit {

Module::Module(const String& path)
: m_path(path)
{
}

Module::~Module()
{
unload();
}

}
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef Module_h
#define Module_h

#include <WebCore/PlatformString.h>
#include <wtf/Noncopyable.h>

#if PLATFORM(MAC)
#include <wtf/RetainPtr.h>
#endif

namespace WebKit {

class Module : public Noncopyable {
public:
Module(const WebCore::String& path);
~Module();

bool load();
// Note: On Mac this leaks the CFBundle to avoid crashes when a bundle is unloaded and there are
// live Objective-C objects whose methods come from that bundle.
void unload();

template<typename FunctionType> FunctionType functionPointer(const char* functionName) const;

private:
void* platformFunctionPointer(const char* functionName) const;

WebCore::String m_path;
#if PLATFORM(MAC)
RetainPtr<CFBundleRef> m_bundle;
#endif
};

template<typename FunctionType> FunctionType Module::functionPointer(const char* functionName) const
{
return reinterpret_cast<FunctionType>(platformFunctionPointer(functionName));
}

}

#endif
@@ -23,62 +23,40 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "NetscapePluginModule.h"
#include "NetscapeBrowserFuncs.h"
#include "Module.h"

namespace WebKit {

void NetscapePluginModule::unload()
bool Module::load()
{
if (m_bundle) {
// 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();
}
}

template<typename FuncType>
static inline FuncType pointerToFunction(CFBundleRef bundle, const char* functionName)
{
RetainPtr<CFStringRef> functionNameString(AdoptCF, CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, functionName, kCFStringEncodingASCII, kCFAllocatorNull));
return reinterpret_cast<FuncType>(CFBundleGetFunctionPointerForName(bundle, functionNameString.get()));
}

bool NetscapePluginModule::tryLoad()
{
RetainPtr<CFStringRef> bundlePath(AdoptCF, m_pluginPath.createCFString());
RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(0, bundlePath.get(), kCFURLPOSIXPathStyle, FALSE));
RetainPtr<CFStringRef> bundlePath(AdoptCF, m_path.createCFString());
RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, bundlePath.get(), kCFURLPOSIXPathStyle, FALSE));
if (!bundleURL)
return false;

m_bundle.adoptCF(CFBundleCreate(kCFAllocatorDefault, bundleURL.get()));
if (!m_bundle)
return false;

if (!CFBundleLoadExecutable(m_bundle.get()))
RetainPtr<CFBundleRef> bundle(AdoptCF, CFBundleCreate(kCFAllocatorDefault, bundleURL.get()));
if (!bundle)
return false;

NP_InitializeFuncPtr initializeFuncPtr = pointerToFunction<NP_InitializeFuncPtr>(m_bundle.get(), "NP_Initialize");
if (!initializeFuncPtr)
if (!CFBundleLoadExecutable(bundle.get()))
return false;

NP_GetEntryPointsFuncPtr getEntryPointsFuncPtr = pointerToFunction<NP_GetEntryPointsFuncPtr>(m_bundle.get(), "NP_GetEntryPoints");
if (!getEntryPointsFuncPtr)
return false;

m_shutdownProcPtr = pointerToFunction<NPP_ShutdownProcPtr>(m_bundle.get(), "NP_Shutdown");
if (!m_shutdownProcPtr)
return false;
m_bundle.adoptCF(bundle.releaseRef());
return true;
}

if (initializeFuncPtr(netscapeBrowserFuncs()) != NPERR_NO_ERROR)
return false;

m_pluginFuncs.size = sizeof(NPPluginFuncs);
m_pluginFuncs.version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
if (getEntryPointsFuncPtr(&m_pluginFuncs) != NPERR_NO_ERROR)
return false;
void Module::unload()
{
// See the comment in Module.h for why we leak the bundle here.
m_bundle.releaseRef();
}

return true;
void* Module::platformFunctionPointer(const char* functionName) const
{
if (!m_bundle)
return 0;
RetainPtr<CFStringRef> functionNameString(AdoptCF, CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, functionName, kCFStringEncodingASCII, kCFAllocatorNull));
return CFBundleGetFunctionPointerForName(m_bundle.get(), functionNameString.get());
}

} // namespace WebKit
}
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "Module.h"

#include "NotImplemented.h"

namespace WebKit {

bool Module::load()
{
notImplemented();
return false;
}

void Module::unload()
{
notImplemented();
}

void* Module::platformFunctionPointer(const char* functionName) const
{
notImplemented();
return 0;
}

}
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "Module.h"

#include "NotImplemented.h"

namespace WebKit {

bool Module::load()
{
notImplemented();
return false;
}

void Module::unload()
{
notImplemented();
}

void* Module::platformFunctionPointer(const char* functionName) const
{
notImplemented();
return 0;
}

}

0 comments on commit 63a9429

Please sign in to comment.