summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.gyp4
-rw-r--r--base/native_library.h47
-rw-r--r--base/native_library_linux.cc36
-rw-r--r--base/native_library_mac.mm38
-rw-r--r--base/native_library_win.cc46
-rw-r--r--chrome/plugin/plugin_thread.cc2
-rw-r--r--chrome/plugin/plugin_thread.h3
-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
12 files changed, 200 insertions, 132 deletions
diff --git a/base/base.gyp b/base/base.gyp
index e7c6adb..3180c70 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -162,6 +162,10 @@
'message_pump_mac.mm',
'message_pump_win.cc',
'message_pump_win.h',
+ 'native_library.h',
+ 'native_library_linux.cc',
+ 'native_library_mac.mm',
+ 'native_library_win.cc',
'non_thread_safe.cc',
'non_thread_safe.h',
'nss_init.cc',
diff --git a/base/native_library.h b/base/native_library.h
new file mode 100644
index 0000000..ce85c23
--- /dev/null
+++ b/base/native_library.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_NATIVE_LIBRARY_H_
+#define BASE_NATIVE_LIBRARY_H_
+
+// This file defines a cross-platform "NativeLibrary" type which represents
+// a loadable module.
+
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+#elif defined(OS_MACOSX)
+#import <Carbon/Carbon.h>
+#endif // OS_*
+
+class FilePath;
+
+namespace base {
+
+#if defined(OS_WIN)
+typedef HMODULE NativeLibrary;
+typedef char* NativeLibraryFunctionNameType;
+#elif defined(OS_MACOSX)
+typedef CFBundleRef NativeLibrary;
+typedef CFStringRef NativeLibraryFunctionNameType;
+#elif defined(OS_LINUX)
+typedef void* NativeLibrary;
+typedef const char* NativeLibraryFunctionNameType;
+#endif // OS_*
+
+// Loads a native library from disk. Release it with UnloadNativeLibrary when
+// you're done.
+NativeLibrary LoadNativeLibrary(const FilePath& library_path);
+
+// Unloads a native library.
+void UnloadNativeLibrary(NativeLibrary library);
+
+// Gets a function pointer from a native library.
+void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
+ NativeLibraryFunctionNameType name);
+
+} // namespace base
+
+#endif // BASE_NATIVE_LIBRARY_H_
diff --git a/base/native_library_linux.cc b/base/native_library_linux.cc
new file mode 100644
index 0000000..1ec7aab
--- /dev/null
+++ b/base/native_library_linux.cc
@@ -0,0 +1,36 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/native_library.h"
+
+#include <dlfcn.h>
+
+#include "base/file_path.h"
+#include "base/logging.h"
+
+namespace base {
+
+// static
+NativeLibrary 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 UnloadNativeLibrary(NativeLibrary library) {
+ int ret = dlclose(library);
+ if (ret < 0)
+ NOTREACHED() << "dlclose failed: " << dlerror();
+}
+
+// static
+void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
+ NativeLibraryFunctionNameType name) {
+ return dlsym(library, name);
+}
+
+} // namespace base
diff --git a/base/native_library_mac.mm b/base/native_library_mac.mm
new file mode 100644
index 0000000..f817a01
--- /dev/null
+++ b/base/native_library_mac.mm
@@ -0,0 +1,38 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/native_library.h"
+
+#import <Carbon/Carbon.h>
+
+#include "base/file_path.h"
+#include "base/scoped_cftyperef.h"
+
+namespace base {
+
+// static
+NativeLibrary 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 UnloadNativeLibrary(NativeLibrary library) {
+ CFRelease(library);
+}
+
+// static
+void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
+ NativeLibraryFunctionNameType name) {
+ return CFBundleGetFunctionPointerForName(library, name);
+}
+
+} // namespace base
diff --git a/base/native_library_win.cc b/base/native_library_win.cc
new file mode 100644
index 0000000..cf477fe
--- /dev/null
+++ b/base/native_library_win.cc
@@ -0,0 +1,46 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/native_library.h"
+
+#include <windows.h>
+
+#include "base/file_path.h"
+#include "base/path_service.h"
+
+namespace base {
+
+// static
+NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
+ // Switch the current directory to the library directory as the library
+ // 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 UnloadNativeLibrary(NativeLibrary library) {
+ FreeLibrary(library);
+}
+
+// static
+void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
+ NativeLibraryFunctionNameType name) {
+ return GetProcAddress(library, name);
+}
+
+} // namespace base
diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc
index fe9aa02..3b7c614 100644
--- a/chrome/plugin/plugin_thread.cc
+++ b/chrome/plugin/plugin_thread.cc
@@ -51,7 +51,7 @@ void PluginThread::Init() {
notification_service_.reset(new NotificationService);
// Preload the library to avoid loading, unloading then reloading
- preloaded_plugin_module_ = NPAPI::PluginLib::LoadNativeLibrary(plugin_path_);
+ preloaded_plugin_module_ = base::LoadNativeLibrary(plugin_path_);
ChromePluginLib::Create(plugin_path_, GetCPBrowserFuncsForPlugin());
diff --git a/chrome/plugin/plugin_thread.h b/chrome/plugin/plugin_thread.h
index 9b999e2..a110a2c 100644
--- a/chrome/plugin/plugin_thread.h
+++ b/chrome/plugin/plugin_thread.h
@@ -6,6 +6,7 @@
#define CHROME_PLUGIN_PLUGIN_THREAD_H_
#include "base/file_path.h"
+#include "base/native_library.h"
#include "chrome/common/child_thread.h"
#include "chrome/plugin/plugin_channel.h"
@@ -35,7 +36,7 @@ class PluginThread : public ChildThread {
scoped_ptr<NotificationService> notification_service_;
// The plugin module which is preloaded in Init
- HMODULE preloaded_plugin_module_;
+ base::NativeLibrary preloaded_plugin_module_;
// Points to the plugin file that this process hosts.
FilePath plugin_path_;
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