Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/net/net_error_tab_helper.cc

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

Powered by Google App Engine
This is Rietveld 408576698