Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |