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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 226 } |
227 | 227 |
228 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 228 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
229 description_ = plugin.desc; | 229 description_ = plugin.desc; |
230 if (Version* new_version = CreateVersionFromString(plugin.version)) | 230 if (Version* new_version = CreateVersionFromString(plugin.version)) |
231 version_.reset(new_version); | 231 version_.reset(new_version); |
232 else | 232 else |
233 version_.reset(Version::GetVersionFromString("0")); | 233 version_.reset(Version::GetVersionFromString("0")); |
234 } | 234 } |
235 | 235 |
236 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 236 bool PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { |
237 // Check if this group already contains this plugin. | 237 // Check if this group already contains this plugin. |
238 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 238 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
239 if (web_plugin_infos_[i].name == plugin.name && | 239 if (web_plugin_infos_[i].name == plugin.name && |
240 web_plugin_infos_[i].version == plugin.version && | 240 web_plugin_infos_[i].version == plugin.version && |
241 FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), | 241 FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), |
242 plugin.path.value())) { | 242 plugin.path.value())) { |
243 return; | 243 return false; |
244 } | 244 } |
245 } | 245 } |
246 web_plugin_infos_.push_back(plugin); | 246 web_plugin_infos_.push_back(plugin); |
247 // The position of this plugin relative to the global list of plugins. | 247 // The position of this plugin relative to the global list of plugins. |
248 web_plugin_positions_.push_back(position); | 248 web_plugin_positions_.push_back(position); |
249 UpdateActivePlugin(plugin); | 249 UpdateActivePlugin(plugin); |
| 250 return true; |
| 251 } |
| 252 |
| 253 std::vector<WebPluginInfo>& PluginGroup::GetPlugins() { |
| 254 return web_plugin_infos_; |
| 255 } |
| 256 |
| 257 std::vector<int>& PluginGroup::GetPluginPositions() { |
| 258 return web_plugin_positions_; |
250 } | 259 } |
251 | 260 |
252 string16 PluginGroup::GetGroupName() const { | 261 string16 PluginGroup::GetGroupName() const { |
253 if (!group_name_.empty()) | 262 if (!group_name_.empty()) |
254 return group_name_; | 263 return group_name_; |
255 DCHECK_EQ(1u, web_plugin_infos_.size()); | 264 DCHECK_EQ(1u, web_plugin_infos_.size()); |
256 FilePath::StringType path = | 265 FilePath::StringType path = |
257 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); | 266 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); |
258 #if defined(OS_POSIX) | 267 #if defined(OS_POSIX) |
259 return UTF8ToUTF16(path); | 268 return UTF8ToUTF16(path); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // Returns true if the latest version of this plugin group is vulnerable. | 369 // Returns true if the latest version of this plugin group is vulnerable. |
361 bool PluginGroup::IsVulnerable() const { | 370 bool PluginGroup::IsVulnerable() const { |
362 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 371 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
363 if (IsPluginOutdated(*version_, version_ranges_[i])) | 372 if (IsPluginOutdated(*version_, version_ranges_[i])) |
364 return true; | 373 return true; |
365 } | 374 } |
366 return false; | 375 return false; |
367 } | 376 } |
368 | 377 |
369 void PluginGroup::DisableOutdatedPlugins() { | 378 void PluginGroup::DisableOutdatedPlugins() { |
| 379 bool first_enabled = true; |
370 description_ = string16(); | 380 description_ = string16(); |
371 enabled_ = false; | 381 enabled_ = false; |
372 | 382 |
373 for (std::vector<WebPluginInfo>::iterator it = | 383 for (std::vector<WebPluginInfo>::iterator it = |
374 web_plugin_infos_.begin(); | 384 web_plugin_infos_.begin(); |
375 it != web_plugin_infos_.end(); ++it) { | 385 it != web_plugin_infos_.end(); ++it) { |
376 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 386 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
377 if (version.get()) { | 387 if (version.get()) { |
378 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 388 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
379 if (IsPluginOutdated(*version, version_ranges_[i])) { | 389 if (IsPluginOutdated(*version, version_ranges_[i])) { |
380 it->enabled = false; | 390 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, false); |
381 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 391 } else if (first_enabled) { |
| 392 UpdateDescriptionAndVersion(*it); |
| 393 first_enabled = false; |
382 } | 394 } |
383 } | 395 } |
384 } | 396 } |
385 UpdateActivePlugin(*it); | |
386 } | 397 } |
387 } | 398 } |
388 | 399 |
389 void PluginGroup::Enable(bool enable) { | 400 void PluginGroup::Enable(bool enable) { |
390 bool enabled_plugin_exists = false; | 401 bool enabled_plugin_exists = false; |
391 for (std::vector<WebPluginInfo>::iterator it = | 402 for (std::vector<WebPluginInfo>::iterator it = |
392 web_plugin_infos_.begin(); | 403 web_plugin_infos_.begin(); |
393 it != web_plugin_infos_.end(); ++it) { | 404 it != web_plugin_infos_.end(); ++it) { |
394 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 405 bool policy_disabled = IsPluginNameDisabledByPolicy(it->name); |
| 406 if (enable && !policy_disabled) { |
395 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 407 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
396 it->enabled = true; | |
397 enabled_plugin_exists = true; | 408 enabled_plugin_exists = true; |
398 } else { | 409 } else { |
399 it->enabled = false; | 410 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, policy_disabled); |
400 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | |
401 } | 411 } |
402 } | 412 } |
403 enabled_ = enabled_plugin_exists; | 413 enabled_ = enabled_plugin_exists; |
| 414 } |
| 415 |
| 416 void PluginGroup::RefreshEnabledState() { |
| 417 bool enabled_plugin_exists = false; |
| 418 for (std::vector<WebPluginInfo>::iterator it = |
| 419 web_plugin_infos_.begin(); |
| 420 it != web_plugin_infos_.end(); ++it) { |
| 421 if (it->enabled) { |
| 422 enabled_plugin_exists = true; |
| 423 break; |
| 424 } |
| 425 } |
| 426 enabled_ = enabled_plugin_exists; |
404 } | 427 } |
OLD | NEW |