[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 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 | |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 7 | #include "build/build_config.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 8 | #include "chrome/grit/generated_resources.h" |
Bret Sepulveda | 362cce4 | 2021-01-13 18:47:54 | [diff] [blame] | 9 | #include "components/permissions/request_type.h" |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 10 | #include "ui/base/l10n/l10n_util.h" |
| 11 | |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 12 | #if defined(OS_ANDROID) |
| 13 | #include "chrome/browser/android/android_theme_resources.h" |
Mugdha Lakhani | 6b39f5fd | 2018-11-23 11:19:01 | [diff] [blame] | 14 | #include "components/url_formatter/elide_url.h" |
| 15 | #include "url/origin.h" |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 16 | #else |
Mugdha Lakhani | b676216 | 2020-03-30 10:23:25 | [diff] [blame] | 17 | #include "components/vector_icons/vector_icons.h" |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 18 | #endif |
| 19 | |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 20 | DownloadPermissionRequest::DownloadPermissionRequest( |
Min Qin | 357184a | 2019-06-25 16:31:44 | [diff] [blame] | 21 | base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host, |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 22 | const url::Origin& requesting_origin) |
| 23 | : PermissionRequest( |
| 24 | requesting_origin.GetURL(), |
| 25 | permissions::RequestType::kMultipleDownloads, |
| 26 | /*has_gesture=*/false, |
| 27 | base::BindOnce(&DownloadPermissionRequest::PermissionDecided, |
| 28 | base::Unretained(this)), |
| 29 | base::BindOnce(&DownloadPermissionRequest::DeleteRequest, |
| 30 | base::Unretained(this))), |
| 31 | host_(host), |
| 32 | requesting_origin_(requesting_origin) {} |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 33 | |
| 34 | DownloadPermissionRequest::~DownloadPermissionRequest() {} |
| 35 | |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 36 | void DownloadPermissionRequest::PermissionDecided(ContentSetting result, |
| 37 | bool is_one_time) { |
Ravjit Singh Uppal | c73b5a6 | 2020-11-13 01:38:52 | [diff] [blame] | 38 | DCHECK(!is_one_time); |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 39 | if (!host_) |
| 40 | return; |
| 41 | |
| 42 | // This may invalidate |host_|. |
| 43 | if (result == ContentSetting::CONTENT_SETTING_ALLOW) { |
| 44 | host_->Accept(requesting_origin_); |
| 45 | } else if (result == ContentSetting::CONTENT_SETTING_BLOCK) { |
| 46 | host_->Cancel(requesting_origin_); |
| 47 | } else { |
| 48 | DCHECK_EQ(CONTENT_SETTING_DEFAULT, result); |
| 49 | host_->CancelOnce(requesting_origin_); |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 53 | void DownloadPermissionRequest::DeleteRequest() { |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 54 | delete this; |
| 55 | } |