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" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Ignore subframe creation - only main frame error pages can link to the | 97 // Ignore subframe creation - only main frame error pages can link to the |
98 // platform's network diagnostics dialog. | 98 // platform's network diagnostics dialog. |
99 if (render_frame_host->GetParent()) | 99 if (render_frame_host->GetParent()) |
100 return; | 100 return; |
101 render_frame_host->Send( | 101 render_frame_host->Send( |
102 new ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog( | 102 new ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog( |
103 render_frame_host->GetRoutingID(), | 103 render_frame_host->GetRoutingID(), |
104 CanShowNetworkDiagnosticsDialog())); | 104 CanShowNetworkDiagnosticsDialog())); |
105 } | 105 } |
106 | 106 |
107 void NetErrorTabHelper::DidStartNavigationToPendingEntry( | 107 void NetErrorTabHelper::DidStartNavigation( |
108 const GURL& url, | 108 content::NavigationHandle* navigation_handle) { |
109 content::ReloadType reload_type) { | 109 if (!navigation_handle->IsInMainFrame()) |
110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
111 | |
112 if (!is_error_page_) | |
113 return; | 110 return; |
114 | 111 |
115 // Only record reloads. | 112 if (navigation_handle->IsErrorPage() && |
116 if (reload_type != content::ReloadType::NONE) { | 113 navigation_handle->GetPageTransition() == ui::PAGE_TRANSITION_RELOAD) { |
117 error_page::RecordEvent( | 114 error_page::RecordEvent( |
118 error_page::NETWORK_ERROR_PAGE_BROWSER_INITIATED_RELOAD); | 115 error_page::NETWORK_ERROR_PAGE_BROWSER_INITIATED_RELOAD); |
119 } | 116 } |
120 } | |
121 | |
122 void NetErrorTabHelper::DidStartProvisionalLoadForFrame( | |
123 content::RenderFrameHost* render_frame_host, | |
124 const GURL& validated_url, | |
125 bool is_error_page, | |
126 bool is_iframe_srcdoc) { | |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
128 | |
129 if (render_frame_host->GetParent()) | |
130 return; | |
131 | |
132 is_error_page_ = is_error_page; | |
133 | 117 |
134 #if BUILDFLAG(ANDROID_JAVA_UI) | 118 #if BUILDFLAG(ANDROID_JAVA_UI) |
135 UpdateHasOfflinePages(render_frame_host); | 119 UpdateHasOfflinePages(navigation_handle->GetFrameTreeNodeId()); |
136 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 120 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
137 } | 121 } |
138 | 122 |
139 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( | 123 void NetErrorTabHelper::DidFinishNavigation( |
140 content::RenderFrameHost* render_frame_host, | 124 content::NavigationHandle* navigation_handle) { |
141 const GURL& url, | 125 if (!navigation_handle->IsInMainFrame()) |
142 PageTransition transition_type) { | 126 return; |
143 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
144 | 127 |
145 if (render_frame_host->GetParent()) | 128 if (IsDnsError(navigation_handle->GetNetErrorCode())) { |
146 return; | 129 dns_error_active_ = true; |
| 130 OnMainFrameDnsError(); |
| 131 } |
147 | 132 |
148 // Resend status every time an error page commits; this is somewhat spammy, | 133 // Resend status every time an error page commits; this is somewhat spammy, |
149 // but ensures that the status will make it to the real error page, even if | 134 // but ensures that the status will make it to the real error page, even if |
150 // the link doctor loads a blank intermediate page or the tab switches | 135 // the link doctor loads a blank intermediate page or the tab switches |
151 // renderer processes. | 136 // renderer processes. |
152 if (is_error_page_ && dns_error_active_) { | 137 if (navigation_handle->IsErrorPage() && dns_error_active_) { |
153 dns_error_page_committed_ = true; | 138 dns_error_page_committed_ = true; |
154 DVLOG(1) << "Committed error page; resending status."; | 139 DVLOG(1) << "Committed error page; resending status."; |
155 SendInfo(); | 140 SendInfo(); |
156 } else { | 141 } else if (navigation_handle->HasCommitted() && |
| 142 !navigation_handle->IsErrorPage()) { |
157 dns_error_active_ = false; | 143 dns_error_active_ = false; |
158 dns_error_page_committed_ = false; | 144 dns_error_page_committed_ = false; |
159 } | 145 } |
160 } | 146 } |
161 | 147 |
162 void NetErrorTabHelper::DidFailProvisionalLoad( | |
163 content::RenderFrameHost* render_frame_host, | |
164 const GURL& validated_url, | |
165 int error_code, | |
166 const base::string16& error_description, | |
167 bool was_ignored_by_handler) { | |
168 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
169 | |
170 if (render_frame_host->GetParent()) | |
171 return; | |
172 | |
173 if (IsDnsError(error_code)) { | |
174 dns_error_active_ = true; | |
175 OnMainFrameDnsError(); | |
176 } | |
177 } | |
178 | |
179 bool NetErrorTabHelper::OnMessageReceived( | 148 bool NetErrorTabHelper::OnMessageReceived( |
180 const IPC::Message& message, | 149 const IPC::Message& message, |
181 content::RenderFrameHost* render_frame_host) { | 150 content::RenderFrameHost* render_frame_host) { |
182 if (render_frame_host != web_contents()->GetMainFrame()) | 151 if (render_frame_host != web_contents()->GetMainFrame()) |
183 return false; | 152 return false; |
184 bool handled = true; | 153 bool handled = true; |
185 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 154 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
186 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | 155 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, |
187 RunNetworkDiagnostics) | 156 RunNetworkDiagnostics) |
188 #if BUILDFLAG(ANDROID_JAVA_UI) | 157 #if BUILDFLAG(ANDROID_JAVA_UI) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // Sanitize URL prior to running diagnostics on it. | 258 // Sanitize URL prior to running diagnostics on it. |
290 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 259 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
291 } | 260 } |
292 | 261 |
293 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 262 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
294 const std::string& sanitized_url) { | 263 const std::string& sanitized_url) { |
295 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 264 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
296 } | 265 } |
297 | 266 |
298 #if BUILDFLAG(ANDROID_JAVA_UI) | 267 #if BUILDFLAG(ANDROID_JAVA_UI) |
299 void NetErrorTabHelper::UpdateHasOfflinePages( | 268 void NetErrorTabHelper::UpdateHasOfflinePages(int frame_tree_node_id) { |
300 content::RenderFrameHost* render_frame_host) { | |
301 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this. | 269 // TODO(chili): remove entirely in M55 if AsyncLoading does not need this. |
302 SetHasOfflinePages(render_frame_host->GetFrameTreeNodeId(), false); | 270 SetHasOfflinePages(frame_tree_node_id, false); |
303 } | 271 } |
304 | 272 |
305 void NetErrorTabHelper::SetHasOfflinePages(int frame_tree_node_id, | 273 void NetErrorTabHelper::SetHasOfflinePages(int frame_tree_node_id, |
306 bool has_offline_pages) { | 274 bool has_offline_pages) { |
307 content::RenderFrameHost* render_frame_host = | 275 content::RenderFrameHost* render_frame_host = |
308 web_contents()->FindFrameByFrameTreeNodeId(frame_tree_node_id); | 276 web_contents()->FindFrameByFrameTreeNodeId(frame_tree_node_id); |
309 if (render_frame_host == nullptr) | 277 if (render_frame_host == nullptr) |
310 return; | 278 return; |
311 | 279 |
312 render_frame_host->Send(new ChromeViewMsg_SetHasOfflinePages( | 280 render_frame_host->Send(new ChromeViewMsg_SetHasOfflinePages( |
(...skipping 13 matching lines...) Expand all Loading... |
326 | 294 |
327 bool NetErrorTabHelper::IsFromErrorPage() const { | 295 bool NetErrorTabHelper::IsFromErrorPage() const { |
328 content::NavigationEntry* entry = | 296 content::NavigationEntry* entry = |
329 web_contents()->GetController().GetLastCommittedEntry(); | 297 web_contents()->GetController().GetLastCommittedEntry(); |
330 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); | 298 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); |
331 } | 299 } |
332 | 300 |
333 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 301 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
334 | 302 |
335 } // namespace chrome_browser_net | 303 } // namespace chrome_browser_net |
OLD | NEW |