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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/common/extensions/api/permissions.h" 13 #include "chrome/common/extensions/api/permissions.h"
13 #include "extensions/common/error_utils.h" 14 #include "extensions/common/error_utils.h"
14 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
15 #include "extensions/common/permissions/permission_set.h" 16 #include "extensions/common/permissions/permission_set.h"
16 #include "extensions/common/permissions/permissions_info.h" 17 #include "extensions/common/permissions/permissions_info.h"
17 #include "extensions/common/permissions/usb_device_permission.h" 18 #include "extensions/common/permissions/usb_device_permission.h"
18 #include "extensions/common/url_pattern_set.h" 19 #include "extensions/common/url_pattern_set.h"
19 20
20 namespace extensions { 21 namespace extensions {
21 22
22 using api::permissions::Permissions; 23 using api::permissions::Permissions;
23 24
24 namespace permissions_api_helpers { 25 namespace permissions_api_helpers {
25 26
26 namespace { 27 namespace {
27 28
28 const char kDelimiter[] = "|"; 29 const char kDelimiter[] = "|";
29 const char kInvalidParameter[] = 30 const char kInvalidParameter[] =
30 "Invalid argument for permission '*'."; 31 "Invalid argument for permission '*'.";
31 const char kInvalidOrigin[] = 32 const char kInvalidOrigin[] =
32 "Invalid value for origin pattern *: *"; 33 "Invalid value for origin pattern *: *";
33 const char kUnknownPermissionError[] = 34 const char kUnknownPermissionError[] =
34 "'*' is not a recognized permission."; 35 "'*' is not a recognized permission.";
35 const char kUnsupportedPermissionId[] = 36 const char kUnsupportedPermissionId[] =
36 "Only the usbDevices permission supports arguments."; 37 "Only the usbDevices permission supports arguments.";
37 38
38 } // namespace 39 } // namespace
39 40
40 scoped_ptr<Permissions> PackPermissionSet(const PermissionSet& set) { 41 std::unique_ptr<Permissions> PackPermissionSet(const PermissionSet& set) {
41 scoped_ptr<Permissions> permissions(new Permissions()); 42 std::unique_ptr<Permissions> permissions(new Permissions());
42 43
43 permissions->permissions.reset(new std::vector<std::string>()); 44 permissions->permissions.reset(new std::vector<std::string>());
44 for (const APIPermission* api : set.apis()) { 45 for (const APIPermission* api : set.apis()) {
45 scoped_ptr<base::Value> value(api->ToValue()); 46 std::unique_ptr<base::Value> value(api->ToValue());
46 if (!value) { 47 if (!value) {
47 permissions->permissions->push_back(api->name()); 48 permissions->permissions->push_back(api->name());
48 } else { 49 } else {
49 std::string name(api->name()); 50 std::string name(api->name());
50 std::string json; 51 std::string json;
51 base::JSONWriter::Write(*value, &json); 52 base::JSONWriter::Write(*value, &json);
52 permissions->permissions->push_back(name + kDelimiter + json); 53 permissions->permissions->push_back(name + kDelimiter + json);
53 } 54 }
54 } 55 }
55 56
56 // TODO(rpaquay): We currently don't expose manifest permissions 57 // TODO(rpaquay): We currently don't expose manifest permissions
57 // to apps/extensions via the permissions API. 58 // to apps/extensions via the permissions API.
58 59
59 permissions->origins.reset(new std::vector<std::string>()); 60 permissions->origins.reset(new std::vector<std::string>());
60 for (const URLPattern& pattern : set.explicit_hosts()) 61 for (const URLPattern& pattern : set.explicit_hosts())
61 permissions->origins->push_back(pattern.GetAsString()); 62 permissions->origins->push_back(pattern.GetAsString());
62 63
63 return permissions; 64 return permissions;
64 } 65 }
65 66
66 scoped_ptr<const PermissionSet> UnpackPermissionSet( 67 std::unique_ptr<const PermissionSet> UnpackPermissionSet(
67 const Permissions& permissions, 68 const Permissions& permissions,
68 bool allow_file_access, 69 bool allow_file_access,
69 std::string* error) { 70 std::string* error) {
70 DCHECK(error); 71 DCHECK(error);
71 APIPermissionSet apis; 72 APIPermissionSet apis;
72 std::vector<std::string>* permissions_list = permissions.permissions.get(); 73 std::vector<std::string>* permissions_list = permissions.permissions.get();
73 if (permissions_list) { 74 if (permissions_list) {
74 PermissionsInfo* info = PermissionsInfo::GetInstance(); 75 PermissionsInfo* info = PermissionsInfo::GetInstance();
75 for (std::vector<std::string>::iterator it = permissions_list->begin(); 76 for (std::vector<std::string>::iterator it = permissions_list->begin();
76 it != permissions_list->end(); ++it) { 77 it != permissions_list->end(); ++it) {
77 // This is a compromise: we currently can't switch to a blend of 78 // This is a compromise: we currently can't switch to a blend of
78 // objects/strings all the way through the API. Until then, put this 79 // objects/strings all the way through the API. Until then, put this
79 // processing here. 80 // processing here.
80 // http://code.google.com/p/chromium/issues/detail?id=162042 81 // http://code.google.com/p/chromium/issues/detail?id=162042
81 if (it->find(kDelimiter) != std::string::npos) { 82 if (it->find(kDelimiter) != std::string::npos) {
82 size_t delimiter = it->find(kDelimiter); 83 size_t delimiter = it->find(kDelimiter);
83 std::string permission_name = it->substr(0, delimiter); 84 std::string permission_name = it->substr(0, delimiter);
84 std::string permission_arg = it->substr(delimiter + 1); 85 std::string permission_arg = it->substr(delimiter + 1);
85 86
86 scoped_ptr<base::Value> permission_json = 87 std::unique_ptr<base::Value> permission_json =
87 base::JSONReader::Read(permission_arg); 88 base::JSONReader::Read(permission_arg);
88 if (!permission_json.get()) { 89 if (!permission_json.get()) {
89 *error = ErrorUtils::FormatErrorMessage(kInvalidParameter, *it); 90 *error = ErrorUtils::FormatErrorMessage(kInvalidParameter, *it);
90 return NULL; 91 return NULL;
91 } 92 }
92 93
93 APIPermission* permission = NULL; 94 APIPermission* permission = NULL;
94 95
95 // Explicitly check the permissions that accept arguments until the bug 96 // Explicitly check the permissions that accept arguments until the bug
96 // referenced above is fixed. 97 // referenced above is fixed.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 *error = ErrorUtils::FormatErrorMessage( 139 *error = ErrorUtils::FormatErrorMessage(
139 kInvalidOrigin, 140 kInvalidOrigin,
140 *it, 141 *it,
141 URLPattern::GetParseResultString(parse_result)); 142 URLPattern::GetParseResultString(parse_result));
142 return NULL; 143 return NULL;
143 } 144 }
144 origins.AddPattern(origin); 145 origins.AddPattern(origin);
145 } 146 }
146 } 147 }
147 148
148 return make_scoped_ptr( 149 return base::WrapUnique(
149 new PermissionSet(apis, manifest_permissions, origins, URLPatternSet())); 150 new PermissionSet(apis, manifest_permissions, origins, URLPatternSet()));
150 } 151 }
151 152
152 } // namespace permissions_api_helpers 153 } // namespace permissions_api_helpers
153 } // namespace extensions 154 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698