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_delegate.h" | 5 #include "chrome/browser/previews/previews_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/optional.h" | 8 #include "base/optional.h" |
| 9 #include "chrome/browser/android/android_theme_resources.h" | 9 #include "chrome/browser/android/android_theme_resources.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | 12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" |
| 13 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 13 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" | 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" |
| 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" | 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" |
| 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | |
| 17 #include "components/infobars/core/infobar.h" | 18 #include "components/infobars/core/infobar.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Key of the UMA Previews.InfoBarAction.LoFi histogram. | 25 // Key of the UMA Previews.InfoBarAction.LoFi histogram. |
| 25 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; | 26 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; |
| 26 | 27 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 int PreviewsInfoBarDelegate::GetButtons() const { | 137 int PreviewsInfoBarDelegate::GetButtons() const { |
| 137 return BUTTON_NONE; | 138 return BUTTON_NONE; |
| 138 } | 139 } |
| 139 | 140 |
| 140 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { | 141 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { |
| 141 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); | 142 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 145 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 145 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED; | 146 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED; |
| 146 if (!on_dismiss_callback_.is_null()) | 147 if (!on_dismiss_callback_.is_null()) |
|
megjablon
2017/05/09 19:58:33
Do Lo-Fi and Lite pages already have on_dismiss_ca
RyanSturm
2017/05/09 22:35:18
Yes. That landed yesterday.
| |
| 147 on_dismiss_callback_.Run(true); | 148 on_dismiss_callback_.Run(true); |
| 148 on_dismiss_callback_.Reset(); | 149 on_dismiss_callback_.Reset(); |
| 149 | 150 |
| 150 content::WebContents* web_contents = | 151 content::WebContents* web_contents = |
| 151 InfoBarService::WebContentsFromInfoBar(infobar()); | 152 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 152 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { | 153 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { |
| 153 auto* data_reduction_proxy_settings = | 154 auto* data_reduction_proxy_settings = |
| 154 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 155 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 155 web_contents->GetBrowserContext()); | 156 web_contents->GetBrowserContext()); |
| 156 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | 157 if (!data_reduction_proxy::params::IsBlackListEnabledForServerPreviews()) |
| 158 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | |
| 157 PreviewsInfoBarTabHelper* infobar_tab_helper = | 159 PreviewsInfoBarTabHelper* infobar_tab_helper = |
| 158 PreviewsInfoBarTabHelper::FromWebContents(web_contents); | 160 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
| 159 if (infobar_tab_helper && | 161 if (infobar_tab_helper && |
| 160 infobar_tab_helper->committed_data_saver_navigation_id()) { | 162 infobar_tab_helper->committed_data_saver_navigation_id()) { |
| 161 data_reduction_proxy_settings->data_reduction_proxy_service() | 163 data_reduction_proxy_settings->data_reduction_proxy_service() |
| 162 ->pingback_client() | 164 ->pingback_client() |
| 163 ->AddOptOut( | 165 ->AddOptOut( |
| 164 infobar_tab_helper->committed_data_saver_navigation_id().value()); | 166 infobar_tab_helper->committed_data_saver_navigation_id().value()); |
| 165 } | 167 } |
| 166 | 168 |
| 167 if (infobar_type_ == LITE_PAGE) | 169 if (infobar_type_ == LITE_PAGE) |
| 168 web_contents->GetController().Reload( | 170 web_contents->GetController().Reload( |
| 169 content::ReloadType::DISABLE_LOFI_MODE, true); | 171 content::ReloadType::DISABLE_LOFI_MODE, true); |
| 170 else if (infobar_type_ == LOFI) | 172 else if (infobar_type_ == LOFI) |
| 171 web_contents->ReloadLoFiImages(); | 173 web_contents->ReloadLoFiImages(); |
| 172 } else if (infobar_type_ == OFFLINE) { | 174 } else if (infobar_type_ == OFFLINE) { |
| 173 // Prevent LoFi and lite page modes from showing after reload. | 175 // Prevent LoFi and lite page modes from showing after reload. |
| 174 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. | 176 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. |
| 175 // crbug.com/707272 | 177 // crbug.com/707272 |
| 176 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, | 178 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, |
| 177 true); | 179 true); |
| 178 } | 180 } |
| 179 | 181 |
| 180 return true; | 182 return true; |
| 181 } | 183 } |
| OLD | NEW |