| 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 // The description of the group needs update either when it's state is |
| 218 // If this is the first enabled plugin, use its description. | 202 // about to change to enabled or if has never been set. |
| 203 if (!enabled_ || description_.empty()) |
| 204 UpdateDescriptionAndVersion(plugin); |
| 205 // In case an enabled plugin has been added to a group that is currently |
| 206 // disabled then we should enable the group. |
| 207 if (!enabled_) |
| 219 enabled_ = true; | 208 enabled_ = true; |
| 220 UpdateDescriptionAndVersion(plugin); | |
| 221 } | |
| 222 } else { | 209 } else { |
| 223 // If this is the first plugin and it's disabled, | 210 // If this is the first plugin and it's disabled, |
| 224 // use its description for now. | 211 // use its description for now. |
| 225 if (description_.empty()) | 212 if (description_.empty()) |
| 226 UpdateDescriptionAndVersion(plugin); | 213 UpdateDescriptionAndVersion(plugin); |
| 227 } | 214 } |
| 228 } | 215 } |
| 229 | 216 |
| 230 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 217 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
| 231 description_ = plugin.desc; | 218 description_ = plugin.desc; |
| 232 if (Version* new_version = CreateVersionFromString(plugin.version)) | 219 if (Version* new_version = CreateVersionFromString(plugin.version)) |
| 233 version_.reset(new_version); | 220 version_.reset(new_version); |
| 234 else | 221 else |
| 235 version_.reset(Version::GetVersionFromString("0")); | 222 version_.reset(Version::GetVersionFromString("0")); |
| 236 } | 223 } |
| 237 | 224 |
| 238 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 225 void PluginGroup::AddPlugin(const WebPluginInfo& plugin) { |
| 239 // Check if this group already contains this plugin. | 226 // Check if this group already contains this plugin. |
| 240 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 227 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 241 if (web_plugin_infos_[i].name == plugin.name && | 228 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())) { | 229 plugin.path.value())) { |
| 245 return; | 230 return; |
| 246 } | 231 } |
| 247 } | 232 } |
| 248 web_plugin_infos_.push_back(plugin); | 233 web_plugin_infos_.push_back(plugin); |
| 249 // The position of this plugin relative to the global list of plugins. | 234 // If the group is disabled disable new plugins in it too. This should cover |
| 250 web_plugin_positions_.push_back(position); | 235 // the case where a plugin has been upgraded that has been disabled and should |
| 251 UpdateActivePlugin(plugin); | 236 // stay disabled after the upgrade. |
| 237 if (!enabled_) |
| 238 DisablePlugin(web_plugin_infos_.back().path); |
| 239 UpdateActivePlugin(web_plugin_infos_.back()); |
| 240 RefreshEnabledState(); |
| 252 } | 241 } |
| 253 | 242 |
| 254 bool PluginGroup::IsEmpty() const { | 243 bool PluginGroup::RemovePlugin(const FilePath& filename) { |
| 255 return web_plugin_infos_.empty(); | 244 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 245 if (web_plugin_infos_[i].path == filename) { |
| 246 web_plugin_infos_.erase(web_plugin_infos_.begin() + i); |
| 247 return true; |
| 248 } |
| 249 } |
| 250 return false; |
| 251 } |
| 252 |
| 253 bool PluginGroup::EnablePlugin(const FilePath& filename) { |
| 254 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 255 if (web_plugin_infos_[i].path == filename) { |
| 256 bool did_enable = Enable(&web_plugin_infos_[i], |
| 257 WebPluginInfo::USER_ENABLED); |
| 258 RefreshEnabledState(); |
| 259 return did_enable; |
| 260 } |
| 261 } |
| 262 return false; |
| 263 } |
| 264 |
| 265 bool PluginGroup::DisablePlugin(const FilePath& filename) { |
| 266 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 267 if (web_plugin_infos_[i].path == filename) { |
| 268 // We are only called for user intervention however we should respect a |
| 269 // policy that might as well be active on this plugin. |
| 270 bool did_disable = Disable( |
| 271 &web_plugin_infos_[i], |
| 272 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) ? |
| 273 WebPluginInfo::USER_DISABLED_POLICY_DISABLED : |
| 274 WebPluginInfo::USER_DISABLED); |
| 275 RefreshEnabledState(); |
| 276 return did_disable; |
| 277 } |
| 278 } |
| 279 return false; |
| 256 } | 280 } |
| 257 | 281 |
| 258 string16 PluginGroup::GetGroupName() const { | 282 string16 PluginGroup::GetGroupName() const { |
| 259 if (!group_name_.empty()) | 283 if (!group_name_.empty()) |
| 260 return group_name_; | 284 return group_name_; |
| 261 DCHECK_EQ(1u, web_plugin_infos_.size()); | 285 DCHECK_EQ(1u, web_plugin_infos_.size()); |
| 262 FilePath::StringType path = | 286 FilePath::StringType path = |
| 263 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); | 287 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); |
| 264 #if defined(OS_POSIX) | 288 #if defined(OS_POSIX) |
| 265 return UTF8ToUTF16(path); | 289 return UTF8ToUTF16(path); |
| 266 #elif defined(OS_WIN) | 290 #elif defined(OS_WIN) |
| 267 return WideToUTF16(path); | 291 return WideToUTF16(path); |
| 268 #endif | 292 #endif |
| 269 } | 293 } |
| 270 | 294 |
| 295 std::vector<WebPluginInfo>& PluginGroup::web_info_plugins() { |
| 296 return web_plugin_infos_; |
| 297 } |
| 298 |
| 299 const std::vector<WebPluginInfo>& PluginGroup::web_info_plugins() const { |
| 300 return web_plugin_infos_; |
| 301 } |
| 302 |
| 303 bool PluginGroup::ContainsPlugin(const FilePath& path) const { |
| 304 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 305 if (web_plugin_infos_[i].path == path) |
| 306 return true; |
| 307 } |
| 308 return false; |
| 309 } |
| 310 |
| 311 |
| 271 DictionaryValue* PluginGroup::GetSummary() const { | 312 DictionaryValue* PluginGroup::GetSummary() const { |
| 272 DictionaryValue* result = new DictionaryValue(); | 313 DictionaryValue* result = new DictionaryValue(); |
| 273 result->SetString("name", GetGroupName()); | 314 result->SetString("name", GetGroupName()); |
| 274 result->SetBoolean("enabled", enabled_); | 315 result->SetBoolean("enabled", enabled_); |
| 275 return result; | 316 return result; |
| 276 } | 317 } |
| 277 | 318 |
| 278 DictionaryValue* PluginGroup::GetDataForUI() const { | 319 DictionaryValue* PluginGroup::GetDataForUI() const { |
| 279 string16 name = GetGroupName(); | 320 string16 name = GetGroupName(); |
| 280 DictionaryValue* result = new DictionaryValue(); | 321 DictionaryValue* result = new DictionaryValue(); |
| 281 result->SetString("name", name); | 322 result->SetString("name", name); |
| 282 result->SetString("description", description_); | 323 result->SetString("description", description_); |
| 283 result->SetString("version", version_->GetString()); | 324 result->SetString("version", version_->GetString()); |
| 284 result->SetString("update_url", update_url_); | 325 result->SetString("update_url", update_url_); |
| 285 result->SetBoolean("critical", IsVulnerable()); | 326 result->SetBoolean("critical", IsVulnerable()); |
| 286 | 327 |
| 287 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); | 328 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); |
| 288 ListValue* plugin_files = new ListValue(); | 329 ListValue* plugin_files = new ListValue(); |
| 289 bool all_plugins_disabled_by_policy = true; | 330 bool all_plugins_disabled_by_policy = true; |
| 290 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 331 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(); | 332 DictionaryValue* plugin_file = new DictionaryValue(); |
| 294 plugin_file->SetString("name", web_plugin.name); | 333 plugin_file->SetString("name", web_plugin_infos_[i].name); |
| 295 plugin_file->SetString("description", web_plugin.desc); | 334 plugin_file->SetString("description", web_plugin_infos_[i].desc); |
| 296 plugin_file->SetString("path", web_plugin.path.value()); | 335 plugin_file->SetString("path", web_plugin_infos_[i].path.value()); |
| 297 plugin_file->SetString("version", web_plugin.version); | 336 plugin_file->SetString("version", web_plugin_infos_[i].version); |
| 298 bool plugin_disabled_by_policy = group_disabled_by_policy || | 337 bool plugin_disabled_by_policy = group_disabled_by_policy || |
| 299 IsPluginNameDisabledByPolicy(web_plugin.name); | 338 ((web_plugin_infos_[i].enabled & WebPluginInfo::POLICY_DISABLED) != 0); |
| 300 if (plugin_disabled_by_policy) { | 339 if (plugin_disabled_by_policy) { |
| 301 plugin_file->SetString("enabledMode", "disabledByPolicy"); | 340 plugin_file->SetString("enabledMode", "disabledByPolicy"); |
| 302 } else { | 341 } else { |
| 303 all_plugins_disabled_by_policy = false; | 342 all_plugins_disabled_by_policy = false; |
| 304 plugin_file->SetString("enabledMode", | 343 plugin_file->SetString( |
| 305 web_plugin.enabled ? "enabled" : "disabledByUser"); | 344 "enabledMode", IsPluginEnabled(web_plugin_infos_[i]) ? |
| 345 "enabled" : "disabledByUser"); |
| 306 } | 346 } |
| 307 plugin_file->SetInteger("priority", priority); | |
| 308 | 347 |
| 309 ListValue* mime_types = new ListValue(); | 348 ListValue* mime_types = new ListValue(); |
| 310 for (std::vector<WebPluginMimeType>::const_iterator type_it = | 349 const std::vector<WebPluginMimeType>& plugin_mime_types = |
| 311 web_plugin.mime_types.begin(); | 350 web_plugin_infos_[i].mime_types; |
| 312 type_it != web_plugin.mime_types.end(); | 351 for (size_t j = 0; j < plugin_mime_types.size(); ++j) { |
| 313 ++type_it) { | |
| 314 DictionaryValue* mime_type = new DictionaryValue(); | 352 DictionaryValue* mime_type = new DictionaryValue(); |
| 315 mime_type->SetString("mimeType", type_it->mime_type); | 353 mime_type->SetString("mimeType", plugin_mime_types[j].mime_type); |
| 316 mime_type->SetString("description", type_it->description); | 354 mime_type->SetString("description", plugin_mime_types[j].description); |
| 317 | 355 |
| 318 ListValue* file_extensions = new ListValue(); | 356 ListValue* file_extensions = new ListValue(); |
| 319 for (std::vector<std::string>::const_iterator ext_it = | 357 const std::vector<std::string>& mime_file_extensions = |
| 320 type_it->file_extensions.begin(); | 358 plugin_mime_types[j].file_extensions; |
| 321 ext_it != type_it->file_extensions.end(); | 359 for (size_t k = 0; k < mime_file_extensions.size(); ++k) |
| 322 ++ext_it) { | 360 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); | 361 mime_type->Set("fileExtensions", file_extensions); |
| 326 | 362 |
| 327 mime_types->Append(mime_type); | 363 mime_types->Append(mime_type); |
| 328 } | 364 } |
| 329 plugin_file->Set("mimeTypes", mime_types); | 365 plugin_file->Set("mimeTypes", mime_types); |
| 330 | 366 |
| 331 plugin_files->Append(plugin_file); | 367 plugin_files->Append(plugin_file); |
| 332 } | 368 } |
| 333 | 369 |
| 334 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { | 370 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 365 | 401 |
| 366 // Returns true if the latest version of this plugin group is vulnerable. | 402 // Returns true if the latest version of this plugin group is vulnerable. |
| 367 bool PluginGroup::IsVulnerable() const { | 403 bool PluginGroup::IsVulnerable() const { |
| 368 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 404 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
| 369 if (IsPluginOutdated(*version_, version_ranges_[i])) | 405 if (IsPluginOutdated(*version_, version_ranges_[i])) |
| 370 return true; | 406 return true; |
| 371 } | 407 } |
| 372 return false; | 408 return false; |
| 373 } | 409 } |
| 374 | 410 |
| 411 bool PluginGroup::IsEmpty() const { |
| 412 return web_plugin_infos_.size() == 0; |
| 413 } |
| 414 |
| 375 void PluginGroup::DisableOutdatedPlugins() { | 415 void PluginGroup::DisableOutdatedPlugins() { |
| 376 description_ = string16(); | 416 bool first_enabled = true; |
| 377 enabled_ = false; | |
| 378 | 417 |
| 379 for (std::vector<WebPluginInfo>::iterator it = | 418 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 380 web_plugin_infos_.begin(); | 419 scoped_ptr<Version> version( |
| 381 it != web_plugin_infos_.end(); ++it) { | 420 CreateVersionFromString(web_plugin_infos_[i].version)); |
| 382 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | |
| 383 if (version.get()) { | 421 if (version.get()) { |
| 384 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 422 bool plugin_is_outdated = false; |
| 385 if (IsPluginOutdated(*version, version_ranges_[i])) { | 423 for (size_t j = 0; j < version_ranges_.size(); ++j) { |
| 386 it->enabled = false; | 424 if (IsPluginOutdated(*version, version_ranges_[j])) { |
| 387 PluginList::Singleton()->DisablePlugin(it->path); | 425 Disable(&web_plugin_infos_[i], WebPluginInfo::USER_DISABLED); |
| 426 plugin_is_outdated = true; |
| 427 break; |
| 388 } | 428 } |
| 389 } | 429 } |
| 430 if (!plugin_is_outdated && first_enabled) { |
| 431 first_enabled = false; |
| 432 UpdateDescriptionAndVersion(web_plugin_infos_[i]); |
| 433 } |
| 390 } | 434 } |
| 391 UpdateActivePlugin(*it); | |
| 392 } | 435 } |
| 393 } | 436 } |
| 394 | 437 |
| 395 void PluginGroup::Enable(bool enable) { | 438 bool PluginGroup::EnableGroup(bool enable) { |
| 396 bool enabled_plugin_exists = false; | 439 bool enabled_plugin_exists = false; |
| 397 for (std::vector<WebPluginInfo>::iterator it = | 440 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); |
| 398 web_plugin_infos_.begin(); | 441 // We can't enable groups disabled by policy |
| 399 it != web_plugin_infos_.end(); ++it) { | 442 if (group_disabled_by_policy && enable) |
| 400 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 443 return false; |
| 401 PluginList::Singleton()->EnablePlugin(it->path); | 444 |
| 402 it->enabled = true; | 445 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 446 bool policy_disabled = |
| 447 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name); |
| 448 if (enable && !policy_disabled) { |
| 449 Enable(&web_plugin_infos_[i], WebPluginInfo::USER_ENABLED); |
| 403 enabled_plugin_exists = true; | 450 enabled_plugin_exists = true; |
| 404 } else { | 451 } else { |
| 405 it->enabled = false; | 452 Disable(&web_plugin_infos_[i], |
| 406 PluginList::Singleton()->DisablePlugin(it->path); | 453 policy_disabled || group_disabled_by_policy ? |
| 454 WebPluginInfo::POLICY_DISABLED : |
| 455 WebPluginInfo::USER_DISABLED); |
| 456 } |
| 457 } |
| 458 enabled_ = enabled_plugin_exists; |
| 459 return enabled_ == enable; |
| 460 } |
| 461 |
| 462 void PluginGroup::EnforceGroupPolicy() { |
| 463 bool enabled_plugin_exists = false; |
| 464 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); |
| 465 |
| 466 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 467 bool policy_disabled = |
| 468 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) | |
| 469 group_disabled_by_policy; |
| 470 |
| 471 // TODO(pastarmovj): Add the code for enforcing enabled by policy... |
| 472 if (policy_disabled) { |
| 473 Disable(&web_plugin_infos_[i], WebPluginInfo::POLICY_DISABLED); |
| 474 // ...here would a else if (policy_enabled) { ... } be then. |
| 475 } else { |
| 476 Enable(&web_plugin_infos_[i], WebPluginInfo::POLICY_UNMANAGED); |
| 477 if (IsPluginEnabled(web_plugin_infos_[i])) |
| 478 enabled_plugin_exists = true; |
| 407 } | 479 } |
| 408 } | 480 } |
| 409 enabled_ = enabled_plugin_exists; | 481 enabled_ = enabled_plugin_exists; |
| 410 } | 482 } |
| 411 | 483 |
| 484 void PluginGroup::RefreshEnabledState() { |
| 485 bool enabled_plugin_exists = false; |
| 486 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 487 if (IsPluginEnabled(web_plugin_infos_[i])) { |
| 488 enabled_plugin_exists = true; |
| 489 break; |
| 490 } |
| 491 } |
| 492 enabled_ = enabled_plugin_exists; |
| 493 } |
| 494 |
| 495 bool PluginGroup::Enable(WebPluginInfo* plugin, |
| 496 int new_reason) { |
| 497 DCHECK(new_reason == WebPluginInfo::USER_ENABLED || |
| 498 new_reason == WebPluginInfo::POLICY_UNMANAGED || |
| 499 new_reason == WebPluginInfo::POLICY_ENABLED); |
| 500 // If we are only stripping the policy then mask the policy bits. |
| 501 if (new_reason == WebPluginInfo::POLICY_UNMANAGED) { |
| 502 plugin->enabled &= WebPluginInfo::USER_MASK; |
| 503 return true; |
| 504 } |
| 505 // If already enabled just upgrade the reason. |
| 506 if (IsPluginEnabled(*plugin)) { |
| 507 plugin->enabled |= new_reason; |
| 508 return true; |
| 509 } else { |
| 510 // Only changeable if not managed. |
| 511 if (plugin->enabled & WebPluginInfo::MANAGED_MASK) |
| 512 return false; |
| 513 plugin->enabled = new_reason; |
| 514 } |
| 515 return true; |
| 516 } |
| 517 |
| 518 bool PluginGroup::Disable(WebPluginInfo* plugin, |
| 519 int new_reason) { |
| 520 DCHECK(new_reason == WebPluginInfo::USER_DISABLED || |
| 521 new_reason == WebPluginInfo::POLICY_DISABLED || |
| 522 new_reason == WebPluginInfo::USER_DISABLED_POLICY_DISABLED); |
| 523 // If already disabled just upgrade the reason. |
| 524 if (!IsPluginEnabled(*plugin)) { |
| 525 plugin->enabled |= new_reason; |
| 526 return true; |
| 527 } else { |
| 528 // Only changeable if not managed. |
| 529 if (plugin->enabled & WebPluginInfo::MANAGED_MASK) |
| 530 return false; |
| 531 plugin->enabled = new_reason; |
| 532 } |
| 533 return true; |
| 534 } |
| 535 |
| 412 } // namespace npapi | 536 } // namespace npapi |
| 413 } // namespace webkit | 537 } // namespace webkit |
| OLD | NEW |