| 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/permissions_updater.h" | 10 #include "chrome/browser/extensions/permissions_updater.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/extensions/api/permissions.h" | 12 #include "chrome/common/extensions/api/permissions.h" |
| 13 #include "extensions/browser/extension_prefs.h" | 13 #include "extensions/browser/extension_prefs.h" |
| 14 #include "extensions/common/error_utils.h" | 14 #include "extensions/common/error_utils.h" |
| 15 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/manifest_handlers/permissions_parser.h" |
| 16 #include "extensions/common/permissions/permission_message_provider.h" | 17 #include "extensions/common/permissions/permission_message_provider.h" |
| 17 #include "extensions/common/permissions/permissions_data.h" | |
| 18 #include "extensions/common/permissions/permissions_info.h" | 18 #include "extensions/common/permissions/permissions_info.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 using api::permissions::Permissions; | 22 using api::permissions::Permissions; |
| 23 | 23 |
| 24 namespace Contains = api::permissions::Contains; | 24 namespace Contains = api::permissions::Contains; |
| 25 namespace GetAll = api::permissions::GetAll; | 25 namespace GetAll = api::permissions::GetAll; |
| 26 namespace Remove = api::permissions::Remove; | 26 namespace Remove = api::permissions::Remove; |
| 27 namespace Request = api::permissions::Request; | 27 namespace Request = api::permissions::Request; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 for (APIPermissionSet::const_iterator i = apis.begin(); | 89 for (APIPermissionSet::const_iterator i = apis.begin(); |
| 90 i != apis.end(); ++i) { | 90 i != apis.end(); ++i) { |
| 91 if (!i->info()->supports_optional()) { | 91 if (!i->info()->supports_optional()) { |
| 92 error_ = ErrorUtils::FormatErrorMessage( | 92 error_ = ErrorUtils::FormatErrorMessage( |
| 93 kNotWhitelistedError, i->name()); | 93 kNotWhitelistedError, i->name()); |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Make sure we don't remove any required pemissions. | 98 // Make sure we don't remove any required pemissions. |
| 99 const PermissionSet* required = | 99 scoped_refptr<const PermissionSet> required = |
| 100 PermissionsData::GetRequiredPermissions(extension); | 100 PermissionsParser::GetRequiredPermissions(extension); |
| 101 scoped_refptr<PermissionSet> intersection( | 101 scoped_refptr<PermissionSet> intersection( |
| 102 PermissionSet::CreateIntersection(permissions.get(), required)); | 102 PermissionSet::CreateIntersection(permissions.get(), required)); |
| 103 if (!intersection->IsEmpty()) { | 103 if (!intersection->IsEmpty()) { |
| 104 error_ = kCantRemoveRequiredPermissionsError; | 104 error_ = kCantRemoveRequiredPermissionsError; |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 | 107 |
| 108 PermissionsUpdater(GetProfile()) | 108 PermissionsUpdater(GetProfile()) |
| 109 .RemovePermissions(extension, permissions.get()); | 109 .RemovePermissions(extension, permissions.get()); |
| 110 results_ = Remove::Results::Create(true); | 110 results_ = Remove::Results::Create(true); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 for (APIPermissionSet::const_iterator i = apis.begin(); | 167 for (APIPermissionSet::const_iterator i = apis.begin(); |
| 168 i != apis.end(); ++i) { | 168 i != apis.end(); ++i) { |
| 169 if (!i->info()->supports_optional()) { | 169 if (!i->info()->supports_optional()) { |
| 170 error_ = ErrorUtils::FormatErrorMessage( | 170 error_ = ErrorUtils::FormatErrorMessage( |
| 171 kNotWhitelistedError, i->name()); | 171 kNotWhitelistedError, i->name()); |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 // The requested permissions must be defined as optional in the manifest. | 176 // The requested permissions must be defined as optional in the manifest. |
| 177 if (!PermissionsData::GetOptionalPermissions(GetExtension()) | 177 if (!PermissionsParser::GetOptionalPermissions(GetExtension()) |
| 178 ->Contains(*requested_permissions_.get())) { | 178 ->Contains(*requested_permissions_)) { |
| 179 error_ = kNotInOptionalPermissionsError; | 179 error_ = kNotInOptionalPermissionsError; |
| 180 return false; | 180 return false; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // We don't need to prompt the user if the requested permissions are a subset | 183 // We don't need to prompt the user if the requested permissions are a subset |
| 184 // of the granted permissions set. | 184 // of the granted permissions set. |
| 185 scoped_refptr<const PermissionSet> granted = ExtensionPrefs::Get( | 185 scoped_refptr<const PermissionSet> granted = ExtensionPrefs::Get( |
| 186 GetProfile())->GetGrantedPermissions(GetExtension()->id()); | 186 GetProfile())->GetGrantedPermissions(GetExtension()->id()); |
| 187 if (granted.get() && granted->Contains(*requested_permissions_.get())) { | 187 if (granted.get() && granted->Contains(*requested_permissions_.get())) { |
| 188 PermissionsUpdater perms_updater(GetProfile()); | 188 PermissionsUpdater perms_updater(GetProfile()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 214 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 214 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
| 215 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); | 215 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); |
| 216 install_ui_->ConfirmPermissions( | 216 install_ui_->ConfirmPermissions( |
| 217 this, GetExtension(), requested_permissions_.get()); | 217 this, GetExtension(), requested_permissions_.get()); |
| 218 } | 218 } |
| 219 | 219 |
| 220 return true; | 220 return true; |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace extensions | 223 } // namespace extensions |
| OLD | NEW |