| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 bool RemovePermissionsFunction::RunImpl() { | 74 bool RemovePermissionsFunction::RunImpl() { |
| 75 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); | 75 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); |
| 76 EXTENSION_FUNCTION_VALIDATE(params.get()); | 76 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 77 | 77 |
| 78 scoped_refptr<PermissionSet> permissions = | 78 scoped_refptr<PermissionSet> permissions = |
| 79 helpers::UnpackPermissionSet(params->permissions, &error_); | 79 helpers::UnpackPermissionSet(params->permissions, &error_); |
| 80 if (!permissions.get()) | 80 if (!permissions.get()) |
| 81 return false; | 81 return false; |
| 82 | 82 |
| 83 const extensions::Extension* extension = GetExtension(); | 83 const extensions::Extension* extension = GetExtension(); |
| 84 PermissionsInfo* info = PermissionsInfo::GetInstance(); | |
| 85 | 84 |
| 86 // Make sure they're only trying to remove permissions supported by this API. | 85 // Make sure they're only trying to remove permissions supported by this API. |
| 87 APIPermissionSet apis = permissions->apis(); | 86 APIPermissionSet apis = permissions->apis(); |
| 88 for (APIPermissionSet::const_iterator i = apis.begin(); | 87 for (APIPermissionSet::const_iterator i = apis.begin(); |
| 89 i != apis.end(); ++i) { | 88 i != apis.end(); ++i) { |
| 90 const APIPermission* api = info->GetByID(*i); | 89 if (!i->permission()->supports_optional()) { |
| 91 if (!api->supports_optional()) { | |
| 92 error_ = ExtensionErrorUtils::FormatErrorMessage( | 90 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 93 kNotWhitelistedError, api->name()); | 91 kNotWhitelistedError, i->name()); |
| 94 return false; | 92 return false; |
| 95 } | 93 } |
| 96 } | 94 } |
| 97 | 95 |
| 98 // Make sure we don't remove any required pemissions. | 96 // Make sure we don't remove any required pemissions. |
| 99 const PermissionSet* required = extension->required_permission_set(); | 97 const PermissionSet* required = extension->required_permission_set(); |
| 100 scoped_refptr<PermissionSet> intersection( | 98 scoped_refptr<PermissionSet> intersection( |
| 101 PermissionSet::CreateIntersection(permissions.get(), required)); | 99 PermissionSet::CreateIntersection(permissions.get(), required)); |
| 102 if (!intersection->IsEmpty()) { | 100 if (!intersection->IsEmpty()) { |
| 103 error_ = kCantRemoveRequiredPermissionsError; | 101 error_ = kCantRemoveRequiredPermissionsError; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 147 } |
| 150 | 148 |
| 151 scoped_ptr<Request::Params> params(Request::Params::Create(*args_)); | 149 scoped_ptr<Request::Params> params(Request::Params::Create(*args_)); |
| 152 EXTENSION_FUNCTION_VALIDATE(params.get()); | 150 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 153 | 151 |
| 154 requested_permissions_ = | 152 requested_permissions_ = |
| 155 helpers::UnpackPermissionSet(params->permissions, &error_); | 153 helpers::UnpackPermissionSet(params->permissions, &error_); |
| 156 if (!requested_permissions_.get()) | 154 if (!requested_permissions_.get()) |
| 157 return false; | 155 return false; |
| 158 | 156 |
| 159 PermissionsInfo* info = PermissionsInfo::GetInstance(); | |
| 160 extensions::ExtensionPrefs* prefs = | 157 extensions::ExtensionPrefs* prefs = |
| 161 profile()->GetExtensionService()->extension_prefs(); | 158 profile()->GetExtensionService()->extension_prefs(); |
| 162 | 159 |
| 163 // Make sure they're only requesting permissions supported by this API. | 160 // Make sure they're only requesting permissions supported by this API. |
| 164 APIPermissionSet apis = requested_permissions_->apis(); | 161 APIPermissionSet apis = requested_permissions_->apis(); |
| 165 for (APIPermissionSet::const_iterator i = apis.begin(); | 162 for (APIPermissionSet::const_iterator i = apis.begin(); |
| 166 i != apis.end(); ++i) { | 163 i != apis.end(); ++i) { |
| 167 const APIPermission* api = info->GetByID(*i); | 164 if (!i->permission()->supports_optional()) { |
| 168 if (!api->supports_optional()) { | |
| 169 error_ = ExtensionErrorUtils::FormatErrorMessage( | 165 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 170 kNotWhitelistedError, api->name()); | 166 kNotWhitelistedError, i->name()); |
| 171 return false; | 167 return false; |
| 172 } | 168 } |
| 173 } | 169 } |
| 174 | 170 |
| 175 // The requested permissions must be defined as optional in the manifest. | 171 // The requested permissions must be defined as optional in the manifest. |
| 176 if (!GetExtension()->optional_permission_set()->Contains( | 172 if (!GetExtension()->optional_permission_set()->Contains( |
| 177 *requested_permissions_)) { | 173 *requested_permissions_)) { |
| 178 error_ = kNotInOptionalPermissionsError; | 174 error_ = kNotInOptionalPermissionsError; |
| 179 results_ = Request::Results::Create(false); | 175 results_ = Request::Results::Create(false); |
| 180 return false; | 176 return false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 195 // Filter out the granted permissions so we only prompt for new ones. | 191 // Filter out the granted permissions so we only prompt for new ones. |
| 196 requested_permissions_ = PermissionSet::CreateDifference( | 192 requested_permissions_ = PermissionSet::CreateDifference( |
| 197 requested_permissions_.get(), granted.get()); | 193 requested_permissions_.get(), granted.get()); |
| 198 | 194 |
| 199 AddRef(); // Balanced in InstallUIProceed() / InstallUIAbort(). | 195 AddRef(); // Balanced in InstallUIProceed() / InstallUIAbort(). |
| 200 | 196 |
| 201 // We don't need to show the prompt if there are no new warnings, or if | 197 // We don't need to show the prompt if there are no new warnings, or if |
| 202 // we're skipping the confirmation UI. All extension types but INTERNAL | 198 // we're skipping the confirmation UI. All extension types but INTERNAL |
| 203 // are allowed to silently increase their permission level. | 199 // are allowed to silently increase their permission level. |
| 204 bool has_no_warnings = requested_permissions_->GetWarningMessages( | 200 bool has_no_warnings = requested_permissions_->GetWarningMessages( |
| 205 GetExtension()->GetType()).size() == 0; | 201 GetExtension()->GetType()).empty(); |
| 206 if (auto_confirm_for_tests == PROCEED || has_no_warnings) { | 202 if (auto_confirm_for_tests == PROCEED || has_no_warnings) { |
| 207 InstallUIProceed(); | 203 InstallUIProceed(); |
| 208 } else if (auto_confirm_for_tests == ABORT) { | 204 } else if (auto_confirm_for_tests == ABORT) { |
| 209 // Pretend the user clicked cancel. | 205 // Pretend the user clicked cancel. |
| 210 InstallUIAbort(true); | 206 InstallUIAbort(true); |
| 211 } else { | 207 } else { |
| 212 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 208 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
| 213 install_ui_.reset( | 209 install_ui_.reset( |
| 214 chrome::CreateExtensionInstallPromptWithBrowser(GetCurrentBrowser())); | 210 chrome::CreateExtensionInstallPromptWithBrowser(GetCurrentBrowser())); |
| 215 install_ui_->ConfirmPermissions( | 211 install_ui_->ConfirmPermissions( |
| 216 this, GetExtension(), requested_permissions_.get()); | 212 this, GetExtension(), requested_permissions_.get()); |
| 217 } | 213 } |
| 218 | 214 |
| 219 return true; | 215 return true; |
| 220 } | 216 } |
| OLD | NEW |