Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: webkit/plugins/npapi/plugin_group.cc

Issue 10828279: Preprocessing version number for plugins to ignore leading zeros during comparisons. This eliminate… (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/npapi/plugin_group.h ('k') | webkit/plugins/npapi/plugin_group_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
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";
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
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
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_group.h ('k') | webkit/plugins/npapi/plugin_group_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698