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

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: 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 25 matching lines...) Expand all
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 // This is a new navigation so we can invalidate any previously scheduled 40 // This is a new navigation so we can invalidate any previously scheduled
41 // operations. 41 // operations.
42 weak_ptr_factory_.InvalidateWeakPtrs(); 42 weak_ptr_factory_.InvalidateWeakPtrs();
43 43
44 // Since this is a new navigation, we will reset the cached offline page, 44 // Since this is a new navigation, we will reset the cached offline page,
45 offline_page_ = nullptr; 45 offline_page_ = nullptr;
46 offline_header_.Clear();
Dmitry Titov 2016/09/16 21:37:23 after rebase, you will need to do figure out when
jianli 2016/09/16 23:08:48 Yes. I think we should also avoid clearing is_offl
46 is_offline_preview_ = false; 47 is_offline_preview_ = false;
47 48
48 reloading_url_on_net_error_ = false; 49 reloading_url_on_net_error_ = false;
49 } 50 }
50 51
51 void OfflinePageTabHelper::DidFinishNavigation( 52 void OfflinePageTabHelper::DidFinishNavigation(
52 content::NavigationHandle* navigation_handle) { 53 content::NavigationHandle* navigation_handle) {
53 // Skips non-main frame. 54 // Skips non-main frame.
54 if (!navigation_handle->IsInMainFrame()) 55 if (!navigation_handle->IsInMainFrame())
55 return; 56 return;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 OfflinePageRequestJob::AggregatedRequestResult:: 107 OfflinePageRequestJob::AggregatedRequestResult::
107 PAGE_NOT_FOUND_ON_FLAKY_NETWORK); 108 PAGE_NOT_FOUND_ON_FLAKY_NETWORK);
108 return; 109 return;
109 } 110 }
110 111
111 reloading_url_on_net_error_ = true; 112 reloading_url_on_net_error_ = true;
112 113
113 // Reloads the page with extra header set to force loading the offline page. 114 // Reloads the page with extra header set to force loading the offline page.
114 content::NavigationController::LoadURLParams load_params(offline_page->url); 115 content::NavigationController::LoadURLParams load_params(offline_page->url);
115 load_params.transition_type = ui::PAGE_TRANSITION_RELOAD; 116 load_params.transition_type = ui::PAGE_TRANSITION_RELOAD;
116 load_params.extra_headers = kOfflinePageHeader; 117 OfflinePageHeader offline_header;
117 load_params.extra_headers += ":"; 118 offline_header.reason = OfflinePageHeader::Reason::NET_ERROR;
118 load_params.extra_headers += kOfflinePageHeaderReasonKey; 119 load_params.extra_headers = offline_header.ToFullHeaderString();
119 load_params.extra_headers += "=";
120 load_params.extra_headers += kOfflinePageHeaderReasonValueDueToNetError;
121 web_contents()->GetController().LoadURLWithParams(load_params); 120 web_contents()->GetController().LoadURLWithParams(load_params);
122 } 121 }
123 122
124 void OfflinePageTabHelper::SetOfflinePage(const OfflinePageItem& offline_page, 123 void OfflinePageTabHelper::SetOfflinePage(
125 bool is_offline_preview) { 124 const OfflinePageItem& offline_page,
125 const OfflinePageHeader& offline_header,
126 bool is_offline_preview) {
126 offline_page_ = base::MakeUnique<OfflinePageItem>(offline_page); 127 offline_page_ = base::MakeUnique<OfflinePageItem>(offline_page);
128 offline_header_ = offline_header;
127 is_offline_preview_ = is_offline_preview; 129 is_offline_preview_ = is_offline_preview;
128 } 130 }
129 131
130 } // namespace offline_pages 132 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698