| 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" | |
| 9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 8 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
| 10 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/navigation_handle.h" | 10 #include "content/public/browser/navigation_handle.h" |
| 12 #include "content/public/browser/render_frame_host.h" | 11 #include "content/public/browser/render_frame_host.h" |
| 13 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 14 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 16 | 15 |
| 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 | |
| 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); | 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); |
| 22 | 17 |
| 23 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} | 18 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} |
| 24 | 19 |
| 25 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( | 20 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( |
| 26 content::WebContents* web_contents) | 21 content::WebContents* web_contents) |
| 27 : content::WebContentsObserver(web_contents), | 22 : content::WebContentsObserver(web_contents), |
| 28 displayed_preview_infobar_(false), | 23 displayed_preview_infobar_(false) { |
| 29 is_showing_offline_preview_(false) { | |
| 30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 24 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 31 } | 25 } |
| 32 | 26 |
| 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 |
| 33 void PreviewsInfoBarTabHelper::DidFinishNavigation( | 36 void PreviewsInfoBarTabHelper::DidFinishNavigation( |
| 34 content::NavigationHandle* navigation_handle) { | 37 content::NavigationHandle* navigation_handle) { |
| 35 // Only show the infobar if this is a full main frame navigation. | 38 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) |
| 36 if (!navigation_handle->IsInMainFrame() || | |
| 37 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) | |
| 38 return; | 39 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 | |
| 59 const net::HttpResponseHeaders* headers = | 40 const net::HttpResponseHeaders* headers = |
| 60 navigation_handle->GetResponseHeaders(); | 41 navigation_handle->GetResponseHeaders(); |
| 61 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { | 42 if (headers && |
| 62 PreviewsInfoBarDelegate::Create(web_contents(), | 43 data_reduction_proxy::IsLitePagePreview(*headers)) { |
| 44 PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(), |
| 63 PreviewsInfoBarDelegate::LITE_PAGE); | 45 PreviewsInfoBarDelegate::LITE_PAGE); |
| 64 } | 46 } |
| 65 } | 47 } |
| 66 | 48 |
| OLD | NEW |