This source file includes following definitions.
- Create
- SetCallbackForTesting
- host_
- GetIconID
- GetMessageText
- GetButtonLabel
- Accept
- Cancel
#include "chrome/browser/download/download_request_infobar_delegate.h"
#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
DownloadRequestInfoBarDelegate::FakeCreateCallback*
DownloadRequestInfoBarDelegate::callback_ = NULL;
DownloadRequestInfoBarDelegate::~DownloadRequestInfoBarDelegate() {
if (!responded_ && host_)
host_->CancelOnce();
}
void DownloadRequestInfoBarDelegate::Create(
InfoBarService* infobar_service,
base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host) {
if (DownloadRequestInfoBarDelegate::callback_ &&
!DownloadRequestInfoBarDelegate::callback_->is_null()) {
DownloadRequestInfoBarDelegate::callback_->Run(infobar_service, host);
} else if (!infobar_service) {
host->Cancel();
} else {
infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
scoped_ptr<ConfirmInfoBarDelegate>(
new DownloadRequestInfoBarDelegate(host))));
}
}
void DownloadRequestInfoBarDelegate::SetCallbackForTesting(
FakeCreateCallback* callback) {
DownloadRequestInfoBarDelegate::callback_ = callback;
}
DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate(
base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host)
: ConfirmInfoBarDelegate(),
responded_(false),
host_(host) {
}
int DownloadRequestInfoBarDelegate::GetIconID() const {
return IDR_INFOBAR_MULTIPLE_DOWNLOADS;
}
base::string16 DownloadRequestInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringUTF16(IDS_MULTI_DOWNLOAD_WARNING);
}
base::string16 DownloadRequestInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
IDS_MULTI_DOWNLOAD_WARNING_ALLOW : IDS_MULTI_DOWNLOAD_WARNING_DENY);
}
bool DownloadRequestInfoBarDelegate::Accept() {
DCHECK(!responded_);
responded_ = true;
if (host_) {
host_->Accept();
}
return !host_;
}
bool DownloadRequestInfoBarDelegate::Cancel() {
DCHECK(!responded_);
responded_ = true;
if (host_) {
host_->Cancel();
}
return !host_;
}