| 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_ANDROID_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_ANDROID_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "chrome/browser/download/download_request_limiter.h" | 10 #include "chrome/browser/download/download_request_limiter.h" |
| 11 #include "components/infobars/core/confirm_infobar_delegate.h" | 11 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 12 | 12 |
| 13 class InfoBarService; | 13 class InfoBarService; |
| 14 | 14 |
| 15 // An infobar delegate that presents the user with a choice to allow or deny | 15 // An infobar delegate that presents the user with a choice to allow or deny |
| 16 // multiple downloads from the same site. This confirmation step protects | 16 // multiple downloads from the same site. This confirmation step protects |
| 17 // against "carpet-bombing", where a malicious site forces multiple downloads | 17 // against "carpet-bombing", where a malicious site forces multiple downloads |
| 18 // on an unsuspecting user. | 18 // on an unsuspecting user. |
| 19 class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate { | 19 class DownloadRequestInfoBarDelegateAndroid : public ConfirmInfoBarDelegate { |
| 20 public: | 20 public: |
| 21 typedef base::Callback<void( | 21 typedef base::Callback<void( |
| 22 InfoBarService* infobar_service, | 22 InfoBarService* infobar_service, |
| 23 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host)> | 23 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host)> |
| 24 FakeCreateCallback; | 24 FakeCreateCallback; |
| 25 | 25 |
| 26 ~DownloadRequestInfoBarDelegate() override; | 26 ~DownloadRequestInfoBarDelegateAndroid() override; |
| 27 | 27 |
| 28 // Creates a download request delegate and adds it to |infobar_service|. | 28 // Creates a download request delegate and adds it to |infobar_service|. |
| 29 static void Create( | 29 static void Create( |
| 30 InfoBarService* infobar_service, | 30 InfoBarService* infobar_service, |
| 31 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host); | 31 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host); |
| 32 | 32 |
| 33 #if defined(UNIT_TEST) | 33 #if defined(UNIT_TEST) |
| 34 static scoped_ptr<DownloadRequestInfoBarDelegate> Create( | 34 static scoped_ptr<DownloadRequestInfoBarDelegateAndroid> Create( |
| 35 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host) { | 35 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host) { |
| 36 return scoped_ptr<DownloadRequestInfoBarDelegate>( | 36 return scoped_ptr<DownloadRequestInfoBarDelegateAndroid>( |
| 37 new DownloadRequestInfoBarDelegate(host)); | 37 new DownloadRequestInfoBarDelegateAndroid(host)); |
| 38 } | 38 } |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 static void SetCallbackForTesting(FakeCreateCallback* callback); | 41 static void SetCallbackForTesting(FakeCreateCallback* callback); |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 static FakeCreateCallback* callback_; | 44 static FakeCreateCallback* callback_; |
| 45 | 45 |
| 46 explicit DownloadRequestInfoBarDelegate( | 46 explicit DownloadRequestInfoBarDelegateAndroid( |
| 47 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host); | 47 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host); |
| 48 | 48 |
| 49 // ConfirmInfoBarDelegate: | 49 // ConfirmInfoBarDelegate: |
| 50 int GetIconId() const override; | 50 int GetIconId() const override; |
| 51 base::string16 GetMessageText() const override; | 51 base::string16 GetMessageText() const override; |
| 52 base::string16 GetButtonLabel(InfoBarButton button) const override; | 52 base::string16 GetButtonLabel(InfoBarButton button) const override; |
| 53 bool Accept() override; | 53 bool Accept() override; |
| 54 bool Cancel() override; | 54 bool Cancel() override; |
| 55 | 55 |
| 56 bool responded_; | 56 bool responded_; |
| 57 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host_; | 57 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host_; |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfoBarDelegate); | 59 DISALLOW_COPY_AND_ASSIGN(DownloadRequestInfoBarDelegateAndroid); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_H_ | 62 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_INFOBAR_DELEGATE_ANDROID_H_ |
| OLD | NEW |