Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: chrome/browser/android/download/dangerous_download_infobar_delegate.cc

Issue 2496983003: Use native implementation of dangerous download infobar (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/android/download/dangerous_download_infobar_delegate.h"
6
7 #include <memory>
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/android/android_theme_resources.h"
11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "components/infobars/core/infobar.h"
14 #include "ui/base/l10n/l10n_util.h"
15
16 // static
17 void DangerousDownloadInfoBarDelegate::Create(
18 InfoBarService* infobar_service,
19 content::DownloadItem* download_item) {
20 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
21 std::unique_ptr<ConfirmInfoBarDelegate>(
22 new DangerousDownloadInfoBarDelegate(download_item))));
23 }
24
25 DangerousDownloadInfoBarDelegate::DangerousDownloadInfoBarDelegate(
26 content::DownloadItem* download_item)
27 : download_item_(download_item) {
28 download_item_->AddObserver(this);
29 }
30
31 DangerousDownloadInfoBarDelegate::~DangerousDownloadInfoBarDelegate() {
32 if (download_item_)
33 download_item_->RemoveObserver(this);
34 }
35
36 void DangerousDownloadInfoBarDelegate::OnDownloadDestroyed(
37 content::DownloadItem* download_item) {
38 DCHECK_EQ(download_item, download_item_);
39 download_item_ = nullptr;
40 }
41
42 infobars::InfoBarDelegate::InfoBarIdentifier
43 DangerousDownloadInfoBarDelegate::GetIdentifier() const {
44 return CONFIRM_DANGEROUS_DOWNLOAD;
45 }
46
47 int DangerousDownloadInfoBarDelegate::GetIconId() const {
48 return IDR_ANDROID_INFOBAR_WARNING;
49 }
50
51 bool DangerousDownloadInfoBarDelegate::ShouldExpire(
52 const NavigationDetails& details) const {
53 return false;
54 }
55
56 void DangerousDownloadInfoBarDelegate::InfoBarDismissed() {
57 if (download_item_)
58 download_item_->Remove();
59 }
60
61 base::string16 DangerousDownloadInfoBarDelegate::GetMessageText() const {
62 return l10n_util::GetStringFUTF16(
63 IDS_PROMPT_DANGEROUS_DOWNLOAD,
64 base::UTF8ToUTF16(download_item_->GetFileNameToReportUser().value()));
65 }
66
67 bool DangerousDownloadInfoBarDelegate::Accept() {
68 if (download_item_)
69 download_item_->ValidateDangerousDownload();
70 return true;
71 }
72
73 bool DangerousDownloadInfoBarDelegate::Cancel() {
74 if (download_item_)
75 download_item_->Remove();
76 return true;
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698