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

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

Issue 2337363002: Load live version when reloading an offline page on connected network (Closed)
Patch Set: Rebase again Created 4 years, 3 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 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chrome/browser/android/offline_pages/offline_page_request_job.h" 10 #include "chrome/browser/android/offline_pages/offline_page_request_job.h"
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 OfflinePageTabHelper::~OfflinePageTabHelper() {} 32 OfflinePageTabHelper::~OfflinePageTabHelper() {}
33 33
34 void OfflinePageTabHelper::DidStartNavigation( 34 void OfflinePageTabHelper::DidStartNavigation(
35 content::NavigationHandle* navigation_handle) { 35 content::NavigationHandle* navigation_handle) {
36 // Skips non-main frame. 36 // Skips non-main frame.
37 if (!navigation_handle->IsInMainFrame()) 37 if (!navigation_handle->IsInMainFrame())
38 return; 38 return;
39 39
40 // If the navigation is referencing fragment (synchronous navigation could
41 // only be referencing fragment navigation or pushState/popState navigation,
42 // while the latter is unlikely because offline page disables Javascript
43 // execution), do not reset out cached offline info.
44 if (navigation_handle->IsSynchronousNavigation())
Dmitry Titov 2016/09/17 02:22:54 As discussed, lets keep the IsSamePage() check in
jianli 2016/09/19 21:29:05 We also need to clear the real values here because
45 return;
46
40 // This is a new navigation so we can invalidate any previously scheduled 47 // This is a new navigation so we can invalidate any previously scheduled
41 // operations. 48 // operations.
42 weak_ptr_factory_.InvalidateWeakPtrs(); 49 weak_ptr_factory_.InvalidateWeakPtrs();
43 50
44 provisional_offline_page_ = nullptr; 51 provisional_offline_page_ = nullptr;
52 offline_page_ = nullptr;
53 offline_header_.Clear();
45 is_offline_preview_ = false; 54 is_offline_preview_ = false;
46 reloading_url_on_net_error_ = false; 55 reloading_url_on_net_error_ = false;
47 } 56 }
48 57
49 void OfflinePageTabHelper::DidFinishNavigation( 58 void OfflinePageTabHelper::DidFinishNavigation(
50 content::NavigationHandle* navigation_handle) { 59 content::NavigationHandle* navigation_handle) {
51 // Skips non-main frame. 60 // Skips non-main frame.
52 if (!navigation_handle->IsInMainFrame()) 61 if (!navigation_handle->IsInMainFrame())
53 return; 62 return;
54 63
55 if (!navigation_handle->HasCommitted()) 64 if (!navigation_handle->HasCommitted())
56 return; 65 return;
57 66
58 if (navigation_handle->IsSamePage()) { 67 if (navigation_handle->IsSynchronousNavigation())
59 return; 68 return;
60 }
61 69
62 offline_page_ = std::move(provisional_offline_page_); 70 offline_page_ = std::move(provisional_offline_page_);
63 provisional_offline_page_ = nullptr; 71 provisional_offline_page_ = nullptr;
64 72
65 // We might be reloading the URL in order to fetch the offline page. 73 // We might be reloading the URL in order to fetch the offline page.
66 // * If successful, nothing to do. 74 // * If successful, nothing to do.
67 // * Otherwise, we're hitting error again. Bail out to avoid loop. 75 // * Otherwise, we're hitting error again. Bail out to avoid loop.
68 if (reloading_url_on_net_error_) 76 if (reloading_url_on_net_error_)
69 return; 77 return;
70 78
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 OfflinePageRequestJob::AggregatedRequestResult:: 122 OfflinePageRequestJob::AggregatedRequestResult::
115 PAGE_NOT_FOUND_ON_FLAKY_NETWORK); 123 PAGE_NOT_FOUND_ON_FLAKY_NETWORK);
116 return; 124 return;
117 } 125 }
118 126
119 reloading_url_on_net_error_ = true; 127 reloading_url_on_net_error_ = true;
120 128
121 // Reloads the page with extra header set to force loading the offline page. 129 // Reloads the page with extra header set to force loading the offline page.
122 content::NavigationController::LoadURLParams load_params(offline_page->url); 130 content::NavigationController::LoadURLParams load_params(offline_page->url);
123 load_params.transition_type = ui::PAGE_TRANSITION_RELOAD; 131 load_params.transition_type = ui::PAGE_TRANSITION_RELOAD;
124 load_params.extra_headers = kOfflinePageHeader; 132 OfflinePageHeader offline_header;
125 load_params.extra_headers += ":"; 133 offline_header.reason = OfflinePageHeader::Reason::NET_ERROR;
126 load_params.extra_headers += kOfflinePageHeaderReasonKey; 134 load_params.extra_headers = offline_header.GetCompleteHeaderString();
127 load_params.extra_headers += "=";
128 load_params.extra_headers += kOfflinePageHeaderReasonValueDueToNetError;
129 web_contents()->GetController().LoadURLWithParams(load_params); 135 web_contents()->GetController().LoadURLWithParams(load_params);
130 } 136 }
131 137
132 // This is a callback from network request interceptor. It happens between 138 // This is a callback from network request interceptor. It happens between
133 // DidStartNavigation and DidFinishNavigation calls on this tab helper. 139 // DidStartNavigation and DidFinishNavigation calls on this tab helper.
134 void OfflinePageTabHelper::SetOfflinePage(const OfflinePageItem& offline_page, 140 void OfflinePageTabHelper::SetOfflinePage(
135 bool is_offline_preview) { 141 const OfflinePageItem& offline_page,
142 const OfflinePageHeader& offline_header,
143 bool is_offline_preview) {
136 provisional_offline_page_ = base::MakeUnique<OfflinePageItem>(offline_page); 144 provisional_offline_page_ = base::MakeUnique<OfflinePageItem>(offline_page);
145 offline_header_ = offline_header;
137 is_offline_preview_ = is_offline_preview; 146 is_offline_preview_ = is_offline_preview;
138 } 147 }
139 148
140 const OfflinePageItem* OfflinePageTabHelper::GetOfflinePageForTest() const { 149 const OfflinePageItem* OfflinePageTabHelper::GetOfflinePageForTest() const {
141 return provisional_offline_page_.get(); 150 return provisional_offline_page_.get();
142 } 151 }
143 152
144 } // namespace offline_pages 153 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698