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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // the link doctor loads a blank intermediate page or the tab switches | 123 // the link doctor loads a blank intermediate page or the tab switches |
124 // renderer processes. | 124 // renderer processes. |
125 if (navigation_handle->IsErrorPage() && dns_error_active_) { | 125 if (navigation_handle->IsErrorPage() && dns_error_active_) { |
126 dns_error_page_committed_ = true; | 126 dns_error_page_committed_ = true; |
127 DVLOG(1) << "Committed error page; resending status."; | 127 DVLOG(1) << "Committed error page; resending status."; |
128 SendInfo(); | 128 SendInfo(); |
129 } else if (navigation_handle->HasCommitted() && | 129 } else if (navigation_handle->HasCommitted() && |
130 !navigation_handle->IsErrorPage()) { | 130 !navigation_handle->IsErrorPage()) { |
131 dns_error_active_ = false; | 131 dns_error_active_ = false; |
132 dns_error_page_committed_ = false; | 132 dns_error_page_committed_ = false; |
| 133 #if defined(OS_ANDROID) |
| 134 is_showing_download_button_in_error_page_ = false; |
| 135 #endif // defined(OS_ANDROID) |
133 } | 136 } |
134 } | 137 } |
135 | 138 |
136 bool NetErrorTabHelper::OnMessageReceived( | 139 bool NetErrorTabHelper::OnMessageReceived( |
137 const IPC::Message& message, | 140 const IPC::Message& message, |
138 content::RenderFrameHost* render_frame_host) { | 141 content::RenderFrameHost* render_frame_host) { |
139 if (render_frame_host != web_contents()->GetMainFrame()) | 142 if (render_frame_host != web_contents()->GetMainFrame()) |
140 return false; | 143 return false; |
141 #if defined(OS_ANDROID) | 144 #if defined(OS_ANDROID) |
142 bool handled = true; | 145 bool handled = true; |
143 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 146 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
144 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DownloadPageLater, DownloadPageLater) | 147 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DownloadPageLater, |
| 148 OnDownloadPageLater) |
| 149 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetIsShowingDownloadButtonInErrorPage, |
| 150 OnSetIsShowingDownloadButtonInErrorPage) |
145 IPC_MESSAGE_UNHANDLED(handled = false) | 151 IPC_MESSAGE_UNHANDLED(handled = false) |
146 IPC_END_MESSAGE_MAP() | 152 IPC_END_MESSAGE_MAP() |
147 | 153 |
148 return handled; | 154 return handled; |
149 #else | 155 #else |
150 return false; | 156 return false; |
151 #endif // defined(OS_ANDROID) | 157 #endif // defined(OS_ANDROID) |
152 } | 158 } |
153 | 159 |
154 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 160 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
155 : WebContentsObserver(contents), | 161 : WebContentsObserver(contents), |
156 network_diagnostics_bindings_(contents, this), | 162 network_diagnostics_bindings_(contents, this), |
157 is_error_page_(false), | 163 is_error_page_(false), |
158 dns_error_active_(false), | 164 dns_error_active_(false), |
159 dns_error_page_committed_(false), | 165 dns_error_page_committed_(false), |
| 166 #if defined(OS_ANDROID) |
| 167 is_showing_download_button_in_error_page_(false), |
| 168 #endif // defined(OS_ANDROID) |
160 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), | 169 dns_probe_status_(error_page::DNS_PROBE_POSSIBLE), |
161 weak_factory_(this) { | 170 weak_factory_(this) { |
162 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 171 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
163 | 172 |
164 // If this helper is under test, it won't have a WebContents. | 173 // If this helper is under test, it won't have a WebContents. |
165 if (contents) | 174 if (contents) |
166 InitializePref(contents); | 175 InitializePref(contents); |
167 } | 176 } |
168 | 177 |
169 void NetErrorTabHelper::OnMainFrameDnsError() { | 178 void NetErrorTabHelper::OnMainFrameDnsError() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 DVLOG(1) << "Finished DNS probe with result " | 211 DVLOG(1) << "Finished DNS probe with result " |
203 << DnsProbeStatusToString(result) << "."; | 212 << DnsProbeStatusToString(result) << "."; |
204 | 213 |
205 dns_probe_status_ = result; | 214 dns_probe_status_ = result; |
206 | 215 |
207 if (dns_error_page_committed_) | 216 if (dns_error_page_committed_) |
208 SendInfo(); | 217 SendInfo(); |
209 } | 218 } |
210 | 219 |
211 #if defined(OS_ANDROID) | 220 #if defined(OS_ANDROID) |
212 void NetErrorTabHelper::DownloadPageLater() { | 221 void NetErrorTabHelper::OnDownloadPageLater() { |
213 // Makes sure that this is coming from an error page. | 222 // Makes sure that this is coming from an error page. |
214 content::NavigationEntry* entry = | 223 content::NavigationEntry* entry = |
215 web_contents()->GetController().GetLastCommittedEntry(); | 224 web_contents()->GetController().GetLastCommittedEntry(); |
216 if (!entry || entry->GetPageType() != content::PAGE_TYPE_ERROR) | 225 if (!entry || entry->GetPageType() != content::PAGE_TYPE_ERROR) |
217 return; | 226 return; |
218 | 227 |
219 // Only download the page for HTTP/HTTPS URLs. | 228 // Only download the page for HTTP/HTTPS URLs. |
220 GURL url(entry->GetVirtualURL()); | 229 GURL url(entry->GetVirtualURL()); |
221 if (!url.SchemeIsHTTPOrHTTPS()) | 230 if (!url.SchemeIsHTTPOrHTTPS()) |
222 return; | 231 return; |
223 | 232 |
224 DownloadPageLaterHelper(url); | 233 DownloadPageLaterHelper(url); |
225 } | 234 } |
| 235 |
| 236 void NetErrorTabHelper::OnSetIsShowingDownloadButtonInErrorPage( |
| 237 bool is_showing_download_button) { |
| 238 is_showing_download_button_in_error_page_ = is_showing_download_button; |
| 239 } |
226 #endif // defined(OS_ANDROID) | 240 #endif // defined(OS_ANDROID) |
227 | 241 |
228 void NetErrorTabHelper::InitializePref(WebContents* contents) { | 242 void NetErrorTabHelper::InitializePref(WebContents* contents) { |
229 DCHECK(contents); | 243 DCHECK(contents); |
230 | 244 |
231 BrowserContext* browser_context = contents->GetBrowserContext(); | 245 BrowserContext* browser_context = contents->GetBrowserContext(); |
232 Profile* profile = Profile::FromBrowserContext(browser_context); | 246 Profile* profile = Profile::FromBrowserContext(browser_context); |
233 resolve_errors_with_web_service_.Init( | 247 resolve_errors_with_web_service_.Init( |
234 prefs::kAlternateErrorPagesEnabled, | 248 prefs::kAlternateErrorPagesEnabled, |
235 profile->GetPrefs()); | 249 profile->GetPrefs()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 offline_pages::ClientId client_id( | 299 offline_pages::ClientId client_id( |
286 offline_pages::kAsyncNamespace, base::GenerateGUID()); | 300 offline_pages::kAsyncNamespace, base::GenerateGUID()); |
287 request_coordinator->SavePageLater( | 301 request_coordinator->SavePageLater( |
288 page_url, client_id, true /*user_requested*/, | 302 page_url, client_id, true /*user_requested*/, |
289 offline_pages::RequestCoordinator::RequestAvailability:: | 303 offline_pages::RequestCoordinator::RequestAvailability:: |
290 ENABLED_FOR_OFFLINER); | 304 ENABLED_FOR_OFFLINER); |
291 } | 305 } |
292 #endif // defined(OS_ANDROID) | 306 #endif // defined(OS_ANDROID) |
293 | 307 |
294 } // namespace chrome_browser_net | 308 } // namespace chrome_browser_net |
OLD | NEW |