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) { | |
|
Bernhard Bauer
2010/12/03 16:13:28
I have a slight suspicion that we might be able to
Jakob Kummerow
2010/12/06 18:21:12
Well, yes -- it might go away someday. Doesn't hav
| |
| 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) .) | |
|
Bernhard Bauer
2010/12/03 16:13:28
Nit: Wrap the code in bars |like this|, then it's
Jakob Kummerow
2010/12/06 18:21:12
Done. ("kind of" being the key word in that senten
| |
| 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 std::vector<PluginGroup> PluginList::GetPluginGroups(bool load_if_necessary) { |
| 480 PluginMap* plugin_groups) { | |
| 481 if (load_if_necessary) | 483 if (load_if_necessary) |
| 482 LoadPlugins(false); | 484 LoadPlugins(false); |
| 483 | 485 std::vector<PluginGroup> plugin_groups; |
| 484 AutoLock lock(lock_); | 486 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); |
| 485 GetPluginGroups(&plugins_, plugin_groups); | 487 it != plugin_groups_.end(); ++it) { |
| 488 plugin_groups.push_back(*it->second); | |
| 489 DCHECK(plugin_groups.back().web_plugin_infos_.size() == | |
| 490 it->second->web_plugin_infos_.size()); | |
| 491 } | |
| 492 return plugin_groups; | |
|
Bernhard Bauer
2010/12/03 16:13:28
Remember back in plugin_exceptions_table_model.cc
Jakob Kummerow
2010/12/06 18:21:12
Done.
| |
| 486 } | 493 } |
| 487 | 494 |
| 488 // static | 495 PluginGroup PluginList::GetPluginGroup(const WebPluginInfo& web_plugin_info) { |
| 489 void PluginList::GetPluginGroups(const std::vector<WebPluginInfo>* plugins, | 496 PluginGroup* group = AddToPluginGroups(web_plugin_info); |
| 490 PluginMap* plugin_groups) { | 497 return PluginGroup(*group); |
| 491 plugin_groups->clear(); | 498 } |
| 492 // We first search for an existing group that matches our name, | 499 |
| 493 // and only create a new group if we can't find any. | 500 string16 PluginList::GetPluginGroupName(std::string identifier) { |
| 494 for (size_t i = 0; i < plugins->size(); ++i) { | 501 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); |
| 495 const WebPluginInfo& web_plugin = (*plugins)[i]; | 502 if (it == plugin_groups_.end()) { |
| 496 PluginGroup* group = PluginGroup::FindGroupMatchingPlugin( | 503 return string16(); |
| 497 *plugin_groups, web_plugin); | 504 } |
| 498 if (!group) { | 505 return it->second->GetGroupName(); |
| 499 group = PluginGroup::CopyOrCreatePluginGroup(web_plugin); | 506 } |
| 500 std::string identifier = group->identifier(); | 507 |
| 501 // If the identifier is not unique, use the full path. This means that we | 508 std::string PluginList::GetPluginGroupIdentifier( |
| 502 // probably won't be able to search for this group by identifier, but at | 509 const WebPluginInfo& web_plugin_info) { |
| 503 // least it's going to be in the set of plugin groups, and if there | 510 PluginGroup* group = AddToPluginGroups(web_plugin_info); |
| 504 // is already a plug-in with the same filename, it's probably going to | 511 return group->identifier(); |
| 505 // handle the same MIME types (and it has a higher priority), so this one | 512 } |
| 506 // is not going to run anyway. | 513 |
| 507 if (plugin_groups->find(identifier) != plugin_groups->end()) | 514 void PluginList::AddHardcodedPluginGroups() { |
| 508 #if defined(OS_POSIX) | 515 AutoLock lock(lock_); |
| 509 identifier = web_plugin.path.value(); | 516 const PluginGroupDefinition* definitions = |
| 510 #elif defined(OS_WIN) | 517 PluginGroup::GetPluginGroupDefinitions(); |
| 511 identifier = base::SysWideToUTF8(web_plugin.path.value()); | 518 for (size_t i = 0; i < PluginGroup::GetPluginGroupDefinitionsSize(); ++i) { |
| 512 #endif | 519 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( |
| 513 DCHECK(plugin_groups->find(identifier) == plugin_groups->end()); | 520 definitions[i]); |
| 514 (*plugin_groups)[identifier] = linked_ptr<PluginGroup>(group); | 521 std::string identifier = definition_group->identifier(); |
| 515 } | 522 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
| 516 group->AddPlugin(web_plugin, i); | 523 plugin_groups_.insert(std::make_pair(identifier, definition_group)); |
| 517 } | 524 } |
| 518 } | 525 } |
| 519 | 526 |
| 527 PluginGroup* PluginList::AddToPluginGroups( | |
| 528 const WebPluginInfo& web_plugin_info) { | |
| 529 AutoLock lock(lock_); | |
| 530 PluginGroup* group = PluginGroup::FindGroupMatchingPlugin( | |
| 531 &plugin_groups_, | |
| 532 web_plugin_info); | |
| 533 if (!group) { | |
| 534 group = PluginGroup::FromWebPluginInfo(web_plugin_info); | |
| 535 std::string identifier = group->identifier(); | |
| 536 // If the identifier is not unique, use the full path. This means that we | |
| 537 // probably won't be able to search for this group by identifier, but at | |
| 538 // least it's going to be in the set of plugin groups, and if there | |
| 539 // is already a plug-in with the same filename, it's probably going to | |
| 540 // handle the same MIME types (and it has a higher priority), so this one | |
| 541 // is not going to run anyway. | |
| 542 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | |
| 543 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | |
| 544 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | |
| 545 plugin_groups_.insert(std::make_pair(identifier, group)); | |
| 546 } | |
| 547 group->AddPlugin(web_plugin_info, next_priority_++); | |
| 548 return group; | |
| 549 } | |
| 550 | |
| 520 bool PluginList::EnablePlugin(const FilePath& filename) { | 551 bool PluginList::EnablePlugin(const FilePath& filename) { |
| 521 AutoLock lock(lock_); | 552 AutoLock lock(lock_); |
| 522 | 553 |
| 523 bool did_enable = false; | 554 bool did_enable = false; |
| 524 | 555 |
| 525 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); | 556 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); |
| 526 if (entry == disabled_plugins_.end()) | 557 if (entry == disabled_plugins_.end()) |
| 527 return did_enable; // Early exit if plugin not in disabled list. | 558 return did_enable; // Early exit if plugin not in disabled list. |
| 528 | 559 |
| 529 disabled_plugins_.erase(entry); // Remove from disabled list. | 560 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()) | 607 if (entry == disabled_groups_.end()) |
| 577 return did_change; // Early exit if group not in disabled list. | 608 return did_change; // Early exit if group not in disabled list. |
| 578 disabled_groups_.erase(entry); // Remove from disabled list. | 609 disabled_groups_.erase(entry); // Remove from disabled list. |
| 579 } else { | 610 } else { |
| 580 if (entry != disabled_groups_.end()) | 611 if (entry != disabled_groups_.end()) |
| 581 return did_change; // Early exit if group already in disabled list. | 612 return did_change; // Early exit if group already in disabled list. |
| 582 disabled_groups_.insert(group_name); | 613 disabled_groups_.insert(group_name); |
| 583 } | 614 } |
| 584 } | 615 } |
| 585 | 616 |
| 586 PluginMap plugin_groups; | 617 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
| 587 GetPluginGroups(false, &plugin_groups); | 618 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) { | 619 if (it->second->GetGroupName() == group_name) { |
| 591 if (it->second->Enabled() != enable) { | 620 if (it->second->Enabled() != enable) { |
| 592 it->second->Enable(enable); | 621 it->second->Enable(enable); |
| 593 did_change = true; | 622 did_change = true; |
| 594 break; | 623 break; |
| 595 } | 624 } |
| 596 } | 625 } |
| 597 } | 626 } |
| 598 | 627 |
| 599 return did_change; | 628 return did_change; |
| 600 } | 629 } |
| 601 | 630 |
| 602 void PluginList::DisableOutdatedPluginGroups() { | 631 void PluginList::DisableOutdatedPluginGroups() { |
| 603 disable_outdated_plugins_ = true; | 632 disable_outdated_plugins_ = true; |
| 604 } | 633 } |
| 605 | 634 |
| 606 PluginList::~PluginList() { | 635 PluginList::~PluginList() { |
| 607 } | 636 } |
| 608 | 637 |
| 609 void PluginList::Shutdown() { | 638 void PluginList::Shutdown() { |
| 610 // TODO | 639 // TODO |
| 640 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but | |
| 641 // since this singleton lives until the process is destroyed, no explicit | |
| 642 // cleanup is necessary. | |
| 611 } | 643 } |
| 612 | 644 |
| 613 } // namespace NPAPI | 645 } // namespace NPAPI |
| OLD | NEW |