| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionOffline, action, | 42 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionOffline, action, |
| 43 PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); | 43 PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 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 |
| 53 RecordPreviewsInfoBarAction(infobar_type_, infobar_dismissed_action_); |
| 52 } | 54 } |
| 53 | 55 |
| 54 // static | 56 // static |
| 55 void PreviewsInfoBarDelegate::Create( | 57 void PreviewsInfoBarDelegate::Create( |
| 56 content::WebContents* web_contents, | 58 content::WebContents* web_contents, |
| 57 PreviewsInfoBarType infobar_type, | 59 PreviewsInfoBarType infobar_type, |
| 58 bool is_data_saver_user, | 60 bool is_data_saver_user, |
| 59 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { | 61 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { |
| 60 PreviewsInfoBarTabHelper* infobar_tab_helper = | 62 PreviewsInfoBarTabHelper* infobar_tab_helper = |
| 61 PreviewsInfoBarTabHelper::FromWebContents(web_contents); | 63 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 86 infobar_tab_helper->set_displayed_preview_infobar(true); | 88 infobar_tab_helper->set_displayed_preview_infobar(true); |
| 87 } | 89 } |
| 88 | 90 |
| 89 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( | 91 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( |
| 90 content::WebContents* web_contents, | 92 content::WebContents* web_contents, |
| 91 PreviewsInfoBarType infobar_type, | 93 PreviewsInfoBarType infobar_type, |
| 92 bool is_data_saver_user, | 94 bool is_data_saver_user, |
| 93 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) | 95 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) |
| 94 : ConfirmInfoBarDelegate(), | 96 : ConfirmInfoBarDelegate(), |
| 95 infobar_type_(infobar_type), | 97 infobar_type_(infobar_type), |
| 98 infobar_dismissed_action_(INFOBAR_DISMISSED_BY_TAB_CLOSURE), |
| 96 message_text_(l10n_util::GetStringUTF16( | 99 message_text_(l10n_util::GetStringUTF16( |
| 97 is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE | 100 is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE |
| 98 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE)), | 101 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE)), |
| 99 on_dismiss_callback_(on_dismiss_callback) {} | 102 on_dismiss_callback_(on_dismiss_callback) {} |
| 100 | 103 |
| 101 infobars::InfoBarDelegate::InfoBarIdentifier | 104 infobars::InfoBarDelegate::InfoBarIdentifier |
| 102 PreviewsInfoBarDelegate::GetIdentifier() const { | 105 PreviewsInfoBarDelegate::GetIdentifier() const { |
| 103 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; | 106 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; |
| 104 } | 107 } |
| 105 | 108 |
| 106 int PreviewsInfoBarDelegate::GetIconId() const { | 109 int PreviewsInfoBarDelegate::GetIconId() const { |
| 107 #if defined(OS_ANDROID) | 110 #if defined(OS_ANDROID) |
| 108 return IDR_ANDROID_INFOBAR_PREVIEWS; | 111 return IDR_ANDROID_INFOBAR_PREVIEWS; |
| 109 #else | 112 #else |
| 110 return kNoIconID; | 113 return kNoIconID; |
| 111 #endif | 114 #endif |
| 112 } | 115 } |
| 113 | 116 |
| 114 bool PreviewsInfoBarDelegate::ShouldExpire( | 117 bool PreviewsInfoBarDelegate::ShouldExpire( |
| 115 const NavigationDetails& details) const { | 118 const NavigationDetails& details) const { |
| 116 RecordPreviewsInfoBarAction( | 119 infobar_dismissed_action_ = details.is_reload |
| 117 infobar_type_, details.is_reload ? INFOBAR_DISMISSED_BY_RELOAD | 120 ? INFOBAR_DISMISSED_BY_RELOAD |
| 118 : INFOBAR_DISMISSED_BY_NAVIGATION); | 121 : INFOBAR_DISMISSED_BY_NAVIGATION; |
| 119 return InfoBarDelegate::ShouldExpire(details); | 122 return InfoBarDelegate::ShouldExpire(details); |
| 120 } | 123 } |
| 121 | 124 |
| 122 void PreviewsInfoBarDelegate::InfoBarDismissed() { | 125 void PreviewsInfoBarDelegate::InfoBarDismissed() { |
| 123 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_USER); | 126 infobar_dismissed_action_ = INFOBAR_DISMISSED_BY_USER; |
| 124 } | 127 } |
| 125 | 128 |
| 126 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { | 129 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { |
| 127 return message_text_; | 130 return message_text_; |
| 128 } | 131 } |
| 129 | 132 |
| 130 int PreviewsInfoBarDelegate::GetButtons() const { | 133 int PreviewsInfoBarDelegate::GetButtons() const { |
| 131 return BUTTON_NONE; | 134 return BUTTON_NONE; |
| 132 } | 135 } |
| 133 | 136 |
| 134 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { | 137 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { |
| 135 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); | 138 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); |
| 136 } | 139 } |
| 137 | 140 |
| 138 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 141 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 139 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_LOAD_ORIGINAL_CLICKED); | 142 infobar_dismissed_action_ = 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) { |
| 147 if (infobar_type_ == LITE_PAGE) | 150 if (infobar_type_ == LITE_PAGE) |
| 148 web_contents->GetController().Reload( | 151 web_contents->GetController().Reload( |
| 149 content::ReloadType::DISABLE_LOFI_MODE, true); | 152 content::ReloadType::DISABLE_LOFI_MODE, true); |
| 150 else if (infobar_type_ == LOFI) | 153 else if (infobar_type_ == LOFI) |
| 151 web_contents->ReloadLoFiImages(); | 154 web_contents->ReloadLoFiImages(); |
| 152 | 155 |
| 153 auto* data_reduction_proxy_settings = | 156 auto* data_reduction_proxy_settings = |
| 154 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 157 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 155 web_contents->GetBrowserContext()); | 158 web_contents->GetBrowserContext()); |
| 156 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | 159 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); |
| 157 } else if (infobar_type_ == OFFLINE) { | 160 } else if (infobar_type_ == OFFLINE) { |
| 158 // Prevent LoFi and lite page modes from showing after reload. | 161 // Prevent LoFi and lite page modes from showing after reload. |
| 159 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. | 162 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS. |
| 160 // crbug.com/707272 | 163 // crbug.com/707272 |
| 161 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, | 164 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE, |
| 162 true); | 165 true); |
| 163 } | 166 } |
| 164 | 167 |
| 165 return true; | 168 return true; |
| 166 } | 169 } |
| OLD | NEW |