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/loader/chrome_navigation_data.h" |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); | 51 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PreviewsInfoBarTabHelper); |
52 | 52 |
53 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() { | 53 PreviewsInfoBarTabHelper::~PreviewsInfoBarTabHelper() { |
54 ClearLastNavigationAsync(); | 54 ClearLastNavigationAsync(); |
55 } | 55 } |
56 | 56 |
57 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( | 57 PreviewsInfoBarTabHelper::PreviewsInfoBarTabHelper( |
58 content::WebContents* web_contents) | 58 content::WebContents* web_contents) |
59 : content::WebContentsObserver(web_contents), | 59 : content::WebContentsObserver(web_contents), |
60 browser_context_(web_contents->GetBrowserContext()), | 60 browser_context_(web_contents->GetBrowserContext()), |
61 displayed_preview_infobar_(false) { | 61 displayed_preview_infobar_(false), |
62 displayed_preview_timestamp_(false) { | |
62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
63 } | 64 } |
64 | 65 |
65 void PreviewsInfoBarTabHelper::DidFinishNavigation( | 66 void PreviewsInfoBarTabHelper::DidFinishNavigation( |
66 content::NavigationHandle* navigation_handle) { | 67 content::NavigationHandle* navigation_handle) { |
67 // Only show the infobar if this is a full main frame navigation. | 68 // Only show the infobar if this is a full main frame navigation. |
68 if (!navigation_handle->IsInMainFrame() || | 69 if (!navigation_handle->IsInMainFrame() || |
69 !navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) | 70 !navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) |
70 return; | 71 return; |
72 // The infobar should only be told if the page was a reload if the previous | |
73 // page displayed a timestamp. | |
74 bool is_reload = | |
75 displayed_preview_timestamp_ | |
76 ? navigation_handle->GetReloadType() != content::ReloadType::NONE | |
77 : false; | |
71 displayed_preview_infobar_ = false; | 78 displayed_preview_infobar_ = false; |
79 displayed_preview_timestamp_ = false; | |
tbansal1
2017/06/23 23:13:31
What happens if the page is reloaded more than onc
megjablon
2017/06/23 23:39:24
With your comment in previews_infobar_delegate.cc,
| |
72 ClearLastNavigationAsync(); | 80 ClearLastNavigationAsync(); |
73 committed_data_saver_navigation_id_.reset(); | 81 committed_data_saver_navigation_id_.reset(); |
74 | 82 |
75 // As documented in content/public/browser/navigation_handle.h, this | 83 // As documented in content/public/browser/navigation_handle.h, this |
76 // NavigationData is a clone of the NavigationData instance returned from | 84 // NavigationData is a clone of the NavigationData instance returned from |
77 // ResourceDispatcherHostDelegate::GetNavigationData during commit. | 85 // ResourceDispatcherHostDelegate::GetNavigationData during commit. |
78 // Because ChromeResourceDispatcherHostDelegate always returns a | 86 // Because ChromeResourceDispatcherHostDelegate always returns a |
79 // ChromeNavigationData, it is safe to static_cast here. | 87 // ChromeNavigationData, it is safe to static_cast here. |
80 ChromeNavigationData* chrome_navigation_data = | 88 ChromeNavigationData* chrome_navigation_data = |
81 static_cast<ChromeNavigationData*>( | 89 static_cast<ChromeNavigationData*>( |
(...skipping 16 matching lines...) Expand all Loading... | |
98 if (navigation_handle->IsErrorPage()) { | 106 if (navigation_handle->IsErrorPage()) { |
99 // TODO(ryansturm): Add UMA for errors. | 107 // TODO(ryansturm): Add UMA for errors. |
100 return; | 108 return; |
101 } | 109 } |
102 data_reduction_proxy::DataReductionProxySettings* | 110 data_reduction_proxy::DataReductionProxySettings* |
103 data_reduction_proxy_settings = | 111 data_reduction_proxy_settings = |
104 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 112 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
105 web_contents()->GetBrowserContext()); | 113 web_contents()->GetBrowserContext()); |
106 PreviewsInfoBarDelegate::Create( | 114 PreviewsInfoBarDelegate::Create( |
107 web_contents(), previews::PreviewsType::OFFLINE, | 115 web_contents(), previews::PreviewsType::OFFLINE, |
108 base::Time() /* previews_freshness */, | 116 base::Time() /* previews_freshness */, false /* is_reload */, |
109 data_reduction_proxy_settings && | 117 data_reduction_proxy_settings && |
110 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), | 118 data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
111 base::Bind(&AddPreviewNavigationCallback, browser_context_, | 119 base::Bind(&AddPreviewNavigationCallback, browser_context_, |
112 navigation_handle->GetRedirectChain()[0], | 120 navigation_handle->GetRedirectChain()[0], |
113 previews::PreviewsType::OFFLINE)); | 121 previews::PreviewsType::OFFLINE)); |
114 // 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. |
115 return; | 123 return; |
116 } | 124 } |
117 #endif // defined(OS_ANDROID) | 125 #endif // defined(OS_ANDROID) |
118 | 126 |
119 const net::HttpResponseHeaders* headers = | 127 const net::HttpResponseHeaders* headers = |
120 navigation_handle->GetResponseHeaders(); | 128 navigation_handle->GetResponseHeaders(); |
121 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { | 129 if (headers && data_reduction_proxy::IsLitePagePreview(*headers)) { |
122 base::Time previews_freshness; | 130 base::Time previews_freshness; |
123 headers->GetDateValue(&previews_freshness); | 131 headers->GetDateValue(&previews_freshness); |
124 PreviewsInfoBarDelegate::Create( | 132 PreviewsInfoBarDelegate::Create( |
125 web_contents(), previews::PreviewsType::LITE_PAGE, previews_freshness, | 133 web_contents(), previews::PreviewsType::LITE_PAGE, previews_freshness, |
126 true /* is_data_saver_user */, | 134 true /* is_data_saver_user */, is_reload, |
127 base::Bind(&AddPreviewNavigationCallback, browser_context_, | 135 base::Bind(&AddPreviewNavigationCallback, browser_context_, |
128 navigation_handle->GetRedirectChain()[0], | 136 navigation_handle->GetRedirectChain()[0], |
129 previews::PreviewsType::LITE_PAGE)); | 137 previews::PreviewsType::LITE_PAGE)); |
130 } | 138 } |
131 } | 139 } |
132 | 140 |
133 void PreviewsInfoBarTabHelper::ClearLastNavigationAsync() const { | 141 void PreviewsInfoBarTabHelper::ClearLastNavigationAsync() const { |
134 if (!committed_data_saver_navigation_id_) | 142 if (!committed_data_saver_navigation_id_) |
135 return; | 143 return; |
136 auto* data_reduction_proxy_settings = | 144 auto* data_reduction_proxy_settings = |
137 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 145 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
138 browser_context_); | 146 browser_context_); |
139 if (!data_reduction_proxy_settings || | 147 if (!data_reduction_proxy_settings || |
140 !data_reduction_proxy_settings->data_reduction_proxy_service()) { | 148 !data_reduction_proxy_settings->data_reduction_proxy_service()) { |
141 return; | 149 return; |
142 } | 150 } |
143 data_reduction_proxy_settings->data_reduction_proxy_service() | 151 data_reduction_proxy_settings->data_reduction_proxy_service() |
144 ->pingback_client() | 152 ->pingback_client() |
145 ->ClearNavigationKeyAsync(committed_data_saver_navigation_id_.value()); | 153 ->ClearNavigationKeyAsync(committed_data_saver_navigation_id_.value()); |
146 } | 154 } |
OLD | NEW |