| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_prefs.h" | 5 #include "extensions/browser/extension_prefs.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_notifier.h" | 10 #include "base/prefs/pref_notifier.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 const std::string& extension_id) : | 204 const std::string& extension_id) : |
| 205 DictionaryPrefUpdate(service, pref_names::kExtensions), | 205 DictionaryPrefUpdate(service, pref_names::kExtensions), |
| 206 extension_id_(extension_id) {} | 206 extension_id_(extension_id) {} |
| 207 | 207 |
| 208 virtual ~ScopedExtensionPrefUpdate() { | 208 virtual ~ScopedExtensionPrefUpdate() { |
| 209 } | 209 } |
| 210 | 210 |
| 211 // DictionaryPrefUpdate overrides: | 211 // DictionaryPrefUpdate overrides: |
| 212 virtual base::DictionaryValue* Get() OVERRIDE { | 212 virtual base::DictionaryValue* Get() OVERRIDE { |
| 213 base::DictionaryValue* dict = DictionaryPrefUpdate::Get(); | 213 base::DictionaryValue* dict = DictionaryPrefUpdate::Get(); |
| 214 base::DictionaryValue* extension = NULL; | 214 base::DictionaryValue* extension = nullptr; |
| 215 if (!dict->GetDictionary(extension_id_, &extension)) { | 215 if (!dict->GetDictionary(extension_id_, &extension)) { |
| 216 // Extension pref does not exist, create it. | 216 // Extension pref does not exist, create it. |
| 217 extension = new base::DictionaryValue(); | 217 extension = new base::DictionaryValue(); |
| 218 dict->SetWithoutPathExpansion(extension_id_, extension); | 218 dict->SetWithoutPathExpansion(extension_id_, extension); |
| 219 } | 219 } |
| 220 return extension; | 220 return extension; |
| 221 } | 221 } |
| 222 | 222 |
| 223 private: | 223 private: |
| 224 const std::string extension_id_; | 224 const std::string extension_id_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 242 ExtensionPrefValueMap* value_map, | 242 ExtensionPrefValueMap* value_map, |
| 243 const std::string& extension_id, | 243 const std::string& extension_id, |
| 244 ExtensionPrefsScope scope) { | 244 ExtensionPrefsScope scope) { |
| 245 std::string scope_string; | 245 std::string scope_string; |
| 246 if (!pref_names::ScopeToPrefName(scope, &scope_string)) | 246 if (!pref_names::ScopeToPrefName(scope, &scope_string)) |
| 247 return; | 247 return; |
| 248 std::string key = extension_id + "." + scope_string; | 248 std::string key = extension_id + "." + scope_string; |
| 249 | 249 |
| 250 const base::DictionaryValue* source_dict = | 250 const base::DictionaryValue* source_dict = |
| 251 prefs->pref_service()->GetDictionary(pref_names::kExtensions); | 251 prefs->pref_service()->GetDictionary(pref_names::kExtensions); |
| 252 const base::DictionaryValue* preferences = NULL; | 252 const base::DictionaryValue* preferences = nullptr; |
| 253 if (!source_dict->GetDictionary(key, &preferences)) | 253 if (!source_dict->GetDictionary(key, &preferences)) |
| 254 return; | 254 return; |
| 255 | 255 |
| 256 for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd(); | 256 for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd(); |
| 257 iter.Advance()) { | 257 iter.Advance()) { |
| 258 value_map->SetExtensionPref( | 258 value_map->SetExtensionPref( |
| 259 extension_id, iter.key(), scope, iter.value().DeepCopy()); | 259 extension_id, iter.key(), scope, iter.value().DeepCopy()); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 290 DCHECK(crx_file::id_util::IdIsValid(extension_id_)); | 290 DCHECK(crx_file::id_util::IdIsValid(extension_id_)); |
| 291 } | 291 } |
| 292 | 292 |
| 293 template <typename T, base::Value::Type type_enum_value> | 293 template <typename T, base::Value::Type type_enum_value> |
| 294 ExtensionPrefs::ScopedUpdate<T, type_enum_value>::~ScopedUpdate() { | 294 ExtensionPrefs::ScopedUpdate<T, type_enum_value>::~ScopedUpdate() { |
| 295 } | 295 } |
| 296 | 296 |
| 297 template <typename T, base::Value::Type type_enum_value> | 297 template <typename T, base::Value::Type type_enum_value> |
| 298 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Get() { | 298 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Get() { |
| 299 base::DictionaryValue* dict = update_.Get(); | 299 base::DictionaryValue* dict = update_.Get(); |
| 300 base::DictionaryValue* extension = NULL; | 300 base::DictionaryValue* extension = nullptr; |
| 301 base::Value* key_value = NULL; | 301 base::Value* key_value = nullptr; |
| 302 if (!dict->GetDictionary(extension_id_, &extension) || | 302 if (!dict->GetDictionary(extension_id_, &extension) || |
| 303 !extension->Get(key_, &key_value)) { | 303 !extension->Get(key_, &key_value)) { |
| 304 return NULL; | 304 return nullptr; |
| 305 } | 305 } |
| 306 return key_value->GetType() == type_enum_value ? | 306 return key_value->GetType() == type_enum_value ? static_cast<T*>(key_value) |
| 307 static_cast<T*>(key_value) : | 307 : nullptr; |
| 308 NULL; | |
| 309 } | 308 } |
| 310 | 309 |
| 311 template <typename T, base::Value::Type type_enum_value> | 310 template <typename T, base::Value::Type type_enum_value> |
| 312 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Create() { | 311 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Create() { |
| 313 base::DictionaryValue* dict = update_.Get(); | 312 base::DictionaryValue* dict = update_.Get(); |
| 314 base::DictionaryValue* extension = NULL; | 313 base::DictionaryValue* extension = nullptr; |
| 315 base::Value* key_value = NULL; | 314 base::Value* key_value = nullptr; |
| 316 T* value_as_t = NULL; | 315 T* value_as_t = nullptr; |
| 317 if (!dict->GetDictionary(extension_id_, &extension)) { | 316 if (!dict->GetDictionary(extension_id_, &extension)) { |
| 318 extension = new base::DictionaryValue; | 317 extension = new base::DictionaryValue; |
| 319 dict->SetWithoutPathExpansion(extension_id_, extension); | 318 dict->SetWithoutPathExpansion(extension_id_, extension); |
| 320 } | 319 } |
| 321 if (!extension->Get(key_, &key_value)) { | 320 if (!extension->Get(key_, &key_value)) { |
| 322 value_as_t = new T; | 321 value_as_t = new T; |
| 323 extension->SetWithoutPathExpansion(key_, value_as_t); | 322 extension->SetWithoutPathExpansion(key_, value_as_t); |
| 324 } else { | 323 } else { |
| 325 CHECK(key_value->GetType() == type_enum_value); | 324 CHECK(key_value->GetType() == type_enum_value); |
| 326 value_as_t = static_cast<T*>(key_value); | 325 value_as_t = static_cast<T*>(key_value); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 395 |
| 397 void ExtensionPrefs::MakePathsRelative() { | 396 void ExtensionPrefs::MakePathsRelative() { |
| 398 const base::DictionaryValue* dict = | 397 const base::DictionaryValue* dict = |
| 399 prefs_->GetDictionary(pref_names::kExtensions); | 398 prefs_->GetDictionary(pref_names::kExtensions); |
| 400 if (!dict || dict->empty()) | 399 if (!dict || dict->empty()) |
| 401 return; | 400 return; |
| 402 | 401 |
| 403 // Collect all extensions ids with absolute paths in |absolute_keys|. | 402 // Collect all extensions ids with absolute paths in |absolute_keys|. |
| 404 std::set<std::string> absolute_keys; | 403 std::set<std::string> absolute_keys; |
| 405 for (base::DictionaryValue::Iterator i(*dict); !i.IsAtEnd(); i.Advance()) { | 404 for (base::DictionaryValue::Iterator i(*dict); !i.IsAtEnd(); i.Advance()) { |
| 406 const base::DictionaryValue* extension_dict = NULL; | 405 const base::DictionaryValue* extension_dict = nullptr; |
| 407 if (!i.value().GetAsDictionary(&extension_dict)) | 406 if (!i.value().GetAsDictionary(&extension_dict)) |
| 408 continue; | 407 continue; |
| 409 int location_value; | 408 int location_value; |
| 410 if (extension_dict->GetInteger(kPrefLocation, &location_value) && | 409 if (extension_dict->GetInteger(kPrefLocation, &location_value) && |
| 411 Manifest::IsUnpackedLocation( | 410 Manifest::IsUnpackedLocation( |
| 412 static_cast<Manifest::Location>(location_value))) { | 411 static_cast<Manifest::Location>(location_value))) { |
| 413 // Unpacked extensions can have absolute paths. | 412 // Unpacked extensions can have absolute paths. |
| 414 continue; | 413 continue; |
| 415 } | 414 } |
| 416 base::FilePath::StringType path_string; | 415 base::FilePath::StringType path_string; |
| 417 if (!extension_dict->GetString(kPrefPath, &path_string)) | 416 if (!extension_dict->GetString(kPrefPath, &path_string)) |
| 418 continue; | 417 continue; |
| 419 base::FilePath path(path_string); | 418 base::FilePath path(path_string); |
| 420 if (path.IsAbsolute()) | 419 if (path.IsAbsolute()) |
| 421 absolute_keys.insert(i.key()); | 420 absolute_keys.insert(i.key()); |
| 422 } | 421 } |
| 423 if (absolute_keys.empty()) | 422 if (absolute_keys.empty()) |
| 424 return; | 423 return; |
| 425 | 424 |
| 426 // Fix these paths. | 425 // Fix these paths. |
| 427 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); | 426 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); |
| 428 base::DictionaryValue* update_dict = update.Get(); | 427 base::DictionaryValue* update_dict = update.Get(); |
| 429 for (std::set<std::string>::iterator i = absolute_keys.begin(); | 428 for (std::set<std::string>::iterator i = absolute_keys.begin(); |
| 430 i != absolute_keys.end(); ++i) { | 429 i != absolute_keys.end(); ++i) { |
| 431 base::DictionaryValue* extension_dict = NULL; | 430 base::DictionaryValue* extension_dict = nullptr; |
| 432 if (!update_dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { | 431 if (!update_dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { |
| 433 NOTREACHED() << "Control should never reach here for extension " << *i; | 432 NOTREACHED() << "Control should never reach here for extension " << *i; |
| 434 continue; | 433 continue; |
| 435 } | 434 } |
| 436 base::FilePath::StringType path_string; | 435 base::FilePath::StringType path_string; |
| 437 extension_dict->GetString(kPrefPath, &path_string); | 436 extension_dict->GetString(kPrefPath, &path_string); |
| 438 base::FilePath path(path_string); | 437 base::FilePath path(path_string); |
| 439 extension_dict->SetString(kPrefPath, | 438 extension_dict->SetString(kPrefPath, |
| 440 MakePathRelative(install_directory_, path)); | 439 MakePathRelative(install_directory_, path)); |
| 441 } | 440 } |
| 442 } | 441 } |
| 443 | 442 |
| 444 const base::DictionaryValue* ExtensionPrefs::GetExtensionPref( | 443 const base::DictionaryValue* ExtensionPrefs::GetExtensionPref( |
| 445 const std::string& extension_id) const { | 444 const std::string& extension_id) const { |
| 446 const base::DictionaryValue* extensions = | 445 const base::DictionaryValue* extensions = |
| 447 prefs_->GetDictionary(pref_names::kExtensions); | 446 prefs_->GetDictionary(pref_names::kExtensions); |
| 448 const base::DictionaryValue* extension_dict = NULL; | 447 const base::DictionaryValue* extension_dict = nullptr; |
| 449 if (!extensions || | 448 if (!extensions || |
| 450 !extensions->GetDictionary(extension_id, &extension_dict)) { | 449 !extensions->GetDictionary(extension_id, &extension_dict)) { |
| 451 return NULL; | 450 return nullptr; |
| 452 } | 451 } |
| 453 return extension_dict; | 452 return extension_dict; |
| 454 } | 453 } |
| 455 | 454 |
| 456 void ExtensionPrefs::UpdateExtensionPref(const std::string& extension_id, | 455 void ExtensionPrefs::UpdateExtensionPref(const std::string& extension_id, |
| 457 const std::string& key, | 456 const std::string& key, |
| 458 base::Value* data_value) { | 457 base::Value* data_value) { |
| 459 if (!crx_file::id_util::IdIsValid(extension_id)) { | 458 if (!crx_file::id_util::IdIsValid(extension_id)) { |
| 460 NOTREACHED() << "Invalid extension_id " << extension_id; | 459 NOTREACHED() << "Invalid extension_id " << extension_id; |
| 461 return; | 460 return; |
| 462 } | 461 } |
| 463 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 462 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 464 if (data_value) | 463 if (data_value) |
| 465 update->Set(key, data_value); | 464 update->Set(key, data_value); |
| 466 else | 465 else |
| 467 update->Remove(key, NULL); | 466 update->Remove(key, nullptr); |
| 468 } | 467 } |
| 469 | 468 |
| 470 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { | 469 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { |
| 471 extension_pref_value_map_->UnregisterExtension(extension_id); | 470 extension_pref_value_map_->UnregisterExtension(extension_id); |
| 472 FOR_EACH_OBSERVER(ExtensionPrefsObserver, | 471 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
| 473 observer_list_, | 472 observer_list_, |
| 474 OnExtensionPrefsDeleted(extension_id)); | 473 OnExtensionPrefsDeleted(extension_id)); |
| 475 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); | 474 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); |
| 476 base::DictionaryValue* dict = update.Get(); | 475 base::DictionaryValue* dict = update.Get(); |
| 477 dict->Remove(extension_id, NULL); | 476 dict->Remove(extension_id, nullptr); |
| 478 } | 477 } |
| 479 | 478 |
| 480 bool ExtensionPrefs::ReadPrefAsBoolean(const std::string& extension_id, | 479 bool ExtensionPrefs::ReadPrefAsBoolean(const std::string& extension_id, |
| 481 const std::string& pref_key, | 480 const std::string& pref_key, |
| 482 bool* out_value) const { | 481 bool* out_value) const { |
| 483 const base::DictionaryValue* ext = GetExtensionPref(extension_id); | 482 const base::DictionaryValue* ext = GetExtensionPref(extension_id); |
| 484 if (!ext || !ext->GetBoolean(pref_key, out_value)) | 483 if (!ext || !ext->GetBoolean(pref_key, out_value)) |
| 485 return false; | 484 return false; |
| 486 | 485 |
| 487 return true; | 486 return true; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 504 if (!ext || !ext->GetString(pref_key, out_value)) | 503 if (!ext || !ext->GetString(pref_key, out_value)) |
| 505 return false; | 504 return false; |
| 506 | 505 |
| 507 return true; | 506 return true; |
| 508 } | 507 } |
| 509 | 508 |
| 510 bool ExtensionPrefs::ReadPrefAsList(const std::string& extension_id, | 509 bool ExtensionPrefs::ReadPrefAsList(const std::string& extension_id, |
| 511 const std::string& pref_key, | 510 const std::string& pref_key, |
| 512 const base::ListValue** out_value) const { | 511 const base::ListValue** out_value) const { |
| 513 const base::DictionaryValue* ext = GetExtensionPref(extension_id); | 512 const base::DictionaryValue* ext = GetExtensionPref(extension_id); |
| 514 const base::ListValue* out = NULL; | 513 const base::ListValue* out = nullptr; |
| 515 if (!ext || !ext->GetList(pref_key, &out)) | 514 if (!ext || !ext->GetList(pref_key, &out)) |
| 516 return false; | 515 return false; |
| 517 if (out_value) | 516 if (out_value) |
| 518 *out_value = out; | 517 *out_value = out; |
| 519 | 518 |
| 520 return true; | 519 return true; |
| 521 } | 520 } |
| 522 | 521 |
| 523 bool ExtensionPrefs::ReadPrefAsDictionary( | 522 bool ExtensionPrefs::ReadPrefAsDictionary( |
| 524 const std::string& extension_id, | 523 const std::string& extension_id, |
| 525 const std::string& pref_key, | 524 const std::string& pref_key, |
| 526 const base::DictionaryValue** out_value) const { | 525 const base::DictionaryValue** out_value) const { |
| 527 const base::DictionaryValue* ext = GetExtensionPref(extension_id); | 526 const base::DictionaryValue* ext = GetExtensionPref(extension_id); |
| 528 const base::DictionaryValue* out = NULL; | 527 const base::DictionaryValue* out = nullptr; |
| 529 if (!ext || !ext->GetDictionary(pref_key, &out)) | 528 if (!ext || !ext->GetDictionary(pref_key, &out)) |
| 530 return false; | 529 return false; |
| 531 if (out_value) | 530 if (out_value) |
| 532 *out_value = out; | 531 *out_value = out; |
| 533 | 532 |
| 534 return true; | 533 return true; |
| 535 } | 534 } |
| 536 | 535 |
| 537 bool ExtensionPrefs::HasPrefForExtension( | 536 bool ExtensionPrefs::HasPrefForExtension( |
| 538 const std::string& extension_id) const { | 537 const std::string& extension_id) const { |
| 539 return GetExtensionPref(extension_id) != NULL; | 538 return GetExtensionPref(extension_id) != nullptr; |
| 540 } | 539 } |
| 541 | 540 |
| 542 bool ExtensionPrefs::ReadPrefAsURLPatternSet(const std::string& extension_id, | 541 bool ExtensionPrefs::ReadPrefAsURLPatternSet(const std::string& extension_id, |
| 543 const std::string& pref_key, | 542 const std::string& pref_key, |
| 544 URLPatternSet* result, | 543 URLPatternSet* result, |
| 545 int valid_schemes) { | 544 int valid_schemes) { |
| 546 const base::ListValue* value = NULL; | 545 const base::ListValue* value = nullptr; |
| 547 if (!ReadPrefAsList(extension_id, pref_key, &value)) | 546 if (!ReadPrefAsList(extension_id, pref_key, &value)) |
| 548 return false; | 547 return false; |
| 549 | 548 |
| 550 bool allow_file_access = AllowFileAccess(extension_id); | 549 bool allow_file_access = AllowFileAccess(extension_id); |
| 551 return result->Populate(*value, valid_schemes, allow_file_access, NULL); | 550 return result->Populate(*value, valid_schemes, allow_file_access, nullptr); |
| 552 } | 551 } |
| 553 | 552 |
| 554 void ExtensionPrefs::SetExtensionPrefURLPatternSet( | 553 void ExtensionPrefs::SetExtensionPrefURLPatternSet( |
| 555 const std::string& extension_id, | 554 const std::string& extension_id, |
| 556 const std::string& pref_key, | 555 const std::string& pref_key, |
| 557 const URLPatternSet& new_value) { | 556 const URLPatternSet& new_value) { |
| 558 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); | 557 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); |
| 559 } | 558 } |
| 560 | 559 |
| 561 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( | 560 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( |
| 562 const std::string& extension_id, | 561 const std::string& extension_id, |
| 563 const std::string& pref_key) const { | 562 const std::string& pref_key) const { |
| 564 bool out_value = false; | 563 bool out_value = false; |
| 565 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; | 564 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; |
| 566 } | 565 } |
| 567 | 566 |
| 568 PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet( | 567 PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet( |
| 569 const std::string& extension_id, | 568 const std::string& extension_id, |
| 570 const std::string& pref_key) { | 569 const std::string& pref_key) { |
| 571 if (!GetExtensionPref(extension_id)) | 570 if (!GetExtensionPref(extension_id)) |
| 572 return NULL; | 571 return nullptr; |
| 573 | 572 |
| 574 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() | 573 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() |
| 575 // for api_values format. | 574 // for api_values format. |
| 576 APIPermissionSet apis; | 575 APIPermissionSet apis; |
| 577 const base::ListValue* api_values = NULL; | 576 const base::ListValue* api_values = nullptr; |
| 578 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 577 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
| 579 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { | 578 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { |
| 580 APIPermissionSet::ParseFromJSON(api_values, | 579 APIPermissionSet::ParseFromJSON(api_values, |
| 581 APIPermissionSet::kAllowInternalPermissions, | 580 APIPermissionSet::kAllowInternalPermissions, |
| 582 &apis, NULL, NULL); | 581 &apis, |
| 582 nullptr, |
| 583 nullptr); |
| 583 } | 584 } |
| 584 | 585 |
| 585 // Retrieve the Manifest Keys permissions. Please refer to | 586 // Retrieve the Manifest Keys permissions. Please refer to |
| 586 // |SetExtensionPrefPermissionSet| for manifest_permissions_values format. | 587 // |SetExtensionPrefPermissionSet| for manifest_permissions_values format. |
| 587 ManifestPermissionSet manifest_permissions; | 588 ManifestPermissionSet manifest_permissions; |
| 588 const base::ListValue* manifest_permissions_values = NULL; | 589 const base::ListValue* manifest_permissions_values = nullptr; |
| 589 std::string manifest_permission_pref = | 590 std::string manifest_permission_pref = |
| 590 JoinPrefs(pref_key, kPrefManifestPermissions); | 591 JoinPrefs(pref_key, kPrefManifestPermissions); |
| 591 if (ReadPrefAsList(extension_id, manifest_permission_pref, | 592 if (ReadPrefAsList(extension_id, manifest_permission_pref, |
| 592 &manifest_permissions_values)) { | 593 &manifest_permissions_values)) { |
| 593 ManifestPermissionSet::ParseFromJSON( | 594 ManifestPermissionSet::ParseFromJSON( |
| 594 manifest_permissions_values, &manifest_permissions, NULL, NULL); | 595 manifest_permissions_values, &manifest_permissions, nullptr, nullptr); |
| 595 } | 596 } |
| 596 | 597 |
| 597 // Retrieve the explicit host permissions. | 598 // Retrieve the explicit host permissions. |
| 598 URLPatternSet explicit_hosts; | 599 URLPatternSet explicit_hosts; |
| 599 ReadPrefAsURLPatternSet( | 600 ReadPrefAsURLPatternSet( |
| 600 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), | 601 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), |
| 601 &explicit_hosts, Extension::kValidHostPermissionSchemes); | 602 &explicit_hosts, Extension::kValidHostPermissionSchemes); |
| 602 | 603 |
| 603 // Retrieve the scriptable host permissions. | 604 // Retrieve the scriptable host permissions. |
| 604 URLPatternSet scriptable_hosts; | 605 URLPatternSet scriptable_hosts; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 bool ExtensionPrefs::IsExternalExtensionAcknowledged( | 680 bool ExtensionPrefs::IsExternalExtensionAcknowledged( |
| 680 const std::string& extension_id) { | 681 const std::string& extension_id) { |
| 681 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged); | 682 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged); |
| 682 } | 683 } |
| 683 | 684 |
| 684 void ExtensionPrefs::AcknowledgeExternalExtension( | 685 void ExtensionPrefs::AcknowledgeExternalExtension( |
| 685 const std::string& extension_id) { | 686 const std::string& extension_id) { |
| 686 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 687 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 687 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged, | 688 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged, |
| 688 new base::FundamentalValue(true)); | 689 new base::FundamentalValue(true)); |
| 689 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); | 690 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, nullptr); |
| 690 } | 691 } |
| 691 | 692 |
| 692 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged( | 693 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged( |
| 693 const std::string& extension_id) { | 694 const std::string& extension_id) { |
| 694 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged); | 695 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged); |
| 695 } | 696 } |
| 696 | 697 |
| 697 void ExtensionPrefs::AcknowledgeBlacklistedExtension( | 698 void ExtensionPrefs::AcknowledgeBlacklistedExtension( |
| 698 const std::string& extension_id) { | 699 const std::string& extension_id) { |
| 699 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 700 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 700 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, | 701 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, |
| 701 new base::FundamentalValue(true)); | 702 new base::FundamentalValue(true)); |
| 702 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); | 703 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, nullptr); |
| 703 } | 704 } |
| 704 | 705 |
| 705 bool ExtensionPrefs::IsExternalInstallFirstRun( | 706 bool ExtensionPrefs::IsExternalInstallFirstRun( |
| 706 const std::string& extension_id) { | 707 const std::string& extension_id) { |
| 707 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun); | 708 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun); |
| 708 } | 709 } |
| 709 | 710 |
| 710 void ExtensionPrefs::SetExternalInstallFirstRun( | 711 void ExtensionPrefs::SetExternalInstallFirstRun( |
| 711 const std::string& extension_id) { | 712 const std::string& extension_id) { |
| 712 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 713 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 713 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun, | 714 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun, |
| 714 new base::FundamentalValue(true)); | 715 new base::FundamentalValue(true)); |
| 715 } | 716 } |
| 716 | 717 |
| 717 bool ExtensionPrefs::HasWipeoutBeenAcknowledged( | 718 bool ExtensionPrefs::HasWipeoutBeenAcknowledged( |
| 718 const std::string& extension_id) { | 719 const std::string& extension_id) { |
| 719 return ReadPrefAsBooleanAndReturn(extension_id, kPrefWipeoutAcknowledged); | 720 return ReadPrefAsBooleanAndReturn(extension_id, kPrefWipeoutAcknowledged); |
| 720 } | 721 } |
| 721 | 722 |
| 722 void ExtensionPrefs::SetWipeoutAcknowledged( | 723 void ExtensionPrefs::SetWipeoutAcknowledged( |
| 723 const std::string& extension_id, | 724 const std::string& extension_id, |
| 724 bool value) { | 725 bool value) { |
| 725 UpdateExtensionPref(extension_id, | 726 UpdateExtensionPref(extension_id, |
| 726 kPrefWipeoutAcknowledged, | 727 kPrefWipeoutAcknowledged, |
| 727 value ? new base::FundamentalValue(value) : NULL); | 728 value ? new base::FundamentalValue(value) : nullptr); |
| 728 } | 729 } |
| 729 | 730 |
| 730 bool ExtensionPrefs::HasSettingsApiBubbleBeenAcknowledged( | 731 bool ExtensionPrefs::HasSettingsApiBubbleBeenAcknowledged( |
| 731 const std::string& extension_id) { | 732 const std::string& extension_id) { |
| 732 return ReadPrefAsBooleanAndReturn(extension_id, | 733 return ReadPrefAsBooleanAndReturn(extension_id, |
| 733 kPrefSettingsBubbleAcknowledged); | 734 kPrefSettingsBubbleAcknowledged); |
| 734 } | 735 } |
| 735 | 736 |
| 736 void ExtensionPrefs::SetSettingsApiBubbleBeenAcknowledged( | 737 void ExtensionPrefs::SetSettingsApiBubbleBeenAcknowledged( |
| 737 const std::string& extension_id, | 738 const std::string& extension_id, |
| 738 bool value) { | 739 bool value) { |
| 739 UpdateExtensionPref(extension_id, | 740 UpdateExtensionPref(extension_id, |
| 740 kPrefSettingsBubbleAcknowledged, | 741 kPrefSettingsBubbleAcknowledged, |
| 741 value ? new base::FundamentalValue(value) : NULL); | 742 value ? new base::FundamentalValue(value) : nullptr); |
| 742 } | 743 } |
| 743 | 744 |
| 744 bool ExtensionPrefs::HasNtpOverriddenBubbleBeenAcknowledged( | 745 bool ExtensionPrefs::HasNtpOverriddenBubbleBeenAcknowledged( |
| 745 const std::string& extension_id) { | 746 const std::string& extension_id) { |
| 746 return ReadPrefAsBooleanAndReturn(extension_id, kPrefNtpBubbleAcknowledged); | 747 return ReadPrefAsBooleanAndReturn(extension_id, kPrefNtpBubbleAcknowledged); |
| 747 } | 748 } |
| 748 | 749 |
| 749 void ExtensionPrefs::SetNtpOverriddenBubbleBeenAcknowledged( | 750 void ExtensionPrefs::SetNtpOverriddenBubbleBeenAcknowledged( |
| 750 const std::string& extension_id, | 751 const std::string& extension_id, |
| 751 bool value) { | 752 bool value) { |
| 752 UpdateExtensionPref(extension_id, | 753 UpdateExtensionPref(extension_id, |
| 753 kPrefNtpBubbleAcknowledged, | 754 kPrefNtpBubbleAcknowledged, |
| 754 value ? new base::FundamentalValue(value) : NULL); | 755 value ? new base::FundamentalValue(value) : nullptr); |
| 755 } | 756 } |
| 756 | 757 |
| 757 bool ExtensionPrefs::HasProxyOverriddenBubbleBeenAcknowledged( | 758 bool ExtensionPrefs::HasProxyOverriddenBubbleBeenAcknowledged( |
| 758 const std::string& extension_id) { | 759 const std::string& extension_id) { |
| 759 return ReadPrefAsBooleanAndReturn(extension_id, kPrefProxyBubbleAcknowledged); | 760 return ReadPrefAsBooleanAndReturn(extension_id, kPrefProxyBubbleAcknowledged); |
| 760 } | 761 } |
| 761 | 762 |
| 762 void ExtensionPrefs::SetProxyOverriddenBubbleBeenAcknowledged( | 763 void ExtensionPrefs::SetProxyOverriddenBubbleBeenAcknowledged( |
| 763 const std::string& extension_id, | 764 const std::string& extension_id, |
| 764 bool value) { | 765 bool value) { |
| 765 UpdateExtensionPref(extension_id, | 766 UpdateExtensionPref(extension_id, |
| 766 kPrefProxyBubbleAcknowledged, | 767 kPrefProxyBubbleAcknowledged, |
| 767 value ? new base::FundamentalValue(value) : NULL); | 768 value ? new base::FundamentalValue(value) : nullptr); |
| 768 } | 769 } |
| 769 | 770 |
| 770 bool ExtensionPrefs::SetAlertSystemFirstRun() { | 771 bool ExtensionPrefs::SetAlertSystemFirstRun() { |
| 771 if (prefs_->GetBoolean(pref_names::kAlertsInitialized)) { | 772 if (prefs_->GetBoolean(pref_names::kAlertsInitialized)) { |
| 772 return true; | 773 return true; |
| 773 } | 774 } |
| 774 prefs_->SetBoolean(pref_names::kAlertsInitialized, true); | 775 prefs_->SetBoolean(pref_names::kAlertsInitialized, true); |
| 775 return false; | 776 return false; |
| 776 } | 777 } |
| 777 | 778 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 break; | 833 break; |
| 833 case DISABLE_REASON_CLEAR: | 834 case DISABLE_REASON_CLEAR: |
| 834 new_value = Extension::DISABLE_NONE; | 835 new_value = Extension::DISABLE_NONE; |
| 835 break; | 836 break; |
| 836 } | 837 } |
| 837 | 838 |
| 838 if (old_value == new_value) // no change, return. | 839 if (old_value == new_value) // no change, return. |
| 839 return; | 840 return; |
| 840 | 841 |
| 841 if (new_value == Extension::DISABLE_NONE) { | 842 if (new_value == Extension::DISABLE_NONE) { |
| 842 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); | 843 UpdateExtensionPref(extension_id, kPrefDisableReasons, nullptr); |
| 843 } else { | 844 } else { |
| 844 UpdateExtensionPref(extension_id, | 845 UpdateExtensionPref(extension_id, |
| 845 kPrefDisableReasons, | 846 kPrefDisableReasons, |
| 846 new base::FundamentalValue(new_value)); | 847 new base::FundamentalValue(new_value)); |
| 847 } | 848 } |
| 848 | 849 |
| 849 FOR_EACH_OBSERVER(ExtensionPrefsObserver, | 850 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
| 850 observer_list_, | 851 observer_list_, |
| 851 OnExtensionDisableReasonsChanged(extension_id, new_value)); | 852 OnExtensionDisableReasonsChanged(extension_id, new_value)); |
| 852 } | 853 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 875 } | 876 } |
| 876 | 877 |
| 877 void ExtensionPrefs::SetExtensionBlacklisted(const std::string& extension_id, | 878 void ExtensionPrefs::SetExtensionBlacklisted(const std::string& extension_id, |
| 878 bool is_blacklisted) { | 879 bool is_blacklisted) { |
| 879 bool currently_blacklisted = IsExtensionBlacklisted(extension_id); | 880 bool currently_blacklisted = IsExtensionBlacklisted(extension_id); |
| 880 if (is_blacklisted == currently_blacklisted) | 881 if (is_blacklisted == currently_blacklisted) |
| 881 return; | 882 return; |
| 882 | 883 |
| 883 // Always make sure the "acknowledged" bit is cleared since the blacklist bit | 884 // Always make sure the "acknowledged" bit is cleared since the blacklist bit |
| 884 // is changing. | 885 // is changing. |
| 885 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, NULL); | 886 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, nullptr); |
| 886 | 887 |
| 887 if (is_blacklisted) { | 888 if (is_blacklisted) { |
| 888 UpdateExtensionPref(extension_id, | 889 UpdateExtensionPref(extension_id, |
| 889 kPrefBlacklist, | 890 kPrefBlacklist, |
| 890 new base::FundamentalValue(true)); | 891 new base::FundamentalValue(true)); |
| 891 } else { | 892 } else { |
| 892 UpdateExtensionPref(extension_id, kPrefBlacklist, NULL); | 893 UpdateExtensionPref(extension_id, kPrefBlacklist, nullptr); |
| 893 const base::DictionaryValue* dict = GetExtensionPref(extension_id); | 894 const base::DictionaryValue* dict = GetExtensionPref(extension_id); |
| 894 if (dict && dict->empty()) | 895 if (dict && dict->empty()) |
| 895 DeleteExtensionPrefs(extension_id); | 896 DeleteExtensionPrefs(extension_id); |
| 896 } | 897 } |
| 897 } | 898 } |
| 898 | 899 |
| 899 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { | 900 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { |
| 900 const base::DictionaryValue* ext_prefs = GetExtensionPref(id); | 901 const base::DictionaryValue* ext_prefs = GetExtensionPref(id); |
| 901 return ext_prefs && IsBlacklistBitSet(ext_prefs); | 902 return ext_prefs && IsBlacklistBitSet(ext_prefs); |
| 902 } | 903 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 const base::DictionaryValue* ext = GetExtensionPref(*ext_id); | 1007 const base::DictionaryValue* ext = GetExtensionPref(*ext_id); |
| 1007 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) | 1008 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) |
| 1008 continue; | 1009 continue; |
| 1009 | 1010 |
| 1010 // Remove the full access bit (empty list will get trimmed). | 1011 // Remove the full access bit (empty list will get trimmed). |
| 1011 UpdateExtensionPref( | 1012 UpdateExtensionPref( |
| 1012 *ext_id, kPrefOldGrantedFullAccess, new base::ListValue()); | 1013 *ext_id, kPrefOldGrantedFullAccess, new base::ListValue()); |
| 1013 | 1014 |
| 1014 // Add the plugin permission if the full access bit was set. | 1015 // Add the plugin permission if the full access bit was set. |
| 1015 if (full_access) { | 1016 if (full_access) { |
| 1016 const base::ListValue* apis = NULL; | 1017 const base::ListValue* apis = nullptr; |
| 1017 base::ListValue* new_apis = NULL; | 1018 base::ListValue* new_apis = nullptr; |
| 1018 | 1019 |
| 1019 std::string granted_apis = JoinPrefs(kPrefGrantedPermissions, kPrefAPIs); | 1020 std::string granted_apis = JoinPrefs(kPrefGrantedPermissions, kPrefAPIs); |
| 1020 if (ext->GetList(kPrefOldGrantedAPIs, &apis)) | 1021 if (ext->GetList(kPrefOldGrantedAPIs, &apis)) |
| 1021 new_apis = apis->DeepCopy(); | 1022 new_apis = apis->DeepCopy(); |
| 1022 else | 1023 else |
| 1023 new_apis = new base::ListValue(); | 1024 new_apis = new base::ListValue(); |
| 1024 | 1025 |
| 1025 std::string plugin_name = info->GetByID(APIPermission::kPlugin)->name(); | 1026 std::string plugin_name = info->GetByID(APIPermission::kPlugin)->name(); |
| 1026 new_apis->Append(new base::StringValue(plugin_name)); | 1027 new_apis->Append(new base::StringValue(plugin_name)); |
| 1027 UpdateExtensionPref(*ext_id, granted_apis, new_apis); | 1028 UpdateExtensionPref(*ext_id, granted_apis, new_apis); |
| 1028 } | 1029 } |
| 1029 | 1030 |
| 1030 // The granted permissions originally only held the effective hosts, | 1031 // The granted permissions originally only held the effective hosts, |
| 1031 // which are a combination of host and user script host permissions. | 1032 // which are a combination of host and user script host permissions. |
| 1032 // We now maintain these lists separately. For migration purposes, it | 1033 // We now maintain these lists separately. For migration purposes, it |
| 1033 // does not matter how we treat the old effective hosts as long as the | 1034 // does not matter how we treat the old effective hosts as long as the |
| 1034 // new effective hosts will be the same, so we move them to explicit | 1035 // new effective hosts will be the same, so we move them to explicit |
| 1035 // host permissions. | 1036 // host permissions. |
| 1036 const base::ListValue* hosts = NULL; | 1037 const base::ListValue* hosts = nullptr; |
| 1037 std::string explicit_hosts = | 1038 std::string explicit_hosts = |
| 1038 JoinPrefs(kPrefGrantedPermissions, kPrefExplicitHosts); | 1039 JoinPrefs(kPrefGrantedPermissions, kPrefExplicitHosts); |
| 1039 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) { | 1040 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) { |
| 1040 UpdateExtensionPref( | 1041 UpdateExtensionPref( |
| 1041 *ext_id, explicit_hosts, hosts->DeepCopy()); | 1042 *ext_id, explicit_hosts, hosts->DeepCopy()); |
| 1042 | 1043 |
| 1043 // We can get rid of the old one by setting it to an empty list. | 1044 // We can get rid of the old one by setting it to an empty list. |
| 1044 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new base::ListValue()); | 1045 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new base::ListValue()); |
| 1045 } | 1046 } |
| 1046 } | 1047 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1061 new_value = Extension::DISABLE_PERMISSIONS_INCREASE; | 1062 new_value = Extension::DISABLE_PERMISSIONS_INCREASE; |
| 1062 break; | 1063 break; |
| 1063 case Extension::DEPRECATED_DISABLE_RELOAD: | 1064 case Extension::DEPRECATED_DISABLE_RELOAD: |
| 1064 new_value = Extension::DISABLE_RELOAD; | 1065 new_value = Extension::DISABLE_RELOAD; |
| 1065 break; | 1066 break; |
| 1066 } | 1067 } |
| 1067 | 1068 |
| 1068 UpdateExtensionPref(*ext_id, kPrefDisableReasons, | 1069 UpdateExtensionPref(*ext_id, kPrefDisableReasons, |
| 1069 new base::FundamentalValue(new_value)); | 1070 new base::FundamentalValue(new_value)); |
| 1070 // Remove the old disable reason. | 1071 // Remove the old disable reason. |
| 1071 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); | 1072 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, nullptr); |
| 1072 } | 1073 } |
| 1073 } | 1074 } |
| 1074 } | 1075 } |
| 1075 | 1076 |
| 1076 PermissionSet* ExtensionPrefs::GetGrantedPermissions( | 1077 PermissionSet* ExtensionPrefs::GetGrantedPermissions( |
| 1077 const std::string& extension_id) { | 1078 const std::string& extension_id) { |
| 1078 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 1079 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 1079 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); | 1080 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); |
| 1080 } | 1081 } |
| 1081 | 1082 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 | 1308 |
| 1308 return version; | 1309 return version; |
| 1309 } | 1310 } |
| 1310 | 1311 |
| 1311 void ExtensionPrefs::UpdateManifest(const Extension* extension) { | 1312 void ExtensionPrefs::UpdateManifest(const Extension* extension) { |
| 1312 if (!Manifest::IsUnpackedLocation(extension->location())) { | 1313 if (!Manifest::IsUnpackedLocation(extension->location())) { |
| 1313 const base::DictionaryValue* extension_dict = | 1314 const base::DictionaryValue* extension_dict = |
| 1314 GetExtensionPref(extension->id()); | 1315 GetExtensionPref(extension->id()); |
| 1315 if (!extension_dict) | 1316 if (!extension_dict) |
| 1316 return; | 1317 return; |
| 1317 const base::DictionaryValue* old_manifest = NULL; | 1318 const base::DictionaryValue* old_manifest = nullptr; |
| 1318 bool update_required = | 1319 bool update_required = |
| 1319 !extension_dict->GetDictionary(kPrefManifest, &old_manifest) || | 1320 !extension_dict->GetDictionary(kPrefManifest, &old_manifest) || |
| 1320 !extension->manifest()->value()->Equals(old_manifest); | 1321 !extension->manifest()->value()->Equals(old_manifest); |
| 1321 if (update_required) { | 1322 if (update_required) { |
| 1322 UpdateExtensionPref(extension->id(), kPrefManifest, | 1323 UpdateExtensionPref(extension->id(), kPrefManifest, |
| 1323 extension->manifest()->value()->DeepCopy()); | 1324 extension->manifest()->value()->DeepCopy()); |
| 1324 } | 1325 } |
| 1325 } | 1326 } |
| 1326 } | 1327 } |
| 1327 | 1328 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1343 } | 1344 } |
| 1344 | 1345 |
| 1345 // Only the following extension types have data saved in the preferences. | 1346 // Only the following extension types have data saved in the preferences. |
| 1346 if (location != Manifest::INTERNAL && | 1347 if (location != Manifest::INTERNAL && |
| 1347 !Manifest::IsUnpackedLocation(location) && | 1348 !Manifest::IsUnpackedLocation(location) && |
| 1348 !Manifest::IsExternalLocation(location)) { | 1349 !Manifest::IsExternalLocation(location)) { |
| 1349 NOTREACHED(); | 1350 NOTREACHED(); |
| 1350 return scoped_ptr<ExtensionInfo>(); | 1351 return scoped_ptr<ExtensionInfo>(); |
| 1351 } | 1352 } |
| 1352 | 1353 |
| 1353 const base::DictionaryValue* manifest = NULL; | 1354 const base::DictionaryValue* manifest = nullptr; |
| 1354 if (!Manifest::IsUnpackedLocation(location) && | 1355 if (!Manifest::IsUnpackedLocation(location) && |
| 1355 !extension->GetDictionary(kPrefManifest, &manifest)) { | 1356 !extension->GetDictionary(kPrefManifest, &manifest)) { |
| 1356 LOG(WARNING) << "Missing manifest for extension " << extension_id; | 1357 LOG(WARNING) << "Missing manifest for extension " << extension_id; |
| 1357 // Just a warning for now. | 1358 // Just a warning for now. |
| 1358 } | 1359 } |
| 1359 | 1360 |
| 1360 base::FilePath::StringType path; | 1361 base::FilePath::StringType path; |
| 1361 if (!extension->GetString(kPrefPath, &path)) | 1362 if (!extension->GetString(kPrefPath, &path)) |
| 1362 return scoped_ptr<ExtensionInfo>(); | 1363 return scoped_ptr<ExtensionInfo>(); |
| 1363 | 1364 |
| 1364 // Make path absolute. Most (but not all) extension types have relative paths. | 1365 // Make path absolute. Most (but not all) extension types have relative paths. |
| 1365 if (!base::FilePath(path).IsAbsolute()) | 1366 if (!base::FilePath(path).IsAbsolute()) |
| 1366 path = install_directory_.Append(path).value(); | 1367 path = install_directory_.Append(path).value(); |
| 1367 | 1368 |
| 1368 return scoped_ptr<ExtensionInfo>(new ExtensionInfo( | 1369 return scoped_ptr<ExtensionInfo>(new ExtensionInfo( |
| 1369 manifest, extension_id, base::FilePath(path), location)); | 1370 manifest, extension_id, base::FilePath(path), location)); |
| 1370 } | 1371 } |
| 1371 | 1372 |
| 1372 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( | 1373 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( |
| 1373 const std::string& extension_id) const { | 1374 const std::string& extension_id) const { |
| 1374 const base::DictionaryValue* ext = NULL; | 1375 const base::DictionaryValue* ext = nullptr; |
| 1375 const base::DictionaryValue* extensions = | 1376 const base::DictionaryValue* extensions = |
| 1376 prefs_->GetDictionary(pref_names::kExtensions); | 1377 prefs_->GetDictionary(pref_names::kExtensions); |
| 1377 if (!extensions || | 1378 if (!extensions || |
| 1378 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) | 1379 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) |
| 1379 return scoped_ptr<ExtensionInfo>(); | 1380 return scoped_ptr<ExtensionInfo>(); |
| 1380 int state_value; | 1381 int state_value; |
| 1381 if (ext->GetInteger(kPrefState, &state_value) && | 1382 if (ext->GetInteger(kPrefState, &state_value) && |
| 1382 state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { | 1383 state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { |
| 1383 LOG(WARNING) << "External extension with id " << extension_id | 1384 LOG(WARNING) << "External extension with id " << extension_id |
| 1384 << " has been uninstalled by the user"; | 1385 << " has been uninstalled by the user"; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1409 } | 1410 } |
| 1410 | 1411 |
| 1411 scoped_ptr<ExtensionPrefs::ExtensionsInfo> | 1412 scoped_ptr<ExtensionPrefs::ExtensionsInfo> |
| 1412 ExtensionPrefs::GetUninstalledExtensionsInfo() const { | 1413 ExtensionPrefs::GetUninstalledExtensionsInfo() const { |
| 1413 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); | 1414 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); |
| 1414 | 1415 |
| 1415 const base::DictionaryValue* extensions = | 1416 const base::DictionaryValue* extensions = |
| 1416 prefs_->GetDictionary(pref_names::kExtensions); | 1417 prefs_->GetDictionary(pref_names::kExtensions); |
| 1417 for (base::DictionaryValue::Iterator extension_id(*extensions); | 1418 for (base::DictionaryValue::Iterator extension_id(*extensions); |
| 1418 !extension_id.IsAtEnd(); extension_id.Advance()) { | 1419 !extension_id.IsAtEnd(); extension_id.Advance()) { |
| 1419 const base::DictionaryValue* ext = NULL; | 1420 const base::DictionaryValue* ext = nullptr; |
| 1420 if (!crx_file::id_util::IdIsValid(extension_id.key()) || | 1421 if (!crx_file::id_util::IdIsValid(extension_id.key()) || |
| 1421 !IsExternalExtensionUninstalled(extension_id.key()) || | 1422 !IsExternalExtensionUninstalled(extension_id.key()) || |
| 1422 !extension_id.value().GetAsDictionary(&ext)) | 1423 !extension_id.value().GetAsDictionary(&ext)) |
| 1423 continue; | 1424 continue; |
| 1424 | 1425 |
| 1425 scoped_ptr<ExtensionInfo> info = | 1426 scoped_ptr<ExtensionInfo> info = |
| 1426 GetInstalledInfoHelper(extension_id.key(), ext); | 1427 GetInstalledInfoHelper(extension_id.key(), ext); |
| 1427 if (info) | 1428 if (info) |
| 1428 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); | 1429 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); |
| 1429 } | 1430 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1460 static_cast<int>(delay_reason)); | 1461 static_cast<int>(delay_reason)); |
| 1461 | 1462 |
| 1462 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict); | 1463 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict); |
| 1463 } | 1464 } |
| 1464 | 1465 |
| 1465 bool ExtensionPrefs::RemoveDelayedInstallInfo( | 1466 bool ExtensionPrefs::RemoveDelayedInstallInfo( |
| 1466 const std::string& extension_id) { | 1467 const std::string& extension_id) { |
| 1467 if (!GetExtensionPref(extension_id)) | 1468 if (!GetExtensionPref(extension_id)) |
| 1468 return false; | 1469 return false; |
| 1469 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 1470 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 1470 bool result = update->Remove(kDelayedInstallInfo, NULL); | 1471 bool result = update->Remove(kDelayedInstallInfo, nullptr); |
| 1471 return result; | 1472 return result; |
| 1472 } | 1473 } |
| 1473 | 1474 |
| 1474 bool ExtensionPrefs::FinishDelayedInstallInfo( | 1475 bool ExtensionPrefs::FinishDelayedInstallInfo( |
| 1475 const std::string& extension_id) { | 1476 const std::string& extension_id) { |
| 1476 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 1477 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
| 1477 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 1478 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 1478 base::DictionaryValue* extension_dict = update.Get(); | 1479 base::DictionaryValue* extension_dict = update.Get(); |
| 1479 base::DictionaryValue* pending_install_dict = NULL; | 1480 base::DictionaryValue* pending_install_dict = nullptr; |
| 1480 if (!extension_dict->GetDictionary(kDelayedInstallInfo, | 1481 if (!extension_dict->GetDictionary(kDelayedInstallInfo, |
| 1481 &pending_install_dict)) { | 1482 &pending_install_dict)) { |
| 1482 return false; | 1483 return false; |
| 1483 } | 1484 } |
| 1484 | 1485 |
| 1485 // Retrieve and clear transient values populated by SetDelayedInstallInfo(). | 1486 // Retrieve and clear transient values populated by SetDelayedInstallInfo(). |
| 1486 // Also do any other data cleanup that makes sense. | 1487 // Also do any other data cleanup that makes sense. |
| 1487 std::string serialized_ordinal; | 1488 std::string serialized_ordinal; |
| 1488 syncer::StringOrdinal suggested_page_ordinal; | 1489 syncer::StringOrdinal suggested_page_ordinal; |
| 1489 bool needs_sort_ordinal = false; | 1490 bool needs_sort_ordinal = false; |
| 1490 if (pending_install_dict->GetString(kPrefSuggestedPageOrdinal, | 1491 if (pending_install_dict->GetString(kPrefSuggestedPageOrdinal, |
| 1491 &serialized_ordinal)) { | 1492 &serialized_ordinal)) { |
| 1492 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal); | 1493 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal); |
| 1493 needs_sort_ordinal = true; | 1494 needs_sort_ordinal = true; |
| 1494 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL); | 1495 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, nullptr); |
| 1495 } | 1496 } |
| 1496 pending_install_dict->Remove(kDelayedInstallReason, NULL); | 1497 pending_install_dict->Remove(kDelayedInstallReason, nullptr); |
| 1497 | 1498 |
| 1498 const base::Time install_time = time_provider_->GetCurrentTime(); | 1499 const base::Time install_time = time_provider_->GetCurrentTime(); |
| 1499 pending_install_dict->Set( | 1500 pending_install_dict->Set( |
| 1500 kPrefInstallTime, | 1501 kPrefInstallTime, |
| 1501 new base::StringValue( | 1502 new base::StringValue( |
| 1502 base::Int64ToString(install_time.ToInternalValue()))); | 1503 base::Int64ToString(install_time.ToInternalValue()))); |
| 1503 | 1504 |
| 1504 // Some extension pref values are written conditionally. If they are not | 1505 // Some extension pref values are written conditionally. If they are not |
| 1505 // present in the delayed install data, they should be removed when the | 1506 // present in the delayed install data, they should be removed when the |
| 1506 // delayed install is committed. | 1507 // delayed install is committed. |
| 1507 extension_dict->Remove(kPrefEphemeralApp, NULL); | 1508 extension_dict->Remove(kPrefEphemeralApp, nullptr); |
| 1508 | 1509 |
| 1509 // Commit the delayed install data. | 1510 // Commit the delayed install data. |
| 1510 for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd(); | 1511 for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd(); |
| 1511 it.Advance()) { | 1512 it.Advance()) { |
| 1512 extension_dict->Set(it.key(), it.value().DeepCopy()); | 1513 extension_dict->Set(it.key(), it.value().DeepCopy()); |
| 1513 } | 1514 } |
| 1514 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, | 1515 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, |
| 1515 suggested_page_ordinal, extension_dict); | 1516 suggested_page_ordinal, extension_dict); |
| 1516 return true; | 1517 return true; |
| 1517 } | 1518 } |
| 1518 | 1519 |
| 1519 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( | 1520 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( |
| 1520 const std::string& extension_id) const { | 1521 const std::string& extension_id) const { |
| 1521 const base::DictionaryValue* extension_prefs = | 1522 const base::DictionaryValue* extension_prefs = |
| 1522 GetExtensionPref(extension_id); | 1523 GetExtensionPref(extension_id); |
| 1523 if (!extension_prefs) | 1524 if (!extension_prefs) |
| 1524 return scoped_ptr<ExtensionInfo>(); | 1525 return scoped_ptr<ExtensionInfo>(); |
| 1525 | 1526 |
| 1526 const base::DictionaryValue* ext = NULL; | 1527 const base::DictionaryValue* ext = nullptr; |
| 1527 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) | 1528 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) |
| 1528 return scoped_ptr<ExtensionInfo>(); | 1529 return scoped_ptr<ExtensionInfo>(); |
| 1529 | 1530 |
| 1530 return GetInstalledInfoHelper(extension_id, ext); | 1531 return GetInstalledInfoHelper(extension_id, ext); |
| 1531 } | 1532 } |
| 1532 | 1533 |
| 1533 ExtensionPrefs::DelayReason ExtensionPrefs::GetDelayedInstallReason( | 1534 ExtensionPrefs::DelayReason ExtensionPrefs::GetDelayedInstallReason( |
| 1534 const std::string& extension_id) const { | 1535 const std::string& extension_id) const { |
| 1535 const base::DictionaryValue* extension_prefs = | 1536 const base::DictionaryValue* extension_prefs = |
| 1536 GetExtensionPref(extension_id); | 1537 GetExtensionPref(extension_id); |
| 1537 if (!extension_prefs) | 1538 if (!extension_prefs) |
| 1538 return DELAY_REASON_NONE; | 1539 return DELAY_REASON_NONE; |
| 1539 | 1540 |
| 1540 const base::DictionaryValue* ext = NULL; | 1541 const base::DictionaryValue* ext = nullptr; |
| 1541 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) | 1542 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) |
| 1542 return DELAY_REASON_NONE; | 1543 return DELAY_REASON_NONE; |
| 1543 | 1544 |
| 1544 int delay_reason; | 1545 int delay_reason; |
| 1545 if (!ext->GetInteger(kDelayedInstallReason, &delay_reason)) | 1546 if (!ext->GetInteger(kDelayedInstallReason, &delay_reason)) |
| 1546 return DELAY_REASON_NONE; | 1547 return DELAY_REASON_NONE; |
| 1547 | 1548 |
| 1548 return static_cast<DelayReason>(delay_reason); | 1549 return static_cast<DelayReason>(delay_reason); |
| 1549 } | 1550 } |
| 1550 | 1551 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1572 return true; | 1573 return true; |
| 1573 | 1574 |
| 1574 // Ephemerality was previously stored in the creation flags, so we must also | 1575 // Ephemerality was previously stored in the creation flags, so we must also |
| 1575 // check it for backcompatibility. | 1576 // check it for backcompatibility. |
| 1576 return (GetCreationFlags(extension_id) & Extension::IS_EPHEMERAL) != 0; | 1577 return (GetCreationFlags(extension_id) & Extension::IS_EPHEMERAL) != 0; |
| 1577 } | 1578 } |
| 1578 | 1579 |
| 1579 void ExtensionPrefs::OnEphemeralAppPromoted(const std::string& extension_id) { | 1580 void ExtensionPrefs::OnEphemeralAppPromoted(const std::string& extension_id) { |
| 1580 DCHECK(IsEphemeralApp(extension_id)); | 1581 DCHECK(IsEphemeralApp(extension_id)); |
| 1581 | 1582 |
| 1582 UpdateExtensionPref(extension_id, kPrefEphemeralApp, NULL); | 1583 UpdateExtensionPref(extension_id, kPrefEphemeralApp, nullptr); |
| 1583 | 1584 |
| 1584 // Ephemerality was previously stored in the creation flags, so ensure the bit | 1585 // Ephemerality was previously stored in the creation flags, so ensure the bit |
| 1585 // is cleared. | 1586 // is cleared. |
| 1586 int creation_flags = Extension::NO_FLAGS; | 1587 int creation_flags = Extension::NO_FLAGS; |
| 1587 if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) { | 1588 if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) { |
| 1588 if (creation_flags & Extension::IS_EPHEMERAL) { | 1589 if (creation_flags & Extension::IS_EPHEMERAL) { |
| 1589 creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL); | 1590 creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL); |
| 1590 UpdateExtensionPref(extension_id, | 1591 UpdateExtensionPref(extension_id, |
| 1591 kPrefCreationFlags, | 1592 kPrefCreationFlags, |
| 1592 new base::FundamentalValue(creation_flags)); | 1593 new base::FundamentalValue(creation_flags)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; | 1635 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; |
| 1635 if (WasInstalledByOem(extension_id)) | 1636 if (WasInstalledByOem(extension_id)) |
| 1636 creation_flags |= Extension::WAS_INSTALLED_BY_OEM; | 1637 creation_flags |= Extension::WAS_INSTALLED_BY_OEM; |
| 1637 } | 1638 } |
| 1638 return creation_flags; | 1639 return creation_flags; |
| 1639 } | 1640 } |
| 1640 | 1641 |
| 1641 int ExtensionPrefs::GetDelayedInstallCreationFlags( | 1642 int ExtensionPrefs::GetDelayedInstallCreationFlags( |
| 1642 const std::string& extension_id) const { | 1643 const std::string& extension_id) const { |
| 1643 int creation_flags = Extension::NO_FLAGS; | 1644 int creation_flags = Extension::NO_FLAGS; |
| 1644 const base::DictionaryValue* delayed_info = NULL; | 1645 const base::DictionaryValue* delayed_info = nullptr; |
| 1645 if (ReadPrefAsDictionary(extension_id, kDelayedInstallInfo, &delayed_info)) { | 1646 if (ReadPrefAsDictionary(extension_id, kDelayedInstallInfo, &delayed_info)) { |
| 1646 delayed_info->GetInteger(kPrefCreationFlags, &creation_flags); | 1647 delayed_info->GetInteger(kPrefCreationFlags, &creation_flags); |
| 1647 } | 1648 } |
| 1648 return creation_flags; | 1649 return creation_flags; |
| 1649 } | 1650 } |
| 1650 | 1651 |
| 1651 bool ExtensionPrefs::WasInstalledByDefault( | 1652 bool ExtensionPrefs::WasInstalledByDefault( |
| 1652 const std::string& extension_id) const { | 1653 const std::string& extension_id) const { |
| 1653 const base::DictionaryValue* dictionary = GetExtensionPref(extension_id); | 1654 const base::DictionaryValue* dictionary = GetExtensionPref(extension_id); |
| 1654 bool result = false; | 1655 bool result = false; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 ExtensionInfo* info = extensions_info->at(i).get(); | 1722 ExtensionInfo* info = extensions_info->at(i).get(); |
| 1722 out->push_back(info->extension_id); | 1723 out->push_back(info->extension_id); |
| 1723 } | 1724 } |
| 1724 } | 1725 } |
| 1725 | 1726 |
| 1726 // static | 1727 // static |
| 1727 ExtensionIdList ExtensionPrefs::GetExtensionsFrom( | 1728 ExtensionIdList ExtensionPrefs::GetExtensionsFrom( |
| 1728 const PrefService* pref_service) { | 1729 const PrefService* pref_service) { |
| 1729 ExtensionIdList result; | 1730 ExtensionIdList result; |
| 1730 | 1731 |
| 1731 const base::DictionaryValue* extension_prefs = NULL; | 1732 const base::DictionaryValue* extension_prefs = nullptr; |
| 1732 const base::Value* extension_prefs_value = | 1733 const base::Value* extension_prefs_value = |
| 1733 pref_service->GetUserPrefValue(pref_names::kExtensions); | 1734 pref_service->GetUserPrefValue(pref_names::kExtensions); |
| 1734 if (!extension_prefs_value || | 1735 if (!extension_prefs_value || |
| 1735 !extension_prefs_value->GetAsDictionary(&extension_prefs)) { | 1736 !extension_prefs_value->GetAsDictionary(&extension_prefs)) { |
| 1736 return result; // Empty set | 1737 return result; // Empty set |
| 1737 } | 1738 } |
| 1738 | 1739 |
| 1739 for (base::DictionaryValue::Iterator it(*extension_prefs); !it.IsAtEnd(); | 1740 for (base::DictionaryValue::Iterator it(*extension_prefs); !it.IsAtEnd(); |
| 1740 it.Advance()) { | 1741 it.Advance()) { |
| 1741 const base::DictionaryValue* ext = NULL; | 1742 const base::DictionaryValue* ext = nullptr; |
| 1742 if (!it.value().GetAsDictionary(&ext)) { | 1743 if (!it.value().GetAsDictionary(&ext)) { |
| 1743 NOTREACHED() << "Invalid pref for extension " << it.key(); | 1744 NOTREACHED() << "Invalid pref for extension " << it.key(); |
| 1744 continue; | 1745 continue; |
| 1745 } | 1746 } |
| 1746 if (!IsBlacklistBitSet(ext)) | 1747 if (!IsBlacklistBitSet(ext)) |
| 1747 result.push_back(it.key()); | 1748 result.push_back(it.key()); |
| 1748 } | 1749 } |
| 1749 return result; | 1750 return result; |
| 1750 } | 1751 } |
| 1751 | 1752 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 extension_pref_value_map_->GetEffectivePrefValue(pref_key, | 1811 extension_pref_value_map_->GetEffectivePrefValue(pref_key, |
| 1811 true, | 1812 true, |
| 1812 &has_incognito_pref_value); | 1813 &has_incognito_pref_value); |
| 1813 return has_incognito_pref_value; | 1814 return has_incognito_pref_value; |
| 1814 } | 1815 } |
| 1815 | 1816 |
| 1816 const base::DictionaryValue* ExtensionPrefs::GetGeometryCache( | 1817 const base::DictionaryValue* ExtensionPrefs::GetGeometryCache( |
| 1817 const std::string& extension_id) const { | 1818 const std::string& extension_id) const { |
| 1818 const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id); | 1819 const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id); |
| 1819 if (!extension_prefs) | 1820 if (!extension_prefs) |
| 1820 return NULL; | 1821 return nullptr; |
| 1821 | 1822 |
| 1822 const base::DictionaryValue* ext = NULL; | 1823 const base::DictionaryValue* ext = nullptr; |
| 1823 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext)) | 1824 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext)) |
| 1824 return NULL; | 1825 return nullptr; |
| 1825 | 1826 |
| 1826 return ext; | 1827 return ext; |
| 1827 } | 1828 } |
| 1828 | 1829 |
| 1829 void ExtensionPrefs::SetGeometryCache( | 1830 void ExtensionPrefs::SetGeometryCache( |
| 1830 const std::string& extension_id, | 1831 const std::string& extension_id, |
| 1831 scoped_ptr<base::DictionaryValue> cache) { | 1832 scoped_ptr<base::DictionaryValue> cache) { |
| 1832 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release()); | 1833 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release()); |
| 1833 } | 1834 } |
| 1834 | 1835 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2038 new base::FundamentalValue(extension->was_installed_by_oem())); | 2039 new base::FundamentalValue(extension->was_installed_by_oem())); |
| 2039 extension_dict->Set(kPrefInstallTime, | 2040 extension_dict->Set(kPrefInstallTime, |
| 2040 new base::StringValue( | 2041 new base::StringValue( |
| 2041 base::Int64ToString(install_time.ToInternalValue()))); | 2042 base::Int64ToString(install_time.ToInternalValue()))); |
| 2042 if (install_flags & kInstallFlagIsBlacklistedForMalware) | 2043 if (install_flags & kInstallFlagIsBlacklistedForMalware) |
| 2043 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); | 2044 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); |
| 2044 | 2045 |
| 2045 if (install_flags & kInstallFlagIsEphemeral) | 2046 if (install_flags & kInstallFlagIsEphemeral) |
| 2046 extension_dict->Set(kPrefEphemeralApp, new base::FundamentalValue(true)); | 2047 extension_dict->Set(kPrefEphemeralApp, new base::FundamentalValue(true)); |
| 2047 else | 2048 else |
| 2048 extension_dict->Remove(kPrefEphemeralApp, NULL); | 2049 extension_dict->Remove(kPrefEphemeralApp, nullptr); |
| 2049 | 2050 |
| 2050 base::FilePath::StringType path = MakePathRelative(install_directory_, | 2051 base::FilePath::StringType path = MakePathRelative(install_directory_, |
| 2051 extension->path()); | 2052 extension->path()); |
| 2052 extension_dict->Set(kPrefPath, new base::StringValue(path)); | 2053 extension_dict->Set(kPrefPath, new base::StringValue(path)); |
| 2053 if (!install_parameter.empty()) { | 2054 if (!install_parameter.empty()) { |
| 2054 extension_dict->Set(kPrefInstallParam, | 2055 extension_dict->Set(kPrefInstallParam, |
| 2055 new base::StringValue(install_parameter)); | 2056 new base::StringValue(install_parameter)); |
| 2056 } | 2057 } |
| 2057 // We store prefs about LOAD extensions, but don't cache their manifest | 2058 // We store prefs about LOAD extensions, but don't cache their manifest |
| 2058 // since it may change on disk. | 2059 // since it may change on disk. |
| 2059 if (!Manifest::IsUnpackedLocation(extension->location())) { | 2060 if (!Manifest::IsUnpackedLocation(extension->location())) { |
| 2060 extension_dict->Set(kPrefManifest, | 2061 extension_dict->Set(kPrefManifest, |
| 2061 extension->manifest()->value()->DeepCopy()); | 2062 extension->manifest()->value()->DeepCopy()); |
| 2062 } | 2063 } |
| 2063 | 2064 |
| 2064 // Only writes kPrefDoNotSync when it is not the default. | 2065 // Only writes kPrefDoNotSync when it is not the default. |
| 2065 if (install_flags & kInstallFlagDoNotSync) | 2066 if (install_flags & kInstallFlagDoNotSync) |
| 2066 extension_dict->Set(kPrefDoNotSync, new base::FundamentalValue(true)); | 2067 extension_dict->Set(kPrefDoNotSync, new base::FundamentalValue(true)); |
| 2067 else | 2068 else |
| 2068 extension_dict->Remove(kPrefDoNotSync, NULL); | 2069 extension_dict->Remove(kPrefDoNotSync, nullptr); |
| 2069 } | 2070 } |
| 2070 | 2071 |
| 2071 void ExtensionPrefs::InitExtensionControlledPrefs( | 2072 void ExtensionPrefs::InitExtensionControlledPrefs( |
| 2072 ExtensionPrefValueMap* value_map) { | 2073 ExtensionPrefValueMap* value_map) { |
| 2073 ExtensionIdList extension_ids; | 2074 ExtensionIdList extension_ids; |
| 2074 GetExtensions(&extension_ids); | 2075 GetExtensions(&extension_ids); |
| 2075 | 2076 |
| 2076 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); | 2077 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); |
| 2077 extension_id != extension_ids.end(); | 2078 extension_id != extension_ids.end(); |
| 2078 ++extension_id) { | 2079 ++extension_id) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 if (!extension_dict->HasKey(pref_names::kPrefContentSettings)) | 2131 if (!extension_dict->HasKey(pref_names::kPrefContentSettings)) |
| 2131 extension_dict->Set(pref_names::kPrefContentSettings, new base::ListValue); | 2132 extension_dict->Set(pref_names::kPrefContentSettings, new base::ListValue); |
| 2132 | 2133 |
| 2133 if (!extension_dict->HasKey(pref_names::kPrefIncognitoContentSettings)) { | 2134 if (!extension_dict->HasKey(pref_names::kPrefIncognitoContentSettings)) { |
| 2134 extension_dict->Set(pref_names::kPrefIncognitoContentSettings, | 2135 extension_dict->Set(pref_names::kPrefIncognitoContentSettings, |
| 2135 new base::ListValue); | 2136 new base::ListValue); |
| 2136 } | 2137 } |
| 2137 | 2138 |
| 2138 // If this point has been reached, any pending installs should be considered | 2139 // If this point has been reached, any pending installs should be considered |
| 2139 // out of date. | 2140 // out of date. |
| 2140 extension_dict->Remove(kDelayedInstallInfo, NULL); | 2141 extension_dict->Remove(kDelayedInstallInfo, nullptr); |
| 2141 | 2142 |
| 2142 // Clear state that may be registered from a previous install. | 2143 // Clear state that may be registered from a previous install. |
| 2143 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); | 2144 extension_dict->Remove(EventRouter::kRegisteredEvents, nullptr); |
| 2144 | 2145 |
| 2145 // FYI, all code below here races on sudden shutdown because |extension_dict|, | 2146 // FYI, all code below here races on sudden shutdown because |extension_dict|, |
| 2146 // |app_sorting_|, |extension_pref_value_map_|, and (potentially) observers | 2147 // |app_sorting_|, |extension_pref_value_map_|, and (potentially) observers |
| 2147 // are updated non-transactionally. This is probably not fixable without | 2148 // are updated non-transactionally. This is probably not fixable without |
| 2148 // nested transactional updates to pref dictionaries. | 2149 // nested transactional updates to pref dictionaries. |
| 2149 if (needs_sort_ordinal) | 2150 if (needs_sort_ordinal) |
| 2150 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); | 2151 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); |
| 2151 | 2152 |
| 2152 bool is_enabled = false; | 2153 bool is_enabled = false; |
| 2153 int initial_state; | 2154 int initial_state; |
| 2154 if (extension_dict->GetInteger(kPrefState, &initial_state)) { | 2155 if (extension_dict->GetInteger(kPrefState, &initial_state)) { |
| 2155 is_enabled = initial_state == Extension::ENABLED; | 2156 is_enabled = initial_state == Extension::ENABLED; |
| 2156 } | 2157 } |
| 2157 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); | 2158 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); |
| 2158 | 2159 |
| 2159 extension_pref_value_map_->RegisterExtension( | 2160 extension_pref_value_map_->RegisterExtension( |
| 2160 extension_id, install_time, is_enabled, is_incognito_enabled); | 2161 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2161 | 2162 |
| 2162 FOR_EACH_OBSERVER( | 2163 FOR_EACH_OBSERVER( |
| 2163 ExtensionPrefsObserver, | 2164 ExtensionPrefsObserver, |
| 2164 observer_list_, | 2165 observer_list_, |
| 2165 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2166 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2166 } | 2167 } |
| 2167 | 2168 |
| 2168 } // namespace extensions | 2169 } // namespace extensions |
| OLD | NEW |