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

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

Issue 10388253: Revert 138502 - Move version metadata from PluginGroup into PluginInstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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_util.h" 10 #include "base/string_util.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 #include "webkit/plugins/npapi/plugin_list.h" 15 #include "webkit/plugins/npapi/plugin_list.h"
16 #include "webkit/plugins/webplugininfo.h" 16 #include "webkit/plugins/webplugininfo.h"
17 17
18 namespace webkit { 18 namespace webkit {
19 namespace npapi { 19 namespace npapi {
20 20
21 // static 21 // static
22 const char PluginGroup::kAdobeReaderGroupName[] = "Adobe Acrobat"; 22 const char PluginGroup::kAdobeReaderGroupName[] = "Adobe Acrobat";
23 const char PluginGroup::kJavaGroupName[] = "Java"; 23 const char PluginGroup::kJavaGroupName[] = "Java";
24 const char PluginGroup::kQuickTimeGroupName[] = "QuickTime"; 24 const char PluginGroup::kQuickTimeGroupName[] = "QuickTime";
25 const char PluginGroup::kShockwaveGroupName[] = "Shockwave"; 25 const char PluginGroup::kShockwaveGroupName[] = "Shockwave";
26 const char PluginGroup::kRealPlayerGroupName[] = "RealPlayer"; 26 const char PluginGroup::kRealPlayerGroupName[] = "RealPlayer";
27 const char PluginGroup::kSilverlightGroupName[] = "Silverlight"; 27 const char PluginGroup::kSilverlightGroupName[] = "Silverlight";
28 const char PluginGroup::kWindowsMediaPlayerGroupName[] = "Windows Media Player"; 28 const char PluginGroup::kWindowsMediaPlayerGroupName[] = "Windows Media Player";
29 29
30 VersionRange::VersionRange(const VersionRangeDefinition& definition)
31 : low_str(definition.version_matcher_low),
32 high_str(definition.version_matcher_high),
33 min_str(definition.min_version) {
34 if (!low_str.empty())
35 low.reset(Version::GetVersionFromString(low_str));
36 if (!high_str.empty())
37 high.reset(Version::GetVersionFromString(high_str));
38 if (!min_str.empty())
39 min.reset(Version::GetVersionFromString(min_str));
40 }
41
42 VersionRange::VersionRange(const VersionRange& other) {
43 InitFrom(other);
44 }
45
46 VersionRange& VersionRange::operator=(const VersionRange& other) {
47 InitFrom(other);
48 return *this;
49 }
50
51 VersionRange::~VersionRange() {}
52
53 void VersionRange::InitFrom(const VersionRange& other) {
54 low_str = other.low_str;
55 high_str = other.high_str;
56 min_str = other.min_str;
57 low.reset(Version::GetVersionFromString(other.low_str));
58 high.reset(Version::GetVersionFromString(other.high_str));
59 min.reset(Version::GetVersionFromString(other.min_str));
60 }
61
30 PluginGroup::PluginGroup(const string16& group_name, 62 PluginGroup::PluginGroup(const string16& group_name,
31 const string16& name_matcher, 63 const string16& name_matcher,
32 const std::string& identifier) 64 const std::string& identifier)
33 : identifier_(identifier), 65 : identifier_(identifier),
34 group_name_(group_name), 66 group_name_(group_name),
35 name_matcher_(name_matcher) { 67 name_matcher_(name_matcher) {
36 } 68 }
37 69
38 void PluginGroup::InitFrom(const PluginGroup& other) { 70 void PluginGroup::InitFrom(const PluginGroup& other) {
39 identifier_ = other.identifier_; 71 identifier_ = other.identifier_;
40 group_name_ = other.group_name_; 72 group_name_ = other.group_name_;
41 name_matcher_ = other.name_matcher_; 73 name_matcher_ = other.name_matcher_;
74 version_ranges_ = other.version_ranges_;
42 web_plugin_infos_ = other.web_plugin_infos_; 75 web_plugin_infos_ = other.web_plugin_infos_;
43 } 76 }
44 77
45 PluginGroup::PluginGroup(const PluginGroup& other) { 78 PluginGroup::PluginGroup(const PluginGroup& other) {
46 InitFrom(other); 79 InitFrom(other);
47 } 80 }
48 81
49 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { 82 PluginGroup& PluginGroup::operator=(const PluginGroup& other) {
50 InitFrom(other); 83 InitFrom(other);
51 return *this; 84 return *this;
52 } 85 }
53 86
54 /*static*/ 87 /*static*/
55 PluginGroup* PluginGroup::FromPluginGroupDefinition( 88 PluginGroup* PluginGroup::FromPluginGroupDefinition(
56 const PluginGroupDefinition& definition) { 89 const PluginGroupDefinition& definition) {
57 return new PluginGroup(ASCIIToUTF16(definition.name), 90 PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name),
58 ASCIIToUTF16(definition.name_matcher), 91 ASCIIToUTF16(definition.name_matcher),
59 definition.identifier); 92 definition.identifier);
93 for (size_t i = 0; i < definition.num_versions; ++i)
94 group->version_ranges_.push_back(VersionRange(definition.versions[i]));
95 return group;
60 } 96 }
61 97
62 PluginGroup::~PluginGroup() { } 98 PluginGroup::~PluginGroup() { }
63 99
64 /*static*/ 100 /*static*/
65 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { 101 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) {
66 #if defined(OS_POSIX) 102 #if defined(OS_POSIX)
67 return wpi.path.BaseName().value(); 103 return wpi.path.BaseName().value();
68 #elif defined(OS_WIN) 104 #elif defined(OS_WIN)
69 return base::SysWideToUTF8(wpi.path.BaseName().value()); 105 return base::SysWideToUTF8(wpi.path.BaseName().value());
(...skipping 19 matching lines...) Expand all
89 bool PluginGroup::Match(const WebPluginInfo& plugin) const { 125 bool PluginGroup::Match(const WebPluginInfo& plugin) const {
90 if (name_matcher_.empty()) { 126 if (name_matcher_.empty()) {
91 return false; 127 return false;
92 } 128 }
93 129
94 // Look for the name matcher anywhere in the plugin name. 130 // Look for the name matcher anywhere in the plugin name.
95 if (plugin.name.find(name_matcher_) == string16::npos) { 131 if (plugin.name.find(name_matcher_) == string16::npos) {
96 return false; 132 return false;
97 } 133 }
98 134
99 return true; 135 if (version_ranges_.empty()) {
136 return true;
137 }
138
139 // There's at least one version range, the plugin's version must be in it.
140 scoped_ptr<Version> plugin_version(CreateVersionFromString(plugin.version));
141 if (plugin_version.get() == NULL) {
142 // No version could be extracted, assume we don't match the range.
143 return false;
144 }
145
146 // Match if the plugin is contained in any of the defined VersionRanges.
147 for (size_t i = 0; i < version_ranges_.size(); ++i) {
148 if (IsVersionInRange(*plugin_version, version_ranges_[i])) {
149 return true;
150 }
151 }
152 // None of the VersionRanges matched.
153 return false;
100 } 154 }
101 155
102 /* static */ 156 /* static */
103 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { 157 Version* PluginGroup::CreateVersionFromString(const string16& version_string) {
104 // Remove spaces and ')' from the version string, 158 // Remove spaces and ')' from the version string,
105 // Replace any instances of 'r', ',' or '(' with a dot. 159 // Replace any instances of 'r', ',' or '(' with a dot.
106 std::string version = UTF16ToASCII(version_string); 160 std::string version = UTF16ToASCII(version_string);
107 RemoveChars(version, ") ", &version); 161 RemoveChars(version, ") ", &version);
108 std::replace(version.begin(), version.end(), 'd', '.'); 162 std::replace(version.begin(), version.end(), 'd', '.');
109 std::replace(version.begin(), version.end(), 'r', '.'); 163 std::replace(version.begin(), version.end(), 'r', '.');
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 206 }
153 207
154 bool PluginGroup::ContainsPlugin(const FilePath& path) const { 208 bool PluginGroup::ContainsPlugin(const FilePath& path) const {
155 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { 209 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
156 if (web_plugin_infos_[i].path == path) 210 if (web_plugin_infos_[i].path == path)
157 return true; 211 return true;
158 } 212 }
159 return false; 213 return false;
160 } 214 }
161 215
216 /*static*/
217 bool PluginGroup::IsVersionInRange(const Version& version,
218 const VersionRange& range) {
219 DCHECK(range.low.get() != NULL || range.high.get() == NULL)
220 << "Lower bound of version range must be defined.";
221 return (range.low.get() == NULL && range.high.get() == NULL) ||
222 (range.low->CompareTo(version) <= 0 &&
223 (range.high.get() == NULL || range.high->CompareTo(version) > 0));
224 }
225
226 /*static*/
227 bool PluginGroup::IsPluginOutdated(const Version& plugin_version,
228 const VersionRange& version_range) {
229 if (IsVersionInRange(plugin_version, version_range)) {
230 if (version_range.min.get() &&
231 plugin_version.CompareTo(*version_range.min) < 0) {
232 return true;
233 }
234 }
235 return false;
236 }
237
238 // Returns true if the latest version of this plugin group is vulnerable.
239 bool PluginGroup::IsVulnerable(const WebPluginInfo& plugin) const {
240 scoped_ptr<Version> version(CreateVersionFromString(plugin.version));
241 if (!version.get())
242 return false;
243
244 for (size_t i = 0; i < version_ranges_.size(); ++i) {
245 if (IsPluginOutdated(*version, version_ranges_[i]))
246 return true;
247 }
248 return false;
249 }
250
162 bool PluginGroup::IsEmpty() const { 251 bool PluginGroup::IsEmpty() const {
163 return web_plugin_infos_.empty(); 252 return web_plugin_infos_.empty();
164 } 253 }
165 254
166 } // namespace npapi 255 } // namespace npapi
167 } // namespace webkit 256 } // 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