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

Side by Side Diff: extensions/common/permissions/media_galleries_permission.cc

Issue 795543002: Added PermissionIDSet to APIPermissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permissions_patch_1_static_initializer_fix
Patch Set: Removed unnecessary constructor and added tests for API permissions Created 6 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/common/permissions/media_galleries_permission.h" 5 #include "extensions/common/permissions/media_galleries_permission.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // No other permissions, so reaching this means 103 // No other permissions, so reaching this means
104 // MediaGalleriesPermissionData is probably out of sync in some way. 104 // MediaGalleriesPermissionData is probably out of sync in some way.
105 // Fail so developers notice this. 105 // Fail so developers notice this.
106 NOTREACHED(); 106 NOTREACHED();
107 return false; 107 return false;
108 } 108 }
109 109
110 return IsValidPermissionSet(has_read, has_copy_to, has_delete, error); 110 return IsValidPermissionSet(has_read, has_copy_to, has_delete, error);
111 } 111 }
112 112
113 PermissionIDSet MediaGalleriesPermission::GetPermissions() const {
114 DCHECK(HasMessages());
115 PermissionIDSet result;
116 AddMessagesAndPermissions(&result, NULL);
117 return result;
118 }
119
113 PermissionMessages MediaGalleriesPermission::GetMessages() const { 120 PermissionMessages MediaGalleriesPermission::GetMessages() const {
114 DCHECK(HasMessages()); 121 DCHECK(HasMessages());
115 PermissionMessages result; 122 PermissionMessages result;
123 AddMessagesAndPermissions(NULL, &result);
124 return result;
125 }
116 126
127 void MediaGalleriesPermission::AddMessagesAndPermissions(
128 PermissionIDSet* permission_ids,
129 PermissionMessages* permission_messages) const {
117 bool has_all_auto_detected = false; 130 bool has_all_auto_detected = false;
118 bool has_read = false; 131 bool has_read = false;
119 bool has_copy_to = false; 132 bool has_copy_to = false;
120 bool has_delete = false; 133 bool has_delete = false;
121 134
122 for (std::set<MediaGalleriesPermissionData>::const_iterator it = 135 for (std::set<MediaGalleriesPermissionData>::const_iterator it =
123 data_set_.begin(); it != data_set_.end(); ++it) { 136 data_set_.begin(); it != data_set_.end(); ++it) {
124 if (it->permission() == kAllAutoDetectedPermission) 137 if (it->permission() == kAllAutoDetectedPermission)
125 has_all_auto_detected = true; 138 has_all_auto_detected = true;
126 else if (it->permission() == kReadPermission) 139 else if (it->permission() == kReadPermission)
127 has_read = true; 140 has_read = true;
128 else if (it->permission() == kCopyToPermission) 141 else if (it->permission() == kCopyToPermission)
129 has_copy_to = true; 142 has_copy_to = true;
130 else if (it->permission() == kDeletePermission) 143 else if (it->permission() == kDeletePermission)
131 has_delete = true; 144 has_delete = true;
132 } 145 }
133 146
134 if (!IsValidPermissionSet(has_read, has_copy_to, has_delete, NULL)) { 147 if (!IsValidPermissionSet(has_read, has_copy_to, has_delete, NULL)) {
135 NOTREACHED(); 148 NOTREACHED();
136 return result; 149 return;
137 } 150 }
138 151
139 // If |has_all_auto_detected| is false, then Chrome will prompt the user at 152 // If |has_all_auto_detected| is false, then Chrome will prompt the user at
140 // runtime when the extension call the getMediaGalleries API. 153 // runtime when the extension call the getMediaGalleries API.
141 if (!has_all_auto_detected) 154 if (!has_all_auto_detected)
142 return result; 155 return;
143 // No access permission case. 156 // No access permission case.
144 if (!has_read) 157 if (!has_read)
145 return result; 158 return;
146 159
147 // Separate PermissionMessage IDs for read, copyTo, and delete. Otherwise an 160 // Separate PermissionMessage IDs for read, copyTo, and delete. Otherwise an
148 // extension can silently gain new access capabilities. 161 // extension can silently gain new access capabilities.
149 result.push_back(PermissionMessage( 162 if (permission_messages) {
150 PermissionMessage::kMediaGalleriesAllGalleriesRead, 163 permission_messages->push_back(PermissionMessage(
151 l10n_util::GetStringUTF16( 164 PermissionMessage::kMediaGalleriesAllGalleriesRead,
152 IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_READ))); 165 l10n_util::GetStringUTF16(
166 IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_READ)));
167 }
168 if (permission_ids) {
169 permission_ids->insert(APIPermission::kMediaGalleriesAllGalleriesRead);
170 }
153 171
154 // For copyTo and delete, the proper combined permission message will be 172 // For copyTo and delete, the proper combined permission message will be
155 // derived in ChromePermissionMessageProvider::GetWarningMessages(), such 173 // derived in ChromePermissionMessageProvider::GetWarningMessages(), such
156 // that the user get 1 entry for all media galleries access permissions, 174 // that the user get 1 entry for all media galleries access permissions,
157 // rather than several separate entries. 175 // rather than several separate entries.
158 if (has_copy_to) { 176 if (has_copy_to) {
159 result.push_back(PermissionMessage( 177 if (permission_messages) {
160 PermissionMessage::kMediaGalleriesAllGalleriesCopyTo, 178 permission_messages->push_back(PermissionMessage(
161 base::string16())); 179 PermissionMessage::kMediaGalleriesAllGalleriesCopyTo,
180 base::string16()));
181 }
182 if (permission_ids) {
183 permission_ids->insert(APIPermission::kMediaGalleriesAllGalleriesCopyTo);
184 }
162 } 185 }
163 if (has_delete) { 186 if (has_delete) {
164 result.push_back(PermissionMessage( 187 if (permission_messages) {
165 PermissionMessage::kMediaGalleriesAllGalleriesDelete, 188 permission_messages->push_back(PermissionMessage(
166 base::string16())); 189 PermissionMessage::kMediaGalleriesAllGalleriesDelete,
190 base::string16()));
191 }
192 if (permission_ids) {
193 permission_ids->insert(APIPermission::kMediaGalleriesAllGalleriesDelete);
194 }
167 } 195 }
168 return result; 196 return;
169 } 197 }
170 198
171 } // namespace extensions 199 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698