1 // Copyright (c) 2012 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.
5 #include "chrome/browser/download/download_request_infobar_delegate.h"
7 #include "chrome/browser/infobars/infobar.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "grit/generated_resources.h"
10 #include "grit/theme_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
13 DownloadRequestInfoBarDelegate::FakeCreateCallback
*
14 DownloadRequestInfoBarDelegate::callback_
= NULL
;
16 DownloadRequestInfoBarDelegate::~DownloadRequestInfoBarDelegate() {
17 if (!responded_
&& host_
)
22 void DownloadRequestInfoBarDelegate::Create(
23 InfoBarService
* infobar_service
,
24 base::WeakPtr
<DownloadRequestLimiter::TabDownloadState
> host
) {
25 if (DownloadRequestInfoBarDelegate::callback_
&&
26 !DownloadRequestInfoBarDelegate::callback_
->is_null()) {
27 DownloadRequestInfoBarDelegate::callback_
->Run(infobar_service
, host
);
28 } else if (!infobar_service
) {
29 // |web_contents| may not have a InfoBarService if it's actually a
30 // WebContents like those used for extension popups/bubbles and hosted apps
32 // TODO(benjhayden): If this is an automatic download from an extension,
33 // it would be convenient for the extension author if we send a message to
34 // the extension's DevTools console (as we do for CSP) about how
35 // extensions should use chrome.downloads.download() (requires the
36 // "downloads" permission) to automatically download >1 files.
39 infobar_service
->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
40 scoped_ptr
<ConfirmInfoBarDelegate
>(
41 new DownloadRequestInfoBarDelegate(host
))));
46 void DownloadRequestInfoBarDelegate::SetCallbackForTesting(
47 FakeCreateCallback
* callback
) {
48 DownloadRequestInfoBarDelegate::callback_
= callback
;
51 DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate(
52 base::WeakPtr
<DownloadRequestLimiter::TabDownloadState
> host
)
53 : ConfirmInfoBarDelegate(),
58 int DownloadRequestInfoBarDelegate::GetIconID() const {
59 return IDR_INFOBAR_MULTIPLE_DOWNLOADS
;
62 base::string16
DownloadRequestInfoBarDelegate::GetMessageText() const {
63 return l10n_util::GetStringUTF16(IDS_MULTI_DOWNLOAD_WARNING
);
66 base::string16
DownloadRequestInfoBarDelegate::GetButtonLabel(
67 InfoBarButton button
) const {
68 return l10n_util::GetStringUTF16((button
== BUTTON_OK
) ?
69 IDS_MULTI_DOWNLOAD_WARNING_ALLOW
: IDS_MULTI_DOWNLOAD_WARNING_DENY
);
72 bool DownloadRequestInfoBarDelegate::Accept() {
76 // This may invalidate |host_|.
82 bool DownloadRequestInfoBarDelegate::Cancel() {
86 // This may invalidate |host_|.