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, the plugin's version 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 // Match if the plugin is contained in any of the defined VersionRanges. |
183 return (version_range_low_->CompareTo(*plugin_version) <= 0 && | 191 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
184 version_range_high_->CompareTo(*plugin_version) > 0); | 192 if (IsVersionInRange(*plugin_version, version_ranges_[i])) { |
| 193 return true; |
| 194 } |
| 195 } |
| 196 // None of the VersionRanges matched. |
| 197 return false; |
185 } | 198 } |
186 | 199 |
187 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { | 200 Version* PluginGroup::CreateVersionFromString(const string16& version_string) { |
188 // Remove spaces and ')' from the version string, | 201 // Remove spaces and ')' from the version string, |
189 // Replace any instances of 'r', ',' or '(' with a dot. | 202 // Replace any instances of 'r', ',' or '(' with a dot. |
190 std::wstring version = UTF16ToWide(version_string); | 203 std::wstring version = UTF16ToWide(version_string); |
191 RemoveChars(version, L") ", &version); | 204 RemoveChars(version, L") ", &version); |
192 std::replace(version.begin(), version.end(), 'r', '.'); | 205 std::replace(version.begin(), version.end(), 'r', '.'); |
193 std::replace(version.begin(), version.end(), ',', '.'); | 206 std::replace(version.begin(), version.end(), ',', '.'); |
194 std::replace(version.begin(), version.end(), '(', '.'); | 207 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) { | 328 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { |
316 result->SetString("enabledMode", "disabledByPolicy"); | 329 result->SetString("enabledMode", "disabledByPolicy"); |
317 } else { | 330 } else { |
318 result->SetString("enabledMode", enabled_ ? "enabled" : "disabledByUser"); | 331 result->SetString("enabledMode", enabled_ ? "enabled" : "disabledByUser"); |
319 } | 332 } |
320 result->Set("plugin_files", plugin_files); | 333 result->Set("plugin_files", plugin_files); |
321 | 334 |
322 return result; | 335 return result; |
323 } | 336 } |
324 | 337 |
| 338 /*static*/ |
| 339 bool PluginGroup::IsVersionInRange(const Version& version, |
| 340 const VersionRange& range) { |
| 341 DCHECK(range.low.get() != NULL || range.high.get() == NULL) |
| 342 << "Lower bound of version range must be defined."; |
| 343 return (range.low.get() == NULL && range.high.get() == NULL) || |
| 344 (range.low->CompareTo(version) <= 0 && |
| 345 (range.high.get() == NULL || range.high->CompareTo(version) > 0)); |
| 346 } |
| 347 |
| 348 /*static*/ |
| 349 bool PluginGroup::IsPluginOutdated(const Version& plugin_version, |
| 350 const VersionRange& version_range) { |
| 351 if (IsVersionInRange(plugin_version, version_range)) { |
| 352 if (version_range.min.get() && |
| 353 plugin_version.CompareTo(*version_range.min) < 0) { |
| 354 return true; |
| 355 } |
| 356 } |
| 357 return false; |
| 358 } |
| 359 |
325 // Returns true if the latest version of this plugin group is vulnerable. | 360 // Returns true if the latest version of this plugin group is vulnerable. |
326 bool PluginGroup::IsVulnerable() const { | 361 bool PluginGroup::IsVulnerable() const { |
327 if (min_version_.get() == NULL || version_->GetString() == "0") { | 362 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
328 return false; | 363 if (IsPluginOutdated(*version_, version_ranges_[i])) |
| 364 return true; |
329 } | 365 } |
330 return version_->CompareTo(*min_version_) < 0; | 366 return false; |
331 } | 367 } |
332 | 368 |
333 void PluginGroup::DisableOutdatedPlugins() { | 369 void PluginGroup::DisableOutdatedPlugins() { |
334 if (!min_version_.get()) | |
335 return; | |
336 | |
337 description_ = string16(); | 370 description_ = string16(); |
338 enabled_ = false; | 371 enabled_ = false; |
339 | 372 |
340 for (std::vector<WebPluginInfo>::iterator it = | 373 for (std::vector<WebPluginInfo>::iterator it = |
341 web_plugin_infos_.begin(); | 374 web_plugin_infos_.begin(); |
342 it != web_plugin_infos_.end(); ++it) { | 375 it != web_plugin_infos_.end(); ++it) { |
343 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 376 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
344 if (version.get() && version->CompareTo(*min_version_) < 0) { | 377 if (version.get()) { |
345 it->enabled = false; | 378 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
346 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 379 if (IsPluginOutdated(*version, version_ranges_[i])) { |
| 380 it->enabled = false; |
| 381 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
| 382 } |
| 383 } |
347 } | 384 } |
348 UpdateActivePlugin(*it); | 385 UpdateActivePlugin(*it); |
349 } | 386 } |
350 } | 387 } |
351 | 388 |
352 void PluginGroup::Enable(bool enable) { | 389 void PluginGroup::Enable(bool enable) { |
353 bool enabled_plugin_exists = false; | 390 bool enabled_plugin_exists = false; |
354 for (std::vector<WebPluginInfo>::iterator it = | 391 for (std::vector<WebPluginInfo>::iterator it = |
355 web_plugin_infos_.begin(); | 392 web_plugin_infos_.begin(); |
356 it != web_plugin_infos_.end(); ++it) { | 393 it != web_plugin_infos_.end(); ++it) { |
357 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 394 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { |
358 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 395 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
359 it->enabled = true; | 396 it->enabled = true; |
360 enabled_plugin_exists = true; | 397 enabled_plugin_exists = true; |
361 } else { | 398 } else { |
362 it->enabled = false; | 399 it->enabled = false; |
363 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 400 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
364 } | 401 } |
365 } | 402 } |
366 enabled_ = enabled_plugin_exists; | 403 enabled_ = enabled_plugin_exists; |
367 } | 404 } |
OLD | NEW |