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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/common/extensions/api/permissions.h" | 10 #include "chrome/common/extensions/api/permissions.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 if (!value) { | 49 if (!value) { |
50 permissions->permissions->push_back(i->name()); | 50 permissions->permissions->push_back(i->name()); |
51 } else { | 51 } else { |
52 std::string name(i->name()); | 52 std::string name(i->name()); |
53 std::string json; | 53 std::string json; |
54 base::JSONWriter::Write(value.get(), &json); | 54 base::JSONWriter::Write(value.get(), &json); |
55 permissions->permissions->push_back(name + kDelimiter + json); | 55 permissions->permissions->push_back(name + kDelimiter + json); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
| 59 // TODO(rpaquay): We currently don't expose manifest permissions |
| 60 // to apps/extensions via the permissions API. |
| 61 |
59 permissions->origins.reset(new std::vector<std::string>()); | 62 permissions->origins.reset(new std::vector<std::string>()); |
60 URLPatternSet hosts = set->explicit_hosts(); | 63 URLPatternSet hosts = set->explicit_hosts(); |
61 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) | 64 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) |
62 permissions->origins->push_back(i->GetAsString()); | 65 permissions->origins->push_back(i->GetAsString()); |
63 | 66 |
64 return scoped_ptr<Permissions>(permissions); | 67 return scoped_ptr<Permissions>(permissions); |
65 } | 68 } |
66 | 69 |
67 scoped_refptr<PermissionSet> UnpackPermissionSet( | 70 scoped_refptr<PermissionSet> UnpackPermissionSet( |
68 const Permissions& permissions, | 71 const Permissions& permissions, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (!permission_info) { | 117 if (!permission_info) { |
115 *error = ErrorUtils::FormatErrorMessage( | 118 *error = ErrorUtils::FormatErrorMessage( |
116 kUnknownPermissionError, *it); | 119 kUnknownPermissionError, *it); |
117 return NULL; | 120 return NULL; |
118 } | 121 } |
119 apis.insert(permission_info->id()); | 122 apis.insert(permission_info->id()); |
120 } | 123 } |
121 } | 124 } |
122 } | 125 } |
123 | 126 |
| 127 // TODO(rpaquay): We currently don't expose manifest permissions |
| 128 // to apps/extensions via the permissions API. |
| 129 ManifestPermissionSet manifest_permissions; |
| 130 |
124 URLPatternSet origins; | 131 URLPatternSet origins; |
125 if (permissions.origins.get()) { | 132 if (permissions.origins.get()) { |
126 for (std::vector<std::string>::iterator it = permissions.origins->begin(); | 133 for (std::vector<std::string>::iterator it = permissions.origins->begin(); |
127 it != permissions.origins->end(); ++it) { | 134 it != permissions.origins->end(); ++it) { |
128 int allowed_schemes = Extension::kValidHostPermissionSchemes; | 135 int allowed_schemes = Extension::kValidHostPermissionSchemes; |
129 if (!allow_file_access) | 136 if (!allow_file_access) |
130 allowed_schemes &= ~URLPattern::SCHEME_FILE; | 137 allowed_schemes &= ~URLPattern::SCHEME_FILE; |
131 URLPattern origin(allowed_schemes); | 138 URLPattern origin(allowed_schemes); |
132 URLPattern::ParseResult parse_result = origin.Parse(*it); | 139 URLPattern::ParseResult parse_result = origin.Parse(*it); |
133 if (URLPattern::PARSE_SUCCESS != parse_result) { | 140 if (URLPattern::PARSE_SUCCESS != parse_result) { |
134 *error = ErrorUtils::FormatErrorMessage( | 141 *error = ErrorUtils::FormatErrorMessage( |
135 kInvalidOrigin, | 142 kInvalidOrigin, |
136 *it, | 143 *it, |
137 URLPattern::GetParseResultString(parse_result)); | 144 URLPattern::GetParseResultString(parse_result)); |
138 return NULL; | 145 return NULL; |
139 } | 146 } |
140 origins.AddPattern(origin); | 147 origins.AddPattern(origin); |
141 } | 148 } |
142 } | 149 } |
143 | 150 |
144 return scoped_refptr<PermissionSet>( | 151 return scoped_refptr<PermissionSet>( |
145 new PermissionSet(apis, origins, URLPatternSet())); | 152 new PermissionSet(apis, manifest_permissions, origins, URLPatternSet())); |
146 } | 153 } |
147 | 154 |
148 } // namespace permissions_api_helpers | 155 } // namespace permissions_api_helpers |
149 } // namespace extensions | 156 } // namespace extensions |
OLD | NEW |