Chromium Code Reviews| 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/plugins/npapi/plugin_group.h" | 5 #include "webkit/plugins/npapi/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 28 matching lines...) Expand all Loading... | |
| 39 policy_disabled_plugin_patterns_->begin()); | 39 policy_disabled_plugin_patterns_->begin()); |
| 40 while (pattern != policy_disabled_plugin_patterns_->end()) { | 40 while (pattern != policy_disabled_plugin_patterns_->end()) { |
| 41 if (MatchPattern(plugin_name, *pattern)) | 41 if (MatchPattern(plugin_name, *pattern)) |
| 42 return true; | 42 return true; |
| 43 ++pattern; | 43 ++pattern; |
| 44 } | 44 } |
| 45 | 45 |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 | 48 |
| 49 /*static*/ | |
| 50 bool PluginGroup::IsPluginPathDisabledByPolicy(const FilePath& plugin_path) { | |
| 51 std::vector<WebPluginInfo> plugins; | |
| 52 PluginList::Singleton()->GetPlugins(false, &plugins); | |
| 53 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); | |
| 54 it != plugins.end(); | |
| 55 ++it) { | |
| 56 if (FilePath::CompareEqualIgnoreCase(it->path.value(), | |
| 57 plugin_path.value()) && IsPluginNameDisabledByPolicy(it->name)) { | |
| 58 return true; | |
| 59 } | |
| 60 } | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 VersionRange::VersionRange(VersionRangeDefinition definition) | 49 VersionRange::VersionRange(VersionRangeDefinition definition) |
| 65 : low_str(definition.version_matcher_low), | 50 : low_str(definition.version_matcher_low), |
| 66 high_str(definition.version_matcher_high), | 51 high_str(definition.version_matcher_high), |
| 67 min_str(definition.min_version) { | 52 min_str(definition.min_version) { |
| 68 if (!low_str.empty()) | 53 if (!low_str.empty()) |
| 69 low.reset(Version::GetVersionFromString(low_str)); | 54 low.reset(Version::GetVersionFromString(low_str)); |
| 70 if (!high_str.empty()) | 55 if (!high_str.empty()) |
| 71 high.reset(Version::GetVersionFromString(high_str)); | 56 high.reset(Version::GetVersionFromString(high_str)); |
| 72 if (!min_str.empty()) | 57 if (!min_str.empty()) |
| 73 min.reset(Version::GetVersionFromString(min_str)); | 58 min.reset(Version::GetVersionFromString(min_str)); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 94 } | 79 } |
| 95 | 80 |
| 96 PluginGroup::PluginGroup(const string16& group_name, | 81 PluginGroup::PluginGroup(const string16& group_name, |
| 97 const string16& name_matcher, | 82 const string16& name_matcher, |
| 98 const std::string& update_url, | 83 const std::string& update_url, |
| 99 const std::string& identifier) | 84 const std::string& identifier) |
| 100 : identifier_(identifier), | 85 : identifier_(identifier), |
| 101 group_name_(group_name), | 86 group_name_(group_name), |
| 102 name_matcher_(name_matcher), | 87 name_matcher_(name_matcher), |
| 103 update_url_(update_url), | 88 update_url_(update_url), |
| 104 enabled_(false), | 89 enabled_(true), |
| 105 version_(Version::GetVersionFromString("0")) { | 90 version_(Version::GetVersionFromString("0")) { |
| 106 } | 91 } |
| 107 | 92 |
| 108 void PluginGroup::InitFrom(const PluginGroup& other) { | 93 void PluginGroup::InitFrom(const PluginGroup& other) { |
| 109 identifier_ = other.identifier_; | 94 identifier_ = other.identifier_; |
| 110 group_name_ = other.group_name_; | 95 group_name_ = other.group_name_; |
| 111 name_matcher_ = other.name_matcher_; | 96 name_matcher_ = other.name_matcher_; |
| 112 description_ = other.description_; | 97 description_ = other.description_; |
| 113 update_url_ = other.update_url_; | 98 update_url_ = other.update_url_; |
| 114 enabled_ = other.enabled_; | 99 enabled_ = other.enabled_; |
| 115 version_ranges_ = other.version_ranges_; | 100 version_ranges_ = other.version_ranges_; |
| 116 version_.reset(other.version_->Clone()); | 101 version_.reset(other.version_->Clone()); |
| 117 web_plugin_infos_ = other.web_plugin_infos_; | 102 web_plugin_infos_ = other.web_plugin_infos_; |
| 118 web_plugin_positions_ = other.web_plugin_positions_; | |
| 119 } | 103 } |
| 120 | 104 |
| 121 PluginGroup::PluginGroup(const PluginGroup& other) { | 105 PluginGroup::PluginGroup(const PluginGroup& other) { |
| 122 InitFrom(other); | 106 InitFrom(other); |
| 123 } | 107 } |
| 124 | 108 |
| 125 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | 109 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
| 126 InitFrom(other); | 110 InitFrom(other); |
| 127 return *this; | 111 return *this; |
| 128 } | 112 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 std::replace(version.begin(), version.end(), 'r', '.'); | 190 std::replace(version.begin(), version.end(), 'r', '.'); |
| 207 std::replace(version.begin(), version.end(), ',', '.'); | 191 std::replace(version.begin(), version.end(), ',', '.'); |
| 208 std::replace(version.begin(), version.end(), '(', '.'); | 192 std::replace(version.begin(), version.end(), '(', '.'); |
| 209 std::replace(version.begin(), version.end(), '_', '.'); | 193 std::replace(version.begin(), version.end(), '_', '.'); |
| 210 | 194 |
| 211 return Version::GetVersionFromString(WideToASCII(version)); | 195 return Version::GetVersionFromString(WideToASCII(version)); |
| 212 } | 196 } |
| 213 | 197 |
| 214 void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) { | 198 void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) { |
| 215 // A group is enabled if any of the files are enabled. | 199 // A group is enabled if any of the files are enabled. |
| 216 if (plugin.enabled) { | 200 if (IsPluginEnabled(plugin)) { |
| 217 if (!enabled_) { | 201 if (!enabled_ || description_.empty()) { |
|
jam
2011/01/19 20:22:09
don't need to look for empty description anymore r
pastarmovj
2011/01/19 23:39:17
Actually I do now. This is not part of the enforce
jam
2011/01/20 00:24:25
Got it. Please add a comment as this is hard to u
| |
| 218 // If this is the first enabled plugin, use its description. | 202 // If this is the first enabled plugin, use its description. |
| 219 enabled_ = true; | 203 enabled_ = true; |
| 220 UpdateDescriptionAndVersion(plugin); | 204 UpdateDescriptionAndVersion(plugin); |
| 221 } | 205 } |
| 222 } else { | 206 } else { |
| 223 // If this is the first plugin and it's disabled, | 207 // If this is the first plugin and it's disabled, |
| 224 // use its description for now. | 208 // use its description for now. |
| 225 if (description_.empty()) | 209 if (description_.empty()) |
| 226 UpdateDescriptionAndVersion(plugin); | 210 UpdateDescriptionAndVersion(plugin); |
| 227 } | 211 } |
| 228 } | 212 } |
| 229 | 213 |
| 230 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 214 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
| 231 description_ = plugin.desc; | 215 description_ = plugin.desc; |
| 232 if (Version* new_version = CreateVersionFromString(plugin.version)) | 216 if (Version* new_version = CreateVersionFromString(plugin.version)) |
| 233 version_.reset(new_version); | 217 version_.reset(new_version); |
| 234 else | 218 else |
| 235 version_.reset(Version::GetVersionFromString("0")); | 219 version_.reset(Version::GetVersionFromString("0")); |
| 236 } | 220 } |
| 237 | 221 |
| 238 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 222 bool PluginGroup::AddPlugin(const WebPluginInfo& plugin, int priority) { |
|
jam
2011/01/19 20:22:09
priority isn't used anymore
pastarmovj
2011/01/19 23:39:17
Done.
| |
| 239 // Check if this group already contains this plugin. | 223 // Check if this group already contains this plugin. |
| 240 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 224 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 241 if (web_plugin_infos_[i].name == plugin.name && | 225 if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), |
| 242 web_plugin_infos_[i].version == plugin.version && | |
| 243 FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), | |
| 244 plugin.path.value())) { | 226 plugin.path.value())) { |
| 245 return; | 227 return false; |
| 246 } | 228 } |
| 247 } | 229 } |
| 248 web_plugin_infos_.push_back(plugin); | 230 web_plugin_infos_.push_back(plugin); |
| 249 // The position of this plugin relative to the global list of plugins. | 231 // If the group is disabled disable new plugins in it too. This should cover |
| 250 web_plugin_positions_.push_back(position); | 232 // the case where a plugin has been upgraded that has been disabled and should |
| 251 UpdateActivePlugin(plugin); | 233 // stay disabled after the upgrade. |
| 234 if (!enabled_) | |
| 235 DisablePlugin(web_plugin_infos_.back().path); | |
| 236 UpdateActivePlugin(web_plugin_infos_.back()); | |
| 237 RefreshEnabledState(); | |
| 238 return true; | |
| 252 } | 239 } |
| 253 | 240 |
| 254 bool PluginGroup::IsEmpty() const { | 241 bool PluginGroup::RemovePlugin(const FilePath& filename) { |
| 255 return web_plugin_infos_.empty(); | 242 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 243 if (web_plugin_infos_[i].path == filename) { | |
| 244 web_plugin_infos_.erase(web_plugin_infos_.begin() + i); | |
| 245 return true; | |
| 246 } | |
| 247 } | |
| 248 return false; | |
| 249 } | |
| 250 | |
| 251 bool PluginGroup::EnablePlugin(const FilePath& filename) { | |
| 252 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | |
| 253 if (web_plugin_infos_[i].path == filename) { | |
| 254 bool did_enable = Enable(&web_plugin_infos_[i], | |
| 255 WebPluginInfo::USER_ENABLED); | |
| 256 RefreshEnabledState(); | |
| 257 return did_enable; | |
| 258 } | |
| 259 } | |
| 260 return false; | |
| 261 } | |
| 262 | |
| 263 bool PluginGroup::DisablePlugin(const FilePath& filename) { | |
| 264 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | |
| 265 if (web_plugin_infos_[i].path == filename) { | |
| 266 // We are only called for user intervention however we should respect a | |
| 267 // policy that might as well be active on this plugin. | |
| 268 bool did_disable = Disable( | |
| 269 &web_plugin_infos_[i], | |
| 270 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) ? | |
| 271 WebPluginInfo::USER_DISABLED_POLICY_DISABLED : | |
| 272 WebPluginInfo::USER_DISABLED); | |
| 273 RefreshEnabledState(); | |
| 274 return did_disable; | |
| 275 } | |
| 276 } | |
| 277 return false; | |
| 256 } | 278 } |
| 257 | 279 |
| 258 string16 PluginGroup::GetGroupName() const { | 280 string16 PluginGroup::GetGroupName() const { |
| 259 if (!group_name_.empty()) | 281 if (!group_name_.empty()) |
| 260 return group_name_; | 282 return group_name_; |
| 261 DCHECK_EQ(1u, web_plugin_infos_.size()); | 283 DCHECK_EQ(1u, web_plugin_infos_.size()); |
| 262 FilePath::StringType path = | 284 FilePath::StringType path = |
| 263 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); | 285 web_plugin_infos_.front().path.BaseName().RemoveExtension().value(); |
|
jam
2011/01/19 20:22:09
nit: any reason to change this? we avoid changing
pastarmovj
2011/01/19 23:39:17
Relict from the times this wasn't a vector. Revert
| |
| 264 #if defined(OS_POSIX) | 286 #if defined(OS_POSIX) |
| 265 return UTF8ToUTF16(path); | 287 return UTF8ToUTF16(path); |
| 266 #elif defined(OS_WIN) | 288 #elif defined(OS_WIN) |
| 267 return WideToUTF16(path); | 289 return WideToUTF16(path); |
| 268 #endif | 290 #endif |
| 269 } | 291 } |
| 270 | 292 |
| 293 const std::vector<WebPluginInfo>& PluginGroup::GetPlugins() const { | |
| 294 return web_plugin_infos_; | |
| 295 } | |
| 296 | |
| 297 bool PluginGroup::ContainsPlugin(const FilePath& path) const { | |
| 298 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | |
| 299 if (web_plugin_infos_[i].path == path) | |
| 300 return true; | |
| 301 } | |
| 302 return false; | |
| 303 } | |
| 304 | |
| 305 | |
| 271 DictionaryValue* PluginGroup::GetSummary() const { | 306 DictionaryValue* PluginGroup::GetSummary() const { |
| 272 DictionaryValue* result = new DictionaryValue(); | 307 DictionaryValue* result = new DictionaryValue(); |
| 273 result->SetString("name", GetGroupName()); | 308 result->SetString("name", GetGroupName()); |
| 274 result->SetBoolean("enabled", enabled_); | 309 result->SetBoolean("enabled", enabled_); |
| 275 return result; | 310 return result; |
| 276 } | 311 } |
| 277 | 312 |
| 278 DictionaryValue* PluginGroup::GetDataForUI() const { | 313 DictionaryValue* PluginGroup::GetDataForUI() const { |
| 279 string16 name = GetGroupName(); | 314 string16 name = GetGroupName(); |
| 280 DictionaryValue* result = new DictionaryValue(); | 315 DictionaryValue* result = new DictionaryValue(); |
| 281 result->SetString("name", name); | 316 result->SetString("name", name); |
| 282 result->SetString("description", description_); | 317 result->SetString("description", description_); |
| 283 result->SetString("version", version_->GetString()); | 318 result->SetString("version", version_->GetString()); |
| 284 result->SetString("update_url", update_url_); | 319 result->SetString("update_url", update_url_); |
| 285 result->SetBoolean("critical", IsVulnerable()); | 320 result->SetBoolean("critical", IsVulnerable()); |
| 286 | 321 |
| 287 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); | 322 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); |
| 288 ListValue* plugin_files = new ListValue(); | 323 ListValue* plugin_files = new ListValue(); |
| 289 bool all_plugins_disabled_by_policy = true; | 324 bool all_plugins_disabled_by_policy = true; |
| 290 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 325 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 291 const WebPluginInfo& web_plugin = web_plugin_infos_[i]; | |
| 292 int priority = web_plugin_positions_[i]; | |
| 293 DictionaryValue* plugin_file = new DictionaryValue(); | 326 DictionaryValue* plugin_file = new DictionaryValue(); |
| 294 plugin_file->SetString("name", web_plugin.name); | 327 plugin_file->SetString("name", web_plugin_infos_[i].name); |
| 295 plugin_file->SetString("description", web_plugin.desc); | 328 plugin_file->SetString("description", web_plugin_infos_[i].desc); |
| 296 plugin_file->SetString("path", web_plugin.path.value()); | 329 plugin_file->SetString("path", web_plugin_infos_[i].path.value()); |
| 297 plugin_file->SetString("version", web_plugin.version); | 330 plugin_file->SetString("version", web_plugin_infos_[i].version); |
| 298 bool plugin_disabled_by_policy = group_disabled_by_policy || | 331 bool plugin_disabled_by_policy = group_disabled_by_policy || |
| 299 IsPluginNameDisabledByPolicy(web_plugin.name); | 332 ((web_plugin_infos_[i].enabled & WebPluginInfo::POLICY_DISABLED) != 0); |
| 300 if (plugin_disabled_by_policy) { | 333 if (plugin_disabled_by_policy) { |
| 301 plugin_file->SetString("enabledMode", "disabledByPolicy"); | 334 plugin_file->SetString("enabledMode", "disabledByPolicy"); |
| 302 } else { | 335 } else { |
| 303 all_plugins_disabled_by_policy = false; | 336 all_plugins_disabled_by_policy = false; |
| 304 plugin_file->SetString("enabledMode", | 337 plugin_file->SetString( |
| 305 web_plugin.enabled ? "enabled" : "disabledByUser"); | 338 "enabledMode", IsPluginEnabled(web_plugin_infos_[i]) ? |
| 339 "enabled" : "disabledByUser"); | |
| 306 } | 340 } |
| 307 plugin_file->SetInteger("priority", priority); | |
| 308 | 341 |
| 309 ListValue* mime_types = new ListValue(); | 342 ListValue* mime_types = new ListValue(); |
| 310 for (std::vector<WebPluginMimeType>::const_iterator type_it = | 343 const std::vector<WebPluginMimeType>& plugin_mime_types = |
| 311 web_plugin.mime_types.begin(); | 344 web_plugin_infos_[i].mime_types; |
| 312 type_it != web_plugin.mime_types.end(); | 345 for (size_t j = 0; j < plugin_mime_types.size(); ++j) { |
| 313 ++type_it) { | |
| 314 DictionaryValue* mime_type = new DictionaryValue(); | 346 DictionaryValue* mime_type = new DictionaryValue(); |
| 315 mime_type->SetString("mimeType", type_it->mime_type); | 347 mime_type->SetString("mimeType", plugin_mime_types[j].mime_type); |
| 316 mime_type->SetString("description", type_it->description); | 348 mime_type->SetString("description", plugin_mime_types[j].description); |
| 317 | 349 |
| 318 ListValue* file_extensions = new ListValue(); | 350 ListValue* file_extensions = new ListValue(); |
| 319 for (std::vector<std::string>::const_iterator ext_it = | 351 const std::vector<std::string>& mime_file_extensions = |
| 320 type_it->file_extensions.begin(); | 352 plugin_mime_types[j].file_extensions; |
| 321 ext_it != type_it->file_extensions.end(); | 353 for (size_t k = 0; k < mime_file_extensions.size(); ++k) |
| 322 ++ext_it) { | 354 file_extensions->Append(new StringValue(mime_file_extensions[k])); |
| 323 file_extensions->Append(new StringValue(*ext_it)); | |
| 324 } | |
| 325 mime_type->Set("fileExtensions", file_extensions); | 355 mime_type->Set("fileExtensions", file_extensions); |
| 326 | 356 |
| 327 mime_types->Append(mime_type); | 357 mime_types->Append(mime_type); |
| 328 } | 358 } |
| 329 plugin_file->Set("mimeTypes", mime_types); | 359 plugin_file->Set("mimeTypes", mime_types); |
| 330 | 360 |
| 331 plugin_files->Append(plugin_file); | 361 plugin_files->Append(plugin_file); |
| 332 } | 362 } |
| 333 | 363 |
| 334 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { | 364 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 365 | 395 |
| 366 // Returns true if the latest version of this plugin group is vulnerable. | 396 // Returns true if the latest version of this plugin group is vulnerable. |
| 367 bool PluginGroup::IsVulnerable() const { | 397 bool PluginGroup::IsVulnerable() const { |
| 368 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 398 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
| 369 if (IsPluginOutdated(*version_, version_ranges_[i])) | 399 if (IsPluginOutdated(*version_, version_ranges_[i])) |
| 370 return true; | 400 return true; |
| 371 } | 401 } |
| 372 return false; | 402 return false; |
| 373 } | 403 } |
| 374 | 404 |
| 405 bool PluginGroup::IsEmpty() const { | |
| 406 return web_plugin_infos_.size() == 0; | |
| 407 } | |
| 408 | |
| 375 void PluginGroup::DisableOutdatedPlugins() { | 409 void PluginGroup::DisableOutdatedPlugins() { |
| 376 description_ = string16(); | 410 bool first_enabled = true; |
| 377 enabled_ = false; | |
| 378 | 411 |
| 379 for (std::vector<WebPluginInfo>::iterator it = | 412 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 380 web_plugin_infos_.begin(); | 413 scoped_ptr<Version> version( |
| 381 it != web_plugin_infos_.end(); ++it) { | 414 CreateVersionFromString(web_plugin_infos_[i].version)); |
| 382 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | |
| 383 if (version.get()) { | 415 if (version.get()) { |
| 384 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 416 bool plugin_is_outdated = false; |
| 385 if (IsPluginOutdated(*version, version_ranges_[i])) { | 417 for (size_t j = 0; j < version_ranges_.size(); ++j) { |
| 386 it->enabled = false; | 418 if (IsPluginOutdated(*version, version_ranges_[j])) { |
| 387 PluginList::Singleton()->DisablePlugin(it->path); | 419 Disable(&web_plugin_infos_[i], WebPluginInfo::USER_DISABLED); |
| 420 plugin_is_outdated = true; | |
| 421 break; | |
| 388 } | 422 } |
| 389 } | 423 } |
| 424 if (!plugin_is_outdated && first_enabled) { | |
| 425 first_enabled = false; | |
| 426 UpdateDescriptionAndVersion(web_plugin_infos_[i]); | |
| 427 } | |
| 390 } | 428 } |
| 391 UpdateActivePlugin(*it); | |
| 392 } | 429 } |
| 393 } | 430 } |
| 394 | 431 |
| 395 void PluginGroup::Enable(bool enable) { | 432 bool PluginGroup::EnableGroup(bool enable) { |
| 396 bool enabled_plugin_exists = false; | 433 bool enabled_plugin_exists = false; |
| 397 for (std::vector<WebPluginInfo>::iterator it = | 434 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); |
| 398 web_plugin_infos_.begin(); | 435 // We can't enable groups disabled by policy |
| 399 it != web_plugin_infos_.end(); ++it) { | 436 if (group_disabled_by_policy && enable) |
| 400 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 437 return false; |
| 401 PluginList::Singleton()->EnablePlugin(it->path); | 438 |
| 402 it->enabled = true; | 439 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 440 bool policy_disabled = | |
| 441 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name); | |
| 442 if (enable && !policy_disabled) { | |
| 443 Enable(&web_plugin_infos_[i], WebPluginInfo::USER_ENABLED); | |
| 403 enabled_plugin_exists = true; | 444 enabled_plugin_exists = true; |
| 404 } else { | 445 } else { |
| 405 it->enabled = false; | 446 Disable(&web_plugin_infos_[i], |
| 406 PluginList::Singleton()->DisablePlugin(it->path); | 447 policy_disabled || group_disabled_by_policy ? |
| 448 WebPluginInfo::POLICY_DISABLED : | |
| 449 WebPluginInfo::USER_DISABLED); | |
| 450 } | |
| 451 } | |
| 452 enabled_ = enabled_plugin_exists; | |
| 453 return enabled_ == enable; | |
| 454 } | |
| 455 | |
| 456 void PluginGroup::EnforceGroupPolicy() { | |
| 457 bool enabled_plugin_exists = false; | |
| 458 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); | |
| 459 | |
| 460 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | |
| 461 bool policy_disabled = | |
| 462 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) | | |
| 463 group_disabled_by_policy; | |
| 464 | |
| 465 // TODO(pastarmovj): Add the code for enforcing enabled by policy... | |
| 466 if (policy_disabled) { | |
| 467 Disable(&web_plugin_infos_[i], WebPluginInfo::POLICY_DISABLED); | |
| 468 // ...here would a else if (policy_enabled) { ... } be then. | |
| 469 } else { | |
| 470 Enable(&web_plugin_infos_[i], WebPluginInfo::POLICY_UNMANAGED); | |
| 471 if (IsPluginEnabled(web_plugin_infos_[i])) | |
| 472 enabled_plugin_exists = true; | |
| 407 } | 473 } |
| 408 } | 474 } |
| 409 enabled_ = enabled_plugin_exists; | 475 enabled_ = enabled_plugin_exists; |
| 410 } | 476 } |
| 411 | 477 |
| 478 void PluginGroup::RefreshEnabledState() { | |
| 479 bool enabled_plugin_exists = false; | |
| 480 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | |
| 481 if (IsPluginEnabled(web_plugin_infos_[i])) { | |
| 482 enabled_plugin_exists = true; | |
| 483 break; | |
| 484 } | |
| 485 } | |
| 486 enabled_ = enabled_plugin_exists; | |
| 487 } | |
| 488 | |
| 489 bool PluginGroup::Enable(WebPluginInfo* plugin, | |
| 490 int new_reason) { | |
| 491 DCHECK(new_reason == WebPluginInfo::USER_ENABLED || | |
| 492 new_reason == WebPluginInfo::POLICY_UNMANAGED || | |
| 493 new_reason == WebPluginInfo::POLICY_ENABLED); | |
| 494 // If we are only stripping the policy then mask the policy bits. | |
| 495 if (new_reason == WebPluginInfo::POLICY_UNMANAGED) { | |
| 496 plugin->enabled &= WebPluginInfo::USER_MASK; | |
| 497 return true; | |
| 498 } | |
| 499 // If already enabled just upgrade the reason. | |
| 500 if (IsPluginEnabled(*plugin)) { | |
| 501 plugin->enabled |= new_reason; | |
| 502 return true; | |
| 503 } else { | |
| 504 // Only changeable if not managed. | |
| 505 if (plugin->enabled & WebPluginInfo::MANAGED_MASK) | |
| 506 return false; | |
| 507 plugin->enabled = new_reason; | |
| 508 } | |
| 509 return true; | |
| 510 } | |
| 511 | |
| 512 bool PluginGroup::Disable(WebPluginInfo* plugin, | |
| 513 int new_reason) { | |
| 514 DCHECK(new_reason == WebPluginInfo::USER_DISABLED || | |
| 515 new_reason == WebPluginInfo::POLICY_DISABLED); | |
| 516 // If already disabled just upgrade the reason. | |
| 517 if (!IsPluginEnabled(*plugin)) { | |
| 518 plugin->enabled |= new_reason; | |
| 519 return true; | |
| 520 } else { | |
| 521 // Only changeable if not managed. | |
| 522 if (plugin->enabled & WebPluginInfo::MANAGED_MASK) | |
| 523 return false; | |
| 524 plugin->enabled = new_reason; | |
| 525 } | |
| 526 return true; | |
| 527 } | |
| 528 | |
| 412 } // namespace npapi | 529 } // namespace npapi |
| 413 } // namespace webkit | 530 } // namespace webkit |
| OLD | NEW |