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" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void PluginGroup::InitFrom(const PluginGroup& other) { | 105 void PluginGroup::InitFrom(const PluginGroup& other) { |
106 identifier_ = other.identifier_; | 106 identifier_ = other.identifier_; |
107 group_name_ = other.group_name_; | 107 group_name_ = other.group_name_; |
108 name_matcher_ = other.name_matcher_; | 108 name_matcher_ = other.name_matcher_; |
109 description_ = other.description_; | 109 description_ = other.description_; |
110 update_url_ = other.update_url_; | 110 update_url_ = other.update_url_; |
111 enabled_ = other.enabled_; | 111 enabled_ = other.enabled_; |
112 for (size_t i = 0; i < other.version_ranges_.size(); ++i) | 112 for (size_t i = 0; i < other.version_ranges_.size(); ++i) |
113 version_ranges_.push_back(other.version_ranges_[i]); | 113 version_ranges_.push_back(other.version_ranges_[i]); |
114 DCHECK_EQ(other.web_plugin_infos_.size(), other.web_plugin_positions_.size()); | 114 DCHECK_EQ(other.web_plugin_infos_.size(), other.web_plugin_positions_.size()); |
115 for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) | 115 std::list<WebPluginInfo>::const_iterator it = other.web_plugin_infos_.begin(); |
116 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); | 116 std::vector<int>::const_iterator itprio = other.web_plugin_positions_.begin(); |
| 117 for (; it != other.web_plugin_infos_.end(); ++it, ++itprio) |
| 118 AddPlugin(*it, *itprio); |
117 if (!version_.get()) | 119 if (!version_.get()) |
118 version_.reset(Version::GetVersionFromString("0")); | 120 version_.reset(Version::GetVersionFromString("0")); |
119 } | 121 } |
120 | 122 |
121 PluginGroup::PluginGroup(const PluginGroup& other) { | 123 PluginGroup::PluginGroup(const PluginGroup& other) { |
122 InitFrom(other); | 124 InitFrom(other); |
123 } | 125 } |
124 | 126 |
125 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | 127 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
126 version_ranges_.clear(); | 128 version_ranges_.clear(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } | 230 } |
229 | 231 |
230 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 232 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
231 description_ = plugin.desc; | 233 description_ = plugin.desc; |
232 if (Version* new_version = CreateVersionFromString(plugin.version)) | 234 if (Version* new_version = CreateVersionFromString(plugin.version)) |
233 version_.reset(new_version); | 235 version_.reset(new_version); |
234 else | 236 else |
235 version_.reset(Version::GetVersionFromString("0")); | 237 version_.reset(Version::GetVersionFromString("0")); |
236 } | 238 } |
237 | 239 |
238 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 240 WebPluginInfo* PluginGroup::AddPlugin( |
| 241 const WebPluginInfo& plugin, int position) { |
239 // Check if this group already contains this plugin. | 242 // Check if this group already contains this plugin. |
240 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 243 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
241 if (web_plugin_infos_[i].name == plugin.name && | 244 it != web_plugin_infos_.end(); ++it) { |
242 web_plugin_infos_[i].version == plugin.version && | 245 if (it->name == plugin.name && |
243 FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), | 246 it->version == plugin.version && |
| 247 FilePath::CompareEqualIgnoreCase(it->path.value(), |
244 plugin.path.value())) { | 248 plugin.path.value())) { |
245 return; | 249 return NULL; |
246 } | 250 } |
247 } | 251 } |
248 web_plugin_infos_.push_back(plugin); | 252 web_plugin_infos_.push_back(plugin); |
249 // The position of this plugin relative to the global list of plugins. | 253 // The position of this plugin relative to the global list of plugins. |
250 web_plugin_positions_.push_back(position); | 254 web_plugin_positions_.push_back(position); |
251 UpdateActivePlugin(plugin); | 255 UpdateActivePlugin(plugin); |
| 256 return &web_plugin_infos_.back(); |
| 257 } |
| 258 |
| 259 std::list<WebPluginInfo>& PluginGroup::GetPlugins() { |
| 260 return web_plugin_infos_; |
| 261 } |
| 262 |
| 263 std::vector<int>& PluginGroup::GetPluginPositions() { |
| 264 return web_plugin_positions_; |
252 } | 265 } |
253 | 266 |
254 string16 PluginGroup::GetGroupName() const { | 267 string16 PluginGroup::GetGroupName() const { |
255 if (!group_name_.empty()) | 268 if (!group_name_.empty()) |
256 return group_name_; | 269 return group_name_; |
257 DCHECK_EQ(1u, web_plugin_infos_.size()); | 270 DCHECK_EQ(1u, web_plugin_infos_.size()); |
258 FilePath::StringType path = | 271 FilePath::StringType path = |
259 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); | 272 web_plugin_infos_.front().path.BaseName().RemoveExtension().value(); |
260 #if defined(OS_POSIX) | 273 #if defined(OS_POSIX) |
261 return UTF8ToUTF16(path); | 274 return UTF8ToUTF16(path); |
262 #elif defined(OS_WIN) | 275 #elif defined(OS_WIN) |
263 return WideToUTF16(path); | 276 return WideToUTF16(path); |
264 #endif | 277 #endif |
265 } | 278 } |
266 | 279 |
267 DictionaryValue* PluginGroup::GetSummary() const { | 280 DictionaryValue* PluginGroup::GetSummary() const { |
268 DictionaryValue* result = new DictionaryValue(); | 281 DictionaryValue* result = new DictionaryValue(); |
269 result->SetString("name", GetGroupName()); | 282 result->SetString("name", GetGroupName()); |
270 result->SetBoolean("enabled", enabled_); | 283 result->SetBoolean("enabled", enabled_); |
271 return result; | 284 return result; |
272 } | 285 } |
273 | 286 |
274 DictionaryValue* PluginGroup::GetDataForUI() const { | 287 DictionaryValue* PluginGroup::GetDataForUI() const { |
275 string16 name = GetGroupName(); | 288 string16 name = GetGroupName(); |
276 DictionaryValue* result = new DictionaryValue(); | 289 DictionaryValue* result = new DictionaryValue(); |
277 result->SetString("name", name); | 290 result->SetString("name", name); |
278 result->SetString("description", description_); | 291 result->SetString("description", description_); |
279 result->SetString("version", version_->GetString()); | 292 result->SetString("version", version_->GetString()); |
280 result->SetString("update_url", update_url_); | 293 result->SetString("update_url", update_url_); |
281 result->SetBoolean("critical", IsVulnerable()); | 294 result->SetBoolean("critical", IsVulnerable()); |
282 | 295 |
283 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); | 296 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); |
284 ListValue* plugin_files = new ListValue(); | 297 ListValue* plugin_files = new ListValue(); |
285 bool all_plugins_disabled_by_policy = true; | 298 bool all_plugins_disabled_by_policy = true; |
286 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 299 std::vector<int>::const_iterator itprio = web_plugin_positions_.begin(); |
287 const WebPluginInfo& web_plugin = web_plugin_infos_[i]; | 300 for (std::list<WebPluginInfo>::const_iterator it = web_plugin_infos_.begin(); |
288 int priority = web_plugin_positions_[i]; | 301 it != web_plugin_infos_.end(); ++it, ++itprio) { |
| 302 const WebPluginInfo& web_plugin = *it; |
| 303 int priority = *itprio; |
289 DictionaryValue* plugin_file = new DictionaryValue(); | 304 DictionaryValue* plugin_file = new DictionaryValue(); |
290 plugin_file->SetString("name", web_plugin.name); | 305 plugin_file->SetString("name", web_plugin.name); |
291 plugin_file->SetString("description", web_plugin.desc); | 306 plugin_file->SetString("description", web_plugin.desc); |
292 plugin_file->SetString("path", web_plugin.path.value()); | 307 plugin_file->SetString("path", web_plugin.path.value()); |
293 plugin_file->SetString("version", web_plugin.version); | 308 plugin_file->SetString("version", web_plugin.version); |
294 bool plugin_disabled_by_policy = group_disabled_by_policy || | 309 bool plugin_disabled_by_policy = group_disabled_by_policy || |
295 IsPluginNameDisabledByPolicy(web_plugin.name); | 310 IsPluginNameDisabledByPolicy(web_plugin.name); |
296 if (plugin_disabled_by_policy) { | 311 if (plugin_disabled_by_policy) { |
297 plugin_file->SetString("enabledMode", "disabledByPolicy"); | 312 plugin_file->SetString("enabledMode", "disabledByPolicy"); |
298 } else { | 313 } else { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // Returns true if the latest version of this plugin group is vulnerable. | 377 // Returns true if the latest version of this plugin group is vulnerable. |
363 bool PluginGroup::IsVulnerable() const { | 378 bool PluginGroup::IsVulnerable() const { |
364 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 379 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
365 if (IsPluginOutdated(*version_, version_ranges_[i])) | 380 if (IsPluginOutdated(*version_, version_ranges_[i])) |
366 return true; | 381 return true; |
367 } | 382 } |
368 return false; | 383 return false; |
369 } | 384 } |
370 | 385 |
371 void PluginGroup::DisableOutdatedPlugins() { | 386 void PluginGroup::DisableOutdatedPlugins() { |
372 description_ = string16(); | 387 bool first_enabled = true; |
373 enabled_ = false; | |
374 | 388 |
375 for (std::vector<WebPluginInfo>::iterator it = | 389 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
376 web_plugin_infos_.begin(); | 390 it != web_plugin_infos_.end(); ++it) { |
377 it != web_plugin_infos_.end(); ++it) { | 391 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
378 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 392 if (version.get()) { |
379 if (version.get()) { | 393 bool plugin_is_outdated = false; |
380 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 394 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
381 if (IsPluginOutdated(*version, version_ranges_[i])) { | 395 if (IsPluginOutdated(*version, version_ranges_[i])) { |
382 it->enabled = false; | 396 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, false); |
383 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 397 plugin_is_outdated = true; |
384 } | 398 break; |
385 } | 399 } |
386 } | 400 } |
387 UpdateActivePlugin(*it); | 401 if (!plugin_is_outdated && first_enabled) { |
388 } | 402 first_enabled = false; |
| 403 UpdateDescriptionAndVersion(*it); |
| 404 } |
| 405 } |
| 406 } |
389 } | 407 } |
390 | 408 |
391 void PluginGroup::Enable(bool enable) { | 409 void PluginGroup::Enable(bool enable) { |
392 bool enabled_plugin_exists = false; | 410 bool enabled_plugin_exists = false; |
393 for (std::vector<WebPluginInfo>::iterator it = | 411 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
394 web_plugin_infos_.begin(); | |
395 it != web_plugin_infos_.end(); ++it) { | 412 it != web_plugin_infos_.end(); ++it) { |
396 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 413 bool policy_disabled = IsPluginNameDisabledByPolicy(it->name); |
| 414 if (enable && !policy_disabled) { |
397 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 415 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
398 it->enabled = true; | |
399 enabled_plugin_exists = true; | 416 enabled_plugin_exists = true; |
400 } else { | 417 } else { |
401 it->enabled = false; | 418 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, policy_disabled); |
402 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | |
403 } | 419 } |
404 } | 420 } |
405 enabled_ = enabled_plugin_exists; | 421 enabled_ = enabled_plugin_exists; |
| 422 } |
| 423 |
| 424 void PluginGroup::RefreshEnabledState() { |
| 425 bool enabled_plugin_exists = false; |
| 426 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
| 427 it != web_plugin_infos_.end(); ++it) { |
| 428 if (it->enabled) { |
| 429 enabled_plugin_exists = true; |
| 430 break; |
| 431 } |
| 432 } |
| 433 enabled_ = enabled_plugin_exists; |
406 } | 434 } |
OLD | NEW |