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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 const URLPatternSet& new_value) { | 488 const URLPatternSet& new_value) { |
489 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); | 489 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); |
490 } | 490 } |
491 | 491 |
492 PermissionSet* ExtensionPrefs::ReadExtensionPrefPermissionSet( | 492 PermissionSet* ExtensionPrefs::ReadExtensionPrefPermissionSet( |
493 const std::string& extension_id, | 493 const std::string& extension_id, |
494 const std::string& pref_key) { | 494 const std::string& pref_key) { |
495 if (!GetExtensionPref(extension_id)) | 495 if (!GetExtensionPref(extension_id)) |
496 return NULL; | 496 return NULL; |
497 | 497 |
498 // Retrieve the API permissions. | 498 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() |
| 499 // for api_values format. |
499 APIPermissionSet apis; | 500 APIPermissionSet apis; |
500 const ListValue* api_values = NULL; | 501 const ListValue* api_values = NULL; |
501 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 502 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
502 if (ReadExtensionPrefList(extension_id, api_pref, &api_values)) { | 503 if (ReadExtensionPrefList(extension_id, api_pref, &api_values)) { |
503 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 504 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
504 for (size_t i = 0; i < api_values->GetSize(); ++i) { | 505 for (size_t i = 0; i < api_values->GetSize(); ++i) { |
| 506 const ListValue* permission_list = NULL; |
505 std::string permission_name; | 507 std::string permission_name; |
506 if (api_values->GetString(i, &permission_name)) { | 508 if (api_values->GetString(i, &permission_name) || |
| 509 (api_values->GetList(i, &permission_list) && |
| 510 permission_list->GetString(0, &permission_name))) { |
507 APIPermission *permission = info->GetByName(permission_name); | 511 APIPermission *permission = info->GetByName(permission_name); |
508 if (permission) | 512 if (permission) { |
509 apis.insert(permission->id()); | 513 const Value* tmp = NULL; |
| 514 scoped_refptr<APIPermissionDetail> detail = |
| 515 permission->CreateDetail(); |
| 516 if (permission_list) { |
| 517 if (permission_list->Get(1, &tmp)) |
| 518 detail->FromValue(tmp); |
| 519 else |
| 520 DLOG(WARNING) << "Get detail from permission_list failed."; |
| 521 } |
| 522 apis.insert(detail); |
| 523 } |
510 } | 524 } |
511 } | 525 } |
512 } | 526 } |
513 | 527 |
514 // Retrieve the explicit host permissions. | 528 // Retrieve the explicit host permissions. |
515 URLPatternSet explicit_hosts; | 529 URLPatternSet explicit_hosts; |
516 ReadExtensionPrefURLPatternSet( | 530 ReadExtensionPrefURLPatternSet( |
517 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), | 531 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), |
518 &explicit_hosts, Extension::kValidHostPermissionSchemes); | 532 &explicit_hosts, Extension::kValidHostPermissionSchemes); |
519 | 533 |
520 // Retrieve the scriptable host permissions. | 534 // Retrieve the scriptable host permissions. |
521 URLPatternSet scriptable_hosts; | 535 URLPatternSet scriptable_hosts; |
522 ReadExtensionPrefURLPatternSet( | 536 ReadExtensionPrefURLPatternSet( |
523 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), | 537 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), |
524 &scriptable_hosts, UserScript::kValidUserScriptSchemes); | 538 &scriptable_hosts, UserScript::kValidUserScriptSchemes); |
525 | 539 |
526 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); | 540 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); |
527 } | 541 } |
528 | 542 |
529 void ExtensionPrefs::SetExtensionPrefPermissionSet( | 543 void ExtensionPrefs::SetExtensionPrefPermissionSet( |
530 const std::string& extension_id, | 544 const std::string& extension_id, |
531 const std::string& pref_key, | 545 const std::string& pref_key, |
532 const PermissionSet* new_value) { | 546 const PermissionSet* new_value) { |
533 // Set the API permissions. | 547 // Set the API permissions. |
| 548 // The format of api_values is: |
| 549 // [ "permission_name1", // permissions do not support detail. |
| 550 // "permission_name2", |
| 551 // [ "permission_name3", value ], |
| 552 // // permission supports detail, permission detail will be stored in value. |
| 553 // ... |
| 554 // ] |
534 ListValue* api_values = new ListValue(); | 555 ListValue* api_values = new ListValue(); |
535 APIPermissionSet apis = new_value->apis(); | 556 APIPermissionSet apis = new_value->apis(); |
536 PermissionsInfo* info = PermissionsInfo::GetInstance(); | |
537 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 557 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
538 for (APIPermissionSet::const_iterator i = apis.begin(); | 558 for (APIPermissionSet::const_iterator i = apis.begin(); |
539 i != apis.end(); ++i) { | 559 i != apis.end(); ++i) { |
540 APIPermission* perm = info->GetByID(*i); | 560 Value* detail = NULL; |
541 if (perm) | 561 i->ToValue(&detail); |
542 api_values->Append(Value::CreateStringValue(perm->name())); | 562 if (!detail) { |
| 563 api_values->Append(Value::CreateStringValue(i->name())); |
| 564 } else { |
| 565 ListValue* tmp = new ListValue(); |
| 566 tmp->Append(Value::CreateStringValue(i->name())); |
| 567 tmp->Append(detail); |
| 568 api_values->Append(tmp); |
| 569 } |
543 } | 570 } |
544 UpdateExtensionPref(extension_id, api_pref, api_values); | 571 UpdateExtensionPref(extension_id, api_pref, api_values); |
545 | 572 |
546 // Set the explicit host permissions. | 573 // Set the explicit host permissions. |
547 if (!new_value->explicit_hosts().is_empty()) { | 574 if (!new_value->explicit_hosts().is_empty()) { |
548 SetExtensionPrefURLPatternSet(extension_id, | 575 SetExtensionPrefURLPatternSet(extension_id, |
549 JoinPrefs(pref_key, kPrefExplicitHosts), | 576 JoinPrefs(pref_key, kPrefExplicitHosts), |
550 new_value->explicit_hosts()); | 577 new_value->explicit_hosts()); |
551 } | 578 } |
552 | 579 |
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 const ExtensionIdSet& strings) { | 2125 const ExtensionIdSet& strings) { |
2099 ListPrefUpdate update(prefs_, pref); | 2126 ListPrefUpdate update(prefs_, pref); |
2100 ListValue* list_of_values = update.Get(); | 2127 ListValue* list_of_values = update.Get(); |
2101 list_of_values->Clear(); | 2128 list_of_values->Clear(); |
2102 for (ExtensionIdSet::const_iterator iter = strings.begin(); | 2129 for (ExtensionIdSet::const_iterator iter = strings.begin(); |
2103 iter != strings.end(); ++iter) | 2130 iter != strings.end(); ++iter) |
2104 list_of_values->Append(new StringValue(*iter)); | 2131 list_of_values->Append(new StringValue(*iter)); |
2105 } | 2132 } |
2106 | 2133 |
2107 } // namespace extensions | 2134 } // namespace extensions |
OLD | NEW |