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

Unified 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: fix unit tests 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/previews/previews_infobar_delegate.cc
diff --git a/chrome/browser/previews/previews_infobar_delegate.cc b/chrome/browser/previews/previews_infobar_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..666ab719294026dc52b3a8b146e8eb921c73b97d
--- /dev/null
+++ b/chrome/browser/previews/previews_infobar_delegate.cc
@@ -0,0 +1,99 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/previews/previews_infobar_delegate.h"
+
+#include "chrome/browser/android/android_theme_resources.h"
+#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/infobars/core/infobar.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/base/l10n/l10n_util.h"
+
+PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {}
+
+// static
+void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents,
+ PreviewsInfoBarType infobar_type) {
+ // 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.
+
+ InfoBarService* infobar_service =
+ InfoBarService::FromWebContents(web_contents);
+
+ infobars::InfoBar* infobar =
+ infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
+ std::unique_ptr<ConfirmInfoBarDelegate>(
+ 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
+
+ if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) {
+ auto* data_reduction_proxy_settings =
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
+ web_contents->GetBrowserContext());
+ 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
+ data_reduction_proxy_settings->IncrementLoFiUIShown();
+ }
+}
+
+PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
+ content::WebContents* web_contents,
+ PreviewsInfoBarType infobar_type)
+ : ConfirmInfoBarDelegate(),
+ infobar_type_(infobar_type) {}
+
+infobars::InfoBarDelegate::InfoBarIdentifier
+PreviewsInfoBarDelegate::GetIdentifier() const {
+ return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE;
+}
+
+int PreviewsInfoBarDelegate::GetIconId() const {
+#if defined(OS_ANDROID)
+ return IDR_ANDROID_INFOBAR_PREVIEWS;
+#else
+ return kNoIconID;
+#endif
+}
+
+bool PreviewsInfoBarDelegate::ShouldExpire(
+ const NavigationDetails& details) const {
+ // TODO: record uma data
bengr 2016/08/25 23:26:18 // TODO(megjablon): Record UMA data.
megjablon 2016/08/26 22:47:30 Done.
+ return InfoBarDelegate::ShouldExpire(details);
+}
+
+base::string16 PreviewsInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE)
+ ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE
+ : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE);
+}
+
+int PreviewsInfoBarDelegate::GetButtons() const {
+ return BUTTON_NONE;
+}
+
+base::string16 PreviewsInfoBarDelegate::GetLinkText() const {
+ return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK);
+}
+
+bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
+ // TODO: record uma data
bengr 2016/08/25 23:26:18 // TODO(megjablon): Record UMA data.
megjablon 2016/08/26 22:47:30 Done.
+ if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) {
+ auto* web_contents =
+ InfoBarService::WebContentsFromInfoBar(infobar());
+
+ 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.
+ web_contents->GetController().ReloadDisableLoFi(true);
+ if (infobar_type_ == LOFI)
+ web_contents->ReloadLoFiImages();
+
+ auto* data_reduction_proxy_settings =
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
+ web_contents->GetBrowserContext());
+ 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
+ data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
+ }
+
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698