| 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_group.h" | 5 #include "webkit/glue/plugins/plugin_group.h" |
| 6 | 6 |
| 7 #include "base/linked_ptr.h" | 7 #include "base/linked_ptr.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 PluginGroup::PluginGroup(const string16& group_name, | 93 PluginGroup::PluginGroup(const string16& group_name, |
| 94 const string16& name_matcher, | 94 const string16& name_matcher, |
| 95 const std::string& update_url, | 95 const std::string& update_url, |
| 96 const std::string& identifier) | 96 const std::string& identifier) |
| 97 : identifier_(identifier), | 97 : identifier_(identifier), |
| 98 group_name_(group_name), | 98 group_name_(group_name), |
| 99 name_matcher_(name_matcher), | 99 name_matcher_(name_matcher), |
| 100 update_url_(update_url), | 100 update_url_(update_url), |
| 101 enabled_(false), | 101 enabled_(false), |
| 102 version_(Version::GetVersionFromString("0")) { | 102 version_(Version::GetVersionFromString("0")), |
| 103 plugin_list_(NULL) { |
| 103 } | 104 } |
| 104 | 105 |
| 105 void PluginGroup::InitFrom(const PluginGroup& other) { | 106 void PluginGroup::InitFrom(const PluginGroup& other) { |
| 106 enabled_ = false; | |
| 107 identifier_ = other.identifier_; | 107 identifier_ = other.identifier_; |
| 108 group_name_ = other.group_name_; | 108 group_name_ = other.group_name_; |
| 109 name_matcher_ = other.name_matcher_; | 109 name_matcher_ = other.name_matcher_; |
| 110 description_ = other.description_; |
| 110 update_url_ = other.update_url_; | 111 update_url_ = other.update_url_; |
| 111 for (size_t i = 0; i < other.version_ranges_.size(); ++i) | |
| 112 version_ranges_.push_back(other.version_ranges_[i]); | |
| 113 DCHECK_EQ(other.web_plugin_infos_.size(), other.web_plugin_positions_.size()); | |
| 114 std::list<WebPluginInfo>::const_iterator it = other.web_plugin_infos_.begin(); | |
| 115 std::vector<int>::const_iterator itprio = other.web_plugin_positions_.begin(); | |
| 116 for (; it != other.web_plugin_infos_.end(); ++it, ++itprio) | |
| 117 AddPlugin(*it, *itprio, NULL); | |
| 118 if (!version_.get()) | |
| 119 version_.reset(Version::GetVersionFromString("0")); | |
| 120 enabled_ = other.enabled_; | 112 enabled_ = other.enabled_; |
| 113 version_ranges_ = other.version_ranges_; |
| 114 version_.reset(other.version_->Clone()); |
| 115 web_plugin_infos_ = other.web_plugin_infos_; |
| 116 web_plugin_positions_ = other.web_plugin_positions_; |
| 117 plugin_list_ = other.plugin_list_; |
| 121 } | 118 } |
| 122 | 119 |
| 123 PluginGroup::PluginGroup(const PluginGroup& other) { | 120 PluginGroup::PluginGroup(const PluginGroup& other) { |
| 124 InitFrom(other); | 121 InitFrom(other); |
| 125 } | 122 } |
| 126 | 123 |
| 127 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | 124 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
| 128 version_ranges_.clear(); | |
| 129 InitFrom(other); | 125 InitFrom(other); |
| 130 return *this; | 126 return *this; |
| 131 } | 127 } |
| 132 | 128 |
| 133 /*static*/ | 129 /*static*/ |
| 134 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 130 PluginGroup* PluginGroup::FromPluginGroupDefinition( |
| 135 const PluginGroupDefinition& definition) { | 131 const PluginGroupDefinition& definition) { |
| 136 PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name), | 132 PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name), |
| 137 ASCIIToUTF16(definition.name_matcher), | 133 ASCIIToUTF16(definition.name_matcher), |
| 138 definition.update_url, | 134 definition.update_url, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 259 } |
| 264 | 260 |
| 265 std::list<WebPluginInfo>& PluginGroup::GetPlugins() { | 261 std::list<WebPluginInfo>& PluginGroup::GetPlugins() { |
| 266 return web_plugin_infos_; | 262 return web_plugin_infos_; |
| 267 } | 263 } |
| 268 | 264 |
| 269 std::vector<int>& PluginGroup::GetPluginPositions() { | 265 std::vector<int>& PluginGroup::GetPluginPositions() { |
| 270 return web_plugin_positions_; | 266 return web_plugin_positions_; |
| 271 } | 267 } |
| 272 | 268 |
| 269 bool PluginGroup::IsEmpty() const { |
| 270 return web_plugin_infos_.empty(); |
| 271 } |
| 272 |
| 273 string16 PluginGroup::GetGroupName() const { | 273 string16 PluginGroup::GetGroupName() const { |
| 274 if (!group_name_.empty()) | 274 if (!group_name_.empty()) |
| 275 return group_name_; | 275 return group_name_; |
| 276 DCHECK_EQ(1u, web_plugin_infos_.size()); | 276 DCHECK_EQ(1u, web_plugin_infos_.size()); |
| 277 FilePath::StringType path = | 277 FilePath::StringType path = |
| 278 web_plugin_infos_.front().path.BaseName().RemoveExtension().value(); | 278 web_plugin_infos_.front().path.BaseName().RemoveExtension().value(); |
| 279 #if defined(OS_POSIX) | 279 #if defined(OS_POSIX) |
| 280 return UTF8ToUTF16(path); | 280 return UTF8ToUTF16(path); |
| 281 #elif defined(OS_WIN) | 281 #elif defined(OS_WIN) |
| 282 return WideToUTF16(path); | 282 return WideToUTF16(path); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 void PluginGroup::DisableOutdatedPlugins() { | 392 void PluginGroup::DisableOutdatedPlugins() { |
| 393 bool first_enabled = true; | 393 bool first_enabled = true; |
| 394 | 394 |
| 395 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); | 395 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
| 396 it != web_plugin_infos_.end(); ++it) { | 396 it != web_plugin_infos_.end(); ++it) { |
| 397 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 397 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
| 398 if (version.get()) { | 398 if (version.get()) { |
| 399 bool plugin_is_outdated = false; | 399 bool plugin_is_outdated = false; |
| 400 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 400 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
| 401 if (IsPluginOutdated(*version, version_ranges_[i])) { | 401 if (IsPluginOutdated(*version, version_ranges_[i])) { |
| 402 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, false); | 402 GetPluginList()->DisablePlugin(it->path, false); |
| 403 plugin_is_outdated = true; | 403 plugin_is_outdated = true; |
| 404 break; | 404 break; |
| 405 } | 405 } |
| 406 } | 406 } |
| 407 if (!plugin_is_outdated && first_enabled) { | 407 if (!plugin_is_outdated && first_enabled) { |
| 408 first_enabled = false; | 408 first_enabled = false; |
| 409 UpdateDescriptionAndVersion(*it); | 409 UpdateDescriptionAndVersion(*it); |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 void PluginGroup::Enable(bool enable) { | 415 void PluginGroup::Enable(bool enable) { |
| 416 bool enabled_plugin_exists = false; | 416 bool enabled_plugin_exists = false; |
| 417 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); | 417 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
| 418 it != web_plugin_infos_.end(); ++it) { | 418 it != web_plugin_infos_.end(); ++it) { |
| 419 bool policy_disabled = IsPluginNameDisabledByPolicy(it->name); | 419 bool policy_disabled = IsPluginNameDisabledByPolicy(it->name); |
| 420 if (enable && !policy_disabled) { | 420 if (enable && !policy_disabled) { |
| 421 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 421 GetPluginList()->EnablePlugin(it->path); |
| 422 enabled_plugin_exists = true; | 422 enabled_plugin_exists = true; |
| 423 } else { | 423 } else { |
| 424 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, policy_disabled); | 424 GetPluginList()->DisablePlugin(it->path, policy_disabled); |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 enabled_ = enabled_plugin_exists; | 427 enabled_ = enabled_plugin_exists; |
| 428 } | 428 } |
| 429 | 429 |
| 430 void PluginGroup::RefreshEnabledState() { | 430 void PluginGroup::RefreshEnabledState() { |
| 431 bool enabled_plugin_exists = false; | 431 bool enabled_plugin_exists = false; |
| 432 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); | 432 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
| 433 it != web_plugin_infos_.end(); ++it) { | 433 it != web_plugin_infos_.end(); ++it) { |
| 434 if (it->enabled) { | 434 if (it->enabled) { |
| 435 enabled_plugin_exists = true; | 435 enabled_plugin_exists = true; |
| 436 break; | 436 break; |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 enabled_ = enabled_plugin_exists; | 439 enabled_ = enabled_plugin_exists; |
| 440 } | 440 } |
| 441 |
| 442 NPAPI::PluginList* PluginGroup::GetPluginList() const { |
| 443 if (plugin_list_) |
| 444 return plugin_list_; |
| 445 return NPAPI::PluginList::Singleton(); |
| 446 } |
| OLD | NEW |