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/api/permissions/permissions_api_helpers.h" | 5 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/common/extensions/api/permissions.h" | 8 #include "chrome/common/extensions/api/permissions.h" |
9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
10 #include "chrome/common/extensions/extension_error_utils.h" | 10 #include "chrome/common/extensions/extension_error_utils.h" |
11 #include "chrome/common/extensions/extension_permission_set.h" | 11 #include "chrome/common/extensions/permissions/permission_set.h" |
| 12 #include "chrome/common/extensions/permissions/permissions_info.h" |
12 #include "chrome/common/extensions/url_pattern_set.h" | 13 #include "chrome/common/extensions/url_pattern_set.h" |
13 | 14 |
| 15 using extensions::APIPermission; |
| 16 using extensions::PermissionSet; |
| 17 using extensions::PermissionsInfo; |
| 18 |
14 namespace extensions { | 19 namespace extensions { |
15 | 20 |
16 using api::permissions::Permissions; | 21 using api::permissions::Permissions; |
17 | 22 |
18 namespace permissions_api_helpers { | 23 namespace permissions_api_helpers { |
19 | 24 |
20 namespace { | 25 namespace { |
21 | 26 |
22 const char kInvalidOrigin[] = | 27 const char kInvalidOrigin[] = |
23 "Invalid value for origin pattern *: *"; | 28 "Invalid value for origin pattern *: *"; |
24 const char kUnknownPermissionError[] = | 29 const char kUnknownPermissionError[] = |
25 "'*' is not a recognized permission."; | 30 "'*' is not a recognized permission."; |
26 | 31 |
27 } // namespace | 32 } // namespace |
28 | 33 |
29 scoped_ptr<Permissions> PackPermissionSet(const ExtensionPermissionSet* set) { | 34 scoped_ptr<Permissions> PackPermissionSet(const PermissionSet* set) { |
30 Permissions* permissions(new Permissions()); | 35 Permissions* permissions(new Permissions()); |
31 | 36 |
32 permissions->permissions.reset(new std::vector<std::string>()); | 37 permissions->permissions.reset(new std::vector<std::string>()); |
33 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | 38 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
34 for (ExtensionAPIPermissionSet::const_iterator i = set->apis().begin(); | 39 for (APIPermissionSet::const_iterator i = set->apis().begin(); |
35 i != set->apis().end(); ++i) { | 40 i != set->apis().end(); ++i) { |
36 permissions->permissions->push_back(info->GetByID(*i)->name()); | 41 permissions->permissions->push_back(info->GetByID(*i)->name()); |
37 } | 42 } |
38 | 43 |
39 permissions->origins.reset(new std::vector<std::string>()); | 44 permissions->origins.reset(new std::vector<std::string>()); |
40 URLPatternSet hosts = set->explicit_hosts(); | 45 URLPatternSet hosts = set->explicit_hosts(); |
41 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) | 46 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) |
42 permissions->origins->push_back(i->GetAsString()); | 47 permissions->origins->push_back(i->GetAsString()); |
43 | 48 |
44 return scoped_ptr<Permissions>(permissions); | 49 return scoped_ptr<Permissions>(permissions); |
45 } | 50 } |
46 | 51 |
47 scoped_refptr<ExtensionPermissionSet> UnpackPermissionSet( | 52 scoped_refptr<PermissionSet> UnpackPermissionSet( |
48 const Permissions& permissions, std::string* error) { | 53 const Permissions& permissions, std::string* error) { |
49 ExtensionAPIPermissionSet apis; | 54 APIPermissionSet apis; |
50 std::vector<std::string>* permissions_list = permissions.permissions.get(); | 55 std::vector<std::string>* permissions_list = permissions.permissions.get(); |
51 if (permissions_list) { | 56 if (permissions_list) { |
52 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | 57 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
53 for (std::vector<std::string>::iterator it = permissions_list->begin(); | 58 for (std::vector<std::string>::iterator it = permissions_list->begin(); |
54 it != permissions_list->end(); ++it) { | 59 it != permissions_list->end(); ++it) { |
55 ExtensionAPIPermission* permission = info->GetByName(*it); | 60 APIPermission* permission = info->GetByName(*it); |
56 if (!permission) { | 61 if (!permission) { |
57 *error = ExtensionErrorUtils::FormatErrorMessage( | 62 *error = ExtensionErrorUtils::FormatErrorMessage( |
58 kUnknownPermissionError, *it); | 63 kUnknownPermissionError, *it); |
59 return NULL; | 64 return NULL; |
60 } | 65 } |
61 apis.insert(permission->id()); | 66 apis.insert(permission->id()); |
62 } | 67 } |
63 } | 68 } |
64 | 69 |
65 URLPatternSet origins; | 70 URLPatternSet origins; |
66 if (permissions.origins.get()) { | 71 if (permissions.origins.get()) { |
67 for (std::vector<std::string>::iterator it = permissions.origins->begin(); | 72 for (std::vector<std::string>::iterator it = permissions.origins->begin(); |
68 it != permissions.origins->end(); ++it) { | 73 it != permissions.origins->end(); ++it) { |
69 URLPattern origin(Extension::kValidHostPermissionSchemes); | 74 URLPattern origin(Extension::kValidHostPermissionSchemes); |
70 URLPattern::ParseResult parse_result = origin.Parse(*it); | 75 URLPattern::ParseResult parse_result = origin.Parse(*it); |
71 if (URLPattern::PARSE_SUCCESS != parse_result) { | 76 if (URLPattern::PARSE_SUCCESS != parse_result) { |
72 *error = ExtensionErrorUtils::FormatErrorMessage( | 77 *error = ExtensionErrorUtils::FormatErrorMessage( |
73 kInvalidOrigin, | 78 kInvalidOrigin, |
74 *it, | 79 *it, |
75 URLPattern::GetParseResultString(parse_result)); | 80 URLPattern::GetParseResultString(parse_result)); |
76 return NULL; | 81 return NULL; |
77 } | 82 } |
78 origins.AddPattern(origin); | 83 origins.AddPattern(origin); |
79 } | 84 } |
80 } | 85 } |
81 | 86 |
82 return scoped_refptr<ExtensionPermissionSet>( | 87 return scoped_refptr<PermissionSet>( |
83 new ExtensionPermissionSet(apis, origins, URLPatternSet())); | 88 new PermissionSet(apis, origins, URLPatternSet())); |
84 } | 89 } |
85 | 90 |
86 } // namespace permissions_api | 91 } // namespace permissions_api |
87 } // namespace extensions | 92 } // namespace extensions |
OLD | NEW |