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

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

Issue 1841903002: Redirect to offline copy on other possible internet connection failures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 base::Bind(&OfflinePageTabHelper::RedirectFromOfflineToOnline, 69 base::Bind(&OfflinePageTabHelper::RedirectFromOfflineToOnline,
70 weak_ptr_factory_.GetWeakPtr(), 70 weak_ptr_factory_.GetWeakPtr(),
71 online_url)); 71 online_url));
72 } 72 }
73 73
74 void OfflinePageTabHelper::DidFinishNavigation( 74 void OfflinePageTabHelper::DidFinishNavigation(
75 content::NavigationHandle* navigation_handle) { 75 content::NavigationHandle* navigation_handle) {
76 GURL last_redirect_from_url_copy = last_redirect_from_url_; 76 GURL last_redirect_from_url_copy = last_redirect_from_url_;
77 last_redirect_from_url_ = GURL(); 77 last_redirect_from_url_ = GURL();
78 78
79 // Skips non-main frame or load failure other than no network. 79 // Skips non-main frame.
80 if (navigation_handle->GetNetErrorCode() != net::ERR_INTERNET_DISCONNECTED || 80 if (!navigation_handle->IsInMainFrame())
81 !navigation_handle->IsInMainFrame()) { 81 return;
82
83 // Skips load failure other than no network.
84 net::Error error_code = navigation_handle->GetNetErrorCode();
85 if (error_code != net::ERR_INTERNET_DISCONNECTED &&
86 error_code != net::ERR_NAME_NOT_RESOLVED &&
87 error_code != net::ERR_ADDRESS_UNREACHABLE &&
88 error_code != net::ERR_PROXY_CONNECTION_FAILED) {
82 return; 89 return;
83 } 90 }
84 91
85 // Redirecting to offline version will only take effect when there is no
86 // network connection.
87 if (!net::NetworkChangeNotifier::IsOffline())
88 return;
89
90 // On a forward or back transition, don't affect the order of the nav stack. 92 // On a forward or back transition, don't affect the order of the nav stack.
91 if (navigation_handle->GetPageTransition() == 93 if (navigation_handle->GetPageTransition() ==
92 ui::PAGE_TRANSITION_FORWARD_BACK) { 94 ui::PAGE_TRANSITION_FORWARD_BACK) {
93 return; 95 return;
94 } 96 }
95 97
96 // Skips if not loading an online version of saved page. 98 // Skips if not loading an online version of saved page.
97 GURL offline_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL( 99 GURL offline_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL(
98 web_contents()->GetBrowserContext(), navigation_handle->GetURL()); 100 web_contents()->GetBrowserContext(), navigation_handle->GetURL());
99 if (!offline_url.is_valid()) 101 if (!offline_url.is_valid())
(...skipping 20 matching lines...) Expand all
120 122
121 void OfflinePageTabHelper::RedirectFromOnlineToOffline( 123 void OfflinePageTabHelper::RedirectFromOnlineToOffline(
122 const GURL& offline_url) { 124 const GURL& offline_url) {
123 UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOfflineCount", 1); 125 UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOfflineCount", 1);
124 content::NavigationController::LoadURLParams load_params(offline_url); 126 content::NavigationController::LoadURLParams load_params(offline_url);
125 load_params.transition_type = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 127 load_params.transition_type = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
126 web_contents()->GetController().LoadURLWithParams(load_params); 128 web_contents()->GetController().LoadURLWithParams(load_params);
127 } 129 }
128 130
129 } // namespace offline_pages 131 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698