Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/extensions/api/permissions/permissions_api_helpers.cc

Issue 141743005: Extensions: Make it possible for permission parsing code to return a detailed error message. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) 64 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i)
65 permissions->origins->push_back(i->GetAsString()); 65 permissions->origins->push_back(i->GetAsString());
66 66
67 return scoped_ptr<Permissions>(permissions); 67 return scoped_ptr<Permissions>(permissions);
68 } 68 }
69 69
70 scoped_refptr<PermissionSet> UnpackPermissionSet( 70 scoped_refptr<PermissionSet> UnpackPermissionSet(
71 const Permissions& permissions, 71 const Permissions& permissions,
72 bool allow_file_access, 72 bool allow_file_access,
73 std::string* error) { 73 std::string* error) {
74 DCHECK(error);
74 APIPermissionSet apis; 75 APIPermissionSet apis;
75 std::vector<std::string>* permissions_list = permissions.permissions.get(); 76 std::vector<std::string>* permissions_list = permissions.permissions.get();
76 if (permissions_list) { 77 if (permissions_list) {
77 PermissionsInfo* info = PermissionsInfo::GetInstance(); 78 PermissionsInfo* info = PermissionsInfo::GetInstance();
78 for (std::vector<std::string>::iterator it = permissions_list->begin(); 79 for (std::vector<std::string>::iterator it = permissions_list->begin();
79 it != permissions_list->end(); ++it) { 80 it != permissions_list->end(); ++it) {
80 // This is a compromise: we currently can't switch to a blend of 81 // This is a compromise: we currently can't switch to a blend of
81 // objects/strings all the way through the API. Until then, put this 82 // objects/strings all the way through the API. Until then, put this
82 // processing here. 83 // processing here.
83 // http://code.google.com/p/chromium/issues/detail?id=162042 84 // http://code.google.com/p/chromium/issues/detail?id=162042
(...skipping 16 matching lines...) Expand all
100 const APIPermissionInfo* usb_device_permission_info = 101 const APIPermissionInfo* usb_device_permission_info =
101 info->GetByID(APIPermission::kUsbDevice); 102 info->GetByID(APIPermission::kUsbDevice);
102 if (permission_name == usb_device_permission_info->name()) { 103 if (permission_name == usb_device_permission_info->name()) {
103 permission = new UsbDevicePermission(usb_device_permission_info); 104 permission = new UsbDevicePermission(usb_device_permission_info);
104 } else { 105 } else {
105 *error = kUnsupportedPermissionId; 106 *error = kUnsupportedPermissionId;
106 return NULL; 107 return NULL;
107 } 108 }
108 109
109 CHECK(permission); 110 CHECK(permission);
110 if (!permission->FromValue(permission_json.get())) { 111 if (!permission->FromValue(permission_json.get(), NULL)) {
111 *error = ErrorUtils::FormatErrorMessage(kInvalidParameter, *it); 112 *error = ErrorUtils::FormatErrorMessage(kInvalidParameter, *it);
112 return NULL; 113 return NULL;
113 } 114 }
114 apis.insert(permission); 115 apis.insert(permission);
115 } else { 116 } else {
116 const APIPermissionInfo* permission_info = info->GetByName(*it); 117 const APIPermissionInfo* permission_info = info->GetByName(*it);
117 if (!permission_info) { 118 if (!permission_info) {
118 *error = ErrorUtils::FormatErrorMessage( 119 *error = ErrorUtils::FormatErrorMessage(
119 kUnknownPermissionError, *it); 120 kUnknownPermissionError, *it);
120 return NULL; 121 return NULL;
(...skipping 26 matching lines...) Expand all
147 origins.AddPattern(origin); 148 origins.AddPattern(origin);
148 } 149 }
149 } 150 }
150 151
151 return scoped_refptr<PermissionSet>( 152 return scoped_refptr<PermissionSet>(
152 new PermissionSet(apis, manifest_permissions, origins, URLPatternSet())); 153 new PermissionSet(apis, manifest_permissions, origins, URLPatternSet()));
153 } 154 }
154 155
155 } // namespace permissions_api_helpers 156 } // namespace permissions_api_helpers
156 } // namespace extensions 157 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698