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

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: rebase Created 4 years, 3 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/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(megjablon): Check that the infobar was not already shown.
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))));
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 data_reduction_proxy_settings->IncrementLoFiUIShown();
37 }
38 }
39
40 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
41 content::WebContents* web_contents,
42 PreviewsInfoBarType infobar_type)
43 : ConfirmInfoBarDelegate(),
44 infobar_type_(infobar_type) {}
45
46 infobars::InfoBarDelegate::InfoBarIdentifier
47 PreviewsInfoBarDelegate::GetIdentifier() const {
48 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE;
49 }
50
51 int PreviewsInfoBarDelegate::GetIconId() const {
52 #if defined(OS_ANDROID)
53 return IDR_ANDROID_INFOBAR_PREVIEWS;
54 #else
55 return kNoIconID;
56 #endif
57 }
58
59 bool PreviewsInfoBarDelegate::ShouldExpire(
60 const NavigationDetails& details) const {
61 // TODO(megjablon): Record UMA data.
62 return InfoBarDelegate::ShouldExpire(details);
63 }
64
65 base::string16 PreviewsInfoBarDelegate::GetMessageText() const {
66 return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE)
67 ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE
68 : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE);
69 }
70
71 int PreviewsInfoBarDelegate::GetButtons() const {
72 return BUTTON_NONE;
73 }
74
75 base::string16 PreviewsInfoBarDelegate::GetLinkText() const {
76 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK);
77 }
78
79 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
80 // TODO(megjablon): Record UMA data.
81 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) {
82 auto* web_contents =
83 InfoBarService::WebContentsFromInfoBar(infobar());
84
85 if (infobar_type_ == LITE_PAGE)
86 web_contents->GetController().ReloadDisableLoFi(true);
87 else if (infobar_type_ == LOFI)
88 web_contents->ReloadLoFiImages();
89
90 auto* data_reduction_proxy_settings =
91 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
92 web_contents->GetBrowserContext());
93 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
94 }
95
96 return true;
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698