Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/net/net_error_tab_helper.h" | 5 #include "chrome/browser/net/net_error_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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/io_thread.h" | 11 #include "chrome/browser/io_thread.h" |
| 12 #include "chrome/browser/net/dns_probe_service.h" | 12 #include "chrome/browser/net/dns_probe_service.h" |
| 13 #include "chrome/browser/net/net_error_diagnostics_dialog.h" | 13 #include "chrome/browser/net/net_error_diagnostics_dialog.h" |
| 14 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "components/error_page/common/net_error_info.h" | 18 #include "components/error_page/common/net_error_info.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 21 #include "ipc/ipc_message_macros.h" | 21 #include "ipc/ipc_message_macros.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 #if defined(OS_ANDROID) | |
| 26 #include "chrome/browser/android/tab_android.h" | |
| 27 #endif | |
| 28 | |
| 25 using content::BrowserContext; | 29 using content::BrowserContext; |
| 26 using content::BrowserThread; | 30 using content::BrowserThread; |
| 27 using content::WebContents; | 31 using content::WebContents; |
| 28 using content::WebContentsObserver; | 32 using content::WebContentsObserver; |
| 29 using error_page::DnsProbeStatus; | 33 using error_page::DnsProbeStatus; |
| 30 using error_page::DnsProbeStatusToString; | 34 using error_page::DnsProbeStatusToString; |
| 31 using ui::PageTransition; | 35 using ui::PageTransition; |
| 32 | 36 |
| 33 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); | 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); |
| 34 | 38 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 content::RenderFrameHost* render_frame_host, | 115 content::RenderFrameHost* render_frame_host, |
| 112 const GURL& validated_url, | 116 const GURL& validated_url, |
| 113 bool is_error_page, | 117 bool is_error_page, |
| 114 bool is_iframe_srcdoc) { | 118 bool is_iframe_srcdoc) { |
| 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 116 | 120 |
| 117 if (render_frame_host->GetParent()) | 121 if (render_frame_host->GetParent()) |
| 118 return; | 122 return; |
| 119 | 123 |
| 120 is_error_page_ = is_error_page; | 124 is_error_page_ = is_error_page; |
| 125 | |
| 126 #if defined(OS_ANDROID) | |
|
mmenke
2015/11/09 19:31:44
Should we use a different label for this, or add a
jianli
2015/11/09 21:59:52
Moved this part into a helper function that is pla
| |
| 127 TabAndroid* tab = | |
| 128 web_contents() ? TabAndroid::FromWebContents(web_contents()) : nullptr; | |
| 129 bool has_offline_pages = (tab && tab->HasOfflinePages()); | |
| 130 render_frame_host->Send( | |
| 131 new ChromeViewMsg_SetHasOfflinePages( | |
| 132 render_frame_host->GetRoutingID(), | |
| 133 has_offline_pages)); | |
| 134 #endif | |
| 121 } | 135 } |
| 122 | 136 |
| 123 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( | 137 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( |
| 124 content::RenderFrameHost* render_frame_host, | 138 content::RenderFrameHost* render_frame_host, |
| 125 const GURL& url, | 139 const GURL& url, |
| 126 PageTransition transition_type) { | 140 PageTransition transition_type) { |
| 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 128 | 142 |
| 129 if (render_frame_host->GetParent()) | 143 if (render_frame_host->GetParent()) |
| 130 return; | 144 return; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 160 } | 174 } |
| 161 } | 175 } |
| 162 | 176 |
| 163 bool NetErrorTabHelper::OnMessageReceived( | 177 bool NetErrorTabHelper::OnMessageReceived( |
| 164 const IPC::Message& message, | 178 const IPC::Message& message, |
| 165 content::RenderFrameHost* render_frame_host) { | 179 content::RenderFrameHost* render_frame_host) { |
| 166 bool handled = true; | 180 bool handled = true; |
| 167 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 181 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
| 168 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | 182 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, |
| 169 RunNetworkDiagnostics) | 183 RunNetworkDiagnostics) |
| 184 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) | |
| 170 IPC_MESSAGE_UNHANDLED(handled = false) | 185 IPC_MESSAGE_UNHANDLED(handled = false) |
| 171 IPC_END_MESSAGE_MAP() | 186 IPC_END_MESSAGE_MAP() |
| 172 | 187 |
| 173 return handled; | 188 return handled; |
| 174 } | 189 } |
| 175 | 190 |
| 176 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 191 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
| 177 : WebContentsObserver(contents), | 192 : WebContentsObserver(contents), |
| 178 is_error_page_(false), | 193 is_error_page_(false), |
| 179 dns_error_active_(false), | 194 dns_error_active_(false), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 return; | 282 return; |
| 268 // Sanitize URL prior to running diagnostics on it. | 283 // Sanitize URL prior to running diagnostics on it. |
| 269 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 284 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
| 270 } | 285 } |
| 271 | 286 |
| 272 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 287 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
| 273 const std::string& sanitized_url) { | 288 const std::string& sanitized_url) { |
| 274 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 289 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
| 275 } | 290 } |
| 276 | 291 |
| 292 void NetErrorTabHelper::ShowOfflinePages() { | |
| 293 #if defined(OS_ANDROID) | |
| 294 TabAndroid* tab = | |
| 295 web_contents() ? TabAndroid::FromWebContents(web_contents()) : nullptr; | |
| 296 if (tab) | |
| 297 tab->ShowOfflinePages(); | |
| 298 #endif | |
| 299 } | |
| 300 | |
| 277 } // namespace chrome_browser_net | 301 } // namespace chrome_browser_net |
| OLD | NEW |