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/plugins/npapi/plugin_list.h" | 5 #include "webkit/plugins/npapi/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/stl_util-inl.h" | |
13 #include "base/string_split.h" | 12 #include "base/string_split.h" |
14 #include "base/string_util.h" | 13 #include "base/string_util.h" |
15 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
17 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
18 #include "net/base/mime_util.h" | 17 #include "net/base/mime_util.h" |
19 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
20 #include "webkit/plugins/npapi/plugin_constants_win.h" | 19 #include "webkit/plugins/npapi/plugin_constants_win.h" |
21 #include "webkit/plugins/npapi/plugin_lib.h" | 20 #include "webkit/plugins/npapi/plugin_lib.h" |
22 #include "webkit/plugins/plugin_switches.h" | 21 #include "webkit/plugins/plugin_switches.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 void PluginList::RegisterInternalPlugin(const FilePath& filename, | 226 void PluginList::RegisterInternalPlugin(const FilePath& filename, |
228 const std::string& name, | 227 const std::string& name, |
229 const std::string& description, | 228 const std::string& description, |
230 const std::string& mime_type_str, | 229 const std::string& mime_type_str, |
231 const PluginEntryPoints& entry_points) { | 230 const PluginEntryPoints& entry_points) { |
232 InternalPlugin plugin; | 231 InternalPlugin plugin; |
233 plugin.info.path = filename; | 232 plugin.info.path = filename; |
234 plugin.info.name = ASCIIToUTF16(name); | 233 plugin.info.name = ASCIIToUTF16(name); |
235 plugin.info.version = ASCIIToUTF16("1"); | 234 plugin.info.version = ASCIIToUTF16("1"); |
236 plugin.info.desc = ASCIIToUTF16(description); | 235 plugin.info.desc = ASCIIToUTF16(description); |
237 plugin.info.enabled = true; | 236 plugin.info.enabled = WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; |
238 | 237 |
239 WebPluginMimeType mime_type; | 238 WebPluginMimeType mime_type; |
240 mime_type.mime_type = mime_type_str; | 239 mime_type.mime_type = mime_type_str; |
241 plugin.info.mime_types.push_back(mime_type); | 240 plugin.info.mime_types.push_back(mime_type); |
242 | 241 |
243 plugin.entry_points = entry_points; | 242 plugin.entry_points = entry_points; |
244 | 243 |
245 base::AutoLock lock(lock_); | 244 base::AutoLock lock(lock_); |
246 internal_plugins_.push_back(plugin); | 245 internal_plugins_.push_back(plugin); |
247 } | 246 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 316 |
318 parsed_mime_types->push_back(mime_type); | 317 parsed_mime_types->push_back(mime_type); |
319 } | 318 } |
320 | 319 |
321 return true; | 320 return true; |
322 } | 321 } |
323 | 322 |
324 PluginList::PluginList() | 323 PluginList::PluginList() |
325 : plugins_loaded_(false), | 324 : plugins_loaded_(false), |
326 plugins_need_refresh_(false), | 325 plugins_need_refresh_(false), |
327 disable_outdated_plugins_(false), | 326 disable_outdated_plugins_(false) { |
328 next_priority_(0) { | |
329 PlatformInit(); | 327 PlatformInit(); |
330 AddHardcodedPluginGroups(); | 328 AddHardcodedPluginGroups(); |
331 } | 329 } |
332 | 330 |
333 bool PluginList::ShouldDisableGroup(const string16& group_name) { | |
334 base::AutoLock lock(lock_); | |
335 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { | |
336 disabled_groups_.insert(group_name); | |
337 return true; | |
338 } | |
339 return disabled_groups_.count(group_name) > 0; | |
340 } | |
341 | |
342 void PluginList::LoadPlugins(bool refresh) { | 331 void PluginList::LoadPlugins(bool refresh) { |
343 // Don't want to hold the lock while loading new plugins, so we don't block | 332 // Don't want to hold the lock while loading new plugins, so we don't block |
344 // other methods if they're called on other threads. | 333 // other methods if they're called on other threads. |
345 std::vector<FilePath> extra_plugin_paths; | 334 std::vector<FilePath> extra_plugin_paths; |
346 std::vector<FilePath> extra_plugin_dirs; | 335 std::vector<FilePath> extra_plugin_dirs; |
347 std::vector<InternalPlugin> internal_plugins; | 336 std::vector<InternalPlugin> internal_plugins; |
348 { | 337 { |
349 base::AutoLock lock(lock_); | 338 base::AutoLock lock(lock_); |
350 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) | 339 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) |
351 return; | 340 return; |
352 | 341 |
353 // Clear the refresh bit now, because it might get set again before we | 342 // Clear the refresh bit now, because it might get set again before we |
354 // reach the end of the method. | 343 // reach the end of the method. |
355 plugins_need_refresh_ = false; | 344 plugins_need_refresh_ = false; |
356 extra_plugin_paths = extra_plugin_paths_; | 345 extra_plugin_paths = extra_plugin_paths_; |
357 extra_plugin_dirs = extra_plugin_dirs_; | 346 extra_plugin_dirs = extra_plugin_dirs_; |
358 internal_plugins = internal_plugins_; | 347 internal_plugins = internal_plugins_; |
359 } | 348 } |
360 | 349 |
361 std::vector<WebPluginInfo> new_plugins; | 350 ScopedVector<PluginGroup> new_plugin_groups; |
362 std::set<FilePath> visited_plugins; | 351 std::set<FilePath> visited_plugins; |
363 | 352 |
364 std::vector<FilePath> directories_to_scan; | 353 std::vector<FilePath> directories_to_scan; |
365 GetPluginDirectories(&directories_to_scan); | 354 GetPluginDirectories(&directories_to_scan); |
366 | 355 |
367 // Load internal plugins first so that, if both an internal plugin and a | 356 // Load internal plugins first so that, if both an internal plugin and a |
368 // "discovered" plugin want to handle the same type, the internal plugin | 357 // "discovered" plugin want to handle the same type, the internal plugin |
369 // will have precedence. | 358 // will have precedence. |
370 for (size_t i = 0; i < internal_plugins.size(); ++i) { | 359 for (size_t i = 0; i < internal_plugins.size(); ++i) { |
371 if (internal_plugins[i].info.path.value() == kDefaultPluginLibraryName) | 360 if (internal_plugins[i].info.path.value() == kDefaultPluginLibraryName) |
372 continue; | 361 continue; |
373 LoadPlugin(internal_plugins[i].info.path, &new_plugins); | 362 LoadPlugin(internal_plugins[i].info.path, &new_plugin_groups); |
374 } | 363 } |
375 | 364 |
376 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | 365 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { |
377 const FilePath& path = extra_plugin_paths[i]; | 366 const FilePath& path = extra_plugin_paths[i]; |
378 if (visited_plugins.find(path) != visited_plugins.end()) | 367 if (visited_plugins.find(path) != visited_plugins.end()) |
379 continue; | 368 continue; |
380 LoadPlugin(path, &new_plugins); | 369 LoadPlugin(path, &new_plugin_groups); |
381 visited_plugins.insert(path); | 370 visited_plugins.insert(path); |
382 } | 371 } |
383 | 372 |
384 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | 373 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { |
385 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); | 374 LoadPluginsFromDir( |
| 375 extra_plugin_dirs[i], &new_plugin_groups, &visited_plugins); |
386 } | 376 } |
387 | 377 |
388 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | 378 for (size_t i = 0; i < directories_to_scan.size(); ++i) { |
389 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); | 379 LoadPluginsFromDir( |
| 380 directories_to_scan[i], &new_plugin_groups, &visited_plugins); |
390 } | 381 } |
391 | 382 |
392 #if defined(OS_WIN) | 383 #if defined(OS_WIN) |
393 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); | 384 LoadPluginsFromRegistry(&new_plugin_groups, &visited_plugins); |
394 #endif | 385 #endif |
395 | 386 |
396 // Load the default plugin last. | 387 // Load the default plugin last. |
397 if (webkit_glue::IsDefaultPluginEnabled()) | 388 if (webkit_glue::IsDefaultPluginEnabled()) |
398 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); | 389 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugin_groups); |
399 | 390 |
| 391 base::AutoLock lock(lock_); |
| 392 |
| 393 // Grab all plugins that were found before to copy enabled statuses. |
| 394 std::vector<WebPluginInfo> old_plugins; |
| 395 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
| 396 const std::vector<WebPluginInfo>& gr_plugins = |
| 397 plugin_groups_[i]->web_plugins_info(); |
| 398 old_plugins.insert(old_plugins.end(), gr_plugins.begin(), gr_plugins.end()); |
| 399 } |
400 // Disable all of the plugins and plugin groups that are disabled by policy. | 400 // Disable all of the plugins and plugin groups that are disabled by policy. |
401 // There's currenly a bug that makes it impossible to correctly re-enable | 401 for (size_t i = 0; i < new_plugin_groups.size(); ++i) { |
402 // plugins or plugin-groups to their original, "pre-policy" state, so | 402 PluginGroup* group = new_plugin_groups[i]; |
403 // plugins and groups are only changed to a more "safe" state after a policy | |
404 // change, i.e. from enabled to disabled. See bug 54681. | |
405 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | |
406 it != plugin_groups_.end(); ++it) { | |
407 PluginGroup* group = it->second; | |
408 string16 group_name = group->GetGroupName(); | 403 string16 group_name = group->GetGroupName(); |
409 if (ShouldDisableGroup(group_name)) { | 404 |
410 group->Enable(false); | 405 std::vector<WebPluginInfo>& gr_plugins = group->GetPluginsContainer(); |
| 406 for (size_t j = 0; j < gr_plugins.size(); ++j) { |
| 407 int plugin_found = -1; |
| 408 for (size_t k = 0; k < old_plugins.size(); ++k) { |
| 409 if (gr_plugins[j].path == old_plugins[k].path) { |
| 410 plugin_found = k; |
| 411 break; |
| 412 } |
| 413 } |
| 414 if (plugin_found >= 0) |
| 415 gr_plugins[j].enabled = old_plugins[plugin_found].enabled; |
| 416 // Set the disabled flag of all plugins scheduled for disabling. |
| 417 for (size_t k = 0; k < prematurely_disabled_plugins_.size(); ++k) { |
| 418 if (gr_plugins[j].path == prematurely_disabled_plugins_[k]) { |
| 419 group->DisablePlugin(gr_plugins[j].path); |
| 420 } |
| 421 } |
| 422 } |
| 423 if (group->IsEmpty()) { |
| 424 if (!group->Enabled()) |
| 425 prematurely_disabled_groups_.push_back(group->GetGroupName()); |
| 426 new_plugin_groups.erase(new_plugin_groups.begin() + i); |
| 427 --i; |
| 428 continue; |
411 } | 429 } |
412 | 430 |
413 if (disable_outdated_plugins_) { | 431 group->EnforceGroupPolicy(); |
| 432 if (disable_outdated_plugins_) |
414 group->DisableOutdatedPlugins(); | 433 group->DisableOutdatedPlugins(); |
415 } | |
416 if (!group->Enabled()) { | |
417 base::AutoLock lock(lock_); | |
418 disabled_groups_.insert(group_name); | |
419 } | |
420 } | 434 } |
421 | 435 |
422 // Only update the data now since loading plugins can take a while. | 436 // We flush the list of prematurely disabled plugins after the load has |
423 base::AutoLock lock(lock_); | 437 // finished. If for some reason a plugin reappears on a second load it is |
| 438 // going to be loaded normally. This is only true for non-policy controlled |
| 439 // plugins though. |
| 440 prematurely_disabled_plugins_.clear(); |
424 | 441 |
425 plugins_ = new_plugins; | 442 plugin_groups_.swap(new_plugin_groups); |
426 plugins_loaded_ = true; | 443 plugins_loaded_ = true; |
427 } | 444 } |
428 | 445 |
429 void PluginList::LoadPlugin(const FilePath& path, | 446 void PluginList::LoadPlugin(const FilePath& path, |
430 std::vector<WebPluginInfo>* plugins) { | 447 ScopedVector<PluginGroup>* plugin_groups) { |
431 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 448 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
432 << "Loading plugin " << path.value(); | 449 << "Loading plugin " << path.value(); |
433 | |
434 WebPluginInfo plugin_info; | 450 WebPluginInfo plugin_info; |
435 const PluginEntryPoints* entry_points; | 451 const PluginEntryPoints* entry_points; |
436 | 452 |
437 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) | 453 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) |
438 return; | 454 return; |
439 | 455 |
440 if (!ShouldLoadPlugin(plugin_info, plugins)) | 456 if (!ShouldLoadPlugin(plugin_info, plugin_groups)) |
441 return; | 457 return; |
442 | 458 |
443 if (path.value() != kDefaultPluginLibraryName | 459 if (path.value() != kDefaultPluginLibraryName |
444 #if defined(OS_WIN) && !defined(NDEBUG) | 460 #if defined(OS_WIN) && !defined(NDEBUG) |
445 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY | 461 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY |
446 #endif | 462 #endif |
447 ) { | 463 ) { |
448 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { | 464 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { |
449 // TODO: don't load global handlers for now. | 465 // TODO: don't load global handlers for now. |
450 // WebKit hands to the Plugin before it tries | 466 // WebKit hands to the Plugin before it tries |
451 // to handle mimeTypes on its own. | 467 // to handle mimeTypes on its own. |
452 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 468 const std::string &mime_type = plugin_info.mime_types[i].mime_type; |
453 if (mime_type == "*" ) | 469 if (mime_type == "*" ) |
454 return; | 470 return; |
455 } | 471 } |
456 } | 472 } |
457 | 473 |
458 // Mark disabled plugins as such. (This has to happen before calling | 474 AddToPluginGroups(plugin_info, plugin_groups); |
459 // |AddToPluginGroups(plugin_info)|.) | |
460 if (disabled_plugins_.count(plugin_info.path)) { | |
461 plugin_info.enabled = false; | |
462 } else { | |
463 plugin_info.enabled = true; | |
464 } | |
465 | |
466 base::AutoLock lock(lock_); | |
467 plugins->push_back(plugin_info); | |
468 AddToPluginGroups(plugin_info); | |
469 } | 475 } |
470 | 476 |
471 bool PluginList::SupportsType(const WebPluginInfo& info, | |
472 const std::string &mime_type, | |
473 bool allow_wildcard) { | |
474 // Webkit will ask for a plugin to handle empty mime types. | |
475 if (mime_type.empty()) | |
476 return false; | |
477 | |
478 for (size_t i = 0; i < info.mime_types.size(); ++i) { | |
479 const WebPluginMimeType& mime_info = info.mime_types[i]; | |
480 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { | |
481 if (!allow_wildcard && mime_info.mime_type == "*") { | |
482 continue; | |
483 } | |
484 return true; | |
485 } | |
486 } | |
487 return false; | |
488 } | |
489 | |
490 bool PluginList::SupportsExtension(const WebPluginInfo& info, | |
491 const std::string &extension, | |
492 std::string* actual_mime_type) { | |
493 for (size_t i = 0; i < info.mime_types.size(); ++i) { | |
494 const WebPluginMimeType& mime_type = info.mime_types[i]; | |
495 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) { | |
496 if (mime_type.file_extensions[j] == extension) { | |
497 if (actual_mime_type) | |
498 *actual_mime_type = mime_type.mime_type; | |
499 return true; | |
500 } | |
501 } | |
502 } | |
503 | |
504 return false; | |
505 } | |
506 | |
507 | |
508 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 477 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
509 LoadPlugins(refresh); | 478 LoadPlugins(refresh); |
510 | 479 |
511 base::AutoLock lock(lock_); | 480 base::AutoLock lock(lock_); |
512 *plugins = plugins_; | 481 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
| 482 const std::vector<WebPluginInfo>& gr_plugins = |
| 483 plugin_groups_[i]->web_plugins_info(); |
| 484 plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end()); |
| 485 } |
513 } | 486 } |
514 | 487 |
515 void PluginList::GetEnabledPlugins(bool refresh, | 488 void PluginList::GetEnabledPlugins(bool refresh, |
516 std::vector<WebPluginInfo>* plugins) { | 489 std::vector<WebPluginInfo>* plugins) { |
517 LoadPlugins(refresh); | 490 LoadPlugins(refresh); |
518 | 491 |
519 plugins->clear(); | 492 plugins->clear(); |
520 base::AutoLock lock(lock_); | 493 base::AutoLock lock(lock_); |
521 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); | 494 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
522 it != plugins_.end(); | 495 const std::vector<WebPluginInfo>& gr_plugins = |
523 ++it) { | 496 plugin_groups_[i]->web_plugins_info(); |
524 if (it->enabled) | 497 for (size_t i = 0; i < gr_plugins.size(); ++i) { |
525 plugins->push_back(*it); | 498 if (IsPluginEnabled(gr_plugins[i])) |
| 499 plugins->push_back(gr_plugins[i]); |
| 500 } |
526 } | 501 } |
527 } | 502 } |
528 | 503 |
529 void PluginList::GetPluginInfoArray( | 504 void PluginList::GetPluginInfoArray( |
530 const GURL& url, | 505 const GURL& url, |
531 const std::string& mime_type, | 506 const std::string& mime_type, |
532 bool allow_wildcard, | 507 bool allow_wildcard, |
533 std::vector<WebPluginInfo>* info, | 508 std::vector<WebPluginInfo>* info, |
534 std::vector<std::string>* actual_mime_types) { | 509 std::vector<std::string>* actual_mime_types) { |
535 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 510 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
536 DCHECK(info); | 511 DCHECK(info); |
537 | 512 |
538 LoadPlugins(false); | 513 LoadPlugins(false); |
539 base::AutoLock lock(lock_); | 514 base::AutoLock lock(lock_); |
540 info->clear(); | 515 info->clear(); |
541 if (actual_mime_types) | 516 if (actual_mime_types) |
542 actual_mime_types->clear(); | 517 actual_mime_types->clear(); |
543 | 518 |
544 std::set<FilePath> visited_plugins; | 519 std::set<FilePath> visited_plugins; |
545 | 520 |
546 // Add in enabled plugins by mime type. | 521 // Add in enabled plugins by mime type. |
547 WebPluginInfo default_plugin; | 522 WebPluginInfo default_plugin; |
548 for (size_t i = 0; i < plugins_.size(); ++i) { | 523 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
549 if (plugins_[i].enabled && | 524 const std::vector<WebPluginInfo>& plugins = |
550 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 525 plugin_groups_[i]->web_plugins_info(); |
551 FilePath path = plugins_[i].path; | 526 for (size_t i = 0; i < plugins.size(); ++i) { |
552 if (path.value() != kDefaultPluginLibraryName && | 527 if (IsPluginEnabled(plugins[i]) && SupportsType(plugins[i], |
553 visited_plugins.insert(path).second) { | 528 mime_type, allow_wildcard)) { |
554 info->push_back(plugins_[i]); | 529 FilePath path = plugins[i].path; |
555 if (actual_mime_types) | 530 if (path.value() != kDefaultPluginLibraryName && |
556 actual_mime_types->push_back(mime_type); | 531 visited_plugins.insert(path).second) { |
| 532 info->push_back(plugins[i]); |
| 533 if (actual_mime_types) |
| 534 actual_mime_types->push_back(mime_type); |
| 535 } |
557 } | 536 } |
558 } | 537 } |
559 } | 538 } |
560 | 539 |
561 // Add in enabled plugins by url. | 540 // Add in enabled plugins by url. |
562 std::string path = url.path(); | 541 std::string path = url.path(); |
563 std::string::size_type last_dot = path.rfind('.'); | 542 std::string::size_type last_dot = path.rfind('.'); |
564 if (last_dot != std::string::npos) { | 543 if (last_dot != std::string::npos) { |
565 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); | 544 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); |
566 std::string actual_mime_type; | 545 std::string actual_mime_type; |
567 for (size_t i = 0; i < plugins_.size(); ++i) { | 546 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
568 if (plugins_[i].enabled && | 547 const std::vector<WebPluginInfo>& plugins = |
569 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { | 548 plugin_groups_[i]->web_plugins_info(); |
570 FilePath path = plugins_[i].path; | 549 for (size_t i = 0; i < plugins.size(); ++i) { |
571 if (path.value() != kDefaultPluginLibraryName && | 550 if (IsPluginEnabled(plugins[i]) && |
572 visited_plugins.insert(path).second) { | 551 SupportsExtension(plugins[i], extension, &actual_mime_type)) { |
573 info->push_back(plugins_[i]); | 552 FilePath path = plugins[i].path; |
574 if (actual_mime_types) | 553 if (path.value() != kDefaultPluginLibraryName && |
575 actual_mime_types->push_back(actual_mime_type); | 554 visited_plugins.insert(path).second) { |
| 555 info->push_back(plugins[i]); |
| 556 if (actual_mime_types) |
| 557 actual_mime_types->push_back(actual_mime_type); |
| 558 } |
576 } | 559 } |
577 } | 560 } |
578 } | 561 } |
579 } | 562 } |
580 | 563 |
581 // Add in disabled plugins by mime type. | 564 // Add in disabled plugins by mime type. |
582 for (size_t i = 0; i < plugins_.size(); ++i) { | 565 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
583 if (!plugins_[i].enabled && | 566 const std::vector<WebPluginInfo>& plugins = |
584 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 567 plugin_groups_[i]->web_plugins_info(); |
585 FilePath path = plugins_[i].path; | 568 for (size_t i = 0; i < plugins.size(); ++i) { |
586 if (path.value() != kDefaultPluginLibraryName && | 569 if (!IsPluginEnabled(plugins[i]) && |
587 visited_plugins.insert(path).second) { | 570 SupportsType(plugins[i], mime_type, allow_wildcard)) { |
588 info->push_back(plugins_[i]); | 571 FilePath path = plugins[i].path; |
589 if (actual_mime_types) | 572 if (path.value() != kDefaultPluginLibraryName && |
590 actual_mime_types->push_back(mime_type); | 573 visited_plugins.insert(path).second) { |
| 574 info->push_back(plugins[i]); |
| 575 if (actual_mime_types) |
| 576 actual_mime_types->push_back(mime_type); |
| 577 } |
591 } | 578 } |
592 } | 579 } |
593 } | 580 } |
594 | 581 |
595 // Add the default plugin at the end if it supports the mime type given, | 582 // Add the default plugin at the end if it supports the mime type given, |
596 // and the default plugin is enabled. | 583 // and the default plugin is enabled. |
597 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { | 584 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
598 const WebPluginInfo& default_info = plugins_.back(); | 585 #if defined(OS_WIN) |
599 if (SupportsType(default_info, mime_type, allow_wildcard)) { | 586 if (plugin_groups_[i]->identifier().compare( |
600 info->push_back(default_info); | 587 WideToUTF8(kDefaultPluginLibraryName)) == 0) { |
601 if (actual_mime_types) | 588 #else |
602 actual_mime_types->push_back(mime_type); | 589 if (plugin_groups_[i]->identifier().compare( |
| 590 kDefaultPluginLibraryName) == 0) { |
| 591 #endif |
| 592 DCHECK_NE(0U, plugin_groups_[i]->web_plugins_info().size()); |
| 593 const WebPluginInfo& default_info = |
| 594 plugin_groups_[i]->web_plugins_info()[0]; |
| 595 if (SupportsType(default_info, mime_type, allow_wildcard)) { |
| 596 info->push_back(default_info); |
| 597 if (actual_mime_types) |
| 598 actual_mime_types->push_back(mime_type); |
| 599 } |
603 } | 600 } |
604 } | 601 } |
605 } | 602 } |
606 | 603 |
607 bool PluginList::GetPluginInfo(const GURL& url, | 604 bool PluginList::GetPluginInfo(const GURL& url, |
608 const std::string& mime_type, | 605 const std::string& mime_type, |
609 bool allow_wildcard, | 606 bool allow_wildcard, |
610 WebPluginInfo* info, | 607 WebPluginInfo* info, |
611 std::string* actual_mime_type) { | 608 std::string* actual_mime_type) { |
612 DCHECK(info); | 609 DCHECK(info); |
(...skipping 17 matching lines...) Expand all Loading... |
630 return true; | 627 return true; |
631 } | 628 } |
632 } | 629 } |
633 return false; | 630 return false; |
634 } | 631 } |
635 | 632 |
636 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 633 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, |
637 WebPluginInfo* info) { | 634 WebPluginInfo* info) { |
638 LoadPlugins(false); | 635 LoadPlugins(false); |
639 base::AutoLock lock(lock_); | 636 base::AutoLock lock(lock_); |
640 for (size_t i = 0; i < plugins_.size(); ++i) { | 637 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
641 if (plugins_[i].path == plugin_path) { | 638 const std::vector<WebPluginInfo>& plugins = |
642 *info = plugins_[i]; | 639 plugin_groups_[i]->web_plugins_info(); |
643 return true; | 640 for (size_t i = 0; i < plugins.size(); ++i) { |
| 641 if (plugins[i].path == plugin_path) { |
| 642 *info = plugins[i]; |
| 643 return true; |
| 644 } |
644 } | 645 } |
645 } | 646 } |
646 | 647 |
647 return false; | 648 return false; |
648 } | 649 } |
649 | 650 |
650 void PluginList::GetPluginGroups( | 651 void PluginList::GetPluginGroups( |
651 bool load_if_necessary, | 652 bool load_if_necessary, |
652 std::vector<PluginGroup>* plugin_groups) { | 653 std::vector<PluginGroup>* plugin_groups) { |
653 if (load_if_necessary) | 654 if (load_if_necessary) |
654 LoadPlugins(false); | 655 LoadPlugins(false); |
| 656 base::AutoLock lock(lock_); |
655 plugin_groups->clear(); | 657 plugin_groups->clear(); |
656 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); | 658 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
657 it != plugin_groups_.end(); ++it) { | 659 // In some unit tests we can get confronted with empty groups but in real |
658 if (!it->second->IsEmpty()) | 660 // world code this if should never be false here. |
659 plugin_groups->push_back(*it->second); | 661 if(!plugin_groups_[i]->IsEmpty()) |
| 662 plugin_groups->push_back(*plugin_groups_[i]); |
660 } | 663 } |
661 } | 664 } |
662 | 665 |
663 const PluginGroup* PluginList::GetPluginGroup( | 666 const PluginGroup* PluginList::GetPluginGroup( |
664 const WebPluginInfo& web_plugin_info) { | 667 const WebPluginInfo& web_plugin_info) { |
665 base::AutoLock lock(lock_); | 668 base::AutoLock lock(lock_); |
666 return AddToPluginGroups(web_plugin_info); | 669 return AddToPluginGroups(web_plugin_info, &plugin_groups_); |
667 } | 670 } |
668 | 671 |
669 string16 PluginList::GetPluginGroupName(std::string identifier) { | 672 string16 PluginList::GetPluginGroupName(const std::string& identifier) { |
670 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); | 673 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
671 if (it == plugin_groups_.end()) { | 674 if(plugin_groups_[i]->identifier() == identifier) |
672 return string16(); | 675 return plugin_groups_[i]->GetGroupName(); |
673 } | 676 } |
674 return it->second->GetGroupName(); | 677 return string16(); |
675 } | 678 } |
676 | 679 |
677 std::string PluginList::GetPluginGroupIdentifier( | 680 std::string PluginList::GetPluginGroupIdentifier( |
678 const WebPluginInfo& web_plugin_info) { | 681 const WebPluginInfo& web_plugin_info) { |
679 base::AutoLock lock(lock_); | 682 base::AutoLock lock(lock_); |
680 PluginGroup* group = AddToPluginGroups(web_plugin_info); | 683 PluginGroup* group = AddToPluginGroups(web_plugin_info, &plugin_groups_); |
681 return group->identifier(); | 684 return group->identifier(); |
682 } | 685 } |
683 | 686 |
684 void PluginList::AddHardcodedPluginGroups() { | 687 void PluginList::AddHardcodedPluginGroups() { |
685 base::AutoLock lock(lock_); | 688 base::AutoLock lock(lock_); |
686 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); | 689 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); |
687 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { | 690 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { |
688 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( | 691 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( |
689 definitions[i]); | 692 definitions[i]); |
690 std::string identifier = definition_group->identifier(); | 693 ProcessGroupAfterInitialize(definition_group); |
691 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 694 plugin_groups_.push_back(definition_group); |
692 plugin_groups_.insert(std::make_pair(identifier, definition_group)); | |
693 } | 695 } |
694 } | 696 } |
695 | 697 |
696 PluginGroup* PluginList::AddToPluginGroups( | 698 PluginGroup* PluginList::AddToPluginGroups( |
697 const WebPluginInfo& web_plugin_info) { | 699 const WebPluginInfo& web_plugin_info, |
| 700 ScopedVector<PluginGroup>* plugin_groups) { |
698 PluginGroup* group = NULL; | 701 PluginGroup* group = NULL; |
699 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 702 for (size_t i = 0; i < plugin_groups->size(); ++i) { |
700 it != plugin_groups_.end(); ++it) { | 703 if ((*plugin_groups)[i]->Match(web_plugin_info)) { |
701 if (it->second->Match(web_plugin_info)) | 704 group = (*plugin_groups)[i]; |
702 group = it->second; | 705 break; |
| 706 } |
703 } | 707 } |
704 if (!group) { | 708 if (!group) { |
705 group = PluginGroup::FromWebPluginInfo(web_plugin_info); | 709 group = PluginGroup::FromWebPluginInfo(web_plugin_info); |
| 710 // If group is scheduled for disabling do that now and remove it from the |
| 711 // list. |
| 712 for(size_t i = 0; i < prematurely_disabled_groups_.size(); ++i) { |
| 713 if (group->GetGroupName() == prematurely_disabled_groups_[i]) { |
| 714 group->EnableGroup(false); |
| 715 prematurely_disabled_groups_.erase( |
| 716 prematurely_disabled_groups_.begin() + i); |
| 717 } |
| 718 } |
| 719 ProcessGroupAfterInitialize(group); |
706 std::string identifier = group->identifier(); | 720 std::string identifier = group->identifier(); |
707 // If the identifier is not unique, use the full path. This means that we | 721 // If the identifier is not unique, use the full path. This means that we |
708 // probably won't be able to search for this group by identifier, but at | 722 // probably won't be able to search for this group by identifier, but at |
709 // least it's going to be in the set of plugin groups, and if there | 723 // least it's going to be in the set of plugin groups, and if there |
710 // is already a plug-in with the same filename, it's probably going to | 724 // is already a plug-in with the same filename, it's probably going to |
711 // handle the same MIME types (and it has a higher priority), so this one | 725 // handle the same MIME types (and it has a higher priority), so this one |
712 // is not going to run anyway. | 726 // is not going to run anyway. |
713 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | 727 for (size_t i = 0; i < plugin_groups->size(); ++i) { |
714 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | 728 if ((*plugin_groups)[i]->identifier() == identifier) { |
715 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 729 group->set_identifier(PluginGroup::GetLongIdentifier(web_plugin_info)); |
716 plugin_groups_.insert(std::make_pair(identifier, group)); | 730 break; |
| 731 } |
| 732 } |
| 733 plugin_groups->push_back(group); |
717 } | 734 } |
718 group->AddPlugin(web_plugin_info, next_priority_++); | 735 group->AddPlugin(web_plugin_info); |
719 return group; | 736 return group; |
720 } | 737 } |
721 | 738 |
722 bool PluginList::EnablePlugin(const FilePath& filename) { | 739 bool PluginList::EnablePlugin(const FilePath& filename) { |
723 base::AutoLock lock(lock_); | 740 base::AutoLock lock(lock_); |
724 | 741 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
725 bool did_enable = false; | 742 if (plugin_groups_[i]->ContainsPlugin(filename)) |
726 | 743 return plugin_groups_[i]->EnablePlugin(filename); |
727 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); | |
728 if (entry == disabled_plugins_.end()) | |
729 return did_enable; // Early exit if plugin not in disabled list. | |
730 | |
731 disabled_plugins_.erase(entry); // Remove from disabled list. | |
732 | |
733 // Set enabled flags if necessary. | |
734 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | |
735 it != plugins_.end(); | |
736 ++it) { | |
737 if (it->path == filename) { | |
738 DCHECK(!it->enabled); // Should have been disabled. | |
739 it->enabled = true; | |
740 did_enable = true; | |
741 } | |
742 } | 744 } |
743 | 745 |
744 return did_enable; | 746 // Non existing plugin is beig enabled. Ignore this request for now because |
| 747 // plugins are anyway born enabled. |
| 748 return true; |
745 } | 749 } |
746 | 750 |
747 bool PluginList::DisablePlugin(const FilePath& filename) { | 751 bool PluginList::DisablePlugin(const FilePath& filename) { |
748 base::AutoLock lock(lock_); | 752 base::AutoLock lock(lock_); |
749 | 753 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
750 bool did_disable = false; | 754 if (plugin_groups_[i]->ContainsPlugin(filename)) |
751 | 755 return plugin_groups_[i]->DisablePlugin(filename); |
752 if (disabled_plugins_.find(filename) != disabled_plugins_.end()) | |
753 return did_disable; // Early exit if plugin already in disabled list. | |
754 | |
755 disabled_plugins_.insert(filename); // Add to disabled list. | |
756 | |
757 // Unset enabled flags if necessary. | |
758 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | |
759 it != plugins_.end(); | |
760 ++it) { | |
761 if (it->path == filename) { | |
762 DCHECK(it->enabled); // Should have been enabled. | |
763 it->enabled = false; | |
764 did_disable = true; | |
765 } | |
766 } | 756 } |
767 | 757 |
768 return did_disable; | 758 // Non existing plugin is being disabled. Queue the plugin so that on the next |
| 759 // load plugins call they will be disabled. |
| 760 prematurely_disabled_plugins_.push_back(filename); |
| 761 return true; |
769 } | 762 } |
770 | 763 |
771 bool PluginList::EnableGroup(bool enable, const string16& group_name) { | 764 bool PluginList::EnableGroup(bool enable, const string16& group_name) { |
772 bool did_change = false; | 765 base::AutoLock lock(lock_); |
773 { | 766 PluginGroup* group = NULL; |
774 base::AutoLock lock(lock_); | 767 for (size_t i = 0; i < plugin_groups_.size(); ++i) { |
775 | 768 if (plugin_groups_[i]->GetGroupName().find(group_name) != string16::npos) { |
776 std::set<string16>::iterator entry = disabled_groups_.find(group_name); | 769 group = plugin_groups_[i]; |
777 if (enable) { | 770 break; |
778 if (entry == disabled_groups_.end()) | |
779 return did_change; // Early exit if group not in disabled list. | |
780 disabled_groups_.erase(entry); // Remove from disabled list. | |
781 } else { | |
782 if (entry != disabled_groups_.end()) | |
783 return did_change; // Early exit if group already in disabled list. | |
784 disabled_groups_.insert(group_name); | |
785 } | 771 } |
786 } | 772 } |
| 773 if (!group) { |
| 774 // Non existing group is being enabled. Queue the group so that on the next |
| 775 // load plugins call they will be disabled. |
| 776 if(!enable) |
| 777 prematurely_disabled_groups_.push_back(group_name); |
| 778 return true; |
| 779 } |
787 | 780 |
788 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 781 return group->EnableGroup(enable); |
789 it != plugin_groups_.end(); ++it) { | 782 } |
790 if (it->second->GetGroupName() == group_name) { | 783 |
791 if (it->second->Enabled() != enable) { | 784 bool PluginList::SupportsType(const WebPluginInfo& plugin, |
792 it->second->Enable(enable); | 785 const std::string& mime_type, |
793 did_change = true; | 786 bool allow_wildcard) { |
794 break; | 787 // Webkit will ask for a plugin to handle empty mime types. |
| 788 if (mime_type.empty()) |
| 789 return false; |
| 790 |
| 791 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
| 792 const WebPluginMimeType& mime_info = plugin.mime_types[i]; |
| 793 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { |
| 794 if (!allow_wildcard && mime_info.mime_type == "*") |
| 795 continue; |
| 796 return true; |
| 797 } |
| 798 } |
| 799 return false; |
| 800 } |
| 801 |
| 802 bool PluginList::SupportsExtension(const WebPluginInfo& plugin, |
| 803 const std::string& extension, |
| 804 std::string* actual_mime_type) { |
| 805 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
| 806 const WebPluginMimeType& mime_type = plugin.mime_types[i]; |
| 807 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) { |
| 808 if (mime_type.file_extensions[j] == extension) { |
| 809 if (actual_mime_type) |
| 810 *actual_mime_type = mime_type.mime_type; |
| 811 return true; |
795 } | 812 } |
796 } | 813 } |
797 } | 814 } |
798 | 815 return false; |
799 return did_change; | |
800 } | 816 } |
801 | 817 |
802 void PluginList::DisableOutdatedPluginGroups() { | 818 void PluginList::DisableOutdatedPluginGroups() { |
803 disable_outdated_plugins_ = true; | 819 disable_outdated_plugins_ = true; |
804 } | 820 } |
805 | 821 |
806 PluginList::~PluginList() { | 822 PluginList::~PluginList() { |
807 Shutdown(); | |
808 } | 823 } |
809 | 824 |
810 void PluginList::Shutdown() { | |
811 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), | |
812 plugin_groups_.end()); | |
813 } | |
814 | 825 |
815 } // namespace npapi | 826 } // namespace npapi |
816 } // namespace webkit | 827 } // namespace webkit |
OLD | NEW |