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

Unified Diff: chrome/browser/previews/previews_infobar_tab_helper.cc

Issue 2462653002: Showing previews UI for Offline Previews (Closed)
Patch Set: fgorski comment Created 4 years, 2 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_tab_helper.cc
diff --git a/chrome/browser/previews/previews_infobar_tab_helper.cc b/chrome/browser/previews/previews_infobar_tab_helper.cc
index 3043a0b2aea563637192c31d229a4bca632b2f69..870d22e2c540b770286cbac46762734d97a694e2 100644
--- a/chrome/browser/previews/previews_infobar_tab_helper.cc
+++ b/chrome/browser/previews/previews_infobar_tab_helper.cc
@@ -1,48 +1,66 @@
// 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_tab_helper.h"
#include "chrome/browser/previews/previews_infobar_delegate.h"
+#include "chrome/common/features.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "net/http/http_response_headers.h"
#include "url/gurl.h"
+#if BUILDFLAG(ANDROID_JAVA_UI)
+#include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
+#endif // BUILDFLAG(ANDROID_JAVA_UI)
+
DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper);
PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {}
PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
- displayed_preview_infobar_(false) {
+ displayed_preview_infobar_(false),
+ is_showing_offline_preview_(false) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
}
-void PreviewsInfoBarTabHelper::DidStartProvisionalLoadForFrame(
- content::RenderFrameHost* render_frame_host,
- const GURL& validated_url,
- bool is_error_page,
- bool is_iframe_srcdoc) {
- if (!render_frame_host->GetParent())
- set_displayed_preview_infobar(false);
-}
-
void PreviewsInfoBarTabHelper::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
- if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
+ // Only show the infobar if this is a full main frame navigation.
+ if (!navigation_handle->IsInMainFrame() ||
+ !navigation_handle->HasCommitted() || navigation_handle->IsSamePage())
+ return;
+ is_showing_offline_preview_ = false;
+ displayed_preview_infobar_ = false;
+
+#if BUILDFLAG(ANDROID_JAVA_UI)
+ offline_pages::OfflinePageTabHelper* tab_helper =
+ offline_pages::OfflinePageTabHelper::FromWebContents(web_contents());
+
+ if (tab_helper && tab_helper->IsShowingOfflinePreview()) {
+ if (navigation_handle->IsErrorPage()) {
+ // TODO(ryansturm): Add UMA for errors.
+ return;
+ }
+ is_showing_offline_preview_ = true;
+ PreviewsInfoBarDelegate::Create(web_contents(),
+ PreviewsInfoBarDelegate::OFFLINE);
+ // Don't try to show other infobars if this is an offline preview.
return;
+ }
+#endif // BUILDFLAG(ANDROID_JAVA_UI)
+
const net::HttpResponseHeaders* headers =
navigation_handle->GetResponseHeaders();
- if (headers &&
- data_reduction_proxy::IsLitePagePreview(*headers)) {
- PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(),
+ if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) {
+ PreviewsInfoBarDelegate::Create(web_contents(),
PreviewsInfoBarDelegate::LITE_PAGE);
}
}
« no previous file with comments | « chrome/browser/previews/previews_infobar_tab_helper.h ('k') | chrome/browser/previews/previews_infobar_tab_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698