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