| 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) | 25 #if defined(ANDROID_JAVA_UI) |
| 26 #include "chrome/browser/android/tab_android.h" | 26 #include "chrome/browser/android/tab_android.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 using content::BrowserContext; | 29 using content::BrowserContext; |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 using content::WebContents; | 31 using content::WebContents; |
| 32 using content::WebContentsObserver; | 32 using content::WebContentsObserver; |
| 33 using error_page::DnsProbeStatus; | 33 using error_page::DnsProbeStatus; |
| 34 using error_page::DnsProbeStatusToString; | 34 using error_page::DnsProbeStatusToString; |
| 35 using ui::PageTransition; | 35 using ui::PageTransition; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const GURL& validated_url, | 116 const GURL& validated_url, |
| 117 bool is_error_page, | 117 bool is_error_page, |
| 118 bool is_iframe_srcdoc) { | 118 bool is_iframe_srcdoc) { |
| 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 120 | 120 |
| 121 if (render_frame_host->GetParent()) | 121 if (render_frame_host->GetParent()) |
| 122 return; | 122 return; |
| 123 | 123 |
| 124 is_error_page_ = is_error_page; | 124 is_error_page_ = is_error_page; |
| 125 | 125 |
| 126 #if defined(OS_ANDROID) | 126 #if defined(ANDROID_JAVA_UI) |
| 127 SetHasOfflinePages(render_frame_host); | 127 SetHasOfflinePages(render_frame_host); |
| 128 #endif | 128 #endif |
| 129 } | 129 } |
| 130 | 130 |
| 131 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( | 131 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( |
| 132 content::RenderFrameHost* render_frame_host, | 132 content::RenderFrameHost* render_frame_host, |
| 133 const GURL& url, | 133 const GURL& url, |
| 134 PageTransition transition_type) { | 134 PageTransition transition_type) { |
| 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 136 | 136 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 bool NetErrorTabHelper::OnMessageReceived( | 171 bool NetErrorTabHelper::OnMessageReceived( |
| 172 const IPC::Message& message, | 172 const IPC::Message& message, |
| 173 content::RenderFrameHost* render_frame_host) { | 173 content::RenderFrameHost* render_frame_host) { |
| 174 bool handled = true; | 174 bool handled = true; |
| 175 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 175 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
| 176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | 176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, |
| 177 RunNetworkDiagnostics) | 177 RunNetworkDiagnostics) |
| 178 #if defined(OS_ANDROID) | 178 #if defined(ANDROID_JAVA_UI) |
| 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) | 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) |
| 180 #endif | 180 #endif |
| 181 IPC_MESSAGE_UNHANDLED(handled = false) | 181 IPC_MESSAGE_UNHANDLED(handled = false) |
| 182 IPC_END_MESSAGE_MAP() | 182 IPC_END_MESSAGE_MAP() |
| 183 | 183 |
| 184 return handled; | 184 return handled; |
| 185 } | 185 } |
| 186 | 186 |
| 187 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 187 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
| 188 : WebContentsObserver(contents), | 188 : WebContentsObserver(contents), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 return; | 278 return; |
| 279 // Sanitize URL prior to running diagnostics on it. | 279 // Sanitize URL prior to running diagnostics on it. |
| 280 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 280 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 283 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
| 284 const std::string& sanitized_url) { | 284 const std::string& sanitized_url) { |
| 285 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 285 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
| 286 } | 286 } |
| 287 | 287 |
| 288 #if defined(OS_ANDROID) | 288 #if defined(ANDROID_JAVA_UI) |
| 289 void NetErrorTabHelper::SetHasOfflinePages( | 289 void NetErrorTabHelper::SetHasOfflinePages( |
| 290 content::RenderFrameHost* render_frame_host) { | 290 content::RenderFrameHost* render_frame_host) { |
| 291 DCHECK(web_contents()); | 291 DCHECK(web_contents()); |
| 292 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | 292 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 293 bool has_offline_pages = tab && tab->HasOfflinePages(); | 293 bool has_offline_pages = tab && tab->HasOfflinePages(); |
| 294 render_frame_host->Send( | 294 render_frame_host->Send( |
| 295 new ChromeViewMsg_SetHasOfflinePages( | 295 new ChromeViewMsg_SetHasOfflinePages( |
| 296 render_frame_host->GetRoutingID(), | 296 render_frame_host->GetRoutingID(), |
| 297 has_offline_pages)); | 297 has_offline_pages)); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void NetErrorTabHelper::ShowOfflinePages() { | 300 void NetErrorTabHelper::ShowOfflinePages() { |
| 301 DCHECK(web_contents()); | 301 DCHECK(web_contents()); |
| 302 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | 302 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 303 if (tab) | 303 if (tab) |
| 304 tab->ShowOfflinePages(); | 304 tab->ShowOfflinePages(); |
| 305 } | 305 } |
| 306 #endif | 306 #endif |
| 307 | 307 |
| 308 } // namespace chrome_browser_net | 308 } // namespace chrome_browser_net |
| OLD | NEW |