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