| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/plugin_list.h" | 5 #include "content/common/plugin_list.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "net/base/mime_util.h" | 16 #include "net/base/mime_util.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 #include "webkit/plugins/npapi/plugin_utils.h" | |
| 19 #include "webkit/plugins/plugin_switches.h" | 18 #include "webkit/plugins/plugin_switches.h" |
| 20 | 19 |
| 21 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 22 #include "content/common/plugin_constants_win.h" | 21 #include "content/common/plugin_constants_win.h" |
| 23 #endif | 22 #endif |
| 24 | 23 |
| 25 using webkit::WebPluginInfo; | 24 using webkit::WebPluginInfo; |
| 26 using webkit::WebPluginMimeType; | 25 using webkit::WebPluginMimeType; |
| 27 | 26 |
| 28 namespace content { | 27 namespace content { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 void PluginList::DisablePluginsDiscovery() { | 69 void PluginList::DisablePluginsDiscovery() { |
| 71 plugins_discovery_disabled_ = true; | 70 plugins_discovery_disabled_ = true; |
| 72 } | 71 } |
| 73 | 72 |
| 74 void PluginList::RefreshPlugins() { | 73 void PluginList::RefreshPlugins() { |
| 75 base::AutoLock lock(lock_); | 74 base::AutoLock lock(lock_); |
| 76 loading_state_ = LOADING_STATE_NEEDS_REFRESH; | 75 loading_state_ = LOADING_STATE_NEEDS_REFRESH; |
| 77 } | 76 } |
| 78 | 77 |
| 79 void PluginList::AddExtraPluginPath(const base::FilePath& plugin_path) { | 78 void PluginList::AddExtraPluginPath(const base::FilePath& plugin_path) { |
| 80 if (!webkit::npapi::NPAPIPluginsSupported()) { | |
| 81 // TODO(jam): remove and just have CHECK once we're sure this doesn't get | |
| 82 // triggered. | |
| 83 DLOG(INFO) << "NPAPI plugins not supported"; | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 // Chrome OS only loads plugins from /opt/google/chrome/plugins. | 79 // Chrome OS only loads plugins from /opt/google/chrome/plugins. |
| 88 #if !defined(OS_CHROMEOS) | 80 #if !defined(OS_CHROMEOS) |
| 89 base::AutoLock lock(lock_); | 81 base::AutoLock lock(lock_); |
| 90 extra_plugin_paths_.push_back(plugin_path); | 82 extra_plugin_paths_.push_back(plugin_path); |
| 91 #endif | 83 #endif |
| 92 } | 84 } |
| 93 | 85 |
| 94 void PluginList::RemoveExtraPluginPath(const base::FilePath& plugin_path) { | 86 void PluginList::RemoveExtraPluginPath(const base::FilePath& plugin_path) { |
| 95 base::AutoLock lock(lock_); | 87 base::AutoLock lock(lock_); |
| 96 std::vector<base::FilePath>::iterator it = | 88 std::vector<base::FilePath>::iterator it = |
| 97 std::find(extra_plugin_paths_.begin(), extra_plugin_paths_.end(), | 89 std::find(extra_plugin_paths_.begin(), extra_plugin_paths_.end(), |
| 98 plugin_path); | 90 plugin_path); |
| 99 if (it != extra_plugin_paths_.end()) | 91 if (it != extra_plugin_paths_.end()) |
| 100 extra_plugin_paths_.erase(it); | 92 extra_plugin_paths_.erase(it); |
| 101 } | 93 } |
| 102 | 94 |
| 103 void PluginList::AddExtraPluginDir(const base::FilePath& plugin_dir) { | 95 void PluginList::AddExtraPluginDir(const base::FilePath& plugin_dir) { |
| 104 // Chrome OS only loads plugins from /opt/google/chrome/plugins. | 96 // Chrome OS only loads plugins from /opt/google/chrome/plugins. |
| 105 #if !defined(OS_CHROMEOS) | 97 #if !defined(OS_CHROMEOS) |
| 106 base::AutoLock lock(lock_); | 98 base::AutoLock lock(lock_); |
| 107 extra_plugin_dirs_.push_back(plugin_dir); | 99 extra_plugin_dirs_.push_back(plugin_dir); |
| 108 #endif | 100 #endif |
| 109 } | 101 } |
| 110 | 102 |
| 111 void PluginList::RegisterInternalPlugin(const webkit::WebPluginInfo& info, | 103 void PluginList::RegisterInternalPlugin(const webkit::WebPluginInfo& info, |
| 112 bool add_at_beginning) { | 104 bool add_at_beginning) { |
| 113 if (!webkit::npapi::NPAPIPluginsSupported() && | |
| 114 info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) { | |
| 115 DLOG(INFO) << "Don't register NPAPI plugins when they're not supported"; | |
| 116 return; | |
| 117 } | |
| 118 | |
| 119 base::AutoLock lock(lock_); | 105 base::AutoLock lock(lock_); |
| 120 | 106 |
| 121 internal_plugins_.push_back(info); | 107 internal_plugins_.push_back(info); |
| 122 if (add_at_beginning) { | 108 if (add_at_beginning) { |
| 123 // Newer registrations go earlier in the list so they can override the MIME | 109 // Newer registrations go earlier in the list so they can override the MIME |
| 124 // types of older registrations. | 110 // types of older registrations. |
| 125 extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path); | 111 extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path); |
| 126 } else { | 112 } else { |
| 127 extra_plugin_paths_.push_back(info.path); | 113 extra_plugin_paths_.push_back(info.path); |
| 128 } | 114 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 194 } |
| 209 | 195 |
| 210 return true; | 196 return true; |
| 211 } | 197 } |
| 212 | 198 |
| 213 PluginList::PluginList() | 199 PluginList::PluginList() |
| 214 : loading_state_(LOADING_STATE_NEEDS_REFRESH), | 200 : loading_state_(LOADING_STATE_NEEDS_REFRESH), |
| 215 plugins_discovery_disabled_(false) { | 201 plugins_discovery_disabled_(false) { |
| 216 } | 202 } |
| 217 | 203 |
| 218 void PluginList::LoadPluginsIntoPluginListInternal( | 204 void PluginList::LoadPlugins(bool include_npapi) { |
| 219 std::vector<webkit::WebPluginInfo>* plugins) { | 205 { |
| 206 base::AutoLock lock(lock_); |
| 207 if (loading_state_ == LOADING_STATE_UP_TO_DATE) |
| 208 return; |
| 209 |
| 210 loading_state_ = LOADING_STATE_REFRESHING; |
| 211 } |
| 212 |
| 213 std::vector<webkit::WebPluginInfo> new_plugins; |
| 220 base::Closure will_load_callback; | 214 base::Closure will_load_callback; |
| 221 { | 215 { |
| 222 base::AutoLock lock(lock_); | 216 base::AutoLock lock(lock_); |
| 223 will_load_callback = will_load_plugins_callback_; | 217 will_load_callback = will_load_plugins_callback_; |
| 224 } | 218 } |
| 225 if (!will_load_callback.is_null()) | 219 if (!will_load_callback.is_null()) |
| 226 will_load_callback.Run(); | 220 will_load_callback.Run(); |
| 227 | 221 |
| 228 std::vector<base::FilePath> plugin_paths; | 222 std::vector<base::FilePath> plugin_paths; |
| 229 GetPluginPathsToLoad(&plugin_paths); | 223 GetPluginPathsToLoad(&plugin_paths, include_npapi); |
| 230 | 224 |
| 231 for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); | 225 for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); |
| 232 it != plugin_paths.end(); | 226 it != plugin_paths.end(); |
| 233 ++it) { | 227 ++it) { |
| 234 WebPluginInfo plugin_info; | 228 WebPluginInfo plugin_info; |
| 235 LoadPluginIntoPluginList(*it, plugins, &plugin_info); | 229 LoadPluginIntoPluginList(*it, &new_plugins, &plugin_info); |
| 236 } | 230 } |
| 237 } | |
| 238 | |
| 239 void PluginList::LoadPlugins() { | |
| 240 { | |
| 241 base::AutoLock lock(lock_); | |
| 242 if (loading_state_ == LOADING_STATE_UP_TO_DATE) | |
| 243 return; | |
| 244 | |
| 245 loading_state_ = LOADING_STATE_REFRESHING; | |
| 246 } | |
| 247 | |
| 248 std::vector<webkit::WebPluginInfo> new_plugins; | |
| 249 // Do the actual loading of the plugins. | |
| 250 LoadPluginsIntoPluginListInternal(&new_plugins); | |
| 251 | 231 |
| 252 base::AutoLock lock(lock_); | 232 base::AutoLock lock(lock_); |
| 253 plugins_list_.swap(new_plugins); | 233 plugins_list_.swap(new_plugins); |
| 254 | 234 |
| 255 // If we haven't been invalidated in the mean time, mark the plug-in list as | 235 // If we haven't been invalidated in the mean time, mark the plug-in list as |
| 256 // up-to-date. | 236 // up-to-date. |
| 257 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) | 237 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) |
| 258 loading_state_ = LOADING_STATE_UP_TO_DATE; | 238 loading_state_ = LOADING_STATE_UP_TO_DATE; |
| 259 } | 239 } |
| 260 | 240 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 280 // to handle mimeTypes on its own. | 260 // to handle mimeTypes on its own. |
| 281 const std::string &mime_type = plugin_info->mime_types[i].mime_type; | 261 const std::string &mime_type = plugin_info->mime_types[i].mime_type; |
| 282 if (mime_type == "*") | 262 if (mime_type == "*") |
| 283 return false; | 263 return false; |
| 284 } | 264 } |
| 285 } | 265 } |
| 286 plugins->push_back(*plugin_info); | 266 plugins->push_back(*plugin_info); |
| 287 return true; | 267 return true; |
| 288 } | 268 } |
| 289 | 269 |
| 290 void PluginList::GetPluginPathsToLoad(std::vector<base::FilePath>* plugin_paths)
{ | 270 void PluginList::GetPluginPathsToLoad(std::vector<base::FilePath>* plugin_paths, |
| 271 bool include_npapi) { |
| 291 // Don't want to hold the lock while loading new plugins, so we don't block | 272 // Don't want to hold the lock while loading new plugins, so we don't block |
| 292 // other methods if they're called on other threads. | 273 // other methods if they're called on other threads. |
| 293 std::vector<base::FilePath> extra_plugin_paths; | 274 std::vector<base::FilePath> extra_plugin_paths; |
| 294 std::vector<base::FilePath> extra_plugin_dirs; | 275 std::vector<base::FilePath> extra_plugin_dirs; |
| 295 { | 276 { |
| 296 base::AutoLock lock(lock_); | 277 base::AutoLock lock(lock_); |
| 297 extra_plugin_paths = extra_plugin_paths_; | 278 extra_plugin_paths = extra_plugin_paths_; |
| 298 extra_plugin_dirs = extra_plugin_dirs_; | 279 extra_plugin_dirs = extra_plugin_dirs_; |
| 299 } | 280 } |
| 300 | 281 |
| 301 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | 282 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { |
| 302 const base::FilePath& path = extra_plugin_paths[i]; | 283 const base::FilePath& path = extra_plugin_paths[i]; |
| 303 if (std::find(plugin_paths->begin(), plugin_paths->end(), path) != | 284 if (std::find(plugin_paths->begin(), plugin_paths->end(), path) != |
| 304 plugin_paths->end()) { | 285 plugin_paths->end()) { |
| 305 continue; | 286 continue; |
| 306 } | 287 } |
| 307 plugin_paths->push_back(path); | 288 plugin_paths->push_back(path); |
| 308 } | 289 } |
| 309 | 290 |
| 310 if (webkit::npapi::NPAPIPluginsSupported()) { | 291 if (include_npapi) { |
| 311 // A bit confusingly, this function is used to load Pepper plugins as well. | 292 // A bit confusingly, this function is used to load Pepper plugins as well. |
| 312 // Those are all internal plugins so we have to use extra_plugin_paths. | 293 // Those are all internal plugins so we have to use extra_plugin_paths. |
| 313 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) | 294 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) |
| 314 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths); | 295 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths); |
| 315 | 296 |
| 316 std::vector<base::FilePath> directories_to_scan; | 297 std::vector<base::FilePath> directories_to_scan; |
| 317 GetPluginDirectories(&directories_to_scan); | 298 GetPluginDirectories(&directories_to_scan); |
| 318 for (size_t i = 0; i < directories_to_scan.size(); ++i) | 299 for (size_t i = 0; i < directories_to_scan.size(); ++i) |
| 319 GetPluginsInDir(directories_to_scan[i], plugin_paths); | 300 GetPluginsInDir(directories_to_scan[i], plugin_paths); |
| 320 | 301 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 332 | 313 |
| 333 plugins_list_.clear(); | 314 plugins_list_.clear(); |
| 334 plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end()); | 315 plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end()); |
| 335 } | 316 } |
| 336 | 317 |
| 337 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { | 318 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { |
| 338 base::AutoLock lock(lock_); | 319 base::AutoLock lock(lock_); |
| 339 will_load_plugins_callback_ = callback; | 320 will_load_plugins_callback_ = callback; |
| 340 } | 321 } |
| 341 | 322 |
| 342 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) { | 323 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins, |
| 343 LoadPlugins(); | 324 bool include_npapi) { |
| 325 LoadPlugins(include_npapi); |
| 344 base::AutoLock lock(lock_); | 326 base::AutoLock lock(lock_); |
| 345 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); | 327 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
| 346 } | 328 } |
| 347 | 329 |
| 348 bool PluginList::GetPluginsNoRefresh( | 330 bool PluginList::GetPluginsNoRefresh( |
| 349 std::vector<webkit::WebPluginInfo>* plugins) { | 331 std::vector<webkit::WebPluginInfo>* plugins) { |
| 350 base::AutoLock lock(lock_); | 332 base::AutoLock lock(lock_); |
| 351 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); | 333 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
| 352 | 334 |
| 353 return loading_state_ == LOADING_STATE_UP_TO_DATE; | 335 return loading_state_ == LOADING_STATE_UP_TO_DATE; |
| 354 } | 336 } |
| 355 | 337 |
| 356 void PluginList::GetPluginInfoArray( | 338 void PluginList::GetPluginInfoArray( |
| 357 const GURL& url, | 339 const GURL& url, |
| 358 const std::string& mime_type, | 340 const std::string& mime_type, |
| 359 bool allow_wildcard, | 341 bool allow_wildcard, |
| 360 bool* use_stale, | 342 bool* use_stale, |
| 343 bool include_npapi, |
| 361 std::vector<webkit::WebPluginInfo>* info, | 344 std::vector<webkit::WebPluginInfo>* info, |
| 362 std::vector<std::string>* actual_mime_types) { | 345 std::vector<std::string>* actual_mime_types) { |
| 363 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 346 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
| 364 DCHECK(info); | 347 DCHECK(info); |
| 365 | 348 |
| 366 if (!use_stale) | 349 if (!use_stale) |
| 367 LoadPlugins(); | 350 LoadPlugins(include_npapi); |
| 368 base::AutoLock lock(lock_); | 351 base::AutoLock lock(lock_); |
| 369 if (use_stale) | 352 if (use_stale) |
| 370 *use_stale = (loading_state_ != LOADING_STATE_UP_TO_DATE); | 353 *use_stale = (loading_state_ != LOADING_STATE_UP_TO_DATE); |
| 371 info->clear(); | 354 info->clear(); |
| 372 if (actual_mime_types) | 355 if (actual_mime_types) |
| 373 actual_mime_types->clear(); | 356 actual_mime_types->clear(); |
| 374 | 357 |
| 375 std::set<base::FilePath> visited_plugins; | 358 std::set<base::FilePath> visited_plugins; |
| 376 | 359 |
| 377 // Add in plugins by mime type. | 360 // Add in plugins by mime type. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 421 } |
| 439 } | 422 } |
| 440 return false; | 423 return false; |
| 441 } | 424 } |
| 442 | 425 |
| 443 PluginList::~PluginList() { | 426 PluginList::~PluginList() { |
| 444 } | 427 } |
| 445 | 428 |
| 446 | 429 |
| 447 } // namespace content | 430 } // namespace content |
| OLD | NEW |