| 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_OFFLINE_PAGE_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 public: | 28 public: |
| 29 ~OfflinePageTabHelper() override; | 29 ~OfflinePageTabHelper() override; |
| 30 | 30 |
| 31 const OfflinePageItem* offline_page() { return offline_page_.get(); } | 31 const OfflinePageItem* offline_page() { return offline_page_.get(); } |
| 32 void SetOfflinePage(const OfflinePageItem& offline_page, | 32 void SetOfflinePage(const OfflinePageItem& offline_page, |
| 33 bool is_offline_preview); | 33 bool is_offline_preview); |
| 34 | 34 |
| 35 // Whether the page is an offline preview. | 35 // Whether the page is an offline preview. |
| 36 bool is_offline_preview() const { return is_offline_preview_; } | 36 bool is_offline_preview() const { return is_offline_preview_; } |
| 37 | 37 |
| 38 // Returns provisional offline page since actual navigation does not happen |
| 39 // during unit tests. |
| 40 const OfflinePageItem* GetOfflinePageForTest() const; |
| 41 |
| 38 private: | 42 private: |
| 39 friend class content::WebContentsUserData<OfflinePageTabHelper>; | 43 friend class content::WebContentsUserData<OfflinePageTabHelper>; |
| 40 | 44 |
| 41 explicit OfflinePageTabHelper(content::WebContents* web_contents); | 45 explicit OfflinePageTabHelper(content::WebContents* web_contents); |
| 42 | 46 |
| 43 // Overridden from content::WebContentsObserver: | 47 // Overridden from content::WebContentsObserver: |
| 44 void DidStartNavigation( | 48 void DidStartNavigation( |
| 45 content::NavigationHandle* navigation_handle) override; | 49 content::NavigationHandle* navigation_handle) override; |
| 46 void DidFinishNavigation( | 50 void DidFinishNavigation( |
| 47 content::NavigationHandle* navigation_handle) override; | 51 content::NavigationHandle* navigation_handle) override; |
| 48 | 52 |
| 49 void SelectPageForOnlineURLDone(const OfflinePageItem* offline_page); | 53 void SelectPageForOnlineURLDone(const OfflinePageItem* offline_page); |
| 50 | 54 |
| 51 // The cached copy of OfflinePageItem if offline page is loaded for current | 55 // The cached copy of OfflinePageItem if offline page is loaded for current |
| 52 // tab. This can be used to by the Tab to synchronously ask about the offline | 56 // tab. This can be used to by the Tab to synchronously ask about the offline |
| 53 // info. | 57 // info. |
| 54 std::unique_ptr<OfflinePageItem> offline_page_; | 58 std::unique_ptr<OfflinePageItem> offline_page_; |
| 59 // Potential new offline page copy. This is reset to nullptr at the start |
| 60 // of every navigation and set by network request interceptor. If the |
| 61 // interceptor decided to not use offline page for the navigation or was not |
| 62 // even invoked (as in case with fragment navigation), this stays nullptr. |
| 63 std::unique_ptr<OfflinePageItem> provisional_offline_page_; |
| 55 | 64 |
| 56 bool reloading_url_on_net_error_ = false; | 65 bool reloading_url_on_net_error_ = false; |
| 57 | 66 |
| 58 // Whether the page is an offline preview. Offline page previews are shown | 67 // Whether the page is an offline preview. Offline page previews are shown |
| 59 // when a user's effective connection type is prohibitively slow. | 68 // when a user's effective connection type is prohibitively slow. |
| 60 bool is_offline_preview_; | 69 bool is_offline_preview_; |
| 61 | 70 |
| 62 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; | 71 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; |
| 63 | 72 |
| 64 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); | 73 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); |
| 65 }; | 74 }; |
| 66 | 75 |
| 67 } // namespace offline_pages | 76 } // namespace offline_pages |
| 68 | 77 |
| 69 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ | 78 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ |
| OLD | NEW |