Chromium Code Reviews| 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 c8c8daf68ca7c6c05ca922487333ee3d9e17d2df..efba7304251e9c71f8f665ad1a253d280110560a 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()) |
| + // Do nothing if this is not a full main frame navigation. |
|
megjablon
2016/10/07 22:48:33
Suggestion: Rather than the double negative
// Onl
RyanSturm
2016/10/07 23:05:48
Done.
|
| + if (!navigation_handle->IsInMainFrame() || |
| + !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) |
|
megjablon
2016/10/07 22:48:33
Does a refresh count as same page?
RyanSturm
2016/10/07 23:05:48
This checks for fragment navigations (i.e. links t
megjablon
2016/10/10 22:25:13
Ok cool.
|
| 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_lo_fi_preview_directive())) { |
| PreviewsInfoBarDelegate::Create(navigation_handle->GetWebContents(), |
| PreviewsInfoBarDelegate::LITE_PAGE); |
| } |
| } |