| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (!version_range_low.empty()) | 150 if (!version_range_low.empty()) |
| 151 version_range_low_.reset(Version::GetVersionFromString(version_range_low)); | 151 version_range_low_.reset(Version::GetVersionFromString(version_range_low)); |
| 152 if (!version_range_high.empty()) { | 152 if (!version_range_high.empty()) { |
| 153 version_range_high_.reset( | 153 version_range_high_.reset( |
| 154 Version::GetVersionFromString(version_range_high)); | 154 Version::GetVersionFromString(version_range_high)); |
| 155 } | 155 } |
| 156 if (!min_version.empty()) | 156 if (!min_version.empty()) |
| 157 min_version_.reset(Version::GetVersionFromString(min_version)); | 157 min_version_.reset(Version::GetVersionFromString(min_version)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void PluginGroup::InitFrom(const PluginGroup& other) { |
| 161 identifier_ = other.identifier_; |
| 162 group_name_ = other.group_name_; |
| 163 name_matcher_ = other.name_matcher_; |
| 164 version_range_low_str_ = other.version_range_low_str_; |
| 165 version_range_high_str_ = other.version_range_high_str_; |
| 166 version_range_low_.reset( |
| 167 Version::GetVersionFromString(version_range_low_str_)); |
| 168 version_range_high_.reset( |
| 169 Version::GetVersionFromString(version_range_high_str_)); |
| 170 description_ = other.description_; |
| 171 update_url_ = other.update_url_; |
| 172 enabled_ = other.enabled_; |
| 173 min_version_str_ = other.min_version_str_; |
| 174 min_version_.reset(Version::GetVersionFromString(min_version_str_)); |
| 175 DCHECK(other.web_plugin_infos_.size() == other.web_plugin_positions_.size()); |
| 176 for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) |
| 177 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); |
| 178 if (!version_.get()) |
| 179 version_.reset(Version::GetVersionFromString("0")); |
| 180 } |
| 181 |
| 182 PluginGroup::PluginGroup(const PluginGroup& other) { |
| 183 InitFrom(other); |
| 184 } |
| 185 |
| 186 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
| 187 InitFrom(other); |
| 188 return *this; |
| 189 } |
| 190 |
| 191 /*static*/ |
| 160 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 192 PluginGroup* PluginGroup::FromPluginGroupDefinition( |
| 161 const PluginGroupDefinition& definition) { | 193 const PluginGroupDefinition& definition) { |
| 162 return new PluginGroup(ASCIIToUTF16(definition.name), | 194 return new PluginGroup(ASCIIToUTF16(definition.name), |
| 163 ASCIIToUTF16(definition.name_matcher), | 195 ASCIIToUTF16(definition.name_matcher), |
| 164 definition.version_matcher_low, | 196 definition.version_matcher_low, |
| 165 definition.version_matcher_high, | 197 definition.version_matcher_high, |
| 166 definition.min_version, | 198 definition.min_version, |
| 167 definition.update_url, | 199 definition.update_url, |
| 168 definition.identifier); | 200 definition.identifier); |
| 169 } | 201 } |
| 170 | 202 |
| 171 PluginGroup::~PluginGroup() { } | 203 PluginGroup::~PluginGroup() { } |
| 172 | 204 |
| 205 /*static*/ |
| 206 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { |
| 207 #if defined(OS_POSIX) |
| 208 return wpi.path.BaseName().value(); |
| 209 #elif defined(OS_WIN) |
| 210 return base::SysWideToUTF8(wpi.path.BaseName().value()); |
| 211 #endif |
| 212 } |
| 213 |
| 214 /*static*/ |
| 215 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { |
| 216 #if defined(OS_POSIX) |
| 217 return wpi.path.value(); |
| 218 #elif defined(OS_WIN) |
| 219 return base::SysWideToUTF8(wpi.path.value()); |
| 220 #endif |
| 221 } |
| 222 |
| 223 /*static*/ |
| 173 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { | 224 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { |
| 174 // Create a matcher from the name of this plugin. | 225 // Create a matcher from the name of this plugin. |
| 175 #if defined(OS_POSIX) | |
| 176 std::string identifier = wpi.path.BaseName().value(); | |
| 177 #elif defined(OS_WIN) | |
| 178 std::string identifier = base::SysWideToUTF8(wpi.path.BaseName().value()); | |
| 179 #endif | |
| 180 return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), | 226 return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), |
| 181 std::string(), std::string(), identifier); | 227 std::string(), std::string(), |
| 182 } | 228 GetIdentifier(wpi)); |
| 183 | |
| 184 PluginGroup* PluginGroup::CopyOrCreatePluginGroup( | |
| 185 const WebPluginInfo& info) { | |
| 186 static PluginMap* hardcoded_plugin_groups = NULL; | |
| 187 if (!hardcoded_plugin_groups) { | |
| 188 PluginMap* groups = new PluginMap(); | |
| 189 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); | |
| 190 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { | |
| 191 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( | |
| 192 definitions[i]); | |
| 193 std::string identifier = definition_group->identifier(); | |
| 194 DCHECK(groups->find(identifier) == groups->end()); | |
| 195 (*groups)[identifier] = linked_ptr<PluginGroup>(definition_group); | |
| 196 } | |
| 197 hardcoded_plugin_groups = groups; | |
| 198 } | |
| 199 | |
| 200 // See if this plugin matches any of the hardcoded groups. | |
| 201 PluginGroup* hardcoded_group = FindGroupMatchingPlugin( | |
| 202 *hardcoded_plugin_groups, info); | |
| 203 if (hardcoded_group) { | |
| 204 // Make a copy. | |
| 205 return hardcoded_group->Copy(); | |
| 206 } else { | |
| 207 // Not found in our hardcoded list, create a new one. | |
| 208 return PluginGroup::FromWebPluginInfo(info); | |
| 209 } | |
| 210 } | |
| 211 | |
| 212 PluginGroup* PluginGroup::FindGroupMatchingPlugin( | |
| 213 const PluginMap& plugin_groups, | |
| 214 const WebPluginInfo& plugin) { | |
| 215 for (std::map<std::string, linked_ptr<PluginGroup> >::const_iterator it = | |
| 216 plugin_groups.begin(); | |
| 217 it != plugin_groups.end(); | |
| 218 ++it) { | |
| 219 if (it->second->Match(plugin)) | |
| 220 return it->second.get(); | |
| 221 } | |
| 222 return NULL; | |
| 223 } | 229 } |
| 224 | 230 |
| 225 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 231 bool PluginGroup::Match(const WebPluginInfo& plugin) const { |
| 226 if (name_matcher_.empty()) { | 232 if (name_matcher_.empty()) { |
| 227 return false; | 233 return false; |
| 228 } | 234 } |
| 229 | 235 |
| 230 // Look for the name matcher anywhere in the plugin name. | 236 // Look for the name matcher anywhere in the plugin name. |
| 231 if (plugin.name.find(name_matcher_) == string16::npos) { | 237 if (plugin.name.find(name_matcher_) == string16::npos) { |
| 232 return false; | 238 return false; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 286 |
| 281 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 287 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
| 282 description_ = plugin.desc; | 288 description_ = plugin.desc; |
| 283 if (Version* new_version = CreateVersionFromString(plugin.version)) | 289 if (Version* new_version = CreateVersionFromString(plugin.version)) |
| 284 version_.reset(new_version); | 290 version_.reset(new_version); |
| 285 else | 291 else |
| 286 version_.reset(Version::GetVersionFromString("0")); | 292 version_.reset(Version::GetVersionFromString("0")); |
| 287 } | 293 } |
| 288 | 294 |
| 289 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 295 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { |
| 296 // Check if this group already contains this plugin. |
| 297 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 298 if (web_plugin_infos_[i].name == plugin.name && |
| 299 web_plugin_infos_[i].version == plugin.version && |
| 300 FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), |
| 301 plugin.path.value())) { |
| 302 return; |
| 303 } |
| 304 } |
| 290 web_plugin_infos_.push_back(plugin); | 305 web_plugin_infos_.push_back(plugin); |
| 291 // The position of this plugin relative to the global list of plugins. | 306 // The position of this plugin relative to the global list of plugins. |
| 292 web_plugin_positions_.push_back(position); | 307 web_plugin_positions_.push_back(position); |
| 293 UpdateActivePlugin(plugin); | 308 UpdateActivePlugin(plugin); |
| 294 } | 309 } |
| 295 | 310 |
| 296 string16 PluginGroup::GetGroupName() const { | 311 string16 PluginGroup::GetGroupName() const { |
| 297 if (!group_name_.empty()) | 312 if (!group_name_.empty()) |
| 298 return group_name_; | 313 return group_name_; |
| 299 DCHECK_EQ(1u, web_plugin_infos_.size()); | 314 DCHECK_EQ(1u, web_plugin_infos_.size()); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 415 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
| 401 if (version.get() && version->CompareTo(*min_version_) < 0) { | 416 if (version.get() && version->CompareTo(*min_version_) < 0) { |
| 402 it->enabled = false; | 417 it->enabled = false; |
| 403 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 418 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
| 404 } | 419 } |
| 405 UpdateActivePlugin(*it); | 420 UpdateActivePlugin(*it); |
| 406 } | 421 } |
| 407 } | 422 } |
| 408 | 423 |
| 409 void PluginGroup::Enable(bool enable) { | 424 void PluginGroup::Enable(bool enable) { |
| 410 for (std::vector<WebPluginInfo>::const_iterator it = | 425 bool enabled_plugin_exists = false; |
| 426 for (std::vector<WebPluginInfo>::iterator it = |
| 411 web_plugin_infos_.begin(); | 427 web_plugin_infos_.begin(); |
| 412 it != web_plugin_infos_.end(); ++it) { | 428 it != web_plugin_infos_.end(); ++it) { |
| 413 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 429 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { |
| 414 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 430 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
| 431 it->enabled = true; |
| 432 enabled_plugin_exists = true; |
| 415 } else { | 433 } else { |
| 434 it->enabled = false; |
| 416 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 435 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
| 417 } | 436 } |
| 418 } | 437 } |
| 438 enabled_ = enabled_plugin_exists; |
| 419 } | 439 } |
| OLD | NEW |