OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 9 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
10 #include "chrome/browser/download/download_request_limiter.h" | 10 #include "chrome/browser/download/download_request_limiter.h" |
11 | 11 |
12 class InfoBarService; | 12 class InfoBarService; |
13 | 13 |
14 // An infobar delegate that presents the user with a choice to allow or deny | 14 // An infobar delegate that presents the user with a choice to allow or deny |
15 // multiple downloads from the same site. This confirmation step protects | 15 // multiple downloads from the same site. This confirmation step protects |
16 // against "carpet-bombing", where a malicious site forces multiple downloads | 16 // against "carpet-bombing", where a malicious site forces multiple downloads |
17 // on an unsuspecting user. | 17 // on an unsuspecting user. |
18 class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate { | 18 class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate { |
19 public: | 19 public: |
20 DownloadRequestInfoBarDelegate( | 20 virtual ~DownloadRequestInfoBarDelegate(); |
21 InfoBarService* infobar_service, | 21 |
22 DownloadRequestLimiter::TabDownloadState* host); | 22 // Creates a download request delegate and adds it to |infobar_service|. |
| 23 static void Create(InfoBarService* infobar_service, |
| 24 DownloadRequestLimiter::TabDownloadState* host); |
| 25 |
| 26 #if defined(UNIT_TEST) |
| 27 static scoped_ptr<DownloadRequestInfoBarDelegate> Create( |
| 28 DownloadRequestLimiter::TabDownloadState* host) { |
| 29 return scoped_ptr<DownloadRequestInfoBarDelegate>( |
| 30 new DownloadRequestInfoBarDelegate(NULL, host)); |
| 31 } |
| 32 #endif |
23 | 33 |
24 void set_host(DownloadRequestLimiter::TabDownloadState* host) { | 34 void set_host(DownloadRequestLimiter::TabDownloadState* host) { |
25 host_ = host; | 35 host_ = host; |
26 } | 36 } |
27 | 37 |
28 private: | 38 private: |
29 virtual ~DownloadRequestInfoBarDelegate(); | 39 DownloadRequestInfoBarDelegate( |
| 40 InfoBarService* infobar_service, |
| 41 DownloadRequestLimiter::TabDownloadState* host); |
30 | 42 |
31 // ConfirmInfoBarDelegate: | 43 // ConfirmInfoBarDelegate: |
32 virtual gfx::Image* GetIcon() const OVERRIDE; | 44 virtual gfx::Image* GetIcon() const OVERRIDE; |
33 virtual string16 GetMessageText() const OVERRIDE; | 45 virtual string16 GetMessageText() const OVERRIDE; |
34 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 46 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
35 virtual bool Accept() OVERRIDE; | 47 virtual bool Accept() OVERRIDE; |
36 | 48 |
37 DownloadRequestLimiter::TabDownloadState* host_; | 49 DownloadRequestLimiter::TabDownloadState* host_; |
38 | 50 |
39 DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfoBarDelegate); | 51 DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfoBarDelegate); |
40 }; | 52 }; |
41 | 53 |
42 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ | 54 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ |
OLD | NEW |