Chromium Code Reviews| 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/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | |
| 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | |
| 9 #include "chrome/browser/previews/previews_infobar_delegate.h" | 11 #include "chrome/browser/previews/previews_infobar_delegate.h" |
| 10 #include "chrome/browser/previews/previews_service.h" | 12 #include "chrome/browser/previews/previews_service.h" |
| 11 #include "chrome/browser/previews/previews_service_factory.h" | 13 #include "chrome/browser/previews/previews_service_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/features.h" | 15 #include "chrome/common/features.h" |
| 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" | |
| 14 #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" |
| 15 #include "components/previews/core/previews_experiments.h" | 18 #include "components/previews/core/previews_experiments.h" |
| 16 #include "components/previews/core/previews_ui_service.h" | 19 #include "components/previews/core/previews_ui_service.h" |
| 17 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
| 20 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 22 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 23 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 | 71 |
| 69 #if BUILDFLAG(ANDROID_JAVA_UI) | 72 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 70 offline_pages::OfflinePageTabHelper* tab_helper = | 73 offline_pages::OfflinePageTabHelper* tab_helper = |
| 71 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); | 74 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); |
| 72 | 75 |
| 73 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { | 76 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { |
| 74 if (navigation_handle->IsErrorPage()) { | 77 if (navigation_handle->IsErrorPage()) { |
| 75 // TODO(ryansturm): Add UMA for errors. | 78 // TODO(ryansturm): Add UMA for errors. |
| 76 return; | 79 return; |
| 77 } | 80 } |
| 81 data_reduction_proxy::DataReductionProxySettings* | |
| 82 data_reduction_proxy_settings = | |
| 83 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
| 84 web_contents()->GetBrowserContext()); | |
| 85 bool is_data_saver_user = false; | |
| 86 if (data_reduction_proxy_settings) { | |
| 87 is_data_saver_user = | |
| 88 data_reduction_proxy_settings->IsDataReductionProxyEnabled(); | |
| 89 } | |
| 78 is_showing_offline_preview_ = true; | 90 is_showing_offline_preview_ = true; |
| 79 PreviewsInfoBarDelegate::Create( | 91 PreviewsInfoBarDelegate::Create( |
| 80 web_contents(), PreviewsInfoBarDelegate::OFFLINE, | 92 web_contents(), PreviewsInfoBarDelegate::OFFLINE, |
| 93 is_data_saver_user /* is_data_saver_user*/, | |
|
bengr
2016/12/16 16:45:30
Why not just replace this with drp_settings && drp
RyanSturm
2016/12/16 19:02:10
Done.
| |
| 81 base::Bind( | 94 base::Bind( |
| 82 &AddPreviewNavigationCallback, web_contents()->GetBrowserContext(), | 95 &AddPreviewNavigationCallback, web_contents()->GetBrowserContext(), |
| 83 navigation_handle->GetURL(), previews::PreviewsType::OFFLINE)); | 96 navigation_handle->GetURL(), previews::PreviewsType::OFFLINE)); |
| 84 // Don't try to show other infobars if this is an offline preview. | 97 // Don't try to show other infobars if this is an offline preview. |
| 85 return; | 98 return; |
| 86 } | 99 } |
| 87 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 100 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 88 | 101 |
| 89 const net::HttpResponseHeaders* headers = | 102 const net::HttpResponseHeaders* headers = |
| 90 navigation_handle->GetResponseHeaders(); | 103 navigation_handle->GetResponseHeaders(); |
| 91 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { | 104 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { |
| 92 PreviewsInfoBarDelegate::Create( | 105 PreviewsInfoBarDelegate::Create( |
| 93 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE, | 106 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE, |
| 107 true /* is_data_saver_user*/, | |
| 94 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 108 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
| 95 } | 109 } |
| 96 } | 110 } |
| 97 | 111 |
| OLD | NEW |