OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/plugin_group.h" | 5 #include "webkit/glue/plugins/plugin_group.h" |
6 | 6 |
7 #include "base/linked_ptr.h" | 7 #include "base/linked_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "base/version.h" | 12 #include "base/version.h" |
13 #include "webkit/glue/plugins/plugin_list.h" | 13 #include "webkit/glue/plugins/plugin_list.h" |
14 #include "webkit/glue/plugins/webplugininfo.h" | 14 #include "webkit/glue/plugins/webplugininfo.h" |
15 | 15 |
16 const char* PluginGroup::kAdobeReader8GroupName = "Adobe Reader 8"; | 16 const char* PluginGroup::kAdobeReaderGroupName = "Adobe Reader"; |
17 const char* PluginGroup::kAdobeReader9GroupName = "Adobe Reader 9"; | |
18 | 17 |
19 /*static*/ | 18 /*static*/ |
20 std::set<string16>* PluginGroup::policy_disabled_plugin_patterns_; | 19 std::set<string16>* PluginGroup::policy_disabled_plugin_patterns_; |
21 | 20 |
22 /*static*/ | 21 /*static*/ |
23 void PluginGroup::SetPolicyDisabledPluginPatterns( | 22 void PluginGroup::SetPolicyDisabledPluginPatterns( |
24 const std::set<string16>& set) { | 23 const std::set<string16>& set) { |
25 if (!policy_disabled_plugin_patterns_) | 24 if (!policy_disabled_plugin_patterns_) |
26 policy_disabled_plugin_patterns_ = new std::set<string16>(set); | 25 policy_disabled_plugin_patterns_ = new std::set<string16>(set); |
27 else | 26 else |
(...skipping 24 matching lines...) Expand all Loading... | |
52 it != plugins.end(); | 51 it != plugins.end(); |
53 ++it) { | 52 ++it) { |
54 if (FilePath::CompareEqualIgnoreCase(it->path.value(), | 53 if (FilePath::CompareEqualIgnoreCase(it->path.value(), |
55 plugin_path.value()) && IsPluginNameDisabledByPolicy(it->name)) { | 54 plugin_path.value()) && IsPluginNameDisabledByPolicy(it->name)) { |
56 return true; | 55 return true; |
57 } | 56 } |
58 } | 57 } |
59 return false; | 58 return false; |
60 } | 59 } |
61 | 60 |
61 VersionRange::VersionRange(VersionRangeDefinition definition) | |
62 : low_str(definition.version_matcher_low), | |
63 high_str(definition.version_matcher_high), | |
64 min_str(definition.min_version) { | |
65 if (!low_str.empty()) | |
66 low.reset(Version::GetVersionFromString(low_str)); | |
67 if (!high_str.empty()) | |
68 high.reset(Version::GetVersionFromString(high_str)); | |
69 if (!min_str.empty()) | |
70 min.reset(Version::GetVersionFromString(min_str)); | |
71 } | |
72 | |
73 VersionRange::VersionRange(const VersionRange& other) { | |
74 InitFrom(other); | |
75 } | |
76 | |
77 VersionRange& VersionRange::operator=(const VersionRange& other) { | |
78 InitFrom(other); | |
79 return *this; | |
80 } | |
81 | |
82 void VersionRange::InitFrom(const VersionRange& other) { | |
83 low_str = other.low_str; | |
84 high_str = other.high_str; | |
85 min_str = other.min_str; | |
86 low.reset(Version::GetVersionFromString(other.low_str)); | |
87 high.reset(Version::GetVersionFromString(other.high_str)); | |
88 min.reset(Version::GetVersionFromString(other.min_str)); | |
89 } | |
90 | |
62 PluginGroup::PluginGroup(const string16& group_name, | 91 PluginGroup::PluginGroup(const string16& group_name, |
63 const string16& name_matcher, | 92 const string16& name_matcher, |
64 const std::string& version_range_low, | |
65 const std::string& version_range_high, | |
66 const std::string& min_version, | |
67 const std::string& update_url, | 93 const std::string& update_url, |
68 const std::string& identifier) | 94 const std::string& identifier) |
69 : identifier_(identifier), | 95 : identifier_(identifier), |
70 group_name_(group_name), | 96 group_name_(group_name), |
71 name_matcher_(name_matcher), | 97 name_matcher_(name_matcher), |
72 version_range_low_str_(version_range_low), | |
73 version_range_high_str_(version_range_high), | |
74 update_url_(update_url), | 98 update_url_(update_url), |
75 enabled_(false), | 99 enabled_(false), |
76 min_version_str_(min_version), | |
77 version_(Version::GetVersionFromString("0")) { | 100 version_(Version::GetVersionFromString("0")) { |
78 if (!version_range_low.empty()) | |
79 version_range_low_.reset(Version::GetVersionFromString(version_range_low)); | |
80 if (!version_range_high.empty()) { | |
81 version_range_high_.reset( | |
82 Version::GetVersionFromString(version_range_high)); | |
83 } | |
84 if (!min_version.empty()) | |
85 min_version_.reset(Version::GetVersionFromString(min_version)); | |
86 } | 101 } |
87 | 102 |
88 void PluginGroup::InitFrom(const PluginGroup& other) { | 103 void PluginGroup::InitFrom(const PluginGroup& other) { |
89 identifier_ = other.identifier_; | 104 identifier_ = other.identifier_; |
90 group_name_ = other.group_name_; | 105 group_name_ = other.group_name_; |
91 name_matcher_ = other.name_matcher_; | 106 name_matcher_ = other.name_matcher_; |
92 version_range_low_str_ = other.version_range_low_str_; | |
93 version_range_high_str_ = other.version_range_high_str_; | |
94 version_range_low_.reset( | |
95 Version::GetVersionFromString(version_range_low_str_)); | |
96 version_range_high_.reset( | |
97 Version::GetVersionFromString(version_range_high_str_)); | |
98 description_ = other.description_; | 107 description_ = other.description_; |
99 update_url_ = other.update_url_; | 108 update_url_ = other.update_url_; |
100 enabled_ = other.enabled_; | 109 enabled_ = other.enabled_; |
101 min_version_str_ = other.min_version_str_; | 110 for (size_t i = 0; i < other.version_ranges_.size(); ++i) |
102 min_version_.reset(Version::GetVersionFromString(min_version_str_)); | 111 version_ranges_.push_back(other.version_ranges_[i]); |
103 DCHECK_EQ(other.web_plugin_infos_.size(), other.web_plugin_positions_.size()); | 112 DCHECK_EQ(other.web_plugin_infos_.size(), other.web_plugin_positions_.size()); |
104 for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) | 113 for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) |
105 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); | 114 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); |
106 if (!version_.get()) | 115 if (!version_.get()) |
107 version_.reset(Version::GetVersionFromString("0")); | 116 version_.reset(Version::GetVersionFromString("0")); |
108 } | 117 } |
109 | 118 |
110 PluginGroup::PluginGroup(const PluginGroup& other) { | 119 PluginGroup::PluginGroup(const PluginGroup& other) { |
111 InitFrom(other); | 120 InitFrom(other); |
112 } | 121 } |
113 | 122 |
114 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | 123 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
124 version_ranges_.clear(); | |
115 InitFrom(other); | 125 InitFrom(other); |
116 return *this; | 126 return *this; |
117 } | 127 } |
118 | 128 |
119 /*static*/ | 129 /*static*/ |
120 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 130 PluginGroup* PluginGroup::FromPluginGroupDefinition( |
121 const PluginGroupDefinition& definition) { | 131 const PluginGroupDefinition& definition) { |
122 return new PluginGroup(ASCIIToUTF16(definition.name), | 132 PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name), |
123 ASCIIToUTF16(definition.name_matcher), | 133 ASCIIToUTF16(definition.name_matcher), |
124 definition.version_matcher_low, | 134 definition.update_url, |
125 definition.version_matcher_high, | 135 definition.identifier); |
126 definition.min_version, | 136 for (size_t i = 0; i < definition.num_versions; ++i) |
127 definition.update_url, | 137 group->version_ranges_.push_back(VersionRange(definition.versions[i])); |
128 definition.identifier); | 138 return group; |
129 } | 139 } |
130 | 140 |
131 PluginGroup::~PluginGroup() { } | 141 PluginGroup::~PluginGroup() { } |
132 | 142 |
133 /*static*/ | 143 /*static*/ |
134 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { | 144 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { |
135 #if defined(OS_POSIX) | 145 #if defined(OS_POSIX) |
136 return wpi.path.BaseName().value(); | 146 return wpi.path.BaseName().value(); |
137 #elif defined(OS_WIN) | 147 #elif defined(OS_WIN) |
138 return base::SysWideToUTF8(wpi.path.BaseName().value()); | 148 return base::SysWideToUTF8(wpi.path.BaseName().value()); |
139 #endif | 149 #endif |
140 } | 150 } |
141 | 151 |
142 /*static*/ | 152 /*static*/ |
143 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { | 153 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { |
144 #if defined(OS_POSIX) | 154 #if defined(OS_POSIX) |
145 return wpi.path.value(); | 155 return wpi.path.value(); |
146 #elif defined(OS_WIN) | 156 #elif defined(OS_WIN) |
147 return base::SysWideToUTF8(wpi.path.value()); | 157 return base::SysWideToUTF8(wpi.path.value()); |
148 #endif | 158 #endif |
149 } | 159 } |
150 | 160 |
151 /*static*/ | 161 /*static*/ |
152 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { | 162 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { |
153 // Create a matcher from the name of this plugin. | 163 // Create a matcher from the name of this plugin. |
154 return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), | 164 return new PluginGroup(wpi.name, wpi.name, std::string(), |
155 std::string(), std::string(), | |
156 GetIdentifier(wpi)); | 165 GetIdentifier(wpi)); |
157 } | 166 } |
158 | 167 |
159 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 168 bool PluginGroup::Match(const WebPluginInfo& plugin) const { |
160 if (name_matcher_.empty()) { | 169 if (name_matcher_.empty()) { |
161 return false; | 170 return false; |
162 } | 171 } |
163 | 172 |
164 // Look for the name matcher anywhere in the plugin name. | 173 // Look for the name matcher anywhere in the plugin name. |
165 if (plugin.name.find(name_matcher_) == string16::npos) { | 174 if (plugin.name.find(name_matcher_) == string16::npos) { |
166 return false; | 175 return false; |
167 } | 176 } |
168 | 177 |
169 if (version_range_low_.get() == NULL || | 178 if (version_ranges_.empty()) { |
170 version_range_high_.get() == NULL) { | |
171 return true; | 179 return true; |
172 } | 180 } |
173 | 181 |
174 // There's a version range, we must be in it. | 182 // There's at least one version range, we must be in it. |
175 scoped_ptr<Version> plugin_version( | 183 scoped_ptr<Version> plugin_version( |
176 Version::GetVersionFromString(UTF16ToWide(plugin.version))); | 184 Version::GetVersionFromString(UTF16ToWide(plugin.version))); |
177 if (plugin_version.get() == NULL) { | 185 if (plugin_version.get() == NULL) { |
178 // No version could be extracted, assume we don't match the range. | 186 // No version could be extracted, assume we don't match the range. |
179 return false; | 187 return false; |
180 } | 188 } |
181 | 189 |
182 // We match if we are in the range: [low, high) | 190 // We match if we are in the range: [low, high) for any of the defined |
183 return (version_range_low_->CompareTo(*plugin_version) <= 0 && | 191 // VersionRanges. |
184 version_range_high_->CompareTo(*plugin_version) > 0); | 192 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
193 const VersionRange* range = &version_ranges_[i]; | |
Bernhard Bauer
2010/12/08 13:36:30
I think you could just use a const VersionRange& h
Jakob Kummerow
2010/12/09 08:58:17
Done.
| |
194 // If the VersionRange defines neither a high nor a low version, it matches | |
195 // everything. | |
196 if (range->low.get() == NULL && | |
197 range->high.get() == NULL) { | |
198 return true; | |
199 } | |
Bernhard Bauer
2010/12/08 13:36:30
I think we could even get rid of this rule. If som
Jakob Kummerow
2010/12/09 08:58:17
No, we can't, because they might want to define a
| |
200 DCHECK(range->low.get() != NULL) << "Lower bound of version range must be " | |
201 << "defined."; | |
202 // An undefined upper bound is treated as infinity. | |
203 if (range->high.get() == NULL) { | |
204 if (range->low->CompareTo(*plugin_version) <= 0) { | |
205 return true; | |
206 } | |
207 continue; | |
208 } | |
209 | |
210 if (range->low->CompareTo(*plugin_version) <= 0 && | |
211 range->high->CompareTo(*plugin_version) > 0) { | |
212 return true; | |
213 } | |
Bernhard Bauer
2010/12/08 13:36:30
You could move these checks together:
if (range-
Jakob Kummerow
2010/12/09 08:58:17
Done.
| |
214 } | |
215 // None of the VersionRanges matched. | |
216 return false; | |
185 } | 217 } |
186 | 218 |
187 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { | 219 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { |
188 // Remove spaces and ')' from the version string, | 220 // Remove spaces and ')' from the version string, |
189 // Replace any instances of 'r', ',' or '(' with a dot. | 221 // Replace any instances of 'r', ',' or '(' with a dot. |
190 std::wstring version = UTF16ToWide(version_string); | 222 std::wstring version = UTF16ToWide(version_string); |
191 RemoveChars(version, L") ", &version); | 223 RemoveChars(version, L") ", &version); |
192 std::replace(version.begin(), version.end(), 'r', '.'); | 224 std::replace(version.begin(), version.end(), 'r', '.'); |
193 std::replace(version.begin(), version.end(), ',', '.'); | 225 std::replace(version.begin(), version.end(), ',', '.'); |
194 std::replace(version.begin(), version.end(), '(', '.'); | 226 std::replace(version.begin(), version.end(), '(', '.'); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { | 347 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { |
316 result->SetString("enabledMode", "disabledByPolicy"); | 348 result->SetString("enabledMode", "disabledByPolicy"); |
317 } else { | 349 } else { |
318 result->SetString("enabledMode", enabled_ ? "enabled" : "disabledByUser"); | 350 result->SetString("enabledMode", enabled_ ? "enabled" : "disabledByUser"); |
319 } | 351 } |
320 result->Set("plugin_files", plugin_files); | 352 result->Set("plugin_files", plugin_files); |
321 | 353 |
322 return result; | 354 return result; |
323 } | 355 } |
324 | 356 |
357 /*static*/ | |
358 bool PluginGroup::IsPluginOutdated(const Version& plugin_version, | |
359 const VersionRange& version_range) { | |
360 if ((version_range.low.get() == NULL && | |
361 version_range.high.get() == NULL) || | |
362 (version_range.low->CompareTo(plugin_version) <= 0 && | |
363 version_range.high.get() == NULL) || | |
364 (version_range.low->CompareTo(plugin_version) <= 0 && | |
365 version_range.high->CompareTo(plugin_version) > 0)) { | |
Bernhard Bauer
2010/12/08 13:36:30
Could you reuse part of the logic in Match here?
Jakob Kummerow
2010/12/09 08:58:17
Done (by refactoring shared code out into a separa
| |
366 // This range is responsible for this plugin. | |
367 if (version_range.min.get() && | |
368 plugin_version.CompareTo(*version_range.min) < 0) { | |
369 return true; | |
370 } | |
371 } | |
372 return false; | |
373 } | |
374 | |
325 // Returns true if the latest version of this plugin group is vulnerable. | 375 // Returns true if the latest version of this plugin group is vulnerable. |
326 bool PluginGroup::IsVulnerable() const { | 376 bool PluginGroup::IsVulnerable() const { |
327 if (min_version_.get() == NULL || version_->GetString() == "0") { | 377 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
328 return false; | 378 if (IsPluginOutdated(*version_, version_ranges_[i])) |
379 return true; | |
329 } | 380 } |
330 return version_->CompareTo(*min_version_) < 0; | 381 return false; |
331 } | 382 } |
332 | 383 |
333 void PluginGroup::DisableOutdatedPlugins() { | 384 void PluginGroup::DisableOutdatedPlugins() { |
334 if (!min_version_.get()) | |
335 return; | |
336 | |
337 description_ = string16(); | 385 description_ = string16(); |
338 enabled_ = false; | 386 enabled_ = false; |
339 | 387 |
340 for (std::vector<WebPluginInfo>::iterator it = | 388 for (std::vector<WebPluginInfo>::iterator it = |
341 web_plugin_infos_.begin(); | 389 web_plugin_infos_.begin(); |
342 it != web_plugin_infos_.end(); ++it) { | 390 it != web_plugin_infos_.end(); ++it) { |
343 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 391 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
344 if (version.get() && version->CompareTo(*min_version_) < 0) { | 392 if (version.get()) { |
345 it->enabled = false; | 393 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
346 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 394 if (IsPluginOutdated(*version, version_ranges_[i])) { |
395 it->enabled = false; | |
396 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | |
397 } | |
398 } | |
347 } | 399 } |
348 UpdateActivePlugin(*it); | 400 UpdateActivePlugin(*it); |
349 } | 401 } |
350 } | 402 } |
351 | 403 |
352 void PluginGroup::Enable(bool enable) { | 404 void PluginGroup::Enable(bool enable) { |
353 bool enabled_plugin_exists = false; | 405 bool enabled_plugin_exists = false; |
354 for (std::vector<WebPluginInfo>::iterator it = | 406 for (std::vector<WebPluginInfo>::iterator it = |
355 web_plugin_infos_.begin(); | 407 web_plugin_infos_.begin(); |
356 it != web_plugin_infos_.end(); ++it) { | 408 it != web_plugin_infos_.end(); ++it) { |
357 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 409 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { |
358 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 410 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
359 it->enabled = true; | 411 it->enabled = true; |
360 enabled_plugin_exists = true; | 412 enabled_plugin_exists = true; |
361 } else { | 413 } else { |
362 it->enabled = false; | 414 it->enabled = false; |
363 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 415 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
364 } | 416 } |
365 } | 417 } |
366 enabled_ = enabled_plugin_exists; | 418 enabled_ = enabled_plugin_exists; |
367 } | 419 } |
OLD | NEW |