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" | |
16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
18 #include "components/error_page/common/net_error_info.h" | 17 #include "components/error_page/common/net_error_info.h" |
19 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/navigation_handle.h" | 21 #include "content/public/browser/navigation_handle.h" |
23 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
24 #include "content/public/common/associated_interface_provider.h" | 23 #include "content/public/common/associated_interface_provider.h" |
25 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
26 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
28 | 27 |
29 #if BUILDFLAG(ANDROID_JAVA_UI) | 28 #if defined(OS_ANDROID) |
30 #include "base/guid.h" | 29 #include "base/guid.h" |
31 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" | 30 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" |
32 #include "components/offline_pages/core/background/request_coordinator.h" | 31 #include "components/offline_pages/core/background/request_coordinator.h" |
33 #include "components/offline_pages/core/client_namespace_constants.h" | 32 #include "components/offline_pages/core/client_namespace_constants.h" |
34 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 33 #endif // defined(OS_ANDROID) |
35 | 34 |
36 using content::BrowserContext; | 35 using content::BrowserContext; |
37 using content::BrowserThread; | 36 using content::BrowserThread; |
38 using content::WebContents; | 37 using content::WebContents; |
39 using content::WebContentsObserver; | 38 using content::WebContentsObserver; |
40 using error_page::DnsProbeStatus; | 39 using error_page::DnsProbeStatus; |
41 using error_page::DnsProbeStatusToString; | 40 using error_page::DnsProbeStatusToString; |
42 using ui::PageTransition; | 41 using ui::PageTransition; |
43 | 42 |
44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); | 43 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 dns_error_active_ = false; | 131 dns_error_active_ = false; |
133 dns_error_page_committed_ = false; | 132 dns_error_page_committed_ = false; |
134 } | 133 } |
135 } | 134 } |
136 | 135 |
137 bool NetErrorTabHelper::OnMessageReceived( | 136 bool NetErrorTabHelper::OnMessageReceived( |
138 const IPC::Message& message, | 137 const IPC::Message& message, |
139 content::RenderFrameHost* render_frame_host) { | 138 content::RenderFrameHost* render_frame_host) { |
140 if (render_frame_host != web_contents()->GetMainFrame()) | 139 if (render_frame_host != web_contents()->GetMainFrame()) |
141 return false; | 140 return false; |
142 #if BUILDFLAG(ANDROID_JAVA_UI) | 141 #if defined(OS_ANDROID) |
143 bool handled = true; | 142 bool handled = true; |
144 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 143 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
145 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DownloadPageLater, DownloadPageLater) | 144 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DownloadPageLater, DownloadPageLater) |
146 IPC_MESSAGE_UNHANDLED(handled = false) | 145 IPC_MESSAGE_UNHANDLED(handled = false) |
147 IPC_END_MESSAGE_MAP() | 146 IPC_END_MESSAGE_MAP() |
148 | 147 |
149 return handled; | 148 return handled; |
150 #else | 149 #else |
151 return false; | 150 return false; |
152 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 151 #endif // defined(OS_ANDROID) |
153 } | 152 } |
154 | 153 |
155 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 154 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
156 : WebContentsObserver(contents), | 155 : WebContentsObserver(contents), |
157 network_diagnostics_bindings_(contents, this), | 156 network_diagnostics_bindings_(contents, this), |
158 is_error_page_(false), | 157 is_error_page_(false), |
159 dns_error_active_(false), | 158 dns_error_active_(false), |
160 dns_error_page_committed_(false), | 159 dns_error_page_committed_(false), |
161 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), | 160 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), |
162 weak_factory_(this) { | 161 weak_factory_(this) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 201 |
203 DVLOG(1) << "Finished DNS probe with result " | 202 DVLOG(1) << "Finished DNS probe with result " |
204 << DnsProbeStatusToString(result) << "."; | 203 << DnsProbeStatusToString(result) << "."; |
205 | 204 |
206 dns_probe_status_ = result; | 205 dns_probe_status_ = result; |
207 | 206 |
208 if (dns_error_page_committed_) | 207 if (dns_error_page_committed_) |
209 SendInfo(); | 208 SendInfo(); |
210 } | 209 } |
211 | 210 |
212 #if BUILDFLAG(ANDROID_JAVA_UI) | 211 #if defined(OS_ANDROID) |
213 void NetErrorTabHelper::DownloadPageLater() { | 212 void NetErrorTabHelper::DownloadPageLater() { |
214 // Makes sure that this is coming from an error page. | 213 // Makes sure that this is coming from an error page. |
215 content::NavigationEntry* entry = | 214 content::NavigationEntry* entry = |
216 web_contents()->GetController().GetLastCommittedEntry(); | 215 web_contents()->GetController().GetLastCommittedEntry(); |
217 if (!entry || entry->GetPageType() != content::PAGE_TYPE_ERROR) | 216 if (!entry || entry->GetPageType() != content::PAGE_TYPE_ERROR) |
218 return; | 217 return; |
219 | 218 |
220 // Only download the page for HTTP/HTTPS URLs. | 219 // Only download the page for HTTP/HTTPS URLs. |
221 GURL url(entry->GetVirtualURL()); | 220 GURL url(entry->GetVirtualURL()); |
222 if (!url.SchemeIsHTTPOrHTTPS()) | 221 if (!url.SchemeIsHTTPOrHTTPS()) |
223 return; | 222 return; |
224 | 223 |
225 DownloadPageLaterHelper(url); | 224 DownloadPageLaterHelper(url); |
226 } | 225 } |
227 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 226 #endif // defined(OS_ANDROID) |
228 | 227 |
229 void NetErrorTabHelper::InitializePref(WebContents* contents) { | 228 void NetErrorTabHelper::InitializePref(WebContents* contents) { |
230 DCHECK(contents); | 229 DCHECK(contents); |
231 | 230 |
232 BrowserContext* browser_context = contents->GetBrowserContext(); | 231 BrowserContext* browser_context = contents->GetBrowserContext(); |
233 Profile* profile = Profile::FromBrowserContext(browser_context); | 232 Profile* profile = Profile::FromBrowserContext(browser_context); |
234 resolve_errors_with_web_service_.Init( | 233 resolve_errors_with_web_service_.Init( |
235 prefs::kAlternateErrorPagesEnabled, | 234 prefs::kAlternateErrorPagesEnabled, |
236 profile->GetPrefs()); | 235 profile->GetPrefs()); |
237 } | 236 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 269 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
271 const std::string& sanitized_url) { | 270 const std::string& sanitized_url) { |
272 if (network_diagnostics_bindings_.GetCurrentTargetFrame() | 271 if (network_diagnostics_bindings_.GetCurrentTargetFrame() |
273 != web_contents()->GetMainFrame()) { | 272 != web_contents()->GetMainFrame()) { |
274 return; | 273 return; |
275 } | 274 } |
276 | 275 |
277 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 276 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
278 } | 277 } |
279 | 278 |
280 #if BUILDFLAG(ANDROID_JAVA_UI) | 279 #if defined(OS_ANDROID) |
281 void NetErrorTabHelper::DownloadPageLaterHelper(const GURL& page_url) { | 280 void NetErrorTabHelper::DownloadPageLaterHelper(const GURL& page_url) { |
282 offline_pages::RequestCoordinator* request_coordinator = | 281 offline_pages::RequestCoordinator* request_coordinator = |
283 offline_pages::RequestCoordinatorFactory::GetForBrowserContext( | 282 offline_pages::RequestCoordinatorFactory::GetForBrowserContext( |
284 web_contents()->GetBrowserContext()); | 283 web_contents()->GetBrowserContext()); |
285 DCHECK(request_coordinator) << "No RequestCoordinator for SavePageLater"; | 284 DCHECK(request_coordinator) << "No RequestCoordinator for SavePageLater"; |
286 offline_pages::ClientId client_id( | 285 offline_pages::ClientId client_id( |
287 offline_pages::kAsyncNamespace, base::GenerateGUID()); | 286 offline_pages::kAsyncNamespace, base::GenerateGUID()); |
288 request_coordinator->SavePageLater( | 287 request_coordinator->SavePageLater( |
289 page_url, client_id, true /*user_requested*/, | 288 page_url, client_id, true /*user_requested*/, |
290 offline_pages::RequestCoordinator::RequestAvailability:: | 289 offline_pages::RequestCoordinator::RequestAvailability:: |
291 ENABLED_FOR_OFFLINER); | 290 ENABLED_FOR_OFFLINER); |
292 } | 291 } |
293 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 292 #endif // defined(OS_ANDROID) |
294 | 293 |
295 } // namespace chrome_browser_net | 294 } // namespace chrome_browser_net |
OLD | NEW |