| 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" |
| 11 #include "components/offline_pages/request_header/offline_page_header.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 12 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 class WebContents; | 17 class WebContents; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace offline_pages { | 20 namespace offline_pages { |
| 20 | 21 |
| 21 struct OfflinePageItem; | 22 struct OfflinePageItem; |
| 22 | 23 |
| 23 // Per-tab class that monitors the navigations and stores the necessary info | 24 // Per-tab class that monitors the navigations and stores the necessary info |
| 24 // to facilitate the synchronous access to offline information. | 25 // to facilitate the synchronous access to offline information. |
| 25 class OfflinePageTabHelper : | 26 class OfflinePageTabHelper : |
| 26 public content::WebContentsObserver, | 27 public content::WebContentsObserver, |
| 27 public content::WebContentsUserData<OfflinePageTabHelper> { | 28 public content::WebContentsUserData<OfflinePageTabHelper> { |
| 28 public: | 29 public: |
| 29 ~OfflinePageTabHelper() override; | 30 ~OfflinePageTabHelper() override; |
| 30 | 31 |
| 32 void SetOfflinePage(const OfflinePageItem& offline_page, |
| 33 const OfflinePageHeader& offline_header, |
| 34 bool is_offline_preview); |
| 35 |
| 31 const OfflinePageItem* offline_page() { return offline_page_.get(); } | 36 const OfflinePageItem* offline_page() { return offline_page_.get(); } |
| 32 void SetOfflinePage(const OfflinePageItem& offline_page, | 37 |
| 33 bool is_offline_preview); | 38 const OfflinePageHeader& offline_header() const { return offline_header_; } |
| 34 | 39 |
| 35 // Whether the page is an offline preview. | 40 // Whether the page is an offline preview. |
| 36 bool is_offline_preview() const { return is_offline_preview_; } | 41 bool is_offline_preview() const { return is_offline_preview_; } |
| 37 | 42 |
| 38 private: | 43 private: |
| 39 friend class content::WebContentsUserData<OfflinePageTabHelper>; | 44 friend class content::WebContentsUserData<OfflinePageTabHelper>; |
| 40 | 45 |
| 41 explicit OfflinePageTabHelper(content::WebContents* web_contents); | 46 explicit OfflinePageTabHelper(content::WebContents* web_contents); |
| 42 | 47 |
| 43 // Overridden from content::WebContentsObserver: | 48 // Overridden from content::WebContentsObserver: |
| 44 void DidStartNavigation( | 49 void DidStartNavigation( |
| 45 content::NavigationHandle* navigation_handle) override; | 50 content::NavigationHandle* navigation_handle) override; |
| 46 void DidFinishNavigation( | 51 void DidFinishNavigation( |
| 47 content::NavigationHandle* navigation_handle) override; | 52 content::NavigationHandle* navigation_handle) override; |
| 48 | 53 |
| 49 void SelectPageForOnlineURLDone(const OfflinePageItem* offline_page); | 54 void SelectPageForOnlineURLDone(const OfflinePageItem* offline_page); |
| 50 | 55 |
| 51 // The cached copy of OfflinePageItem if offline page is loaded for current | 56 // 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 | 57 // tab. This can be used to by the Tab to synchronously ask about the offline |
| 53 // info. | 58 // info. |
| 54 std::unique_ptr<OfflinePageItem> offline_page_; | 59 std::unique_ptr<OfflinePageItem> offline_page_; |
| 55 | 60 |
| 61 // The offline header that is provided when offline page is loaded for current |
| 62 // tab. |
| 63 OfflinePageHeader offline_header_; |
| 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 |