| 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/extension_management.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 | 135 |
| 136 // static | 136 // static |
| 137 void PermissionsRequestFunction::SetIgnoreUserGestureForTests( | 137 void PermissionsRequestFunction::SetIgnoreUserGestureForTests( |
| 138 bool ignore) { | 138 bool ignore) { |
| 139 ignore_user_gesture_for_tests = ignore; | 139 ignore_user_gesture_for_tests = ignore; |
| 140 } | 140 } |
| 141 | 141 |
| 142 PermissionsRequestFunction::PermissionsRequestFunction() {} | 142 PermissionsRequestFunction::PermissionsRequestFunction() {} |
| 143 | 143 |
| 144 void PermissionsRequestFunction::InstallUIProceed() { | |
| 145 PermissionsUpdater perms_updater(GetProfile()); | |
| 146 perms_updater.AddPermissions(extension(), *requested_permissions_); | |
| 147 | |
| 148 results_ = Request::Results::Create(true); | |
| 149 SendResponse(true); | |
| 150 | |
| 151 Release(); // Balanced in RunAsync(). | |
| 152 } | |
| 153 | |
| 154 void PermissionsRequestFunction::InstallUIAbort(bool user_initiated) { | |
| 155 SendResponse(true); | |
| 156 | |
| 157 Release(); // Balanced in RunAsync(). | |
| 158 } | |
| 159 | |
| 160 PermissionsRequestFunction::~PermissionsRequestFunction() {} | 144 PermissionsRequestFunction::~PermissionsRequestFunction() {} |
| 161 | 145 |
| 162 bool PermissionsRequestFunction::RunAsync() { | 146 bool PermissionsRequestFunction::RunAsync() { |
| 163 results_ = Request::Results::Create(false); | 147 results_ = Request::Results::Create(false); |
| 164 | 148 |
| 165 if (!user_gesture() && | 149 if (!user_gesture() && |
| 166 !ignore_user_gesture_for_tests && | 150 !ignore_user_gesture_for_tests && |
| 167 extension_->location() != Manifest::COMPONENT) { | 151 extension_->location() != Manifest::COMPONENT) { |
| 168 error_ = kUserGestureRequiredError; | 152 error_ = kUserGestureRequiredError; |
| 169 return false; | 153 return false; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 204 |
| 221 // Filter out the granted permissions so we only prompt for new ones. | 205 // Filter out the granted permissions so we only prompt for new ones. |
| 222 requested_permissions_ = | 206 requested_permissions_ = |
| 223 PermissionSet::CreateDifference(*requested_permissions_, *granted); | 207 PermissionSet::CreateDifference(*requested_permissions_, *granted); |
| 224 | 208 |
| 225 // Filter out the active permissions. | 209 // Filter out the active permissions. |
| 226 requested_permissions_ = PermissionSet::CreateDifference( | 210 requested_permissions_ = PermissionSet::CreateDifference( |
| 227 *requested_permissions_, | 211 *requested_permissions_, |
| 228 extension()->permissions_data()->active_permissions()); | 212 extension()->permissions_data()->active_permissions()); |
| 229 | 213 |
| 230 AddRef(); // Balanced in InstallUIProceed() / InstallUIAbort(). | 214 AddRef(); // Balanced in OnInstallPromptDone(). |
| 231 | 215 |
| 232 // We don't need to show the prompt if there are no new warnings, or if | 216 // We don't need to show the prompt if there are no new warnings, or if |
| 233 // we're skipping the confirmation UI. All extension types but INTERNAL | 217 // we're skipping the confirmation UI. All extension types but INTERNAL |
| 234 // are allowed to silently increase their permission level. | 218 // are allowed to silently increase their permission level. |
| 235 const PermissionMessageProvider* message_provider = | 219 const PermissionMessageProvider* message_provider = |
| 236 PermissionMessageProvider::Get(); | 220 PermissionMessageProvider::Get(); |
| 237 bool has_no_warnings = | 221 bool has_no_warnings = |
| 238 message_provider->GetPermissionMessages( | 222 message_provider->GetPermissionMessages( |
| 239 message_provider->GetAllPermissionIDs( | 223 message_provider->GetAllPermissionIDs( |
| 240 *requested_permissions_, extension()->GetType())) | 224 *requested_permissions_, extension()->GetType())) |
| 241 .empty(); | 225 .empty(); |
| 242 if (auto_confirm_for_tests == PROCEED || has_no_warnings || | 226 if (auto_confirm_for_tests == PROCEED || has_no_warnings || |
| 243 extension_->location() == Manifest::COMPONENT) { | 227 extension_->location() == Manifest::COMPONENT) { |
| 244 InstallUIProceed(); | 228 OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED); |
| 245 } else if (auto_confirm_for_tests == ABORT) { | 229 } else if (auto_confirm_for_tests == ABORT) { |
| 246 // Pretend the user clicked cancel. | 230 // Pretend the user clicked cancel. |
| 247 InstallUIAbort(true); | 231 OnInstallPromptDone(ExtensionInstallPrompt::Result::USER_CANCELED); |
| 248 } else { | 232 } else { |
| 249 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 233 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
| 250 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); | 234 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); |
| 251 install_ui_->ShowDialog( | 235 install_ui_->ShowDialog( |
| 252 this, extension(), nullptr, | 236 base::Bind(&PermissionsRequestFunction::OnInstallPromptDone, this), |
| 237 extension(), nullptr, |
| 253 make_scoped_ptr(new ExtensionInstallPrompt::Prompt( | 238 make_scoped_ptr(new ExtensionInstallPrompt::Prompt( |
| 254 ExtensionInstallPrompt::PERMISSIONS_PROMPT)), | 239 ExtensionInstallPrompt::PERMISSIONS_PROMPT)), |
| 255 requested_permissions_->Clone(), | 240 requested_permissions_->Clone(), |
| 256 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 241 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 257 } | 242 } |
| 258 | 243 |
| 259 return true; | 244 return true; |
| 260 } | 245 } |
| 261 | 246 |
| 247 void PermissionsRequestFunction::OnInstallPromptDone( |
| 248 ExtensionInstallPrompt::Result result) { |
| 249 if (result == ExtensionInstallPrompt::Result::ACCEPTED) { |
| 250 PermissionsUpdater perms_updater(GetProfile()); |
| 251 perms_updater.AddPermissions(extension(), *requested_permissions_); |
| 252 |
| 253 results_ = Request::Results::Create(true); |
| 254 } |
| 255 |
| 256 SendResponse(true); |
| 257 Release(); // Balanced in RunAsync(). |
| 258 } |
| 259 |
| 262 } // namespace extensions | 260 } // namespace extensions |
| OLD | NEW |