| 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 29 matching lines...) Expand all Loading... |
| 210 } else { | 206 } else { |
| 211 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 207 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
| 212 install_ui_.reset( | 208 install_ui_.reset( |
| 213 chrome::CreateExtensionInstallPromptWithBrowser(GetCurrentBrowser())); | 209 chrome::CreateExtensionInstallPromptWithBrowser(GetCurrentBrowser())); |
| 214 install_ui_->ConfirmPermissions( | 210 install_ui_->ConfirmPermissions( |
| 215 this, GetExtension(), requested_permissions_.get()); | 211 this, GetExtension(), requested_permissions_.get()); |
| 216 } | 212 } |
| 217 | 213 |
| 218 return true; | 214 return true; |
| 219 } | 215 } |
| OLD | NEW |