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