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

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

Issue 5783005: PluginList: Unit tests and bugfixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a few details 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 PluginGroup::PluginGroup(const string16& group_name, 93 PluginGroup::PluginGroup(const string16& group_name,
94 const string16& name_matcher, 94 const string16& name_matcher,
95 const std::string& update_url, 95 const std::string& update_url,
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 plugin_list_(NULL) {
103 } 104 }
104 105
105 void PluginGroup::InitFrom(const PluginGroup& other) { 106 void PluginGroup::InitFrom(const PluginGroup& other) {
107 enabled_ = false;
danno 2010/12/15 10:42:12 Please comment why there enabled_ flag is set twic
Jakob Kummerow 2010/12/15 18:03:27 Done. Cleaned up this whole method, it now perform
106 identifier_ = other.identifier_; 108 identifier_ = other.identifier_;
107 group_name_ = other.group_name_; 109 group_name_ = other.group_name_;
108 name_matcher_ = other.name_matcher_; 110 name_matcher_ = other.name_matcher_;
109 description_ = other.description_;
110 update_url_ = other.update_url_; 111 update_url_ = other.update_url_;
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 std::list<WebPluginInfo>::const_iterator it = other.web_plugin_infos_.begin(); 115 std::list<WebPluginInfo>::const_iterator it = other.web_plugin_infos_.begin();
116 std::vector<int>::const_iterator itprio = other.web_plugin_positions_.begin(); 116 std::vector<int>::const_iterator itprio = other.web_plugin_positions_.begin();
117 for (; it != other.web_plugin_infos_.end(); ++it, ++itprio) 117 for (; it != other.web_plugin_infos_.end(); ++it, ++itprio)
118 AddPlugin(*it, *itprio); 118 AddPlugin(*it, *itprio);
119 if (!version_.get()) 119 if (!version_.get())
120 version_.reset(Version::GetVersionFromString("0")); 120 version_.reset(Version::GetVersionFromString("0"));
121 DCHECK_EQ(0, version_->CompareTo(*other.version_));
122 plugin_list_ = other.plugin_list_;
123 enabled_ = other.enabled_;
121 } 124 }
122 125
123 PluginGroup::PluginGroup(const PluginGroup& other) { 126 PluginGroup::PluginGroup(const PluginGroup& other) {
124 InitFrom(other); 127 InitFrom(other);
125 } 128 }
126 129
127 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { 130 PluginGroup& PluginGroup::operator=(const PluginGroup& other) {
danno 2010/12/15 10:42:12 use the copy/swap idiom?
Jakob Kummerow 2010/12/15 18:03:27 As discussed offline: would be nice to have, but i
128 version_ranges_.clear(); 131 version_ranges_.clear();
129 InitFrom(other); 132 InitFrom(other);
130 return *this; 133 return *this;
131 } 134 }
132 135
133 /*static*/ 136 /*static*/
134 PluginGroup* PluginGroup::FromPluginGroupDefinition( 137 PluginGroup* PluginGroup::FromPluginGroupDefinition(
135 const PluginGroupDefinition& definition) { 138 const PluginGroupDefinition& definition) {
136 PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name), 139 PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name),
137 ASCIIToUTF16(definition.name_matcher), 140 ASCIIToUTF16(definition.name_matcher),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 260 }
258 261
259 std::list<WebPluginInfo>& PluginGroup::GetPlugins() { 262 std::list<WebPluginInfo>& PluginGroup::GetPlugins() {
260 return web_plugin_infos_; 263 return web_plugin_infos_;
261 } 264 }
262 265
263 std::vector<int>& PluginGroup::GetPluginPositions() { 266 std::vector<int>& PluginGroup::GetPluginPositions() {
264 return web_plugin_positions_; 267 return web_plugin_positions_;
265 } 268 }
266 269
270 bool PluginGroup::IsEmpty() {
271 return web_plugin_infos_.empty();
272 }
273
267 string16 PluginGroup::GetGroupName() const { 274 string16 PluginGroup::GetGroupName() const {
268 if (!group_name_.empty()) 275 if (!group_name_.empty())
269 return group_name_; 276 return group_name_;
270 DCHECK_EQ(1u, web_plugin_infos_.size()); 277 DCHECK_EQ(1u, web_plugin_infos_.size());
271 FilePath::StringType path = 278 FilePath::StringType path =
272 web_plugin_infos_.front().path.BaseName().RemoveExtension().value(); 279 web_plugin_infos_.front().path.BaseName().RemoveExtension().value();
273 #if defined(OS_POSIX) 280 #if defined(OS_POSIX)
274 return UTF8ToUTF16(path); 281 return UTF8ToUTF16(path);
275 #elif defined(OS_WIN) 282 #elif defined(OS_WIN)
276 return WideToUTF16(path); 283 return WideToUTF16(path);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 void PluginGroup::DisableOutdatedPlugins() { 393 void PluginGroup::DisableOutdatedPlugins() {
387 bool first_enabled = true; 394 bool first_enabled = true;
388 395
389 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); 396 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin();
390 it != web_plugin_infos_.end(); ++it) { 397 it != web_plugin_infos_.end(); ++it) {
391 scoped_ptr<Version> version(CreateVersionFromString(it->version)); 398 scoped_ptr<Version> version(CreateVersionFromString(it->version));
392 if (version.get()) { 399 if (version.get()) {
393 bool plugin_is_outdated = false; 400 bool plugin_is_outdated = false;
394 for (size_t i = 0; i < version_ranges_.size(); ++i) { 401 for (size_t i = 0; i < version_ranges_.size(); ++i) {
395 if (IsPluginOutdated(*version, version_ranges_[i])) { 402 if (IsPluginOutdated(*version, version_ranges_[i])) {
396 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, false); 403 GetPluginList()->DisablePlugin(it->path, false);
397 plugin_is_outdated = true; 404 plugin_is_outdated = true;
398 break; 405 break;
399 } 406 }
400 } 407 }
401 if (!plugin_is_outdated && first_enabled) { 408 if (!plugin_is_outdated && first_enabled) {
402 first_enabled = false; 409 first_enabled = false;
403 UpdateDescriptionAndVersion(*it); 410 UpdateDescriptionAndVersion(*it);
404 } 411 }
405 } 412 }
406 } 413 }
407 } 414 }
408 415
409 void PluginGroup::Enable(bool enable) { 416 void PluginGroup::Enable(bool enable) {
410 bool enabled_plugin_exists = false; 417 bool enabled_plugin_exists = false;
411 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); 418 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin();
412 it != web_plugin_infos_.end(); ++it) { 419 it != web_plugin_infos_.end(); ++it) {
413 bool policy_disabled = IsPluginNameDisabledByPolicy(it->name); 420 bool policy_disabled = IsPluginNameDisabledByPolicy(it->name);
414 if (enable && !policy_disabled) { 421 if (enable && !policy_disabled) {
415 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); 422 GetPluginList()->EnablePlugin(it->path);
416 enabled_plugin_exists = true; 423 enabled_plugin_exists = true;
417 } else { 424 } else {
418 NPAPI::PluginList::Singleton()->DisablePlugin(it->path, policy_disabled); 425 GetPluginList()->DisablePlugin(it->path, policy_disabled);
419 } 426 }
420 } 427 }
421 enabled_ = enabled_plugin_exists; 428 enabled_ = enabled_plugin_exists;
422 } 429 }
423 430
424 void PluginGroup::RefreshEnabledState() { 431 void PluginGroup::RefreshEnabledState() {
425 bool enabled_plugin_exists = false; 432 bool enabled_plugin_exists = false;
426 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); 433 for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin();
427 it != web_plugin_infos_.end(); ++it) { 434 it != web_plugin_infos_.end(); ++it) {
428 if (it->enabled) { 435 if (it->enabled) {
429 enabled_plugin_exists = true; 436 enabled_plugin_exists = true;
430 break; 437 break;
431 } 438 }
432 } 439 }
433 enabled_ = enabled_plugin_exists; 440 enabled_ = enabled_plugin_exists;
434 } 441 }
442
443 NPAPI::PluginList* PluginGroup::GetPluginList() {
danno 2010/12/15 10:42:12 I think you might be better served by making this
Jakob Kummerow 2010/12/15 18:03:27 As discussed offline: Good plan, but would require
444 if (plugin_list_)
445 return plugin_list_;
446 return NPAPI::PluginList::Singleton();
447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698