| OLD | NEW |
| 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/previews/previews_infobar_delegate.h" | 7 #include "chrome/browser/previews/previews_infobar_delegate.h" |
| 8 #include "chrome/common/features.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" |
| 9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/navigation_handle.h" | 11 #include "content/public/browser/navigation_handle.h" |
| 11 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 17 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 18 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| 19 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 20 |
| 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); | 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); |
| 17 | 22 |
| 18 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} | 23 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} |
| 19 | 24 |
| 20 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( | 25 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( |
| 21 content::WebContents* web_contents) | 26 content::WebContents* web_contents) |
| 22 : content::WebContentsObserver(web_contents), | 27 : content::WebContentsObserver(web_contents), |
| 23 displayed_preview_infobar_(false) { | 28 displayed_preview_infobar_(false), |
| 29 is_showing_offline_preview_(false) { |
| 24 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 25 } | 31 } |
| 26 | 32 |
| 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( | 33 void PreviewsInfoBarTabHelper::DidFinishNavigation( |
| 37 content::NavigationHandle* navigation_handle) { | 34 content::NavigationHandle* navigation_handle) { |
| 38 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) | 35 // Only show the infobar if this is a full main frame navigation. |
| 36 if (!navigation_handle->IsInMainFrame() || |
| 37 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) |
| 39 return; | 38 return; |
| 39 is_showing_offline_preview_ = false; |
| 40 displayed_preview_infobar_ = false; |
| 41 |
| 42 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 43 offline_pages::OfflinePageTabHelper* tab_helper = |
| 44 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); |
| 45 |
| 46 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { |
| 47 if (navigation_handle->IsErrorPage()) { |
| 48 // TODO(ryansturm): Add UMA for errors. |
| 49 return; |
| 50 } |
| 51 is_showing_offline_preview_ = true; |
| 52 PreviewsInfoBarDelegate::Create(web_contents(), |
| 53 PreviewsInfoBarDelegate::OFFLINE); |
| 54 // Don't try to show other infobars if this is an offline preview. |
| 55 return; |
| 56 } |
| 57 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 58 |
| 40 const net::HttpResponseHeaders* headers = | 59 const net::HttpResponseHeaders* headers = |
| 41 navigation_handle->GetResponseHeaders(); | 60 navigation_handle->GetResponseHeaders(); |
| 42 if (headers && | 61 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { |
| 43 data_reduction_proxy::IsLitePagePreview(*headers)) { | 62 PreviewsInfoBarDelegate::Create(web_contents(), |
| 44 PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(), | |
| 45 PreviewsInfoBarDelegate::LITE_PAGE); | 63 PreviewsInfoBarDelegate::LITE_PAGE); |
| 46 } | 64 } |
| 47 } | 65 } |
| 48 | 66 |
| OLD | NEW |