Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1343)

Side by Side Diff: chrome/browser/previews/previews_infobar_delegate.cc

Issue 2581533003: Show the Data Saver string for offline previews when Data Saver is enabled (Closed)
Patch Set: bengr comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/android/android_theme_resources.h" 8 #include "chrome/browser/android/android_theme_resources.h"
9 #include "chrome/browser/infobars/infobar_service.h" 9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() { 49 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {
50 if (!on_dismiss_callback_.is_null()) 50 if (!on_dismiss_callback_.is_null())
51 on_dismiss_callback_.Run(false); 51 on_dismiss_callback_.Run(false);
52 } 52 }
53 53
54 // static 54 // static
55 void PreviewsInfoBarDelegate::Create( 55 void PreviewsInfoBarDelegate::Create(
56 content::WebContents* web_contents, 56 content::WebContents* web_contents,
57 PreviewsInfoBarType infobar_type, 57 PreviewsInfoBarType infobar_type,
58 bool is_data_saver_user,
58 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { 59 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) {
59 PreviewsInfoBarTabHelper* infobar_tab_helper = 60 PreviewsInfoBarTabHelper* infobar_tab_helper =
60 PreviewsInfoBarTabHelper::FromWebContents(web_contents); 61 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
61 if (infobar_tab_helper->displayed_preview_infobar()) 62 if (infobar_tab_helper->displayed_preview_infobar())
62 return; 63 return;
63 64
64 InfoBarService* infobar_service = 65 InfoBarService* infobar_service =
65 InfoBarService::FromWebContents(web_contents); 66 InfoBarService::FromWebContents(web_contents);
66 67
67 infobars::InfoBar* infobar = 68 infobars::InfoBar* infobar =
68 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( 69 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
69 std::unique_ptr<ConfirmInfoBarDelegate>(new PreviewsInfoBarDelegate( 70 std::unique_ptr<ConfirmInfoBarDelegate>(new PreviewsInfoBarDelegate(
70 web_contents, infobar_type, on_dismiss_callback)))); 71 web_contents, infobar_type, is_data_saver_user,
72 on_dismiss_callback))));
71 73
72 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { 74 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) {
73 auto* data_reduction_proxy_settings = 75 auto* data_reduction_proxy_settings =
74 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 76 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
75 web_contents->GetBrowserContext()); 77 web_contents->GetBrowserContext());
76 data_reduction_proxy_settings->IncrementLoFiUIShown(); 78 data_reduction_proxy_settings->IncrementLoFiUIShown();
77 } 79 }
78 80
79 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); 81 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN);
80 infobar_tab_helper->set_displayed_preview_infobar(true); 82 infobar_tab_helper->set_displayed_preview_infobar(true);
81 } 83 }
82 84
83 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( 85 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
84 content::WebContents* web_contents, 86 content::WebContents* web_contents,
85 PreviewsInfoBarType infobar_type, 87 PreviewsInfoBarType infobar_type,
88 bool is_data_saver_user,
86 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) 89 const OnDismissPreviewsInfobarCallback& on_dismiss_callback)
87 : ConfirmInfoBarDelegate(), 90 : ConfirmInfoBarDelegate(),
88 infobar_type_(infobar_type), 91 infobar_type_(infobar_type),
92 message_text_(l10n_util::GetStringUTF16(
93 is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE
94 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE)),
89 on_dismiss_callback_(on_dismiss_callback) {} 95 on_dismiss_callback_(on_dismiss_callback) {}
90 96
91 infobars::InfoBarDelegate::InfoBarIdentifier 97 infobars::InfoBarDelegate::InfoBarIdentifier
92 PreviewsInfoBarDelegate::GetIdentifier() const { 98 PreviewsInfoBarDelegate::GetIdentifier() const {
93 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; 99 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE;
94 } 100 }
95 101
96 int PreviewsInfoBarDelegate::GetIconId() const { 102 int PreviewsInfoBarDelegate::GetIconId() const {
97 #if defined(OS_ANDROID) 103 #if defined(OS_ANDROID)
98 return IDR_ANDROID_INFOBAR_PREVIEWS; 104 return IDR_ANDROID_INFOBAR_PREVIEWS;
99 #else 105 #else
100 return kNoIconID; 106 return kNoIconID;
101 #endif 107 #endif
102 } 108 }
103 109
104 bool PreviewsInfoBarDelegate::ShouldExpire( 110 bool PreviewsInfoBarDelegate::ShouldExpire(
105 const NavigationDetails& details) const { 111 const NavigationDetails& details) const {
106 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_NAVIGATION); 112 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_NAVIGATION);
107 return InfoBarDelegate::ShouldExpire(details); 113 return InfoBarDelegate::ShouldExpire(details);
108 } 114 }
109 115
110 void PreviewsInfoBarDelegate::InfoBarDismissed() { 116 void PreviewsInfoBarDelegate::InfoBarDismissed() {
111 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_USER); 117 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_USER);
112 } 118 }
113 119
114 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { 120 base::string16 PreviewsInfoBarDelegate::GetMessageText() const {
115 return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE) 121 return message_text_;
116 ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE
117 : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE);
118 } 122 }
119 123
120 int PreviewsInfoBarDelegate::GetButtons() const { 124 int PreviewsInfoBarDelegate::GetButtons() const {
121 return BUTTON_NONE; 125 return BUTTON_NONE;
122 } 126 }
123 127
124 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { 128 base::string16 PreviewsInfoBarDelegate::GetLinkText() const {
125 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); 129 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK);
126 } 130 }
127 131
(...skipping 14 matching lines...) Expand all
142 auto* data_reduction_proxy_settings = 146 auto* data_reduction_proxy_settings =
143 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 147 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
144 web_contents->GetBrowserContext()); 148 web_contents->GetBrowserContext());
145 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); 149 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
146 } else if (infobar_type_ == OFFLINE) { 150 } else if (infobar_type_ == OFFLINE) {
147 web_contents->GetController().Reload(true); 151 web_contents->GetController().Reload(true);
148 } 152 }
149 153
150 return true; 154 return true;
151 } 155 }
OLDNEW
« no previous file with comments | « chrome/browser/previews/previews_infobar_delegate.h ('k') | chrome/browser/previews/previews_infobar_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698