 Chromium Code Reviews
 Chromium Code Reviews Issue 5699005:
  Policy: Re-enabled plugin still disabled  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 5699005:
  Policy: Re-enabled plugin still disabled  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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; | |
| 318 std::set<FilePath> visited_plugins; | 317 std::set<FilePath> visited_plugins; | 
| 319 | 318 | 
| 320 std::vector<FilePath> directories_to_scan; | 319 std::vector<FilePath> directories_to_scan; | 
| 321 GetPluginDirectories(&directories_to_scan); | 320 GetPluginDirectories(&directories_to_scan); | 
| 322 | 321 | 
| 323 // Load internal plugins first so that, if both an internal plugin and a | 322 // 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 | 323 // "discovered" plugin want to handle the same type, the internal plugin | 
| 325 // will have precedence. | 324 // will have precedence. | 
| 326 for (size_t i = 0; i < internal_plugins.size(); ++i) { | 325 for (size_t i = 0; i < internal_plugins.size(); ++i) { | 
| 327 if (internal_plugins[i].path.value() == kDefaultPluginLibraryName) | 326 if (internal_plugins[i].path.value() == kDefaultPluginLibraryName) | 
| 328 continue; | 327 continue; | 
| 329 LoadPlugin(internal_plugins[i].path, &new_plugins); | 328 LoadPlugin(internal_plugins[i].path); | 
| 330 } | 329 } | 
| 331 | 330 | 
| 332 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | 331 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | 
| 333 const FilePath& path = extra_plugin_paths[i]; | 332 const FilePath& path = extra_plugin_paths[i]; | 
| 334 if (visited_plugins.find(path) != visited_plugins.end()) | 333 if (visited_plugins.find(path) != visited_plugins.end()) | 
| 335 continue; | 334 continue; | 
| 336 LoadPlugin(path, &new_plugins); | 335 LoadPlugin(path); | 
| 337 visited_plugins.insert(path); | 336 visited_plugins.insert(path); | 
| 338 } | 337 } | 
| 339 | 338 | 
| 340 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | 339 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | 
| 341 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); | 340 LoadPluginsFromDir(extra_plugin_dirs[i], &visited_plugins); | 
| 342 } | 341 } | 
| 343 | 342 | 
| 344 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | 343 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | 
| 345 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); | 344 LoadPluginsFromDir(directories_to_scan[i], &visited_plugins); | 
| 346 } | 345 } | 
| 347 | 346 | 
| 348 #if defined(OS_WIN) | 347 #if defined(OS_WIN) | 
| 349 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); | 348 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); | 
| 350 #endif | 349 #endif | 
| 351 | 350 | 
| 352 // Load the default plugin last. | 351 // Load the default plugin last. | 
| 353 if (webkit_glue::IsDefaultPluginEnabled()) | 352 if (webkit_glue::IsDefaultPluginEnabled()) | 
| 354 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); | 353 LoadPlugin(FilePath(kDefaultPluginLibraryName)); | 
| 355 | 354 | 
| 356 // Disable all of the plugins and plugin groups that are disabled by policy. | 355 // 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 | 356 // 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 | 357 // 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 | 358 // 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. | 359 // change, i.e. from enabled to disabled. See bug 54681. | 
| 361 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 360 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 
| 362 it != plugin_groups_.end(); ++it) { | 361 it != plugin_groups_.end(); ++it) { | 
| 363 PluginGroup* group = it->second; | 362 PluginGroup* group = it->second; | 
| 364 string16 group_name = group->GetGroupName(); | 363 string16 group_name = group->GetGroupName(); | 
| 365 if (ShouldDisableGroup(group_name)) { | 364 if (ShouldDisableGroup(group_name)) { | 
| 366 group->Enable(false); | 365 group->Enable(false); | 
| 367 } | 366 } | 
| 368 | 367 | 
| 369 if (disable_outdated_plugins_) { | 368 if (disable_outdated_plugins_) { | 
| 370 group->DisableOutdatedPlugins(); | 369 group->DisableOutdatedPlugins(); | 
| 371 } | 370 } | 
| 372 if (!group->Enabled()) { | 371 if (!group->Enabled()) { | 
| 373 AutoLock lock(lock_); | 372 AutoLock lock(lock_); | 
| 374 disabled_groups_.insert(group_name); | 373 if (disabled_groups_.count(group_name) == 0) | 
| 374 disabled_groups_.insert(DisabledGroupsListElement(group_name, USER)); | |
| 375 } | 375 } | 
| 376 } | 376 } | 
| 377 | 377 | 
| 378 // Only update the data now since loading plugins can take a while. | |
| 379 AutoLock lock(lock_); | 378 AutoLock lock(lock_); | 
| 380 | |
| 381 plugins_ = new_plugins; | |
| 382 plugins_loaded_ = true; | 379 plugins_loaded_ = true; | 
| 383 } | 380 } | 
| 384 | 381 | 
| 385 void PluginList::LoadPlugin(const FilePath& path, | 382 void PluginList::LoadPlugin(const FilePath& path) { | 
| 386 std::vector<WebPluginInfo>* plugins) { | |
| 387 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 383 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 
| 388 << "Loading plugin " << path.value(); | 384 << "Loading plugin " << path.value(); | 
| 389 | 385 | 
| 390 WebPluginInfo plugin_info; | 386 WebPluginInfo plugin_info; | 
| 391 const PluginEntryPoints* entry_points; | 387 const PluginEntryPoints* entry_points; | 
| 392 | 388 | 
| 393 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) | 389 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) | 
| 394 return; | 390 return; | 
| 395 | 391 | 
| 396 if (!ShouldLoadPlugin(plugin_info, plugins)) | 392 if (!ShouldLoadPlugin(plugin_info)) | 
| 397 return; | 393 return; | 
| 398 | 394 | 
| 399 if (path.value() != kDefaultPluginLibraryName | 395 if (path.value() != kDefaultPluginLibraryName | 
| 400 #if defined(OS_WIN) && !defined(NDEBUG) | 396 #if defined(OS_WIN) && !defined(NDEBUG) | 
| 401 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY | 397 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY | 
| 402 #endif | 398 #endif | 
| 403 ) { | 399 ) { | 
| 404 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { | 400 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { | 
| 405 // TODO: don't load global handlers for now. | 401 // TODO: don't load global handlers for now. | 
| 406 // WebKit hands to the Plugin before it tries | 402 // WebKit hands to the Plugin before it tries | 
| 407 // to handle mimeTypes on its own. | 403 // to handle mimeTypes on its own. | 
| 408 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 404 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 
| 409 if (mime_type == "*" ) | 405 if (mime_type == "*" ) | 
| 410 return; | 406 return; | 
| 411 } | 407 } | 
| 412 } | 408 } | 
| 413 | 409 | 
| 414 // Mark disabled plugins as such. (This has to happen before calling | 410 // Mark disabled plugins as such. (This has to happen before calling | 
| 415 // |AddToPluginGroups(plugin_info)|.) | 411 // |AddToPluginGroups(plugin_info)|.) | 
| 416 if (disabled_plugins_.count(plugin_info.path)) { | 412 if (disabled_plugins_.count(plugin_info.path)) { | 
| 417 plugin_info.enabled = false; | 413 plugin_info.enabled = false; | 
| 418 } else { | 414 } else { | 
| 419 plugin_info.enabled = true; | 415 plugin_info.enabled = true; | 
| 420 } | 416 } | 
| 421 | 417 | 
| 422 AutoLock lock(lock_); | 418 AutoLock lock(lock_); | 
| 423 plugins->push_back(plugin_info); | |
| 424 AddToPluginGroups(plugin_info); | 419 AddToPluginGroups(plugin_info); | 
| 425 } | 420 } | 
| 426 | 421 | 
| 427 bool PluginList::SupportsType(const WebPluginInfo& info, | 422 bool PluginList::SupportsType(const WebPluginInfo& info, | 
| 428 const std::string &mime_type, | 423 const std::string &mime_type, | 
| 429 bool allow_wildcard) { | 424 bool allow_wildcard) { | 
| 430 // Webkit will ask for a plugin to handle empty mime types. | 425 // Webkit will ask for a plugin to handle empty mime types. | 
| 431 if (mime_type.empty()) | 426 if (mime_type.empty()) | 
| 432 return false; | 427 return false; | 
| 433 | 428 | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 458 } | 453 } | 
| 459 | 454 | 
| 460 return false; | 455 return false; | 
| 461 } | 456 } | 
| 462 | 457 | 
| 463 | 458 | 
| 464 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 459 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 
| 465 LoadPlugins(refresh); | 460 LoadPlugins(refresh); | 
| 466 | 461 | 
| 467 AutoLock lock(lock_); | 462 AutoLock lock(lock_); | 
| 468 *plugins = plugins_; | 463 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); | 
| 464 it != plugins_.end(); | |
| 465 ++it) { | |
| 466 plugins->push_back(**it); | |
| 467 } | |
| 469 } | 468 } | 
| 470 | 469 | 
| 471 void PluginList::GetEnabledPlugins(bool refresh, | 470 void PluginList::GetEnabledPlugins(bool refresh, | 
| 472 std::vector<WebPluginInfo>* plugins) { | 471 std::vector<WebPluginInfo>* plugins) { | 
| 473 LoadPlugins(refresh); | 472 LoadPlugins(refresh); | 
| 474 | 473 | 
| 475 plugins->clear(); | 474 plugins->clear(); | 
| 476 AutoLock lock(lock_); | 475 AutoLock lock(lock_); | 
| 477 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); | 476 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); | 
| 478 it != plugins_.end(); | 477 it != plugins_.end(); | 
| 479 ++it) { | 478 ++it) { | 
| 480 if (it->enabled) | 479 if ((*it)->enabled) | 
| 481 plugins->push_back(*it); | 480 plugins->push_back(**it); | 
| 482 } | 481 } | 
| 483 } | 482 } | 
| 484 | 483 | 
| 485 void PluginList::GetPluginInfoArray( | 484 void PluginList::GetPluginInfoArray( | 
| 486 const GURL& url, | 485 const GURL& url, | 
| 487 const std::string& mime_type, | 486 const std::string& mime_type, | 
| 488 bool allow_wildcard, | 487 bool allow_wildcard, | 
| 489 std::vector<WebPluginInfo>* info, | 488 std::vector<WebPluginInfo>* info, | 
| 490 std::vector<std::string>* actual_mime_types) { | 489 std::vector<std::string>* actual_mime_types) { | 
| 491 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 490 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 
| 492 DCHECK(info); | 491 DCHECK(info); | 
| 493 | 492 | 
| 494 LoadPlugins(false); | 493 LoadPlugins(false); | 
| 495 AutoLock lock(lock_); | 494 AutoLock lock(lock_); | 
| 496 info->clear(); | 495 info->clear(); | 
| 497 if (actual_mime_types) | 496 if (actual_mime_types) | 
| 498 actual_mime_types->clear(); | 497 actual_mime_types->clear(); | 
| 499 | 498 | 
| 500 std::set<FilePath> visited_plugins; | 499 std::set<FilePath> visited_plugins; | 
| 501 | 500 | 
| 502 // Add in enabled plugins by mime type. | 501 // Add in enabled plugins by mime type. | 
| 503 WebPluginInfo default_plugin; | 502 WebPluginInfo default_plugin; | 
| 504 for (size_t i = 0; i < plugins_.size(); ++i) { | 503 for (size_t i = 0; i < plugins_.size(); ++i) { | 
| 505 if (plugins_[i].enabled && | 504 if (plugins_[i]->enabled && | 
| 506 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 505 SupportsType(*plugins_[i], mime_type, allow_wildcard)) { | 
| 507 FilePath path = plugins_[i].path; | 506 FilePath path = plugins_[i]->path; | 
| 508 if (path.value() != kDefaultPluginLibraryName && | 507 if (path.value() != kDefaultPluginLibraryName && | 
| 509 visited_plugins.insert(path).second) { | 508 visited_plugins.insert(path).second) { | 
| 510 info->push_back(plugins_[i]); | 509 info->push_back(*plugins_[i]); | 
| 511 if (actual_mime_types) | 510 if (actual_mime_types) | 
| 512 actual_mime_types->push_back(mime_type); | 511 actual_mime_types->push_back(mime_type); | 
| 513 } | 512 } | 
| 514 } | 513 } | 
| 515 } | 514 } | 
| 516 | 515 | 
| 517 // Add in enabled plugins by url. | 516 // Add in enabled plugins by url. | 
| 518 std::string path = url.path(); | 517 std::string path = url.path(); | 
| 519 std::string::size_type last_dot = path.rfind('.'); | 518 std::string::size_type last_dot = path.rfind('.'); | 
| 520 if (last_dot != std::string::npos) { | 519 if (last_dot != std::string::npos) { | 
| 521 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); | 520 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); | 
| 522 std::string actual_mime_type; | 521 std::string actual_mime_type; | 
| 523 for (size_t i = 0; i < plugins_.size(); ++i) { | 522 for (size_t i = 0; i < plugins_.size(); ++i) { | 
| 524 if (plugins_[i].enabled && | 523 if (plugins_[i]->enabled && | 
| 525 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { | 524 SupportsExtension(*plugins_[i], extension, &actual_mime_type)) { | 
| 526 FilePath path = plugins_[i].path; | 525 FilePath path = plugins_[i]->path; | 
| 527 if (path.value() != kDefaultPluginLibraryName && | 526 if (path.value() != kDefaultPluginLibraryName && | 
| 528 visited_plugins.insert(path).second) { | 527 visited_plugins.insert(path).second) { | 
| 529 info->push_back(plugins_[i]); | 528 info->push_back(*plugins_[i]); | 
| 530 if (actual_mime_types) | 529 if (actual_mime_types) | 
| 531 actual_mime_types->push_back(actual_mime_type); | 530 actual_mime_types->push_back(actual_mime_type); | 
| 532 } | 531 } | 
| 533 } | 532 } | 
| 534 } | 533 } | 
| 535 } | 534 } | 
| 536 | 535 | 
| 537 // Add in disabled plugins by mime type. | 536 // Add in disabled plugins by mime type. | 
| 538 for (size_t i = 0; i < plugins_.size(); ++i) { | 537 for (size_t i = 0; i < plugins_.size(); ++i) { | 
| 539 if (!plugins_[i].enabled && | 538 if (!plugins_[i]->enabled && | 
| 540 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 539 SupportsType(*plugins_[i], mime_type, allow_wildcard)) { | 
| 541 FilePath path = plugins_[i].path; | 540 FilePath path = plugins_[i]->path; | 
| 542 if (path.value() != kDefaultPluginLibraryName && | 541 if (path.value() != kDefaultPluginLibraryName && | 
| 543 visited_plugins.insert(path).second) { | 542 visited_plugins.insert(path).second) { | 
| 544 info->push_back(plugins_[i]); | 543 info->push_back(*plugins_[i]); | 
| 545 if (actual_mime_types) | 544 if (actual_mime_types) | 
| 546 actual_mime_types->push_back(mime_type); | 545 actual_mime_types->push_back(mime_type); | 
| 547 } | 546 } | 
| 548 } | 547 } | 
| 549 } | 548 } | 
| 550 | 549 | 
| 551 // Add the default plugin at the end if it supports the mime type given, | 550 // Add the default plugin at the end if it supports the mime type given, | 
| 552 // and the default plugin is enabled. | 551 // and the default plugin is enabled. | 
| 553 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { | 552 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { | 
| 554 const WebPluginInfo& default_info = plugins_.back(); | 553 const WebPluginInfo& default_info = *plugins_.back(); | 
| 555 if (SupportsType(default_info, mime_type, allow_wildcard)) { | 554 if (SupportsType(default_info, mime_type, allow_wildcard)) { | 
| 556 info->push_back(default_info); | 555 info->push_back(default_info); | 
| 557 if (actual_mime_types) | 556 if (actual_mime_types) | 
| 558 actual_mime_types->push_back(mime_type); | 557 actual_mime_types->push_back(mime_type); | 
| 559 } | 558 } | 
| 560 } | 559 } | 
| 561 } | 560 } | 
| 562 | 561 | 
| 563 bool PluginList::GetPluginInfo(const GURL& url, | 562 bool PluginList::GetPluginInfo(const GURL& url, | 
| 564 const std::string& mime_type, | 563 const std::string& mime_type, | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 587 } | 586 } | 
| 588 } | 587 } | 
| 589 return false; | 588 return false; | 
| 590 } | 589 } | 
| 591 | 590 | 
| 592 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 591 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 
| 593 WebPluginInfo* info) { | 592 WebPluginInfo* info) { | 
| 594 LoadPlugins(false); | 593 LoadPlugins(false); | 
| 595 AutoLock lock(lock_); | 594 AutoLock lock(lock_); | 
| 596 for (size_t i = 0; i < plugins_.size(); ++i) { | 595 for (size_t i = 0; i < plugins_.size(); ++i) { | 
| 597 if (plugins_[i].path == plugin_path) { | 596 if (plugins_[i]->path == plugin_path) { | 
| 598 *info = plugins_[i]; | 597 *info = *plugins_[i]; | 
| 599 return true; | 598 return true; | 
| 600 } | 599 } | 
| 601 } | 600 } | 
| 602 | 601 | 
| 603 return false; | 602 return false; | 
| 604 } | 603 } | 
| 605 | 604 | 
| 606 void PluginList::GetPluginGroups( | 605 void PluginList::GetPluginGroups( | 
| 607 bool load_if_necessary, | 606 bool load_if_necessary, | 
| 608 std::vector<PluginGroup>* plugin_groups) { | 607 std::vector<PluginGroup>* plugin_groups) { | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 // probably won't be able to search for this group by identifier, but at | 662 // 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 | 663 // 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 | 664 // 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 | 665 // handle the same MIME types (and it has a higher priority), so this one | 
| 667 // is not going to run anyway. | 666 // is not going to run anyway. | 
| 668 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | 667 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | 
| 669 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | 668 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | 
| 670 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 669 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 
| 671 plugin_groups_.insert(std::make_pair(identifier, group)); | 670 plugin_groups_.insert(std::make_pair(identifier, group)); | 
| 672 } | 671 } | 
| 673 group->AddPlugin(web_plugin_info, next_priority_++); | 672 WebPluginInfo* group_copy = group->AddPlugin(web_plugin_info, next_priority_); | 
| 673 if (group_copy) { | |
| 674 next_priority_++; | |
| 675 plugins_.push_back(group_copy); | |
| 676 string16 group_name = group->GetGroupName(); | |
| 677 if (!group->Enabled() && !disabled_groups_.count(group_name)) { | |
| 678 disabled_groups_.insert(DisabledGroupsListElement( | |
| 679 group_name, | |
| 680 PluginGroup::IsPluginNameDisabledByPolicy(group_name) ? | |
| 681 POLICY : USER)); | |
| 682 } else if (group->Enabled() && disabled_groups_.count(group_name)) { | |
| 683 disabled_groups_.erase(group_name); | |
| 684 } | |
| 685 // We don't need to protect the flag here because it is protected from the | |
| 686 // callers of |AddToPluginGroups|. | |
| 
Bernhard Bauer
2010/12/15 17:23:45
Nit: Leftover comment?
 | |
| 687 } | |
| 674 return group; | 688 return group; | 
| 675 } | 689 } | 
| 676 | 690 | 
| 677 bool PluginList::EnablePlugin(const FilePath& filename) { | 691 bool PluginList::EnablePlugin(const FilePath& filename) { | 
| 678 AutoLock lock(lock_); | 692 AutoLock lock(lock_); | 
| 679 | 693 | 
| 680 bool did_enable = false; | 694 bool did_enable = false; | 
| 681 | 695 | 
| 682 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); | 696 DisabledPlugins::iterator entry = | 
| 683 if (entry == disabled_plugins_.end()) | 697 disabled_plugins_.find(filename); | 
| 698 if (entry == disabled_plugins_.end() || entry->second == POLICY) | |
| 684 return did_enable; // Early exit if plugin not in disabled list. | 699 return did_enable; // Early exit if plugin not in disabled list. | 
| 
Bernhard Bauer
2010/12/15 17:23:45
Please update this comment.
 | |
| 685 | 700 | 
| 686 disabled_plugins_.erase(entry); // Remove from disabled list. | 701 disabled_plugins_.erase(entry); // Remove from disabled list. | 
| 687 | 702 | 
| 688 // Set enabled flags if necessary. | 703 // Set enabled flags if necessary. | 
| 689 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | 704 for (std::vector<WebPluginInfo*>::iterator it = plugins_.begin(); | 
| 690 it != plugins_.end(); | 705 it != plugins_.end(); | 
| 691 ++it) { | 706 ++it) { | 
| 692 if (it->path == filename) { | 707 if ((*it)->path == filename) { | 
| 693 DCHECK(!it->enabled); // Should have been disabled. | 708 DCHECK(!(*it)->enabled); // Should have been disabled. | 
| 694 it->enabled = true; | 709 (*it)->enabled = true; | 
| 710 PluginGroup* group = AddToPluginGroups(**it); | |
| 711 bool group_was_enabled = group->Enabled(); | |
| 712 group->RefreshEnabledState(); | |
| 713 if (group_was_enabled && group->Enabled()) { | |
| 714 DisabledGroups::iterator entry = | |
| 715 disabled_groups_.find(group->GetGroupName()); | |
| 716 if (entry != disabled_groups_.end()) | |
| 717 disabled_groups_.erase(entry); | |
| 
Bernhard Bauer
2010/12/15 17:23:45
Nit: just disabled_groups_.erase(group->GetGroupNa
 | |
| 718 } | |
| 695 did_enable = true; | 719 did_enable = true; | 
| 696 } | 720 } | 
| 697 } | 721 } | 
| 698 | 722 | 
| 699 return did_enable; | 723 return did_enable; | 
| 700 } | 724 } | 
| 701 | 725 | 
| 702 bool PluginList::DisablePlugin(const FilePath& filename) { | 726 bool PluginList::DisablePlugin(const FilePath& filename, bool policy_disabled) { | 
| 703 AutoLock lock(lock_); | 727 AutoLock lock(lock_); | 
| 704 | 728 | 
| 705 bool did_disable = false; | 729 bool did_disable = false; | 
| 706 | 730 | 
| 707 if (disabled_plugins_.find(filename) != disabled_plugins_.end()) | 731 DisabledPlugins::iterator entry = | 
| 732 disabled_plugins_.find(filename); | |
| 733 if (entry != disabled_plugins_.end()) { | |
| 734 if ((entry->second == POLICY && !policy_disabled) || | |
| 735 (entry->second == USER && policy_disabled)) | |
| 736 entry->second = POLICY_AND_USER; | |
| 
Bernhard Bauer
2010/12/15 17:23:45
Nit: Braces around this line.
 | |
| 708 return did_disable; // Early exit if plugin already in disabled list. | 737 return did_disable; // Early exit if plugin already in disabled list. | 
| 
Bernhard Bauer
2010/12/15 17:23:45
Nit: Update comment.
 | |
| 738 } | |
| 709 | 739 | 
| 710 disabled_plugins_.insert(filename); // Add to disabled list. | 740 // Add to disabled list. | 
| 741 disabled_plugins_.insert( | |
| 742 DisabledPluginsListElement(filename, policy_disabled ? POLICY : USER)); | |
| 711 | 743 | 
| 712 // Unset enabled flags if necessary. | 744 // Unset enabled flags if necessary. | 
| 713 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | 745 for (std::vector<WebPluginInfo*>::iterator it = plugins_.begin(); | 
| 714 it != plugins_.end(); | 746 it != plugins_.end(); | 
| 715 ++it) { | 747 ++it) { | 
| 716 if (it->path == filename) { | 748 if ((*it)->path == filename) { | 
| 717 DCHECK(it->enabled); // Should have been enabled. | 749 DCHECK((*it)->enabled); // Should have been enabled. | 
| 718 it->enabled = false; | 750 (*it)->enabled = false; | 
| 751 PluginGroup* group = AddToPluginGroups(**it); | |
| 752 group->RefreshEnabledState(); | |
| 753 if (!group->Enabled()) { | |
| 754 if (!disabled_groups_.count(group->GetGroupName())) { | |
| 755 disabled_groups_.insert( | |
| 756 DisabledGroupsListElement(group->GetGroupName(), | |
| 757 policy_disabled ? POLICY : USER)); | |
| 758 } | |
| 759 } | |
| 719 did_disable = true; | 760 did_disable = true; | 
| 720 } | 761 } | 
| 721 } | 762 } | 
| 722 | 763 | 
| 723 return did_disable; | 764 return did_disable; | 
| 724 } | 765 } | 
| 725 | 766 | 
| 726 bool PluginList::EnableGroup(bool enable, const string16& group_name) { | 767 bool PluginList::EnableGroup(bool enable, const string16& group_name) { | 
| 727 bool did_change = false; | 768 bool did_change = false; | 
| 728 { | 769 { | 
| 729 AutoLock lock(lock_); | 770 AutoLock lock(lock_); | 
| 730 | 771 | 
| 731 std::set<string16>::iterator entry = disabled_groups_.find(group_name); | 772 DisabledGroups::iterator entry = | 
| 773 disabled_groups_.find(group_name); | |
| 732 if (enable) { | 774 if (enable) { | 
| 733 if (entry == disabled_groups_.end()) | 775 if (entry == disabled_groups_.end() || entry->second == POLICY) | 
| 734 return did_change; // Early exit if group not in disabled list. | 776 return did_change; // Early exit if group not in disabled list. | 
| 735 disabled_groups_.erase(entry); // Remove from disabled list. | 777 disabled_groups_.erase(entry); // Remove from disabled list. | 
| 736 } else { | 778 } else { | 
| 737 if (entry != disabled_groups_.end()) | 779 if (entry != disabled_groups_.end()) | 
| 738 return did_change; // Early exit if group already in disabled list. | 780 return did_change; // Early exit if group already in disabled list. | 
| 739 disabled_groups_.insert(group_name); | 781 disabled_groups_.insert( | 
| 782 DisabledGroupsListElement( | |
| 783 group_name, | |
| 784 PluginGroup::IsPluginNameDisabledByPolicy(group_name) ? | |
| 785 POLICY : USER)); | |
| 740 } | 786 } | 
| 741 } | 787 } | 
| 742 | 788 | 
| 743 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 789 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 
| 744 it != plugin_groups_.end(); ++it) { | 790 it != plugin_groups_.end(); ++it) { | 
| 745 if (it->second->GetGroupName() == group_name) { | 791 if (it->second->GetGroupName() == group_name) { | 
| 746 if (it->second->Enabled() != enable) { | 792 if (it->second->Enabled() != enable) { | 
| 747 it->second->Enable(enable); | 793 it->second->Enable(enable); | 
| 748 did_change = true; | 794 did_change = true; | 
| 749 break; | 795 break; | 
| 750 } | 796 } | 
| 751 } | 797 } | 
| 752 } | 798 } | 
| 753 | 799 | 
| 754 return did_change; | 800 return did_change; | 
| 755 } | 801 } | 
| 756 | 802 | 
| 757 void PluginList::DisableOutdatedPluginGroups() { | 803 void PluginList::DisableOutdatedPluginGroups() { | 
| 758 disable_outdated_plugins_ = true; | 804 disable_outdated_plugins_ = true; | 
| 759 } | 805 } | 
| 760 | 806 | 
| 807 const PluginList::DisabledPlugins& PluginList::GetDisabledPlugins() const { | |
| 808 AutoLock lock(lock_); | |
| 809 return disabled_plugins_; | |
| 810 } | |
| 811 | |
| 812 const PluginList::DisabledGroups& PluginList::GetDisabledGroups() const { | |
| 813 AutoLock lock(lock_); | |
| 814 return disabled_groups_; | |
| 815 } | |
| 816 | |
| 761 PluginList::~PluginList() { | 817 PluginList::~PluginList() { | 
| 762 Shutdown(); | 818 Shutdown(); | 
| 763 } | 819 } | 
| 764 | 820 | 
| 765 void PluginList::Shutdown() { | 821 void PluginList::Shutdown() { | 
| 766 // TODO | 822 // TODO | 
| 767 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but | 823 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but | 
| 768 // since this singleton lives until the process is destroyed, no explicit | 824 // since this singleton lives until the process is destroyed, no explicit | 
| 769 // cleanup is necessary. | 825 // cleanup is necessary. | 
| 770 // However, when running on Valgrind, we need to do the cleanup to keep the | 826 // However, when running on Valgrind, we need to do the cleanup to keep the | 
| 771 // memory tree green. | 827 // memory tree green. | 
| 772 #if defined(OS_POSIX) | 828 #if defined(OS_POSIX) | 
| 773 if (RUNNING_ON_VALGRIND) { | 829 if (RUNNING_ON_VALGRIND) { | 
| 774 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), | 830 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), | 
| 775 plugin_groups_.end()); | 831 plugin_groups_.end()); | 
| 776 } | 832 } | 
| 777 #endif | 833 #endif | 
| 778 } | 834 } | 
| 779 | 835 | 
| 780 } // namespace NPAPI | 836 } // namespace NPAPI | 
| OLD | NEW |