Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_tab_helper.h

Issue 2362033002: Showing previews UI for Offline Previews (Closed)
Patch Set: megjablon comments rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "components/offline_pages/loaded_offline_page_info.h"
11 #include "components/offline_pages/request_header/offline_page_header.h" 14 #include "components/offline_pages/request_header/offline_page_header.h"
12 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 16 #include "content/public/browser/web_contents_user_data.h"
14 #include "url/gurl.h" 17 #include "url/gurl.h"
15 18
16 namespace content { 19 namespace content {
17 class WebContents; 20 class WebContents;
18 } 21 }
19 22
20 namespace offline_pages { 23 namespace offline_pages {
21
22 struct OfflinePageItem; 24 struct OfflinePageItem;
23 25
24 // Per-tab class that monitors the navigations and stores the necessary info 26 // Per-tab class that monitors the navigations and stores the necessary info
25 // to facilitate the synchronous access to offline information. 27 // to facilitate the synchronous access to offline information.
26 class OfflinePageTabHelper : 28 class OfflinePageTabHelper :
27 public content::WebContentsObserver, 29 public content::WebContentsObserver,
28 public content::WebContentsUserData<OfflinePageTabHelper> { 30 public content::WebContentsUserData<OfflinePageTabHelper> {
29 public: 31 public:
30 ~OfflinePageTabHelper() override; 32 ~OfflinePageTabHelper() override;
31 33
32 void SetOfflinePage(const OfflinePageItem& offline_page, 34 const OfflinePageItem* offline_page() const {
33 const OfflinePageHeader& offline_header, 35 if (!offline_info_ || !offline_info_->offline_page())
34 bool is_offline_preview); 36 return nullptr;
35 37 return offline_info_->offline_page();
36 const OfflinePageItem* offline_page() {
37 return offline_info_.offline_page.get();
38 } 38 }
39 39
40 const OfflinePageHeader& offline_header() const { 40 const OfflinePageHeader* offline_header() const {
41 return offline_info_.offline_header; 41 if (!offline_info_ || !offline_info_->offline_header()) {
42 return nullptr;
43 }
44 return offline_info_->offline_header();
42 } 45 }
43 46
44 // Whether the page is an offline preview.
45 bool is_offline_preview() const { return offline_info_.is_offline_preview; }
46
47 // Returns provisional offline page since actual navigation does not happen
48 // during unit tests.
49 const OfflinePageItem* GetOfflinePageForTest() const;
50
51 private: 47 private:
52 friend class content::WebContentsUserData<OfflinePageTabHelper>; 48 friend class content::WebContentsUserData<OfflinePageTabHelper>;
53 49
54 // Contains the info about the offline page being loaded.
55 struct LoadedOfflinePageInfo {
56 LoadedOfflinePageInfo();
57 ~LoadedOfflinePageInfo();
58
59 // The cached copy of OfflinePageItem.
60 std::unique_ptr<OfflinePageItem> offline_page;
61
62 // The offline header that is provided when offline page is loaded.
63 OfflinePageHeader offline_header;
64
65 // Whether the page is an offline preview. Offline page previews are shown
66 // when a user's effective connection type is prohibitively slow.
67 bool is_offline_preview;
68
69 void Clear();
70 };
71
72 explicit OfflinePageTabHelper(content::WebContents* web_contents); 50 explicit OfflinePageTabHelper(content::WebContents* web_contents);
73 51
74 // Overridden from content::WebContentsObserver: 52 // Overridden from content::WebContentsObserver:
75 void DidStartNavigation( 53 void DidStartNavigation(
76 content::NavigationHandle* navigation_handle) override; 54 content::NavigationHandle* navigation_handle) override;
77 void DidFinishNavigation( 55 void DidFinishNavigation(
78 content::NavigationHandle* navigation_handle) override; 56 content::NavigationHandle* navigation_handle) override;
79 57
80 void SelectPageForOnlineURLDone(const OfflinePageItem* offline_page); 58 void SelectPageForOnlineURLDone(const OfflinePageItem* offline_page);
81 59
82 // The provisional info about the offline page being loaded. This is set when 60 // The info about offline page being loaded. This is set when the navigation
83 // the offline interceptor decides to serve the offline page and it will be 61 // is committed without error. This can be used to by the Tab to synchronously
84 // moved to |offline_info_| once the navigation is committed without error. 62 // ask about the offline info.
85 LoadedOfflinePageInfo provisional_offline_info_; 63 std::unique_ptr<LoadedOfflinePageInfo> offline_info_;
86
87 // The info about offline page being loaded. This is set from
88 // |provisional_offline_info_| when the navigation is committed without error.
89 // This can be used to by the Tab to synchronously ask about the offline
90 // info.
91 LoadedOfflinePageInfo offline_info_;
92 64
93 bool reloading_url_on_net_error_ = false; 65 bool reloading_url_on_net_error_ = false;
94 66
95 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; 67 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
96 68
97 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); 69 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
98 }; 70 };
99 71
100 } // namespace offline_pages 72 } // namespace offline_pages
101 73
102 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 74 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698