OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 5 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "chrome/browser/loader/chrome_navigation_data.h" |
9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
11 #include "chrome/browser/previews/previews_infobar_delegate.h" | 12 #include "chrome/browser/previews/previews_infobar_delegate.h" |
12 #include "chrome/browser/previews/previews_service.h" | 13 #include "chrome/browser/previews/previews_service.h" |
13 #include "chrome/browser/previews/previews_service_factory.h" | 14 #include "chrome/browser/previews/previews_service_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
| 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping
back_client.h" |
| 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
17 #include "components/previews/core/previews_experiments.h" | 21 #include "components/previews/core/previews_experiments.h" |
18 #include "components/previews/core/previews_ui_service.h" | 22 #include "components/previews/core/previews_ui_service.h" |
19 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
20 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
22 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
24 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
(...skipping 17 matching lines...) Expand all Loading... |
42 opt_out); | 46 opt_out); |
43 } | 47 } |
44 } | 48 } |
45 | 49 |
46 } // namespace | 50 } // namespace |
47 | 51 |
48 #endif // defined(OS_ANDROID) | 52 #endif // defined(OS_ANDROID) |
49 | 53 |
50 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); | 54 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); |
51 | 55 |
52 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() {} | 56 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() { |
| 57 auto* data_reduction_proxy_settings = |
| 58 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 59 browser_context_); |
| 60 if (data_reduction_proxy_settings && |
| 61 data_reduction_proxy_settings->data_reduction_proxy_service()) { |
| 62 data_reduction_proxy_settings->data_reduction_proxy_service() |
| 63 ->pingback_client() |
| 64 ->ClearTabKeyAsync(web_contents_); |
| 65 } |
| 66 } |
53 | 67 |
54 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( | 68 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( |
55 content::WebContents* web_contents) | 69 content::WebContents* web_contents) |
56 : content::WebContentsObserver(web_contents), | 70 : content::WebContentsObserver(web_contents), |
57 displayed_preview_infobar_(false){ | 71 browser_context_(web_contents->GetBrowserContext()), |
| 72 web_contents_(web_contents), |
| 73 displayed_preview_infobar_(false) { |
58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
59 } | 75 } |
60 | 76 |
61 void PreviewsInfoBarTabHelper::DidFinishNavigation( | 77 void PreviewsInfoBarTabHelper::DidFinishNavigation( |
62 content::NavigationHandle* navigation_handle) { | 78 content::NavigationHandle* navigation_handle) { |
63 // Only show the infobar if this is a full main frame navigation. | 79 // Only show the infobar if this is a full main frame navigation. |
64 if (!navigation_handle->IsInMainFrame() || | 80 if (!navigation_handle->IsInMainFrame() || |
65 !navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) | 81 !navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) |
66 return; | 82 return; |
67 displayed_preview_infobar_ = false; | 83 displayed_preview_infobar_ = false; |
| 84 committed_data_saver_page_id_.reset(); |
| 85 |
| 86 // As documented in content/public/browser/navigation_handle.h, this |
| 87 // NavigationData is a clone of the NavigationData instance returned from |
| 88 // ResourceDispatcherHostDelegate::GetNavigationData during commit. |
| 89 // Because ChromeResourceDispatcherHostDelegate always returns a |
| 90 // ChromeNavigationData, it is safe to static_cast here. |
| 91 ChromeNavigationData* chrome_navigation_data = |
| 92 static_cast<ChromeNavigationData*>( |
| 93 navigation_handle->GetNavigationData()); |
| 94 if (chrome_navigation_data) { |
| 95 data_reduction_proxy::DataReductionProxyData* data = |
| 96 chrome_navigation_data->GetDataReductionProxyData(); |
| 97 |
| 98 if (data) |
| 99 committed_data_saver_page_id_ = data->page_id(); |
| 100 } |
68 | 101 |
69 #if defined(OS_ANDROID) | 102 #if defined(OS_ANDROID) |
70 offline_pages::OfflinePageTabHelper* tab_helper = | 103 offline_pages::OfflinePageTabHelper* tab_helper = |
71 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); | 104 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents_); |
72 | 105 |
73 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { | 106 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { |
74 if (navigation_handle->IsErrorPage()) { | 107 if (navigation_handle->IsErrorPage()) { |
75 // TODO(ryansturm): Add UMA for errors. | 108 // TODO(ryansturm): Add UMA for errors. |
76 return; | 109 return; |
77 } | 110 } |
78 data_reduction_proxy::DataReductionProxySettings* | 111 data_reduction_proxy::DataReductionProxySettings* |
79 data_reduction_proxy_settings = | 112 data_reduction_proxy_settings = |
80 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 113 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
81 web_contents()->GetBrowserContext()); | 114 browser_context_); |
82 PreviewsInfoBarDelegate::Create( | 115 PreviewsInfoBarDelegate::Create( |
83 web_contents(), PreviewsInfoBarDelegate::OFFLINE, | 116 web_contents_, PreviewsInfoBarDelegate::OFFLINE, |
84 data_reduction_proxy_settings && | 117 data_reduction_proxy_settings && |
85 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), | 118 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
86 base::Bind( | 119 base::Bind(&AddPreviewNavigationCallback, browser_context_, |
87 &AddPreviewNavigationCallback, web_contents()->GetBrowserContext(), | 120 navigation_handle->GetURL(), |
88 navigation_handle->GetURL(), previews::PreviewsType::OFFLINE)); | 121 previews::PreviewsType::OFFLINE)); |
89 // Don't try to show other infobars if this is an offline preview. | 122 // Don't try to show other infobars if this is an offline preview. |
90 return; | 123 return; |
91 } | 124 } |
92 #endif // defined(OS_ANDROID) | 125 #endif // defined(OS_ANDROID) |
93 | 126 |
94 const net::HttpResponseHeaders* headers = | 127 const net::HttpResponseHeaders* headers = |
95 navigation_handle->GetResponseHeaders(); | 128 navigation_handle->GetResponseHeaders(); |
96 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { | 129 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { |
97 PreviewsInfoBarDelegate::Create( | 130 PreviewsInfoBarDelegate::Create( |
98 web_contents(), PreviewsInfoBarDelegate::LITE_PAGE, | 131 web_contents_, PreviewsInfoBarDelegate::LITE_PAGE, |
99 true /* is_data_saver_user */, | 132 true /* is_data_saver_user */, |
100 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 133 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
101 } | 134 } |
102 } | 135 } |
103 | 136 |
OLD | NEW |