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

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

Issue 1721103002: Switch between online and offline version per network connection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch Created 4 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/web_contents.h"
13 #include "net/base/net_errors.h"
14 #include "net/base/network_change_notifier.h"
15
16 namespace {
17
18 bool IsOnline() {
19 enum net::NetworkChangeNotifier::ConnectionType connection =
20 net::NetworkChangeNotifier::GetConnectionType();
21 return connection != net::NetworkChangeNotifier::CONNECTION_NONE &&
Pete Williamson 2016/02/23 23:13:47 Let's replace this IsOnline check with NetworkChan
22 connection != net::NetworkChangeNotifier::CONNECTION_BLUETOOTH;
23 }
24
25 }
26
27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OfflinePageTabHelper);
28
29 OfflinePageTabHelper::~OfflinePageTabHelper() {}
30
31 OfflinePageTabHelper::OfflinePageTabHelper(content::WebContents* web_contents)
32 : content::WebContentsObserver(web_contents) {
33 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
34 }
35
36 void OfflinePageTabHelper::DidStartProvisionalLoadForFrame(
37 content::RenderFrameHost* render_frame_host,
38 const GURL& validated_url,
39 bool is_error_page,
40 bool is_iframe_srcdoc) {
41 if (!IsOnline() ||
Pete Williamson 2016/02/23 23:13:47 Why return early if we are offline, are we intenti
Pete Williamson 2016/02/24 00:35:33 Ah, nevermind, I see what is going on now, this is
42 render_frame_host->GetParent() != nullptr) {
43 return;
44 }
45
46 GURL online_url = offline_pages::OfflinePageUtils::GetOnlineURLForOfflineURL(
47 web_contents()->GetBrowserContext(), validated_url);
48 if (!online_url.is_valid())
49 return;
50
51 content::NavigationController::LoadURLParams load_params(online_url);
52 web_contents()->GetController().LoadURLWithParams(load_params);
53 }
54
55 void OfflinePageTabHelper::DidFailProvisionalLoad(
56 content::RenderFrameHost* render_frame_host,
57 const GURL& validated_url,
58 int error_code,
59 const base::string16& error_description,
60 bool was_ignored_by_handler) {
61 if (error_code != net::ERR_INTERNET_DISCONNECTED ||
62 IsOnline() ||
63 render_frame_host->GetParent() != nullptr) {
64 return;
65 }
66
67 GURL offline_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL(
68 web_contents()->GetBrowserContext(), validated_url);
69 if (!offline_url.is_valid())
70 return;
71
72 content::NavigationController::LoadURLParams load_params(offline_url);
73 web_contents()->GetController().LoadURLWithParams(load_params);
74 }
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_tab_helper.h ('k') | chrome/browser/ui/tab_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698