summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 00:56:07 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 00:56:07 +0000
commitf38e25f12f542ed26b0b9d310d2e432297520995 (patch)
tree91968df6d61551cadf4ec12152f9790e5904f1b5 /webkit
parent53e45f18ee44a3b7ace0ebf96960c1af9f8f1ae6 (diff)
downloadchromium_src-f38e25f12f542ed26b0b9d310d2e432297520995.zip
chromium_src-f38e25f12f542ed26b0b9d310d2e432297520995.tar.gz
chromium_src-f38e25f12f542ed26b0b9d310d2e432297520995.tar.bz2
plugins: move NativeLibrary into base.
NativeLibrary is used by some plugin code under chrome/. Rather than including webkit/glue there, this relocation is the smallest logical bite to take. :\ Review URL: http://codereview.chromium.org/87012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/plugins/plugin_lib.cc35
-rw-r--r--webkit/glue/plugins/plugin_lib.h32
-rw-r--r--webkit/glue/plugins/plugin_lib_linux.cc26
-rw-r--r--webkit/glue/plugins/plugin_lib_mac.mm28
-rw-r--r--webkit/glue/plugins/plugin_lib_win.cc35
5 files changed, 26 insertions, 130 deletions
diff --git a/webkit/glue/plugins/plugin_lib.cc b/webkit/glue/plugins/plugin_lib.cc
index 1479f1e..c5b2d21 100644
--- a/webkit/glue/plugins/plugin_lib.cc
+++ b/webkit/glue/plugins/plugin_lib.cc
@@ -15,6 +15,14 @@
#include "webkit/glue/plugins/plugin_host.h"
#include "webkit/glue/plugins/plugin_list.h"
+// A macro for converting string constants into appropriate
+// NativeLibraryFunctionNameTypes.
+#if defined(OS_MACOSX)
+#define NATIVE_LIBRARY_FUNCTION_NAME(x) CFSTR(x)
+#else
+#define NATIVE_LIBRARY_FUNCTION_NAME(x) x
+#endif // OS_*
+
namespace NPAPI
{
@@ -154,35 +162,36 @@ void PluginLib::CloseInstance() {
bool PluginLib::Load() {
bool rv = false;
- NativeLibrary library = 0;
+ base::NativeLibrary library = 0;
if (!internal_) {
if (library_ != 0)
return rv;
- library = LoadNativeLibrary(web_plugin_info_.path);
+ library = base::LoadNativeLibrary(web_plugin_info_.path);
if (library == 0)
return rv;
rv = true; // assume success now
entry_points_.np_initialize =
- (NP_InitializeFunc)GetFunctionPointerFromNativeLibrary(library,
- FUNCTION_NAME("NP_Initialize"));
+ (NP_InitializeFunc)base::GetFunctionPointerFromNativeLibrary(library,
+ NATIVE_LIBRARY_FUNCTION_NAME("NP_Initialize"));
if (entry_points_.np_initialize == 0)
rv = false;
#if !defined(OS_LINUX)
entry_points_.np_getentrypoints =
- (NP_GetEntryPointsFunc)GetFunctionPointerFromNativeLibrary(library,
- FUNCTION_NAME("NP_GetEntryPoints"));
+ (NP_GetEntryPointsFunc)base::GetFunctionPointerFromNativeLibrary(
+ library,
+ NATIVE_LIBRARY_FUNCTION_NAME("NP_GetEntryPoints"));
if (entry_points_.np_getentrypoints == 0)
rv = false;
#endif
entry_points_.np_shutdown =
- (NP_ShutdownFunc)GetFunctionPointerFromNativeLibrary(library,
- FUNCTION_NAME("NP_Shutdown"));
+ (NP_ShutdownFunc)base::GetFunctionPointerFromNativeLibrary(library,
+ NATIVE_LIBRARY_FUNCTION_NAME("NP_Shutdown"));
if (entry_points_.np_shutdown == 0)
rv = false;
} else {
@@ -204,7 +213,7 @@ bool PluginLib::Load() {
if (rv)
library_ = library;
else
- UnloadNativeLibrary(library);
+ base::UnloadNativeLibrary(library);
}
return rv;
@@ -213,7 +222,7 @@ bool PluginLib::Load() {
// This class implements delayed NP_Shutdown and FreeLibrary on the plugin dll.
class FreePluginLibraryTask : public Task {
public:
- FreePluginLibraryTask(PluginLib::NativeLibrary library,
+ FreePluginLibraryTask(base::NativeLibrary library,
NP_ShutdownFunc shutdown_func)
: library_(library),
NP_Shutdown_(shutdown_func) {
@@ -226,13 +235,13 @@ class FreePluginLibraryTask : public Task {
NP_Shutdown_();
if (library_) {
- PluginLib::UnloadNativeLibrary(library_);
+ base::UnloadNativeLibrary(library_);
library_ = NULL;
}
}
private:
- PluginLib::NativeLibrary library_;
+ base::NativeLibrary library_;
NP_ShutdownFunc NP_Shutdown_;
DISALLOW_EVIL_CONSTRUCTORS(FreePluginLibraryTask);
};
@@ -257,7 +266,7 @@ void PluginLib::Unload() {
MessageLoop::current()->PostTask(FROM_HERE, free_library_task);
} else {
Shutdown();
- UnloadNativeLibrary(library_);
+ base::UnloadNativeLibrary(library_);
}
library_ = 0;
diff --git a/webkit/glue/plugins/plugin_lib.h b/webkit/glue/plugins/plugin_lib.h
index 0b44212..46b5b01 100644
--- a/webkit/glue/plugins/plugin_lib.h
+++ b/webkit/glue/plugins/plugin_lib.h
@@ -5,13 +5,12 @@
#ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_LIB_H__
#define WEBKIT_GLUE_PLUGIN_PLUGIN_LIB_H__
-#include "build/build_config.h"
-
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/file_path.h"
+#include "base/native_library.h"
#include "base/ref_counted.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/webplugin.h"
@@ -83,37 +82,10 @@ class PluginLib : public base::RefCounted<PluginLib> {
// Shutdown the plugin library.
void Shutdown();
- public:
-#if defined(OS_WIN)
- typedef HMODULE NativeLibrary;
- typedef char* NativeLibraryFunctionNameType;
-#define FUNCTION_NAME(x) x
-#elif defined(OS_MACOSX)
- typedef CFBundleRef NativeLibrary;
- typedef CFStringRef NativeLibraryFunctionNameType;
-#define FUNCTION_NAME(x) CFSTR(x)
-#elif defined(OS_LINUX)
- typedef void* NativeLibrary;
- typedef const char* NativeLibraryFunctionNameType;
-#define FUNCTION_NAME(x) x
-#endif // OS_*
-
- // Loads a native library from disk. NOTE: You must release it with
- // UnloadNativeLibrary when you're done.
- static NativeLibrary LoadNativeLibrary(const FilePath& library_path);
-
- // Unloads a native library.
- static void UnloadNativeLibrary(NativeLibrary library);
-
private:
- // Gets a function pointer from a native library.
- static void* GetFunctionPointerFromNativeLibrary(
- NativeLibrary library,
- NativeLibraryFunctionNameType name);
-
bool internal_; // Whether this an internal plugin.
WebPluginInfo web_plugin_info_; // supported mime types, description
- NativeLibrary library_; // the opened library reference
+ base::NativeLibrary library_; // the opened library reference
NPPluginFuncs plugin_funcs_; // the struct of plugin side functions
bool initialized_; // is the plugin initialized
NPSavedData *saved_data_; // persisted plugin info for NPAPI
diff --git a/webkit/glue/plugins/plugin_lib_linux.cc b/webkit/glue/plugins/plugin_lib_linux.cc
index 36de951..c88ffee 100644
--- a/webkit/glue/plugins/plugin_lib_linux.cc
+++ b/webkit/glue/plugins/plugin_lib_linux.cc
@@ -19,36 +19,12 @@
namespace NPAPI {
-// static
-PluginLib::NativeLibrary PluginLib::LoadNativeLibrary(
- const FilePath& library_path) {
- void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY);
- if (!dl)
- NOTREACHED() << "dlopen failed: " << dlerror();
-
- return dl;
-}
-
-// static
-void PluginLib::UnloadNativeLibrary(NativeLibrary library) {
- int ret = dlclose(library);
- if (ret < 0)
- NOTREACHED() << "dlclose failed: " << dlerror();
-}
-
-// static
-void* PluginLib::GetFunctionPointerFromNativeLibrary(
- NativeLibrary library,
- NativeLibraryFunctionNameType name) {
- return dlsym(library, name);
-}
-
bool PluginLib::ReadWebPluginInfo(const FilePath& filename,
WebPluginInfo* info) {
// The file to reference is:
// http://mxr.mozilla.org/firefox/source/modules/plugin/base/src/nsPluginsDirUnix.cpp
- void* dl = LoadNativeLibrary(filename);
+ void* dl = base::LoadNativeLibrary(filename);
if (!dl)
return false;
diff --git a/webkit/glue/plugins/plugin_lib_mac.mm b/webkit/glue/plugins/plugin_lib_mac.mm
index a12a626..04510a4 100644
--- a/webkit/glue/plugins/plugin_lib_mac.mm
+++ b/webkit/glue/plugins/plugin_lib_mac.mm
@@ -20,32 +20,6 @@ static const short kSTRPluginDescriptionResourceID = 126;
namespace NPAPI
{
-/* static */
-PluginLib::NativeLibrary PluginLib::LoadNativeLibrary(
- const FilePath& library_path) {
- scoped_cftyperef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(
- kCFAllocatorDefault,
- (const UInt8*)library_path.value().c_str(),
- library_path.value().length(),
- true));
- if (!url)
- return NULL;
-
- return CFBundleCreate(kCFAllocatorDefault, url.get());
-}
-
-/* static */
-void PluginLib::UnloadNativeLibrary(NativeLibrary library) {
- CFRelease(library);
-}
-
-/* static */
-void* PluginLib::GetFunctionPointerFromNativeLibrary(
- NativeLibrary library,
- NativeLibraryFunctionNameType name) {
- return CFBundleGetFunctionPointerForName(library, name);
-}
-
namespace {
NSDictionary* GetMIMETypes(CFBundleRef bundle) {
@@ -322,7 +296,7 @@ bool PluginLib::ReadWebPluginInfo(const FilePath &filename,
//
// Strictly speaking, only STR# 128 is required.
- scoped_cftyperef<CFBundleRef> bundle(LoadNativeLibrary(filename));
+ scoped_cftyperef<CFBundleRef> bundle(base::LoadNativeLibrary(filename));
if (!bundle)
return false;
diff --git a/webkit/glue/plugins/plugin_lib_win.cc b/webkit/glue/plugins/plugin_lib_win.cc
index 208896a..18a687d 100644
--- a/webkit/glue/plugins/plugin_lib_win.cc
+++ b/webkit/glue/plugins/plugin_lib_win.cc
@@ -13,41 +13,6 @@
namespace NPAPI
{
-
-/* static */
-PluginLib::NativeLibrary PluginLib::LoadNativeLibrary(
- const FilePath& library_path) {
- // Switch the current directory to the plugin directory as the plugin
- // may have dependencies on dlls in this directory.
- bool restore_directory = false;
- std::wstring current_directory;
- if (PathService::Get(base::DIR_CURRENT, &current_directory)) {
- FilePath plugin_path = library_path.DirName();
- if (!plugin_path.value().empty()) {
- PathService::SetCurrentDirectory(plugin_path.value());
- restore_directory = true;
- }
- }
-
- HMODULE module = LoadLibrary(library_path.value().c_str());
- if (restore_directory)
- PathService::SetCurrentDirectory(current_directory);
-
- return module;
-}
-
-/* static */
-void PluginLib::UnloadNativeLibrary(NativeLibrary library) {
- FreeLibrary(library);
-}
-
-/* static */
-void* PluginLib::GetFunctionPointerFromNativeLibrary(
- NativeLibrary library,
- NativeLibraryFunctionNameType name) {
- return GetProcAddress(library, name);
-}
-
bool PluginLib::ReadWebPluginInfo(const FilePath &filename,
WebPluginInfo* info) {
// On windows, the way we get the mime types for the library is