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 "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/io_thread.h" | 10 #include "chrome/browser/io_thread.h" |
| 11 #include "chrome/browser/net/dns_probe_service.h" | 11 #include "chrome/browser/net/dns_probe_service.h" |
| 12 #include "chrome/browser/net/net_error_diagnostics_dialog.h" | 12 #include "chrome/browser/net/net_error_diagnostics_dialog.h" |
| 13 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/features.h" | 15 #include "chrome/common/features.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 "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "content/public/browser/web_contents_interface_registry.h" | |
| 24 #include "ipc/ipc_message_macros.h" | 25 #include "ipc/ipc_message_macros.h" |
| 25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 27 | 28 |
| 28 #if BUILDFLAG(ANDROID_JAVA_UI) | 29 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 29 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 30 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 30 #include "chrome/browser/android/tab_android.h" | 31 #include "chrome/browser/android/tab_android.h" |
| 31 #include "components/offline_pages/client_namespace_constants.h" | 32 #include "components/offline_pages/client_namespace_constants.h" |
| 32 #include "components/offline_pages/offline_page_feature.h" | 33 #include "components/offline_pages/offline_page_feature.h" |
| 33 #include "components/offline_pages/offline_page_item.h" | 34 #include "components/offline_pages/offline_page_item.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 void NetErrorTabHelper::set_state_for_testing(TestingState state) { | 92 void NetErrorTabHelper::set_state_for_testing(TestingState state) { |
| 92 testing_state_ = state; | 93 testing_state_ = state; |
| 93 } | 94 } |
| 94 | 95 |
| 95 void NetErrorTabHelper::RenderFrameCreated( | 96 void NetErrorTabHelper::RenderFrameCreated( |
| 96 content::RenderFrameHost* render_frame_host) { | 97 content::RenderFrameHost* render_frame_host) { |
| 97 // Ignore subframe creation - only main frame error pages can link to the | 98 // Ignore subframe creation - only main frame error pages can link to the |
| 98 // platform's network diagnostics dialog. | 99 // platform's network diagnostics dialog. |
| 99 if (render_frame_host->GetParent()) | 100 if (render_frame_host->GetParent()) |
| 100 return; | 101 return; |
| 101 render_frame_host->Send( | 102 |
| 102 new ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog( | 103 remote_network_diagnostics_client_.ForFrame(render_frame_host) |
|
Sam McNally
2016/09/07 01:48:47
Do we need to keep connections alive beyond this m
Ken Rockot(use gerrit already)
2016/09/07 22:48:18
Not in this case. I've removed RemoteFrameInterfac
| |
| 103 render_frame_host->GetRoutingID(), | 104 ->SetCanShowNetworkDiagnosticsDialog(CanShowNetworkDiagnosticsDialog()); |
| 104 CanShowNetworkDiagnosticsDialog())); | |
| 105 } | 105 } |
| 106 | 106 |
| 107 void NetErrorTabHelper::DidStartNavigationToPendingEntry( | 107 void NetErrorTabHelper::DidStartNavigationToPendingEntry( |
| 108 const GURL& url, | 108 const GURL& url, |
| 109 content::NavigationController::ReloadType reload_type) { | 109 content::NavigationController::ReloadType reload_type) { |
| 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 111 | 111 |
| 112 if (!is_error_page_) | 112 if (!is_error_page_) |
| 113 return; | 113 return; |
| 114 | 114 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool NetErrorTabHelper::OnMessageReceived( | 179 bool NetErrorTabHelper::OnMessageReceived( |
| 180 const IPC::Message& message, | 180 const IPC::Message& message, |
| 181 content::RenderFrameHost* render_frame_host) { | 181 content::RenderFrameHost* render_frame_host) { |
| 182 if (render_frame_host != web_contents()->GetMainFrame()) | 182 if (render_frame_host != web_contents()->GetMainFrame()) |
| 183 return false; | 183 return false; |
| 184 bool handled = true; | 184 bool handled = true; |
| 185 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 185 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
| 186 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | |
| 187 RunNetworkDiagnostics) | |
| 188 #if BUILDFLAG(ANDROID_JAVA_UI) | 186 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 189 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) | 187 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) |
| 188 #else | |
| 189 case 0: // MSVC complains if we have a switch with only a default clause. | |
|
Sam McNally
2016/09/07 01:48:47
Can we move the entire message map into the #if?
Ken Rockot(use gerrit already)
2016/09/07 22:48:18
Done
| |
| 190 return false; | |
| 190 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 191 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 191 IPC_MESSAGE_UNHANDLED(handled = false) | 192 IPC_MESSAGE_UNHANDLED(handled = false) |
| 192 IPC_END_MESSAGE_MAP() | 193 IPC_END_MESSAGE_MAP() |
| 193 | 194 |
| 194 return handled; | 195 return handled; |
| 195 } | 196 } |
| 196 | 197 |
| 197 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 198 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
| 198 : WebContentsObserver(contents), | 199 : WebContentsObserver(contents), |
| 200 network_diagnostics_binding_(contents, this), | |
| 199 is_error_page_(false), | 201 is_error_page_(false), |
| 200 dns_error_active_(false), | 202 dns_error_active_(false), |
| 201 dns_error_page_committed_(false), | 203 dns_error_page_committed_(false), |
| 202 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), | 204 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), |
| 203 weak_factory_(this) { | 205 weak_factory_(this) { |
| 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 206 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 205 | 207 |
| 206 // If this helper is under test, it won't have a WebContents. | 208 // If this helper is under test, it won't have a WebContents. |
| 207 if (contents) | 209 if (contents) |
| 208 InitializePref(contents); | 210 InitializePref(contents); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 | 281 |
| 280 if (!dns_probe_status_snoop_callback_.is_null()) | 282 if (!dns_probe_status_snoop_callback_.is_null()) |
| 281 dns_probe_status_snoop_callback_.Run(dns_probe_status_); | 283 dns_probe_status_snoop_callback_.Run(dns_probe_status_); |
| 282 } | 284 } |
| 283 | 285 |
| 284 void NetErrorTabHelper::RunNetworkDiagnostics(const GURL& url) { | 286 void NetErrorTabHelper::RunNetworkDiagnostics(const GURL& url) { |
| 285 // Only run diagnostics on HTTP or HTTPS URLs. Shouldn't receive URLs with | 287 // Only run diagnostics on HTTP or HTTPS URLs. Shouldn't receive URLs with |
| 286 // any other schemes, but the renderer is not trusted. | 288 // any other schemes, but the renderer is not trusted. |
| 287 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) | 289 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) |
| 288 return; | 290 return; |
| 291 | |
| 289 // Sanitize URL prior to running diagnostics on it. | 292 // Sanitize URL prior to running diagnostics on it. |
| 290 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 293 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
| 291 } | 294 } |
| 292 | 295 |
| 293 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 296 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
| 294 const std::string& sanitized_url) { | 297 const std::string& sanitized_url) { |
| 298 if (web_contents()->GetInterfaces()->GetCurrentTargetFrame() | |
| 299 != web_contents()->GetMainFrame()) | |
|
Sam McNally
2016/09/07 01:48:47
{}
Ken Rockot(use gerrit already)
2016/09/07 22:48:18
Done
| |
| 300 return; | |
| 301 | |
| 295 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 302 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
| 296 } | 303 } |
| 297 | 304 |
| 298 #if BUILDFLAG(ANDROID_JAVA_UI) | 305 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 299 void NetErrorTabHelper::UpdateHasOfflinePages( | 306 void NetErrorTabHelper::UpdateHasOfflinePages( |
| 300 content::RenderFrameHost* render_frame_host) { | 307 content::RenderFrameHost* render_frame_host) { |
| 301 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this. | 308 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this. |
| 302 SetHasOfflinePages(render_frame_host->GetFrameTreeNodeId(), false); | 309 SetHasOfflinePages(render_frame_host->GetFrameTreeNodeId(), false); |
| 303 } | 310 } |
| 304 | 311 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 326 | 333 |
| 327 bool NetErrorTabHelper::IsFromErrorPage() const { | 334 bool NetErrorTabHelper::IsFromErrorPage() const { |
| 328 content::NavigationEntry* entry = | 335 content::NavigationEntry* entry = |
| 329 web_contents()->GetController().GetLastCommittedEntry(); | 336 web_contents()->GetController().GetLastCommittedEntry(); |
| 330 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); | 337 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); |
| 331 } | 338 } |
| 332 | 339 |
| 333 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 340 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 334 | 341 |
| 335 } // namespace chrome_browser_net | 342 } // namespace chrome_browser_net |
| OLD | NEW |