OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 if (has_delete) { | 31 if (has_delete) { |
32 if (has_read) | 32 if (has_read) |
33 return true; | 33 return true; |
34 if (error) | 34 if (error) |
35 *error = "delete permission requires read permission"; | 35 *error = "delete permission requires read permission"; |
36 return false; | 36 return false; |
37 } | 37 } |
38 return true; | 38 return true; |
39 } | 39 } |
40 | 40 |
41 // Adds the permissions from the |data_set| to the permission lists that are | 41 // Adds the permissions from the |data_set| to |ids|. |
42 // not NULL. If NULL, that list is ignored. | |
43 void AddPermissionsToLists( | 42 void AddPermissionsToLists( |
44 const std::set<MediaGalleriesPermissionData>& data_set, | 43 const std::set<MediaGalleriesPermissionData>& data_set, |
45 PermissionIDSet* ids, | 44 PermissionIDSet* ids) { |
46 PermissionMessages* messages) { | |
47 // TODO(sashab): Once GetMessages() is deprecated, move this logic back into | 45 // TODO(sashab): Once GetMessages() is deprecated, move this logic back into |
48 // GetPermissions(). | 46 // GetPermissions(). |
49 bool has_all_auto_detected = false; | 47 bool has_all_auto_detected = false; |
50 bool has_read = false; | 48 bool has_read = false; |
51 bool has_copy_to = false; | 49 bool has_copy_to = false; |
52 bool has_delete = false; | 50 bool has_delete = false; |
53 | 51 |
54 for (std::set<MediaGalleriesPermissionData>::const_iterator it = | 52 for (std::set<MediaGalleriesPermissionData>::const_iterator it = |
55 data_set.begin(); | 53 data_set.begin(); |
56 it != data_set.end(); ++it) { | 54 it != data_set.end(); ++it) { |
(...skipping 16 matching lines...) Expand all Loading... |
73 // If |has_all_auto_detected| is false, then Chrome will prompt the user at | 71 // If |has_all_auto_detected| is false, then Chrome will prompt the user at |
74 // runtime when the extension call the getMediaGalleries API. | 72 // runtime when the extension call the getMediaGalleries API. |
75 if (!has_all_auto_detected) | 73 if (!has_all_auto_detected) |
76 return; | 74 return; |
77 // No access permission case. | 75 // No access permission case. |
78 if (!has_read) | 76 if (!has_read) |
79 return; | 77 return; |
80 | 78 |
81 // Separate PermissionMessage IDs for read, copyTo, and delete. Otherwise an | 79 // Separate PermissionMessage IDs for read, copyTo, and delete. Otherwise an |
82 // extension can silently gain new access capabilities. | 80 // extension can silently gain new access capabilities. |
83 if (messages) { | 81 ids->insert(APIPermission::kMediaGalleriesAllGalleriesRead); |
84 messages->push_back(PermissionMessage( | |
85 PermissionMessage::kMediaGalleriesAllGalleriesRead, | |
86 l10n_util::GetStringUTF16( | |
87 IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_READ))); | |
88 } | |
89 if (ids) | |
90 ids->insert(APIPermission::kMediaGalleriesAllGalleriesRead); | |
91 | 82 |
92 // For copyTo and delete, the proper combined permission message will be | 83 // For copyTo and delete, the proper combined permission message will be |
93 // derived in ChromePermissionMessageProvider::GetWarningMessages(), such | 84 // derived in ChromePermissionMessageProvider::GetWarningMessages(), such |
94 // that the user get 1 entry for all media galleries access permissions, | 85 // that the user get 1 entry for all media galleries access permissions, |
95 // rather than several separate entries. | 86 // rather than several separate entries. |
96 if (has_copy_to) { | 87 if (has_copy_to) |
97 if (messages) { | 88 ids->insert(APIPermission::kMediaGalleriesAllGalleriesCopyTo); |
98 messages->push_back(PermissionMessage( | 89 if (has_delete) |
99 PermissionMessage::kMediaGalleriesAllGalleriesCopyTo, | 90 ids->insert(APIPermission::kMediaGalleriesAllGalleriesDelete); |
100 base::string16())); | |
101 } | |
102 if (ids) | |
103 ids->insert(APIPermission::kMediaGalleriesAllGalleriesCopyTo); | |
104 } | |
105 if (has_delete) { | |
106 if (messages) { | |
107 messages->push_back(PermissionMessage( | |
108 PermissionMessage::kMediaGalleriesAllGalleriesDelete, | |
109 base::string16())); | |
110 } | |
111 if (ids) | |
112 ids->insert(APIPermission::kMediaGalleriesAllGalleriesDelete); | |
113 } | |
114 return; | |
115 } | 91 } |
116 | 92 |
117 } // namespace | 93 } // namespace |
118 | 94 |
119 const char MediaGalleriesPermission::kAllAutoDetectedPermission[] = | 95 const char MediaGalleriesPermission::kAllAutoDetectedPermission[] = |
120 "allAutoDetected"; | 96 "allAutoDetected"; |
121 const char MediaGalleriesPermission::kScanPermission[] = "scan"; | 97 const char MediaGalleriesPermission::kScanPermission[] = "scan"; |
122 const char MediaGalleriesPermission::kReadPermission[] = "read"; | 98 const char MediaGalleriesPermission::kReadPermission[] = "read"; |
123 const char MediaGalleriesPermission::kCopyToPermission[] = "copyTo"; | 99 const char MediaGalleriesPermission::kCopyToPermission[] = "copyTo"; |
124 const char MediaGalleriesPermission::kDeletePermission[] = "delete"; | 100 const char MediaGalleriesPermission::kDeletePermission[] = "delete"; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // Fail so developers notice this. | 157 // Fail so developers notice this. |
182 NOTREACHED(); | 158 NOTREACHED(); |
183 return false; | 159 return false; |
184 } | 160 } |
185 | 161 |
186 return IsValidPermissionSet(has_read, has_copy_to, has_delete, error); | 162 return IsValidPermissionSet(has_read, has_copy_to, has_delete, error); |
187 } | 163 } |
188 | 164 |
189 PermissionIDSet MediaGalleriesPermission::GetPermissions() const { | 165 PermissionIDSet MediaGalleriesPermission::GetPermissions() const { |
190 PermissionIDSet result; | 166 PermissionIDSet result; |
191 AddPermissionsToLists(data_set_, &result, NULL); | 167 AddPermissionsToLists(data_set_, &result); |
192 return result; | 168 return result; |
193 } | 169 } |
194 | 170 |
195 } // namespace extensions | 171 } // namespace extensions |
OLD | NEW |