Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 62 base::string16 DangerousDownloadInfoBarDelegate::GetMessageText() const { | |
| 63 return l10n_util::GetStringFUTF16( | |
| 64 IDS_PROMPT_DANGEROUS_DOWNLOAD, | |
| 65 base::UTF8ToUTF16(download_item_->GetFileNameToReportUser().value())); | |
| 66 } | |
| 67 | |
| 68 bool DangerousDownloadInfoBarDelegate::Accept() { | |
| 69 if (download_item_) { | |
|
gone
2016/10/24 18:08:56
nit: do you need braces here? you didn't use them
qinmin
2016/10/24 23:35:30
All brackets for single line if statement are remo
| |
| 70 download_item_->ValidateDangerousDownload(); | |
| 71 } | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 bool DangerousDownloadInfoBarDelegate::Cancel() { | |
| 76 if (download_item_) { | |
| 77 download_item_->Remove(); | |
| 78 } | |
| 79 return true; | |
| 80 } | |
| OLD | NEW |