OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/native_library.h" | 5 #include "base/native_library.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 // static | 15 // static |
16 NativeLibrary LoadNativeLibrary(const FilePath& library_path) { | 16 NativeLibrary LoadNativeLibrary(const FilePath& library_path) { |
17 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY); | 17 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY); |
18 if (!dl) { | 18 if (!dl) { |
19 LOG(ERROR) << "dlopen failed when trying to open " << library_path.value() | 19 std::string error_message = dlerror(); |
20 << ": " << dlerror(); | 20 // Some obsolete plugins depend on libxul or libxpcom. |
| 21 // Ignore the error messages when failing to load these. |
| 22 if (error_message.find("libxul.so") == std::string::npos && |
| 23 error_message.find("libxpcom.so") == std::string::npos) { |
| 24 LOG(ERROR) << "dlopen failed when trying to open " << library_path.value() |
| 25 << ": " << error_message; |
| 26 } |
21 } | 27 } |
22 | 28 |
23 return dl; | 29 return dl; |
24 } | 30 } |
25 | 31 |
26 // static | 32 // static |
27 void UnloadNativeLibrary(NativeLibrary library) { | 33 void UnloadNativeLibrary(NativeLibrary library) { |
28 int ret = dlclose(library); | 34 int ret = dlclose(library); |
29 if (ret < 0) { | 35 if (ret < 0) { |
30 LOG(ERROR) << "dlclose failed: " << dlerror(); | 36 LOG(ERROR) << "dlclose failed: " << dlerror(); |
31 NOTREACHED(); | 37 NOTREACHED(); |
32 } | 38 } |
33 } | 39 } |
34 | 40 |
35 // static | 41 // static |
36 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, | 42 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, |
37 const char* name) { | 43 const char* name) { |
38 return dlsym(library, name); | 44 return dlsym(library, name); |
39 } | 45 } |
40 | 46 |
41 // static | 47 // static |
42 string16 GetNativeLibraryName(const string16& name) { | 48 string16 GetNativeLibraryName(const string16& name) { |
43 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); | 49 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); |
44 } | 50 } |
45 | 51 |
46 } // namespace base | 52 } // namespace base |
OLD | NEW |