OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/admin_policy.h" | 10 #include "chrome/browser/extensions/admin_policy.h" |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 if (!GetExtensionPref(extension_id)) | 476 if (!GetExtensionPref(extension_id)) |
477 return NULL; | 477 return NULL; |
478 | 478 |
479 // Retrieve the API permissions. | 479 // Retrieve the API permissions. |
480 APIPermissionSet apis; | 480 APIPermissionSet apis; |
481 const ListValue* api_values = NULL; | 481 const ListValue* api_values = NULL; |
482 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 482 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
483 if (ReadExtensionPrefList(extension_id, api_pref, &api_values)) { | 483 if (ReadExtensionPrefList(extension_id, api_pref, &api_values)) { |
484 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 484 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
485 for (size_t i = 0; i < api_values->GetSize(); ++i) { | 485 for (size_t i = 0; i < api_values->GetSize(); ++i) { |
486 ListValue* permission_list = NULL; | |
486 std::string permission_name; | 487 std::string permission_name; |
487 if (api_values->GetString(i, &permission_name)) { | 488 if (api_values->GetString(i, &permission_name) || |
489 (api_values->GetList(i, &permission_list) && | |
490 permission_list->GetString(0, &permission_name))) { | |
488 APIPermission *permission = info->GetByName(permission_name); | 491 APIPermission *permission = info->GetByName(permission_name); |
489 if (permission) | 492 if (permission) { |
490 apis.insert(permission->id()); | 493 Value* tmp = NULL; |
494 if (!permission_list || !permission_list->Get(1, &tmp)) | |
495 tmp = NULL; | |
miket_OOO
2012/07/31 18:18:37
Does permission_list->Get() change the Value yet a
Peng
2012/07/31 19:32:28
Done. I checked ListValue::Get() the tmp will be u
| |
496 scoped_refptr<APIPermissionDetail> detail = | |
497 permission->CreateDetail(); | |
498 detail->FromValue(tmp); | |
miket_OOO
2012/07/31 18:18:37
Does this work if tmp is NULL? Should we even be a
Peng
2012/07/31 19:32:28
Done.
| |
499 apis.insert(detail); | |
500 } | |
491 } | 501 } |
492 } | 502 } |
493 } | 503 } |
494 | 504 |
495 // Retrieve the explicit host permissions. | 505 // Retrieve the explicit host permissions. |
496 URLPatternSet explicit_hosts; | 506 URLPatternSet explicit_hosts; |
497 ReadExtensionPrefURLPatternSet( | 507 ReadExtensionPrefURLPatternSet( |
498 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), | 508 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), |
499 &explicit_hosts, Extension::kValidHostPermissionSchemes); | 509 &explicit_hosts, Extension::kValidHostPermissionSchemes); |
500 | 510 |
501 // Retrieve the scriptable host permissions. | 511 // Retrieve the scriptable host permissions. |
502 URLPatternSet scriptable_hosts; | 512 URLPatternSet scriptable_hosts; |
503 ReadExtensionPrefURLPatternSet( | 513 ReadExtensionPrefURLPatternSet( |
504 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), | 514 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), |
505 &scriptable_hosts, UserScript::kValidUserScriptSchemes); | 515 &scriptable_hosts, UserScript::kValidUserScriptSchemes); |
506 | 516 |
507 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); | 517 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); |
508 } | 518 } |
509 | 519 |
510 void ExtensionPrefs::SetExtensionPrefPermissionSet( | 520 void ExtensionPrefs::SetExtensionPrefPermissionSet( |
511 const std::string& extension_id, | 521 const std::string& extension_id, |
512 const std::string& pref_key, | 522 const std::string& pref_key, |
513 const PermissionSet* new_value) { | 523 const PermissionSet* new_value) { |
514 // Set the API permissions. | 524 // Set the API permissions. |
515 ListValue* api_values = new ListValue(); | 525 ListValue* api_values = new ListValue(); |
516 APIPermissionSet apis = new_value->apis(); | 526 APIPermissionSet apis = new_value->apis(); |
517 PermissionsInfo* info = PermissionsInfo::GetInstance(); | |
518 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 527 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
519 for (APIPermissionSet::const_iterator i = apis.begin(); | 528 for (APIPermissionSet::const_iterator i = apis.begin(); |
520 i != apis.end(); ++i) { | 529 i != apis.end(); ++i) { |
521 APIPermission* perm = info->GetByID(*i); | 530 Value* detail = NULL; |
522 if (perm) | 531 i->ToValue(&detail); |
523 api_values->Append(Value::CreateStringValue(perm->name())); | 532 if (!detail) { |
533 api_values->Append(Value::CreateStringValue(i->name())); | |
534 } else { | |
535 ListValue* tmp = new ListValue(); | |
536 tmp->Append(Value::CreateStringValue(i->name())); | |
537 tmp->Append(detail); | |
538 api_values->Append(tmp); | |
539 } | |
524 } | 540 } |
525 UpdateExtensionPref(extension_id, api_pref, api_values); | 541 UpdateExtensionPref(extension_id, api_pref, api_values); |
526 | 542 |
527 // Set the explicit host permissions. | 543 // Set the explicit host permissions. |
528 if (!new_value->explicit_hosts().is_empty()) { | 544 if (!new_value->explicit_hosts().is_empty()) { |
529 SetExtensionPrefURLPatternSet(extension_id, | 545 SetExtensionPrefURLPatternSet(extension_id, |
530 JoinPrefs(pref_key, kPrefExplicitHosts), | 546 JoinPrefs(pref_key, kPrefExplicitHosts), |
531 new_value->explicit_hosts()); | 547 new_value->explicit_hosts()); |
532 } | 548 } |
533 | 549 |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1934 0, // default value | 1950 0, // default value |
1935 PrefService::UNSYNCABLE_PREF); | 1951 PrefService::UNSYNCABLE_PREF); |
1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1952 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1937 0, // default value | 1953 0, // default value |
1938 PrefService::UNSYNCABLE_PREF); | 1954 PrefService::UNSYNCABLE_PREF); |
1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1955 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
1940 PrefService::UNSYNCABLE_PREF); | 1956 PrefService::UNSYNCABLE_PREF); |
1941 } | 1957 } |
1942 | 1958 |
1943 } // namespace extensions | 1959 } // namespace extensions |
OLD | NEW |