OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/plugins/plugin_list.h" | 5 #include "webkit/glue/plugins/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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 plugins_need_refresh_(false), | 282 plugins_need_refresh_(false), |
283 disable_outdated_plugins_(false), | 283 disable_outdated_plugins_(false), |
284 next_priority_(0) { | 284 next_priority_(0) { |
285 PlatformInit(); | 285 PlatformInit(); |
286 AddHardcodedPluginGroups(); | 286 AddHardcodedPluginGroups(); |
287 } | 287 } |
288 | 288 |
289 bool PluginList::ShouldDisableGroup(const string16& group_name) { | 289 bool PluginList::ShouldDisableGroup(const string16& group_name) { |
290 AutoLock lock(lock_); | 290 AutoLock lock(lock_); |
291 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { | 291 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { |
292 disabled_groups_.insert(group_name); | 292 disabled_groups_.insert(DisabledGroupsListElement(group_name, POLICY)); |
293 return true; | 293 return true; |
294 } | 294 } |
295 return disabled_groups_.count(group_name) > 0; | 295 return disabled_groups_.count(group_name) > 0; |
296 } | 296 } |
297 | 297 |
298 void PluginList::LoadPlugins(bool refresh) { | 298 void PluginList::LoadPlugins(bool refresh) { |
299 // Don't want to hold the lock while loading new plugins, so we don't block | 299 // Don't want to hold the lock while loading new plugins, so we don't block |
300 // other methods if they're called on other threads. | 300 // other methods if they're called on other threads. |
301 std::vector<FilePath> extra_plugin_paths; | 301 std::vector<FilePath> extra_plugin_paths; |
302 std::vector<FilePath> extra_plugin_dirs; | 302 std::vector<FilePath> extra_plugin_dirs; |
303 std::vector<PluginVersionInfo> internal_plugins; | 303 std::vector<PluginVersionInfo> internal_plugins; |
304 { | 304 { |
305 AutoLock lock(lock_); | 305 AutoLock lock(lock_); |
306 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) | 306 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) |
307 return; | 307 return; |
308 | 308 |
309 // Clear the refresh bit now, because it might get set again before we | 309 // Clear the refresh bit now, because it might get set again before we |
310 // reach the end of the method. | 310 // reach the end of the method. |
311 plugins_need_refresh_ = false; | 311 plugins_need_refresh_ = false; |
312 extra_plugin_paths = extra_plugin_paths_; | 312 extra_plugin_paths = extra_plugin_paths_; |
313 extra_plugin_dirs = extra_plugin_dirs_; | 313 extra_plugin_dirs = extra_plugin_dirs_; |
314 internal_plugins = internal_plugins_; | 314 internal_plugins = internal_plugins_; |
315 } | 315 } |
316 | 316 |
317 std::vector<WebPluginInfo> new_plugins; | 317 std::vector<WebPluginInfo*> new_plugins; |
jam
2010/12/15 18:25:50
why is this change necessary?
pastarmovj
2010/12/15 21:56:04
Before we got a copy of the plugins in PluginsList
| |
318 std::set<FilePath> visited_plugins; | 318 std::set<FilePath> visited_plugins; |
319 | 319 |
320 std::vector<FilePath> directories_to_scan; | 320 std::vector<FilePath> directories_to_scan; |
321 GetPluginDirectories(&directories_to_scan); | 321 GetPluginDirectories(&directories_to_scan); |
322 | 322 |
323 // Load internal plugins first so that, if both an internal plugin and a | 323 // Load internal plugins first so that, if both an internal plugin and a |
324 // "discovered" plugin want to handle the same type, the internal plugin | 324 // "discovered" plugin want to handle the same type, the internal plugin |
325 // will have precedence. | 325 // will have precedence. |
326 for (size_t i = 0; i < internal_plugins.size(); ++i) { | 326 for (size_t i = 0; i < internal_plugins.size(); ++i) { |
327 if (internal_plugins[i].path.value() == kDefaultPluginLibraryName) | 327 if (internal_plugins[i].path.value() == kDefaultPluginLibraryName) |
(...skipping 11 matching lines...) Expand all Loading... | |
339 | 339 |
340 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | 340 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { |
341 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); | 341 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); |
342 } | 342 } |
343 | 343 |
344 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | 344 for (size_t i = 0; i < directories_to_scan.size(); ++i) { |
345 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); | 345 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); |
346 } | 346 } |
347 | 347 |
348 #if defined(OS_WIN) | 348 #if defined(OS_WIN) |
349 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); | 349 LoadPluginsFromRegistry(&visited_plugins, &new_plugins); |
350 #endif | 350 #endif |
351 | 351 |
352 // Load the default plugin last. | 352 // Load the default plugin last. |
353 if (webkit_glue::IsDefaultPluginEnabled()) | 353 if (webkit_glue::IsDefaultPluginEnabled()) |
354 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); | 354 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); |
355 | 355 |
356 // Disable all of the plugins and plugin groups that are disabled by policy. | 356 // Disable all of the plugins and plugin groups that are disabled by policy. |
357 // There's currenly a bug that makes it impossible to correctly re-enable | 357 // There's currenly a bug that makes it impossible to correctly re-enable |
358 // plugins or plugin-groups to their original, "pre-policy" state, so | 358 // plugins or plugin-groups to their original, "pre-policy" state, so |
359 // plugins and groups are only changed to a more "safe" state after a policy | 359 // plugins and groups are only changed to a more "safe" state after a policy |
360 // change, i.e. from enabled to disabled. See bug 54681. | 360 // change, i.e. from enabled to disabled. See bug 54681. |
361 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 361 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
362 it != plugin_groups_.end(); ++it) { | 362 it != plugin_groups_.end(); ++it) { |
363 PluginGroup* group = it->second; | 363 PluginGroup* group = it->second; |
364 string16 group_name = group->GetGroupName(); | 364 string16 group_name = group->GetGroupName(); |
365 if (ShouldDisableGroup(group_name)) { | 365 if (ShouldDisableGroup(group_name)) { |
366 group->Enable(false); | 366 group->Enable(false); |
367 } | 367 } |
368 | 368 |
369 if (disable_outdated_plugins_) { | 369 if (disable_outdated_plugins_) { |
370 group->DisableOutdatedPlugins(); | 370 group->DisableOutdatedPlugins(); |
371 } | 371 } |
372 if (!group->Enabled()) { | 372 if (!group->Enabled()) { |
373 AutoLock lock(lock_); | 373 AutoLock lock(lock_); |
374 disabled_groups_.insert(group_name); | 374 if (disabled_groups_.count(group_name) == 0) |
375 disabled_groups_.insert(DisabledGroupsListElement(group_name, USER)); | |
375 } | 376 } |
376 } | 377 } |
377 | 378 |
378 // Only update the data now since loading plugins can take a while. | |
379 AutoLock lock(lock_); | 379 AutoLock lock(lock_); |
380 | |
381 plugins_ = new_plugins; | 380 plugins_ = new_plugins; |
Bernhard Bauer
2010/12/15 17:23:45
What happens to the old pointers in |plugins_|? Do
pastarmovj
2010/12/15 21:56:04
About the reason for pointers please look at the r
| |
382 plugins_loaded_ = true; | 381 plugins_loaded_ = true; |
383 } | 382 } |
384 | 383 |
385 void PluginList::LoadPlugin(const FilePath& path, | 384 void PluginList::LoadPlugin(const FilePath& path, |
386 std::vector<WebPluginInfo>* plugins) { | 385 std::vector<WebPluginInfo*>* plugins) { |
387 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 386 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
388 << "Loading plugin " << path.value(); | 387 << "Loading plugin " << path.value(); |
389 | 388 |
390 WebPluginInfo plugin_info; | 389 WebPluginInfo plugin_info; |
391 const PluginEntryPoints* entry_points; | 390 const PluginEntryPoints* entry_points; |
392 | 391 |
393 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) | 392 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) |
394 return; | 393 return; |
395 | 394 |
396 if (!ShouldLoadPlugin(plugin_info, plugins)) | 395 if (!ShouldLoadPlugin(plugin_info, plugins)) |
(...skipping 16 matching lines...) Expand all Loading... | |
413 | 412 |
414 // Mark disabled plugins as such. (This has to happen before calling | 413 // Mark disabled plugins as such. (This has to happen before calling |
415 // |AddToPluginGroups(plugin_info)|.) | 414 // |AddToPluginGroups(plugin_info)|.) |
416 if (disabled_plugins_.count(plugin_info.path)) { | 415 if (disabled_plugins_.count(plugin_info.path)) { |
417 plugin_info.enabled = false; | 416 plugin_info.enabled = false; |
418 } else { | 417 } else { |
419 plugin_info.enabled = true; | 418 plugin_info.enabled = true; |
420 } | 419 } |
421 | 420 |
422 AutoLock lock(lock_); | 421 AutoLock lock(lock_); |
423 plugins->push_back(plugin_info); | 422 AddToPluginGroups(plugin_info, plugins); |
424 AddToPluginGroups(plugin_info); | |
425 } | 423 } |
426 | 424 |
427 bool PluginList::SupportsType(const WebPluginInfo& info, | 425 bool PluginList::SupportsType(const WebPluginInfo& info, |
428 const std::string &mime_type, | 426 const std::string &mime_type, |
429 bool allow_wildcard) { | 427 bool allow_wildcard) { |
430 // Webkit will ask for a plugin to handle empty mime types. | 428 // Webkit will ask for a plugin to handle empty mime types. |
431 if (mime_type.empty()) | 429 if (mime_type.empty()) |
432 return false; | 430 return false; |
433 | 431 |
434 for (size_t i = 0; i < info.mime_types.size(); ++i) { | 432 for (size_t i = 0; i < info.mime_types.size(); ++i) { |
(...skipping 23 matching lines...) Expand all Loading... | |
458 } | 456 } |
459 | 457 |
460 return false; | 458 return false; |
461 } | 459 } |
462 | 460 |
463 | 461 |
464 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 462 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
465 LoadPlugins(refresh); | 463 LoadPlugins(refresh); |
466 | 464 |
467 AutoLock lock(lock_); | 465 AutoLock lock(lock_); |
468 *plugins = plugins_; | 466 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); |
467 it != plugins_.end(); | |
468 ++it) { | |
469 plugins->push_back(**it); | |
470 } | |
469 } | 471 } |
470 | 472 |
471 void PluginList::GetEnabledPlugins(bool refresh, | 473 void PluginList::GetEnabledPlugins(bool refresh, |
472 std::vector<WebPluginInfo>* plugins) { | 474 std::vector<WebPluginInfo>* plugins) { |
473 LoadPlugins(refresh); | 475 LoadPlugins(refresh); |
474 | 476 |
475 plugins->clear(); | 477 plugins->clear(); |
476 AutoLock lock(lock_); | 478 AutoLock lock(lock_); |
477 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); | 479 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); |
478 it != plugins_.end(); | 480 it != plugins_.end(); |
479 ++it) { | 481 ++it) { |
480 if (it->enabled) | 482 if ((*it)->enabled) |
481 plugins->push_back(*it); | 483 plugins->push_back(**it); |
482 } | 484 } |
483 } | 485 } |
484 | 486 |
485 void PluginList::GetPluginInfoArray( | 487 void PluginList::GetPluginInfoArray( |
486 const GURL& url, | 488 const GURL& url, |
487 const std::string& mime_type, | 489 const std::string& mime_type, |
488 bool allow_wildcard, | 490 bool allow_wildcard, |
489 std::vector<WebPluginInfo>* info, | 491 std::vector<WebPluginInfo>* info, |
490 std::vector<std::string>* actual_mime_types) { | 492 std::vector<std::string>* actual_mime_types) { |
491 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 493 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
492 DCHECK(info); | 494 DCHECK(info); |
493 | 495 |
494 LoadPlugins(false); | 496 LoadPlugins(false); |
495 AutoLock lock(lock_); | 497 AutoLock lock(lock_); |
496 info->clear(); | 498 info->clear(); |
497 if (actual_mime_types) | 499 if (actual_mime_types) |
498 actual_mime_types->clear(); | 500 actual_mime_types->clear(); |
499 | 501 |
500 std::set<FilePath> visited_plugins; | 502 std::set<FilePath> visited_plugins; |
501 | 503 |
502 // Add in enabled plugins by mime type. | 504 // Add in enabled plugins by mime type. |
503 WebPluginInfo default_plugin; | 505 WebPluginInfo default_plugin; |
504 for (size_t i = 0; i < plugins_.size(); ++i) { | 506 for (size_t i = 0; i < plugins_.size(); ++i) { |
505 if (plugins_[i].enabled && | 507 if (plugins_[i]->enabled && |
506 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 508 SupportsType(*plugins_[i], mime_type, allow_wildcard)) { |
507 FilePath path = plugins_[i].path; | 509 FilePath path = plugins_[i]->path; |
508 if (path.value() != kDefaultPluginLibraryName && | 510 if (path.value() != kDefaultPluginLibraryName && |
509 visited_plugins.insert(path).second) { | 511 visited_plugins.insert(path).second) { |
510 info->push_back(plugins_[i]); | 512 info->push_back(*plugins_[i]); |
511 if (actual_mime_types) | 513 if (actual_mime_types) |
512 actual_mime_types->push_back(mime_type); | 514 actual_mime_types->push_back(mime_type); |
513 } | 515 } |
514 } | 516 } |
515 } | 517 } |
516 | 518 |
517 // Add in enabled plugins by url. | 519 // Add in enabled plugins by url. |
518 std::string path = url.path(); | 520 std::string path = url.path(); |
519 std::string::size_type last_dot = path.rfind('.'); | 521 std::string::size_type last_dot = path.rfind('.'); |
520 if (last_dot != std::string::npos) { | 522 if (last_dot != std::string::npos) { |
521 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); | 523 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); |
522 std::string actual_mime_type; | 524 std::string actual_mime_type; |
523 for (size_t i = 0; i < plugins_.size(); ++i) { | 525 for (size_t i = 0; i < plugins_.size(); ++i) { |
524 if (plugins_[i].enabled && | 526 if (plugins_[i]->enabled && |
525 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { | 527 SupportsExtension(*plugins_[i], extension, &actual_mime_type)) { |
526 FilePath path = plugins_[i].path; | 528 FilePath path = plugins_[i]->path; |
527 if (path.value() != kDefaultPluginLibraryName && | 529 if (path.value() != kDefaultPluginLibraryName && |
528 visited_plugins.insert(path).second) { | 530 visited_plugins.insert(path).second) { |
529 info->push_back(plugins_[i]); | 531 info->push_back(*plugins_[i]); |
530 if (actual_mime_types) | 532 if (actual_mime_types) |
531 actual_mime_types->push_back(actual_mime_type); | 533 actual_mime_types->push_back(actual_mime_type); |
532 } | 534 } |
533 } | 535 } |
534 } | 536 } |
535 } | 537 } |
536 | 538 |
537 // Add in disabled plugins by mime type. | 539 // Add in disabled plugins by mime type. |
538 for (size_t i = 0; i < plugins_.size(); ++i) { | 540 for (size_t i = 0; i < plugins_.size(); ++i) { |
539 if (!plugins_[i].enabled && | 541 if (!plugins_[i]->enabled && |
540 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 542 SupportsType(*plugins_[i], mime_type, allow_wildcard)) { |
541 FilePath path = plugins_[i].path; | 543 FilePath path = plugins_[i]->path; |
542 if (path.value() != kDefaultPluginLibraryName && | 544 if (path.value() != kDefaultPluginLibraryName && |
543 visited_plugins.insert(path).second) { | 545 visited_plugins.insert(path).second) { |
544 info->push_back(plugins_[i]); | 546 info->push_back(*plugins_[i]); |
545 if (actual_mime_types) | 547 if (actual_mime_types) |
546 actual_mime_types->push_back(mime_type); | 548 actual_mime_types->push_back(mime_type); |
547 } | 549 } |
548 } | 550 } |
549 } | 551 } |
550 | 552 |
551 // Add the default plugin at the end if it supports the mime type given, | 553 // Add the default plugin at the end if it supports the mime type given, |
552 // and the default plugin is enabled. | 554 // and the default plugin is enabled. |
553 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { | 555 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { |
554 const WebPluginInfo& default_info = plugins_.back(); | 556 const WebPluginInfo& default_info = *plugins_.back(); |
555 if (SupportsType(default_info, mime_type, allow_wildcard)) { | 557 if (SupportsType(default_info, mime_type, allow_wildcard)) { |
556 info->push_back(default_info); | 558 info->push_back(default_info); |
557 if (actual_mime_types) | 559 if (actual_mime_types) |
558 actual_mime_types->push_back(mime_type); | 560 actual_mime_types->push_back(mime_type); |
559 } | 561 } |
560 } | 562 } |
561 } | 563 } |
562 | 564 |
563 bool PluginList::GetPluginInfo(const GURL& url, | 565 bool PluginList::GetPluginInfo(const GURL& url, |
564 const std::string& mime_type, | 566 const std::string& mime_type, |
(...skipping 22 matching lines...) Expand all Loading... | |
587 } | 589 } |
588 } | 590 } |
589 return false; | 591 return false; |
590 } | 592 } |
591 | 593 |
592 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 594 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, |
593 WebPluginInfo* info) { | 595 WebPluginInfo* info) { |
594 LoadPlugins(false); | 596 LoadPlugins(false); |
595 AutoLock lock(lock_); | 597 AutoLock lock(lock_); |
596 for (size_t i = 0; i < plugins_.size(); ++i) { | 598 for (size_t i = 0; i < plugins_.size(); ++i) { |
597 if (plugins_[i].path == plugin_path) { | 599 if (plugins_[i]->path == plugin_path) { |
598 *info = plugins_[i]; | 600 *info = *plugins_[i]; |
599 return true; | 601 return true; |
600 } | 602 } |
601 } | 603 } |
602 | 604 |
603 return false; | 605 return false; |
604 } | 606 } |
605 | 607 |
606 void PluginList::GetPluginGroups( | 608 void PluginList::GetPluginGroups( |
607 bool load_if_necessary, | 609 bool load_if_necessary, |
608 std::vector<PluginGroup>* plugin_groups) { | 610 std::vector<PluginGroup>* plugin_groups) { |
609 if (load_if_necessary) | 611 if (load_if_necessary) |
610 LoadPlugins(false); | 612 LoadPlugins(false); |
613 AutoLock lock(lock_); | |
611 plugin_groups->clear(); | 614 plugin_groups->clear(); |
612 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); | 615 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); |
613 it != plugin_groups_.end(); ++it) { | 616 it != plugin_groups_.end(); ++it) { |
614 plugin_groups->push_back(*it->second); | 617 plugin_groups->push_back(*it->second); |
615 } | 618 } |
616 } | 619 } |
617 | 620 |
618 const PluginGroup* PluginList::GetPluginGroup( | 621 const PluginGroup* PluginList::GetPluginGroup( |
619 const WebPluginInfo& web_plugin_info) { | 622 const WebPluginInfo& web_plugin_info) { |
620 AutoLock lock(lock_); | 623 AutoLock lock(lock_); |
621 return AddToPluginGroups(web_plugin_info); | 624 return AddToPluginGroups(web_plugin_info, NULL); |
622 } | 625 } |
623 | 626 |
624 string16 PluginList::GetPluginGroupName(std::string identifier) { | 627 string16 PluginList::GetPluginGroupName(std::string identifier) { |
625 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); | 628 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); |
626 if (it == plugin_groups_.end()) { | 629 if (it == plugin_groups_.end()) { |
627 return string16(); | 630 return string16(); |
628 } | 631 } |
629 return it->second->GetGroupName(); | 632 return it->second->GetGroupName(); |
630 } | 633 } |
631 | 634 |
632 std::string PluginList::GetPluginGroupIdentifier( | 635 std::string PluginList::GetPluginGroupIdentifier( |
633 const WebPluginInfo& web_plugin_info) { | 636 const WebPluginInfo& web_plugin_info) { |
634 AutoLock lock(lock_); | 637 AutoLock lock(lock_); |
635 PluginGroup* group = AddToPluginGroups(web_plugin_info); | 638 PluginGroup* group = AddToPluginGroups(web_plugin_info, NULL); |
636 return group->identifier(); | 639 return group->identifier(); |
637 } | 640 } |
638 | 641 |
639 void PluginList::AddHardcodedPluginGroups() { | 642 void PluginList::AddHardcodedPluginGroups() { |
640 AutoLock lock(lock_); | 643 AutoLock lock(lock_); |
641 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); | 644 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); |
642 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { | 645 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { |
643 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( | 646 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( |
644 definitions[i]); | 647 definitions[i]); |
645 std::string identifier = definition_group->identifier(); | 648 std::string identifier = definition_group->identifier(); |
646 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 649 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
647 plugin_groups_.insert(std::make_pair(identifier, definition_group)); | 650 plugin_groups_.insert(std::make_pair(identifier, definition_group)); |
648 } | 651 } |
649 } | 652 } |
650 | 653 |
651 PluginGroup* PluginList::AddToPluginGroups( | 654 PluginGroup* PluginList::AddToPluginGroups( |
652 const WebPluginInfo& web_plugin_info) { | 655 const WebPluginInfo& web_plugin_info, |
656 std::vector<WebPluginInfo*>* plugins) { | |
653 PluginGroup* group = NULL; | 657 PluginGroup* group = NULL; |
654 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 658 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
655 it != plugin_groups_.end(); ++it) { | 659 it != plugin_groups_.end(); ++it) { |
656 if (it->second->Match(web_plugin_info)) | 660 if (it->second->Match(web_plugin_info)) |
657 group = it->second; | 661 group = it->second; |
658 } | 662 } |
659 if (!group) { | 663 if (!group) { |
660 group = PluginGroup::FromWebPluginInfo(web_plugin_info); | 664 group = PluginGroup::FromWebPluginInfo(web_plugin_info); |
661 std::string identifier = group->identifier(); | 665 std::string identifier = group->identifier(); |
662 // If the identifier is not unique, use the full path. This means that we | 666 // If the identifier is not unique, use the full path. This means that we |
663 // probably won't be able to search for this group by identifier, but at | 667 // probably won't be able to search for this group by identifier, but at |
664 // least it's going to be in the set of plugin groups, and if there | 668 // least it's going to be in the set of plugin groups, and if there |
665 // is already a plug-in with the same filename, it's probably going to | 669 // is already a plug-in with the same filename, it's probably going to |
666 // handle the same MIME types (and it has a higher priority), so this one | 670 // handle the same MIME types (and it has a higher priority), so this one |
667 // is not going to run anyway. | 671 // is not going to run anyway. |
668 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | 672 if (plugin_groups_.find(identifier) != plugin_groups_.end()) |
669 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | 673 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); |
670 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 674 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
671 plugin_groups_.insert(std::make_pair(identifier, group)); | 675 plugin_groups_.insert(std::make_pair(identifier, group)); |
672 } | 676 } |
673 group->AddPlugin(web_plugin_info, next_priority_++); | 677 WebPluginInfo* group_plugin_copy; |
678 bool is_new_addition = group->AddPlugin( | |
679 web_plugin_info, next_priority_, &group_plugin_copy); | |
680 if (plugins) | |
681 plugins->push_back(group_plugin_copy); | |
682 if (is_new_addition) { | |
683 next_priority_++; | |
684 string16 group_name = group->GetGroupName(); | |
685 if (!group->Enabled() && !disabled_groups_.count(group_name)) { | |
686 disabled_groups_.insert(DisabledGroupsListElement( | |
687 group_name, | |
688 PluginGroup::IsPluginNameDisabledByPolicy(group_name) ? | |
689 POLICY : USER)); | |
690 } else if (group->Enabled() && disabled_groups_.count(group_name)) { | |
691 disabled_groups_.erase(group_name); | |
692 } | |
693 // We don't need to protect the flag here because it is protected from the | |
694 // callers of |AddToPluginGroups|. | |
695 } | |
674 return group; | 696 return group; |
675 } | 697 } |
676 | 698 |
677 bool PluginList::EnablePlugin(const FilePath& filename) { | 699 bool PluginList::EnablePlugin(const FilePath& filename) { |
678 AutoLock lock(lock_); | 700 AutoLock lock(lock_); |
679 | 701 |
680 bool did_enable = false; | 702 bool did_enable = false; |
681 | 703 |
682 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); | 704 DisabledPlugins::iterator entry = |
683 if (entry == disabled_plugins_.end()) | 705 disabled_plugins_.find(filename); |
706 if (entry == disabled_plugins_.end() || entry->second == POLICY) | |
684 return did_enable; // Early exit if plugin not in disabled list. | 707 return did_enable; // Early exit if plugin not in disabled list. |
685 | 708 |
686 disabled_plugins_.erase(entry); // Remove from disabled list. | 709 disabled_plugins_.erase(entry); // Remove from disabled list. |
687 | 710 |
688 // Set enabled flags if necessary. | 711 // Set enabled flags if necessary. |
689 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | 712 for (std::vector<WebPluginInfo*>::iterator it = plugins_.begin(); |
690 it != plugins_.end(); | 713 it != plugins_.end(); |
691 ++it) { | 714 ++it) { |
692 if (it->path == filename) { | 715 if ((*it)->path == filename) { |
693 DCHECK(!it->enabled); // Should have been disabled. | 716 DCHECK(!(*it)->enabled); // Should have been disabled. |
694 it->enabled = true; | 717 (*it)->enabled = true; |
718 PluginGroup* group = AddToPluginGroups(**it, NULL); | |
719 bool group_was_enabled = group->Enabled(); | |
720 group->RefreshEnabledState(); | |
721 if (group_was_enabled && group->Enabled()) { | |
722 DisabledGroups::iterator entry = | |
723 disabled_groups_.find(group->GetGroupName()); | |
724 if (entry != disabled_groups_.end()) | |
725 disabled_groups_.erase(entry); | |
726 } | |
695 did_enable = true; | 727 did_enable = true; |
696 } | 728 } |
697 } | 729 } |
698 | 730 |
699 return did_enable; | 731 return did_enable; |
700 } | 732 } |
701 | 733 |
702 bool PluginList::DisablePlugin(const FilePath& filename) { | 734 bool PluginList::DisablePlugin(const FilePath& filename, bool policy_disabled) { |
703 AutoLock lock(lock_); | 735 AutoLock lock(lock_); |
704 | 736 |
705 bool did_disable = false; | 737 bool did_disable = false; |
706 | 738 |
707 if (disabled_plugins_.find(filename) != disabled_plugins_.end()) | 739 DisabledPlugins::iterator entry = |
740 disabled_plugins_.find(filename); | |
741 if (entry != disabled_plugins_.end()) { | |
742 if ((entry->second == POLICY && !policy_disabled) || | |
743 (entry->second == USER && policy_disabled)) | |
744 entry->second = POLICY_AND_USER; | |
708 return did_disable; // Early exit if plugin already in disabled list. | 745 return did_disable; // Early exit if plugin already in disabled list. |
746 } | |
709 | 747 |
710 disabled_plugins_.insert(filename); // Add to disabled list. | 748 // Add to disabled list. |
749 disabled_plugins_.insert( | |
750 DisabledPluginsListElement(filename, policy_disabled ? POLICY : USER)); | |
711 | 751 |
712 // Unset enabled flags if necessary. | 752 // Unset enabled flags if necessary. |
713 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | 753 for (std::vector<WebPluginInfo*>::iterator it = plugins_.begin(); |
714 it != plugins_.end(); | 754 it != plugins_.end(); |
715 ++it) { | 755 ++it) { |
716 if (it->path == filename) { | 756 if ((*it)->path == filename) { |
717 DCHECK(it->enabled); // Should have been enabled. | 757 DCHECK((*it)->enabled); // Should have been enabled. |
718 it->enabled = false; | 758 (*it)->enabled = false; |
759 PluginGroup* group = AddToPluginGroups(**it, NULL); | |
760 group->RefreshEnabledState(); | |
761 if (!group->Enabled()) { | |
762 if (!disabled_groups_.count(group->GetGroupName())) { | |
763 disabled_groups_.insert( | |
764 DisabledGroupsListElement(group->GetGroupName(), | |
765 policy_disabled ? POLICY : USER)); | |
766 } | |
767 } | |
719 did_disable = true; | 768 did_disable = true; |
720 } | 769 } |
721 } | 770 } |
722 | 771 |
723 return did_disable; | 772 return did_disable; |
724 } | 773 } |
725 | 774 |
726 bool PluginList::EnableGroup(bool enable, const string16& group_name) { | 775 bool PluginList::EnableGroup(bool enable, const string16& group_name) { |
727 bool did_change = false; | 776 bool did_change = false; |
728 { | 777 { |
729 AutoLock lock(lock_); | 778 AutoLock lock(lock_); |
730 | 779 |
731 std::set<string16>::iterator entry = disabled_groups_.find(group_name); | 780 DisabledGroups::iterator entry = |
781 disabled_groups_.find(group_name); | |
732 if (enable) { | 782 if (enable) { |
733 if (entry == disabled_groups_.end()) | 783 if (entry == disabled_groups_.end() || entry->second == POLICY) |
734 return did_change; // Early exit if group not in disabled list. | 784 return did_change; // Early exit if group not in disabled list. |
735 disabled_groups_.erase(entry); // Remove from disabled list. | 785 disabled_groups_.erase(entry); // Remove from disabled list. |
736 } else { | 786 } else { |
737 if (entry != disabled_groups_.end()) | 787 if (entry != disabled_groups_.end()) |
738 return did_change; // Early exit if group already in disabled list. | 788 return did_change; // Early exit if group already in disabled list. |
739 disabled_groups_.insert(group_name); | 789 disabled_groups_.insert( |
790 DisabledGroupsListElement( | |
791 group_name, | |
792 PluginGroup::IsPluginNameDisabledByPolicy(group_name) ? | |
793 POLICY : USER)); | |
740 } | 794 } |
741 } | 795 } |
742 | 796 |
743 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 797 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
744 it != plugin_groups_.end(); ++it) { | 798 it != plugin_groups_.end(); ++it) { |
745 if (it->second->GetGroupName() == group_name) { | 799 if (it->second->GetGroupName() == group_name) { |
746 if (it->second->Enabled() != enable) { | 800 if (it->second->Enabled() != enable) { |
747 it->second->Enable(enable); | 801 it->second->Enable(enable); |
748 did_change = true; | 802 did_change = true; |
749 break; | 803 break; |
750 } | 804 } |
751 } | 805 } |
752 } | 806 } |
753 | 807 |
754 return did_change; | 808 return did_change; |
755 } | 809 } |
756 | 810 |
757 void PluginList::DisableOutdatedPluginGroups() { | 811 void PluginList::DisableOutdatedPluginGroups() { |
758 disable_outdated_plugins_ = true; | 812 disable_outdated_plugins_ = true; |
759 } | 813 } |
760 | 814 |
815 const PluginList::DisabledPlugins& PluginList::GetDisabledPlugins() const { | |
816 AutoLock lock(lock_); | |
817 return disabled_plugins_; | |
818 } | |
819 | |
820 const PluginList::DisabledGroups& PluginList::GetDisabledGroups() const { | |
821 AutoLock lock(lock_); | |
822 return disabled_groups_; | |
823 } | |
824 | |
761 PluginList::~PluginList() { | 825 PluginList::~PluginList() { |
762 Shutdown(); | 826 Shutdown(); |
763 } | 827 } |
764 | 828 |
765 void PluginList::Shutdown() { | 829 void PluginList::Shutdown() { |
766 // TODO | 830 // TODO |
767 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but | 831 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but |
768 // since this singleton lives until the process is destroyed, no explicit | 832 // since this singleton lives until the process is destroyed, no explicit |
769 // cleanup is necessary. | 833 // cleanup is necessary. |
770 // However, when running on Valgrind, we need to do the cleanup to keep the | 834 // However, when running on Valgrind, we need to do the cleanup to keep the |
771 // memory tree green. | 835 // memory tree green. |
772 #if defined(OS_POSIX) | 836 #if defined(OS_POSIX) |
773 if (RUNNING_ON_VALGRIND) { | 837 if (RUNNING_ON_VALGRIND) { |
774 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), | 838 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), |
775 plugin_groups_.end()); | 839 plugin_groups_.end()); |
776 } | 840 } |
777 #endif | 841 #endif |
778 } | 842 } |
779 | 843 |
780 } // namespace NPAPI | 844 } // namespace NPAPI |
OLD | NEW |