Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "chrome/browser/download/download_permission_request.h" | ||||
6 | |||||
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 7 | #include <memory> |
8 | |||||
Florian Jacky | 11f9810 | 2025-05-20 15:57:18 | [diff] [blame] | 9 | #include "base/functional/callback_helpers.h" |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 11 | #include "chrome/grit/generated_resources.h" |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 12 | #include "components/content_settings/core/common/content_settings_types.h" |
Florian Jacky | d02023d | 2025-06-18 20:21:31 | [diff] [blame] | 13 | #include "components/permissions/permission_decision.h" |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 14 | #include "components/permissions/permission_request_data.h" |
Bret Sepulveda | 362cce4 | 2021-01-13 18:47:54 | [diff] [blame] | 15 | #include "components/permissions/request_type.h" |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 16 | #include "components/permissions/resolvers/content_setting_permission_resolver.h" |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 17 | #include "ui/base/l10n/l10n_util.h" |
18 | |||||
Xiaohan Wang | ab5fb91 | 2022-01-12 19:21:48 | [diff] [blame] | 19 | #if BUILDFLAG(IS_ANDROID) |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 20 | #include "chrome/browser/android/android_theme_resources.h" |
Mugdha Lakhani | 6b39f5fd | 2018-11-23 11:19:01 | [diff] [blame] | 21 | #include "components/url_formatter/elide_url.h" |
22 | #include "url/origin.h" | ||||
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 23 | #else |
Mugdha Lakhani | b676216 | 2020-03-30 10:23:25 | [diff] [blame] | 24 | #include "components/vector_icons/vector_icons.h" |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 25 | #endif |
26 | |||||
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 27 | DownloadPermissionRequest::DownloadPermissionRequest( |
Min Qin | 357184a | 2019-06-25 16:31:44 | [diff] [blame] | 28 | base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host, |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 29 | const url::Origin& requesting_origin) |
30 | : PermissionRequest( | ||||
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 31 | std::make_unique<permissions::PermissionRequestData>( |
32 | std::make_unique<permissions::ContentSettingPermissionResolver>( | ||||
33 | permissions::RequestType::kMultipleDownloads), | ||||
34 | /*user_gesture=*/false, | ||||
35 | requesting_origin.GetURL()), | ||||
Illia Klimov | e406ecc1 | 2022-11-22 15:53:29 | [diff] [blame] | 36 | base::BindRepeating(&DownloadPermissionRequest::PermissionDecided, |
Florian Jacky | 11f9810 | 2025-05-20 15:57:18 | [diff] [blame] | 37 | base::Unretained(this))), |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 38 | host_(host), |
39 | requesting_origin_(requesting_origin) {} | ||||
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 40 | |
Sorin Jianu | 057cba6a | 2024-11-29 05:49:34 | [diff] [blame] | 41 | DownloadPermissionRequest::~DownloadPermissionRequest() = default; |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 42 | |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 43 | void DownloadPermissionRequest::PermissionDecided( |
Florian Jacky | d02023d | 2025-06-18 20:21:31 | [diff] [blame] | 44 | PermissionDecision decision, |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 45 | bool is_final_decision, |
Chris Fredrickson | 173060c86 | 2025-05-14 14:23:01 | [diff] [blame] | 46 | const permissions::PermissionRequestData& request_data) { |
Florian Jacky | 2cb5ada | 2025-06-18 20:21:50 | [diff] [blame] | 47 | DCHECK(decision != PermissionDecision::kAllowThisTime); |
Illia Klimov | e406ecc1 | 2022-11-22 15:53:29 | [diff] [blame] | 48 | DCHECK(is_final_decision); |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 49 | if (!host_) |
50 | return; | ||||
51 | |||||
52 | // This may invalidate |host_|. | ||||
Florian Jacky | d02023d | 2025-06-18 20:21:31 | [diff] [blame] | 53 | if (decision == PermissionDecision::kAllow) { |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 54 | host_->Accept(requesting_origin_); |
Florian Jacky | d02023d | 2025-06-18 20:21:31 | [diff] [blame] | 55 | } else if (decision == PermissionDecision::kDeny) { |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 56 | host_->Cancel(requesting_origin_); |
57 | } else { | ||||
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 58 | host_->CancelOnce(requesting_origin_); |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 59 | } |
60 | } |