Chromium Code Reviews| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool PluginList::PluginsLoaded() { | 161 bool PluginList::PluginsLoaded() { |
| 162 AutoLock lock(lock_); | 162 AutoLock lock(lock_); |
| 163 return plugins_loaded_; | 163 return plugins_loaded_; |
| 164 } | 164 } |
| 165 | 165 |
| 166 void PluginList::RefreshPlugins() { | 166 void PluginList::RefreshPlugins() { |
| 167 AutoLock lock(lock_); | 167 AutoLock lock(lock_); |
| 168 plugins_need_refresh_ = true; | 168 plugins_need_refresh_ = true; |
| 169 plugins_vector_is_dirty_ = true; | |
| 169 } | 170 } |
| 170 | 171 |
| 171 void PluginList::AddExtraPluginPath(const FilePath& plugin_path) { | 172 void PluginList::AddExtraPluginPath(const FilePath& plugin_path) { |
| 172 // Chrome OS only loads plugins from /opt/google/chrome/plugins. | 173 // Chrome OS only loads plugins from /opt/google/chrome/plugins. |
| 173 #if !defined(OS_CHROMEOS) | 174 #if !defined(OS_CHROMEOS) |
| 174 AutoLock lock(lock_); | 175 AutoLock lock(lock_); |
| 175 extra_plugin_paths_.push_back(plugin_path); | 176 extra_plugin_paths_.push_back(plugin_path); |
| 176 #endif | 177 #endif |
| 177 } | 178 } |
| 178 | 179 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 | 274 |
| 274 info->mime_types.push_back(mime_type); | 275 info->mime_types.push_back(mime_type); |
| 275 } | 276 } |
| 276 | 277 |
| 277 return true; | 278 return true; |
| 278 } | 279 } |
| 279 | 280 |
| 280 PluginList::PluginList() | 281 PluginList::PluginList() |
| 281 : plugins_loaded_(false), | 282 : plugins_loaded_(false), |
| 282 plugins_need_refresh_(false), | 283 plugins_need_refresh_(false), |
| 284 plugins_vector_is_dirty_(false), | |
| 283 disable_outdated_plugins_(false), | 285 disable_outdated_plugins_(false), |
| 284 next_priority_(0) { | 286 next_priority_(0) { |
| 285 PlatformInit(); | 287 PlatformInit(); |
| 286 AddHardcodedPluginGroups(); | 288 AddHardcodedPluginGroups(); |
| 287 } | 289 } |
| 288 | 290 |
| 289 bool PluginList::ShouldDisableGroup(const string16& group_name) { | 291 bool PluginList::ShouldDisableGroup(const string16& group_name) { |
| 290 AutoLock lock(lock_); | 292 AutoLock lock(lock_); |
| 291 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { | 293 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { |
| 292 disabled_groups_.insert(group_name); | 294 disabled_groups_.insert(DisabledGroupsListElement(group_name, POLICY)); |
| 293 return true; | 295 return true; |
| 294 } | 296 } |
| 295 return disabled_groups_.count(group_name) > 0; | 297 return disabled_groups_.count(group_name) > 0; |
| 296 } | 298 } |
| 297 | 299 |
| 298 void PluginList::LoadPlugins(bool refresh) { | 300 void PluginList::LoadPlugins(bool refresh) { |
| 299 // Don't want to hold the lock while loading new plugins, so we don't block | 301 // 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. | 302 // other methods if they're called on other threads. |
| 301 std::vector<FilePath> extra_plugin_paths; | 303 std::vector<FilePath> extra_plugin_paths; |
| 302 std::vector<FilePath> extra_plugin_dirs; | 304 std::vector<FilePath> extra_plugin_dirs; |
| 303 std::vector<PluginVersionInfo> internal_plugins; | 305 std::vector<PluginVersionInfo> internal_plugins; |
| 304 { | 306 { |
| 305 AutoLock lock(lock_); | 307 AutoLock lock(lock_); |
| 306 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) | 308 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) |
| 307 return; | 309 return; |
| 308 | 310 |
| 309 // Clear the refresh bit now, because it might get set again before we | 311 // Clear the refresh bit now, because it might get set again before we |
| 310 // reach the end of the method. | 312 // reach the end of the method. |
| 311 plugins_need_refresh_ = false; | 313 plugins_need_refresh_ = false; |
| 312 extra_plugin_paths = extra_plugin_paths_; | 314 extra_plugin_paths = extra_plugin_paths_; |
| 313 extra_plugin_dirs = extra_plugin_dirs_; | 315 extra_plugin_dirs = extra_plugin_dirs_; |
| 314 internal_plugins = internal_plugins_; | 316 internal_plugins = internal_plugins_; |
| 315 } | 317 } |
| 316 | 318 |
| 317 std::vector<WebPluginInfo> new_plugins; | |
| 318 std::set<FilePath> visited_plugins; | 319 std::set<FilePath> visited_plugins; |
| 319 | 320 |
| 320 std::vector<FilePath> directories_to_scan; | 321 std::vector<FilePath> directories_to_scan; |
| 321 GetPluginDirectories(&directories_to_scan); | 322 GetPluginDirectories(&directories_to_scan); |
| 322 | 323 |
| 323 // Load internal plugins first so that, if both an internal plugin and a | 324 // 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 | 325 // "discovered" plugin want to handle the same type, the internal plugin |
| 325 // will have precedence. | 326 // will have precedence. |
| 326 for (size_t i = 0; i < internal_plugins.size(); ++i) { | 327 for (size_t i = 0; i < internal_plugins.size(); ++i) { |
| 327 if (internal_plugins[i].path.value() == kDefaultPluginLibraryName) | 328 if (internal_plugins[i].path.value() == kDefaultPluginLibraryName) |
| 328 continue; | 329 continue; |
| 329 LoadPlugin(internal_plugins[i].path, &new_plugins); | 330 LoadPlugin(internal_plugins[i].path); |
| 330 } | 331 } |
| 331 | 332 |
| 332 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | 333 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { |
| 333 const FilePath& path = extra_plugin_paths[i]; | 334 const FilePath& path = extra_plugin_paths[i]; |
| 334 if (visited_plugins.find(path) != visited_plugins.end()) | 335 if (visited_plugins.find(path) != visited_plugins.end()) |
| 335 continue; | 336 continue; |
| 336 LoadPlugin(path, &new_plugins); | 337 LoadPlugin(path); |
| 337 visited_plugins.insert(path); | 338 visited_plugins.insert(path); |
| 338 } | 339 } |
| 339 | 340 |
| 340 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | 341 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { |
| 341 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); | 342 LoadPluginsFromDir(extra_plugin_dirs[i], &visited_plugins); |
| 342 } | 343 } |
| 343 | 344 |
| 344 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | 345 for (size_t i = 0; i < directories_to_scan.size(); ++i) { |
| 345 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); | 346 LoadPluginsFromDir(directories_to_scan[i], &visited_plugins); |
| 346 } | 347 } |
| 347 | 348 |
| 348 #if defined(OS_WIN) | 349 #if defined(OS_WIN) |
| 349 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); | 350 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); |
| 350 #endif | 351 #endif |
| 351 | 352 |
| 352 // Load the default plugin last. | 353 // Load the default plugin last. |
| 353 if (webkit_glue::IsDefaultPluginEnabled()) | 354 if (webkit_glue::IsDefaultPluginEnabled()) |
| 354 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); | 355 LoadPlugin(FilePath(kDefaultPluginLibraryName)); |
| 355 | 356 |
| 356 // Disable all of the plugins and plugin groups that are disabled by policy. | 357 // 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 | 358 // 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 | 359 // 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 | 360 // 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. | 361 // change, i.e. from enabled to disabled. See bug 54681. |
| 361 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 362 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
| 362 it != plugin_groups_.end(); ++it) { | 363 it != plugin_groups_.end(); ++it) { |
| 363 PluginGroup* group = it->second; | 364 PluginGroup* group = it->second; |
| 364 string16 group_name = group->GetGroupName(); | 365 string16 group_name = group->GetGroupName(); |
| 365 if (ShouldDisableGroup(group_name)) { | 366 if (ShouldDisableGroup(group_name)) { |
| 366 group->Enable(false); | 367 group->Enable(false); |
| 367 } | 368 } |
| 368 | 369 |
| 369 if (disable_outdated_plugins_) { | 370 if (disable_outdated_plugins_) { |
| 370 group->DisableOutdatedPlugins(); | 371 group->DisableOutdatedPlugins(); |
| 371 } | 372 } |
| 372 if (!group->Enabled()) { | 373 if (!group->Enabled()) { |
| 373 AutoLock lock(lock_); | 374 AutoLock lock(lock_); |
| 374 disabled_groups_.insert(group_name); | 375 if(0 == disabled_groups_.count(group_name)) |
|
danno
2010/12/14 09:43:39
use == 0 formatting (reverse order). compiler give
pastarmovj
2010/12/15 14:44:51
Done.
| |
| 376 disabled_groups_.insert(DisabledGroupsListElement(group_name, USER)); | |
| 375 } | 377 } |
| 376 } | 378 } |
| 377 | 379 |
| 378 // Only update the data now since loading plugins can take a while. | 380 // Only update the data now since loading plugins can take a while. |
| 381 RebuildPluginsList(); | |
|
danno
2010/12/14 09:43:39
You also acquire the lock inside of RebuildPluginL
pastarmovj
2010/12/15 14:44:51
I have to for the plugins_loaded_ flag. However th
| |
| 382 //plugins_ = new_plugins; | |
| 379 AutoLock lock(lock_); | 383 AutoLock lock(lock_); |
| 380 | |
| 381 plugins_ = new_plugins; | |
| 382 plugins_loaded_ = true; | 384 plugins_loaded_ = true; |
| 383 } | 385 } |
| 384 | 386 |
| 385 void PluginList::LoadPlugin(const FilePath& path, | 387 void PluginList::RebuildPluginsList() { |
| 386 std::vector<WebPluginInfo>* plugins) { | 388 AutoLock lock(lock_); |
| 389 if(!plugins_vector_is_dirty_) return; | |
| 390 plugins_vector_is_dirty_ = false; | |
| 391 | |
| 392 std::vector<WebPluginInfo*> new_plugins; | |
| 393 new_plugins.resize(this->next_priority_); | |
| 394 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | |
| 395 it != plugin_groups_.end(); ++it) { | |
| 396 std::vector<WebPluginInfo>& group_plugins = it->second->GetPlugins(); | |
| 397 std::vector<int>::iterator itprio = | |
| 398 it->second->GetPluginPositions().begin(); | |
| 399 for (std::vector<WebPluginInfo>::iterator itp = group_plugins.begin(); | |
| 400 itp != group_plugins.end(); | |
| 401 ++itp,++itprio) { | |
| 402 new_plugins[*itprio] = &(*itp); | |
|
danno
2010/12/14 09:43:39
Whoa. Taking the address of a dereferenced iterato
pastarmovj
2010/12/15 14:44:51
Cool right ;)
| |
| 403 } | |
| 404 } | |
| 405 plugins_ = new_plugins; | |
| 406 } | |
| 407 | |
| 408 void PluginList::LoadPlugin(const FilePath& path) { | |
|
Bernhard Bauer
2010/12/14 04:21:49
Drive-by: Removing the |plugins| parameter may see
pastarmovj
2010/12/15 14:44:51
Done.
| |
| 387 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 409 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
| 388 << "Loading plugin " << path.value(); | 410 << "Loading plugin " << path.value(); |
| 389 | 411 |
| 390 WebPluginInfo plugin_info; | 412 WebPluginInfo plugin_info; |
| 391 const PluginEntryPoints* entry_points; | 413 const PluginEntryPoints* entry_points; |
| 392 | 414 |
| 393 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) | 415 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) |
| 394 return; | 416 return; |
| 395 | 417 |
| 396 if (!ShouldLoadPlugin(plugin_info, plugins)) | 418 if (!ShouldLoadPlugin(plugin_info)) |
| 397 return; | 419 return; |
| 398 | 420 |
| 399 if (path.value() != kDefaultPluginLibraryName | 421 if (path.value() != kDefaultPluginLibraryName |
| 400 #if defined(OS_WIN) && !defined(NDEBUG) | 422 #if defined(OS_WIN) && !defined(NDEBUG) |
| 401 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY | 423 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY |
| 402 #endif | 424 #endif |
| 403 ) { | 425 ) { |
| 404 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { | 426 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { |
| 405 // TODO: don't load global handlers for now. | 427 // TODO: don't load global handlers for now. |
| 406 // WebKit hands to the Plugin before it tries | 428 // WebKit hands to the Plugin before it tries |
| 407 // to handle mimeTypes on its own. | 429 // to handle mimeTypes on its own. |
| 408 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 430 const std::string &mime_type = plugin_info.mime_types[i].mime_type; |
| 409 if (mime_type == "*" ) | 431 if (mime_type == "*" ) |
| 410 return; | 432 return; |
| 411 } | 433 } |
| 412 } | 434 } |
| 413 | 435 |
| 414 // Mark disabled plugins as such. (This has to happen before calling | 436 // Mark disabled plugins as such. (This has to happen before calling |
| 415 // |AddToPluginGroups(plugin_info)|.) | 437 // |AddToPluginGroups(plugin_info)|.) |
| 416 if (disabled_plugins_.count(plugin_info.path)) { | 438 if (disabled_plugins_.count(plugin_info.path)) { |
| 417 plugin_info.enabled = false; | 439 plugin_info.enabled = false; |
| 418 } else { | 440 } else { |
| 419 plugin_info.enabled = true; | 441 plugin_info.enabled = true; |
| 420 } | 442 } |
| 421 | 443 |
| 422 AutoLock lock(lock_); | 444 AutoLock lock(lock_); |
| 423 plugins->push_back(plugin_info); | |
| 424 AddToPluginGroups(plugin_info); | 445 AddToPluginGroups(plugin_info); |
| 425 } | 446 } |
| 426 | 447 |
| 427 bool PluginList::SupportsType(const WebPluginInfo& info, | 448 bool PluginList::SupportsType(const WebPluginInfo& info, |
| 428 const std::string &mime_type, | 449 const std::string &mime_type, |
| 429 bool allow_wildcard) { | 450 bool allow_wildcard) { |
| 430 // Webkit will ask for a plugin to handle empty mime types. | 451 // Webkit will ask for a plugin to handle empty mime types. |
| 431 if (mime_type.empty()) | 452 if (mime_type.empty()) |
| 432 return false; | 453 return false; |
| 433 | 454 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 458 } | 479 } |
| 459 | 480 |
| 460 return false; | 481 return false; |
| 461 } | 482 } |
| 462 | 483 |
| 463 | 484 |
| 464 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 485 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
| 465 LoadPlugins(refresh); | 486 LoadPlugins(refresh); |
| 466 | 487 |
| 467 AutoLock lock(lock_); | 488 AutoLock lock(lock_); |
| 468 *plugins = plugins_; | 489 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); |
| 490 it != plugins_.end(); | |
| 491 ++it) { | |
| 492 plugins->push_back(**it); | |
| 493 } | |
| 469 } | 494 } |
| 470 | 495 |
| 471 void PluginList::GetEnabledPlugins(bool refresh, | 496 void PluginList::GetEnabledPlugins(bool refresh, |
| 472 std::vector<WebPluginInfo>* plugins) { | 497 std::vector<WebPluginInfo>* plugins) { |
| 473 LoadPlugins(refresh); | 498 LoadPlugins(refresh); |
| 474 | 499 |
| 475 plugins->clear(); | 500 plugins->clear(); |
| 476 AutoLock lock(lock_); | 501 AutoLock lock(lock_); |
| 477 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); | 502 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); |
| 478 it != plugins_.end(); | 503 it != plugins_.end(); |
| 479 ++it) { | 504 ++it) { |
| 480 if (it->enabled) | 505 if ((*it)->enabled) |
| 481 plugins->push_back(*it); | 506 plugins->push_back(**it); |
| 482 } | 507 } |
| 483 } | 508 } |
| 484 | 509 |
| 485 void PluginList::GetPluginInfoArray( | 510 void PluginList::GetPluginInfoArray( |
| 486 const GURL& url, | 511 const GURL& url, |
| 487 const std::string& mime_type, | 512 const std::string& mime_type, |
| 488 bool allow_wildcard, | 513 bool allow_wildcard, |
| 489 std::vector<WebPluginInfo>* info, | 514 std::vector<WebPluginInfo>* info, |
| 490 std::vector<std::string>* actual_mime_types) { | 515 std::vector<std::string>* actual_mime_types) { |
| 491 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 516 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
| 492 DCHECK(info); | 517 DCHECK(info); |
| 493 | 518 |
| 494 LoadPlugins(false); | 519 LoadPlugins(false); |
| 495 AutoLock lock(lock_); | 520 AutoLock lock(lock_); |
| 496 info->clear(); | 521 info->clear(); |
| 497 if (actual_mime_types) | 522 if (actual_mime_types) |
| 498 actual_mime_types->clear(); | 523 actual_mime_types->clear(); |
| 499 | 524 |
| 500 std::set<FilePath> visited_plugins; | 525 std::set<FilePath> visited_plugins; |
| 501 | 526 |
| 502 // Add in enabled plugins by mime type. | 527 // Add in enabled plugins by mime type. |
| 503 WebPluginInfo default_plugin; | 528 WebPluginInfo default_plugin; |
| 504 for (size_t i = 0; i < plugins_.size(); ++i) { | 529 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 505 if (plugins_[i].enabled && | 530 if (plugins_[i]->enabled && |
| 506 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 531 SupportsType(*plugins_[i], mime_type, allow_wildcard)) { |
| 507 FilePath path = plugins_[i].path; | 532 FilePath path = plugins_[i]->path; |
| 508 if (path.value() != kDefaultPluginLibraryName && | 533 if (path.value() != kDefaultPluginLibraryName && |
| 509 visited_plugins.insert(path).second) { | 534 visited_plugins.insert(path).second) { |
| 510 info->push_back(plugins_[i]); | 535 info->push_back(*plugins_[i]); |
| 511 if (actual_mime_types) | 536 if (actual_mime_types) |
| 512 actual_mime_types->push_back(mime_type); | 537 actual_mime_types->push_back(mime_type); |
| 513 } | 538 } |
| 514 } | 539 } |
| 515 } | 540 } |
| 516 | 541 |
| 517 // Add in enabled plugins by url. | 542 // Add in enabled plugins by url. |
| 518 std::string path = url.path(); | 543 std::string path = url.path(); |
| 519 std::string::size_type last_dot = path.rfind('.'); | 544 std::string::size_type last_dot = path.rfind('.'); |
| 520 if (last_dot != std::string::npos) { | 545 if (last_dot != std::string::npos) { |
| 521 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); | 546 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); |
| 522 std::string actual_mime_type; | 547 std::string actual_mime_type; |
| 523 for (size_t i = 0; i < plugins_.size(); ++i) { | 548 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 524 if (plugins_[i].enabled && | 549 if (plugins_[i]->enabled && |
| 525 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { | 550 SupportsExtension(*plugins_[i], extension, &actual_mime_type)) { |
| 526 FilePath path = plugins_[i].path; | 551 FilePath path = plugins_[i]->path; |
| 527 if (path.value() != kDefaultPluginLibraryName && | 552 if (path.value() != kDefaultPluginLibraryName && |
| 528 visited_plugins.insert(path).second) { | 553 visited_plugins.insert(path).second) { |
| 529 info->push_back(plugins_[i]); | 554 info->push_back(*plugins_[i]); |
| 530 if (actual_mime_types) | 555 if (actual_mime_types) |
| 531 actual_mime_types->push_back(actual_mime_type); | 556 actual_mime_types->push_back(actual_mime_type); |
| 532 } | 557 } |
| 533 } | 558 } |
| 534 } | 559 } |
| 535 } | 560 } |
| 536 | 561 |
| 537 // Add in disabled plugins by mime type. | 562 // Add in disabled plugins by mime type. |
| 538 for (size_t i = 0; i < plugins_.size(); ++i) { | 563 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 539 if (!plugins_[i].enabled && | 564 if (!plugins_[i]->enabled && |
| 540 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 565 SupportsType(*plugins_[i], mime_type, allow_wildcard)) { |
| 541 FilePath path = plugins_[i].path; | 566 FilePath path = plugins_[i]->path; |
| 542 if (path.value() != kDefaultPluginLibraryName && | 567 if (path.value() != kDefaultPluginLibraryName && |
| 543 visited_plugins.insert(path).second) { | 568 visited_plugins.insert(path).second) { |
| 544 info->push_back(plugins_[i]); | 569 info->push_back(*plugins_[i]); |
| 545 if (actual_mime_types) | 570 if (actual_mime_types) |
| 546 actual_mime_types->push_back(mime_type); | 571 actual_mime_types->push_back(mime_type); |
| 547 } | 572 } |
| 548 } | 573 } |
| 549 } | 574 } |
| 550 | 575 |
| 551 // Add the default plugin at the end if it supports the mime type given, | 576 // Add the default plugin at the end if it supports the mime type given, |
| 552 // and the default plugin is enabled. | 577 // and the default plugin is enabled. |
| 553 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { | 578 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { |
| 554 const WebPluginInfo& default_info = plugins_.back(); | 579 const WebPluginInfo& default_info = *plugins_.back(); |
| 555 if (SupportsType(default_info, mime_type, allow_wildcard)) { | 580 if (SupportsType(default_info, mime_type, allow_wildcard)) { |
| 556 info->push_back(default_info); | 581 info->push_back(default_info); |
| 557 if (actual_mime_types) | 582 if (actual_mime_types) |
| 558 actual_mime_types->push_back(mime_type); | 583 actual_mime_types->push_back(mime_type); |
| 559 } | 584 } |
| 560 } | 585 } |
| 561 } | 586 } |
| 562 | 587 |
| 563 bool PluginList::GetPluginInfo(const GURL& url, | 588 bool PluginList::GetPluginInfo(const GURL& url, |
| 564 const std::string& mime_type, | 589 const std::string& mime_type, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 587 } | 612 } |
| 588 } | 613 } |
| 589 return false; | 614 return false; |
| 590 } | 615 } |
| 591 | 616 |
| 592 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 617 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, |
| 593 WebPluginInfo* info) { | 618 WebPluginInfo* info) { |
| 594 LoadPlugins(false); | 619 LoadPlugins(false); |
| 595 AutoLock lock(lock_); | 620 AutoLock lock(lock_); |
| 596 for (size_t i = 0; i < plugins_.size(); ++i) { | 621 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 597 if (plugins_[i].path == plugin_path) { | 622 if (plugins_[i]->path == plugin_path) { |
| 598 *info = plugins_[i]; | 623 *info = *plugins_[i]; |
| 599 return true; | 624 return true; |
| 600 } | 625 } |
| 601 } | 626 } |
| 602 | 627 |
| 603 return false; | 628 return false; |
| 604 } | 629 } |
| 605 | 630 |
| 606 void PluginList::GetPluginGroups( | 631 void PluginList::GetPluginGroups( |
| 607 bool load_if_necessary, | 632 bool load_if_necessary, |
| 608 std::vector<PluginGroup>* plugin_groups) { | 633 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 | 688 // 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 | 689 // 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 | 690 // 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 | 691 // handle the same MIME types (and it has a higher priority), so this one |
| 667 // is not going to run anyway. | 692 // is not going to run anyway. |
| 668 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | 693 if (plugin_groups_.find(identifier) != plugin_groups_.end()) |
| 669 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | 694 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); |
| 670 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 695 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
| 671 plugin_groups_.insert(std::make_pair(identifier, group)); | 696 plugin_groups_.insert(std::make_pair(identifier, group)); |
| 672 } | 697 } |
| 673 group->AddPlugin(web_plugin_info, next_priority_++); | 698 if(group->AddPlugin(web_plugin_info, next_priority_++)){ |
| 699 // We don't need to protect the flag here because it is protected from the | |
| 700 // callers of |AddToPluginGroups|. | |
| 701 plugins_vector_is_dirty_ = true; | |
| 702 } | |
| 674 return group; | 703 return group; |
| 675 } | 704 } |
| 676 | 705 |
| 677 bool PluginList::EnablePlugin(const FilePath& filename) { | 706 bool PluginList::EnablePlugin(const FilePath& filename) { |
| 707 RebuildPluginsList(); | |
| 678 AutoLock lock(lock_); | 708 AutoLock lock(lock_); |
| 679 | 709 |
| 680 bool did_enable = false; | 710 bool did_enable = false; |
| 681 | 711 |
| 682 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); | 712 DisabledPluginsList::iterator entry = |
| 683 if (entry == disabled_plugins_.end()) | 713 disabled_plugins_.find(filename); |
| 714 if (entry == disabled_plugins_.end() || entry->second == POLICY) | |
| 684 return did_enable; // Early exit if plugin not in disabled list. | 715 return did_enable; // Early exit if plugin not in disabled list. |
| 685 | 716 |
| 686 disabled_plugins_.erase(entry); // Remove from disabled list. | 717 disabled_plugins_.erase(entry); // Remove from disabled list. |
| 687 | 718 |
| 688 // Set enabled flags if necessary. | 719 // Set enabled flags if necessary. |
| 689 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | 720 for (std::vector<WebPluginInfo*>::iterator it = plugins_.begin(); |
| 690 it != plugins_.end(); | 721 it != plugins_.end(); |
| 691 ++it) { | 722 ++it) { |
| 692 if (it->path == filename) { | 723 if ((*it)->path == filename) { |
| 693 DCHECK(!it->enabled); // Should have been disabled. | 724 DCHECK(!(*it)->enabled); // Should have been disabled. |
| 694 it->enabled = true; | 725 (*it)->enabled = true; |
| 726 AddToPluginGroups(**it)->RefreshEnabledState(); | |
| 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) { |
| 735 RebuildPluginsList(); | |
| 703 AutoLock lock(lock_); | 736 AutoLock lock(lock_); |
| 704 | 737 |
| 705 bool did_disable = false; | 738 bool did_disable = false; |
| 706 | 739 |
| 707 if (disabled_plugins_.find(filename) != disabled_plugins_.end()) | 740 DisabledPluginsList::iterator entry = |
| 741 disabled_plugins_.find(filename); | |
| 742 if (entry != disabled_plugins_.end()) | |
| 743 { | |
| 744 if ((entry->second == POLICY && !policy_disabled) || | |
| 745 (entry->second == USER && policy_disabled)) | |
| 746 entry->second = POLICY_AND_USER; | |
| 708 return did_disable; // Early exit if plugin already in disabled list. | 747 return did_disable; // Early exit if plugin already in disabled list. |
| 748 } | |
| 709 | 749 |
| 710 disabled_plugins_.insert(filename); // Add to disabled list. | 750 // Add to disabled list. |
| 751 disabled_plugins_.insert( | |
| 752 DisabledPluginsListElement(filename, policy_disabled ? POLICY : USER)); | |
| 711 | 753 |
| 712 // Unset enabled flags if necessary. | 754 // Unset enabled flags if necessary. |
| 713 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin(); | 755 for (std::vector<WebPluginInfo*>::iterator it = plugins_.begin(); |
| 714 it != plugins_.end(); | 756 it != plugins_.end(); |
| 715 ++it) { | 757 ++it) { |
| 716 if (it->path == filename) { | 758 if ((*it)->path == filename) { |
| 717 DCHECK(it->enabled); // Should have been enabled. | 759 DCHECK((*it)->enabled); // Should have been enabled. |
| 718 it->enabled = false; | 760 (*it)->enabled = false; |
| 761 AddToPluginGroups(**it)->RefreshEnabledState(); | |
| 719 did_disable = true; | 762 did_disable = true; |
| 720 } | 763 } |
| 721 } | 764 } |
| 722 | 765 |
| 723 return did_disable; | 766 return did_disable; |
| 724 } | 767 } |
| 725 | 768 |
| 726 bool PluginList::EnableGroup(bool enable, const string16& group_name) { | 769 bool PluginList::EnableGroup(bool enable, const string16& group_name) { |
| 727 bool did_change = false; | 770 bool did_change = false; |
| 728 { | 771 { |
| 729 AutoLock lock(lock_); | 772 AutoLock lock(lock_); |
| 730 | 773 |
| 731 std::set<string16>::iterator entry = disabled_groups_.find(group_name); | 774 DisabledGroupsList::iterator entry = |
| 775 disabled_groups_.find(group_name); | |
| 732 if (enable) { | 776 if (enable) { |
| 733 if (entry == disabled_groups_.end()) | 777 if (entry == disabled_groups_.end() || entry->second == POLICY) |
| 734 return did_change; // Early exit if group not in disabled list. | 778 return did_change; // Early exit if group not in disabled list. |
| 735 disabled_groups_.erase(entry); // Remove from disabled list. | 779 disabled_groups_.erase(entry); // Remove from disabled list. |
| 736 } else { | 780 } else { |
| 737 if (entry != disabled_groups_.end()) | 781 if (entry != disabled_groups_.end()) |
| 738 return did_change; // Early exit if group already in disabled list. | 782 return did_change; // Early exit if group already in disabled list. |
| 739 disabled_groups_.insert(group_name); | 783 disabled_groups_.insert( |
| 784 DisabledGroupsListElement( | |
| 785 group_name, | |
| 786 PluginGroup::IsPluginNameDisabledByPolicy(group_name) ? | |
| 787 POLICY : USER)); | |
| 740 } | 788 } |
| 741 } | 789 } |
| 742 | 790 |
| 743 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 791 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
| 744 it != plugin_groups_.end(); ++it) { | 792 it != plugin_groups_.end(); ++it) { |
| 745 if (it->second->GetGroupName() == group_name) { | 793 if (it->second->GetGroupName() == group_name) { |
| 746 if (it->second->Enabled() != enable) { | 794 if (it->second->Enabled() != enable) { |
| 747 it->second->Enable(enable); | 795 it->second->Enable(enable); |
| 748 did_change = true; | 796 did_change = true; |
| 749 break; | 797 break; |
| 750 } | 798 } |
| 751 } | 799 } |
| 752 } | 800 } |
| 753 | 801 |
| 754 return did_change; | 802 return did_change; |
| 755 } | 803 } |
| 756 | 804 |
| 757 void PluginList::DisableOutdatedPluginGroups() { | 805 void PluginList::DisableOutdatedPluginGroups() { |
| 758 disable_outdated_plugins_ = true; | 806 disable_outdated_plugins_ = true; |
| 759 } | 807 } |
| 760 | 808 |
| 809 void PluginList::GetDisabledPlugins(DisabledPluginsList* disabled_plugins) { | |
| 810 AutoLock lock(lock_); | |
| 811 *disabled_plugins = disabled_plugins_; | |
| 812 } | |
| 813 | |
| 814 void PluginList::GetDisabledGroups(DisabledGroupsList* disabled_groups) { | |
| 815 AutoLock lock(lock_); | |
| 816 *disabled_groups = disabled_groups_; | |
| 817 } | |
| 818 | |
| 761 PluginList::~PluginList() { | 819 PluginList::~PluginList() { |
| 762 Shutdown(); | 820 Shutdown(); |
| 763 } | 821 } |
| 764 | 822 |
| 765 void PluginList::Shutdown() { | 823 void PluginList::Shutdown() { |
| 766 // TODO | 824 // TODO |
| 767 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but | 825 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but |
| 768 // since this singleton lives until the process is destroyed, no explicit | 826 // since this singleton lives until the process is destroyed, no explicit |
| 769 // cleanup is necessary. | 827 // cleanup is necessary. |
| 770 // However, when running on Valgrind, we need to do the cleanup to keep the | 828 // However, when running on Valgrind, we need to do the cleanup to keep the |
| 771 // memory tree green. | 829 // memory tree green. |
| 772 #if defined(OS_POSIX) | 830 #if defined(OS_POSIX) |
| 773 if (RUNNING_ON_VALGRIND) { | 831 if (RUNNING_ON_VALGRIND) { |
| 774 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), | 832 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), |
| 775 plugin_groups_.end()); | 833 plugin_groups_.end()); |
| 776 } | 834 } |
| 777 #endif | 835 #endif |
| 778 } | 836 } |
| 779 | 837 |
| 780 } // namespace NPAPI | 838 } // namespace NPAPI |
| OLD | NEW |