| 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 e91e78d891787f9576690a7f67dee38374c12912..6781202b2470cd9bdce5639ec9983e7cef31c7e0 100644
|
| --- a/chrome/browser/previews/previews_infobar_tab_helper.cc
|
| +++ b/chrome/browser/previews/previews_infobar_tab_helper.cc
|
| @@ -1,49 +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/loader/chrome_navigation_data.h"
|
| #include "chrome/browser/previews/previews_infobar_delegate.h"
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
|
| +#include "components/offline_pages/loaded_offline_page_info.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"
|
|
|
| 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;
|
| +
|
| + ChromeNavigationData* chrome_navigation_data =
|
| + ChromeNavigationData::GetForNavigationHandle(navigation_handle);
|
| + if (chrome_navigation_data) {
|
| + offline_pages::LoadedOfflinePageInfo* info =
|
| + chrome_navigation_data->GetLoadedOfflinePageInfo();
|
| + if (info && info->is_offline_preview()) {
|
| + if (navigation_handle->IsErrorPage()) {
|
| + // TODO(ryansturm): Add UMA for errors.
|
| + return;
|
| + }
|
| + is_showing_offline_preview_ = true;
|
| + PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(),
|
| + PreviewsInfoBarDelegate::OFFLINE);
|
| + // Don't try to show other infobars if this is an offline preview.
|
| + return;
|
| + }
|
| + }
|
| +
|
| const net::HttpResponseHeaders* headers =
|
| navigation_handle->GetResponseHeaders();
|
| if (headers &&
|
| headers->HasHeaderValue(
|
| data_reduction_proxy::chrome_proxy_header(),
|
| data_reduction_proxy::chrome_proxy_lite_page_directive())) {
|
| PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(),
|
| PreviewsInfoBarDelegate::LITE_PAGE);
|
| }
|
| }
|
|
|