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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/offline_pages/offline_page_tab_helper.cc
diff --git a/chrome/browser/android/offline_pages/offline_page_tab_helper.cc b/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..94988838db422fcf52d159dddae5bf96e0f52309
--- /dev/null
+++ b/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
@@ -0,0 +1,74 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
+
+#include "base/logging.h"
+#include "chrome/browser/android/offline_pages/offline_page_utils.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+#include "net/base/net_errors.h"
+#include "net/base/network_change_notifier.h"
+
+namespace {
+
+bool IsOnline() {
+ enum net::NetworkChangeNotifier::ConnectionType connection =
+ net::NetworkChangeNotifier::GetConnectionType();
+ return connection != net::NetworkChangeNotifier::CONNECTION_NONE &&
Pete Williamson 2016/02/23 23:13:47 Let's replace this IsOnline check with NetworkChan
+ connection != net::NetworkChangeNotifier::CONNECTION_BLUETOOTH;
+}
+
+}
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(OfflinePageTabHelper);
+
+OfflinePageTabHelper::~OfflinePageTabHelper() {}
+
+OfflinePageTabHelper::OfflinePageTabHelper(content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+}
+
+void OfflinePageTabHelper::DidStartProvisionalLoadForFrame(
+ content::RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ bool is_error_page,
+ bool is_iframe_srcdoc) {
+ 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
+ render_frame_host->GetParent() != nullptr) {
+ return;
+ }
+
+ GURL online_url = offline_pages::OfflinePageUtils::GetOnlineURLForOfflineURL(
+ web_contents()->GetBrowserContext(), validated_url);
+ if (!online_url.is_valid())
+ return;
+
+ content::NavigationController::LoadURLParams load_params(online_url);
+ web_contents()->GetController().LoadURLWithParams(load_params);
+}
+
+void OfflinePageTabHelper::DidFailProvisionalLoad(
+ content::RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ int error_code,
+ const base::string16& error_description,
+ bool was_ignored_by_handler) {
+ if (error_code != net::ERR_INTERNET_DISCONNECTED ||
+ IsOnline() ||
+ render_frame_host->GetParent() != nullptr) {
+ return;
+ }
+
+ GURL offline_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL(
+ web_contents()->GetBrowserContext(), validated_url);
+ if (!offline_url.is_valid())
+ return;
+
+ content::NavigationController::LoadURLParams load_params(offline_url);
+ web_contents()->GetController().LoadURLWithParams(load_params);
+}
« 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