Chromium Code Reviews| 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 const URLPatternSet& new_value) { | 479 const URLPatternSet& new_value) { |
| 480 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); | 480 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); |
| 481 } | 481 } |
| 482 | 482 |
| 483 PermissionSet* ExtensionPrefs::ReadExtensionPrefPermissionSet( | 483 PermissionSet* ExtensionPrefs::ReadExtensionPrefPermissionSet( |
| 484 const std::string& extension_id, | 484 const std::string& extension_id, |
| 485 const std::string& pref_key) { | 485 const std::string& pref_key) { |
| 486 if (!GetExtensionPref(extension_id)) | 486 if (!GetExtensionPref(extension_id)) |
| 487 return NULL; | 487 return NULL; |
| 488 | 488 |
| 489 // Retrieve the API permissions. | 489 // Retrieve the API permissions. |
|
Mihai Parparita -not on Chrome
2012/08/10 00:16:16
Can you add a comment explaining how permissions a
Peng
2012/08/13 16:26:10
Done.
| |
| 490 APIPermissionSet apis; | 490 APIPermissionSet apis; |
| 491 const ListValue* api_values = NULL; | 491 const ListValue* api_values = NULL; |
| 492 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 492 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
| 493 if (ReadExtensionPrefList(extension_id, api_pref, &api_values)) { | 493 if (ReadExtensionPrefList(extension_id, api_pref, &api_values)) { |
| 494 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 494 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 495 for (size_t i = 0; i < api_values->GetSize(); ++i) { | 495 for (size_t i = 0; i < api_values->GetSize(); ++i) { |
| 496 const ListValue* permission_list = NULL; | |
| 496 std::string permission_name; | 497 std::string permission_name; |
| 497 if (api_values->GetString(i, &permission_name)) { | 498 if (api_values->GetString(i, &permission_name) || |
| 499 (api_values->GetList(i, &permission_list) && | |
| 500 permission_list->GetString(0, &permission_name))) { | |
| 498 APIPermission *permission = info->GetByName(permission_name); | 501 APIPermission *permission = info->GetByName(permission_name); |
| 499 if (permission) | 502 if (permission) { |
| 500 apis.insert(permission->id()); | 503 const Value* tmp = NULL; |
| 504 scoped_refptr<APIPermissionDetail> detail = | |
| 505 permission->CreateDetail(); | |
| 506 if (permission_list) { | |
| 507 if (permission_list->Get(1, &tmp)) | |
| 508 detail->FromValue(tmp); | |
| 509 else | |
| 510 DLOG(WARNING) << "Get detail from permission_list failed."; | |
| 511 } | |
| 512 apis.insert(detail); | |
| 513 } | |
| 501 } | 514 } |
| 502 } | 515 } |
| 503 } | 516 } |
| 504 | 517 |
| 505 // Retrieve the explicit host permissions. | 518 // Retrieve the explicit host permissions. |
| 506 URLPatternSet explicit_hosts; | 519 URLPatternSet explicit_hosts; |
| 507 ReadExtensionPrefURLPatternSet( | 520 ReadExtensionPrefURLPatternSet( |
| 508 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), | 521 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), |
| 509 &explicit_hosts, Extension::kValidHostPermissionSchemes); | 522 &explicit_hosts, Extension::kValidHostPermissionSchemes); |
| 510 | 523 |
| 511 // Retrieve the scriptable host permissions. | 524 // Retrieve the scriptable host permissions. |
| 512 URLPatternSet scriptable_hosts; | 525 URLPatternSet scriptable_hosts; |
| 513 ReadExtensionPrefURLPatternSet( | 526 ReadExtensionPrefURLPatternSet( |
| 514 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), | 527 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), |
| 515 &scriptable_hosts, UserScript::kValidUserScriptSchemes); | 528 &scriptable_hosts, UserScript::kValidUserScriptSchemes); |
| 516 | 529 |
| 517 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); | 530 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); |
| 518 } | 531 } |
| 519 | 532 |
| 520 void ExtensionPrefs::SetExtensionPrefPermissionSet( | 533 void ExtensionPrefs::SetExtensionPrefPermissionSet( |
| 521 const std::string& extension_id, | 534 const std::string& extension_id, |
| 522 const std::string& pref_key, | 535 const std::string& pref_key, |
| 523 const PermissionSet* new_value) { | 536 const PermissionSet* new_value) { |
| 524 // Set the API permissions. | 537 // Set the API permissions. |
| 525 ListValue* api_values = new ListValue(); | 538 ListValue* api_values = new ListValue(); |
| 526 APIPermissionSet apis = new_value->apis(); | 539 APIPermissionSet apis = new_value->apis(); |
| 527 PermissionsInfo* info = PermissionsInfo::GetInstance(); | |
| 528 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 540 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
| 529 for (APIPermissionSet::const_iterator i = apis.begin(); | 541 for (APIPermissionSet::const_iterator i = apis.begin(); |
| 530 i != apis.end(); ++i) { | 542 i != apis.end(); ++i) { |
| 531 APIPermission* perm = info->GetByID(*i); | 543 Value* detail = NULL; |
| 532 if (perm) | 544 i->ToValue(&detail); |
| 533 api_values->Append(Value::CreateStringValue(perm->name())); | 545 if (!detail) { |
| 546 api_values->Append(Value::CreateStringValue(i->name())); | |
| 547 } else { | |
| 548 ListValue* tmp = new ListValue(); | |
| 549 tmp->Append(Value::CreateStringValue(i->name())); | |
| 550 tmp->Append(detail); | |
| 551 api_values->Append(tmp); | |
| 552 } | |
| 534 } | 553 } |
| 535 UpdateExtensionPref(extension_id, api_pref, api_values); | 554 UpdateExtensionPref(extension_id, api_pref, api_values); |
| 536 | 555 |
| 537 // Set the explicit host permissions. | 556 // Set the explicit host permissions. |
| 538 if (!new_value->explicit_hosts().is_empty()) { | 557 if (!new_value->explicit_hosts().is_empty()) { |
| 539 SetExtensionPrefURLPatternSet(extension_id, | 558 SetExtensionPrefURLPatternSet(extension_id, |
| 540 JoinPrefs(pref_key, kPrefExplicitHosts), | 559 JoinPrefs(pref_key, kPrefExplicitHosts), |
| 541 new_value->explicit_hosts()); | 560 new_value->explicit_hosts()); |
| 542 } | 561 } |
| 543 | 562 |
| (...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2067 0, // default value | 2086 0, // default value |
| 2068 PrefService::UNSYNCABLE_PREF); | 2087 PrefService::UNSYNCABLE_PREF); |
| 2069 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 2088 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 2070 0, // default value | 2089 0, // default value |
| 2071 PrefService::UNSYNCABLE_PREF); | 2090 PrefService::UNSYNCABLE_PREF); |
| 2072 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 2091 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
| 2073 PrefService::UNSYNCABLE_PREF); | 2092 PrefService::UNSYNCABLE_PREF); |
| 2074 } | 2093 } |
| 2075 | 2094 |
| 2076 } // namespace extensions | 2095 } // namespace extensions |
| OLD | NEW |