Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: webkit/glue/plugins/plugin_group.cc

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Plugin reloading works completely now. Lint made happy as well. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const std::string& identifier) 96 const std::string& identifier)
97 : identifier_(identifier), 97 : identifier_(identifier),
98 group_name_(group_name), 98 group_name_(group_name),
99 name_matcher_(name_matcher), 99 name_matcher_(name_matcher),
100 update_url_(update_url), 100 update_url_(update_url),
101 enabled_(false), 101 enabled_(false),
102 version_(Version::GetVersionFromString("0")) { 102 version_(Version::GetVersionFromString("0")) {
103 } 103 }
104 104
105 void PluginGroup::InitFrom(const PluginGroup& other) { 105 void PluginGroup::InitFrom(const PluginGroup& other) {
106 enabled_ = false;
106 identifier_ = other.identifier_; 107 identifier_ = other.identifier_;
107 group_name_ = other.group_name_; 108 group_name_ = other.group_name_;
108 name_matcher_ = other.name_matcher_; 109 name_matcher_ = other.name_matcher_;
109 description_ = other.description_;
110 update_url_ = other.update_url_; 110 update_url_ = other.update_url_;
111 enabled_ = other.enabled_;
112 for (size_t i = 0; i < other.version_ranges_.size(); ++i) 111 for (size_t i = 0; i < other.version_ranges_.size(); ++i)
113 version_ranges_.push_back(other.version_ranges_[i]); 112 version_ranges_.push_back(other.version_ranges_[i]);
114 DCHECK_EQ(other.web_plugin_infos_.size(), other.web_plugin_positions_.size()); 113 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) 114 std::list<WebPluginInfo>::const_iterator it = other.web_plugin_infos_.begin();
116 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); 115 std::vector<int>::const_iterator itprio = other.web_plugin_positions_.begin();
116 for (; it != other.web_plugin_infos_.end(); ++it, ++itprio)
117 AddPlugin(*it, *itprio, NULL);
117 if (!version_.get()) 118 if (!version_.get())
118 version_.reset(Version::GetVersionFromString("0")); 119 version_.reset(Version::GetVersionFromString("0"));
120 enabled_ = other.enabled_;
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();
127 InitFrom(other); 129 InitFrom(other);
128 return *this; 130 return *this;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool PluginGroup::AddPlugin(
241 const WebPluginInfo& plugin,
242 int position,
243 WebPluginInfo** group_plugin_copy) {
239 // Check if this group already contains this plugin. 244 // Check if this group already contains this plugin.
240 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { 245 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin();
241 if (web_plugin_infos_[i].name == plugin.name && 246 it != web_plugin_infos_.end(); ++it) {
242 web_plugin_infos_[i].version == plugin.version && 247 if (it->name == plugin.name &&
243 FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), 248 it->version == plugin.version &&
249 FilePath::CompareEqualIgnoreCase(it->path.value(),
244 plugin.path.value())) { 250 plugin.path.value())) {
245 return; 251 if (group_plugin_copy)
252 *group_plugin_copy = &(*it);
253 return false;
246 } 254 }
247 } 255 }
248 web_plugin_infos_.push_back(plugin); 256 web_plugin_infos_.push_back(plugin);
249 // The position of this plugin relative to the global list of plugins. 257 // The position of this plugin relative to the global list of plugins.
250 web_plugin_positions_.push_back(position); 258 web_plugin_positions_.push_back(position);
251 UpdateActivePlugin(plugin); 259 UpdateActivePlugin(plugin);
260 if (group_plugin_copy)
261 *group_plugin_copy = &web_plugin_infos_.back();
262 return true;
263 }
264
265 std::list<WebPluginInfo>& PluginGroup::GetPlugins() {
266 return web_plugin_infos_;
267 }
268
269 std::vector<int>& PluginGroup::GetPluginPositions() {
270 return web_plugin_positions_;
252 } 271 }
253 272
254 string16 PluginGroup::GetGroupName() const { 273 string16 PluginGroup::GetGroupName() const {
255 if (!group_name_.empty()) 274 if (!group_name_.empty())
256 return group_name_; 275 return group_name_;
257 DCHECK_EQ(1u, web_plugin_infos_.size()); 276 DCHECK_EQ(1u, web_plugin_infos_.size());
258 FilePath::StringType path = 277 FilePath::StringType path =
259 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); 278 web_plugin_infos_.front().path.BaseName().RemoveExtension().value();
260 #if defined(OS_POSIX) 279 #if defined(OS_POSIX)
261 return UTF8ToUTF16(path); 280 return UTF8ToUTF16(path);
262 #elif defined(OS_WIN) 281 #elif defined(OS_WIN)
263 return WideToUTF16(path); 282 return WideToUTF16(path);
264 #endif 283 #endif
265 } 284 }
266 285
267 DictionaryValue* PluginGroup::GetSummary() const { 286 DictionaryValue* PluginGroup::GetSummary() const {
268 DictionaryValue* result = new DictionaryValue(); 287 DictionaryValue* result = new DictionaryValue();
269 result->SetString("name", GetGroupName()); 288 result->SetString("name", GetGroupName());
270 result->SetBoolean("enabled", enabled_); 289 result->SetBoolean("enabled", enabled_);
271 return result; 290 return result;
272 } 291 }
273 292
274 DictionaryValue* PluginGroup::GetDataForUI() const { 293 DictionaryValue* PluginGroup::GetDataForUI() const {
275 string16 name = GetGroupName(); 294 string16 name = GetGroupName();
276 DictionaryValue* result = new DictionaryValue(); 295 DictionaryValue* result = new DictionaryValue();
277 result->SetString("name", name); 296 result->SetString("name", name);
278 result->SetString("description", description_); 297 result->SetString("description", description_);
279 result->SetString("version", version_->GetString()); 298 result->SetString("version", version_->GetString());
280 result->SetString("update_url", update_url_); 299 result->SetString("update_url", update_url_);
281 result->SetBoolean("critical", IsVulnerable()); 300 result->SetBoolean("critical", IsVulnerable());
282 301
283 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); 302 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name);
284 ListValue* plugin_files = new ListValue(); 303 ListValue* plugin_files = new ListValue();
285 bool all_plugins_disabled_by_policy = true; 304 bool all_plugins_disabled_by_policy = true;
286 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { 305 std::vector<int>::const_iterator itprio = web_plugin_positions_.begin();
287 const WebPluginInfo& web_plugin = web_plugin_infos_[i]; 306 for (std::list<WebPluginInfo>::const_iterator it = web_plugin_infos_.begin();
jam 2010/12/15 19:48:55 ditto, using an iterator here makes the code unnec
288 int priority = web_plugin_positions_[i]; 307 it != web_plugin_infos_.end(); ++it, ++itprio) {
308 const WebPluginInfo& web_plugin = *it;
309 int priority = *itprio;
289 DictionaryValue* plugin_file = new DictionaryValue(); 310 DictionaryValue* plugin_file = new DictionaryValue();
290 plugin_file->SetString("name", web_plugin.name); 311 plugin_file->SetString("name", web_plugin.name);
291 plugin_file->SetString("description", web_plugin.desc); 312 plugin_file->SetString("description", web_plugin.desc);
292 plugin_file->SetString("path", web_plugin.path.value()); 313 plugin_file->SetString("path", web_plugin.path.value());
293 plugin_file->SetString("version", web_plugin.version); 314 plugin_file->SetString("version", web_plugin.version);
294 bool plugin_disabled_by_policy = group_disabled_by_policy || 315 bool plugin_disabled_by_policy = group_disabled_by_policy ||
295 IsPluginNameDisabledByPolicy(web_plugin.name); 316 IsPluginNameDisabledByPolicy(web_plugin.name);
296 if (plugin_disabled_by_policy) { 317 if (plugin_disabled_by_policy) {
297 plugin_file->SetString("enabledMode", "disabledByPolicy"); 318 plugin_file->SetString("enabledMode", "disabledByPolicy");
298 } else { 319 } else {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // Returns true if the latest version of this plugin group is vulnerable. 383 // Returns true if the latest version of this plugin group is vulnerable.
363 bool PluginGroup::IsVulnerable() const { 384 bool PluginGroup::IsVulnerable() const {
364 for (size_t i = 0; i < version_ranges_.size(); ++i) { 385 for (size_t i = 0; i < version_ranges_.size(); ++i) {
365 if (IsPluginOutdated(*version_, version_ranges_[i])) 386 if (IsPluginOutdated(*version_, version_ranges_[i]))
366 return true; 387 return true;
367 } 388 }
368 return false; 389 return false;
369 } 390 }
370 391
371 void PluginGroup::DisableOutdatedPlugins() { 392 void PluginGroup::DisableOutdatedPlugins() {
372 description_ = string16(); 393 bool first_enabled = true;
373 enabled_ = false;
374 394
375 for (std::vector<WebPluginInfo>::iterator it = 395 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin();
376 web_plugin_infos_.begin(); 396 it != web_plugin_infos_.end(); ++it) {
377 it != web_plugin_infos_.end(); ++it) {
378 scoped_ptr<Version> version(CreateVersionFromString(it->version)); 397 scoped_ptr<Version> version(CreateVersionFromString(it->version));
379 if (version.get()) { 398 if (version.get()) {
399 bool plugin_is_outdated = false;
380 for (size_t i = 0; i < version_ranges_.size(); ++i) { 400 for (size_t i = 0; i < version_ranges_.size(); ++i) {
381 if (IsPluginOutdated(*version, version_ranges_[i])) { 401 if (IsPluginOutdated(*version, version_ranges_[i])) {
382 it->enabled = false; 402 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, false);
383 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); 403 plugin_is_outdated = true;
404 break;
384 } 405 }
385 } 406 }
407 if (!plugin_is_outdated && first_enabled) {
408 first_enabled = false;
409 UpdateDescriptionAndVersion(*it);
410 }
386 } 411 }
387 UpdateActivePlugin(*it);
388 } 412 }
389 } 413 }
390 414
391 void PluginGroup::Enable(bool enable) { 415 void PluginGroup::Enable(bool enable) {
392 bool enabled_plugin_exists = false; 416 bool enabled_plugin_exists = false;
393 for (std::vector<WebPluginInfo>::iterator it = 417 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin();
394 web_plugin_infos_.begin();
395 it != web_plugin_infos_.end(); ++it) { 418 it != web_plugin_infos_.end(); ++it) {
396 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { 419 bool policy_disabled = IsPluginNameDisabledByPolicy(it->name);
420 if (enable && !policy_disabled) {
397 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); 421 NPAPI::PluginList::Singleton()->EnablePlugin(it->path);
398 it->enabled = true;
399 enabled_plugin_exists = true; 422 enabled_plugin_exists = true;
400 } else { 423 } else {
401 it->enabled = false; 424 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, policy_disabled);
402 NPAPI::PluginList::Singleton()->DisablePlugin(it->path);
403 } 425 }
404 } 426 }
405 enabled_ = enabled_plugin_exists; 427 enabled_ = enabled_plugin_exists;
428 }
429
430 void PluginGroup::RefreshEnabledState() {
431 bool enabled_plugin_exists = false;
432 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin();
433 it != web_plugin_infos_.end(); ++it) {
434 if (it->enabled) {
435 enabled_plugin_exists = true;
436 break;
437 }
438 }
439 enabled_ = enabled_plugin_exists;
406 } 440 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698