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

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

Issue 1750113002: Remove "Show saved copy" button from error page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 9 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
« no previous file with comments | « chrome/browser/net/net_error_tab_helper.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 21 matching lines...) Expand all
32 #include "components/offline_pages/offline_page_item.h" 32 #include "components/offline_pages/offline_page_item.h"
33 #include "components/offline_pages/offline_page_model.h" 33 #include "components/offline_pages/offline_page_model.h"
34 #endif // BUILDFLAG(ANDROID_JAVA_UI) 34 #endif // BUILDFLAG(ANDROID_JAVA_UI)
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 error_page::OfflinePageStatus;
43 using ui::PageTransition; 42 using ui::PageTransition;
44 43
45 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); 44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper);
46 45
47 namespace chrome_browser_net { 46 namespace chrome_browser_net {
48 47
49 namespace { 48 namespace {
50 49
51 static NetErrorTabHelper::TestingState testing_state_ = 50 static NetErrorTabHelper::TestingState testing_state_ =
52 NetErrorTabHelper::TESTING_DEFAULT; 51 NetErrorTabHelper::TESTING_DEFAULT;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 bool is_error_page, 124 bool is_error_page,
126 bool is_iframe_srcdoc) { 125 bool is_iframe_srcdoc) {
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); 126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
128 127
129 if (render_frame_host->GetParent()) 128 if (render_frame_host->GetParent())
130 return; 129 return;
131 130
132 is_error_page_ = is_error_page; 131 is_error_page_ = is_error_page;
133 132
134 #if BUILDFLAG(ANDROID_JAVA_UI) 133 #if BUILDFLAG(ANDROID_JAVA_UI)
135 SetOfflinePageInfo(render_frame_host, validated_url); 134 SetHasOfflinePages(render_frame_host);
136 #endif // BUILDFLAG(ANDROID_JAVA_UI) 135 #endif // BUILDFLAG(ANDROID_JAVA_UI)
137 } 136 }
138 137
139 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( 138 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame(
140 content::RenderFrameHost* render_frame_host, 139 content::RenderFrameHost* render_frame_host,
141 const GURL& url, 140 const GURL& url,
142 PageTransition transition_type) { 141 PageTransition transition_type) {
143 DCHECK_CURRENTLY_ON(BrowserThread::UI); 142 DCHECK_CURRENTLY_ON(BrowserThread::UI);
144 143
145 if (render_frame_host->GetParent()) 144 if (render_frame_host->GetParent())
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 const IPC::Message& message, 179 const IPC::Message& message,
181 content::RenderFrameHost* render_frame_host) { 180 content::RenderFrameHost* render_frame_host) {
182 if (render_frame_host != web_contents()->GetMainFrame()) 181 if (render_frame_host != web_contents()->GetMainFrame())
183 return false; 182 return false;
184 bool handled = true; 183 bool handled = true;
185 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) 184 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message)
186 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, 185 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics,
187 RunNetworkDiagnostics) 186 RunNetworkDiagnostics)
188 #if BUILDFLAG(ANDROID_JAVA_UI) 187 #if BUILDFLAG(ANDROID_JAVA_UI)
189 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) 188 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages)
190 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LoadOfflineCopy, LoadOfflineCopy)
191 #endif // BUILDFLAG(ANDROID_JAVA_UI) 189 #endif // BUILDFLAG(ANDROID_JAVA_UI)
192 IPC_MESSAGE_UNHANDLED(handled = false) 190 IPC_MESSAGE_UNHANDLED(handled = false)
193 IPC_END_MESSAGE_MAP() 191 IPC_END_MESSAGE_MAP()
194 192
195 return handled; 193 return handled;
196 } 194 }
197 195
198 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) 196 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents)
199 : WebContentsObserver(contents), 197 : WebContentsObserver(contents),
200 is_error_page_(false), 198 is_error_page_(false),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Sanitize URL prior to running diagnostics on it. 288 // Sanitize URL prior to running diagnostics on it.
291 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); 289 RunNetworkDiagnosticsHelper(url.GetOrigin().spec());
292 } 290 }
293 291
294 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( 292 void NetErrorTabHelper::RunNetworkDiagnosticsHelper(
295 const std::string& sanitized_url) { 293 const std::string& sanitized_url) {
296 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); 294 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url);
297 } 295 }
298 296
299 #if BUILDFLAG(ANDROID_JAVA_UI) 297 #if BUILDFLAG(ANDROID_JAVA_UI)
300 void NetErrorTabHelper::SetOfflinePageInfo( 298 void NetErrorTabHelper::SetHasOfflinePages(
301 content::RenderFrameHost* render_frame_host, 299 content::RenderFrameHost* render_frame_host) {
302 const GURL& url) {
303 // Bails out if offline pages not supported. 300 // Bails out if offline pages not supported.
304 if (!offline_pages::IsOfflinePagesEnabled()) 301 if (!offline_pages::IsOfflinePagesEnabled())
305 return; 302 return;
306 303
307 offline_pages::OfflinePageModel* offline_page_model = 304 offline_pages::OfflinePageModel* offline_page_model =
308 offline_pages::OfflinePageModelFactory::GetForBrowserContext( 305 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
309 web_contents()->GetBrowserContext()); 306 web_contents()->GetBrowserContext());
310 if (!offline_page_model) 307 if (!offline_page_model)
311 return; 308 return;
312 309
313 OfflinePageStatus status = OfflinePageStatus::NONE; 310 render_frame_host->Send(new ChromeViewMsg_SetHasOfflinePages(
314 if (offline_page_model->HasOfflinePages()) { 311 render_frame_host->GetRoutingID(),
315 status = offline_page_model->GetPageByOnlineURL(url) 312 offline_page_model->HasOfflinePages()));
316 ? OfflinePageStatus::HAS_OFFLINE_PAGE
317 : OfflinePageStatus::HAS_OTHER_OFFLINE_PAGES;
318 }
319 render_frame_host->Send(new ChromeViewMsg_SetOfflinePageInfo(
320 render_frame_host->GetRoutingID(), status));
321 } 313 }
322 314
323 void NetErrorTabHelper::ShowOfflinePages() { 315 void NetErrorTabHelper::ShowOfflinePages() {
324 // Makes sure that this is coming from an error page. 316 // Makes sure that this is coming from an error page.
325 if (!IsFromErrorPage()) 317 if (!IsFromErrorPage())
326 return; 318 return;
327 319
328 DCHECK(web_contents()); 320 DCHECK(web_contents());
329 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); 321 TabAndroid* tab = TabAndroid::FromWebContents(web_contents());
330 if (tab) 322 if (tab)
331 tab->ShowOfflinePages(); 323 tab->ShowOfflinePages();
332 } 324 }
333 325
334 void NetErrorTabHelper::LoadOfflineCopy(const GURL& url) {
335 // Makes sure that this is coming from an error page.
336 if (!IsFromErrorPage())
337 return;
338
339 GURL validated_url(url);
340 if (!validated_url.is_valid())
341 return;
342
343 if (validated_url != web_contents()->GetLastCommittedURL())
344 return;
345
346 TabAndroid* tab = TabAndroid::FromWebContents(web_contents());
347 if (tab)
348 tab->LoadOfflineCopy(url);
349 }
350
351 bool NetErrorTabHelper::IsFromErrorPage() const { 326 bool NetErrorTabHelper::IsFromErrorPage() const {
352 content::NavigationEntry* entry = 327 content::NavigationEntry* entry =
353 web_contents()->GetController().GetLastCommittedEntry(); 328 web_contents()->GetController().GetLastCommittedEntry();
354 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR); 329 return entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR);
355 } 330 }
356 331
357 #endif // BUILDFLAG(ANDROID_JAVA_UI) 332 #endif // BUILDFLAG(ANDROID_JAVA_UI)
358 333
359 } // namespace chrome_browser_net 334 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/net_error_tab_helper.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698