| 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/feature_engagement_tracker/feature_engagement_tracker_f
actory.h" |
| 9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 11 #include "chrome/browser/previews/previews_infobar_delegate.h" | 12 #include "chrome/browser/previews/previews_infobar_delegate.h" |
| 12 #include "chrome/browser/previews/previews_service.h" | 13 #include "chrome/browser/previews/previews_service.h" |
| 13 #include "chrome/browser/previews/previews_service_factory.h" | 14 #include "chrome/browser/previews/previews_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" | 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
| 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
| 18 #include "components/feature_engagement_tracker/public/feature_engagement_tracke
r.h" |
| 17 #include "components/previews/core/previews_experiments.h" | 19 #include "components/previews/core/previews_experiments.h" |
| 18 #include "components/previews/core/previews_ui_service.h" | 20 #include "components/previews/core/previews_ui_service.h" |
| 19 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 24 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 25 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 26 | 28 |
| 27 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
| 28 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" | 30 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 34 const char kIPHDataSaverPreviewEvent[] = "Event_DataSaverPreview"; |
| 35 |
| 32 // Adds the preview navigation to the black list. This method is only used on | 36 // Adds the preview navigation to the black list. This method is only used on |
| 33 // android currently. | 37 // android currently. |
| 34 void AddPreviewNavigationCallback(content::BrowserContext* browser_context, | 38 void AddPreviewNavigationCallback(content::BrowserContext* browser_context, |
| 35 const GURL& url, | 39 const GURL& url, |
| 36 previews::PreviewsType type, | 40 previews::PreviewsType type, |
| 37 bool opt_out) { | 41 bool opt_out) { |
| 38 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( | 42 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 39 Profile::FromBrowserContext(browser_context)); | 43 Profile::FromBrowserContext(browser_context)); |
| 40 if (previews_service && previews_service->previews_ui_service()) { | 44 if (previews_service && previews_service->previews_ui_service()) { |
| 41 previews_service->previews_ui_service()->AddPreviewNavigation(url, type, | 45 previews_service->previews_ui_service()->AddPreviewNavigation(url, type, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 68 | 72 |
| 69 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID) |
| 70 offline_pages::OfflinePageTabHelper* tab_helper = | 74 offline_pages::OfflinePageTabHelper* tab_helper = |
| 71 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); | 75 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); |
| 72 | 76 |
| 73 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { | 77 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { |
| 74 if (navigation_handle->IsErrorPage()) { | 78 if (navigation_handle->IsErrorPage()) { |
| 75 // TODO(ryansturm): Add UMA for errors. | 79 // TODO(ryansturm): Add UMA for errors. |
| 76 return; | 80 return; |
| 77 } | 81 } |
| 82 |
| 83 feature_engagement_tracker::FeatureEngagementTracker* tracker = |
| 84 FeatureEngagementTrackerFactory::GetInstance()->GetForBrowserContext( |
| 85 web_contents()->GetBrowserContext()); |
| 86 tracker->NotifyEvent(kIPHDataSaverPreviewEvent); |
| 87 |
| 78 data_reduction_proxy::DataReductionProxySettings* | 88 data_reduction_proxy::DataReductionProxySettings* |
| 79 data_reduction_proxy_settings = | 89 data_reduction_proxy_settings = |
| 80 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 90 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 81 web_contents()->GetBrowserContext()); | 91 web_contents()->GetBrowserContext()); |
| 82 PreviewsInfoBarDelegate::Create( | 92 PreviewsInfoBarDelegate::Create( |
| 83 web_contents(), PreviewsInfoBarDelegate::OFFLINE, | 93 web_contents(), PreviewsInfoBarDelegate::OFFLINE, |
| 84 data_reduction_proxy_settings && | 94 data_reduction_proxy_settings && |
| 85 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), | 95 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
| 86 base::Bind( | 96 base::Bind( |
| 87 &AddPreviewNavigationCallback, web_contents()->GetBrowserContext(), | 97 &AddPreviewNavigationCallback, web_contents()->GetBrowserContext(), |
| 88 navigation_handle->GetURL(), previews::PreviewsType::OFFLINE)); | 98 navigation_handle->GetURL(), previews::PreviewsType::OFFLINE)); |
| 89 // Don't try to show other infobars if this is an offline preview. | 99 // Don't try to show other infobars if this is an offline preview. |
| 90 return; | 100 return; |
| 91 } | 101 } |
| 92 #endif // defined(OS_ANDROID) | 102 #endif // defined(OS_ANDROID) |
| 93 | 103 |
| 94 const net::HttpResponseHeaders* headers = | 104 const net::HttpResponseHeaders* headers = |
| 95 navigation_handle->GetResponseHeaders(); | 105 navigation_handle->GetResponseHeaders(); |
| 96 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { | 106 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { |
| 97 PreviewsInfoBarDelegate::Create( | 107 PreviewsInfoBarDelegate::Create( |
| 98 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE, | 108 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE, |
| 99 true /* is_data_saver_user */, | 109 true /* is_data_saver_user */, |
| 100 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 110 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
| 101 } | 111 } |
| 102 } | 112 } |
| 103 | 113 |
| OLD | NEW |