| 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 30 matching lines...) Expand all Loading... |
| 159 #endif | 143 #endif |
| 160 } | 144 } |
| 161 | 145 |
| 162 /*static*/ | 146 /*static*/ |
| 163 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { | 147 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { |
| 164 // Create a matcher from the name of this plugin. | 148 // Create a matcher from the name of this plugin. |
| 165 return new PluginGroup(wpi.name, wpi.name, std::string(), | 149 return new PluginGroup(wpi.name, wpi.name, std::string(), |
| 166 GetIdentifier(wpi)); | 150 GetIdentifier(wpi)); |
| 167 } | 151 } |
| 168 | 152 |
| 153 /*static*/ |
| 154 PluginGroup* PluginGroup::CreateEmptyGroup(const string16& name) { |
| 155 // Create a matcher from the name of this plugin. |
| 156 return new PluginGroup(name, name, std::string(), std::string()); |
| 157 } |
| 158 |
| 169 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 159 bool PluginGroup::Match(const WebPluginInfo& plugin) const { |
| 170 if (name_matcher_.empty()) { | 160 if (name_matcher_.empty()) { |
| 171 return false; | 161 return false; |
| 172 } | 162 } |
| 173 | 163 |
| 174 // Look for the name matcher anywhere in the plugin name. | 164 // Look for the name matcher anywhere in the plugin name. |
| 175 if (plugin.name.find(name_matcher_) == string16::npos) { | 165 if (plugin.name.find(name_matcher_) == string16::npos) { |
| 176 return false; | 166 return false; |
| 177 } | 167 } |
| 178 | 168 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 206 std::replace(version.begin(), version.end(), 'r', '.'); | 196 std::replace(version.begin(), version.end(), 'r', '.'); |
| 207 std::replace(version.begin(), version.end(), ',', '.'); | 197 std::replace(version.begin(), version.end(), ',', '.'); |
| 208 std::replace(version.begin(), version.end(), '(', '.'); | 198 std::replace(version.begin(), version.end(), '(', '.'); |
| 209 std::replace(version.begin(), version.end(), '_', '.'); | 199 std::replace(version.begin(), version.end(), '_', '.'); |
| 210 | 200 |
| 211 return Version::GetVersionFromString(WideToASCII(version)); | 201 return Version::GetVersionFromString(WideToASCII(version)); |
| 212 } | 202 } |
| 213 | 203 |
| 214 void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) { | 204 void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) { |
| 215 // A group is enabled if any of the files are enabled. | 205 // A group is enabled if any of the files are enabled. |
| 216 if (plugin.enabled) { | 206 if (IsPluginEnabled(plugin)) { |
| 217 if (!enabled_) { | 207 if (!enabled_ || description_.empty()) { |
| 218 // If this is the first enabled plugin, use its description. | 208 // If this is the first enabled plugin, use its description. |
| 219 enabled_ = true; | 209 enabled_ = true; |
| 220 UpdateDescriptionAndVersion(plugin); | 210 UpdateDescriptionAndVersion(plugin); |
| 221 } | 211 } |
| 222 } else { | 212 } else { |
| 223 // If this is the first plugin and it's disabled, | 213 // If this is the first plugin and it's disabled, |
| 224 // use its description for now. | 214 // use its description for now. |
| 225 if (description_.empty()) | 215 if (description_.empty()) |
| 226 UpdateDescriptionAndVersion(plugin); | 216 UpdateDescriptionAndVersion(plugin); |
| 227 } | 217 } |
| 228 } | 218 } |
| 229 | 219 |
| 230 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 220 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
| 231 description_ = plugin.desc; | 221 description_ = plugin.desc; |
| 232 if (Version* new_version = CreateVersionFromString(plugin.version)) | 222 if (Version* new_version = CreateVersionFromString(plugin.version)) |
| 233 version_.reset(new_version); | 223 version_.reset(new_version); |
| 234 else | 224 else |
| 235 version_.reset(Version::GetVersionFromString("0")); | 225 version_.reset(Version::GetVersionFromString("0")); |
| 236 } | 226 } |
| 237 | 227 |
| 238 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 228 bool PluginGroup::AddPlugin(const WebPluginInfo& plugin, int priority) { |
| 239 // Check if this group already contains this plugin. | 229 // Check if this group already contains this plugin. |
| 240 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 230 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 241 if (web_plugin_infos_[i].name == plugin.name && | 231 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())) { | 232 plugin.path.value())) { |
| 245 return; | 233 return false; |
| 246 } | 234 } |
| 247 } | 235 } |
| 248 web_plugin_infos_.push_back(plugin); | 236 web_plugin_infos_.push_back(plugin); |
| 249 // The position of this plugin relative to the global list of plugins. | 237 // If the group is disabled disable new plugins in it too. This should cover |
| 250 web_plugin_positions_.push_back(position); | 238 // the case where a plugin has been upgraded that has been disabled and should |
| 251 UpdateActivePlugin(plugin); | 239 // stay disabled after the upgrade. |
| 240 if (!enabled_) |
| 241 DisablePlugin(web_plugin_infos_.back().path); |
| 242 UpdateActivePlugin(web_plugin_infos_.back()); |
| 243 RefreshEnabledState(); |
| 244 return true; |
| 252 } | 245 } |
| 253 | 246 |
| 254 bool PluginGroup::IsEmpty() const { | 247 bool PluginGroup::RemovePlugin(const FilePath& filename) { |
| 255 return web_plugin_infos_.empty(); | 248 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 249 if (web_plugin_infos_[i].path == filename) { |
| 250 web_plugin_infos_.erase(web_plugin_infos_.begin() + i); |
| 251 return true; |
| 252 } |
| 253 } |
| 254 return false; |
| 255 } |
| 256 |
| 257 bool PluginGroup::EnablePlugin(const FilePath& filename) { |
| 258 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 259 if (web_plugin_infos_[i].path == filename) { |
| 260 bool did_enable = Enable(&web_plugin_infos_[i], |
| 261 WebPluginInfo::USER_ENABLED); |
| 262 RefreshEnabledState(); |
| 263 return did_enable; |
| 264 } |
| 265 } |
| 266 return false; |
| 267 } |
| 268 |
| 269 bool PluginGroup::DisablePlugin(const FilePath& filename) { |
| 270 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 271 if (web_plugin_infos_[i].path == filename) { |
| 272 // We are only called for user intervention however we should respect a |
| 273 // policy that might as well be active on this plugin. |
| 274 bool did_disable = Disable( |
| 275 &web_plugin_infos_[i], |
| 276 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) ? |
| 277 WebPluginInfo::USER_DISABLED_POLICY_DISABLED : |
| 278 WebPluginInfo::USER_DISABLED); |
| 279 RefreshEnabledState(); |
| 280 return did_disable; |
| 281 } |
| 282 } |
| 283 return false; |
| 256 } | 284 } |
| 257 | 285 |
| 258 string16 PluginGroup::GetGroupName() const { | 286 string16 PluginGroup::GetGroupName() const { |
| 259 if (!group_name_.empty()) | 287 if (!group_name_.empty()) |
| 260 return group_name_; | 288 return group_name_; |
| 261 DCHECK_EQ(1u, web_plugin_infos_.size()); | 289 DCHECK_EQ(1u, web_plugin_infos_.size()); |
| 262 FilePath::StringType path = | 290 FilePath::StringType path = |
| 263 web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); | 291 web_plugin_infos_.front().path.BaseName().RemoveExtension().value(); |
| 264 #if defined(OS_POSIX) | 292 #if defined(OS_POSIX) |
| 265 return UTF8ToUTF16(path); | 293 return UTF8ToUTF16(path); |
| 266 #elif defined(OS_WIN) | 294 #elif defined(OS_WIN) |
| 267 return WideToUTF16(path); | 295 return WideToUTF16(path); |
| 268 #endif | 296 #endif |
| 269 } | 297 } |
| 270 | 298 |
| 299 const std::vector<WebPluginInfo>& PluginGroup::GetPlugins() 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 // If already disabled just upgrade the reason. |
| 523 if (!IsPluginEnabled(*plugin)) { |
| 524 plugin->enabled |= new_reason; |
| 525 return true; |
| 526 } else { |
| 527 // Only changeable if not managed. |
| 528 if (plugin->enabled & WebPluginInfo::MANAGED_MASK) |
| 529 return false; |
| 530 plugin->enabled = new_reason; |
| 531 } |
| 532 return true; |
| 533 } |
| 534 |
| 412 } // namespace npapi | 535 } // namespace npapi |
| 413 } // namespace webkit | 536 } // namespace webkit |
| OLD | NEW |