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.h" | 5 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 8 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/permissions_updater.h" | 10 #include "chrome/browser/extensions/permissions_updater.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 APIPermissionSet apis = requested_permissions_->apis(); | 162 APIPermissionSet apis = requested_permissions_->apis(); |
163 for (APIPermissionSet::const_iterator i = apis.begin(); | 163 for (APIPermissionSet::const_iterator i = apis.begin(); |
164 i != apis.end(); ++i) { | 164 i != apis.end(); ++i) { |
165 if (!i->info()->supports_optional()) { | 165 if (!i->info()->supports_optional()) { |
166 error_ = ErrorUtils::FormatErrorMessage( | 166 error_ = ErrorUtils::FormatErrorMessage( |
167 kNotWhitelistedError, i->name()); | 167 kNotWhitelistedError, i->name()); |
168 return false; | 168 return false; |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
| 172 // Filter out permissions that do not need to be listed in the optional |
| 173 // section of the manifest. |
| 174 scoped_refptr<extensions::PermissionSet> |
| 175 manifest_required_requested_permissions = |
| 176 PermissionSet::ExcludeNotInManifestPermissions( |
| 177 requested_permissions_.get()); |
| 178 |
172 // The requested permissions must be defined as optional in the manifest. | 179 // The requested permissions must be defined as optional in the manifest. |
173 if (!GetExtension()->optional_permission_set()->Contains( | 180 if (!GetExtension()->optional_permission_set()->Contains( |
174 *requested_permissions_)) { | 181 *manifest_required_requested_permissions)) { |
175 error_ = kNotInOptionalPermissionsError; | 182 error_ = kNotInOptionalPermissionsError; |
176 results_ = Request::Results::Create(false); | 183 results_ = Request::Results::Create(false); |
177 return false; | 184 return false; |
178 } | 185 } |
179 | 186 |
180 // We don't need to prompt the user if the requested permissions are a subset | 187 // We don't need to prompt the user if the requested permissions are a subset |
181 // of the granted permissions set. | 188 // of the granted permissions set. |
182 scoped_refptr<const PermissionSet> granted = | 189 scoped_refptr<const PermissionSet> granted = |
183 prefs->GetGrantedPermissions(GetExtension()->id()); | 190 prefs->GetGrantedPermissions(GetExtension()->id()); |
184 if (granted.get() && granted->Contains(*requested_permissions_)) { | 191 if (granted.get() && granted->Contains(*requested_permissions_)) { |
(...skipping 22 matching lines...) Expand all Loading... |
207 InstallUIAbort(true); | 214 InstallUIAbort(true); |
208 } else { | 215 } else { |
209 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 216 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
210 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); | 217 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); |
211 install_ui_->ConfirmPermissions( | 218 install_ui_->ConfirmPermissions( |
212 this, GetExtension(), requested_permissions_.get()); | 219 this, GetExtension(), requested_permissions_.get()); |
213 } | 220 } |
214 | 221 |
215 return true; | 222 return true; |
216 } | 223 } |
OLD | NEW |