| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_list.h" | 5 #include "webkit/glue/plugins/plugin_list.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "net/base/mime_util.h" | 11 #include "net/base/mime_util.h" |
| 12 #include "webkit/default_plugin/plugin_main.h" | 12 #include "webkit/default_plugin/plugin_main.h" |
| 13 #include "webkit/glue/plugins/plugin_constants_win.h" | 13 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 14 #include "webkit/glue/plugins/plugin_lib.h" | 14 #include "webkit/glue/plugins/plugin_lib.h" |
| 15 #include "webkit/glue/webkit_glue.h" | 15 #include "webkit/glue/webkit_glue.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 | 17 |
| 18 #define kNpGoogleNaClPlugin (FILE_PATH_LITERAL("npgooglenaclplugin")) | |
| 19 | |
| 20 namespace NPAPI { | 18 namespace NPAPI { |
| 21 | 19 |
| 22 base::LazyInstance<PluginList> g_singleton(base::LINKER_INITIALIZED); | 20 base::LazyInstance<PluginList> g_singleton(base::LINKER_INITIALIZED); |
| 23 | 21 |
| 24 // static | 22 // static |
| 25 PluginList* PluginList::Singleton() { | 23 PluginList* PluginList::Singleton() { |
| 26 return g_singleton.Pointer(); | 24 return g_singleton.Pointer(); |
| 27 } | 25 } |
| 28 | 26 |
| 29 bool PluginList::PluginsLoaded() { | 27 bool PluginList::PluginsLoaded() { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 mime_type.description.erase(ext); | 106 mime_type.description.erase(ext); |
| 109 } | 107 } |
| 110 } | 108 } |
| 111 | 109 |
| 112 info->mime_types.push_back(mime_type); | 110 info->mime_types.push_back(mime_type); |
| 113 } | 111 } |
| 114 | 112 |
| 115 return true; | 113 return true; |
| 116 } | 114 } |
| 117 | 115 |
| 118 PluginList::PluginList() : plugins_loaded_(false), | 116 PluginList::PluginList() : plugins_loaded_(false) { |
| 119 use_internal_nacl_(false) { | |
| 120 PlatformInit(); | 117 PlatformInit(); |
| 121 | 118 |
| 122 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
| 123 const PluginVersionInfo default_plugin = { | 120 const PluginVersionInfo default_plugin = { |
| 124 FilePath(kDefaultPluginLibraryName), | 121 FilePath(kDefaultPluginLibraryName), |
| 125 L"Default Plug-in", | 122 L"Default Plug-in", |
| 126 L"Provides functionality for installing third-party plug-ins", | 123 L"Provides functionality for installing third-party plug-ins", |
| 127 L"1", | 124 L"1", |
| 128 L"*", | 125 L"*", |
| 129 L"", | 126 L"", |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 LoadPlugin(extra_plugin_paths[i], &new_plugins); | 161 LoadPlugin(extra_plugin_paths[i], &new_plugins); |
| 165 | 162 |
| 166 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | 163 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { |
| 167 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins); | 164 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins); |
| 168 } | 165 } |
| 169 | 166 |
| 170 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | 167 for (size_t i = 0; i < directories_to_scan.size(); ++i) { |
| 171 LoadPluginsFromDir(directories_to_scan[i], &new_plugins); | 168 LoadPluginsFromDir(directories_to_scan[i], &new_plugins); |
| 172 } | 169 } |
| 173 | 170 |
| 174 if (use_internal_nacl_) { | |
| 175 LoadPlugin(FilePath(kNaClPluginLibraryName), &new_plugins); | |
| 176 } | |
| 177 | |
| 178 if (webkit_glue::IsDefaultPluginEnabled()) | 171 if (webkit_glue::IsDefaultPluginEnabled()) |
| 179 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); | 172 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); |
| 180 | 173 |
| 181 base::TimeTicks end_time = base::TimeTicks::Now(); | 174 base::TimeTicks end_time = base::TimeTicks::Now(); |
| 182 base::TimeDelta elapsed = end_time - start_time; | 175 base::TimeDelta elapsed = end_time - start_time; |
| 183 DLOG(INFO) << "Loaded plugin list in " << elapsed.InMilliseconds() << " ms."; | 176 DLOG(INFO) << "Loaded plugin list in " << elapsed.InMilliseconds() << " ms."; |
| 184 | 177 |
| 185 AutoLock lock(lock_); | 178 AutoLock lock(lock_); |
| 186 plugins_ = new_plugins; | 179 plugins_ = new_plugins; |
| 187 plugins_loaded_ = true; | 180 plugins_loaded_ = true; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 209 // to handle mimeTypes on its own. | 202 // to handle mimeTypes on its own. |
| 210 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 203 const std::string &mime_type = plugin_info.mime_types[i].mime_type; |
| 211 if (mime_type == "*" ) | 204 if (mime_type == "*" ) |
| 212 return; | 205 return; |
| 213 } | 206 } |
| 214 } | 207 } |
| 215 | 208 |
| 216 plugins->push_back(plugin_info); | 209 plugins->push_back(plugin_info); |
| 217 } | 210 } |
| 218 | 211 |
| 219 bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, | |
| 220 std::vector<WebPluginInfo>* plugins) { | |
| 221 FilePath::StringType filename = | |
| 222 StringToLowerASCII(info.path.BaseName().value()); | |
| 223 | |
| 224 // Don't load the external version of NaCl when we need to use | |
| 225 // the internal one. | |
| 226 if (use_internal_nacl_) { | |
| 227 if (std::wstring::npos != filename.find(kNpGoogleNaClPlugin)) | |
| 228 return false; | |
| 229 } | |
| 230 return PlatformShouldLoadPlugin(info, plugins); | |
| 231 } | |
| 232 | |
| 233 bool PluginList::FindPlugin(const std::string& mime_type, | 212 bool PluginList::FindPlugin(const std::string& mime_type, |
| 234 bool allow_wildcard, | 213 bool allow_wildcard, |
| 235 WebPluginInfo* info) { | 214 WebPluginInfo* info) { |
| 236 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 215 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
| 237 | 216 |
| 238 LoadPlugins(false); | 217 LoadPlugins(false); |
| 239 AutoLock lock(lock_); | 218 AutoLock lock(lock_); |
| 240 for (size_t i = 0; i < plugins_.size(); ++i) { | 219 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 241 if (SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 220 if (SupportsType(plugins_[i], mime_type, allow_wildcard)) { |
| 242 *info = plugins_[i]; | 221 *info = plugins_[i]; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 320 } |
| 342 } | 321 } |
| 343 | 322 |
| 344 return false; | 323 return false; |
| 345 } | 324 } |
| 346 | 325 |
| 347 void PluginList::Shutdown() { | 326 void PluginList::Shutdown() { |
| 348 // TODO | 327 // TODO |
| 349 } | 328 } |
| 350 | 329 |
| 351 // static | |
| 352 void PluginList::UseInternalNaCl(PluginEntryPoints* entry_points) { | |
| 353 // We access the singleton directly, and not through Singleton(), since | |
| 354 // we don't want LoadPlugins() to be called. | |
| 355 g_singleton.Pointer()->use_internal_nacl_ = true; | |
| 356 | |
| 357 const NPAPI::PluginVersionInfo nacl_plugin_info = { | |
| 358 FilePath(kNaClPluginLibraryName), | |
| 359 L"Native Client", | |
| 360 L"Statically linked NaCl", | |
| 361 L"1, 0, 0, 1", | |
| 362 L"application/x-nacl-srpc", | |
| 363 L"", | |
| 364 L"", | |
| 365 *entry_points | |
| 366 }; | |
| 367 | |
| 368 Singleton()->RegisterInternalPlugin(nacl_plugin_info); | |
| 369 } | |
| 370 | |
| 371 } // namespace NPAPI | 330 } // namespace NPAPI |
| OLD | NEW |