Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 BUILDFLAG(ANDROID_JAVA_UI) |
| 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, |
| 146 OnDownloadPageLater) | |
| 147 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetIsShowingDownloadButtonInErrorPage, | |
| 148 OnSetIsShowingDownloadButtonInErrorPage) | |
| 146 IPC_MESSAGE_UNHANDLED(handled = false) | 149 IPC_MESSAGE_UNHANDLED(handled = false) |
| 147 IPC_END_MESSAGE_MAP() | 150 IPC_END_MESSAGE_MAP() |
| 148 | 151 |
| 149 return handled; | 152 return handled; |
| 150 #else | 153 #else |
| 151 return false; | 154 return false; |
| 152 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 155 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 153 } | 156 } |
| 154 | 157 |
| 155 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 158 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
| 156 : WebContentsObserver(contents), | 159 : WebContentsObserver(contents), |
| 157 network_diagnostics_bindings_(contents, this), | 160 network_diagnostics_bindings_(contents, this), |
| 158 is_error_page_(false), | 161 is_error_page_(false), |
| 159 dns_error_active_(false), | 162 dns_error_active_(false), |
| 160 dns_error_page_committed_(false), | 163 dns_error_page_committed_(false), |
| 164 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 165 is_showing_download_button_in_error_page_(false), | |
| 166 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
| 161 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), | 167 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), |
| 162 weak_factory_(this) { | 168 weak_factory_(this) { |
| 163 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 169 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 164 | 170 |
| 165 // If this helper is under test, it won't have a WebContents. | 171 // If this helper is under test, it won't have a WebContents. |
| 166 if (contents) | 172 if (contents) |
| 167 InitializePref(contents); | 173 InitializePref(contents); |
| 168 } | 174 } |
| 169 | 175 |
| 170 void NetErrorTabHelper::OnMainFrameDnsError() { | 176 void NetErrorTabHelper::OnMainFrameDnsError() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 DVLOG(1) << "Finished DNS probe with result " | 209 DVLOG(1) << "Finished DNS probe with result " |
| 204 << DnsProbeStatusToString(result) << "."; | 210 << DnsProbeStatusToString(result) << "."; |
| 205 | 211 |
| 206 dns_probe_status_ = result; | 212 dns_probe_status_ = result; |
| 207 | 213 |
| 208 if (dns_error_page_committed_) | 214 if (dns_error_page_committed_) |
| 209 SendInfo(); | 215 SendInfo(); |
| 210 } | 216 } |
| 211 | 217 |
| 212 #if BUILDFLAG(ANDROID_JAVA_UI) | 218 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 213 void NetErrorTabHelper::DownloadPageLater() { | 219 void NetErrorTabHelper::OnDownloadPageLater() { |
| 214 // Makes sure that this is coming from an error page. | 220 // Makes sure that this is coming from an error page. |
| 215 content::NavigationEntry* entry = | 221 content::NavigationEntry* entry = |
| 216 web_contents()->GetController().GetLastCommittedEntry(); | 222 web_contents()->GetController().GetLastCommittedEntry(); |
| 217 if (!entry || entry->GetPageType() != content::PAGE_TYPE_ERROR) | 223 if (!entry || entry->GetPageType() != content::PAGE_TYPE_ERROR) |
| 218 return; | 224 return; |
| 219 | 225 |
| 220 // Only download the page for HTTP/HTTPS URLs. | 226 // Only download the page for HTTP/HTTPS URLs. |
| 221 GURL url(entry->GetVirtualURL()); | 227 GURL url(entry->GetVirtualURL()); |
| 222 if (!url.SchemeIsHTTPOrHTTPS()) | 228 if (!url.SchemeIsHTTPOrHTTPS()) |
| 223 return; | 229 return; |
| 224 | 230 |
| 225 DownloadPageLaterHelper(url); | 231 DownloadPageLaterHelper(url); |
| 226 } | 232 } |
| 233 | |
| 234 void NetErrorTabHelper::OnSetIsShowingDownloadButtonInErrorPage(bool show) { | |
|
mmenke
2017/01/09 20:35:39
"show" seems a bit short. Maybe just showing_butt
jianli
2017/01/09 23:35:07
Done.
| |
| 235 is_showing_download_button_in_error_page_ = show; | |
| 236 } | |
| 227 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 237 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 228 | 238 |
| 229 void NetErrorTabHelper::InitializePref(WebContents* contents) { | 239 void NetErrorTabHelper::InitializePref(WebContents* contents) { |
| 230 DCHECK(contents); | 240 DCHECK(contents); |
| 231 | 241 |
| 232 BrowserContext* browser_context = contents->GetBrowserContext(); | 242 BrowserContext* browser_context = contents->GetBrowserContext(); |
| 233 Profile* profile = Profile::FromBrowserContext(browser_context); | 243 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 234 resolve_errors_with_web_service_.Init( | 244 resolve_errors_with_web_service_.Init( |
| 235 prefs::kAlternateErrorPagesEnabled, | 245 prefs::kAlternateErrorPagesEnabled, |
| 236 profile->GetPrefs()); | 246 profile->GetPrefs()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 offline_pages::ClientId client_id( | 296 offline_pages::ClientId client_id( |
| 287 offline_pages::kAsyncNamespace, base::GenerateGUID()); | 297 offline_pages::kAsyncNamespace, base::GenerateGUID()); |
| 288 request_coordinator->SavePageLater( | 298 request_coordinator->SavePageLater( |
| 289 page_url, client_id, true /*user_requested*/, | 299 page_url, client_id, true /*user_requested*/, |
| 290 offline_pages::RequestCoordinator::RequestAvailability:: | 300 offline_pages::RequestCoordinator::RequestAvailability:: |
| 291 ENABLED_FOR_OFFLINER); | 301 ENABLED_FOR_OFFLINER); |
| 292 } | 302 } |
| 293 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 303 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 294 | 304 |
| 295 } // namespace chrome_browser_net | 305 } // namespace chrome_browser_net |
| OLD | NEW |