| 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 28 matching lines...) Expand all Loading... |
| 39 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLitePage, action, | 39 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLitePage, action, |
| 40 PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); | 40 PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); |
| 41 } else if (infobar_type == PreviewsInfoBarDelegate::OFFLINE) { | 41 } else if (infobar_type == PreviewsInfoBarDelegate::OFFLINE) { |
| 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()) |
| 51 on_dismiss_callback_.Run(false); |
| 52 } |
| 50 | 53 |
| 51 // static | 54 // static |
| 52 void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents, | 55 void PreviewsInfoBarDelegate::Create( |
| 53 PreviewsInfoBarType infobar_type) { | 56 content::WebContents* web_contents, |
| 57 PreviewsInfoBarType infobar_type, |
| 58 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { |
| 54 PreviewsInfoBarTabHelper* infobar_tab_helper = | 59 PreviewsInfoBarTabHelper* infobar_tab_helper = |
| 55 PreviewsInfoBarTabHelper::FromWebContents(web_contents); | 60 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
| 56 if (infobar_tab_helper->displayed_preview_infobar()) | 61 if (infobar_tab_helper->displayed_preview_infobar()) |
| 57 return; | 62 return; |
| 58 | 63 |
| 59 InfoBarService* infobar_service = | 64 InfoBarService* infobar_service = |
| 60 InfoBarService::FromWebContents(web_contents); | 65 InfoBarService::FromWebContents(web_contents); |
| 61 | 66 |
| 62 infobars::InfoBar* infobar = | 67 infobars::InfoBar* infobar = |
| 63 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 68 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| 64 std::unique_ptr<ConfirmInfoBarDelegate>( | 69 std::unique_ptr<ConfirmInfoBarDelegate>(new PreviewsInfoBarDelegate( |
| 65 new PreviewsInfoBarDelegate(web_contents, infobar_type)))); | 70 web_contents, infobar_type, on_dismiss_callback)))); |
| 66 | 71 |
| 67 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { | 72 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { |
| 68 auto* data_reduction_proxy_settings = | 73 auto* data_reduction_proxy_settings = |
| 69 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 74 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 70 web_contents->GetBrowserContext()); | 75 web_contents->GetBrowserContext()); |
| 71 data_reduction_proxy_settings->IncrementLoFiUIShown(); | 76 data_reduction_proxy_settings->IncrementLoFiUIShown(); |
| 72 } | 77 } |
| 73 | 78 |
| 74 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); | 79 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); |
| 75 infobar_tab_helper->set_displayed_preview_infobar(true); | 80 infobar_tab_helper->set_displayed_preview_infobar(true); |
| 76 } | 81 } |
| 77 | 82 |
| 78 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( | 83 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( |
| 79 content::WebContents* web_contents, | 84 content::WebContents* web_contents, |
| 80 PreviewsInfoBarType infobar_type) | 85 PreviewsInfoBarType infobar_type, |
| 86 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) |
| 81 : ConfirmInfoBarDelegate(), | 87 : ConfirmInfoBarDelegate(), |
| 82 infobar_type_(infobar_type) {} | 88 infobar_type_(infobar_type), |
| 89 on_dismiss_callback_(on_dismiss_callback) {} |
| 83 | 90 |
| 84 infobars::InfoBarDelegate::InfoBarIdentifier | 91 infobars::InfoBarDelegate::InfoBarIdentifier |
| 85 PreviewsInfoBarDelegate::GetIdentifier() const { | 92 PreviewsInfoBarDelegate::GetIdentifier() const { |
| 86 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; | 93 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; |
| 87 } | 94 } |
| 88 | 95 |
| 89 int PreviewsInfoBarDelegate::GetIconId() const { | 96 int PreviewsInfoBarDelegate::GetIconId() const { |
| 90 #if defined(OS_ANDROID) | 97 #if defined(OS_ANDROID) |
| 91 return IDR_ANDROID_INFOBAR_PREVIEWS; | 98 return IDR_ANDROID_INFOBAR_PREVIEWS; |
| 92 #else | 99 #else |
| (...skipping 20 matching lines...) Expand all Loading... |
| 113 int PreviewsInfoBarDelegate::GetButtons() const { | 120 int PreviewsInfoBarDelegate::GetButtons() const { |
| 114 return BUTTON_NONE; | 121 return BUTTON_NONE; |
| 115 } | 122 } |
| 116 | 123 |
| 117 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { | 124 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { |
| 118 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); | 125 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); |
| 119 } | 126 } |
| 120 | 127 |
| 121 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 128 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 122 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_LOAD_ORIGINAL_CLICKED); | 129 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_LOAD_ORIGINAL_CLICKED); |
| 130 if (!on_dismiss_callback_.is_null()) |
| 131 on_dismiss_callback_.Run(true); |
| 132 on_dismiss_callback_.Reset(); |
| 133 |
| 123 content::WebContents* web_contents = | 134 content::WebContents* web_contents = |
| 124 InfoBarService::WebContentsFromInfoBar(infobar()); | 135 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 125 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { | 136 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { |
| 126 if (infobar_type_ == LITE_PAGE) | 137 if (infobar_type_ == LITE_PAGE) |
| 127 web_contents->GetController().ReloadDisableLoFi(true); | 138 web_contents->GetController().ReloadDisableLoFi(true); |
| 128 else if (infobar_type_ == LOFI) | 139 else if (infobar_type_ == LOFI) |
| 129 web_contents->ReloadLoFiImages(); | 140 web_contents->ReloadLoFiImages(); |
| 130 | 141 |
| 131 auto* data_reduction_proxy_settings = | 142 auto* data_reduction_proxy_settings = |
| 132 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 143 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 133 web_contents->GetBrowserContext()); | 144 web_contents->GetBrowserContext()); |
| 134 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | 145 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); |
| 135 } else if (infobar_type_ == OFFLINE) { | 146 } else if (infobar_type_ == OFFLINE) { |
| 136 web_contents->GetController().Reload(true); | 147 web_contents->GetController().Reload(true); |
| 137 } | 148 } |
| 138 | 149 |
| 139 return true; | 150 return true; |
| 140 } | 151 } |
| OLD | NEW |