| 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_group.h" | 5 #include "webkit/plugins/npapi/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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // Look for the name matcher anywhere in the plugin name. | 174 // Look for the name matcher anywhere in the plugin name. |
| 175 if (plugin.name.find(name_matcher_) == string16::npos) { | 175 if (plugin.name.find(name_matcher_) == string16::npos) { |
| 176 return false; | 176 return false; |
| 177 } | 177 } |
| 178 | 178 |
| 179 if (version_ranges_.empty()) { | 179 if (version_ranges_.empty()) { |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // There's at least one version range, the plugin's version must be in it. | 183 // There's at least one version range, the plugin's version must be in it. |
| 184 scoped_ptr<Version> plugin_version( | 184 scoped_ptr<Version> plugin_version(CreateVersionFromString(plugin.version)); |
| 185 Version::GetVersionFromString(UTF16ToASCII(plugin.version))); | |
| 186 if (plugin_version.get() == NULL) { | 185 if (plugin_version.get() == NULL) { |
| 187 // No version could be extracted, assume we don't match the range. | 186 // No version could be extracted, assume we don't match the range. |
| 188 return false; | 187 return false; |
| 189 } | 188 } |
| 190 | 189 |
| 191 // Match if the plugin is contained in any of the defined VersionRanges. | 190 // Match if the plugin is contained in any of the defined VersionRanges. |
| 192 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 191 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
| 193 if (IsVersionInRange(*plugin_version, version_ranges_[i])) { | 192 if (IsVersionInRange(*plugin_version, version_ranges_[i])) { |
| 194 return true; | 193 return true; |
| 195 } | 194 } |
| 196 } | 195 } |
| 197 // None of the VersionRanges matched. | 196 // None of the VersionRanges matched. |
| 198 return false; | 197 return false; |
| 199 } | 198 } |
| 200 | 199 |
| 201 /* static */ | 200 /* static */ |
| 202 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { | 201 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { |
| 203 // Remove spaces and ')' from the version string, | 202 // Remove spaces and ')' from the version string, |
| 204 // Replace any instances of 'r', ',' or '(' with a dot. | 203 // Replace any instances of 'r', ',' or '(' with a dot. |
| 205 std::wstring version = UTF16ToWide(version_string); | 204 std::wstring version = UTF16ToWide(version_string); |
| 206 RemoveChars(version, L") ", &version); | 205 RemoveChars(version, L") ", &version); |
| 207 std::replace(version.begin(), version.end(), 'r', '.'); | 206 std::replace(version.begin(), version.end(), 'r', '.'); |
| 208 std::replace(version.begin(), version.end(), ',', '.'); | 207 std::replace(version.begin(), version.end(), ',', '.'); |
| 209 std::replace(version.begin(), version.end(), '(', '.'); | 208 std::replace(version.begin(), version.end(), '(', '.'); |
| 209 std::replace(version.begin(), version.end(), '_', '.'); |
| 210 | 210 |
| 211 return Version::GetVersionFromString(WideToASCII(version)); | 211 return Version::GetVersionFromString(WideToASCII(version)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) { | 214 void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) { |
| 215 // A group is enabled if any of the files are enabled. | 215 // A group is enabled if any of the files are enabled. |
| 216 if (plugin.enabled) { | 216 if (plugin.enabled) { |
| 217 if (!enabled_) { | 217 if (!enabled_) { |
| 218 // If this is the first enabled plugin, use its description. | 218 // If this is the first enabled plugin, use its description. |
| 219 enabled_ = true; | 219 enabled_ = true; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } else { | 404 } else { |
| 405 it->enabled = false; | 405 it->enabled = false; |
| 406 PluginList::Singleton()->DisablePlugin(it->path); | 406 PluginList::Singleton()->DisablePlugin(it->path); |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 enabled_ = enabled_plugin_exists; | 409 enabled_ = enabled_plugin_exists; |
| 410 } | 410 } |
| 411 | 411 |
| 412 } // namespace npapi | 412 } // namespace npapi |
| 413 } // namespace webkit | 413 } // namespace webkit |
| OLD | NEW |