| 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 917d3ebfe75f971b74c06c06e12e3d47bda40eee..beaaa92386d3b25bdd826abc7bea4492f3e61c62 100644
|
| --- a/chrome/browser/previews/previews_infobar_tab_helper.cc
|
| +++ b/chrome/browser/previews/previews_infobar_tab_helper.cc
|
| @@ -6,12 +6,16 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| +#include "chrome/browser/loader/chrome_navigation_data.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/browser/previews/previews_infobar_delegate.h"
|
| #include "chrome/browser/previews/previews_service.h"
|
| #include "chrome/browser/previews/previews_service_factory.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
|
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.h"
|
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
|
| #include "components/previews/core/previews_experiments.h"
|
| @@ -49,12 +53,24 @@ void AddPreviewNavigationCallback(content::BrowserContext* browser_context,
|
|
|
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper);
|
|
|
| -PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {}
|
| +PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {
|
| + auto* data_reduction_proxy_settings =
|
| + DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
|
| + browser_context_);
|
| + if (data_reduction_proxy_settings &&
|
| + data_reduction_proxy_settings->data_reduction_proxy_service()) {
|
| + data_reduction_proxy_settings->data_reduction_proxy_service()
|
| + ->pingback_client()
|
| + ->ClearTabKeyAsync(web_contents_);
|
| + }
|
| +}
|
|
|
| PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper(
|
| content::WebContents* web_contents)
|
| : content::WebContentsObserver(web_contents),
|
| - displayed_preview_infobar_(false){
|
| + browser_context_(web_contents->GetBrowserContext()),
|
| + web_contents_(web_contents),
|
| + displayed_preview_infobar_(false) {
|
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| }
|
|
|
| @@ -65,10 +81,27 @@ void PreviewsInfoBarTabHelper::DidFinishNavigation(
|
| !navigation_handle->HasCommitted() || navigation_handle->IsSameDocument())
|
| return;
|
| displayed_preview_infobar_ = false;
|
| + committed_data_saver_page_id_.reset();
|
| +
|
| + // As documented in content/public/browser/navigation_handle.h, this
|
| + // NavigationData is a clone of the NavigationData instance returned from
|
| + // ResourceDispatcherHostDelegate::GetNavigationData during commit.
|
| + // Because ChromeResourceDispatcherHostDelegate always returns a
|
| + // ChromeNavigationData, it is safe to static_cast here.
|
| + ChromeNavigationData* chrome_navigation_data =
|
| + static_cast<ChromeNavigationData*>(
|
| + navigation_handle->GetNavigationData());
|
| + if (chrome_navigation_data) {
|
| + data_reduction_proxy::DataReductionProxyData* data =
|
| + chrome_navigation_data->GetDataReductionProxyData();
|
| +
|
| + if (data)
|
| + committed_data_saver_page_id_ = data->page_id();
|
| + }
|
|
|
| #if defined(OS_ANDROID)
|
| offline_pages::OfflinePageTabHelper* tab_helper =
|
| - offline_pages::OfflinePageTabHelper::FromWebContents(web_contents());
|
| + offline_pages::OfflinePageTabHelper::FromWebContents(web_contents_);
|
|
|
| if (tab_helper && tab_helper->IsShowingOfflinePreview()) {
|
| if (navigation_handle->IsErrorPage()) {
|
| @@ -78,14 +111,14 @@ void PreviewsInfoBarTabHelper::DidFinishNavigation(
|
| data_reduction_proxy::DataReductionProxySettings*
|
| data_reduction_proxy_settings =
|
| DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
|
| - web_contents()->GetBrowserContext());
|
| + browser_context_);
|
| PreviewsInfoBarDelegate::Create(
|
| - web_contents(), PreviewsInfoBarDelegate::OFFLINE,
|
| + web_contents_, PreviewsInfoBarDelegate::OFFLINE,
|
| data_reduction_proxy_settings &&
|
| data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
|
| - base::Bind(
|
| - &AddPreviewNavigationCallback, web_contents()->GetBrowserContext(),
|
| - navigation_handle->GetURL(), previews::PreviewsType::OFFLINE));
|
| + base::Bind(&AddPreviewNavigationCallback, browser_context_,
|
| + navigation_handle->GetURL(),
|
| + previews::PreviewsType::OFFLINE));
|
| // Don't try to show other infobars if this is an offline preview.
|
| return;
|
| }
|
| @@ -95,7 +128,7 @@ void PreviewsInfoBarTabHelper::DidFinishNavigation(
|
| navigation_handle->GetResponseHeaders();
|
| if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) {
|
| PreviewsInfoBarDelegate::Create(
|
| - web_contents(), PreviewsInfoBarDelegate::LITE_PAGE,
|
| + web_contents_, PreviewsInfoBarDelegate::LITE_PAGE,
|
| true /* is_data_saver_user */,
|
| PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
|
| }
|
|
|