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 bool PluginGroup::ContainsPlugin(const FilePath& path) const { |
| 296 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 297 if (web_plugin_infos_[i].path == path) |
| 298 return true; |
| 299 } |
| 300 return false; |
| 301 } |
| 302 |
| 303 |
271 DictionaryValue* PluginGroup::GetSummary() const { | 304 DictionaryValue* PluginGroup::GetSummary() const { |
272 DictionaryValue* result = new DictionaryValue(); | 305 DictionaryValue* result = new DictionaryValue(); |
273 result->SetString("name", GetGroupName()); | 306 result->SetString("name", GetGroupName()); |
274 result->SetBoolean("enabled", enabled_); | 307 result->SetBoolean("enabled", enabled_); |
275 return result; | 308 return result; |
276 } | 309 } |
277 | 310 |
278 DictionaryValue* PluginGroup::GetDataForUI() const { | 311 DictionaryValue* PluginGroup::GetDataForUI() const { |
279 string16 name = GetGroupName(); | 312 string16 name = GetGroupName(); |
280 DictionaryValue* result = new DictionaryValue(); | 313 DictionaryValue* result = new DictionaryValue(); |
281 result->SetString("name", name); | 314 result->SetString("name", name); |
282 result->SetString("description", description_); | 315 result->SetString("description", description_); |
283 result->SetString("version", version_->GetString()); | 316 result->SetString("version", version_->GetString()); |
284 result->SetString("update_url", update_url_); | 317 result->SetString("update_url", update_url_); |
285 result->SetBoolean("critical", IsVulnerable()); | 318 result->SetBoolean("critical", IsVulnerable()); |
286 | 319 |
287 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); | 320 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); |
288 ListValue* plugin_files = new ListValue(); | 321 ListValue* plugin_files = new ListValue(); |
289 bool all_plugins_disabled_by_policy = true; | 322 bool all_plugins_disabled_by_policy = true; |
290 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | 323 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(); | 324 DictionaryValue* plugin_file = new DictionaryValue(); |
294 plugin_file->SetString("name", web_plugin.name); | 325 plugin_file->SetString("name", web_plugin_infos_[i].name); |
295 plugin_file->SetString("description", web_plugin.desc); | 326 plugin_file->SetString("description", web_plugin_infos_[i].desc); |
296 plugin_file->SetString("path", web_plugin.path.value()); | 327 plugin_file->SetString("path", web_plugin_infos_[i].path.value()); |
297 plugin_file->SetString("version", web_plugin.version); | 328 plugin_file->SetString("version", web_plugin_infos_[i].version); |
298 bool plugin_disabled_by_policy = group_disabled_by_policy || | 329 bool plugin_disabled_by_policy = group_disabled_by_policy || |
299 IsPluginNameDisabledByPolicy(web_plugin.name); | 330 ((web_plugin_infos_[i].enabled & WebPluginInfo::POLICY_DISABLED) != 0); |
300 if (plugin_disabled_by_policy) { | 331 if (plugin_disabled_by_policy) { |
301 plugin_file->SetString("enabledMode", "disabledByPolicy"); | 332 plugin_file->SetString("enabledMode", "disabledByPolicy"); |
302 } else { | 333 } else { |
303 all_plugins_disabled_by_policy = false; | 334 all_plugins_disabled_by_policy = false; |
304 plugin_file->SetString("enabledMode", | 335 plugin_file->SetString( |
305 web_plugin.enabled ? "enabled" : "disabledByUser"); | 336 "enabledMode", IsPluginEnabled(web_plugin_infos_[i]) ? |
| 337 "enabled" : "disabledByUser"); |
306 } | 338 } |
307 plugin_file->SetInteger("priority", priority); | |
308 | 339 |
309 ListValue* mime_types = new ListValue(); | 340 ListValue* mime_types = new ListValue(); |
310 for (std::vector<WebPluginMimeType>::const_iterator type_it = | 341 const std::vector<WebPluginMimeType>& plugin_mime_types = |
311 web_plugin.mime_types.begin(); | 342 web_plugin_infos_[i].mime_types; |
312 type_it != web_plugin.mime_types.end(); | 343 for (size_t j = 0; j < plugin_mime_types.size(); ++j) { |
313 ++type_it) { | |
314 DictionaryValue* mime_type = new DictionaryValue(); | 344 DictionaryValue* mime_type = new DictionaryValue(); |
315 mime_type->SetString("mimeType", type_it->mime_type); | 345 mime_type->SetString("mimeType", plugin_mime_types[j].mime_type); |
316 mime_type->SetString("description", type_it->description); | 346 mime_type->SetString("description", plugin_mime_types[j].description); |
317 | 347 |
318 ListValue* file_extensions = new ListValue(); | 348 ListValue* file_extensions = new ListValue(); |
319 for (std::vector<std::string>::const_iterator ext_it = | 349 const std::vector<std::string>& mime_file_extensions = |
320 type_it->file_extensions.begin(); | 350 plugin_mime_types[j].file_extensions; |
321 ext_it != type_it->file_extensions.end(); | 351 for (size_t k = 0; k < mime_file_extensions.size(); ++k) |
322 ++ext_it) { | 352 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); | 353 mime_type->Set("fileExtensions", file_extensions); |
326 | 354 |
327 mime_types->Append(mime_type); | 355 mime_types->Append(mime_type); |
328 } | 356 } |
329 plugin_file->Set("mimeTypes", mime_types); | 357 plugin_file->Set("mimeTypes", mime_types); |
330 | 358 |
331 plugin_files->Append(plugin_file); | 359 plugin_files->Append(plugin_file); |
332 } | 360 } |
333 | 361 |
334 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { | 362 if (group_disabled_by_policy || all_plugins_disabled_by_policy) { |
(...skipping 30 matching lines...) Expand all Loading... |
365 | 393 |
366 // Returns true if the latest version of this plugin group is vulnerable. | 394 // Returns true if the latest version of this plugin group is vulnerable. |
367 bool PluginGroup::IsVulnerable() const { | 395 bool PluginGroup::IsVulnerable() const { |
368 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 396 for (size_t i = 0; i < version_ranges_.size(); ++i) { |
369 if (IsPluginOutdated(*version_, version_ranges_[i])) | 397 if (IsPluginOutdated(*version_, version_ranges_[i])) |
370 return true; | 398 return true; |
371 } | 399 } |
372 return false; | 400 return false; |
373 } | 401 } |
374 | 402 |
| 403 bool PluginGroup::IsEmpty() const { |
| 404 return web_plugin_infos_.size() == 0; |
| 405 } |
| 406 |
375 void PluginGroup::DisableOutdatedPlugins() { | 407 void PluginGroup::DisableOutdatedPlugins() { |
376 description_ = string16(); | 408 bool first_enabled = true; |
377 enabled_ = false; | |
378 | 409 |
379 for (std::vector<WebPluginInfo>::iterator it = | 410 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
380 web_plugin_infos_.begin(); | 411 scoped_ptr<Version> version( |
381 it != web_plugin_infos_.end(); ++it) { | 412 CreateVersionFromString(web_plugin_infos_[i].version)); |
382 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | |
383 if (version.get()) { | 413 if (version.get()) { |
384 for (size_t i = 0; i < version_ranges_.size(); ++i) { | 414 bool plugin_is_outdated = false; |
385 if (IsPluginOutdated(*version, version_ranges_[i])) { | 415 for (size_t j = 0; j < version_ranges_.size(); ++j) { |
386 it->enabled = false; | 416 if (IsPluginOutdated(*version, version_ranges_[j])) { |
387 PluginList::Singleton()->DisablePlugin(it->path); | 417 Disable(&web_plugin_infos_[i], WebPluginInfo::USER_DISABLED); |
| 418 plugin_is_outdated = true; |
| 419 break; |
388 } | 420 } |
389 } | 421 } |
| 422 if (!plugin_is_outdated && first_enabled) { |
| 423 first_enabled = false; |
| 424 UpdateDescriptionAndVersion(web_plugin_infos_[i]); |
| 425 } |
390 } | 426 } |
391 UpdateActivePlugin(*it); | |
392 } | 427 } |
393 } | 428 } |
394 | 429 |
395 void PluginGroup::Enable(bool enable) { | 430 bool PluginGroup::EnableGroup(bool enable) { |
396 bool enabled_plugin_exists = false; | 431 bool enabled_plugin_exists = false; |
397 for (std::vector<WebPluginInfo>::iterator it = | 432 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); |
398 web_plugin_infos_.begin(); | 433 // We can't enable groups disabled by policy |
399 it != web_plugin_infos_.end(); ++it) { | 434 if (group_disabled_by_policy && enable) |
400 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 435 return false; |
401 PluginList::Singleton()->EnablePlugin(it->path); | 436 |
402 it->enabled = true; | 437 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 438 bool policy_disabled = |
| 439 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name); |
| 440 if (enable && !policy_disabled) { |
| 441 Enable(&web_plugin_infos_[i], WebPluginInfo::USER_ENABLED); |
403 enabled_plugin_exists = true; | 442 enabled_plugin_exists = true; |
404 } else { | 443 } else { |
405 it->enabled = false; | 444 Disable(&web_plugin_infos_[i], |
406 PluginList::Singleton()->DisablePlugin(it->path); | 445 policy_disabled || group_disabled_by_policy ? |
| 446 WebPluginInfo::POLICY_DISABLED : |
| 447 WebPluginInfo::USER_DISABLED); |
| 448 } |
| 449 } |
| 450 enabled_ = enabled_plugin_exists; |
| 451 return enabled_ == enable; |
| 452 } |
| 453 |
| 454 void PluginGroup::EnforceGroupPolicy() { |
| 455 bool enabled_plugin_exists = false; |
| 456 bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_); |
| 457 |
| 458 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 459 bool policy_disabled = |
| 460 IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) | |
| 461 group_disabled_by_policy; |
| 462 |
| 463 // TODO(pastarmovj): Add the code for enforcing enabled by policy... |
| 464 if (policy_disabled) { |
| 465 Disable(&web_plugin_infos_[i], WebPluginInfo::POLICY_DISABLED); |
| 466 // ...here would a else if (policy_enabled) { ... } be then. |
| 467 } else { |
| 468 Enable(&web_plugin_infos_[i], WebPluginInfo::POLICY_UNMANAGED); |
| 469 if (IsPluginEnabled(web_plugin_infos_[i])) |
| 470 enabled_plugin_exists = true; |
407 } | 471 } |
408 } | 472 } |
409 enabled_ = enabled_plugin_exists; | 473 enabled_ = enabled_plugin_exists; |
410 } | 474 } |
411 | 475 |
| 476 void PluginGroup::RefreshEnabledState() { |
| 477 bool enabled_plugin_exists = false; |
| 478 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| 479 if (IsPluginEnabled(web_plugin_infos_[i])) { |
| 480 enabled_plugin_exists = true; |
| 481 break; |
| 482 } |
| 483 } |
| 484 enabled_ = enabled_plugin_exists; |
| 485 } |
| 486 |
| 487 bool PluginGroup::Enable(WebPluginInfo* plugin, |
| 488 int new_reason) { |
| 489 DCHECK(new_reason == WebPluginInfo::USER_ENABLED || |
| 490 new_reason == WebPluginInfo::POLICY_UNMANAGED || |
| 491 new_reason == WebPluginInfo::POLICY_ENABLED); |
| 492 // If we are only stripping the policy then mask the policy bits. |
| 493 if (new_reason == WebPluginInfo::POLICY_UNMANAGED) { |
| 494 plugin->enabled &= WebPluginInfo::USER_MASK; |
| 495 return true; |
| 496 } |
| 497 // If already enabled just upgrade the reason. |
| 498 if (IsPluginEnabled(*plugin)) { |
| 499 plugin->enabled |= new_reason; |
| 500 return true; |
| 501 } else { |
| 502 // Only changeable if not managed. |
| 503 if (plugin->enabled & WebPluginInfo::MANAGED_MASK) |
| 504 return false; |
| 505 plugin->enabled = new_reason; |
| 506 } |
| 507 return true; |
| 508 } |
| 509 |
| 510 bool PluginGroup::Disable(WebPluginInfo* plugin, |
| 511 int new_reason) { |
| 512 DCHECK(new_reason == WebPluginInfo::USER_DISABLED || |
| 513 new_reason == WebPluginInfo::POLICY_DISABLED || |
| 514 new_reason == WebPluginInfo::USER_DISABLED_POLICY_DISABLED); |
| 515 // If already disabled just upgrade the reason. |
| 516 if (!IsPluginEnabled(*plugin)) { |
| 517 plugin->enabled |= new_reason; |
| 518 return true; |
| 519 } else { |
| 520 // Only changeable if not managed. |
| 521 if (plugin->enabled & WebPluginInfo::MANAGED_MASK) |
| 522 return false; |
| 523 plugin->enabled = new_reason; |
| 524 } |
| 525 return true; |
| 526 } |
| 527 |
412 } // namespace npapi | 528 } // namespace npapi |
413 } // namespace webkit | 529 } // namespace webkit |
OLD | NEW |