Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "webkit/plugins/npapi/plugin_group.h" | 7 #include "webkit/plugins/npapi/plugin_group.h" |
| 8 | 8 |
| 9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
| 10 #include "base/string_split.h" | |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "base/version.h" | 15 #include "base/version.h" |
| 15 #include "webkit/plugins/npapi/plugin_list.h" | 16 #include "webkit/plugins/npapi/plugin_list.h" |
| 16 #include "webkit/plugins/webplugininfo.h" | 17 #include "webkit/plugins/webplugininfo.h" |
| 17 | 18 |
| 18 namespace webkit { | 19 namespace webkit { |
| 19 namespace npapi { | 20 namespace npapi { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 | 94 |
| 94 // Look for the name matcher anywhere in the plugin name. | 95 // Look for the name matcher anywhere in the plugin name. |
| 95 if (plugin.name.find(name_matcher_) == string16::npos) { | 96 if (plugin.name.find(name_matcher_) == string16::npos) { |
| 96 return false; | 97 return false; |
| 97 } | 98 } |
| 98 | 99 |
| 99 return true; | 100 return true; |
| 100 } | 101 } |
| 101 | 102 |
| 102 /* static */ | 103 /* static */ |
| 104 std::string PluginGroup::RemoveLeadingZerosFromVersionComponents( | |
| 105 const std::string& version) { | |
| 106 std::string no_leading_zeros_version = ""; | |
|
Bernhard Bauer
2012/08/13 11:25:43
Nit: The default constructor for std::string alrea
ibraaaa
2012/08/13 12:26:45
Done.
| |
| 107 std::vector<std::string> numbers; | |
| 108 base::SplitString(version, '.', &numbers); | |
| 109 for (size_t i = 0; i < numbers.size(); ++i) { | |
| 110 size_t n = numbers[i].size(); | |
| 111 size_t j = 0; | |
| 112 while (j < n && numbers[i][j] == '0') { | |
| 113 ++j; | |
| 114 } | |
| 115 no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0"; | |
|
Bernhard Bauer
2012/08/13 11:25:43
I think this slightly changes the behavior for emp
ibraaaa
2012/08/13 12:26:45
Done.
| |
| 116 if (i != numbers.size() - 1) { | |
| 117 no_leading_zeros_version += "."; | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 return no_leading_zeros_version; | |
| 122 } | |
| 123 | |
| 124 /* static */ | |
| 103 void PluginGroup::CreateVersionFromString(const string16& version_string, | 125 void PluginGroup::CreateVersionFromString(const string16& version_string, |
| 104 Version* parsed_version) { | 126 Version* parsed_version) { |
| 105 // Remove spaces and ')' from the version string, | 127 // Remove spaces and ')' from the version string, |
| 106 // Replace any instances of 'r', ',' or '(' with a dot. | 128 // Replace any instances of 'r', ',' or '(' with a dot. |
| 107 std::string version = UTF16ToASCII(version_string); | 129 std::string version = UTF16ToASCII(version_string); |
| 108 RemoveChars(version, ") ", &version); | 130 RemoveChars(version, ") ", &version); |
| 109 std::replace(version.begin(), version.end(), 'd', '.'); | 131 std::replace(version.begin(), version.end(), 'd', '.'); |
| 110 std::replace(version.begin(), version.end(), 'r', '.'); | 132 std::replace(version.begin(), version.end(), 'r', '.'); |
| 111 std::replace(version.begin(), version.end(), ',', '.'); | 133 std::replace(version.begin(), version.end(), ',', '.'); |
| 112 std::replace(version.begin(), version.end(), '(', '.'); | 134 std::replace(version.begin(), version.end(), '(', '.'); |
| 113 std::replace(version.begin(), version.end(), '_', '.'); | 135 std::replace(version.begin(), version.end(), '_', '.'); |
| 114 | 136 |
| 137 // Remove leading zeros from each of the version components. | |
| 138 version = RemoveLeadingZerosFromVersionComponents(version); | |
| 139 | |
| 115 *parsed_version = Version(version); | 140 *parsed_version = Version(version); |
| 116 } | 141 } |
| 117 | 142 |
| 118 void PluginGroup::AddPlugin(const WebPluginInfo& plugin) { | 143 void PluginGroup::AddPlugin(const WebPluginInfo& plugin) { |
| 119 // Check if this group already contains this plugin. | 144 // Check if this group already contains this plugin. |
| 120 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 145 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 121 if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), | 146 if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), |
| 122 plugin.path.value())) { | 147 plugin.path.value())) { |
| 123 return; | 148 return; |
| 124 } | 149 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 } | 184 } |
| 160 return false; | 185 return false; |
| 161 } | 186 } |
| 162 | 187 |
| 163 bool PluginGroup::IsEmpty() const { | 188 bool PluginGroup::IsEmpty() const { |
| 164 return web_plugin_infos_.empty(); | 189 return web_plugin_infos_.empty(); |
| 165 } | 190 } |
| 166 | 191 |
| 167 } // namespace npapi | 192 } // namespace npapi |
| 168 } // namespace webkit | 193 } // namespace webkit |
| OLD | NEW |