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

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: add count of infobars shown per session 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..a0ebe292ea19ae7853884fe7d89f4802a88f93cc
--- /dev/null
+++ b/chrome/browser/previews/previews_infobar_delegate.cc
@@ -0,0 +1,129 @@
+// 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/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 "content/public/browser/web_contents_observer.h"
+#include "grit/theme_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+class PreviewsInfoBarDelegate::PreviewInfoBarWebContentsObserver
+ : public content::WebContentsObserver {
+ public:
+ PreviewInfoBarWebContentsObserver(content::WebContents* web_contents,
+ PreviewsInfoBarDelegate* delegate)
+ : content::WebContentsObserver(web_contents), delegate_(delegate) {}
+
+ // content::WebContentsObserver implementation:
+ void DidStartProvisionalLoadForFrame(
Peter Kasting 2016/08/23 19:48:18 It seems like this whole object is defined just so
megjablon 2016/08/23 23:54:17 I've moved the preview infobar to being displayed
+ content::RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ bool is_error_page,
+ bool is_iframe_srcdoc) override {
+ if (!render_frame_host->GetParent()) {
Peter Kasting 2016/08/23 19:48:17 Nit: No {}
megjablon 2016/08/23 23:54:17 Acknowledged.
+ delegate_->RemoveInfoBar();
Peter Kasting 2016/08/23 19:48:17 I believe a member class is an implicit friend of
megjablon 2016/08/23 23:54:16 Acknowledged.
+ }
+ }
+
+ private:
+ PreviewsInfoBarDelegate* delegate_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PreviewInfoBarWebContentsObserver);
Peter Kasting 2016/08/23 19:48:17 Nit: DISALLOW_COPY_AND_ASSIGN is sufficient, you'v
megjablon 2016/08/23 23:54:17 Acknowledged.
+};
+
+// static
+void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents,
+ PreviewsInfoBarType infobar_type) {
+ // TODO: Check that infobar was not already shown.
+
+ InfoBarService* infobar_service =
+ InfoBarService::FromWebContents(web_contents);
+ std::unique_ptr<infobars::InfoBar> infobar(
+ infobar_service->CreateConfirmInfoBar(
+ std::unique_ptr<ConfirmInfoBarDelegate>(
+ new PreviewsInfoBarDelegate(web_contents, infobar_type))));
+
+ infobar_service->AddInfoBar(std::move(infobar));
+
+ if (infobar_type == PREVIEW || infobar_type == LOFI) {
Peter Kasting 2016/08/23 19:48:18 Nit: Why not just "if (infobar_type != OFFLINE) {"
megjablon 2016/08/23 23:54:17 We will be adding new preview types to this class
+ DataReductionProxyChromeSettings* data_reduction_proxy_settings =
Peter Kasting 2016/08/23 19:48:17 Nit: To reduce verbosity I'd probably just start t
megjablon 2016/08/23 23:54:16 Done.
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
+ web_contents->GetBrowserContext());
+ data_reduction_proxy_settings->IncrementLoFiUIShown();
+ }
+}
+
+PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
+ content::WebContents* web_contents,
+ PreviewsInfoBarType infobar_type)
+ : ConfirmInfoBarDelegate(),
+ web_contents_observer_(
+ new PreviewInfoBarWebContentsObserver(web_contents, this)),
+ infobar_type_(infobar_type) {}
+
+PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {}
+
+void PreviewsInfoBarDelegate::RemoveInfoBar() {
+ infobar()->owner()->RemoveInfoBar(infobar());
+}
+
+bool PreviewsInfoBarDelegate::ShouldExpire(
+ const NavigationDetails& details) const {
+ // InfoBars are dismissed on navigation commit by ShouldExpire. This InfoBar
+ // can be shown for a page before a navigation commits, so
+ // DidStartProvisionalLoadForFrame is used to dismiss it.
+ return false;
+}
+
+infobars::InfoBarDelegate::InfoBarIdentifier
+PreviewsInfoBarDelegate::GetIdentifier() const {
+ return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE;
+}
+
+int PreviewsInfoBarDelegate::GetIconId() const {
+ return IDR_INFOBAR_PREVIEWS;
Peter Kasting 2016/08/23 19:48:18 If at all possible, prefer to add new vector icons
megjablon 2016/08/23 23:54:17 If we don't restrict this to just Android, I'll up
+}
+
+base::string16 PreviewsInfoBarDelegate::GetMessageText() const {
+ if (infobar_type_ == OFFLINE)
+ return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE);
+ else
+ return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE);
Peter Kasting 2016/08/23 19:48:17 Nit: Simpler: return l10n_util::GetStringUTF16(
megjablon 2016/08/23 23:54:17 Done.
+}
+
+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
+ content::WebContents* web_contents =
+ InfoBarService::WebContentsFromInfoBar(infobar());
+ web_contents_observer_.reset();
Peter Kasting 2016/08/23 19:48:17 Are you doing this because if you don't do it, the
megjablon 2016/08/23 23:54:17 Acknowledged.
+
+ DataReductionProxyChromeSettings* data_reduction_proxy_settings =
Peter Kasting 2016/08/23 19:48:17 Nit: Seems like it might be better to do something
megjablon 2016/08/23 23:54:17 As mentioned above, more types will be added, and
Peter Kasting 2016/08/24 03:18:27 Your counter-proposal looks fine to me. I would s
megjablon 2016/08/24 21:44:29 Done.
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
+ web_contents->GetBrowserContext());
+
+ if (infobar_type_ == PREVIEW) {
+ web_contents->GetController().ReloadDisableLoFi(true);
+ data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
+ } else if (infobar_type_ == LOFI) {
+ web_contents->ReloadLoFiImages();
+ data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
+ }
+
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698