OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/previews/previews_infobar_delegate.h" | |
6 | |
7 #include "chrome/browser/android/android_theme_resources.h" | |
8 #include "chrome/browser/infobars/infobar_service.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" | |
11 #include "chrome/grit/generated_resources.h" | |
12 #include "components/infobars/core/infobar.h" | |
13 #include "content/public/browser/render_frame_host.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 | |
17 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {} | |
18 | |
19 // static | |
20 void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents, | |
21 PreviewsInfoBarType infobar_type) { | |
22 // TODO: Check that infobar was not already shown. | |
bengr
2016/08/25 23:26:18
// TODO(megjablon): Check that the infobar was not
megjablon
2016/08/26 22:47:30
Done.
| |
23 | |
24 InfoBarService* infobar_service = | |
25 InfoBarService::FromWebContents(web_contents); | |
26 | |
27 infobars::InfoBar* infobar = | |
28 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | |
29 std::unique_ptr<ConfirmInfoBarDelegate>( | |
30 new PreviewsInfoBarDelegate(web_contents, infobar_type)))); | |
bengr
2016/08/25 23:26:18
You can use base::MakeUnique<PreviewsInfobarDelega
Peter Kasting
2016/08/25 23:55:18
Nope. I already suggested that and quickly withdr
| |
31 | |
32 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { | |
33 auto* data_reduction_proxy_settings = | |
34 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
35 web_contents->GetBrowserContext()); | |
36 if (data_reduction_proxy_settings) | |
bengr
2016/08/25 23:26:18
Can this ever be null?
megjablon
2016/08/26 22:47:30
Nope, we shouldn't be showing a LoFi or Lite Page
| |
37 data_reduction_proxy_settings->IncrementLoFiUIShown(); | |
38 } | |
39 } | |
40 | |
41 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( | |
42 content::WebContents* web_contents, | |
43 PreviewsInfoBarType infobar_type) | |
44 : ConfirmInfoBarDelegate(), | |
45 infobar_type_(infobar_type) {} | |
46 | |
47 infobars::InfoBarDelegate::InfoBarIdentifier | |
48 PreviewsInfoBarDelegate::GetIdentifier() const { | |
49 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; | |
50 } | |
51 | |
52 int PreviewsInfoBarDelegate::GetIconId() const { | |
53 #if defined(OS_ANDROID) | |
54 return IDR_ANDROID_INFOBAR_PREVIEWS; | |
55 #else | |
56 return kNoIconID; | |
57 #endif | |
58 } | |
59 | |
60 bool PreviewsInfoBarDelegate::ShouldExpire( | |
61 const NavigationDetails& details) const { | |
62 // TODO: record uma data | |
bengr
2016/08/25 23:26:18
// TODO(megjablon): Record UMA data.
megjablon
2016/08/26 22:47:30
Done.
| |
63 return InfoBarDelegate::ShouldExpire(details); | |
64 } | |
65 | |
66 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { | |
67 return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE) | |
68 ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE | |
69 : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE); | |
70 } | |
71 | |
72 int PreviewsInfoBarDelegate::GetButtons() const { | |
73 return BUTTON_NONE; | |
74 } | |
75 | |
76 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { | |
77 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); | |
78 } | |
79 | |
80 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | |
81 // TODO: record uma data | |
bengr
2016/08/25 23:26:18
// TODO(megjablon): Record UMA data.
megjablon
2016/08/26 22:47:30
Done.
| |
82 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { | |
83 auto* web_contents = | |
84 InfoBarService::WebContentsFromInfoBar(infobar()); | |
85 | |
86 if (infobar_type_ == LITE_PAGE) | |
bengr
2016/08/25 23:26:19
This might be a little clearer with a switch.
Peter Kasting
2016/08/25 23:55:18
I don't think so:
switch (infobar_type) {
megjablon
2016/08/26 22:47:30
Done.
| |
87 web_contents->GetController().ReloadDisableLoFi(true); | |
88 if (infobar_type_ == LOFI) | |
89 web_contents->ReloadLoFiImages(); | |
90 | |
91 auto* data_reduction_proxy_settings = | |
92 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
93 web_contents->GetBrowserContext()); | |
94 if (data_reduction_proxy_settings) | |
bengr
2016/08/25 23:26:18
Can this ever be null?
megjablon
2016/08/26 22:47:30
Nope, we shouldn't be showing a LoFi or Lite Page
| |
95 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | |
96 } | |
97 | |
98 return true; | |
99 } | |
OLD | NEW |