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_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 | |
62 PluginGroup::PluginGroup(const string16& group_name, | 30 PluginGroup::PluginGroup(const string16& group_name, |
63 const string16& name_matcher, | 31 const string16& name_matcher, |
64 const std::string& identifier) | 32 const std::string& identifier) |
65 : identifier_(identifier), | 33 : identifier_(identifier), |
66 group_name_(group_name), | 34 group_name_(group_name), |
67 name_matcher_(name_matcher) { | 35 name_matcher_(name_matcher) { |
68 } | 36 } |
69 | 37 |
70 void PluginGroup::InitFrom(const PluginGroup& other) { | 38 void PluginGroup::InitFrom(const PluginGroup& other) { |
71 identifier_ = other.identifier_; | 39 identifier_ = other.identifier_; |
72 group_name_ = other.group_name_; | 40 group_name_ = other.group_name_; |
73 name_matcher_ = other.name_matcher_; | 41 name_matcher_ = other.name_matcher_; |
74 version_ranges_ = other.version_ranges_; | |
75 web_plugin_infos_ = other.web_plugin_infos_; | 42 web_plugin_infos_ = other.web_plugin_infos_; |
76 } | 43 } |
77 | 44 |
78 PluginGroup::PluginGroup(const PluginGroup& other) { | 45 PluginGroup::PluginGroup(const PluginGroup& other) { |
79 InitFrom(other); | 46 InitFrom(other); |
80 } | 47 } |
81 | 48 |
82 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | 49 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
83 InitFrom(other); | 50 InitFrom(other); |
84 return *this; | 51 return *this; |
85 } | 52 } |
86 | 53 |
87 /*static*/ | 54 /*static*/ |
88 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 55 PluginGroup* PluginGroup::FromPluginGroupDefinition( |
89 const PluginGroupDefinition& definition) { | 56 const PluginGroupDefinition& definition) { |
90 PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name), | 57 return new PluginGroup(ASCIIToUTF16(definition.name), |
91 ASCIIToUTF16(definition.name_matcher), | 58 ASCIIToUTF16(definition.name_matcher), |
92 definition.identifier); | 59 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; | |
96 } | 60 } |
97 | 61 |
98 PluginGroup::~PluginGroup() { } | 62 PluginGroup::~PluginGroup() { } |
99 | 63 |
100 /*static*/ | 64 /*static*/ |
101 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { | 65 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { |
102 #if defined(OS_POSIX) | 66 #if defined(OS_POSIX) |
103 return wpi.path.BaseName().value(); | 67 return wpi.path.BaseName().value(); |
104 #elif defined(OS_WIN) | 68 #elif defined(OS_WIN) |
105 return base::SysWideToUTF8(wpi.path.BaseName().value()); | 69 return base::SysWideToUTF8(wpi.path.BaseName().value()); |
(...skipping 19 matching lines...) Expand all Loading... |
125 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 89 bool PluginGroup::Match(const WebPluginInfo& plugin) const { |
126 if (name_matcher_.empty()) { | 90 if (name_matcher_.empty()) { |
127 return false; | 91 return false; |
128 } | 92 } |
129 | 93 |
130 // Look for the name matcher anywhere in the plugin name. | 94 // Look for the name matcher anywhere in the plugin name. |
131 if (plugin.name.find(name_matcher_) == string16::npos) { | 95 if (plugin.name.find(name_matcher_) == string16::npos) { |
132 return false; | 96 return false; |
133 } | 97 } |
134 | 98 |
135 if (version_ranges_.empty()) { | 99 return true; |
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; | |
154 } | 100 } |
155 | 101 |
156 /* static */ | 102 /* static */ |
157 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { | 103 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { |
158 // Remove spaces and ')' from the version string, | 104 // Remove spaces and ')' from the version string, |
159 // Replace any instances of 'r', ',' or '(' with a dot. | 105 // Replace any instances of 'r', ',' or '(' with a dot. |
160 std::string version = UTF16ToASCII(version_string); | 106 std::string version = UTF16ToASCII(version_string); |
161 RemoveChars(version, ") ", &version); | 107 RemoveChars(version, ") ", &version); |
162 std::replace(version.begin(), version.end(), 'd', '.'); | 108 std::replace(version.begin(), version.end(), 'd', '.'); |
163 std::replace(version.begin(), version.end(), 'r', '.'); | 109 std::replace(version.begin(), version.end(), 'r', '.'); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 152 } |
207 | 153 |
208 bool PluginGroup::ContainsPlugin(const FilePath& path) const { | 154 bool PluginGroup::ContainsPlugin(const FilePath& path) const { |
209 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 155 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
210 if (web_plugin_infos_[i].path == path) | 156 if (web_plugin_infos_[i].path == path) |
211 return true; | 157 return true; |
212 } | 158 } |
213 return false; | 159 return false; |
214 } | 160 } |
215 | 161 |
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 | |
251 bool PluginGroup::IsEmpty() const { | 162 bool PluginGroup::IsEmpty() const { |
252 return web_plugin_infos_.empty(); | 163 return web_plugin_infos_.empty(); |
253 } | 164 } |
254 | 165 |
255 } // namespace npapi | 166 } // namespace npapi |
256 } // namespace webkit | 167 } // namespace webkit |
OLD | NEW |