| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_ANDROID_OFFLINE_PAGES_DOWNLOADS_OFFLINE_PAGE_INFOBAR_DELE
GATE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_DOWNLOADS_OFFLINE_PAGE_INFOBAR_DELE
GATE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_DOWNLOADS_OFFLINE_PAGE_INFOBAR_DELE
GATE_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_DOWNLOADS_OFFLINE_PAGE_INFOBAR_DELE
GATE_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "chrome/browser/android/download/download_overwrite_infobar_delegate.h" | 9 #include "chrome/browser/android/download/download_overwrite_infobar_delegate.h" |
| 10 #include "components/infobars/core/infobar_delegate.h" | 10 #include "components/infobars/core/infobar_delegate.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 class WebContents; | 13 class WebContents; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace offline_pages { | 16 namespace offline_pages { |
| 17 | 17 |
| 18 // An InfoBarDelegate that appears when a user attempt to save offline pages for |
| 19 // a URL that is already saved. This piggy-backs off the Download infobar, |
| 20 // since the UI should be the same between Downloads and Offline Pages in this |
| 21 // case. There are two actions: Create New, and Overwrite. Since Overwrite is |
| 22 // not straightforward for offline pages, the behavior is to delete ALL other |
| 23 // pages that are saved for the given URL, then save the newly requested page. |
| 18 class OfflinePageInfoBarDelegate | 24 class OfflinePageInfoBarDelegate |
| 19 : public chrome::android::DownloadOverwriteInfoBarDelegate { | 25 : public chrome::android::DownloadOverwriteInfoBarDelegate { |
| 20 public: | 26 public: |
| 27 enum class Action { CREATE_NEW, OVERWRITE }; |
| 28 |
| 21 // Creates an offline page infobar and a delegate and adds the infobar to the | 29 // Creates an offline page infobar and a delegate and adds the infobar to the |
| 22 // InfoBarService associated with |web_contents|. |page_name| is the name | 30 // InfoBarService associated with |web_contents|. |page_name| is the name |
| 23 // shown for this file in the infobar text. | 31 // shown for this file in the infobar text. |
| 24 static void Create(const base::Closure& confirm_continuation, | 32 static void Create(const base::Callback<void(Action)>& confirm_continuation, |
| 33 const std::string& downloads_label, |
| 25 const std::string& page_name, | 34 const std::string& page_name, |
| 26 content::WebContents* web_contents); | 35 content::WebContents* web_contents); |
| 27 ~OfflinePageInfoBarDelegate() override; | 36 ~OfflinePageInfoBarDelegate() override; |
| 28 | 37 |
| 29 private: | 38 private: |
| 30 OfflinePageInfoBarDelegate(const base::Closure& confirm_continuation, | 39 OfflinePageInfoBarDelegate( |
| 31 const std::string& page_name); | 40 const base::Callback<void(Action)>& confirm_continuation, |
| 41 const std::string& downloads_label, |
| 42 const std::string& page_name); |
| 32 | 43 |
| 33 // DownloadOverwriteInfoBarDelegate: | 44 // DownloadOverwriteInfoBarDelegate: |
| 34 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 45 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
| 35 bool EqualsDelegate(InfoBarDelegate* delegate) const override; | 46 bool EqualsDelegate(InfoBarDelegate* delegate) const override; |
| 36 bool OverwriteExistingFile() override; | 47 bool OverwriteExistingFile() override; |
| 37 bool CreateNewFile() override; | 48 bool CreateNewFile() override; |
| 38 std::string GetFileName() const override; | 49 std::string GetFileName() const override; |
| 39 std::string GetDirName() const override; | 50 std::string GetDirName() const override; |
| 40 std::string GetDirFullPath() const override; | 51 std::string GetDirFullPath() const override; |
| 41 bool ShouldExpire(const NavigationDetails& details) const override; | 52 bool ShouldExpire(const NavigationDetails& details) const override; |
| 42 OfflinePageInfoBarDelegate* AsOfflinePageInfoBarDelegate() override; | 53 OfflinePageInfoBarDelegate* AsOfflinePageInfoBarDelegate() override; |
| 43 | 54 |
| 44 // Continuation called when the user chooses to create a new file. | 55 // Continuation called when the user chooses to create a new file. |
| 45 base::Closure confirm_continuation_; | 56 base::Callback<void(Action)> confirm_continuation_; |
| 46 | 57 |
| 58 std::string downloads_label_; |
| 47 std::string page_name_; | 59 std::string page_name_; |
| 48 | 60 |
| 49 DISALLOW_COPY_AND_ASSIGN(OfflinePageInfoBarDelegate); | 61 DISALLOW_COPY_AND_ASSIGN(OfflinePageInfoBarDelegate); |
| 50 }; | 62 }; |
| 51 | 63 |
| 52 } // namespace offline_pages | 64 } // namespace offline_pages |
| 53 | 65 |
| 54 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_DOWNLOADS_OFFLINE_PAGE_INFOBAR_D
ELEGATE_H_ | 66 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_DOWNLOADS_OFFLINE_PAGE_INFOBAR_D
ELEGATE_H_ |
| OLD | NEW |