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

Side by Side Diff: chrome/browser/previews/previews_infobar_tab_helper.cc

Issue 2362033002: Showing previews UI for Offline Previews (Closed)
Patch Set: megjablon comments rebase Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/previews/previews_infobar_tab_helper.h" 5 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
6 6
7 #include "chrome/browser/loader/chrome_navigation_data.h"
7 #include "chrome/browser/previews/previews_infobar_delegate.h" 8 #include "chrome/browser/previews/previews_infobar_delegate.h"
8 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
10 #include "components/offline_pages/loaded_offline_page_info.h"
9 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/navigation_handle.h" 12 #include "content/public/browser/navigation_handle.h"
11 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
13 #include "net/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
14 #include "url/gurl.h" 16 #include "url/gurl.h"
15 17
16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper);
17 19
18 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} 20 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {}
19 21
20 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( 22 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper(
21 content::WebContents* web_contents) 23 content::WebContents* web_contents)
22 : content::WebContentsObserver(web_contents), 24 : content::WebContentsObserver(web_contents),
23 displayed_preview_infobar_(false) { 25 displayed_preview_infobar_(false),
26 is_showing_offline_preview_(false) {
24 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
25 } 28 }
26 29
27 void PreviewsInfoBarTabHelper::DidStartProvisionalLoadForFrame(
28 content::RenderFrameHost* render_frame_host,
29 const GURL& validated_url,
30 bool is_error_page,
31 bool is_iframe_srcdoc) {
32 if (!render_frame_host->GetParent())
33 set_displayed_preview_infobar(false);
34 }
35
36 void PreviewsInfoBarTabHelper::DidFinishNavigation( 30 void PreviewsInfoBarTabHelper::DidFinishNavigation(
37 content::NavigationHandle* navigation_handle) { 31 content::NavigationHandle* navigation_handle) {
38 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) 32 // Do nothing if this is not a full main frame navigation.
megjablon 2016/10/07 22:48:33 Suggestion: Rather than the double negative // Onl
RyanSturm 2016/10/07 23:05:48 Done.
33 if (!navigation_handle->IsInMainFrame() ||
34 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage())
megjablon 2016/10/07 22:48:33 Does a refresh count as same page?
RyanSturm 2016/10/07 23:05:48 This checks for fragment navigations (i.e. links t
megjablon 2016/10/10 22:25:13 Ok cool.
39 return; 35 return;
36 is_showing_offline_preview_ = false;
37 displayed_preview_infobar_ = false;
38
39 ChromeNavigationData* chrome_navigation_data =
40 ChromeNavigationData::GetForNavigationHandle(navigation_handle);
41 if (chrome_navigation_data) {
42 offline_pages::LoadedOfflinePageInfo* info =
43 chrome_navigation_data->GetLoadedOfflinePageInfo();
44 if (info && info->is_offline_preview()) {
45 if (navigation_handle->IsErrorPage()) {
46 // TODO(ryansturm): Add UMA for errors.
47 return;
48 }
49 is_showing_offline_preview_ = true;
50 PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(),
51 PreviewsInfoBarDelegate::OFFLINE);
52 // Don't try to show other infobars if this is an offline preview.
53 return;
54 }
55 }
56
40 const net::HttpResponseHeaders* headers = 57 const net::HttpResponseHeaders* headers =
41 navigation_handle->GetResponseHeaders(); 58 navigation_handle->GetResponseHeaders();
42 if (headers && 59 if (headers &&
43 headers->HasHeaderValue( 60 headers->HasHeaderValue(
44 data_reduction_proxy::chrome_proxy_header(), 61 data_reduction_proxy::chrome_proxy_header(),
45 data_reduction_proxy::chrome_proxy_lo_fi_preview_directive())) { 62 data_reduction_proxy::chrome_proxy_lo_fi_preview_directive())) {
46 PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(), 63 PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(),
47 PreviewsInfoBarDelegate::LITE_PAGE); 64 PreviewsInfoBarDelegate::LITE_PAGE);
48 } 65 }
49 } 66 }
50 67
OLDNEW
« no previous file with comments | « chrome/browser/previews/previews_infobar_tab_helper.h ('k') | chrome/browser/previews/previews_infobar_tab_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698