OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/plugin_lib.h" | 5 #include "webkit/glue/plugins/plugin_lib.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stats_counters.h" | 9 #include "base/stats_counters.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (saved_data_ != 0) { | 91 if (saved_data_ != 0) { |
92 // TODO - delete the savedData object here | 92 // TODO - delete the savedData object here |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 NPPluginFuncs* PluginLib::functions() { | 96 NPPluginFuncs* PluginLib::functions() { |
97 return &plugin_funcs_; | 97 return &plugin_funcs_; |
98 } | 98 } |
99 | 99 |
100 NPError PluginLib::NP_Initialize() { | 100 NPError PluginLib::NP_Initialize() { |
101 LOG(INFO) << "PluginLib::NP_Initialize(" << web_plugin_info_.path.value() << | 101 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
102 "): initialized=" << initialized_; | 102 << "PluginLib::NP_Initialize(" << web_plugin_info_.path.value() |
| 103 << "): initialized=" << initialized_; |
103 if (initialized_) | 104 if (initialized_) |
104 return NPERR_NO_ERROR; | 105 return NPERR_NO_ERROR; |
105 | 106 |
106 if (!Load()) | 107 if (!Load()) |
107 return NPERR_MODULE_LOAD_FAILED_ERROR; | 108 return NPERR_MODULE_LOAD_FAILED_ERROR; |
108 | 109 |
109 PluginHost* host = PluginHost::Singleton(); | 110 PluginHost* host = PluginHost::Singleton(); |
110 if (host == 0) | 111 if (host == 0) |
111 return NPERR_GENERIC_ERROR; | 112 return NPERR_GENERIC_ERROR; |
112 | 113 |
113 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 114 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
114 NPError rv = entry_points_.np_initialize(host->host_functions(), | 115 NPError rv = entry_points_.np_initialize(host->host_functions(), |
115 &plugin_funcs_); | 116 &plugin_funcs_); |
116 #else | 117 #else |
117 NPError rv = entry_points_.np_initialize(host->host_functions()); | 118 NPError rv = entry_points_.np_initialize(host->host_functions()); |
118 #if defined(OS_MACOSX) | 119 #if defined(OS_MACOSX) |
119 // On the Mac, we need to get entry points after calling np_initialize to | 120 // On the Mac, we need to get entry points after calling np_initialize to |
120 // match the behavior of other browsers. | 121 // match the behavior of other browsers. |
121 if (rv == NPERR_NO_ERROR) { | 122 if (rv == NPERR_NO_ERROR) { |
122 rv = entry_points_.np_getentrypoints(&plugin_funcs_); | 123 rv = entry_points_.np_getentrypoints(&plugin_funcs_); |
123 } | 124 } |
124 #endif // OS_MACOSX | 125 #endif // OS_MACOSX |
125 #endif | 126 #endif |
126 LOG(INFO) << "PluginLib::NP_Initialize(" << web_plugin_info_.path.value() << | 127 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
127 "): result=" << rv; | 128 << "PluginLib::NP_Initialize(" << web_plugin_info_.path.value() |
| 129 << "): result=" << rv; |
128 initialized_ = (rv == NPERR_NO_ERROR); | 130 initialized_ = (rv == NPERR_NO_ERROR); |
129 return rv; | 131 return rv; |
130 } | 132 } |
131 | 133 |
132 void PluginLib::NP_Shutdown(void) { | 134 void PluginLib::NP_Shutdown(void) { |
133 DCHECK(initialized_); | 135 DCHECK(initialized_); |
134 entry_points_.np_shutdown(); | 136 entry_points_.np_shutdown(); |
135 } | 137 } |
136 | 138 |
137 void PluginLib::PreventLibraryUnload() { | 139 void PluginLib::PreventLibraryUnload() { |
(...skipping 20 matching lines...) Expand all Loading... |
158 bool PluginLib::Load() { | 160 bool PluginLib::Load() { |
159 if (library_) | 161 if (library_) |
160 return true; | 162 return true; |
161 | 163 |
162 bool rv = false; | 164 bool rv = false; |
163 base::NativeLibrary library = 0; | 165 base::NativeLibrary library = 0; |
164 | 166 |
165 if (!internal_) { | 167 if (!internal_) { |
166 library = base::LoadNativeLibrary(web_plugin_info_.path); | 168 library = base::LoadNativeLibrary(web_plugin_info_.path); |
167 if (library == 0) { | 169 if (library == 0) { |
168 LOG_IF(INFO, PluginList::DebugPluginLoading()) | 170 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
169 << "Couldn't load plugin " << web_plugin_info_.path.value(); | 171 << "Couldn't load plugin " << web_plugin_info_.path.value(); |
170 return rv; | 172 return rv; |
171 } | 173 } |
172 | 174 |
173 #if defined(OS_MACOSX) | 175 #if defined(OS_MACOSX) |
174 // According to the WebKit source, QuickTime at least requires us to call | 176 // According to the WebKit source, QuickTime at least requires us to call |
175 // UseResFile on the plugin resources before loading. | 177 // UseResFile on the plugin resources before loading. |
176 if (library->bundle_resource_ref != -1) | 178 if (library->bundle_resource_ref != -1) |
177 UseResFile(library->bundle_resource_ref); | 179 UseResFile(library->bundle_resource_ref); |
178 #endif | 180 #endif |
(...skipping 29 matching lines...) Expand all Loading... |
208 #if !defined(OS_POSIX) | 210 #if !defined(OS_POSIX) |
209 if (entry_points_.np_getentrypoints(&plugin_funcs_) != NPERR_NO_ERROR) | 211 if (entry_points_.np_getentrypoints(&plugin_funcs_) != NPERR_NO_ERROR) |
210 rv = false; | 212 rv = false; |
211 #else | 213 #else |
212 // On Linux and Mac, we get the plugin entry points during NP_Initialize. | 214 // On Linux and Mac, we get the plugin entry points during NP_Initialize. |
213 #endif | 215 #endif |
214 } | 216 } |
215 | 217 |
216 if (!internal_) { | 218 if (!internal_) { |
217 if (rv) { | 219 if (rv) { |
218 LOG_IF(INFO, PluginList::DebugPluginLoading()) | 220 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
219 << "Plugin " << web_plugin_info_.path.value() | 221 << "Plugin " << web_plugin_info_.path.value() |
220 << " loaded successfully."; | 222 << " loaded successfully."; |
221 library_ = library; | 223 library_ = library; |
222 } else { | 224 } else { |
223 LOG_IF(INFO, PluginList::DebugPluginLoading()) | 225 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
224 << "Plugin " << web_plugin_info_.path.value() | 226 << "Plugin " << web_plugin_info_.path.value() |
225 << " failed to load, unloading."; | 227 << " failed to load, unloading."; |
226 base::UnloadNativeLibrary(library); | 228 base::UnloadNativeLibrary(library); |
227 } | 229 } |
228 } | 230 } |
229 | 231 |
230 return rv; | 232 return rv; |
231 } | 233 } |
232 | 234 |
233 // This class implements delayed NP_Shutdown and FreeLibrary on the plugin dll. | 235 // This class implements delayed NP_Shutdown and FreeLibrary on the plugin dll. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // NP_Shutdown and FreeLibrary calls at least till the next | 272 // NP_Shutdown and FreeLibrary calls at least till the next |
271 // peek message. | 273 // peek message. |
272 defer_unload = true; | 274 defer_unload = true; |
273 #endif | 275 #endif |
274 */ | 276 */ |
275 | 277 |
276 if (defer_unload) { | 278 if (defer_unload) { |
277 FreePluginLibraryTask* free_library_task = | 279 FreePluginLibraryTask* free_library_task = |
278 new FreePluginLibraryTask(skip_unload_ ? NULL : library_, | 280 new FreePluginLibraryTask(skip_unload_ ? NULL : library_, |
279 entry_points_.np_shutdown); | 281 entry_points_.np_shutdown); |
280 LOG_IF(INFO, PluginList::DebugPluginLoading()) | 282 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
281 << "Scheduling delayed unload for plugin " | 283 << "Scheduling delayed unload for plugin " |
282 << web_plugin_info_.path.value(); | 284 << web_plugin_info_.path.value(); |
283 MessageLoop::current()->PostTask(FROM_HERE, free_library_task); | 285 MessageLoop::current()->PostTask(FROM_HERE, free_library_task); |
284 } else { | 286 } else { |
285 Shutdown(); | 287 Shutdown(); |
286 if (!skip_unload_) { | 288 if (!skip_unload_) { |
287 LOG_IF(INFO, PluginList::DebugPluginLoading()) | 289 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
288 << "Unloading plugin " << web_plugin_info_.path.value(); | 290 << "Unloading plugin " << web_plugin_info_.path.value(); |
289 base::UnloadNativeLibrary(library_); | 291 base::UnloadNativeLibrary(library_); |
290 } | 292 } |
291 } | 293 } |
292 | 294 |
293 library_ = NULL; | 295 library_ = NULL; |
294 } | 296 } |
295 | 297 |
296 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { | 298 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { |
297 if ((*g_loaded_libs)[i].get() == this) { | 299 if ((*g_loaded_libs)[i].get() == this) { |
298 g_loaded_libs->erase(g_loaded_libs->begin() + i); | 300 g_loaded_libs->erase(g_loaded_libs->begin() + i); |
299 break; | 301 break; |
300 } | 302 } |
301 } | 303 } |
302 if (g_loaded_libs->empty()) { | 304 if (g_loaded_libs->empty()) { |
303 delete g_loaded_libs; | 305 delete g_loaded_libs; |
304 g_loaded_libs = NULL; | 306 g_loaded_libs = NULL; |
305 } | 307 } |
306 } | 308 } |
307 | 309 |
308 void PluginLib::Shutdown() { | 310 void PluginLib::Shutdown() { |
309 if (initialized_ && !internal_) { | 311 if (initialized_ && !internal_) { |
310 NP_Shutdown(); | 312 NP_Shutdown(); |
311 initialized_ = false; | 313 initialized_ = false; |
312 } | 314 } |
313 } | 315 } |
314 | 316 |
315 } // namespace NPAPI | 317 } // namespace NPAPI |
OLD | NEW |