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 "chrome/browser/android/android_theme_resources.h" | 7 #include "chrome/browser/android/android_theme_resources.h" |
8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" |
11 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | |
11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
12 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
13 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 | 17 |
17 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {} | 18 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {} |
18 | 19 |
19 // static | 20 // static |
20 void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents, | 21 void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents, |
21 PreviewsInfoBarType infobar_type) { | 22 PreviewsInfoBarType infobar_type) { |
22 // TODO(megjablon): Check that the infobar was not already shown. | 23 PreviewsInfoBarTabHelper* infobar_tab_helper = |
24 PreviewsInfoBarTabHelper::FromWebContents(web_contents); | |
25 if (infobar_tab_helper->DisplayedPreviewInfoBar()) | |
bengr
2016/08/31 23:27:04
Can infobar_tab_helper be null?
megjablon
2016/09/08 00:25:15
The PreviewsInfoBarTabHelper is created in AttachT
| |
26 return; | |
23 | 27 |
24 InfoBarService* infobar_service = | 28 InfoBarService* infobar_service = |
25 InfoBarService::FromWebContents(web_contents); | 29 InfoBarService::FromWebContents(web_contents); |
26 | 30 |
27 infobars::InfoBar* infobar = | 31 infobars::InfoBar* infobar = |
28 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 32 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
29 std::unique_ptr<ConfirmInfoBarDelegate>( | 33 std::unique_ptr<ConfirmInfoBarDelegate>( |
30 new PreviewsInfoBarDelegate(web_contents, infobar_type)))); | 34 new PreviewsInfoBarDelegate(web_contents, infobar_type)))); |
31 | 35 |
32 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { | 36 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { |
33 auto* data_reduction_proxy_settings = | 37 auto* data_reduction_proxy_settings = |
34 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 38 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
35 web_contents->GetBrowserContext()); | 39 web_contents->GetBrowserContext()); |
36 data_reduction_proxy_settings->IncrementLoFiUIShown(); | 40 data_reduction_proxy_settings->IncrementLoFiUIShown(); |
37 } | 41 } |
42 | |
43 infobar_tab_helper->SetDisplayedPreviewInfoBar(true); | |
38 } | 44 } |
39 | 45 |
40 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( | 46 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( |
41 content::WebContents* web_contents, | 47 content::WebContents* web_contents, |
42 PreviewsInfoBarType infobar_type) | 48 PreviewsInfoBarType infobar_type) |
43 : ConfirmInfoBarDelegate(), | 49 : ConfirmInfoBarDelegate(), |
44 infobar_type_(infobar_type) {} | 50 infobar_type_(infobar_type) {} |
45 | 51 |
46 infobars::InfoBarDelegate::InfoBarIdentifier | 52 infobars::InfoBarDelegate::InfoBarIdentifier |
47 PreviewsInfoBarDelegate::GetIdentifier() const { | 53 PreviewsInfoBarDelegate::GetIdentifier() const { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 web_contents->ReloadLoFiImages(); | 94 web_contents->ReloadLoFiImages(); |
89 | 95 |
90 auto* data_reduction_proxy_settings = | 96 auto* data_reduction_proxy_settings = |
91 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 97 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
92 web_contents->GetBrowserContext()); | 98 web_contents->GetBrowserContext()); |
93 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | 99 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); |
94 } | 100 } |
95 | 101 |
96 return true; | 102 return true; |
97 } | 103 } |
OLD | NEW |