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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c8c8daf68ca7c6c05ca922487333ee3d9e17d2df |
--- /dev/null |
+++ b/chrome/browser/previews/previews_infobar_tab_helper.cc |
@@ -0,0 +1,50 @@ |
+// 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 "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" |
+ |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); |
+ |
+PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} |
+ |
+PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( |
+ content::WebContents* web_contents) |
+ : content::WebContentsObserver(web_contents), |
+ displayed_preview_infobar_(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()) |
+ 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); |
+ } |
+} |
+ |