Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/net/net_error_tab_helper.cc

Issue 2310583002: Convert some NetError[Tab]Helper messages to mojom (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/associated_interface_provider.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
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 mojom::NetworkDiagnosticsClientAssociatedPtr client;
103 render_frame_host->GetRoutingID(), 104 render_frame_host->GetRemoteAssociatedInterfaces()->GetInterface(&client);
104 CanShowNetworkDiagnosticsDialog())); 105 client->SetCanShowNetworkDiagnosticsDialog(CanShowNetworkDiagnosticsDialog());
105 } 106 }
106 107
107 void NetErrorTabHelper::DidStartNavigationToPendingEntry( 108 void NetErrorTabHelper::DidStartNavigationToPendingEntry(
108 const GURL& url, 109 const GURL& url,
109 content::ReloadType reload_type) { 110 content::ReloadType reload_type) {
110 DCHECK_CURRENTLY_ON(BrowserThread::UI); 111 DCHECK_CURRENTLY_ON(BrowserThread::UI);
111 112
112 if (!is_error_page_) 113 if (!is_error_page_)
113 return; 114 return;
114 115
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 dns_error_active_ = true; 175 dns_error_active_ = true;
175 OnMainFrameDnsError(); 176 OnMainFrameDnsError();
176 } 177 }
177 } 178 }
178 179
179 bool NetErrorTabHelper::OnMessageReceived( 180 bool NetErrorTabHelper::OnMessageReceived(
180 const IPC::Message& message, 181 const IPC::Message& message,
181 content::RenderFrameHost* render_frame_host) { 182 content::RenderFrameHost* render_frame_host) {
182 if (render_frame_host != web_contents()->GetMainFrame()) 183 if (render_frame_host != web_contents()->GetMainFrame())
183 return false; 184 return false;
185 #if BUILDFLAG(ANDROID_JAVA_UI)
184 bool handled = true; 186 bool handled = true;
185 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) 187 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) 188 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages)
190 #endif // BUILDFLAG(ANDROID_JAVA_UI)
191 IPC_MESSAGE_UNHANDLED(handled = false) 189 IPC_MESSAGE_UNHANDLED(handled = false)
192 IPC_END_MESSAGE_MAP() 190 IPC_END_MESSAGE_MAP()
193 191
194 return handled; 192 return handled;
193 #else
194 return false;
195 #endif // BUILDFLAG(ANDROID_JAVA_UI)
195 } 196 }
196 197
197 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) 198 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents)
198 : WebContentsObserver(contents), 199 : WebContentsObserver(contents),
200 network_diagnostics_bindings_(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
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 (network_diagnostics_bindings_.GetCurrentTargetFrame()
299 != web_contents()->GetMainFrame()) {
300 return;
301 }
302
295 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); 303 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url);
296 } 304 }
297 305
298 #if BUILDFLAG(ANDROID_JAVA_UI) 306 #if BUILDFLAG(ANDROID_JAVA_UI)
299 void NetErrorTabHelper::UpdateHasOfflinePages( 307 void NetErrorTabHelper::UpdateHasOfflinePages(
300 content::RenderFrameHost* render_frame_host) { 308 content::RenderFrameHost* render_frame_host) {
301 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this. 309 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this.
302 SetHasOfflinePages(render_frame_host->GetFrameTreeNodeId(), false); 310 SetHasOfflinePages(render_frame_host->GetFrameTreeNodeId(), false);
303 } 311 }
304 312
(...skipping 21 matching lines...) Expand all
326 334
327 bool NetErrorTabHelper::IsFromErrorPage() const { 335 bool NetErrorTabHelper::IsFromErrorPage() const {
328 content::NavigationEntry* entry = 336 content::NavigationEntry* entry =
329 web_contents()->GetController().GetLastCommittedEntry(); 337 web_contents()->GetController().GetLastCommittedEntry();
330 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); 338 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR);
331 } 339 }
332 340
333 #endif // BUILDFLAG(ANDROID_JAVA_UI) 341 #endif // BUILDFLAG(ANDROID_JAVA_UI)
334 342
335 } // namespace chrome_browser_net 343 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/net_error_tab_helper.h ('k') | chrome/browser/net/net_error_tab_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698