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

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

Issue 10823434: [6] Moves CreateVersionFromString to plugin_utils and updates the callers. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added missing include <algorithm> Created 8 years, 3 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
« 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_split.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 94
95 // Look for the name matcher anywhere in the plugin name. 95 // Look for the name matcher anywhere in the plugin name.
96 if (plugin.name.find(name_matcher_) == string16::npos) { 96 if (plugin.name.find(name_matcher_) == string16::npos) {
97 return false; 97 return false;
98 } 98 }
99 99
100 return true; 100 return true;
101 } 101 }
102 102
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 */
125 void PluginGroup::CreateVersionFromString(const string16& version_string,
126 Version* parsed_version) {
127 // Remove spaces and ')' from the version string,
128 // Replace any instances of 'r', ',' or '(' with a dot.
129 std::string version = UTF16ToASCII(version_string);
130 RemoveChars(version, ") ", &version);
131 std::replace(version.begin(), version.end(), 'd', '.');
132 std::replace(version.begin(), version.end(), 'r', '.');
133 std::replace(version.begin(), version.end(), ',', '.');
134 std::replace(version.begin(), version.end(), '(', '.');
135 std::replace(version.begin(), version.end(), '_', '.');
136
137 // Remove leading zeros from each of the version components.
138 version = RemoveLeadingZerosFromVersionComponents(version);
139
140 *parsed_version = Version(version);
141 }
142
143 void PluginGroup::AddPlugin(const WebPluginInfo& plugin) { 103 void PluginGroup::AddPlugin(const WebPluginInfo& plugin) {
144 // Check if this group already contains this plugin. 104 // Check if this group already contains this plugin.
145 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { 105 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
146 if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), 106 if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(),
147 plugin.path.value())) { 107 plugin.path.value())) {
148 return; 108 return;
149 } 109 }
150 } 110 }
151 web_plugin_infos_.push_back(plugin); 111 web_plugin_infos_.push_back(plugin);
152 } 112 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 144 }
185 return false; 145 return false;
186 } 146 }
187 147
188 bool PluginGroup::IsEmpty() const { 148 bool PluginGroup::IsEmpty() const {
189 return web_plugin_infos_.empty(); 149 return web_plugin_infos_.empty();
190 } 150 }
191 151
192 } // namespace npapi 152 } // namespace npapi
193 } // namespace webkit 153 } // 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