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" |
| 25 #include "content/public/common/associated_interface_provider.h" |
24 #include "ipc/ipc_message_macros.h" | 26 #include "ipc/ipc_message_macros.h" |
25 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
27 | 29 |
28 #if BUILDFLAG(ANDROID_JAVA_UI) | 30 #if BUILDFLAG(ANDROID_JAVA_UI) |
29 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 31 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
30 #include "chrome/browser/android/tab_android.h" | 32 #include "chrome/browser/android/tab_android.h" |
31 #include "components/offline_pages/client_namespace_constants.h" | 33 #include "components/offline_pages/client_namespace_constants.h" |
32 #include "components/offline_pages/offline_page_feature.h" | 34 #include "components/offline_pages/offline_page_feature.h" |
33 #include "components/offline_pages/offline_page_item.h" | 35 #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) { | 93 void NetErrorTabHelper::set_state_for_testing(TestingState state) { |
92 testing_state_ = state; | 94 testing_state_ = state; |
93 } | 95 } |
94 | 96 |
95 void NetErrorTabHelper::RenderFrameCreated( | 97 void NetErrorTabHelper::RenderFrameCreated( |
96 content::RenderFrameHost* render_frame_host) { | 98 content::RenderFrameHost* render_frame_host) { |
97 // Ignore subframe creation - only main frame error pages can link to the | 99 // Ignore subframe creation - only main frame error pages can link to the |
98 // platform's network diagnostics dialog. | 100 // platform's network diagnostics dialog. |
99 if (render_frame_host->GetParent()) | 101 if (render_frame_host->GetParent()) |
100 return; | 102 return; |
101 render_frame_host->Send( | 103 |
102 new ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog( | 104 mojom::NetworkDiagnosticsClientAssociatedPtr client; |
103 render_frame_host->GetRoutingID(), | 105 render_frame_host->GetRemoteAssociatedInterfaces()->GetInterface(&client); |
104 CanShowNetworkDiagnosticsDialog())); | 106 client->SetCanShowNetworkDiagnosticsDialog(CanShowNetworkDiagnosticsDialog()); |
105 } | 107 } |
106 | 108 |
107 void NetErrorTabHelper::DidStartNavigationToPendingEntry( | 109 void NetErrorTabHelper::DidStartNavigationToPendingEntry( |
108 const GURL& url, | 110 const GURL& url, |
109 content::NavigationController::ReloadType reload_type) { | 111 content::NavigationController::ReloadType reload_type) { |
110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
111 | 113 |
112 if (!is_error_page_) | 114 if (!is_error_page_) |
113 return; | 115 return; |
114 | 116 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 dns_error_active_ = true; | 176 dns_error_active_ = true; |
175 OnMainFrameDnsError(); | 177 OnMainFrameDnsError(); |
176 } | 178 } |
177 } | 179 } |
178 | 180 |
179 bool NetErrorTabHelper::OnMessageReceived( | 181 bool NetErrorTabHelper::OnMessageReceived( |
180 const IPC::Message& message, | 182 const IPC::Message& message, |
181 content::RenderFrameHost* render_frame_host) { | 183 content::RenderFrameHost* render_frame_host) { |
182 if (render_frame_host != web_contents()->GetMainFrame()) | 184 if (render_frame_host != web_contents()->GetMainFrame()) |
183 return false; | 185 return false; |
| 186 #if BUILDFLAG(ANDROID_JAVA_UI) |
184 bool handled = true; | 187 bool handled = true; |
185 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 188 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
186 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | |
187 RunNetworkDiagnostics) | |
188 #if BUILDFLAG(ANDROID_JAVA_UI) | |
189 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) | 189 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) |
190 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
191 IPC_MESSAGE_UNHANDLED(handled = false) | 190 IPC_MESSAGE_UNHANDLED(handled = false) |
192 IPC_END_MESSAGE_MAP() | 191 IPC_END_MESSAGE_MAP() |
193 | 192 |
194 return handled; | 193 return handled; |
| 194 #else |
| 195 return false; |
| 196 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
195 } | 197 } |
196 | 198 |
197 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 199 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
198 : WebContentsObserver(contents), | 200 : WebContentsObserver(contents), |
| 201 network_diagnostics_binding_(contents, this), |
199 is_error_page_(false), | 202 is_error_page_(false), |
200 dns_error_active_(false), | 203 dns_error_active_(false), |
201 dns_error_page_committed_(false), | 204 dns_error_page_committed_(false), |
202 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), | 205 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), |
203 weak_factory_(this) { | 206 weak_factory_(this) { |
204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
205 | 208 |
206 // If this helper is under test, it won't have a WebContents. | 209 // If this helper is under test, it won't have a WebContents. |
207 if (contents) | 210 if (contents) |
208 InitializePref(contents); | 211 InitializePref(contents); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 282 |
280 if (!dns_probe_status_snoop_callback_.is_null()) | 283 if (!dns_probe_status_snoop_callback_.is_null()) |
281 dns_probe_status_snoop_callback_.Run(dns_probe_status_); | 284 dns_probe_status_snoop_callback_.Run(dns_probe_status_); |
282 } | 285 } |
283 | 286 |
284 void NetErrorTabHelper::RunNetworkDiagnostics(const GURL& url) { | 287 void NetErrorTabHelper::RunNetworkDiagnostics(const GURL& url) { |
285 // Only run diagnostics on HTTP or HTTPS URLs. Shouldn't receive URLs with | 288 // Only run diagnostics on HTTP or HTTPS URLs. Shouldn't receive URLs with |
286 // any other schemes, but the renderer is not trusted. | 289 // any other schemes, but the renderer is not trusted. |
287 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) | 290 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) |
288 return; | 291 return; |
| 292 |
289 // Sanitize URL prior to running diagnostics on it. | 293 // Sanitize URL prior to running diagnostics on it. |
290 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 294 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
291 } | 295 } |
292 | 296 |
293 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 297 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
294 const std::string& sanitized_url) { | 298 const std::string& sanitized_url) { |
| 299 if (web_contents()->GetInterfaces()->GetCurrentTargetFrame() |
| 300 != web_contents()->GetMainFrame()) { |
| 301 return; |
| 302 } |
| 303 |
295 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 304 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
296 } | 305 } |
297 | 306 |
298 #if BUILDFLAG(ANDROID_JAVA_UI) | 307 #if BUILDFLAG(ANDROID_JAVA_UI) |
299 void NetErrorTabHelper::UpdateHasOfflinePages( | 308 void NetErrorTabHelper::UpdateHasOfflinePages( |
300 content::RenderFrameHost* render_frame_host) { | 309 content::RenderFrameHost* render_frame_host) { |
301 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this. | 310 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this. |
302 SetHasOfflinePages(render_frame_host->GetFrameTreeNodeId(), false); | 311 SetHasOfflinePages(render_frame_host->GetFrameTreeNodeId(), false); |
303 } | 312 } |
304 | 313 |
(...skipping 21 matching lines...) Expand all Loading... |
326 | 335 |
327 bool NetErrorTabHelper::IsFromErrorPage() const { | 336 bool NetErrorTabHelper::IsFromErrorPage() const { |
328 content::NavigationEntry* entry = | 337 content::NavigationEntry* entry = |
329 web_contents()->GetController().GetLastCommittedEntry(); | 338 web_contents()->GetController().GetLastCommittedEntry(); |
330 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); | 339 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); |
331 } | 340 } |
332 | 341 |
333 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 342 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
334 | 343 |
335 } // namespace chrome_browser_net | 344 } // namespace chrome_browser_net |
OLD | NEW |