Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/previews/previews_infobar_delegate.cc

Issue 2250223002: Add InfoBar delegate for previews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pkasting comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/infobars/infobar_service.h"
8 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "components/infobars/core/infobar.h"
12 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_observer.h"
Peter Kasting 2016/08/24 03:18:27 Nit: I think at least this #include can now be rem
megjablon 2016/08/24 21:28:36 Ah oops. I've gotten too used to eclipse pointing
15 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 // static
19 void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents,
20 PreviewsInfoBarType infobar_type) {
21 // TODO: Check that infobar was not already shown.
Peter Kasting 2016/08/24 03:18:28 By this I assume you're referring to your separate
Peter Kasting 2016/08/24 03:53:04 Wow, I am sorry, I totally cross-wired. This comm
megjablon 2016/08/24 21:28:36 Acknowledged.
22
23 InfoBarService* infobar_service =
24 InfoBarService::FromWebContents(web_contents);
25 std::unique_ptr<infobars::InfoBar> infobar(
Peter Kasting 2016/08/24 03:18:27 Nit: I'd probably inline this below as most Create
megjablon 2016/08/24 21:28:36 Done.
26 infobar_service->CreateConfirmInfoBar(
27 std::unique_ptr<ConfirmInfoBarDelegate>(
28 new PreviewsInfoBarDelegate(web_contents, infobar_type))));
Peter Kasting 2016/08/24 03:18:27 Nit: Prefer MakeUnique to unique_ptr(new X).
Peter Kasting 2016/08/24 03:43:07 Belay that, you can't use MakeUnique() with a priv
megjablon 2016/08/24 21:28:36 Acknowledged.
29
30 infobar_service->AddInfoBar(std::move(infobar));
31
32 if (infobar_type == LITE_PAGE || infobar_type == LOFI) {
33 auto* data_reduction_proxy_settings =
Peter Kasting 2016/08/24 03:18:27 Nit: If you're going to use auto here (which I'm i
megjablon 2016/08/24 21:28:36 Done.
34 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
35 web_contents->GetBrowserContext());
36 data_reduction_proxy_settings->IncrementLoFiUIShown();
Peter Kasting 2016/08/24 03:18:27 You should only increment this if AddInfoBar() suc
megjablon 2016/08/24 21:28:36 Done.
37 }
38 }
39
40 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
41 content::WebContents* web_contents,
42 PreviewsInfoBarType infobar_type)
43 : ConfirmInfoBarDelegate(),
44 infobar_type_(infobar_type) {}
45
46 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {}
47
48 bool PreviewsInfoBarDelegate::ShouldExpire(
49 const NavigationDetails& details) const {
50 // TODO: record uma data
51 return true;
Peter Kasting 2016/08/24 03:18:27 I don't think you want to unconditionally return t
megjablon 2016/08/24 21:28:36 Updated this to calling InfoBarDelegate which chec
52 }
53
54 infobars::InfoBarDelegate::InfoBarIdentifier
55 PreviewsInfoBarDelegate::GetIdentifier() const {
56 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE;
57 }
58
59 int PreviewsInfoBarDelegate::GetIconId() const {
60 return IDR_INFOBAR_PREVIEWS;
61 }
62
63 base::string16 PreviewsInfoBarDelegate::GetMessageText() const {
64 return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE)
65 ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE
66 : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE);
67 }
68
69 int PreviewsInfoBarDelegate::GetButtons() const {
70 return BUTTON_NONE;
71 }
72
73 base::string16 PreviewsInfoBarDelegate::GetLinkText() const {
74 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK);
75 }
76
77 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
78 // TODO: record uma data
79 content::WebContents* web_contents =
80 InfoBarService::WebContentsFromInfoBar(infobar());
81
82 DataReductionProxyChromeSettings* data_reduction_proxy_settings =
83 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
84 web_contents->GetBrowserContext());
85
86 if (infobar_type_ == LITE_PAGE) {
87 web_contents->GetController().ReloadDisableLoFi(true);
88 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
89 } else if (infobar_type_ == LOFI) {
90 web_contents->ReloadLoFiImages();
91 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
92 }
93
94 return true;
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698