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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 150 |
| 151 info->mime_types.push_back(mime_type); | 151 info->mime_types.push_back(mime_type); |
| 152 } | 152 } |
| 153 | 153 |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 | 156 |
| 157 PluginList::PluginList() | 157 PluginList::PluginList() |
| 158 : plugins_loaded_(false), | 158 : plugins_loaded_(false), |
| 159 plugins_need_refresh_(false), | 159 plugins_need_refresh_(false), |
| 160 disable_outdated_plugins_(false) { | 160 disable_outdated_plugins_(false), |
| 161 next_priority_(0) { | |
| 161 PlatformInit(); | 162 PlatformInit(); |
| 163 AddHardcodedPluginGroups(); | |
| 162 } | 164 } |
| 163 | 165 |
| 164 bool PluginList::ShouldDisableGroup(const string16& group_name) { | 166 bool PluginList::ShouldDisableGroup(const string16& group_name) { |
| 165 AutoLock lock(lock_); | 167 AutoLock lock(lock_); |
| 166 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { | 168 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { |
| 167 disabled_groups_.insert(group_name); | 169 disabled_groups_.insert(group_name); |
| 168 return true; | 170 return true; |
| 169 } | 171 } |
| 170 return disabled_groups_.count(group_name) > 0; | 172 return disabled_groups_.count(group_name) > 0; |
| 171 } | 173 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 228 |
| 227 // Load the default plugin last. | 229 // Load the default plugin last. |
| 228 if (webkit_glue::IsDefaultPluginEnabled()) | 230 if (webkit_glue::IsDefaultPluginEnabled()) |
| 229 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); | 231 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); |
| 230 | 232 |
| 231 // Disable all of the plugins and plugin groups that are disabled by policy. | 233 // Disable all of the plugins and plugin groups that are disabled by policy. |
| 232 // There's currenly a bug that makes it impossible to correctly re-enable | 234 // There's currenly a bug that makes it impossible to correctly re-enable |
| 233 // plugins or plugin-groups to their original, "pre-policy" state, so | 235 // plugins or plugin-groups to their original, "pre-policy" state, so |
| 234 // plugins and groups are only changed to a more "safe" state after a policy | 236 // plugins and groups are only changed to a more "safe" state after a policy |
| 235 // change, i.e. from enabled to disabled. See bug 54681. | 237 // change, i.e. from enabled to disabled. See bug 54681. |
| 236 PluginMap plugin_groups; | 238 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
| 237 GetPluginGroups(&new_plugins, &plugin_groups); | 239 it != plugin_groups_.end(); ++it) { |
| 238 for (PluginMap::const_iterator it = plugin_groups.begin(); | 240 PluginGroup* group = it->second; |
| 239 it != plugin_groups.end(); ++it) { | |
| 240 PluginGroup* group = it->second.get(); | |
| 241 string16 group_name = group->GetGroupName(); | 241 string16 group_name = group->GetGroupName(); |
| 242 if (ShouldDisableGroup(group_name)) { | 242 if (ShouldDisableGroup(group_name)) { |
| 243 it->second->Enable(false); | 243 group->Enable(false); |
| 244 } | 244 } |
| 245 | 245 |
| 246 if (disable_outdated_plugins_) { | 246 if (disable_outdated_plugins_) { |
| 247 group->DisableOutdatedPlugins(); | 247 group->DisableOutdatedPlugins(); |
| 248 if (!group->Enabled()) { | 248 } |
| 249 AutoLock lock(lock_); | 249 if (!group->Enabled()) { |
| 250 disabled_groups_.insert(group_name); | 250 AutoLock lock(lock_); |
| 251 } | 251 disabled_groups_.insert(group_name); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Only update the data now since loading plugins can take a while. | 255 // Only update the data now since loading plugins can take a while. |
| 256 AutoLock lock(lock_); | 256 AutoLock lock(lock_); |
| 257 | 257 |
| 258 // Mark disabled plugins as such. | |
| 259 for (size_t i = 0; i < new_plugins.size(); ++i) { | |
| 260 if (disabled_plugins_.count(new_plugins[i].path)) | |
| 261 new_plugins[i].enabled = false; | |
| 262 } | |
| 263 | |
| 264 plugins_ = new_plugins; | 258 plugins_ = new_plugins; |
| 265 plugins_loaded_ = true; | 259 plugins_loaded_ = true; |
| 266 } | 260 } |
| 267 | 261 |
| 268 void PluginList::LoadPlugin(const FilePath& path, | 262 void PluginList::LoadPlugin(const FilePath& path, |
| 269 std::vector<WebPluginInfo>* plugins) { | 263 std::vector<WebPluginInfo>* plugins) { |
| 270 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 264 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
| 271 << "Loading plugin " << path.value(); | 265 << "Loading plugin " << path.value(); |
| 272 | 266 |
| 273 WebPluginInfo plugin_info; | 267 WebPluginInfo plugin_info; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 287 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { | 281 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { |
| 288 // TODO: don't load global handlers for now. | 282 // TODO: don't load global handlers for now. |
| 289 // WebKit hands to the Plugin before it tries | 283 // WebKit hands to the Plugin before it tries |
| 290 // to handle mimeTypes on its own. | 284 // to handle mimeTypes on its own. |
| 291 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 285 const std::string &mime_type = plugin_info.mime_types[i].mime_type; |
| 292 if (mime_type == "*" ) | 286 if (mime_type == "*" ) |
| 293 return; | 287 return; |
| 294 } | 288 } |
| 295 } | 289 } |
| 296 | 290 |
| 291 // Mark disabled plugins as such. (This has to happen before calling | |
| 292 // |AddToPluginGroups(plugin_info)|.) | |
| 293 if (disabled_plugins_.count(plugin_info.path)) { | |
| 294 plugin_info.enabled = false; | |
| 295 } else { | |
| 296 plugin_info.enabled = true; | |
| 297 } | |
| 298 | |
| 297 plugins->push_back(plugin_info); | 299 plugins->push_back(plugin_info); |
| 300 AddToPluginGroups(plugin_info); | |
| 298 } | 301 } |
| 299 | 302 |
| 300 bool PluginList::SupportsType(const WebPluginInfo& info, | 303 bool PluginList::SupportsType(const WebPluginInfo& info, |
| 301 const std::string &mime_type, | 304 const std::string &mime_type, |
| 302 bool allow_wildcard) { | 305 bool allow_wildcard) { |
| 303 // Webkit will ask for a plugin to handle empty mime types. | 306 // Webkit will ask for a plugin to handle empty mime types. |
| 304 if (mime_type.empty()) | 307 if (mime_type.empty()) |
| 305 return false; | 308 return false; |
| 306 | 309 |
| 307 for (size_t i = 0; i < info.mime_types.size(); ++i) { | 310 for (size_t i = 0; i < info.mime_types.size(); ++i) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 for (size_t i = 0; i < plugins_.size(); ++i) { | 472 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 470 if (plugins_[i].path == plugin_path) { | 473 if (plugins_[i].path == plugin_path) { |
| 471 *info = plugins_[i]; | 474 *info = plugins_[i]; |
| 472 return true; | 475 return true; |
| 473 } | 476 } |
| 474 } | 477 } |
| 475 | 478 |
| 476 return false; | 479 return false; |
| 477 } | 480 } |
| 478 | 481 |
| 479 void PluginList::GetPluginGroups(bool load_if_necessary, | 482 void PluginList::GetPluginGroups( |
| 480 PluginMap* plugin_groups) { | 483 bool load_if_necessary, |
| 484 std::vector<PluginGroup>* plugin_groups) { | |
| 481 if (load_if_necessary) | 485 if (load_if_necessary) |
| 482 LoadPlugins(false); | 486 LoadPlugins(false); |
| 483 | |
| 484 AutoLock lock(lock_); | |
| 485 GetPluginGroups(&plugins_, plugin_groups); | |
| 486 } | |
| 487 | |
| 488 // static | |
| 489 void PluginList::GetPluginGroups(const std::vector<WebPluginInfo>* plugins, | |
| 490 PluginMap* plugin_groups) { | |
| 491 plugin_groups->clear(); | 487 plugin_groups->clear(); |
| 492 // We first search for an existing group that matches our name, | 488 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); |
| 493 // and only create a new group if we can't find any. | 489 it != plugin_groups_.end(); ++it) { |
| 494 for (size_t i = 0; i < plugins->size(); ++i) { | 490 plugin_groups->push_back(*it->second); |
| 495 const WebPluginInfo& web_plugin = (*plugins)[i]; | |
| 496 PluginGroup* group = PluginGroup::FindGroupMatchingPlugin( | |
| 497 *plugin_groups, web_plugin); | |
| 498 if (!group) { | |
| 499 group = PluginGroup::CopyOrCreatePluginGroup(web_plugin); | |
| 500 std::string identifier = group->identifier(); | |
| 501 // If the identifier is not unique, use the full path. This means that we | |
| 502 // probably won't be able to search for this group by identifier, but at | |
| 503 // least it's going to be in the set of plugin groups, and if there | |
| 504 // is already a plug-in with the same filename, it's probably going to | |
| 505 // handle the same MIME types (and it has a higher priority), so this one | |
| 506 // is not going to run anyway. | |
| 507 if (plugin_groups->find(identifier) != plugin_groups->end()) | |
| 508 #if defined(OS_POSIX) | |
| 509 identifier = web_plugin.path.value(); | |
| 510 #elif defined(OS_WIN) | |
| 511 identifier = base::SysWideToUTF8(web_plugin.path.value()); | |
| 512 #endif | |
| 513 DCHECK(plugin_groups->find(identifier) == plugin_groups->end()); | |
| 514 (*plugin_groups)[identifier] = linked_ptr<PluginGroup>(group); | |
| 515 } | |
| 516 group->AddPlugin(web_plugin, i); | |
| 517 } | 491 } |
| 518 } | 492 } |
| 519 | 493 |
| 494 const PluginGroup* PluginList::GetPluginGroup( | |
| 495 const WebPluginInfo& web_plugin_info) { | |
| 496 return AddToPluginGroups(web_plugin_info); | |
| 497 } | |
| 498 | |
| 499 string16 PluginList::GetPluginGroupName(std::string identifier) { | |
| 500 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); | |
| 501 if (it == plugin_groups_.end()) { | |
| 502 return string16(); | |
| 503 } | |
| 504 return it->second->GetGroupName(); | |
| 505 } | |
| 506 | |
| 507 std::string PluginList::GetPluginGroupIdentifier( | |
| 508 const WebPluginInfo& web_plugin_info) { | |
| 509 PluginGroup* group = AddToPluginGroups(web_plugin_info); | |
| 510 return group->identifier(); | |
| 511 } | |
| 512 | |
| 513 void PluginList::AddHardcodedPluginGroups() { | |
| 514 AutoLock lock(lock_); | |
| 515 const PluginGroupDefinition* definitions = | |
| 516 PluginGroup::GetPluginGroupDefinitions(); | |
| 517 for (size_t i = 0; i < PluginGroup::GetPluginGroupDefinitionsSize(); ++i) { | |
| 518 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( | |
| 519 definitions[i]); | |
| 520 std::string identifier = definition_group->identifier(); | |
| 521 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | |
| 522 plugin_groups_.insert(std::make_pair(identifier, definition_group)); | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 PluginGroup* PluginList::AddToPluginGroups( | |
| 527 const WebPluginInfo& web_plugin_info) { | |
| 528 AutoLock lock(lock_); | |
|
Bernhard Bauer
2010/12/07 10:32:05
As discussed offline, please move this lock to the
Jakob Kummerow
2010/12/07 11:43:08
Done.
| |
| 529 PluginGroup* group = NULL; | |
| 530 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | |
| 531 it != plugin_groups_.end(); ++it) { | |
| 532 if (it->second->Match(web_plugin_info)) | |
| 533 group = it->second; | |
| 534 } | |
| 535 if (!group) { | |
| 536 group = PluginGroup::FromWebPluginInfo(web_plugin_info); | |
| 537 std::string identifier = group->identifier(); | |
| 538 // If the identifier is not unique, use the full path. This means that we | |
| 539 // probably won't be able to search for this group by identifier, but at | |
| 540 // least it's going to be in the set of plugin groups, and if there | |
| 541 // is already a plug-in with the same filename, it's probably going to | |
| 542 // handle the same MIME types (and it has a higher priority), so this one | |
| 543 // is not going to run anyway. | |
| 544 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | |
| 545 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | |
| 546 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | |
| 547 plugin_groups_.insert(std::make_pair(identifier, group)); | |
| 548 } | |
| 549 group->AddPlugin(web_plugin_info, next_priority_++); | |
| 550 return group; | |
| 551 } | |
| 552 | |
| 520 bool PluginList::EnablePlugin(const FilePath& filename) { | 553 bool PluginList::EnablePlugin(const FilePath& filename) { |
| 521 AutoLock lock(lock_); | 554 AutoLock lock(lock_); |
| 522 | 555 |
| 523 bool did_enable = false; | 556 bool did_enable = false; |
| 524 | 557 |
| 525 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); | 558 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); |
| 526 if (entry == disabled_plugins_.end()) | 559 if (entry == disabled_plugins_.end()) |
| 527 return did_enable; // Early exit if plugin not in disabled list. | 560 return did_enable; // Early exit if plugin not in disabled list. |
| 528 | 561 |
| 529 disabled_plugins_.erase(entry); // Remove from disabled list. | 562 disabled_plugins_.erase(entry); // Remove from disabled list. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 if (entry == disabled_groups_.end()) | 609 if (entry == disabled_groups_.end()) |
| 577 return did_change; // Early exit if group not in disabled list. | 610 return did_change; // Early exit if group not in disabled list. |
| 578 disabled_groups_.erase(entry); // Remove from disabled list. | 611 disabled_groups_.erase(entry); // Remove from disabled list. |
| 579 } else { | 612 } else { |
| 580 if (entry != disabled_groups_.end()) | 613 if (entry != disabled_groups_.end()) |
| 581 return did_change; // Early exit if group already in disabled list. | 614 return did_change; // Early exit if group already in disabled list. |
| 582 disabled_groups_.insert(group_name); | 615 disabled_groups_.insert(group_name); |
| 583 } | 616 } |
| 584 } | 617 } |
| 585 | 618 |
| 586 PluginMap plugin_groups; | 619 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
| 587 GetPluginGroups(false, &plugin_groups); | 620 it != plugin_groups_.end(); ++it) { |
| 588 for (PluginMap::const_iterator it = plugin_groups.begin(); | |
| 589 it != plugin_groups.end(); ++it) { | |
| 590 if (it->second->GetGroupName() == group_name) { | 621 if (it->second->GetGroupName() == group_name) { |
| 591 if (it->second->Enabled() != enable) { | 622 if (it->second->Enabled() != enable) { |
| 592 it->second->Enable(enable); | 623 it->second->Enable(enable); |
| 593 did_change = true; | 624 did_change = true; |
| 594 break; | 625 break; |
| 595 } | 626 } |
| 596 } | 627 } |
| 597 } | 628 } |
| 598 | 629 |
| 599 return did_change; | 630 return did_change; |
| 600 } | 631 } |
| 601 | 632 |
| 602 void PluginList::DisableOutdatedPluginGroups() { | 633 void PluginList::DisableOutdatedPluginGroups() { |
| 603 disable_outdated_plugins_ = true; | 634 disable_outdated_plugins_ = true; |
| 604 } | 635 } |
| 605 | 636 |
| 606 PluginList::~PluginList() { | 637 PluginList::~PluginList() { |
| 607 } | 638 } |
| 608 | 639 |
| 609 void PluginList::Shutdown() { | 640 void PluginList::Shutdown() { |
| 610 // TODO | 641 // TODO |
| 642 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but | |
| 643 // since this singleton lives until the process is destroyed, no explicit | |
| 644 // cleanup is necessary. | |
| 611 } | 645 } |
| 612 | 646 |
| 613 } // namespace NPAPI | 647 } // namespace NPAPI |
| OLD | NEW |