| 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 "components/offline_pages/offline_page_types.h" |
| 10 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
| 11 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 class WebContents; | 16 class WebContents; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace offline_pages { | 19 namespace offline_pages { |
| 19 | 20 |
| 21 struct OfflinePageItem; |
| 22 |
| 20 // Per-tab class to manage switch between online version and offline version. | 23 // Per-tab class to manage switch between online version and offline version. |
| 21 class OfflinePageTabHelper : | 24 class OfflinePageTabHelper : |
| 22 public content::WebContentsObserver, | 25 public content::WebContentsObserver, |
| 23 public content::WebContentsUserData<OfflinePageTabHelper> { | 26 public content::WebContentsUserData<OfflinePageTabHelper> { |
| 24 public: | 27 public: |
| 25 ~OfflinePageTabHelper() override; | 28 ~OfflinePageTabHelper() override; |
| 26 | 29 |
| 30 const OfflinePageItem* offline_page() { return offline_page_.get(); } |
| 31 |
| 27 private: | 32 private: |
| 33 enum class RedirectReason { |
| 34 DISCONNECTED_NETWORK, |
| 35 FLAKY_NETWORK, |
| 36 FLAKY_NETWORK_FORWARD_BACK |
| 37 }; |
| 38 |
| 28 friend class content::WebContentsUserData<OfflinePageTabHelper>; | 39 friend class content::WebContentsUserData<OfflinePageTabHelper>; |
| 29 friend class OfflinePageTabHelperTest; | 40 friend class OfflinePageTabHelperTest; |
| 30 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest, | 41 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest, |
| 31 NewNavigationCancelsPendingRedirects); | 42 NewNavigationCancelsPendingRedirects); |
| 32 | 43 |
| 33 explicit OfflinePageTabHelper(content::WebContents* web_contents); | 44 explicit OfflinePageTabHelper(content::WebContents* web_contents); |
| 34 | 45 |
| 35 // Overridden from content::WebContentsObserver: | 46 // Overridden from content::WebContentsObserver: |
| 36 void DidStartNavigation( | 47 void DidStartNavigation( |
| 37 content::NavigationHandle* navigation_handle) override; | 48 content::NavigationHandle* navigation_handle) override; |
| 38 void DidFinishNavigation( | 49 void DidFinishNavigation( |
| 39 content::NavigationHandle* navigation_handle) override; | 50 content::NavigationHandle* navigation_handle) override; |
| 40 | 51 |
| 41 void GotRedirectURLForSupportedErrorCode(ui::PageTransition transition, | 52 void RedirectToOnline(const GURL& from_url, |
| 42 const GURL& from_url, | 53 const OfflinePageItem* offline_page); |
| 43 const GURL& redirect_url); | 54 void TryRedirectToOffline(RedirectReason redirect_reason, |
| 44 void GotRedirectURLForStartedNavigation(const GURL& from_url, | 55 const GURL& from_url, |
| 45 const GURL& redirect_url); | 56 const OfflinePageItem* offline_page); |
| 46 | 57 |
| 47 void Redirect(const GURL& from_url, const GURL& to_url); | 58 void Redirect(const GURL& from_url, const GURL& to_url); |
| 48 | 59 |
| 60 // Iff the tab we are associated with is redirected to an offline page, |
| 61 // |offline_page_| will be non-null. This can be used to synchronously ask |
| 62 // about the offline state of the current web contents. |
| 63 std::unique_ptr<OfflinePageItem> offline_page_; |
| 49 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; | 64 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; |
| 50 | 65 |
| 51 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); | 66 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); |
| 52 }; | 67 }; |
| 53 | 68 |
| 54 } // namespace offline_pages | 69 } // namespace offline_pages |
| 55 | 70 |
| 56 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ | 71 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ |
| OLD | NEW |