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/infobars/core/infobar.h" | 17 #include "components/infobars/core/infobar.h" |
18 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 | 21 |
22 #if defined(OS_ANDROID) | |
23 #include "chrome/browser/ui/android/infobars/previews_infobar.h" | |
24 #endif | |
25 | |
22 namespace { | 26 namespace { |
23 | 27 |
24 // Key of the UMA Previews.InfoBarAction.LoFi histogram. | 28 // Key of the UMA Previews.InfoBarAction.LoFi histogram. |
25 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; | 29 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; |
26 | 30 |
27 // Key of the UMA Previews.InfoBarAction.Offline histogram. | 31 // Key of the UMA Previews.InfoBarAction.Offline histogram. |
28 const char kUMAPreviewsInfoBarActionOffline[] = | 32 const char kUMAPreviewsInfoBarActionOffline[] = |
29 "Previews.InfoBarAction.Offline"; | 33 "Previews.InfoBarAction.Offline"; |
30 | 34 |
31 // Key of the UMA Previews.InfoBarAction.LitePage histogram. | 35 // Key of the UMA Previews.InfoBarAction.LitePage histogram. |
(...skipping 17 matching lines...) Expand all Loading... | |
49 | 53 |
50 } // namespace | 54 } // namespace |
51 | 55 |
52 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() { | 56 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() { |
53 if (!on_dismiss_callback_.is_null()) | 57 if (!on_dismiss_callback_.is_null()) |
54 on_dismiss_callback_.Run(false); | 58 on_dismiss_callback_.Run(false); |
55 | 59 |
56 RecordPreviewsInfoBarAction(infobar_type_, infobar_dismissed_action_); | 60 RecordPreviewsInfoBarAction(infobar_type_, infobar_dismissed_action_); |
57 } | 61 } |
58 | 62 |
63 PreviewsInfoBarDelegate* PreviewsInfoBarDelegate::AsPreviewsInfoBarDelegate() { | |
64 return this; | |
65 } | |
66 | |
59 // static | 67 // static |
60 void PreviewsInfoBarDelegate::Create( | 68 void PreviewsInfoBarDelegate::Create( |
61 content::WebContents* web_contents, | 69 content::WebContents* web_contents, |
62 PreviewsInfoBarType infobar_type, | 70 PreviewsInfoBarType infobar_type, |
63 bool is_data_saver_user, | 71 bool is_data_saver_user, |
64 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { | 72 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { |
65 PreviewsInfoBarTabHelper* infobar_tab_helper = | 73 PreviewsInfoBarTabHelper* infobar_tab_helper = |
66 PreviewsInfoBarTabHelper::FromWebContents(web_contents); | 74 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
67 InfoBarService* infobar_service = | 75 InfoBarService* infobar_service = |
68 InfoBarService::FromWebContents(web_contents); | 76 InfoBarService::FromWebContents(web_contents); |
69 | 77 |
70 // The WebContents may not have TabHelpers set. If TabHelpers are not set, | 78 // The WebContents may not have TabHelpers set. If TabHelpers are not set, |
71 // don't show Previews infobars. | 79 // don't show Previews infobars. |
72 if (!infobar_tab_helper || !infobar_service) | 80 if (!infobar_tab_helper || !infobar_service) |
73 return; | 81 return; |
74 if (infobar_tab_helper->displayed_preview_infobar()) | 82 if (infobar_tab_helper->displayed_preview_infobar()) |
75 return; | 83 return; |
76 | 84 |
85 #if defined(OS_ANDROID) | |
86 infobars::InfoBar* infobar = | |
87 infobar_service->AddInfoBar(PreviewsInfoBar::CreateInfoBar( | |
88 infobar_service, | |
89 std::unique_ptr<PreviewsInfoBarDelegate>(new PreviewsInfoBarDelegate( | |
Peter Kasting
2017/05/08 23:33:35
Nit: Since PreviewsInfoBarDelegate is a ConfirmInf
megjablon
2017/05/09 00:14:30
Done.
| |
90 web_contents, infobar_type, is_data_saver_user, | |
91 on_dismiss_callback)))); | |
92 #else | |
77 infobars::InfoBar* infobar = | 93 infobars::InfoBar* infobar = |
78 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 94 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
79 std::unique_ptr<ConfirmInfoBarDelegate>(new PreviewsInfoBarDelegate( | 95 std::unique_ptr<ConfirmInfoBarDelegate>(new PreviewsInfoBarDelegate( |
80 web_contents, infobar_type, is_data_saver_user, | 96 web_contents, infobar_type, is_data_saver_user, |
81 on_dismiss_callback)))); | 97 on_dismiss_callback)))); |
98 #endif | |
82 | 99 |
83 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { | 100 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { |
84 auto* data_reduction_proxy_settings = | 101 auto* data_reduction_proxy_settings = |
85 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 102 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
86 web_contents->GetBrowserContext()); | 103 web_contents->GetBrowserContext()); |
87 data_reduction_proxy_settings->IncrementLoFiUIShown(); | 104 data_reduction_proxy_settings->IncrementLoFiUIShown(); |
88 } | 105 } |
89 | 106 |
90 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); | 107 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); |
91 infobar_tab_helper->set_displayed_preview_infobar(true); | 108 infobar_tab_helper->set_displayed_preview_infobar(true); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 } else if (infobar_type_ == OFFLINE) { | 189 } else if (infobar_type_ == OFFLINE) { |
173 // Prevent LoFi and lite page modes from showing after reload. | 190 // Prevent LoFi and lite page modes from showing after reload. |
174 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. | 191 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. |
175 // crbug.com/707272 | 192 // crbug.com/707272 |
176 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, | 193 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, |
177 true); | 194 true); |
178 } | 195 } |
179 | 196 |
180 return true; | 197 return true; |
181 } | 198 } |
199 | |
200 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const { | |
201 return base::string16(); | |
202 } | |
OLD | NEW |