Chromium Code Reviews| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 scoped_refptr<const PermissionSet> required = | 99 scoped_refptr<const PermissionSet> required = |
| 100 PermissionsParser::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.get())); |
| 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); |
| 111 return true; | 111 return true; |
| 112 } | 112 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 (!PermissionsParser::GetOptionalPermissions(extension()) | 177 if (!PermissionsParser::GetOptionalPermissions(extension()) |
| 178 ->Contains(*requested_permissions_)) { | 178 ->Contains(*requested_permissions_.get())) { |
|
Jeffrey Yasskin
2014/08/26 01:14:16
You shouldn't need to add a .get() to something th
dcheng
2014/08/26 01:26:00
scoped_refptr doesn't implement operator*, for bet
| |
| 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 = | 185 scoped_refptr<const PermissionSet> granted = |
| 186 ExtensionPrefs::Get(GetProfile()) | 186 ExtensionPrefs::Get(GetProfile()) |
| 187 ->GetGrantedPermissions(extension()->id()); | 187 ->GetGrantedPermissions(extension()->id()); |
| 188 if (granted.get() && granted->Contains(*requested_permissions_.get())) { | 188 if (granted.get() && granted->Contains(*requested_permissions_.get())) { |
| 189 PermissionsUpdater perms_updater(GetProfile()); | 189 PermissionsUpdater perms_updater(GetProfile()); |
| 190 perms_updater.AddPermissions(extension(), requested_permissions_.get()); | 190 perms_updater.AddPermissions(extension(), requested_permissions_.get()); |
| 191 results_ = Request::Results::Create(true); | 191 results_ = Request::Results::Create(true); |
| 192 SendResponse(true); | 192 SendResponse(true); |
| 193 return true; | 193 return true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Filter out the granted permissions so we only prompt for new ones. | 196 // Filter out the granted permissions so we only prompt for new ones. |
| 197 requested_permissions_ = PermissionSet::CreateDifference( | 197 requested_permissions_ = PermissionSet::CreateDifference( |
| 198 requested_permissions_.get(), granted.get()); | 198 requested_permissions_.get(), granted.get()); |
| 199 | 199 |
| 200 AddRef(); // Balanced in InstallUIProceed() / InstallUIAbort(). | 200 AddRef(); // Balanced in InstallUIProceed() / InstallUIAbort(). |
| 201 | 201 |
| 202 // We don't need to show the prompt if there are no new warnings, or if | 202 // We don't need to show the prompt if there are no new warnings, or if |
| 203 // we're skipping the confirmation UI. All extension types but INTERNAL | 203 // we're skipping the confirmation UI. All extension types but INTERNAL |
| 204 // are allowed to silently increase their permission level. | 204 // are allowed to silently increase their permission level. |
| 205 bool has_no_warnings = | 205 bool has_no_warnings = PermissionMessageProvider::Get() |
| 206 PermissionMessageProvider::Get() | 206 ->GetWarningMessages(requested_permissions_.get(), |
| 207 ->GetWarningMessages(requested_permissions_, extension()->GetType()) | 207 extension()->GetType()) |
| 208 .empty(); | 208 .empty(); |
| 209 if (auto_confirm_for_tests == PROCEED || has_no_warnings || | 209 if (auto_confirm_for_tests == PROCEED || has_no_warnings || |
| 210 extension_->location() == Manifest::COMPONENT) { | 210 extension_->location() == Manifest::COMPONENT) { |
| 211 InstallUIProceed(); | 211 InstallUIProceed(); |
| 212 } else if (auto_confirm_for_tests == ABORT) { | 212 } else if (auto_confirm_for_tests == ABORT) { |
| 213 // Pretend the user clicked cancel. | 213 // Pretend the user clicked cancel. |
| 214 InstallUIAbort(true); | 214 InstallUIAbort(true); |
| 215 } else { | 215 } else { |
| 216 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 216 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
| 217 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); | 217 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); |
| 218 install_ui_->ConfirmPermissions( | 218 install_ui_->ConfirmPermissions( |
| 219 this, extension(), requested_permissions_.get()); | 219 this, extension(), requested_permissions_.get()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 return true; | 222 return true; |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace extensions | 225 } // namespace extensions |
| OLD | NEW |