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 "chrome/browser/android/android_theme_resources.h" | 9 #include "chrome/browser/android/android_theme_resources.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
11 #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" |
12 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 13 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
13 #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" |
| 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
14 #include "components/infobars/core/infobar.h" | 17 #include "components/infobars/core/infobar.h" |
15 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
17 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
18 | 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 // Key of the UMA Previews.InfoBarAction.LoFi histogram. | 24 // Key of the UMA Previews.InfoBarAction.LoFi histogram. |
22 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; | 25 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; |
23 | 26 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 140 |
138 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 141 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
139 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_LOAD_ORIGINAL_CLICKED); | 142 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_LOAD_ORIGINAL_CLICKED); |
140 if (!on_dismiss_callback_.is_null()) | 143 if (!on_dismiss_callback_.is_null()) |
141 on_dismiss_callback_.Run(true); | 144 on_dismiss_callback_.Run(true); |
142 on_dismiss_callback_.Reset(); | 145 on_dismiss_callback_.Reset(); |
143 | 146 |
144 content::WebContents* web_contents = | 147 content::WebContents* web_contents = |
145 InfoBarService::WebContentsFromInfoBar(infobar()); | 148 InfoBarService::WebContentsFromInfoBar(infobar()); |
146 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { | 149 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { |
| 150 auto* data_reduction_proxy_settings = |
| 151 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 152 web_contents->GetBrowserContext()); |
| 153 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); |
| 154 PreviewsInfoBarTabHelper* infobar_tab_helper = |
| 155 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
| 156 if (infobar_tab_helper && |
| 157 infobar_tab_helper->committed_data_saver_navigation_id()) { |
| 158 data_reduction_proxy_settings->data_reduction_proxy_service() |
| 159 ->pingback_client() |
| 160 ->AddOptOut( |
| 161 infobar_tab_helper->committed_data_saver_navigation_id().value()); |
| 162 } |
| 163 |
147 if (infobar_type_ == LITE_PAGE) | 164 if (infobar_type_ == LITE_PAGE) |
148 web_contents->GetController().Reload( | 165 web_contents->GetController().Reload( |
149 content::ReloadType::DISABLE_LOFI_MODE, true); | 166 content::ReloadType::DISABLE_LOFI_MODE, true); |
150 else if (infobar_type_ == LOFI) | 167 else if (infobar_type_ == LOFI) |
151 web_contents->ReloadLoFiImages(); | 168 web_contents->ReloadLoFiImages(); |
152 | |
153 auto* data_reduction_proxy_settings = | |
154 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
155 web_contents->GetBrowserContext()); | |
156 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | |
157 } else if (infobar_type_ == OFFLINE) { | 169 } else if (infobar_type_ == OFFLINE) { |
158 // Prevent LoFi and lite page modes from showing after reload. | 170 // Prevent LoFi and lite page modes from showing after reload. |
159 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. | 171 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. |
160 // crbug.com/707272 | 172 // crbug.com/707272 |
161 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, | 173 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, |
162 true); | 174 true); |
163 } | 175 } |
164 | 176 |
165 return true; | 177 return true; |
166 } | 178 } |
OLD | NEW |