| 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/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 9 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
| 10 #include "chrome/browser/extensions/extension_management.h" |
| 10 #include "chrome/browser/extensions/permissions_updater.h" | 11 #include "chrome/browser/extensions/permissions_updater.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/extensions/api/permissions.h" | 13 #include "chrome/common/extensions/api/permissions.h" |
| 13 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
| 14 #include "extensions/common/error_utils.h" | 15 #include "extensions/common/error_utils.h" |
| 15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/manifest_handlers/permissions_parser.h" | 17 #include "extensions/common/manifest_handlers/permissions_parser.h" |
| 17 #include "extensions/common/permissions/permission_message_provider.h" | 18 #include "extensions/common/permissions/permission_message_provider.h" |
| 18 #include "extensions/common/permissions/permissions_data.h" | 19 #include "extensions/common/permissions/permissions_data.h" |
| 19 #include "extensions/common/permissions/permissions_info.h" | 20 #include "extensions/common/permissions/permissions_info.h" |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 | 23 |
| 23 using api::permissions::Permissions; | 24 using api::permissions::Permissions; |
| 24 | 25 |
| 25 namespace Contains = api::permissions::Contains; | 26 namespace Contains = api::permissions::Contains; |
| 26 namespace GetAll = api::permissions::GetAll; | 27 namespace GetAll = api::permissions::GetAll; |
| 27 namespace Remove = api::permissions::Remove; | 28 namespace Remove = api::permissions::Remove; |
| 28 namespace Request = api::permissions::Request; | 29 namespace Request = api::permissions::Request; |
| 29 namespace helpers = permissions_api_helpers; | 30 namespace helpers = permissions_api_helpers; |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 34 const char kBlockedByEnterprisePolicy[] = |
| 35 "Permissions are blocked by enterprise policy."; |
| 33 const char kCantRemoveRequiredPermissionsError[] = | 36 const char kCantRemoveRequiredPermissionsError[] = |
| 34 "You cannot remove required permissions."; | 37 "You cannot remove required permissions."; |
| 35 const char kNotInOptionalPermissionsError[] = | 38 const char kNotInOptionalPermissionsError[] = |
| 36 "Optional permissions must be listed in extension manifest."; | 39 "Optional permissions must be listed in extension manifest."; |
| 37 const char kNotWhitelistedError[] = | 40 const char kNotWhitelistedError[] = |
| 38 "The optional permissions API does not support '*'."; | 41 "The optional permissions API does not support '*'."; |
| 39 const char kUserGestureRequiredError[] = | 42 const char kUserGestureRequiredError[] = |
| 40 "This function must be called during a user gesture"; | 43 "This function must be called during a user gesture"; |
| 41 | 44 |
| 42 enum AutoConfirmForTest { | 45 enum AutoConfirmForTest { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 176 } |
| 174 } | 177 } |
| 175 | 178 |
| 176 // The requested permissions must be defined as optional in the manifest. | 179 // The requested permissions must be defined as optional in the manifest. |
| 177 if (!PermissionsParser::GetOptionalPermissions(extension()) | 180 if (!PermissionsParser::GetOptionalPermissions(extension()) |
| 178 ->Contains(*requested_permissions_.get())) { | 181 ->Contains(*requested_permissions_.get())) { |
| 179 error_ = kNotInOptionalPermissionsError; | 182 error_ = kNotInOptionalPermissionsError; |
| 180 return false; | 183 return false; |
| 181 } | 184 } |
| 182 | 185 |
| 186 // Automatically declines api permissions requests, which are blocked by |
| 187 // enterprise policy. |
| 188 if (!ExtensionManagementFactory::GetForBrowserContext(GetProfile()) |
| 189 ->IsPermissionSetAllowed(extension()->id(), |
| 190 requested_permissions_)) { |
| 191 error_ = kBlockedByEnterprisePolicy; |
| 192 return false; |
| 193 } |
| 194 |
| 183 // We don't need to prompt the user if the requested permissions are a subset | 195 // We don't need to prompt the user if the requested permissions are a subset |
| 184 // of the granted permissions set. | 196 // of the granted permissions set. |
| 185 scoped_refptr<const PermissionSet> granted = | 197 scoped_refptr<const PermissionSet> granted = |
| 186 ExtensionPrefs::Get(GetProfile()) | 198 ExtensionPrefs::Get(GetProfile()) |
| 187 ->GetGrantedPermissions(extension()->id()); | 199 ->GetGrantedPermissions(extension()->id()); |
| 188 if (granted.get() && granted->Contains(*requested_permissions_.get())) { | 200 if (granted.get() && granted->Contains(*requested_permissions_.get())) { |
| 189 PermissionsUpdater perms_updater(GetProfile()); | 201 PermissionsUpdater perms_updater(GetProfile()); |
| 190 perms_updater.AddPermissions(extension(), requested_permissions_.get()); | 202 perms_updater.AddPermissions(extension(), requested_permissions_.get()); |
| 191 results_ = Request::Results::Create(true); | 203 results_ = Request::Results::Create(true); |
| 192 SendResponse(true); | 204 SendResponse(true); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 216 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 228 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
| 217 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); | 229 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); |
| 218 install_ui_->ConfirmPermissions( | 230 install_ui_->ConfirmPermissions( |
| 219 this, extension(), requested_permissions_.get()); | 231 this, extension(), requested_permissions_.get()); |
| 220 } | 232 } |
| 221 | 233 |
| 222 return true; | 234 return true; |
| 223 } | 235 } |
| 224 | 236 |
| 225 } // namespace extensions | 237 } // namespace extensions |
| OLD | NEW |