[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 | |||||
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 7 | #include "chrome/grit/generated_resources.h" |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 8 | #include "ui/base/l10n/l10n_util.h" |
9 | |||||
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 10 | #if defined(OS_ANDROID) |
11 | #include "chrome/browser/android/android_theme_resources.h" | ||||
Mugdha Lakhani | 6b39f5fd | 2018-11-23 11:19:01 | [diff] [blame] | 12 | #include "components/url_formatter/elide_url.h" |
13 | #include "url/origin.h" | ||||
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 14 | #else |
Mugdha Lakhani | b676216 | 2020-03-30 10:23:25 | [diff] [blame^] | 15 | #include "components/vector_icons/vector_icons.h" |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 16 | #endif |
17 | |||||
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 18 | DownloadPermissionRequest::DownloadPermissionRequest( |
Min Qin | 357184a | 2019-06-25 16:31:44 | [diff] [blame] | 19 | base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host, |
Min Qin | 5f2f6a1 | 2019-08-12 21:50:48 | [diff] [blame] | 20 | const url::Origin& request_origin) |
Min Qin | 357184a | 2019-06-25 16:31:44 | [diff] [blame] | 21 | : host_(host), request_origin_(request_origin) {} |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 22 | |
23 | DownloadPermissionRequest::~DownloadPermissionRequest() {} | ||||
24 | |||||
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 25 | permissions::PermissionRequest::IconId DownloadPermissionRequest::GetIconId() |
26 | const { | ||||
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 27 | #if defined(OS_ANDROID) |
28 | return IDR_ANDROID_INFOBAR_MULTIPLE_DOWNLOADS; | ||||
29 | #else | ||||
Mugdha Lakhani | b676216 | 2020-03-30 10:23:25 | [diff] [blame^] | 30 | return vector_icons::kFileDownloadIcon; |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 31 | #endif |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 32 | } |
33 | |||||
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 34 | #if defined(OS_ANDROID) |
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 35 | base::string16 DownloadPermissionRequest::GetMessageText() const { |
Mugdha Lakhani | 6b39f5fd | 2018-11-23 11:19:01 | [diff] [blame] | 36 | return l10n_util::GetStringFUTF16( |
Min Qin | 5f2f6a1 | 2019-08-12 21:50:48 | [diff] [blame] | 37 | IDS_MULTI_DOWNLOAD_WARNING, url_formatter::FormatOriginForSecurityDisplay( |
38 | request_origin_, | ||||
39 | /*scheme_display = */ url_formatter:: | ||||
40 | SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | ||||
timloh | 178801f | 2017-06-13 04:17:58 | [diff] [blame] | 41 | } |
42 | #endif | ||||
43 | |||||
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 44 | base::string16 DownloadPermissionRequest::GetMessageTextFragment() const { |
45 | return l10n_util::GetStringUTF16(IDS_MULTI_DOWNLOAD_PERMISSION_FRAGMENT); | ||||
46 | } | ||||
47 | |||||
johnme | fe4e96d | 2016-01-27 16:14:41 | [diff] [blame] | 48 | GURL DownloadPermissionRequest::GetOrigin() const { |
Min Qin | 5f2f6a1 | 2019-08-12 21:50:48 | [diff] [blame] | 49 | return request_origin_.GetURL(); |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 50 | } |
51 | |||||
52 | void DownloadPermissionRequest::PermissionGranted() { | ||||
53 | if (host_) { | ||||
54 | // This may invalidate |host_|. | ||||
Min Qin | 357184a | 2019-06-25 16:31:44 | [diff] [blame] | 55 | host_->Accept(request_origin_); |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 56 | } |
57 | } | ||||
58 | |||||
59 | void DownloadPermissionRequest::PermissionDenied() { | ||||
60 | if (host_) { | ||||
61 | // This may invalidate |host_|. | ||||
Min Qin | 357184a | 2019-06-25 16:31:44 | [diff] [blame] | 62 | host_->Cancel(request_origin_); |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 63 | } |
64 | } | ||||
65 | |||||
66 | void DownloadPermissionRequest::Cancelled() { | ||||
felt | 43d0cdb | 2015-04-11 00:00:17 | [diff] [blame] | 67 | if (host_) { |
68 | // This may invalidate |host_|. | ||||
Min Qin | 357184a | 2019-06-25 16:31:44 | [diff] [blame] | 69 | host_->CancelOnce(request_origin_); |
felt | 43d0cdb | 2015-04-11 00:00:17 | [diff] [blame] | 70 | } |
[email protected] | 87ac156 | 2014-02-26 17:50:46 | [diff] [blame] | 71 | } |
72 | |||||
73 | void DownloadPermissionRequest::RequestFinished() { | ||||
74 | delete this; | ||||
75 | } | ||||
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 76 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 77 | permissions::PermissionRequestType |
78 | DownloadPermissionRequest::GetPermissionRequestType() const { | ||||
79 | return permissions::PermissionRequestType::DOWNLOAD; | ||||
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 80 | } |