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 "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 Loading... | |
| 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 is_data_saver_user_(is_data_saver_user), | |
| 89 on_dismiss_callback_(on_dismiss_callback) {} | 93 on_dismiss_callback_(on_dismiss_callback) {} |
| 90 | 94 |
| 91 infobars::InfoBarDelegate::InfoBarIdentifier | 95 infobars::InfoBarDelegate::InfoBarIdentifier |
| 92 PreviewsInfoBarDelegate::GetIdentifier() const { | 96 PreviewsInfoBarDelegate::GetIdentifier() const { |
| 93 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; | 97 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; |
| 94 } | 98 } |
| 95 | 99 |
| 96 int PreviewsInfoBarDelegate::GetIconId() const { | 100 int PreviewsInfoBarDelegate::GetIconId() const { |
| 97 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
| 98 return IDR_ANDROID_INFOBAR_PREVIEWS; | 102 return IDR_ANDROID_INFOBAR_PREVIEWS; |
| 99 #else | 103 #else |
| 100 return kNoIconID; | 104 return kNoIconID; |
| 101 #endif | 105 #endif |
| 102 } | 106 } |
| 103 | 107 |
| 104 bool PreviewsInfoBarDelegate::ShouldExpire( | 108 bool PreviewsInfoBarDelegate::ShouldExpire( |
| 105 const NavigationDetails& details) const { | 109 const NavigationDetails& details) const { |
| 106 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_NAVIGATION); | 110 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_NAVIGATION); |
| 107 return InfoBarDelegate::ShouldExpire(details); | 111 return InfoBarDelegate::ShouldExpire(details); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void PreviewsInfoBarDelegate::InfoBarDismissed() { | 114 void PreviewsInfoBarDelegate::InfoBarDismissed() { |
| 111 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_USER); | 115 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_USER); |
| 112 } | 116 } |
| 113 | 117 |
| 114 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { | 118 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { |
| 115 return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE) | 119 return l10n_util::GetStringUTF16( |
| 116 ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE | 120 (is_data_saver_user_) ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE |
|
bengr
2016/12/16 00:38:43
Seems you want to choose a string when you create
RyanSturm
2016/12/16 19:02:09
Done.
| |
| 117 : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE); | 121 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_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 Loading... | |
| 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 } |
| OLD | NEW |