| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "chrome/browser/loader/chrome_navigation_data.h" | 9 #include "chrome/browser/loader/chrome_navigation_data.h" |
| 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/navigation_handle.h" | 24 #include "content/public/browser/navigation_handle.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 | 29 |
| 30 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
| 31 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" | 31 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| 32 #endif // defined(OS_ANDROID) |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // Adds the preview navigation to the black list. This method is only used on | 36 // Adds the preview navigation to the black list. |
| 36 // android currently. | |
| 37 void AddPreviewNavigationCallback(content::BrowserContext* browser_context, | 37 void AddPreviewNavigationCallback(content::BrowserContext* browser_context, |
| 38 const GURL& url, | 38 const GURL& url, |
| 39 previews::PreviewsType type, | 39 previews::PreviewsType type, |
| 40 bool opt_out) { | 40 bool opt_out) { |
| 41 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( | 41 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 42 Profile::FromBrowserContext(browser_context)); | 42 Profile::FromBrowserContext(browser_context)); |
| 43 if (previews_service && previews_service->previews_ui_service()) { | 43 if (previews_service && previews_service->previews_ui_service()) { |
| 44 previews_service->previews_ui_service()->AddPreviewNavigation(url, type, | 44 previews_service->previews_ui_service()->AddPreviewNavigation(url, type, |
| 45 opt_out); | 45 opt_out); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 #endif // defined(OS_ANDROID) | |
| 52 | |
| 53 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); | 51 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); |
| 54 | 52 |
| 55 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() { | 53 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() { |
| 56 ClearLastNavigationAsync(); | 54 ClearLastNavigationAsync(); |
| 57 } | 55 } |
| 58 | 56 |
| 59 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( | 57 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( |
| 60 content::WebContents* web_contents) | 58 content::WebContents* web_contents) |
| 61 : content::WebContentsObserver(web_contents), | 59 : content::WebContentsObserver(web_contents), |
| 62 browser_context_(web_contents->GetBrowserContext()), | 60 browser_context_(web_contents->GetBrowserContext()), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 101 } |
| 104 data_reduction_proxy::DataReductionProxySettings* | 102 data_reduction_proxy::DataReductionProxySettings* |
| 105 data_reduction_proxy_settings = | 103 data_reduction_proxy_settings = |
| 106 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 104 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 107 web_contents()->GetBrowserContext()); | 105 web_contents()->GetBrowserContext()); |
| 108 PreviewsInfoBarDelegate::Create( | 106 PreviewsInfoBarDelegate::Create( |
| 109 web_contents(), PreviewsInfoBarDelegate::OFFLINE, | 107 web_contents(), PreviewsInfoBarDelegate::OFFLINE, |
| 110 data_reduction_proxy_settings && | 108 data_reduction_proxy_settings && |
| 111 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), | 109 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
| 112 base::Bind(&AddPreviewNavigationCallback, browser_context_, | 110 base::Bind(&AddPreviewNavigationCallback, browser_context_, |
| 113 navigation_handle->GetURL(), | 111 navigation_handle->GetRedirectChain()[0], |
| 114 previews::PreviewsType::OFFLINE)); | 112 previews::PreviewsType::OFFLINE)); |
| 115 // Don't try to show other infobars if this is an offline preview. | 113 // Don't try to show other infobars if this is an offline preview. |
| 116 return; | 114 return; |
| 117 } | 115 } |
| 118 #endif // defined(OS_ANDROID) | 116 #endif // defined(OS_ANDROID) |
| 119 | 117 |
| 120 const net::HttpResponseHeaders* headers = | 118 const net::HttpResponseHeaders* headers = |
| 121 navigation_handle->GetResponseHeaders(); | 119 navigation_handle->GetResponseHeaders(); |
| 122 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { | 120 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { |
| 123 PreviewsInfoBarDelegate::Create( | 121 PreviewsInfoBarDelegate::Create( |
| 124 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE, | 122 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE, |
| 125 true /* is_data_saver_user */, | 123 true /* is_data_saver_user */, |
| 126 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 124 base::Bind(&AddPreviewNavigationCallback, browser_context_, |
| 125 navigation_handle->GetRedirectChain()[0], |
| 126 previews::PreviewsType::LITE_PAGE)); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void PreviewsInfoBarTabHelper::ClearLastNavigationAsync() const { | 130 void PreviewsInfoBarTabHelper::ClearLastNavigationAsync() const { |
| 131 if (!committed_data_saver_navigation_id_) | 131 if (!committed_data_saver_navigation_id_) |
| 132 return; | 132 return; |
| 133 auto* data_reduction_proxy_settings = | 133 auto* data_reduction_proxy_settings = |
| 134 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 134 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 135 browser_context_); | 135 browser_context_); |
| 136 if (!data_reduction_proxy_settings || | 136 if (!data_reduction_proxy_settings || |
| 137 !data_reduction_proxy_settings->data_reduction_proxy_service()) { | 137 !data_reduction_proxy_settings->data_reduction_proxy_service()) { |
| 138 return; | 138 return; |
| 139 } | 139 } |
| 140 data_reduction_proxy_settings->data_reduction_proxy_service() | 140 data_reduction_proxy_settings->data_reduction_proxy_service() |
| 141 ->pingback_client() | 141 ->pingback_client() |
| 142 ->ClearNavigationKeyAsync(committed_data_saver_navigation_id_.value()); | 142 ->ClearNavigationKeyAsync(committed_data_saver_navigation_id_.value()); |
| 143 } | 143 } |
| OLD | NEW |