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