Chromium Code Reviews| Index: chrome/browser/android/download/dangerous_download_infobar_delegate.cc |
| diff --git a/chrome/browser/android/download/dangerous_download_infobar_delegate.cc b/chrome/browser/android/download/dangerous_download_infobar_delegate.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..54faf8cfe80bd56863a90eb83e82387ae8ea5390 |
| --- /dev/null |
| +++ b/chrome/browser/android/download/dangerous_download_infobar_delegate.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/download/dangerous_download_infobar_delegate.h" |
| + |
| +#include <memory> |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/android/android_theme_resources.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "components/infobars/core/infobar.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +// static |
| +void DangerousDownloadInfoBarDelegate::Create( |
| + InfoBarService* infobar_service, |
| + content::DownloadItem* download_item) { |
| + infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| + std::unique_ptr<ConfirmInfoBarDelegate>( |
| + new DangerousDownloadInfoBarDelegate(download_item)))); |
| +} |
| + |
| +DangerousDownloadInfoBarDelegate::DangerousDownloadInfoBarDelegate( |
| + content::DownloadItem* download_item) |
| + : download_item_(download_item) { |
| + download_item_->AddObserver(this); |
| +} |
| + |
| +DangerousDownloadInfoBarDelegate::~DangerousDownloadInfoBarDelegate() { |
| + if (download_item_) |
| + download_item_->RemoveObserver(this); |
| +} |
| + |
| +void DangerousDownloadInfoBarDelegate::OnDownloadDestroyed( |
| + content::DownloadItem* download_item) { |
| + DCHECK_EQ(download_item, download_item_); |
| + download_item_ = nullptr; |
| +} |
| + |
| +infobars::InfoBarDelegate::InfoBarIdentifier |
| +DangerousDownloadInfoBarDelegate::GetIdentifier() const { |
| + return CONFIRM_DANGEROUS_DOWNLOAD; |
| +} |
| + |
| +int DangerousDownloadInfoBarDelegate::GetIconId() const { |
| + return IDR_ANDROID_INFOBAR_WARNING; |
| +} |
| + |
| +bool DangerousDownloadInfoBarDelegate::ShouldExpire( |
| + const NavigationDetails& details) const { |
| + return false; |
| +} |
| + |
| +void DangerousDownloadInfoBarDelegate::InfoBarDismissed() { |
| + if (download_item_) { |
| + download_item_->Remove(); |
| + } |
| +} |
| + |
| +base::string16 DangerousDownloadInfoBarDelegate::GetMessageText() const { |
| + return l10n_util::GetStringFUTF16( |
| + IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| + base::UTF8ToUTF16(download_item_->GetFileNameToReportUser().value())); |
| +} |
| + |
| +bool DangerousDownloadInfoBarDelegate::Accept() { |
| + 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
|
| + download_item_->ValidateDangerousDownload(); |
| + } |
| + return true; |
| +} |
| + |
| +bool DangerousDownloadInfoBarDelegate::Cancel() { |
| + if (download_item_) { |
| + download_item_->Remove(); |
| + } |
| + return true; |
| +} |