Commit 57639811 authored by Aaron Tagliaboschi's avatar Aaron Tagliaboschi Committed by Commit Bot

[client hints] Remove explicit lifetimes behind FeaturePolicyForClientHints flag

Adding changes to client hint lifetimes <https://github.com/httpwg/http-extensions/commit/7d24ea40f02ba791c13e5fd70d6932079abf14cf>
under the client hint feature policy flag.

Bug: 1017166
Change-Id: Ia4d63777c4a4fcb150d4e854312851105fa0a11b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919953Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Aaron Tagliaboschi <aarontag@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719162}
parent 2812e863
...@@ -1765,9 +1765,8 @@ void DocumentLoader::ParseAndPersistClientHints( ...@@ -1765,9 +1765,8 @@ void DocumentLoader::ParseAndPersistClientHints(
const ResourceResponse& response) { const ResourceResponse& response) {
const KURL& url = response.CurrentRequestUrl(); const KURL& url = response.CurrentRequestUrl();
// The accept-ch-lifetime header is honored only on the navigation responses // The accept-ch header is honored only on the navigation responses from a top
// from a top level frame or with an origin matching the origin of the top // level frame or with an origin matching the origin of the to level frame.
// level frame.
if (!frame_->IsMainFrame()) { if (!frame_->IsMainFrame()) {
bool is_first_party_origin = bool is_first_party_origin =
frame_->Tree() frame_->Tree()
...@@ -1779,15 +1778,31 @@ void DocumentLoader::ParseAndPersistClientHints( ...@@ -1779,15 +1778,31 @@ void DocumentLoader::ParseAndPersistClientHints(
return; return;
} }
if (!response.HttpHeaderFields().Contains(http_names::kAcceptCH))
return;
FrameClientHintsPreferencesContext hints_context(GetFrame()); FrameClientHintsPreferencesContext hints_context(GetFrame());
// TODO(crbug.com/1017166): Kill ACHL header completely once feature ships.
client_hints_preferences_.UpdateFromAcceptClientHintsLifetimeHeader( client_hints_preferences_.UpdateFromAcceptClientHintsLifetimeHeader(
response.HttpHeaderField(http_names::kAcceptCHLifetime), url, response.HttpHeaderField(http_names::kAcceptCHLifetime), url,
&hints_context); &hints_context);
client_hints_preferences_.UpdateFromAcceptClientHintsHeader( client_hints_preferences_.UpdateFromAcceptClientHintsHeader(
response.HttpHeaderField(http_names::kAcceptCH), url, &hints_context); response.HttpHeaderField(http_names::kAcceptCH), url, &hints_context);
base::TimeDelta persist_duration;
// If the FeaturePolicyForClientHints feature is enabled, the lifetime
// should not expire. Setting the duration to "max" should essentially
// do the same thing.
if (RuntimeEnabledFeatures::FeaturePolicyForClientHintsEnabled()) {
persist_duration = base::TimeDelta::Max();
} else {
persist_duration = client_hints_preferences_.GetPersistDuration();
}
// Notify content settings client of persistent client hints. // Notify content settings client of persistent client hints.
if (client_hints_preferences_.GetPersistDuration().InSeconds() <= 0) if (persist_duration.InSeconds() <= 0)
return; return;
auto* settings_client = frame_->GetContentSettingsClient(); auto* settings_client = frame_->GetContentSettingsClient();
...@@ -1799,8 +1814,8 @@ void DocumentLoader::ParseAndPersistClientHints( ...@@ -1799,8 +1814,8 @@ void DocumentLoader::ParseAndPersistClientHints(
if (!settings_client->AllowScriptFromSource(allow_script, url)) if (!settings_client->AllowScriptFromSource(allow_script, url))
return; return;
settings_client->PersistClientHints( settings_client->PersistClientHints(
client_hints_preferences_.GetWebEnabledClientHints(), client_hints_preferences_.GetWebEnabledClientHints(), persist_duration,
client_hints_preferences_.GetPersistDuration(), url); url);
} }
void DocumentLoader::InitializePrefetchedSignedExchangeManager() { void DocumentLoader::InitializePrefetchedSignedExchangeManager() {
......
...@@ -57,8 +57,14 @@ bool AllowScriptFromSourceWithoutNotifying( ...@@ -57,8 +57,14 @@ bool AllowScriptFromSourceWithoutNotifying(
// Notifies content settings client of persistent client hint headers. // Notifies content settings client of persistent client hint headers.
void NotifyPersistentClientHintsToContentSettingsClient(Document& document) { void NotifyPersistentClientHintsToContentSettingsClient(Document& document) {
base::TimeDelta persist_duration = base::TimeDelta persist_duration;
if (RuntimeEnabledFeatures::FeaturePolicyForClientHintsEnabled()) {
persist_duration = base::TimeDelta::Max();
} else {
persist_duration =
document.GetFrame()->GetClientHintsPreferences().GetPersistDuration(); document.GetFrame()->GetClientHintsPreferences().GetPersistDuration();
}
if (persist_duration.InSeconds() <= 0) if (persist_duration.InSeconds() <= 0)
return; return;
...@@ -167,6 +173,9 @@ void HttpEquiv::ProcessHttpEquivAcceptCHLifetime(Document& document, ...@@ -167,6 +173,9 @@ void HttpEquiv::ProcessHttpEquivAcceptCHLifetime(Document& document,
if (!frame) if (!frame)
return; return;
if (RuntimeEnabledFeatures::FeaturePolicyForClientHintsEnabled())
return;
UseCounter::Count(document, WebFeature::kClientHintsMetaAcceptCHLifetime); UseCounter::Count(document, WebFeature::kClientHintsMetaAcceptCHLifetime);
FrameClientHintsPreferencesContext hints_context(frame); FrameClientHintsPreferencesContext hints_context(frame);
frame->GetClientHintsPreferences().UpdateFromAcceptClientHintsLifetimeHeader( frame->GetClientHintsPreferences().UpdateFromAcceptClientHintsLifetimeHeader(
......
...@@ -12,16 +12,14 @@ in this web page, and two in the other web pages. ...@@ -12,16 +12,14 @@ in this web page, and two in the other web pages.
<script> <script>
// This test fetches resources/accept_ch.html. The response headers to // This test fetches resources/accept_ch.html. The response headers to
// that webpage contains only the Accept-CH header. Due to the missing // that webpage contains only the Accept-CH header. These preferences should be
// Accept-CH-Lifetime header, the user-agent should not persist origin // stored so that the next request to the same origin is sent with the
// preferences for the client hints specified in Accept-CH header. // requested client hint headers.
// Next, to verify that the origin preferences were not persisted by the user // Next, to verify that the origin preferences were persisted by the user
// agent, this test fetches resources/do_not_expect_client_hints_headers.html // agent, this test fetches resources/expect_client_hints_headers.html in a new
// in a new window. Fetching of // window. Fetching of resources/expect_client_hints_headers.html verifies that
// resources/do_not_expect_client_hints_headers.html // the user agent does send the client hints in the request headers.
// verifies that the user agent does not send the client hints in the request
// headers.
// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726 // Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
// is resolved. // is resolved.
...@@ -39,7 +37,7 @@ promise_test(t => { ...@@ -39,7 +37,7 @@ promise_test(t => {
async_test(t => { async_test(t => {
window.addEventListener('message', t.step_func(function(e) { window.addEventListener('message', t.step_func(function(e) {
if(!e.source.location.pathname.includes("do_not_expect_client_hints_headers.html")) { if(!e.source.location.pathname.includes("expect_client_hints_headers.html")) {
return; return;
} }
if(typeof e.data != "string") if(typeof e.data != "string")
...@@ -47,12 +45,12 @@ async_test(t => { ...@@ -47,12 +45,12 @@ async_test(t => {
assert_equals(e.data, "PASS"); assert_equals(e.data, "PASS");
t.done(); t.done();
})); }));
}, "Loading of resources/do_not_expect_client_hints_headers.html did not finish."); }, "Loading of resources/expect_client_hints_headers.html did not finish.");
function acceptChLoaded() { function acceptChLoaded() {
// Open a new window. Verify that the user agent does not attach the client // Open a new window. Verify that the user agent does not attach the client
// hints. // hints.
var verify_win = window.open("resources/do_not_expect_client_hints_headers.html"); var verify_win = window.open("resources/expect_client_hints_headers.html");
assert_not_equals(verify_win, null, "Popup windows not allowed?"); assert_not_equals(verify_win, null, "Popup windows not allowed?");
} }
......
...@@ -12,16 +12,15 @@ ...@@ -12,16 +12,15 @@
<script> <script>
// This test contains accept-ch http-equiv header. Due to the missing // This test contains accept-ch http-equiv header. The user-agent should
// Accept-CH-Lifetime header, the user-agent should not persist origin // persist origin preferences for the client hints specified in Accept-CH
// preferences for the client hints specified in Accept-CH header. // header.
// Next, to verify that the origin preferences were not persisted by the user // Next, to verify that the origin preferences were persisted by the user
// agent, this test fetches resources/do_not_expect_client_hints_headers.html // agent, this test fetches resources/do_not_expect_client_hints_headers.html
// in a new window. Fetching of // in a new window. Fetching of
// resources/do_not_expect_client_hints_headers.html // resources/do_not_expect_client_hints_headers.html verifies that the user
// verifies that the user agent does not send the client hints in the request // agent does not send the client hints in the request headers.
// headers.
// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726 // Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
// is resolved. // is resolved.
...@@ -37,12 +36,12 @@ promise_test(t => { ...@@ -37,12 +36,12 @@ promise_test(t => {
// Verify that the browser does not attach client hints on resources in a // Verify that the browser does not attach client hints on resources in a
// different navigation. This verifies that the client hint preferences were // different navigation. This verifies that the client hint preferences were
// not persisted for the origin. // not persisted for the origin.
window.open("resources/do_not_expect_client_hints_headers.html"); window.open("resources/expect_client_hints_headers.html");
async_test(t => { async_test(t => {
window.addEventListener('message', t.step_func_done(e => { window.addEventListener('message', t.step_func_done(e => {
assert_equals(e.data, 'PASS'); assert_equals(e.data, 'PASS');
})); }));
}, "Loading of resources/do_not_expect_client_hints_headers.html did not finish."); }, "Loading of resources/expect_client_hints_headers.html did not finish.");
</script> </script>
</body> </body>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment