diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-11-28 16:14:41 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-12-13 15:19:41 +0000 |
commit | 61d9742824d54be5693191fe502325a909feca59 (patch) | |
tree | cbf28e779b11338fe52eb75b915684cd8955542c /chromium/net/base | |
parent | 45f9ded08bb7526984b24ccb5a5327aaf6821676 (diff) | |
download | qtwebengine-chromium-61d9742824d54be5693191fe502325a909feca59.tar.gz |
BASELINE: Update Chromium to 108.0.5359.70
Change-Id: I77334ff232b819600f275bd3cfe41fbaa3619230
Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/445904
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/net/base')
285 files changed, 3086 insertions, 1219 deletions
diff --git a/chromium/net/base/BUILD.gn b/chromium/net/base/BUILD.gn index 5c005ab659a..315f921ed4b 100644 --- a/chromium/net/base/BUILD.gn +++ b/chromium/net/base/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2022 The Chromium Authors. All rights reserved. +# Copyright 2022 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/net/base/DEPS b/chromium/net/base/DEPS index fac79a66f61..54ab40cde0e 100644 --- a/chromium/net/base/DEPS +++ b/chromium/net/base/DEPS @@ -1,3 +1,9 @@ include_rules = [ "+grit", # For generated headers ] + +specific_include_rules = { + "platform_mime_util_linux\.cc": [ + "+third_party/xdg_shared_mime_info", + ] +} diff --git a/chromium/net/base/address_family.cc b/chromium/net/base/address_family.cc index dbc72262327..3c745ac81e7 100644 --- a/chromium/net/base/address_family.cc +++ b/chromium/net/base/address_family.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_family.h b/chromium/net/base/address_family.h index 856792caa85..be4310e3baa 100644 --- a/chromium/net/base/address_family.h +++ b/chromium/net/base/address_family.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright 2010 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_family_unittest.cc b/chromium/net/base/address_family_unittest.cc index 8248c87a34e..5880a049cc1 100644 --- a/chromium/net/base/address_family_unittest.cc +++ b/chromium/net/base/address_family_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_list.cc b/chromium/net/base/address_list.cc index 95304b0dfec..74850b5f7cf 100644 --- a/chromium/net/base/address_list.cc +++ b/chromium/net/base/address_list.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_list.h b/chromium/net/base/address_list.h index a93093e41f3..589d605f2f6 100644 --- a/chromium/net/base/address_list.h +++ b/chromium/net/base/address_list.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_list_unittest.cc b/chromium/net/base/address_list_unittest.cc index d6f29346656..1b5945b6086 100644 --- a/chromium/net/base/address_list_unittest.cc +++ b/chromium/net/base/address_list_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_tracker_linux.cc b/chromium/net/base/address_tracker_linux.cc index d1a77c6d3ed..242f40f543d 100644 --- a/chromium/net/base/address_tracker_linux.cc +++ b/chromium/net/base/address_tracker_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_tracker_linux.h b/chromium/net/base/address_tracker_linux.h index c2d4ea8c7ce..4398c5880ad 100644 --- a/chromium/net/base/address_tracker_linux.h +++ b/chromium/net/base/address_tracker_linux.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_tracker_linux_fuzzer.cc b/chromium/net/base/address_tracker_linux_fuzzer.cc index 124cf3298b5..26119059d26 100644 --- a/chromium/net/base/address_tracker_linux_fuzzer.cc +++ b/chromium/net/base/address_tracker_linux_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/address_tracker_linux_unittest.cc b/chromium/net/base/address_tracker_linux_unittest.cc index 83f8051b063..93a28623912 100644 --- a/chromium/net/base/address_tracker_linux_unittest.cc +++ b/chromium/net/base/address_tracker_linux_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/android/java_templates/NetFeatures.java.tmpl b/chromium/net/base/android/java_templates/NetFeatures.java.tmpl index d3d8899f2eb..fe11c0b9a64 100644 --- a/chromium/net/base/android/java_templates/NetFeatures.java.tmpl +++ b/chromium/net/base/android/java_templates/NetFeatures.java.tmpl @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/auth.cc b/chromium/net/base/auth.cc index 9f27cdd3e76..e915de6b7e7 100644 --- a/chromium/net/base/auth.cc +++ b/chromium/net/base/auth.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/auth.h b/chromium/net/base/auth.h index 6bf763475ca..e80006ee9ac 100644 --- a/chromium/net/base/auth.h +++ b/chromium/net/base/auth.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/backoff_entry.cc b/chromium/net/base/backoff_entry.cc index 400a4052712..fc47925e450 100644 --- a/chromium/net/base/backoff_entry.cc +++ b/chromium/net/base/backoff_entry.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/backoff_entry.h b/chromium/net/base/backoff_entry.h index f4754449e29..45f92a6975e 100644 --- a/chromium/net/base/backoff_entry.h +++ b/chromium/net/base/backoff_entry.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/backoff_entry_serializer.cc b/chromium/net/base/backoff_entry_serializer.cc index 2a65462e551..932c204c0f9 100644 --- a/chromium/net/base/backoff_entry_serializer.cc +++ b/chromium/net/base/backoff_entry_serializer.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,7 +15,7 @@ namespace { // This max defines how many times we are willing to call -// |BackoffEntry::InformOfRequest| in |DeserializeFromValue|. +// |BackoffEntry::InformOfRequest| in |DeserializeFromList|. // // This value is meant to large enough that the computed backoff duration can // still be saturated. Given that the duration is an int64 and assuming 1.01 as @@ -34,8 +34,9 @@ bool BackoffDurationSafeToSerialize(const base::TimeDelta& duration) { namespace net { -base::Value BackoffEntrySerializer::SerializeToValue(const BackoffEntry& entry, - base::Time time_now) { +base::Value::List BackoffEntrySerializer::SerializeToList( + const BackoffEntry& entry, + base::Time time_now) { base::Value::List serialized; serialized.Append(SerializationFormatVersion::kVersion2); @@ -68,7 +69,7 @@ base::Value BackoffEntrySerializer::SerializeToValue(const BackoffEntry& entry, serialized.Append( base::NumberToString(absolute_release_time.ToInternalValue())); - return base::Value(std::move(serialized)); + return serialized; } std::unique_ptr<BackoffEntry> BackoffEntrySerializer::DeserializeFromList( @@ -171,15 +172,4 @@ std::unique_ptr<BackoffEntry> BackoffEntrySerializer::DeserializeFromList( return entry; } -std::unique_ptr<BackoffEntry> BackoffEntrySerializer::DeserializeFromValue( - const base::Value& serialized, - const BackoffEntry::Policy* policy, - const base::TickClock* tick_clock, - base::Time time_now) { - if (!serialized.is_list()) - return nullptr; - return DeserializeFromList(serialized.GetList(), policy, tick_clock, - time_now); -} - } // namespace net diff --git a/chromium/net/base/backoff_entry_serializer.h b/chromium/net/base/backoff_entry_serializer.h index 6a35545981c..4835afa1899 100644 --- a/chromium/net/base/backoff_entry_serializer.h +++ b/chromium/net/base/backoff_entry_serializer.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,7 +31,7 @@ class NET_EXPORT BackoffEntrySerializer { BackoffEntrySerializer(const BackoffEntrySerializer&) = delete; BackoffEntrySerializer& operator=(const BackoffEntrySerializer&) = delete; - // Serializes the release time and failure count into a Value that can + // Serializes the release time and failure count into a List that can // later be passed to Deserialize to re-create the given BackoffEntry. It // always serializes using the latest format version. The Policy is not // serialized, instead callers must pass an identical Policy* when @@ -40,8 +40,8 @@ class NET_EXPORT BackoffEntrySerializer { // converted to an absolute timestamp, thus the time will continue counting // down even whilst the device is powered off, and will be partially // vulnerable to changes in the system clock time. - static base::Value SerializeToValue(const BackoffEntry& entry, - base::Time time_now); + static base::Value::List SerializeToList(const BackoffEntry& entry, + base::Time time_now); // Deserializes a `list` back to a BackoffEntry. It supports all // serialization format versions. `policy` MUST be the same Policy as the @@ -56,16 +56,6 @@ class NET_EXPORT BackoffEntrySerializer { const BackoffEntry::Policy* policy, const base::TickClock* clock, base::Time time_now); - - // Same as `DeserializeFromList` if `serialized` is a list. - // Returns `nullptr` otherwise. - // TODO(https://crbug.com/1352136) migrated call sites to - // DeserializeFromList and remove DeserializeFromValue. - static std::unique_ptr<BackoffEntry> DeserializeFromValue( - const base::Value& serialized, - const BackoffEntry::Policy* policy, - const base::TickClock* clock, - base::Time time_now); }; } // namespace net diff --git a/chromium/net/base/backoff_entry_serializer_fuzzer.cc b/chromium/net/base/backoff_entry_serializer_fuzzer.cc index 04a3d1f5b2b..f08d3d58aa7 100644 --- a/chromium/net/base/backoff_entry_serializer_fuzzer.cc +++ b/chromium/net/base/backoff_entry_serializer_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -99,21 +99,21 @@ void TestDeserialize(const ProtoTranslator& translator) { // Attempt to deserialize a BackoffEntry. std::unique_ptr<BackoffEntry> entry = - BackoffEntrySerializer::DeserializeFromValue(*value, &policy, &clock, - translator.parse_time()); + BackoffEntrySerializer::DeserializeFromList( + value->GetList(), &policy, &clock, translator.parse_time()); if (!entry) return; - base::Value reserialized = - BackoffEntrySerializer::SerializeToValue(*entry, translator.parse_time()); + base::Value::List reserialized = + BackoffEntrySerializer::SerializeToList(*entry, translator.parse_time()); // Due to fuzzy interpretation in BackoffEntrySerializer:: - // DeserializeFromValue, we cannot assert that |*reserialized == *value|. + // DeserializeFromList, we cannot assert that |*reserialized == *value|. // Rather, we can deserialize |reserialized| and check that some weaker // properties are preserved. std::unique_ptr<BackoffEntry> entry_reparsed = - BackoffEntrySerializer::DeserializeFromValue( - reserialized, &policy, &clock, translator.parse_time()); + BackoffEntrySerializer::DeserializeFromList(reserialized, &policy, &clock, + translator.parse_time()); CHECK(entry_reparsed); CHECK_EQ(entry_reparsed->failure_count(), entry->failure_count()); CHECK_LE(entry_reparsed->GetReleaseTime(), entry->GetReleaseTime()); @@ -128,18 +128,17 @@ void TestSerialize(const ProtoTranslator& translator) { // Serialize the BackoffEntry. BackoffEntry native_entry(&policy); - base::Value serialized = BackoffEntrySerializer::SerializeToValue( + base::Value::List serialized = BackoffEntrySerializer::SerializeToList( native_entry, translator.serialize_time()); - CHECK(serialized.is_list()); MockClock clock; clock.SetNow(translator.now_ticks()); // Deserialize it. std::unique_ptr<BackoffEntry> deserialized_entry = - BackoffEntrySerializer::DeserializeFromValue(serialized, &policy, &clock, - translator.parse_time()); - // Even though SerializeToValue was successful, we're not guaranteed to have a + BackoffEntrySerializer::DeserializeFromList(serialized, &policy, &clock, + translator.parse_time()); + // Even though SerializeToList was successful, we're not guaranteed to have a // |deserialized_entry|. One reason deserialization may fail is if the parsed // |absolute_release_time_us| is below zero. if (!deserialized_entry) diff --git a/chromium/net/base/backoff_entry_serializer_fuzzer_input.proto b/chromium/net/base/backoff_entry_serializer_fuzzer_input.proto index 06cb247dd2a..58c9e6064ec 100644 --- a/chromium/net/base/backoff_entry_serializer_fuzzer_input.proto +++ b/chromium/net/base/backoff_entry_serializer_fuzzer_input.proto @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/backoff_entry_serializer_unittest.cc b/chromium/net/base/backoff_entry_serializer_unittest.cc index 5bcb3ebea5b..0bb8e0ba629 100644 --- a/chromium/net/base/backoff_entry_serializer_unittest.cc +++ b/chromium/net/base/backoff_entry_serializer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -25,13 +25,13 @@ const Time kParseTime = Time::FromJsTime(1430907555111); // May 2015 for realism BackoffEntry::Policy base_policy = { - 0 /* num_errors_to_ignore */, - 1000 /* initial_delay_ms */, - 2.0 /* multiply_factor */, - 0.0 /* jitter_factor */, - 20000 /* maximum_backoff_ms */, - 2000 /* entry_lifetime_ms */, - false /* always_use_initial_delay */ + 0 /* num_errors_to_ignore */, + 1000 /* initial_delay_ms */, + 2.0 /* multiply_factor */, + 0.0 /* jitter_factor */, + 20000 /* maximum_backoff_ms */, + 2000 /* entry_lifetime_ms */, + false /* always_use_initial_delay */ }; class TestTickClock : public base::TickClock { @@ -49,10 +49,10 @@ class TestTickClock : public base::TickClock { }; // This test exercises the code that computes the "backoff duration" and tests -// BackoffEntrySerializer::SerializeToValue computes the backoff duration of a +// BackoffEntrySerializer::SerializeToList computes the backoff duration of a // BackoffEntry by subtracting two base::TimeTicks values. Note that // base::TimeTicks::operator- does not protect against overflow. Because -// SerializeToValue never returns null, its resolution strategy is to default to +// SerializeToList never returns null, its resolution strategy is to default to // a zero base::TimeDelta when the subtraction would overflow. TEST(BackoffEntrySerializerTest, SpecialCasesOfBackoffDuration) { const base::TimeTicks kZeroTicks; @@ -136,12 +136,12 @@ TEST(BackoffEntrySerializerTest, SpecialCasesOfBackoffDuration) { BackoffEntry original(&base_policy, &original_ticks); // Set the custom release time. original.SetCustomReleaseTime(test_case.release_time); - base::Value serialized = - BackoffEntrySerializer::SerializeToValue(original, original_time); + base::Value::List serialized = + BackoffEntrySerializer::SerializeToList(original, original_time); // Check that the serialized backoff duration matches our expectation. const std::string& serialized_backoff_duration_string = - serialized.GetList()[2].GetString(); + serialized[2].GetString(); int64_t serialized_backoff_duration_us; EXPECT_TRUE(base::StringToInt64(serialized_backoff_duration_string, &serialized_backoff_duration_us)); @@ -152,7 +152,7 @@ TEST(BackoffEntrySerializerTest, SpecialCasesOfBackoffDuration) { } } -// This test verifies that BackoffEntrySerializer::SerializeToValue will not +// This test verifies that BackoffEntrySerializer::SerializeToList will not // serialize an infinite release time. // // In pseudocode, this is how absolute_release_time is computed: @@ -169,19 +169,18 @@ TEST(BackoffEntrySerializerTest, SerializeFiniteReleaseTime) { original_ticks.set_now(TimeTicks()); BackoffEntry original(&base_policy, &original_ticks); original.SetCustomReleaseTime(release_time); - base::Value serialized = - BackoffEntrySerializer::SerializeToValue(original, original_time); + base::Value::List serialized = + BackoffEntrySerializer::SerializeToList(original, original_time); // Reach into the serialization and check the string-formatted release time. - const std::string& serialized_release_time = - serialized.GetList()[3].GetString(); + const std::string& serialized_release_time = serialized[3].GetString(); EXPECT_EQ(serialized_release_time, "0"); - // Test that |DeserializeFromValue| notices this zero-valued release time and + // Test that |DeserializeFromList| notices this zero-valued release time and // does not take it at face value. std::unique_ptr<BackoffEntry> deserialized = - BackoffEntrySerializer::DeserializeFromValue(serialized, &base_policy, - &original_ticks, kParseTime); + BackoffEntrySerializer::DeserializeFromList(serialized, &base_policy, + &original_ticks, kParseTime); ASSERT_TRUE(deserialized.get()); EXPECT_EQ(original.GetReleaseTime(), deserialized->GetReleaseTime()); } @@ -191,11 +190,11 @@ TEST(BackoffEntrySerializerTest, SerializeNoFailures) { TestTickClock original_ticks; original_ticks.set_now(TimeTicks::Now()); BackoffEntry original(&base_policy, &original_ticks); - base::Value serialized = - BackoffEntrySerializer::SerializeToValue(original, original_time); + base::Value::List serialized = + BackoffEntrySerializer::SerializeToList(original, original_time); std::unique_ptr<BackoffEntry> deserialized = - BackoffEntrySerializer::DeserializeFromValue( + BackoffEntrySerializer::DeserializeFromList( serialized, &base_policy, &original_ticks, original_time); ASSERT_TRUE(deserialized.get()); EXPECT_EQ(original.failure_count(), deserialized->failure_count()); @@ -218,9 +217,8 @@ TEST(BackoffEntrySerializerTest, DeserializeNeverInfiniteReleaseTime) { base::Time::FromDeltaSinceWindowsEpoch(base::Microseconds(-1)); std::unique_ptr<BackoffEntry> entry = - BackoffEntrySerializer::DeserializeFromValue( - base::Value(std::move(serialized)), &base_policy, &original_ticks, - time_now); + BackoffEntrySerializer::DeserializeFromList(serialized, &base_policy, + &original_ticks, time_now); ASSERT_FALSE(entry); } @@ -231,13 +229,13 @@ TEST(BackoffEntrySerializerTest, SerializeTimeOffsets) { // 2 errors. original.InformOfRequest(false); original.InformOfRequest(false); - base::Value serialized = - BackoffEntrySerializer::SerializeToValue(original, original_time); + base::Value::List serialized = + BackoffEntrySerializer::SerializeToList(original, original_time); { // Test that immediate deserialization round-trips. std::unique_ptr<BackoffEntry> deserialized = - BackoffEntrySerializer::DeserializeFromValue( + BackoffEntrySerializer::DeserializeFromList( serialized, &base_policy, &original_ticks, original_time); ASSERT_TRUE(deserialized.get()); EXPECT_EQ(original.failure_count(), deserialized->failure_count()); @@ -249,7 +247,7 @@ TEST(BackoffEntrySerializerTest, SerializeTimeOffsets) { // hasn't (e.g. device was rebooted). Time later_time = original_time + base::Days(1); std::unique_ptr<BackoffEntry> deserialized = - BackoffEntrySerializer::DeserializeFromValue( + BackoffEntrySerializer::DeserializeFromList( serialized, &base_policy, &original_ticks, later_time); ASSERT_TRUE(deserialized.get()); EXPECT_EQ(original.failure_count(), deserialized->failure_count()); @@ -268,7 +266,7 @@ TEST(BackoffEntrySerializerTest, SerializeTimeOffsets) { TestTickClock later_ticks; later_ticks.set_now(TimeTicks() + base::Days(1)); std::unique_ptr<BackoffEntry> deserialized = - BackoffEntrySerializer::DeserializeFromValue( + BackoffEntrySerializer::DeserializeFromList( serialized, &base_policy, &later_ticks, original_time); ASSERT_TRUE(deserialized.get()); EXPECT_EQ(original.failure_count(), deserialized->failure_count()); @@ -292,8 +290,8 @@ TEST(BackoffEntrySerializerTest, SerializeTimeOffsets) { later_ticks.set_now(TimeTicks() + base::Days(1)); Time later_time = original_time + base::Days(1); std::unique_ptr<BackoffEntry> deserialized = - BackoffEntrySerializer::DeserializeFromValue(serialized, &base_policy, - &later_ticks, later_time); + BackoffEntrySerializer::DeserializeFromList(serialized, &base_policy, + &later_ticks, later_time); ASSERT_TRUE(deserialized.get()); EXPECT_EQ(original.failure_count(), deserialized->failure_count()); // Since both have advanced by the same amount, the absolute release time @@ -310,7 +308,7 @@ TEST(BackoffEntrySerializerTest, SerializeTimeOffsets) { EXPECT_LT(base::Seconds(1), original.GetTimeUntilRelease()); Time earlier_time = original_time - base::Seconds(1); std::unique_ptr<BackoffEntry> deserialized = - BackoffEntrySerializer::DeserializeFromValue( + BackoffEntrySerializer::DeserializeFromList( serialized, &base_policy, &original_ticks, earlier_time); ASSERT_TRUE(deserialized.get()); EXPECT_EQ(original.failure_count(), deserialized->failure_count()); @@ -336,8 +334,8 @@ TEST(BackoffEntrySerializerTest, DeserializeUnknownVersion) { serialized.Append(2.0); // Backoff duration serialized.Append("1234"); // Absolute release time - auto deserialized = BackoffEntrySerializer::DeserializeFromValue( - base::Value(std::move(serialized)), &base_policy, nullptr, kParseTime); + auto deserialized = BackoffEntrySerializer::DeserializeFromList( + serialized, &base_policy, nullptr, kParseTime); ASSERT_FALSE(deserialized); } @@ -348,8 +346,8 @@ TEST(BackoffEntrySerializerTest, DeserializeVersion1) { serialized.Append(2.0); // Backoff duration in seconds as double serialized.Append("1234"); // Absolute release time - auto deserialized = BackoffEntrySerializer::DeserializeFromValue( - base::Value(std::move(serialized)), &base_policy, nullptr, kParseTime); + auto deserialized = BackoffEntrySerializer::DeserializeFromList( + serialized, &base_policy, nullptr, kParseTime); ASSERT_TRUE(deserialized); } @@ -360,8 +358,8 @@ TEST(BackoffEntrySerializerTest, DeserializeVersion2) { serialized.Append("2000"); // Backoff duration serialized.Append("1234"); // Absolute release time - auto deserialized = BackoffEntrySerializer::DeserializeFromValue( - base::Value(std::move(serialized)), &base_policy, nullptr, kParseTime); + auto deserialized = BackoffEntrySerializer::DeserializeFromList( + serialized, &base_policy, nullptr, kParseTime); ASSERT_TRUE(deserialized); } @@ -372,8 +370,8 @@ TEST(BackoffEntrySerializerTest, DeserializeVersion2NegativeDuration) { serialized.Append("-2000"); // Backoff duration serialized.Append("1234"); // Absolute release time - auto deserialized = BackoffEntrySerializer::DeserializeFromValue( - base::Value(std::move(serialized)), &base_policy, nullptr, kParseTime); + auto deserialized = BackoffEntrySerializer::DeserializeFromList( + serialized, &base_policy, nullptr, kParseTime); ASSERT_TRUE(deserialized); } @@ -384,8 +382,8 @@ TEST(BackoffEntrySerializerTest, DeserializeVersion1WrongDurationType) { serialized.Append("2000"); // Backoff duration in seconds as double serialized.Append("1234"); // Absolute release time - auto deserialized = BackoffEntrySerializer::DeserializeFromValue( - base::Value(std::move(serialized)), &base_policy, nullptr, kParseTime); + auto deserialized = BackoffEntrySerializer::DeserializeFromList( + serialized, &base_policy, nullptr, kParseTime); ASSERT_FALSE(deserialized); } @@ -396,8 +394,8 @@ TEST(BackoffEntrySerializerTest, DeserializeVersion2WrongDurationType) { serialized.Append(2.0); // Backoff duration serialized.Append("1234"); // Absolute release time - auto deserialized = BackoffEntrySerializer::DeserializeFromValue( - base::Value(std::move(serialized)), &base_policy, nullptr, kParseTime); + auto deserialized = BackoffEntrySerializer::DeserializeFromList( + serialized, &base_policy, nullptr, kParseTime); ASSERT_FALSE(deserialized); } diff --git a/chromium/net/base/backoff_entry_unittest.cc b/chromium/net/base/backoff_entry_unittest.cc index 4cebdecbb54..ddd84eec540 100644 --- a/chromium/net/base/backoff_entry_unittest.cc +++ b/chromium/net/base/backoff_entry_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/cache_metrics.cc b/chromium/net/base/cache_metrics.cc index 72f5ebcc123..ce21976a2bd 100644 --- a/chromium/net/base/cache_metrics.cc +++ b/chromium/net/base/cache_metrics.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/cache_metrics.h b/chromium/net/base/cache_metrics.h index 6979e5dd512..75d11bdf03b 100644 --- a/chromium/net/base/cache_metrics.h +++ b/chromium/net/base/cache_metrics.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/net/base/cache_type.h b/chromium/net/base/cache_type.h index 9a9a002bb03..7e8f82601d1 100644 --- a/chromium/net/base/cache_type.h +++ b/chromium/net/base/cache_type.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright 2009 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/chunked_upload_data_stream.cc b/chromium/net/base/chunked_upload_data_stream.cc index fac1432a7e0..3c6521a5bdb 100644 --- a/chromium/net/base/chunked_upload_data_stream.cc +++ b/chromium/net/base/chunked_upload_data_stream.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/chunked_upload_data_stream.h b/chromium/net/base/chunked_upload_data_stream.h index a8564f9bded..36f87c46521 100644 --- a/chromium/net/base/chunked_upload_data_stream.h +++ b/chromium/net/base/chunked_upload_data_stream.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/chunked_upload_data_stream_unittest.cc b/chromium/net/base/chunked_upload_data_stream_unittest.cc index 37e8f3edf26..8dbb8e59078 100644 --- a/chromium/net/base/chunked_upload_data_stream_unittest.cc +++ b/chromium/net/base/chunked_upload_data_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/completion_once_callback.h b/chromium/net/base/completion_once_callback.h index f299bbf09b7..d41ce7a277e 100644 --- a/chromium/net/base/completion_once_callback.h +++ b/chromium/net/base/completion_once_callback.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/completion_repeating_callback.h b/chromium/net/base/completion_repeating_callback.h index 0e96e6cd767..44c8e6e178c 100644 --- a/chromium/net/base/completion_repeating_callback.h +++ b/chromium/net/base/completion_repeating_callback.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/connection_endpoint_metadata.cc b/chromium/net/base/connection_endpoint_metadata.cc index 1bdf66a4812..10b196849e4 100644 --- a/chromium/net/base/connection_endpoint_metadata.cc +++ b/chromium/net/base/connection_endpoint_metadata.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/connection_endpoint_metadata.h b/chromium/net/base/connection_endpoint_metadata.h index 56f9c6be09e..8d81b5ad6e0 100644 --- a/chromium/net/base/connection_endpoint_metadata.h +++ b/chromium/net/base/connection_endpoint_metadata.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/connection_endpoint_metadata_test_util.cc b/chromium/net/base/connection_endpoint_metadata_test_util.cc index 837a430c737..78812b903f6 100644 --- a/chromium/net/base/connection_endpoint_metadata_test_util.cc +++ b/chromium/net/base/connection_endpoint_metadata_test_util.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/connection_endpoint_metadata_test_util.h b/chromium/net/base/connection_endpoint_metadata_test_util.h index 4ec01b4d349..f8737b4c0b6 100644 --- a/chromium/net/base/connection_endpoint_metadata_test_util.h +++ b/chromium/net/base/connection_endpoint_metadata_test_util.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/data_url.cc b/chromium/net/base/data_url.cc index 42b69399e79..9125ba36eb2 100644 --- a/chromium/net/base/data_url.cc +++ b/chromium/net/base/data_url.cc @@ -1,17 +1,16 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // NOTE: based loosely on mozilla's nsDataChannel.cpp -#include <algorithm> - #include "net/base/data_url.h" #include "base/base64.h" #include "base/containers/cxx20_erase.h" #include "base/feature_list.h" #include "base/features.h" +#include "base/ranges/algorithm.h" #include "base/strings/escape.h" #include "base/strings/string_piece.h" #include "base/strings/string_split.h" @@ -24,15 +23,21 @@ namespace net { namespace { +// https://infra.spec.whatwg.org/#ascii-whitespace, which is referenced by +// https://infra.spec.whatwg.org/#forgiving-base64, does not include \v in the +// set of ASCII whitespace characters the way Unicode does. +bool IsBase64Whitespace(char c) { + return c != '\v' && base::IsAsciiWhitespace(c); +} + // A data URL is ready for decode if it: // - Doesn't need any extra padding. // - Does not have any escaped characters. // - Does not have any whitespace. bool IsDataURLReadyForDecode(base::StringPiece body) { - return (body.length() % 4) == 0 && base::ranges::find_if(body, [](char c) { - return c == '%' || - base::IsAsciiWhitespace(c); - }) == std::end(body); + return (body.length() % 4) == 0 && base::ranges::none_of(body, [](char c) { + return c == '%' || IsBase64Whitespace(c); + }); } } // namespace @@ -58,16 +63,12 @@ bool DataURL::Parse(const GURL& url, content = content_string; } - base::StringPiece::const_iterator begin = content.begin(); - base::StringPiece::const_iterator end = content.end(); - - base::StringPiece::const_iterator comma = std::find(begin, end, ','); - - if (comma == end) + base::StringPiece::const_iterator comma = base::ranges::find(content, ','); + if (comma == content.end()) return false; std::vector<base::StringPiece> meta_data = - base::SplitStringPiece(base::MakeStringPiece(begin, comma), ";", + base::SplitStringPiece(base::MakeStringPiece(content.begin(), comma), ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); // These are moved to |mime_type| and |charset| on success. @@ -128,7 +129,7 @@ bool DataURL::Parse(const GURL& url, // spaces itself, anyways. Should we just trim leading spaces instead? // Allowing random intermediary spaces seems unnecessary. - auto raw_body = base::MakeStringPiece(comma + 1, end); + auto raw_body = base::MakeStringPiece(comma + 1, content.end()); // For base64, we may have url-escaped whitespace which is not part // of the data, and should be stripped. Otherwise, the escaped whitespace @@ -143,7 +144,7 @@ bool DataURL::Parse(const GURL& url, std::string unescaped_body = base::UnescapeBinaryURLComponent(raw_body); // Strip spaces, which aren't allowed in Base64 encoding. - base::EraseIf(unescaped_body, base::IsAsciiWhitespace<char>); + base::EraseIf(unescaped_body, IsBase64Whitespace); size_t length = unescaped_body.length(); size_t padding_needed = 4 - (length % 4); diff --git a/chromium/net/base/data_url.h b/chromium/net/base/data_url.h index cb3cbb790cf..066d5d5bc17 100644 --- a/chromium/net/base/data_url.h +++ b/chromium/net/base/data_url.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/data_url_fuzzer.cc b/chromium/net/base/data_url_fuzzer.cc index 39afc0383f7..0a3d7e511c6 100644 --- a/chromium/net/base/data_url_fuzzer.cc +++ b/chromium/net/base/data_url_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/data_url_unittest.cc b/chromium/net/base/data_url_unittest.cc index 6fe83aad889..7e969852305 100644 --- a/chromium/net/base/data_url_unittest.cc +++ b/chromium/net/base/data_url_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/datagram_buffer.cc b/chromium/net/base/datagram_buffer.cc index 255fabbcd53..4b0446bdf21 100644 --- a/chromium/net/base/datagram_buffer.cc +++ b/chromium/net/base/datagram_buffer.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/datagram_buffer.h b/chromium/net/base/datagram_buffer.h index b272722b486..e0deee7fc46 100644 --- a/chromium/net/base/datagram_buffer.h +++ b/chromium/net/base/datagram_buffer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/datagram_buffer_unittest.cc b/chromium/net/base/datagram_buffer_unittest.cc index d62f7b3989f..0d2f7f778a9 100644 --- a/chromium/net/base/datagram_buffer_unittest.cc +++ b/chromium/net/base/datagram_buffer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/directory_lister.cc b/chromium/net/base/directory_lister.cc index b606f7d114f..e006e96987a 100644 --- a/chromium/net/base/directory_lister.cc +++ b/chromium/net/base/directory_lister.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/directory_lister.h b/chromium/net/base/directory_lister.h index 3701a5a69c8..991d15b7987 100644 --- a/chromium/net/base/directory_lister.h +++ b/chromium/net/base/directory_lister.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/directory_lister_unittest.cc b/chromium/net/base/directory_lister_unittest.cc index ec25e3b1e8c..0dc0fa0dd00 100644 --- a/chromium/net/base/directory_lister_unittest.cc +++ b/chromium/net/base/directory_lister_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/directory_listing.cc b/chromium/net/base/directory_listing.cc index 87bf63e896b..82b805c70fe 100644 --- a/chromium/net/base/directory_listing.cc +++ b/chromium/net/base/directory_listing.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/directory_listing.h b/chromium/net/base/directory_listing.h index 8df2f2069ef..5cd073f850b 100644 --- a/chromium/net/base/directory_listing.h +++ b/chromium/net/base/directory_listing.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/directory_listing_unittest.cc b/chromium/net/base/directory_listing_unittest.cc index 2fcbb0e6fc9..11cf9059bfc 100644 --- a/chromium/net/base/directory_listing_unittest.cc +++ b/chromium/net/base/directory_listing_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/elements_upload_data_stream.cc b/chromium/net/base/elements_upload_data_stream.cc index 6d91c8beac7..f034db840ee 100644 --- a/chromium/net/base/elements_upload_data_stream.cc +++ b/chromium/net/base/elements_upload_data_stream.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/elements_upload_data_stream.h b/chromium/net/base/elements_upload_data_stream.h index d2e73880463..3b13c259491 100644 --- a/chromium/net/base/elements_upload_data_stream.h +++ b/chromium/net/base/elements_upload_data_stream.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/elements_upload_data_stream_unittest.cc b/chromium/net/base/elements_upload_data_stream_unittest.cc index 6516c288eda..22efde4e413 100644 --- a/chromium/net/base/elements_upload_data_stream_unittest.cc +++ b/chromium/net/base/elements_upload_data_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/expiring_cache.h b/chromium/net/base/expiring_cache.h index f466ab55a1b..1f958bc42c5 100644 --- a/chromium/net/base/expiring_cache.h +++ b/chromium/net/base/expiring_cache.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/expiring_cache_unittest.cc b/chromium/net/base/expiring_cache_unittest.cc index 275bc340594..06bb0f0f9cd 100644 --- a/chromium/net/base/expiring_cache_unittest.cc +++ b/chromium/net/base/expiring_cache_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/features.cc b/chromium/net/base/features.cc index a43cca47a57..10e0f6848fa 100644 --- a/chromium/net/base/features.cc +++ b/chromium/net/base/features.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,17 +11,19 @@ namespace net::features { -const base::Feature kAlpsForHttp2{"AlpsForHttp2", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kAlpsForHttp2, "AlpsForHttp2", base::FEATURE_ENABLED_BY_DEFAULT); -const base::Feature kAvoidH2Reprioritization{"AvoidH2Reprioritization", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kAvoidH2Reprioritization, + "AvoidH2Reprioritization", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kCapReferrerToOriginOnCrossOrigin{ - "CapReferrerToOriginOnCrossOrigin", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kCapReferrerToOriginOnCrossOrigin, + "CapReferrerToOriginOnCrossOrigin", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kDnsTransactionDynamicTimeouts{ - "DnsTransactionDynamicTimeouts", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kDnsTransactionDynamicTimeouts, + "DnsTransactionDynamicTimeouts", + base::FEATURE_DISABLED_BY_DEFAULT); const base::FeatureParam<double> kDnsTransactionTimeoutMultiplier{ &kDnsTransactionDynamicTimeouts, "DnsTransactionTimeoutMultiplier", 7.5}; @@ -30,133 +32,98 @@ const base::FeatureParam<base::TimeDelta> kDnsMinTransactionTimeout{ &kDnsTransactionDynamicTimeouts, "DnsMinTransactionTimeout", base::Seconds(12)}; -const base::Feature kDnsHttpssvc{"DnsHttpssvc", - base::FEATURE_DISABLED_BY_DEFAULT}; - -const base::FeatureParam<bool> kDnsHttpssvcUseHttpssvc{ - &kDnsHttpssvc, "DnsHttpssvcUseHttpssvc", false}; - -const base::FeatureParam<bool> kDnsHttpssvcUseIntegrity{ - &kDnsHttpssvc, "DnsHttpssvcUseIntegrity", false}; - -const base::FeatureParam<bool> kDnsHttpssvcEnableQueryOverInsecure{ - &kDnsHttpssvc, "DnsHttpssvcEnableQueryOverInsecure", false}; - -const base::FeatureParam<int> kDnsHttpssvcExtraTimeMs{ - &kDnsHttpssvc, "DnsHttpssvcExtraTimeMs", 10}; - -const base::FeatureParam<int> kDnsHttpssvcExtraTimePercent{ - &kDnsHttpssvc, "DnsHttpssvcExtraTimePercent", 5}; - -const base::FeatureParam<std::string> kDnsHttpssvcExperimentDomains{ - &kDnsHttpssvc, "DnsHttpssvcExperimentDomains", ""}; - -const base::FeatureParam<std::string> kDnsHttpssvcControlDomains{ - &kDnsHttpssvc, "DnsHttpssvcControlDomains", ""}; - -const base::FeatureParam<bool> kDnsHttpssvcControlDomainWildcard{ - &kDnsHttpssvc, "DnsHttpssvcControlDomainWildcard", false}; - -namespace dns_httpssvc_experiment { -base::TimeDelta GetExtraTimeAbsolute() { - DCHECK(base::FeatureList::IsEnabled(features::kDnsHttpssvc)); - return base::Milliseconds(kDnsHttpssvcExtraTimeMs.Get()); -} -} // namespace dns_httpssvc_experiment - -const base::Feature kUseDnsHttpsSvcb{"UseDnsHttpsSvcb", - base::FEATURE_DISABLED_BY_DEFAULT}; - -const base::FeatureParam<bool> kUseDnsHttpsSvcbHttpUpgrade{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbHttpUpgrade", false}; +BASE_FEATURE(kUseDnsHttpsSvcb, + "UseDnsHttpsSvcb", + base::FEATURE_ENABLED_BY_DEFAULT); const base::FeatureParam<bool> kUseDnsHttpsSvcbEnforceSecureResponse{ &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbEnforceSecureResponse", false}; -const base::FeatureParam<bool> kUseDnsHttpsSvcbEnableInsecure{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbEnableInsecure", false}; - const base::FeatureParam<base::TimeDelta> kUseDnsHttpsSvcbInsecureExtraTimeMax{ &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbInsecureExtraTimeMax", - base::TimeDelta()}; + base::Milliseconds(50)}; const base::FeatureParam<int> kUseDnsHttpsSvcbInsecureExtraTimePercent{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbInsecureExtraTimePercent", 0}; + &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbInsecureExtraTimePercent", 20}; const base::FeatureParam<base::TimeDelta> kUseDnsHttpsSvcbInsecureExtraTimeMin{ &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbInsecureExtraTimeMin", - base::TimeDelta()}; + base::Milliseconds(5)}; const base::FeatureParam<base::TimeDelta> kUseDnsHttpsSvcbSecureExtraTimeMax{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbSecureExtraTimeMax", base::TimeDelta()}; + &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbSecureExtraTimeMax", + base::Milliseconds(50)}; const base::FeatureParam<int> kUseDnsHttpsSvcbSecureExtraTimePercent{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbSecureExtraTimePercent", 0}; + &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbSecureExtraTimePercent", 20}; const base::FeatureParam<base::TimeDelta> kUseDnsHttpsSvcbSecureExtraTimeMin{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbSecureExtraTimeMin", base::TimeDelta()}; - -const base::FeatureParam<base::TimeDelta> kUseDnsHttpsSvcbExtraTimeAbsolute{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbExtraTimeAbsolute", base::TimeDelta()}; + &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbSecureExtraTimeMin", + base::Milliseconds(5)}; -const base::FeatureParam<int> kUseDnsHttpsSvcbExtraTimePercent{ - &kUseDnsHttpsSvcb, "UseDnsHttpsSvcbExtraTimePercent", 0}; +BASE_FEATURE(kUseDnsHttpsSvcbAlpn, + "UseDnsHttpsSvcbAlpn", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kUseDnsHttpsSvcbAlpn{"UseDnsHttpsSvcbAlpn", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kEnableTLS13EarlyData, + "EnableTLS13EarlyData", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kEnableTLS13EarlyData{"EnableTLS13EarlyData", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kEncryptedClientHello, + "EncryptedClientHello", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kEncryptedClientHello{"EncryptedClientHello", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kNetworkQualityEstimator, + "NetworkQualityEstimator", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kNetworkQualityEstimator{"NetworkQualityEstimator", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kSplitCacheByIncludeCredentials, + "SplitCacheByIncludeCredentials", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kSplitCacheByIncludeCredentials{ - "SplitCacheByIncludeCredentials", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kSplitCacheByNetworkIsolationKey, + "SplitCacheByNetworkIsolationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kSplitCacheByNetworkIsolationKey{ - "SplitCacheByNetworkIsolationKey", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kSplitHostCacheByNetworkIsolationKey, + "SplitHostCacheByNetworkIsolationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kSplitHostCacheByNetworkIsolationKey{ - "SplitHostCacheByNetworkIsolationKey", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kPartitionConnectionsByNetworkIsolationKey, + "PartitionConnectionsByNetworkIsolationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPartitionConnectionsByNetworkIsolationKey{ - "PartitionConnectionsByNetworkIsolationKey", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kForceIsolationInfoFrameOriginToTopLevelFrame, + "ForceIsolationInfoFrameOriginToTopLevelFrame", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kForceIsolationInfoFrameOriginToTopLevelFrame{ - "ForceIsolationInfoFrameOriginToTopLevelFrame", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kPartitionHttpServerPropertiesByNetworkIsolationKey, + "PartitionHttpServerPropertiesByNetworkIsolationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPartitionHttpServerPropertiesByNetworkIsolationKey{ - "PartitionHttpServerPropertiesByNetworkIsolationKey", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kPartitionSSLSessionsByNetworkIsolationKey, + "PartitionSSLSessionsByNetworkIsolationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPartitionSSLSessionsByNetworkIsolationKey{ - "PartitionSSLSessionsByNetworkIsolationKey", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kPartitionExpectCTStateByNetworkIsolationKey, + "PartitionExpectCTStateByNetworkIsolationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPartitionExpectCTStateByNetworkIsolationKey{ - "PartitionExpectCTStateByNetworkIsolationKey", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kPartitionNelAndReportingByNetworkIsolationKey, + "PartitionNelAndReportingByNetworkIsolationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPartitionNelAndReportingByNetworkIsolationKey{ - "PartitionNelAndReportingByNetworkIsolationKey", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kEnableDoubleKeyNetworkAnonymizationKey, + "EnableDoubleKeyNetworkAnonymizationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kEnableDoubleKeyNetworkAnonymizationKey{ - "EnableDoubleKeyNetworkAnonymizationKey", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kEnableCrossSiteFlagNetworkAnonymizationKey, + "EnableCrossSiteFlagNetworkAnonymizationKey", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kEnableCrossSiteFlagNetworkAnonymizationKey{ - "EnableCrossSiteFlagNetworkAnonymizationKey", - base::FEATURE_DISABLED_BY_DEFAULT}; - -const base::Feature kExpectCTPruning{"ExpectCTPruning", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kExpectCTPruning, + "ExpectCTPruning", + base::FEATURE_ENABLED_BY_DEFAULT); NET_EXPORT extern const base::FeatureParam<int> kExpectCTPruneMax(&kExpectCTPruning, "ExpectCTPruneMax", 2000); @@ -173,81 +140,85 @@ NET_EXPORT extern const base::FeatureParam<int> kExpectCTMaxEntriesPerNik( NET_EXPORT extern const base::FeatureParam<int> kExpectCTPruneDelaySecs(&kExpectCTPruning, "ExpectCTPruneDelaySecs", 60); -const base::Feature kTLS13KeyUpdate{"TLS13KeyUpdate", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kTLS13KeyUpdate, + "TLS13KeyUpdate", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPermuteTLSExtensions{"PermuteTLSExtensions", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kPermuteTLSExtensions, + "PermuteTLSExtensions", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPostQuantumCECPQ2{"PostQuantumCECPQ2", - base::FEATURE_DISABLED_BY_DEFAULT}; -const base::Feature kPostQuantumCECPQ2SomeDomains{ - "PostQuantumCECPQ2SomeDomains", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kPostQuantumCECPQ2, + "PostQuantumCECPQ2", + base::FEATURE_DISABLED_BY_DEFAULT); +BASE_FEATURE(kPostQuantumCECPQ2SomeDomains, + "PostQuantumCECPQ2SomeDomains", + base::FEATURE_DISABLED_BY_DEFAULT); const base::FeatureParam<std::string> kPostQuantumCECPQ2Prefix(&kPostQuantumCECPQ2SomeDomains, "prefix", "a"); -const base::Feature kNetUnusedIdleSocketTimeout{ - "NetUnusedIdleSocketTimeout", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kNetUnusedIdleSocketTimeout, + "NetUnusedIdleSocketTimeout", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kShortLaxAllowUnsafeThreshold{ - "ShortLaxAllowUnsafeThreshold", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kShortLaxAllowUnsafeThreshold, + "ShortLaxAllowUnsafeThreshold", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kSameSiteDefaultChecksMethodRigorously{ - "SameSiteDefaultChecksMethodRigorously", base::FEATURE_DISABLED_BY_DEFAULT}; - -#if BUILDFLAG(BUILTIN_CERT_VERIFIER_FEATURE_SUPPORTED) -const base::Feature kCertVerifierBuiltinFeature{ - "CertVerifierBuiltin", base::FEATURE_DISABLED_BY_DEFAULT}; -#if BUILDFLAG(IS_MAC) -const base::FeatureParam<int> kCertVerifierBuiltinImpl{ - &kCertVerifierBuiltinFeature, "impl", 0}; -const base::FeatureParam<int> kCertVerifierBuiltinCacheSize{ - &kCertVerifierBuiltinFeature, "cachesize", 0}; -#endif /* BUILDFLAG(IS_MAC) */ -#endif +BASE_FEATURE(kSameSiteDefaultChecksMethodRigorously, + "SameSiteDefaultChecksMethodRigorously", + base::FEATURE_DISABLED_BY_DEFAULT); #if BUILDFLAG(TRIAL_COMPARISON_CERT_VERIFIER_SUPPORTED) // Enables the dual certificate verification trial feature. // https://crbug.com/649026 -const base::Feature kCertDualVerificationTrialFeature{ - "CertDualVerificationTrial", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kCertDualVerificationTrialFeature, + "CertDualVerificationTrial", + base::FEATURE_DISABLED_BY_DEFAULT); #if BUILDFLAG(IS_MAC) const base::FeatureParam<int> kCertDualVerificationTrialImpl{ &kCertDualVerificationTrialFeature, "impl", 0}; const base::FeatureParam<int> kCertDualVerificationTrialCacheSize{ &kCertDualVerificationTrialFeature, "cachesize", 0}; #endif /* BUILDFLAG(IS_MAC) */ -#if BUILDFLAG(BUILTIN_CERT_VERIFIER_FEATURE_SUPPORTED) && \ - BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED) -const base::FeatureParam<bool> kCertDualVerificationTrialUseCrs{ - &kCertDualVerificationTrialFeature, "use_crs", false}; -#endif #endif #if BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED) -const base::Feature kChromeRootStoreUsed{"ChromeRootStoreUsed", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kChromeRootStoreUsed, + "ChromeRootStoreUsed", + base::FEATURE_DISABLED_BY_DEFAULT); +#if BUILDFLAG(IS_MAC) +const base::FeatureParam<int> kChromeRootStoreSysImpl{&kChromeRootStoreUsed, + "sysimpl", 0}; +const base::FeatureParam<int> kChromeRootStoreSysCacheSize{ + &kChromeRootStoreUsed, "syscachesize", 0}; +#endif /* BUILDFLAG(IS_MAC) */ #endif /* BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED) */ -const base::Feature kTurnOffStreamingMediaCachingOnBattery{ - "TurnOffStreamingMediaCachingOnBattery", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kTurnOffStreamingMediaCachingOnBattery, + "TurnOffStreamingMediaCachingOnBattery", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kTurnOffStreamingMediaCachingAlways{ - "TurnOffStreamingMediaCachingAlways", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kTurnOffStreamingMediaCachingAlways, + "TurnOffStreamingMediaCachingAlways", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kSchemefulSameSite{"SchemefulSameSite", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kSchemefulSameSite, + "SchemefulSameSite", + base::FEATURE_ENABLED_BY_DEFAULT); -const base::Feature kLimitOpenUDPSockets{"LimitOpenUDPSockets", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kLimitOpenUDPSockets, + "LimitOpenUDPSockets", + base::FEATURE_ENABLED_BY_DEFAULT); extern const base::FeatureParam<int> kLimitOpenUDPSocketsMax( &kLimitOpenUDPSockets, "LimitOpenUDPSocketsMax", 6000); -const base::Feature kTimeoutTcpConnectAttempt{ - "TimeoutTcpConnectAttempt", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kTimeoutTcpConnectAttempt, + "TimeoutTcpConnectAttempt", + base::FEATURE_DISABLED_BY_DEFAULT); extern const base::FeatureParam<double> kTimeoutTcpConnectAttemptRTTMultiplier( &kTimeoutTcpConnectAttempt, @@ -265,57 +236,91 @@ extern const base::FeatureParam<base::TimeDelta> kTimeoutTcpConnectAttemptMax( base::Seconds(30)); #if BUILDFLAG(ENABLE_REPORTING) -const base::Feature kDocumentReporting{"DocumentReporting", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kDocumentReporting, + "DocumentReporting", + base::FEATURE_ENABLED_BY_DEFAULT); #endif // BUILDFLAG(ENABLE_REPORTING) #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) -const base::Feature kUdpSocketPosixAlwaysUpdateBytesReceived{ - "UdpSocketPosixAlwaysUpdateBytesReceived", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kUdpSocketPosixAlwaysUpdateBytesReceived, + "UdpSocketPosixAlwaysUpdateBytesReceived", + base::FEATURE_ENABLED_BY_DEFAULT); #endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) -const base::Feature kCookieSameSiteConsidersRedirectChain{ - "CookieSameSiteConsidersRedirectChain", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kCookieSameSiteConsidersRedirectChain, + "CookieSameSiteConsidersRedirectChain", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kSamePartyCookiesConsideredFirstParty{ - "SamePartyCookiesConsideredFirstParty", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kSamePartyCookiesConsideredFirstParty, + "SamePartyCookiesConsideredFirstParty", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kPartitionedCookies{"PartitionedCookies", - base::FEATURE_DISABLED_BY_DEFAULT}; -const base::Feature kPartitionedCookiesBypassOriginTrial{ - "PartitionedCookiesBypassOriginTrial", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kSamePartyAttributeEnabled, + "SamePartyAttributeEnabled", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kNoncedPartitionedCookies{"NoncedPartitionedCookies", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kPartitionedCookies, + "PartitionedCookies", + base::FEATURE_DISABLED_BY_DEFAULT); +BASE_FEATURE(kPartitionedCookiesBypassOriginTrial, + "PartitionedCookiesBypassOriginTrial", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kExtraCookieValidityChecks{ - "ExtraCookieValidityChecks", base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kNoncedPartitionedCookies, + "NoncedPartitionedCookies", + base::FEATURE_ENABLED_BY_DEFAULT); -const base::Feature kRecordRadioWakeupTrigger{ - "RecordRadioWakeupTrigger", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kExtraCookieValidityChecks, + "ExtraCookieValidityChecks", + base::FEATURE_ENABLED_BY_DEFAULT); -const base::Feature kClampCookieExpiryTo400Days( - "ClampCookieExpiryTo400Days", - base::FEATURE_ENABLED_BY_DEFAULT); +BASE_FEATURE(kRecordRadioWakeupTrigger, + "RecordRadioWakeupTrigger", + base::FEATURE_DISABLED_BY_DEFAULT); -const base::Feature kStaticKeyPinningEnforcement( - "StaticKeyPinningEnforcement", - base::FEATURE_ENABLED_BY_DEFAULT); +BASE_FEATURE(kClampCookieExpiryTo400Days, + "ClampCookieExpiryTo400Days", + base::FEATURE_ENABLED_BY_DEFAULT); -const base::Feature kCookieDomainRejectNonASCII{ - "CookieDomainRejectNonASCII", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kStaticKeyPinningEnforcement, + "StaticKeyPinningEnforcement", + base::FEATURE_ENABLED_BY_DEFAULT); -const base::Feature kBlockSetCookieHeader{"BlockSetCookieHeader", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kCookieDomainRejectNonASCII, + "CookieDomainRejectNonASCII", + base::FEATURE_DISABLED_BY_DEFAULT); + +BASE_FEATURE(kBlockSetCookieHeader, + "BlockSetCookieHeader", + base::FEATURE_ENABLED_BY_DEFAULT); + +// Run callbacks optimstically for write calls to the blockfile disk cache +// implementation. +BASE_FEATURE(kOptimisticBlockfileWrite, + "OptimisticBlockfileWrite", + base::FEATURE_DISABLED_BY_DEFAULT); // Read as much of the net::URLRequest as there is space in the Mojo data pipe. -const base::Feature kOptimizeNetworkBuffers{"OptimizeNetworkBuffers2", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kOptimizeNetworkBuffers, + "OptimizeNetworkBuffers2", + base::FEATURE_DISABLED_BY_DEFAULT); const base::FeatureParam<int> kOptimizeNetworkBuffersBytesReadLimit{ &kOptimizeNetworkBuffers, "bytes_read_limit", 64 * 1024}; +// If InputStream.available() returns less than this, +// kOptimizeNetworkBuffersMinInputStreamReadSize will be used instead. +const base::FeatureParam<int> + kOptimizeNetworkBuffersMinInputStreamAvailableValueToIgnore{ + &kOptimizeNetworkBuffers, "min_input_stream_available_value_to_ignore", + 16}; + +// The smallest amount we'll try to read at a time if InputStream.available() +// returned less than +// kOptimizeNetworkBuffersMinInputStreamAvailableValueToIgnore. +const base::FeatureParam<int> kOptimizeNetworkBuffersMinInputStreamReadSize{ + &kOptimizeNetworkBuffers, "min_input_stream_read_size", 1024}; + const base::FeatureParam<int> kOptimizeNetworkBuffersMaxInputStreamBytesToReadWhenAvailableUnknown{ &kOptimizeNetworkBuffers, "max_input_stream_bytes_available_unknown", @@ -329,8 +334,9 @@ const base::FeatureParam<int> const base::FeatureParam<bool> kOptimizeNetworkBuffersInputStreamCheckAvailable{ &kOptimizeNetworkBuffers, "input_stream_check_available", true}; -const base::Feature kStorageAccessAPI{"StorageAccessAPI", - base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kStorageAccessAPI, + "StorageAccessAPI", + base::FEATURE_DISABLED_BY_DEFAULT); constexpr int kStorageAccessAPIDefaultImplicitGrantLimit = 5; const base::FeatureParam<int> kStorageAccessAPIImplicitGrantLimit{ &kStorageAccessAPI, "storage-access-api-implicit-grant-limit", @@ -339,9 +345,37 @@ const base::FeatureParam<bool> kStorageAccessAPIGrantsUnpartitionedStorage( &kStorageAccessAPI, "storage-access-api-grants-unpartitioned-storage", false); +const base::FeatureParam<bool> kStorageAccessAPIAutoGrantInFPS{ + &kStorageAccessAPI, "storage_access_api_auto_grant_in_fps", true}; +const base::FeatureParam<bool> kStorageAccessAPIAutoDenyOutsideFPS{ + &kStorageAccessAPI, "storage_access_api_auto_deny_outside_fps", true}; // Enables partitioning of third party storage (IndexedDB, CacheStorage, etc.) // by the top level site to reduce fingerprinting. -const base::Feature kThirdPartyStoragePartitioning{ - "ThirdPartyStoragePartitioning", base::FEATURE_DISABLED_BY_DEFAULT}; +BASE_FEATURE(kThirdPartyStoragePartitioning, + "ThirdPartyStoragePartitioning", + base::FEATURE_DISABLED_BY_DEFAULT); + +BASE_FEATURE(kAlpsParsing, "AlpsParsing", base::FEATURE_ENABLED_BY_DEFAULT); + +BASE_FEATURE(kAlpsClientHintParsing, + "AlpsClientHintParsing", + base::FEATURE_ENABLED_BY_DEFAULT); + +BASE_FEATURE(kShouldKillSessionOnAcceptChMalformed, + "ShouldKillSessionOnAcceptChMalformed", + base::FEATURE_DISABLED_BY_DEFAULT); + +BASE_FEATURE(kCaseInsensitiveCookiePrefix, + "CaseInsensitiveCookiePrefix", + base::FEATURE_ENABLED_BY_DEFAULT); + +BASE_FEATURE(kEnableWebsocketsOverHttp3, + "EnableWebsocketsOverHttp3", + base::FEATURE_DISABLED_BY_DEFAULT); + +BASE_FEATURE(kUseNAT64ForIPv4Literal, + "UseNAT64ForIPv4Literal", + base::FEATURE_ENABLED_BY_DEFAULT); + } // namespace net::features diff --git a/chromium/net/base/features.h b/chromium/net/base/features.h index 6729475a475..745c3488f09 100644 --- a/chromium/net/base/features.h +++ b/chromium/net/base/features.h @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,18 +20,18 @@ namespace net::features { // Enables ALPS extension of TLS 1.3 for HTTP/2, see // https://vasilvv.github.io/tls-alps/draft-vvv-tls-alps.html and // https://vasilvv.github.io/httpbis-alps/draft-vvv-httpbis-alps.html. -NET_EXPORT extern const base::Feature kAlpsForHttp2; +NET_EXPORT BASE_DECLARE_FEATURE(kAlpsForHttp2); // Disable H2 reprioritization, in order to measure its impact. -NET_EXPORT extern const base::Feature kAvoidH2Reprioritization; +NET_EXPORT BASE_DECLARE_FEATURE(kAvoidH2Reprioritization); // When kCapReferrerToOriginOnCrossOrigin is enabled, HTTP referrers on cross- // origin requests are restricted to contain at most the source origin. -NET_EXPORT extern const base::Feature kCapReferrerToOriginOnCrossOrigin; +NET_EXPORT BASE_DECLARE_FEATURE(kCapReferrerToOriginOnCrossOrigin); // Support for altering the parameters used for DNS transaction timeout. See // ResolveContext::SecureTransactionTimeout(). -NET_EXPORT extern const base::Feature kDnsTransactionDynamicTimeouts; +NET_EXPORT BASE_DECLARE_FEATURE(kDnsTransactionDynamicTimeouts); // Multiplier applied to current fallback periods in determining a transaction // timeout. NET_EXPORT extern const base::FeatureParam<double> @@ -39,75 +39,10 @@ NET_EXPORT extern const base::FeatureParam<double> NET_EXPORT extern const base::FeatureParam<base::TimeDelta> kDnsMinTransactionTimeout; -// Enables DNS query-only experiments for HTTPSSVC or INTEGRITY records, -// depending on feature parameters. Received responses never affect Chrome -// behavior other than metrics. -// -// Not to be confused with `kUseDnsHttpsSvcb` which is querying HTTPS in order -// to affect Chrome connection behavior. -NET_EXPORT extern const base::Feature kDnsHttpssvc; - -// Determine which kind of record should be queried: HTTPSSVC or INTEGRITY. No -// more than one of these feature parameters should be enabled at once. In the -// event that both are enabled, |kDnsHttpssvcUseIntegrity| takes priority, and -// |kDnsHttpssvcUseHttpssvc| will be ignored. -NET_EXPORT extern const base::FeatureParam<bool> kDnsHttpssvcUseHttpssvc; -NET_EXPORT extern const base::FeatureParam<bool> kDnsHttpssvcUseIntegrity; - -// Enable HTTPSSVC or INTEGRITY to be queried over insecure DNS. -NET_EXPORT extern const base::FeatureParam<bool> - kDnsHttpssvcEnableQueryOverInsecure; - -// If we are still waiting for an HTTPSSVC or INTEGRITY query after all the -// other queries in a DnsTask have completed, we will compute a timeout for the -// remaining query. The timeout will be the min of: -// (a) |kDnsHttpssvcExtraTimeMs.Get()| -// (b) |kDnsHttpssvcExtraTimePercent.Get() / 100 * t|, where |t| is the -// number of milliseconds since the first query began. -NET_EXPORT extern const base::FeatureParam<int> kDnsHttpssvcExtraTimeMs; -NET_EXPORT extern const base::FeatureParam<int> kDnsHttpssvcExtraTimePercent; - -// These parameters, respectively, are the list of experimental and control -// domains for which we will query HTTPSSVC or INTEGRITY records. We expect -// valid INTEGRITY results for experiment domains. We expect no INTEGRITY -// results for control domains. -// -// The format of both parameters is a comma-separated list of domains. -// Whitespace around domain names is permitted. Trailing comma is optional. -// -// See helper functions: -// |dns_httpssvc_experiment::GetDnsHttpssvcExperimentDomains| and -// |dns_httpssvc_experiment::GetDnsHttpssvcControlDomains|. -NET_EXPORT extern const base::FeatureParam<std::string> - kDnsHttpssvcExperimentDomains; -NET_EXPORT extern const base::FeatureParam<std::string> - kDnsHttpssvcControlDomains; - -// This param controls how we determine whether a domain is an experimental or -// control domain. When false, domains must be in |kDnsHttpssvcControlDomains| -// to be considered a control. When true, we ignore |kDnsHttpssvcControlDomains| -// and any non-experiment domain (not in |kDnsHttpssvcExperimentDomains|) is -// considered a control domain. -NET_EXPORT extern const base::FeatureParam<bool> - kDnsHttpssvcControlDomainWildcard; - -namespace dns_httpssvc_experiment { -// Get the value of |kDnsHttpssvcExtraTimeMs|. -NET_EXPORT base::TimeDelta GetExtraTimeAbsolute(); -} // namespace dns_httpssvc_experiment - // Enables querying HTTPS DNS records that will affect results from HostResolver // and may be used to affect connection behavior. Whether or not those results // are used (e.g. to connect via ECH) may be controlled by separate features. -// -// Not to be confused with `kDnsHttpssvc` which is for experiment-only queries -// where received HTTPS results do not affect Chrome behavior and are only used -// for metrics. -NET_EXPORT extern const base::Feature kUseDnsHttpsSvcb; - -// Param to control whether or not presence of an HTTPS record for an HTTP -// request will force an HTTP->HTTPS upgrade redirect. -NET_EXPORT extern const base::FeatureParam<bool> kUseDnsHttpsSvcbHttpUpgrade; +NET_EXPORT BASE_DECLARE_FEATURE(kUseDnsHttpsSvcb); // Param to control whether or not HostResolver, when using Secure DNS, will // fail the entire connection attempt when receiving an inconclusive response to @@ -116,10 +51,6 @@ NET_EXPORT extern const base::FeatureParam<bool> kUseDnsHttpsSvcbHttpUpgrade; NET_EXPORT extern const base::FeatureParam<bool> kUseDnsHttpsSvcbEnforceSecureResponse; -// Param to control whether HTTPS queries will be allowed via Insecure DNS -// (instead of just via Secure DNS). -NET_EXPORT extern const base::FeatureParam<bool> kUseDnsHttpsSvcbEnableInsecure; - // If we are still waiting for an HTTPS transaction after all the // other transactions in an insecure DnsTask have completed, we will compute a // timeout for the remaining transaction. The timeout will be @@ -152,65 +83,52 @@ NET_EXPORT extern const base::FeatureParam<int> NET_EXPORT extern const base::FeatureParam<base::TimeDelta> kUseDnsHttpsSvcbSecureExtraTimeMin; -// Deprecated in favor of `kUseDnsHttpsSvcbInsecureExtraTime...` and -// `kUseDnsHttpsSvcbSecureExtraTime...` params. Ignored for insecure DnsTasks if -// any `kUseDnsHttpsSvcbInsecureExtraTime...` params are non-zero, and ignored -// for secure DnsTasks if any `kUseDnsHttpsSvcbSecureExtraTime...` params are -// non-zero. -NET_EXPORT extern const base::FeatureParam<base::TimeDelta> - kUseDnsHttpsSvcbExtraTimeAbsolute; -NET_EXPORT extern const base::FeatureParam<int> - kUseDnsHttpsSvcbExtraTimePercent; - // Update protocol using ALPN information in HTTPS DNS records. -NET_EXPORT extern const base::Feature kUseDnsHttpsSvcbAlpn; +NET_EXPORT BASE_DECLARE_FEATURE(kUseDnsHttpsSvcbAlpn); // Enables TLS 1.3 early data. -NET_EXPORT extern const base::Feature kEnableTLS13EarlyData; +NET_EXPORT BASE_DECLARE_FEATURE(kEnableTLS13EarlyData); // Enables the TLS Encrypted ClientHello feature. // https://datatracker.ietf.org/doc/html/draft-ietf-tls-esni-13 -NET_EXPORT extern const base::Feature kEncryptedClientHello; +NET_EXPORT BASE_DECLARE_FEATURE(kEncryptedClientHello); // Enables optimizing the network quality estimation algorithms in network // quality estimator (NQE). -NET_EXPORT extern const base::Feature kNetworkQualityEstimator; +NET_EXPORT BASE_DECLARE_FEATURE(kNetworkQualityEstimator); // Splits cache entries by the request's includeCredentials. -NET_EXPORT extern const base::Feature kSplitCacheByIncludeCredentials; +NET_EXPORT BASE_DECLARE_FEATURE(kSplitCacheByIncludeCredentials); // Splits cache entries by the request's NetworkIsolationKey if one is // available. -NET_EXPORT extern const base::Feature kSplitCacheByNetworkIsolationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kSplitCacheByNetworkIsolationKey); // Splits host cache entries by the DNS request's NetworkIsolationKey if one is // available. Also prevents merging live DNS lookups when there is a NIK // mismatch. -NET_EXPORT extern const base::Feature kSplitHostCacheByNetworkIsolationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kSplitHostCacheByNetworkIsolationKey); // Partitions connections based on the NetworkIsolationKey associated with a // request. -NET_EXPORT extern const base::Feature - kPartitionConnectionsByNetworkIsolationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kPartitionConnectionsByNetworkIsolationKey); // Forces the `frame_origin` value in IsolationInfo to the `top_level_origin` // value when an IsolationInfo instance is created. This is to enable // expirimenting with double keyed network partitions. -NET_EXPORT extern const base::Feature - kForceIsolationInfoFrameOriginToTopLevelFrame; +NET_EXPORT BASE_DECLARE_FEATURE(kForceIsolationInfoFrameOriginToTopLevelFrame); // Partitions HttpServerProperties based on the NetworkIsolationKey associated // with a request. -NET_EXPORT extern const base::Feature - kPartitionHttpServerPropertiesByNetworkIsolationKey; +NET_EXPORT BASE_DECLARE_FEATURE( + kPartitionHttpServerPropertiesByNetworkIsolationKey); // Partitions TLS sessions and QUIC server configs based on the // NetworkIsolationKey associated with a request. // // This feature requires kPartitionConnectionsByNetworkIsolationKey to be // enabled to work. -NET_EXPORT extern const base::Feature - kPartitionSSLSessionsByNetworkIsolationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kPartitionSSLSessionsByNetworkIsolationKey); // Partitions Expect-CT data by NetworkIsolationKey. This only affects the // Expect-CT data itself. Regardless of this value, reports will be uploaded @@ -219,8 +137,7 @@ NET_EXPORT extern const base::Feature // This feature requires kPartitionConnectionsByNetworkIsolationKey, // kPartitionHttpServerPropertiesByNetworkIsolationKey, and // kPartitionConnectionsByNetworkIsolationKey to all be enabled to work. -NET_EXPORT extern const base::Feature - kPartitionExpectCTStateByNetworkIsolationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kPartitionExpectCTStateByNetworkIsolationKey); // Partitions Network Error Logging and Reporting API data by // NetworkIsolationKey. Also partitions all reports generated by other consumers @@ -231,8 +148,7 @@ NET_EXPORT extern const base::Feature // NetworkIsolationKey parameters, and they're cleared while loading from the // cache, but internal objects can be created with them (e.g., endpoints), for // testing. -NET_EXPORT extern const base::Feature - kPartitionNelAndReportingByNetworkIsolationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kPartitionNelAndReportingByNetworkIsolationKey); // Creates a <double key + is_cross_site> NetworkAnonymizationKey which is used // to partition the network state. This double key will have the following @@ -242,18 +158,17 @@ NET_EXPORT extern const base::Feature // to the frame site. The frame site will not be stored in this key so the value // of is_cross_site will be computed at key construction. This feature overrides // `kEnableDoubleKeyNetworkAnonymizationKey` if both are enabled. -NET_EXPORT extern const base::Feature - kEnableCrossSiteFlagNetworkAnonymizationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kEnableCrossSiteFlagNetworkAnonymizationKey); // Creates a double keyed NetworkAnonymizationKey which is used to partition the // network state. This double key will have the following properties: // `top_frame_site` -> the schemeful site of the top level page. // `frame_site ` -> nullopt // `is_cross_site` -> nullopt -NET_EXPORT extern const base::Feature kEnableDoubleKeyNetworkAnonymizationKey; +NET_EXPORT BASE_DECLARE_FEATURE(kEnableDoubleKeyNetworkAnonymizationKey); // Enables limiting the size of Expect-CT table. -NET_EXPORT extern const base::Feature kExpectCTPruning; +NET_EXPORT BASE_DECLARE_FEATURE(kExpectCTPruning); // FeatureParams associated with kExpectCTPruning. @@ -276,25 +191,25 @@ NET_EXPORT extern const base::FeatureParam<int> kExpectCTPruneDelaySecs; // to ensure that this corner of the spec is exercised. This is currently // disabled by default because we discovered incompatibilities with some // servers. -NET_EXPORT extern const base::Feature kTLS13KeyUpdate; +NET_EXPORT BASE_DECLARE_FEATURE(kTLS13KeyUpdate); // Enables permuting TLS extensions in the ClientHello, to reduce the risk of // non-compliant servers ossifying parts of the ClientHello and interfering with // deployment of future security improvements. -NET_EXPORT extern const base::Feature kPermuteTLSExtensions; +NET_EXPORT BASE_DECLARE_FEATURE(kPermuteTLSExtensions); // Enables CECPQ2, a post-quantum key-agreement, in TLS 1.3 connections. -NET_EXPORT extern const base::Feature kPostQuantumCECPQ2; +NET_EXPORT BASE_DECLARE_FEATURE(kPostQuantumCECPQ2); // Enables CECPQ2, a post-quantum key-agreement, in TLS 1.3 connections for a // subset of domains. (This is intended as Finch kill-switch. For testing // compatibility with large ClientHello messages, use |kPostQuantumCECPQ2|.) -NET_EXPORT extern const base::Feature kPostQuantumCECPQ2SomeDomains; +NET_EXPORT BASE_DECLARE_FEATURE(kPostQuantumCECPQ2SomeDomains); NET_EXPORT extern const base::FeatureParam<std::string> kPostQuantumCECPQ2Prefix; // Changes the timeout after which unused sockets idle sockets are cleaned up. -NET_EXPORT extern const base::Feature kNetUnusedIdleSocketTimeout; +NET_EXPORT BASE_DECLARE_FEATURE(kNetUnusedIdleSocketTimeout); // When enabled, the time threshold for Lax-allow-unsafe cookies will be lowered // from 2 minutes to 10 seconds. This time threshold refers to the age cutoff @@ -303,59 +218,46 @@ NET_EXPORT extern const base::Feature kNetUnusedIdleSocketTimeout; // of HTTP method (i.e. allowing unsafe methods). This is a convenience for // integration tests which may want to test behavior of cookies older than the // threshold, but which would not be practical to run for 2 minutes. -NET_EXPORT extern const base::Feature kShortLaxAllowUnsafeThreshold; +NET_EXPORT BASE_DECLARE_FEATURE(kShortLaxAllowUnsafeThreshold); // When enabled, the SameSite by default feature does not add the // "Lax-allow-unsafe" behavior. Any cookies that do not specify a SameSite // attribute will be treated as Lax only, i.e. POST and other unsafe HTTP // methods will not be allowed at all for top-level cross-site navigations. // This only has an effect if the cookie defaults to SameSite=Lax. -NET_EXPORT extern const base::Feature kSameSiteDefaultChecksMethodRigorously; - -#if BUILDFLAG(BUILTIN_CERT_VERIFIER_FEATURE_SUPPORTED) -// When enabled, use the builtin cert verifier instead of the platform verifier. -NET_EXPORT extern const base::Feature kCertVerifierBuiltinFeature; -#if BUILDFLAG(IS_MAC) -NET_EXPORT extern const base::FeatureParam<int> kCertVerifierBuiltinImpl; -NET_EXPORT extern const base::FeatureParam<int> kCertVerifierBuiltinCacheSize; -#endif /* BUILDFLAG(IS_MAC) */ -#endif /* BUILDFLAG(BUILTIN_CERT_VERIFIER_FEATURE_SUPPORTED) */ +NET_EXPORT BASE_DECLARE_FEATURE(kSameSiteDefaultChecksMethodRigorously); #if BUILDFLAG(TRIAL_COMPARISON_CERT_VERIFIER_SUPPORTED) -NET_EXPORT extern const base::Feature kCertDualVerificationTrialFeature; +NET_EXPORT BASE_DECLARE_FEATURE(kCertDualVerificationTrialFeature); #if BUILDFLAG(IS_MAC) NET_EXPORT extern const base::FeatureParam<int> kCertDualVerificationTrialImpl; NET_EXPORT extern const base::FeatureParam<int> kCertDualVerificationTrialCacheSize; #endif /* BUILDFLAG(IS_MAC) */ -#if BUILDFLAG(BUILTIN_CERT_VERIFIER_FEATURE_SUPPORTED) && \ - BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED) -// If both builtin verifier+system roots and builtin verifier+CRS flags are -// supported in the same build, this param can be used to choose which to test -// in the trial. -NET_EXPORT extern const base::FeatureParam<bool> - kCertDualVerificationTrialUseCrs; -#endif #endif /* BUILDFLAG(TRIAL_COMPARISON_CERT_VERIFIER_SUPPORTED) */ #if BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED) // When enabled, use the Chrome Root Store instead of the system root store -NET_EXPORT extern const base::Feature kChromeRootStoreUsed; +NET_EXPORT BASE_DECLARE_FEATURE(kChromeRootStoreUsed); +#if BUILDFLAG(IS_MAC) +NET_EXPORT extern const base::FeatureParam<int> kChromeRootStoreSysImpl; +NET_EXPORT extern const base::FeatureParam<int> kChromeRootStoreSysCacheSize; +#endif /* BUILDFLAG(IS_MAC) */ #endif /* BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED) */ // Turns off streaming media caching to disk when on battery power. -NET_EXPORT extern const base::Feature kTurnOffStreamingMediaCachingOnBattery; +NET_EXPORT BASE_DECLARE_FEATURE(kTurnOffStreamingMediaCachingOnBattery); // Turns off streaming media caching to disk always. -NET_EXPORT extern const base::Feature kTurnOffStreamingMediaCachingAlways; +NET_EXPORT BASE_DECLARE_FEATURE(kTurnOffStreamingMediaCachingAlways); // When enabled this feature will cause same-site calculations to take into // account the scheme of the site-for-cookies and the request/response url. -NET_EXPORT extern const base::Feature kSchemefulSameSite; +NET_EXPORT BASE_DECLARE_FEATURE(kSchemefulSameSite); // Enables a process-wide limit on "open" UDP sockets. See // udp_socket_global_limits.h for details on what constitutes an "open" socket. -NET_EXPORT extern const base::Feature kLimitOpenUDPSockets; +NET_EXPORT BASE_DECLARE_FEATURE(kLimitOpenUDPSockets); // FeatureParams associated with kLimitOpenUDPSockets. @@ -365,7 +267,7 @@ NET_EXPORT extern const base::FeatureParam<int> kLimitOpenUDPSocketsMax; // Enables a timeout on individual TCP connect attempts, based on // the parameter values. -NET_EXPORT extern const base::Feature kTimeoutTcpConnectAttempt; +NET_EXPORT BASE_DECLARE_FEATURE(kTimeoutTcpConnectAttempt); // FeatureParams associated with kTimeoutTcpConnectAttempt. @@ -389,7 +291,7 @@ NET_EXPORT extern const base::FeatureParam<base::TimeDelta> // When enabled this feature will allow a new Reporting-Endpoints header to // configure reporting endpoints for report delivery. This is used to support // the new Document Reporting spec. -NET_EXPORT extern const base::Feature kDocumentReporting; +NET_EXPORT BASE_DECLARE_FEATURE(kDocumentReporting); #endif // BUILDFLAG(ENABLE_REPORTING) #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) @@ -398,7 +300,7 @@ NET_EXPORT extern const base::Feature kDocumentReporting; // This should reduce the number of wake ups and improve battery consumption. // TODO(https://crbug.com/1189805): Cleanup the feature after verifying that it // doesn't negatively affect performance. -NET_EXPORT extern const base::Feature kUdpSocketPosixAlwaysUpdateBytesReceived; +NET_EXPORT BASE_DECLARE_FEATURE(kUdpSocketPosixAlwaysUpdateBytesReceived); #endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) // When this feature is enabled, redirected requests will be considered @@ -407,61 +309,75 @@ NET_EXPORT extern const base::Feature kUdpSocketPosixAlwaysUpdateBytesReceived; // redirected request was same-site with the target URL (and the // site-for-cookies). // See spec changes in https://github.com/httpwg/http-extensions/pull/1348 -NET_EXPORT extern const base::Feature kCookieSameSiteConsidersRedirectChain; +NET_EXPORT BASE_DECLARE_FEATURE(kCookieSameSiteConsidersRedirectChain); + +// When this feature is enabled, the SameParty attribute is enabled. (Note that +// when this feature is disabled, the SameParty attribute is still parsed and +// saved for cookie-sets, but it has no associated semantics (when setting or +// reading cookies).) +NET_EXPORT BASE_DECLARE_FEATURE(kSamePartyAttributeEnabled); // When enabled, cookies with the SameParty attribute are treated as // "first-party" when in same-party contexts, for the purposes of third-party // cookie blocking. (Note that as a consequence, some cookies may be blocked // while others are allowed on a cross-site, same-party request. Additionally, // privacy mode is disabled in same-party contexts.) -NET_EXPORT extern const base::Feature kSamePartyCookiesConsideredFirstParty; +NET_EXPORT BASE_DECLARE_FEATURE(kSamePartyCookiesConsideredFirstParty); // When enabled, sites can opt-in to having their cookies partitioned by // top-level site with the Partitioned attribute. Partitioned cookies will only // be sent when the browser is on the same top-level site that it was on when // the cookie was set. -NET_EXPORT extern const base::Feature kPartitionedCookies; +NET_EXPORT BASE_DECLARE_FEATURE(kPartitionedCookies); // Flag to bypass the origin trial opt-in to use Partitioned cookies. This // allows developers to test Partitioned cookies manually in development // environments. // TODO(crbug.com/1296161): Remove this feature when the CHIPS OT ends. -NET_EXPORT extern const base::Feature kPartitionedCookiesBypassOriginTrial; +NET_EXPORT BASE_DECLARE_FEATURE(kPartitionedCookiesBypassOriginTrial); // When enabled, then we allow partitioned cookies even if kPartitionedCookies // is disabled only if the cookie partition key contains a nonce. So far, this // is used to create temporary cookie jar partitions for fenced and anonymous // frames. -NET_EXPORT extern const base::Feature kNoncedPartitionedCookies; +NET_EXPORT BASE_DECLARE_FEATURE(kNoncedPartitionedCookies); // When enabled, additional cookie-related APIs will perform cookie field size // and character set validation to enforce stricter conformance with RFC6265bis. // TODO(crbug.com/1243852) Eventually enable this permanently and remove the // feature flag, assuming no breakage occurs with it enabled. -NET_EXPORT extern const base::Feature kExtraCookieValidityChecks; +NET_EXPORT BASE_DECLARE_FEATURE(kExtraCookieValidityChecks); // Enable recording UMAs for network activities which can wake-up radio on // Android. -NET_EXPORT extern const base::Feature kRecordRadioWakeupTrigger; +NET_EXPORT BASE_DECLARE_FEATURE(kRecordRadioWakeupTrigger); // When enabled, cookies cannot have an expiry date further than 400 days in the // future. -NET_EXPORT extern const base::Feature kClampCookieExpiryTo400Days; +NET_EXPORT BASE_DECLARE_FEATURE(kClampCookieExpiryTo400Days); // Controls whether static key pinning is enforced. -NET_EXPORT extern const base::Feature kStaticKeyPinningEnforcement; +NET_EXPORT BASE_DECLARE_FEATURE(kStaticKeyPinningEnforcement); // When enabled, cookies with a non-ASCII domain attribute will be rejected. -NET_EXPORT extern const base::Feature kCookieDomainRejectNonASCII; +NET_EXPORT BASE_DECLARE_FEATURE(kCookieDomainRejectNonASCII); // Blocks the 'Set-Cookie' request header on outbound fetch requests. -NET_EXPORT extern const base::Feature kBlockSetCookieHeader; +NET_EXPORT BASE_DECLARE_FEATURE(kBlockSetCookieHeader); -NET_EXPORT extern const base::Feature kOptimizeNetworkBuffers; +NET_EXPORT BASE_DECLARE_FEATURE(kOptimisticBlockfileWrite); + +NET_EXPORT BASE_DECLARE_FEATURE(kOptimizeNetworkBuffers); NET_EXPORT extern const base::FeatureParam<int> kOptimizeNetworkBuffersBytesReadLimit; NET_EXPORT extern const base::FeatureParam<int> + kOptimizeNetworkBuffersMinInputStreamAvailableValueToIgnore; + +NET_EXPORT extern const base::FeatureParam<int> + kOptimizeNetworkBuffersMinInputStreamReadSize; + +NET_EXPORT extern const base::FeatureParam<int> kOptimizeNetworkBuffersMaxInputStreamBytesToReadWhenAvailableUnknown; NET_EXPORT extern const base::FeatureParam<int> @@ -471,7 +387,7 @@ NET_EXPORT extern const base::FeatureParam<bool> kOptimizeNetworkBuffersInputStreamCheckAvailable; // Enable the Storage Access API. https://crbug.com/989663. -NET_EXPORT extern const base::Feature kStorageAccessAPI; +NET_EXPORT BASE_DECLARE_FEATURE(kStorageAccessAPI); // Set the default number of "automatic" implicit storage access grants per // third party origin that can be granted. This can be overridden via @@ -484,8 +400,32 @@ NET_EXPORT extern const base::FeatureParam<int> // granted if the storage is partitioned. NET_EXPORT extern const base::FeatureParam<bool> kStorageAccessAPIGrantsUnpartitionedStorage; +// Whether to auto-grant storage access requests when the top level origin and +// the requesting origin are in the same First-Party Set. +NET_EXPORT extern const base::FeatureParam<bool> + kStorageAccessAPIAutoGrantInFPS; +// Whether to auto-deny storage access requests when the top level origin and +// the requesting origin are not in the same First-Party Set. +NET_EXPORT extern const base::FeatureParam<bool> + kStorageAccessAPIAutoDenyOutsideFPS; + +NET_EXPORT BASE_DECLARE_FEATURE(kThirdPartyStoragePartitioning); + +// Whether ALPS parsing is on for any type of frame. +NET_EXPORT BASE_DECLARE_FEATURE(kAlpsParsing); + +// Whether ALPS parsing is on for client hint parsing specifically. +NET_EXPORT BASE_DECLARE_FEATURE(kAlpsClientHintParsing); + +// Whether to kill the session on Error::kAcceptChMalformed. +NET_EXPORT BASE_DECLARE_FEATURE(kShouldKillSessionOnAcceptChMalformed); + +NET_EXPORT BASE_DECLARE_FEATURE(kCaseInsensitiveCookiePrefix); + +NET_EXPORT BASE_DECLARE_FEATURE(kEnableWebsocketsOverHttp3); -NET_EXPORT extern const base::Feature kThirdPartyStoragePartitioning; +// Whether to do IPv4 to IPv6 address translation for IPv4 literals. +NET_EXPORT BASE_DECLARE_FEATURE(kUseNAT64ForIPv4Literal); } // namespace net::features diff --git a/chromium/net/base/file_stream.cc b/chromium/net/base/file_stream.cc index 038f60cd490..c554ecb25d4 100644 --- a/chromium/net/base/file_stream.cc +++ b/chromium/net/base/file_stream.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/file_stream.h b/chromium/net/base/file_stream.h index 60f58bdd12f..407f5e1fa14 100644 --- a/chromium/net/base/file_stream.h +++ b/chromium/net/base/file_stream.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/file_stream_context.cc b/chromium/net/base/file_stream_context.cc index fabb36e39cf..1b092d9ff08 100644 --- a/chromium/net/base/file_stream_context.cc +++ b/chromium/net/base/file_stream_context.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/file_stream_context.h b/chromium/net/base/file_stream_context.h index 16c2b5000c4..493a9e5a683 100644 --- a/chromium/net/base/file_stream_context.h +++ b/chromium/net/base/file_stream_context.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/file_stream_context_posix.cc b/chromium/net/base/file_stream_context_posix.cc index 0669b466b38..3a48653b943 100644 --- a/chromium/net/base/file_stream_context_posix.cc +++ b/chromium/net/base/file_stream_context_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/file_stream_context_win.cc b/chromium/net/base/file_stream_context_win.cc index 0b1a516375b..93406c97d19 100644 --- a/chromium/net/base/file_stream_context_win.cc +++ b/chromium/net/base/file_stream_context_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/file_stream_unittest.cc b/chromium/net/base/file_stream_unittest.cc index 11b672ce80d..3ad6be356ed 100644 --- a/chromium/net/base/file_stream_unittest.cc +++ b/chromium/net/base/file_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/filename_util.cc b/chromium/net/base/filename_util.cc index ccd0d3dabb7..1fb7fff6ab9 100644 --- a/chromium/net/base/filename_util.cc +++ b/chromium/net/base/filename_util.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/filename_util.h b/chromium/net/base/filename_util.h index c6fa118b6e4..cc31342c2b1 100644 --- a/chromium/net/base/filename_util.h +++ b/chromium/net/base/filename_util.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/filename_util_icu.cc b/chromium/net/base/filename_util_icu.cc index ae061c41117..efecede1c8c 100644 --- a/chromium/net/base/filename_util_icu.cc +++ b/chromium/net/base/filename_util_icu.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/filename_util_internal.cc b/chromium/net/base/filename_util_internal.cc index 33a246bae7e..c128560c8a3 100644 --- a/chromium/net/base/filename_util_internal.cc +++ b/chromium/net/base/filename_util_internal.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/filename_util_internal.h b/chromium/net/base/filename_util_internal.h index 46a8e58e329..831e5a62fc3 100644 --- a/chromium/net/base/filename_util_internal.h +++ b/chromium/net/base/filename_util_internal.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/filename_util_unittest.cc b/chromium/net/base/filename_util_unittest.cc index 239c758053d..664b8bea79c 100644 --- a/chromium/net/base/filename_util_unittest.cc +++ b/chromium/net/base/filename_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/fuzzer_test_support.cc b/chromium/net/base/fuzzer_test_support.cc index a977ebc0ab8..f05a3de0bcc 100644 --- a/chromium/net/base/fuzzer_test_support.cc +++ b/chromium/net/base/fuzzer_test_support.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/hash_value.cc b/chromium/net/base/hash_value.cc index 4a35bdafb1b..14339fb28dd 100644 --- a/chromium/net/base/hash_value.cc +++ b/chromium/net/base/hash_value.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/hash_value.h b/chromium/net/base/hash_value.h index 64b11fc16fb..15b23b88c13 100644 --- a/chromium/net/base/hash_value.h +++ b/chromium/net/base/hash_value.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/hex_utils.cc b/chromium/net/base/hex_utils.cc index ea0a093ab25..8790eeb93e7 100644 --- a/chromium/net/base/hex_utils.cc +++ b/chromium/net/base/hex_utils.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/hex_utils.h b/chromium/net/base/hex_utils.h index 295091e0d2c..e3e73fe6091 100644 --- a/chromium/net/base/hex_utils.h +++ b/chromium/net/base/hex_utils.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/host_mapping_rules.cc b/chromium/net/base/host_mapping_rules.cc index 3cd80277bf2..e9de7436a9a 100644 --- a/chromium/net/base/host_mapping_rules.cc +++ b/chromium/net/base/host_mapping_rules.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright 2010 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/host_mapping_rules.h b/chromium/net/base/host_mapping_rules.h index 356a799b4b8..d81baf4c98b 100644 --- a/chromium/net/base/host_mapping_rules.h +++ b/chromium/net/base/host_mapping_rules.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/host_mapping_rules_unittest.cc b/chromium/net/base/host_mapping_rules_unittest.cc index 82268586b23..7fd1c2abdd0 100644 --- a/chromium/net/base/host_mapping_rules_unittest.cc +++ b/chromium/net/base/host_mapping_rules_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright 2010 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/host_port_pair.cc b/chromium/net/base/host_port_pair.cc index 32e48c53e82..1abe5141d2d 100644 --- a/chromium/net/base/host_port_pair.cc +++ b/chromium/net/base/host_port_pair.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/host_port_pair.h b/chromium/net/base/host_port_pair.h index ae37263ac04..b86d3b2c328 100644 --- a/chromium/net/base/host_port_pair.h +++ b/chromium/net/base/host_port_pair.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/host_port_pair_unittest.cc b/chromium/net/base/host_port_pair_unittest.cc index f50de395813..89907a77193 100644 --- a/chromium/net/base/host_port_pair_unittest.cc +++ b/chromium/net/base/host_port_pair_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/http_user_agent_settings.h b/chromium/net/base/http_user_agent_settings.h index 9fed104e1fa..c3b6762600c 100644 --- a/chromium/net/base/http_user_agent_settings.h +++ b/chromium/net/base/http_user_agent_settings.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/idempotency.h b/chromium/net/base/idempotency.h index d1b394d10b7..42b6895f43f 100644 --- a/chromium/net/base/idempotency.h +++ b/chromium/net/base/idempotency.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/interval.h b/chromium/net/base/interval.h index 8ac3b5e44d8..db318d37976 100644 --- a/chromium/net/base/interval.h +++ b/chromium/net/base/interval.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/net/base/interval_test.cc b/chromium/net/base/interval_test.cc index a0a61170119..7e8359124af 100644 --- a/chromium/net/base/interval_test.cc +++ b/chromium/net/base/interval_test.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/net/base/io_buffer.cc b/chromium/net/base/io_buffer.cc index b61780cbe1b..c3a7c6164a4 100644 --- a/chromium/net/base/io_buffer.cc +++ b/chromium/net/base/io_buffer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/io_buffer.h b/chromium/net/base/io_buffer.h index b8f9a8abc64..aa2b10f6101 100644 --- a/chromium/net/base/io_buffer.h +++ b/chromium/net/base/io_buffer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/ip_address.cc b/chromium/net/base/ip_address.cc index e69bcea5cfd..7ac63312e59 100644 --- a/chromium/net/base/ip_address.cc +++ b/chromium/net/base/ip_address.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -490,4 +490,148 @@ size_t MaskPrefixLength(const IPAddress& mask) { IPAddress(all_ones->data(), all_ones->size())); } +Dns64PrefixLength ExtractPref64FromIpv4onlyArpaAAAA(const IPAddress& address) { + DCHECK(address.IsIPv6()); + IPAddress ipv4onlyarpa0(192, 0, 0, 170); + IPAddress ipv4onlyarpa1(192, 0, 0, 171); + if (std::equal(ipv4onlyarpa0.bytes().begin(), ipv4onlyarpa0.bytes().end(), + address.bytes().begin() + 12u) || + std::equal(ipv4onlyarpa1.bytes().begin(), ipv4onlyarpa1.bytes().end(), + address.bytes().begin() + 12u)) { + return Dns64PrefixLength::k96bit; + } else if (std::equal(ipv4onlyarpa0.bytes().begin(), + ipv4onlyarpa0.bytes().end(), + address.bytes().begin() + 9u) || + std::equal(ipv4onlyarpa1.bytes().begin(), + ipv4onlyarpa1.bytes().end(), + address.bytes().begin() + 9u)) { + return Dns64PrefixLength::k64bit; + } else if ((std::equal(ipv4onlyarpa0.bytes().begin(), + ipv4onlyarpa0.bytes().begin() + 1u, + address.bytes().begin() + 7u) && + std::equal(ipv4onlyarpa0.bytes().begin() + 1u, + ipv4onlyarpa0.bytes().end(), + address.bytes().begin() + 9u)) || + (std::equal(ipv4onlyarpa1.bytes().begin(), + ipv4onlyarpa1.bytes().begin() + 1u, + address.bytes().begin() + 7u) && + std::equal(ipv4onlyarpa1.bytes().begin() + 1u, + ipv4onlyarpa1.bytes().end(), + address.bytes().begin() + 9u))) { + return Dns64PrefixLength::k56bit; + } else if ((std::equal(ipv4onlyarpa0.bytes().begin(), + ipv4onlyarpa0.bytes().begin() + 2u, + address.bytes().begin() + 6u) && + std::equal(ipv4onlyarpa0.bytes().begin() + 2u, + ipv4onlyarpa0.bytes().end(), + address.bytes().begin() + 9u)) || + ((std::equal(ipv4onlyarpa1.bytes().begin(), + ipv4onlyarpa1.bytes().begin() + 2u, + address.bytes().begin() + 6u) && + std::equal(ipv4onlyarpa1.bytes().begin() + 2u, + ipv4onlyarpa1.bytes().end(), + address.bytes().begin() + 9u)))) { + return Dns64PrefixLength::k48bit; + } else if ((std::equal(ipv4onlyarpa0.bytes().begin(), + ipv4onlyarpa0.bytes().begin() + 3u, + address.bytes().begin() + 5u) && + std::equal(ipv4onlyarpa0.bytes().begin() + 3u, + ipv4onlyarpa0.bytes().end(), + address.bytes().begin() + 9u)) || + (std::equal(ipv4onlyarpa1.bytes().begin(), + ipv4onlyarpa1.bytes().begin() + 3u, + address.bytes().begin() + 5u) && + std::equal(ipv4onlyarpa1.bytes().begin() + 3u, + ipv4onlyarpa1.bytes().end(), + address.bytes().begin() + 9u))) { + return Dns64PrefixLength::k40bit; + } else if (std::equal(ipv4onlyarpa0.bytes().begin(), + ipv4onlyarpa0.bytes().end(), + address.bytes().begin() + 4u) || + std::equal(ipv4onlyarpa1.bytes().begin(), + ipv4onlyarpa1.bytes().end(), + address.bytes().begin() + 4u)) { + return Dns64PrefixLength::k32bit; + } else { + // if ipv4onlyarpa address is not found return 0 + return Dns64PrefixLength::kInvalid; + } +} + +IPAddress ConvertIPv4ToIPv4EmbeddedIPv6(const IPAddress& ipv4_address, + const IPAddress& ipv6_address, + Dns64PrefixLength prefix_length) { + DCHECK(ipv4_address.IsIPv4()); + DCHECK(ipv6_address.IsIPv6()); + + base::StackVector<uint8_t, 16> bytes; + + uint8_t zero_bits[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + switch (prefix_length) { + case Dns64PrefixLength::k96bit: + bytes->insert(bytes->end(), ipv6_address.bytes().begin(), + ipv6_address.bytes().begin() + 12u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin(), + ipv4_address.bytes().end()); + return IPAddress(bytes->data(), bytes->size()); + case Dns64PrefixLength::k64bit: + bytes->insert(bytes->end(), ipv6_address.bytes().begin(), + ipv6_address.bytes().begin() + 8u); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 1u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin(), + ipv4_address.bytes().end()); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 3u); + return IPAddress(bytes->data(), bytes->size()); + case Dns64PrefixLength::k56bit: + bytes->insert(bytes->end(), ipv6_address.bytes().begin(), + ipv6_address.bytes().begin() + 7u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin(), + ipv4_address.bytes().begin() + 1u); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 1u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin() + 1u, + ipv4_address.bytes().end()); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 4u); + return IPAddress(bytes->data(), bytes->size()); + case Dns64PrefixLength::k48bit: + bytes->insert(bytes->end(), ipv6_address.bytes().begin(), + ipv6_address.bytes().begin() + 6u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin(), + ipv4_address.bytes().begin() + 2u); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 1u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin() + 2u, + ipv4_address.bytes().end()); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 5u); + return IPAddress(bytes->data(), bytes->size()); + case Dns64PrefixLength::k40bit: + bytes->insert(bytes->end(), ipv6_address.bytes().begin(), + ipv6_address.bytes().begin() + 5u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin(), + ipv4_address.bytes().begin() + 3u); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 1u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin() + 3u, + ipv4_address.bytes().end()); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 6u); + return IPAddress(bytes->data(), bytes->size()); + case Dns64PrefixLength::k32bit: + bytes->insert(bytes->end(), ipv6_address.bytes().begin(), + ipv6_address.bytes().begin() + 4u); + bytes->insert(bytes->end(), ipv4_address.bytes().begin(), + ipv4_address.bytes().end()); + bytes->insert(bytes->end(), std::begin(zero_bits), + std::begin(zero_bits) + 8u); + return IPAddress(bytes->data(), bytes->size()); + case Dns64PrefixLength::kInvalid: + return ipv4_address; + } +} + } // namespace net diff --git a/chromium/net/base/ip_address.h b/chromium/net/base/ip_address.h index b6a5657eedb..ea00438f199 100644 --- a/chromium/net/base/ip_address.h +++ b/chromium/net/base/ip_address.h @@ -1,4 +1,4 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -293,6 +293,53 @@ bool IPAddressStartsWith(const IPAddress& address, const uint8_t (&prefix)[N]) { return std::equal(prefix, prefix + N, address.bytes().begin()); } +// According to RFC6052 Section 2.2 IPv4-Embedded IPv6 Address Format. +// https://www.rfc-editor.org/rfc/rfc6052#section-2.2 +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// |PL| 0-------------32--40--48--56--64--72--80--88--96--104---------| +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// |32| prefix |v4(32) | u | suffix | +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// |40| prefix |v4(24) | u |(8)| suffix | +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// |48| prefix |v4(16) | u | (16) | suffix | +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// |56| prefix |(8)| u | v4(24) | suffix | +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// |64| prefix | u | v4(32) | suffix | +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// |96| prefix | v4(32) | +// +--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +// +// The NAT64/DNS64 translation prefixes has one of the following lengths. +enum class Dns64PrefixLength { + k32bit, + k40bit, + k48bit, + k56bit, + k64bit, + k96bit, + kInvalid +}; + +// Extracts the NAT64 translation prefix from the IPv6 address using the well +// known address ipv4only.arpa 192.0.0.170 and 192.0.0.171. +// Returns prefix length on success, or Dns64PrefixLength::kInvalid on failure +// (when the ipv4only.arpa IPv4 address is not found) +NET_EXPORT Dns64PrefixLength +ExtractPref64FromIpv4onlyArpaAAAA(const IPAddress& address); + +// Converts an IPv4 address to an IPv4-embedded IPv6 address using the given +// prefix. For example 192.168.0.1 and 64:ff9b::/96 would be converted to +// 64:ff9b::192.168.0.1 +// Returns converted IPv6 address when prefix_length is not +// Dns64PrefixLength::kInvalid, and returns the original IPv4 address when +// prefix_length is Dns64PrefixLength::kInvalid. +NET_EXPORT IPAddress +ConvertIPv4ToIPv4EmbeddedIPv6(const IPAddress& ipv4_address, + const IPAddress& ipv6_address, + Dns64PrefixLength prefix_length); + } // namespace net #endif // NET_BASE_IP_ADDRESS_H_ diff --git a/chromium/net/base/ip_address_unittest.cc b/chromium/net/base/ip_address_unittest.cc index 3c8baea9d3a..1345bcd7806 100644 --- a/chromium/net/base/ip_address_unittest.cc +++ b/chromium/net/base/ip_address_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -677,6 +677,160 @@ TEST(IPAddressTest, IsLinkLocal) { } } +// Tests extraction of the NAT64 translation prefix. +TEST(IPAddressTest, ExtractPref64FromIpv4onlyArpaAAAA) { + // Well Known Prefix 64:ff9b::/96. + IPAddress ipv6_address_WKP_0(0, 100, 255, 155, 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, + 0, 170); + IPAddress ipv6_address_WKP_1(0, 100, 255, 155, 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, + 0, 171); + Dns64PrefixLength pref64_length_WKP_0 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_WKP_0); + Dns64PrefixLength pref64_length_WKP_1 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_WKP_1); + EXPECT_EQ(Dns64PrefixLength::k96bit, pref64_length_WKP_0); + EXPECT_EQ(Dns64PrefixLength::k96bit, pref64_length_WKP_1); + + // Prefix length 96 + IPAddress ipv6_address_96_0(32, 1, 13, 184, 1, 34, 3, 68, 0, 0, 0, 0, 192, 0, + 0, 170); + IPAddress ipv6_address_96_1(32, 1, 13, 184, 1, 34, 3, 68, 0, 0, 0, 0, 192, 0, + 0, 171); + Dns64PrefixLength pref64_length_96_0 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_96_0); + Dns64PrefixLength pref64_length_96_1 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_96_1); + EXPECT_EQ(Dns64PrefixLength::k96bit, pref64_length_96_0); + EXPECT_EQ(Dns64PrefixLength::k96bit, pref64_length_96_1); + + // Prefix length 64 + IPAddress ipv6_address_64_0(32, 1, 13, 184, 1, 34, 3, 68, 0, 192, 0, 0, 170, + 0, 0, 0); + IPAddress ipv6_address_64_1(32, 1, 13, 184, 1, 34, 3, 68, 0, 192, 0, 0, 171, + 0, 0, 0); + Dns64PrefixLength pref64_length_64_0 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_64_0); + Dns64PrefixLength pref64_length_64_1 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_64_1); + EXPECT_EQ(Dns64PrefixLength::k64bit, pref64_length_64_0); + EXPECT_EQ(Dns64PrefixLength::k64bit, pref64_length_64_1); + + // Prefix length 56 + IPAddress ipv6_address_56_0(32, 1, 13, 184, 1, 34, 3, 192, 0, 0, 0, 170, 0, 0, + 0, 0); + IPAddress ipv6_address_56_1(32, 1, 13, 184, 1, 34, 3, 192, 0, 0, 0, 171, 0, 0, + 0, 0); + Dns64PrefixLength pref64_length_56_0 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_56_0); + Dns64PrefixLength pref64_length_56_1 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_56_1); + EXPECT_EQ(Dns64PrefixLength::k56bit, pref64_length_56_0); + EXPECT_EQ(Dns64PrefixLength::k56bit, pref64_length_56_1); + + // Prefix length 48 + IPAddress ipv6_address_48_0(32, 1, 13, 184, 1, 34, 192, 0, 0, 0, 170, 0, 0, 0, + 0, 0); + IPAddress ipv6_address_48_1(32, 1, 13, 184, 1, 34, 192, 0, 0, 0, 171, 0, 0, 0, + 0, 0); + Dns64PrefixLength pref64_length_48_0 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_48_0); + Dns64PrefixLength pref64_length_48_1 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_48_1); + EXPECT_EQ(Dns64PrefixLength::k48bit, pref64_length_48_0); + EXPECT_EQ(Dns64PrefixLength::k48bit, pref64_length_48_1); + + // Prefix length 40 + IPAddress ipv6_address_40_0(32, 1, 13, 184, 1, 192, 0, 0, 0, 170, 0, 0, 0, 0, + 0, 0); + IPAddress ipv6_address_40_1(32, 1, 13, 184, 1, 192, 0, 0, 0, 171, 0, 0, 0, 0, + 0, 0); + Dns64PrefixLength pref64_length_40_0 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_40_0); + Dns64PrefixLength pref64_length_40_1 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_40_1); + EXPECT_EQ(Dns64PrefixLength::k40bit, pref64_length_40_0); + EXPECT_EQ(Dns64PrefixLength::k40bit, pref64_length_40_1); + + // Prefix length 32 + IPAddress ipv6_address_32_0(32, 1, 13, 184, 192, 0, 0, 170, 0, 0, 0, 0, 0, 0, + 0, 0); + IPAddress ipv6_address_32_1(32, 1, 13, 184, 192, 0, 0, 171, 0, 0, 0, 0, 0, 0, + 0, 0); + Dns64PrefixLength pref64_length_32_0 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_32_0); + Dns64PrefixLength pref64_length_32_1 = + ExtractPref64FromIpv4onlyArpaAAAA(ipv6_address_32_1); + EXPECT_EQ(Dns64PrefixLength::k32bit, pref64_length_32_0); + EXPECT_EQ(Dns64PrefixLength::k32bit, pref64_length_32_1); +} + +// Tests mapping an IPv4 address to an IPv6 address. +TEST(IPAddressTest, ConvertIPv4ToIPv4EmbeddedIPv6) { + IPAddress ipv4_address(192, 0, 2, 33); + + // Well Known Prefix 64:ff9b::/96. + IPAddress ipv6_address_WKP(0, 100, 255, 155, 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, + 0, 170); + IPAddress converted_ipv6_address_WKP = ConvertIPv4ToIPv4EmbeddedIPv6( + ipv4_address, ipv6_address_WKP, Dns64PrefixLength::k96bit); + EXPECT_EQ("0,100,255,155,0,0,0,0,0,0,0,0,192,0,2,33", + DumpIPAddress(converted_ipv6_address_WKP)); + EXPECT_EQ("64:ff9b::c000:221", converted_ipv6_address_WKP.ToString()); + + // Prefix length 96 + IPAddress ipv6_address_96(32, 1, 13, 184, 1, 34, 3, 68, 0, 0, 0, 0, 0, 0, 0, + 0); + IPAddress converted_ipv6_address_96 = ConvertIPv4ToIPv4EmbeddedIPv6( + ipv4_address, ipv6_address_96, Dns64PrefixLength::k96bit); + EXPECT_EQ("32,1,13,184,1,34,3,68,0,0,0,0,192,0,2,33", + DumpIPAddress(converted_ipv6_address_96)); + EXPECT_EQ("2001:db8:122:344::c000:221", converted_ipv6_address_96.ToString()); + + // Prefix length 64 + IPAddress ipv6_address_64(32, 1, 13, 184, 1, 34, 3, 68, 0, 0, 0, 0, 0, 0, 0, + 0); + IPAddress converted_ipv6_address_64 = ConvertIPv4ToIPv4EmbeddedIPv6( + ipv4_address, ipv6_address_64, Dns64PrefixLength::k64bit); + EXPECT_EQ("32,1,13,184,1,34,3,68,0,192,0,2,33,0,0,0", + DumpIPAddress(converted_ipv6_address_64)); + EXPECT_EQ("2001:db8:122:344:c0:2:2100:0", + converted_ipv6_address_64.ToString()); + + // Prefix length 56 + IPAddress ipv6_address_56(32, 1, 13, 184, 1, 34, 3, 0, 0, 0, 0, 0, 0, 0, 0, + 0); + IPAddress converted_ipv6_address_56 = ConvertIPv4ToIPv4EmbeddedIPv6( + ipv4_address, ipv6_address_56, Dns64PrefixLength::k56bit); + EXPECT_EQ("32,1,13,184,1,34,3,192,0,0,2,33,0,0,0,0", + DumpIPAddress(converted_ipv6_address_56)); + EXPECT_EQ("2001:db8:122:3c0:0:221::", converted_ipv6_address_56.ToString()); + + // Prefix length 48 + IPAddress ipv6_address_48(32, 1, 13, 184, 1, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0); + IPAddress converted_ipv6_address_48 = ConvertIPv4ToIPv4EmbeddedIPv6( + ipv4_address, ipv6_address_48, Dns64PrefixLength::k48bit); + EXPECT_EQ("32,1,13,184,1,34,192,0,0,2,33,0,0,0,0,0", + DumpIPAddress(converted_ipv6_address_48)); + EXPECT_EQ("2001:db8:122:c000:2:2100::", converted_ipv6_address_48.ToString()); + + // Prefix length 40 + IPAddress ipv6_address_40(32, 1, 13, 184, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + IPAddress converted_ipv6_address_40 = ConvertIPv4ToIPv4EmbeddedIPv6( + ipv4_address, ipv6_address_40, Dns64PrefixLength::k40bit); + EXPECT_EQ("32,1,13,184,1,192,0,2,0,33,0,0,0,0,0,0", + DumpIPAddress(converted_ipv6_address_40)); + EXPECT_EQ("2001:db8:1c0:2:21::", converted_ipv6_address_40.ToString()); + + // Prefix length 32 + IPAddress ipv6_address_32(32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + IPAddress converted_ipv6_address_32 = ConvertIPv4ToIPv4EmbeddedIPv6( + ipv4_address, ipv6_address_32, Dns64PrefixLength::k32bit); + EXPECT_EQ("32,1,13,184,192,0,2,33,0,0,0,0,0,0,0,0", + DumpIPAddress(converted_ipv6_address_32)); + EXPECT_EQ("2001:db8:c000:221::", converted_ipv6_address_32.ToString()); +} + } // anonymous namespace } // namespace net diff --git a/chromium/net/base/ip_endpoint.cc b/chromium/net/base/ip_endpoint.cc index 27da99b90bf..05466120b1c 100644 --- a/chromium/net/base/ip_endpoint.cc +++ b/chromium/net/base/ip_endpoint.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/ip_endpoint.h b/chromium/net/base/ip_endpoint.h index ef9547a640b..8e0f8a50638 100644 --- a/chromium/net/base/ip_endpoint.h +++ b/chromium/net/base/ip_endpoint.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/ip_endpoint_unittest.cc b/chromium/net/base/ip_endpoint_unittest.cc index afa1ad512db..fc100b22878 100644 --- a/chromium/net/base/ip_endpoint_unittest.cc +++ b/chromium/net/base/ip_endpoint_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/isolation_info.cc b/chromium/net/base/isolation_info.cc index 3380ec1dd8c..a6fc72fc160 100644 --- a/chromium/net/base/isolation_info.cc +++ b/chromium/net/base/isolation_info.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,9 +8,11 @@ #include "base/check_op.h" #include "base/unguessable_token.h" -#include "isolation_info.h" #include "net/base/features.h" +#include "net/base/isolation_info.h" #include "net/base/isolation_info.pb.h" +#include "net/base/network_anonymization_key.h" +#include "net/base/proxy_server.h" #include "third_party/abseil-cpp/absl/types/optional.h" namespace net { @@ -185,14 +187,12 @@ IsolationInfo IsolationInfo::CreatePartial( // TODO(https://crbug.com/1148927): Use null origins in this case. url::Origin top_frame_origin = network_isolation_key.GetTopFrameSite()->site_as_origin_; - url::Origin frame_origin; + absl::optional<url::Origin> frame_origin; if (IsFrameSiteEnabled() && network_isolation_key.GetFrameSite().has_value()) { frame_origin = network_isolation_key.GetFrameSite()->site_as_origin_; - } else if (request_type == RequestType::kMainFrame) { - frame_origin = top_frame_origin; } else { - frame_origin = url::Origin(); + frame_origin = absl::nullopt; } const base::UnguessableToken* nonce = @@ -205,6 +205,48 @@ IsolationInfo IsolationInfo::CreatePartial( absl::nullopt /* party_context */); } +IsolationInfo IsolationInfo::DoNotUseCreatePartialFromNak( + const net::NetworkAnonymizationKey& network_anonymization_key) { + if (!network_anonymization_key.IsFullyPopulated()) { + return IsolationInfo(); + } + + url::Origin top_frame_origin = + network_anonymization_key.GetTopFrameSite()->site_as_origin_; + + absl::optional<url::Origin> frame_origin; + if (NetworkAnonymizationKey::IsFrameSiteEnabled() && + network_anonymization_key.GetFrameSite().has_value()) { + // If frame site is set on the network anonymization key, use it to set the + // frame origin on the isolation info. + frame_origin = network_anonymization_key.GetFrameSite()->site_as_origin_; + } else if (NetworkAnonymizationKey::IsCrossSiteFlagSchemeEnabled() && + network_anonymization_key.GetIsCrossSite().value()) { + // If frame site is not set on the network anonymization key but we know + // that it is cross site to the top level site, create an empty origin to + // use as the frame origin for the isolation info. This should be cross site + // with the top level origin. + frame_origin = url::Origin(); + } else { + // If frame sit is not set on the network anonymization key and we don't + // know that it's cross site to the top level site, use the top frame site + // to set the frame origin. + frame_origin = top_frame_origin; + } + + const base::UnguessableToken* nonce = + network_anonymization_key.GetNonce() + ? &network_anonymization_key.GetNonce().value() + : nullptr; + + auto isolation_info = IsolationInfo::Create( + IsolationInfo::RequestType::kOther, top_frame_origin, + frame_origin.value(), SiteForCookies(), + /*party_context=*/absl::nullopt, nonce); + // TODO(crbug/1343856): DCHECK isolation info is fully populated. + return isolation_info; +} + absl::optional<IsolationInfo> IsolationInfo::CreateIfConsistent( RequestType request_type, const absl::optional<url::Origin>& top_frame_origin, @@ -240,8 +282,13 @@ IsolationInfo IsolationInfo::CreateForRedirect( } const absl::optional<url::Origin>& IsolationInfo::frame_origin() const { - // TODO: @brgoldstein, add CHECK that - // `kForceIsolationInfoFrameOriginToTopLevelFrame` is not enabled. + // Frame origin will be empty if double-keying is enabled. + CHECK(IsolationInfo::IsFrameSiteEnabled()); + return frame_origin_; +} + +const absl::optional<url::Origin>& IsolationInfo::frame_origin_for_testing() + const { return frame_origin_; } @@ -250,6 +297,7 @@ bool IsolationInfo::IsEqualForTesting(const IsolationInfo& other) const { top_frame_origin_ == other.top_frame_origin_ && frame_origin_ == other.frame_origin_ && network_isolation_key_ == other.network_isolation_key_ && + network_anonymization_key_ == other.network_anonymization_key_ && nonce_ == other.nonce_ && site_for_cookies_.IsEquivalent(other.site_for_cookies_) && party_context_ == other.party_context_); @@ -295,6 +343,44 @@ bool IsolationInfo::IsFrameSiteEnabled() { net::features::kForceIsolationInfoFrameOriginToTopLevelFrame); } +NetworkAnonymizationKey +IsolationInfo::CreateNetworkAnonymizationKeyForIsolationInfo( + const absl::optional<url::Origin>& top_frame_origin, + const absl::optional<url::Origin>& frame_origin, + const base::UnguessableToken* nonce) const { + if (!top_frame_origin) { + return NetworkAnonymizationKey(); + } + + // When IsolationInfo::IsFrameSiteEnabled and + // NetworkAnonymizationKey::IsFrameSiteEnabled set the `nak_frame_site` to the + // passed value. When NetworkAnonymizationKey::IsFrameSiteEnabled is false set + // the `nak_frame_site` to nullopt. When IsolationInfo::IsFrameSiteEnabled is + // false but NetworkAnonymizationKey::IsFrameSiteEnabled is true we might have + // the frame_site passed correctly to the constructor OR we might have created + // a double key in which case we cannot determine the `nak_frame_site`. + absl::optional<SchemefulSite> nak_frame_site = + NetworkAnonymizationKey::IsFrameSiteEnabled() && frame_origin.has_value() + ? absl::make_optional((SchemefulSite(*frame_origin))) + : absl::nullopt; + + bool nak_is_cross_site; + if (frame_origin) { + SiteForCookies site_for_cookies = + net::SiteForCookies::FromOrigin(top_frame_origin.value()); + nak_is_cross_site = !site_for_cookies.IsFirstParty(frame_origin->GetURL()); + } else { + // If we are unable to determine if the frame is cross site we should create + // it as cross site. + nak_is_cross_site = true; + } + + return NetworkAnonymizationKey( + SchemefulSite(*top_frame_origin), nak_frame_site, + absl::make_optional(nak_is_cross_site), + nonce ? absl::make_optional(*nonce) : absl::nullopt); +} + IsolationInfo::IsolationInfo( RequestType request_type, const absl::optional<url::Origin>& top_frame_origin, @@ -313,6 +399,10 @@ IsolationInfo::IsolationInfo( ? SchemefulSite(*frame_origin) : SchemefulSite(), nonce)), + network_anonymization_key_( + CreateNetworkAnonymizationKeyForIsolationInfo(top_frame_origin, + frame_origin, + nonce)), site_for_cookies_(site_for_cookies), nonce_(nonce ? absl::make_optional(*nonce) : absl::nullopt), party_context_(party_context.has_value() && diff --git a/chromium/net/base/isolation_info.h b/chromium/net/base/isolation_info.h index 2a5e3946e49..2c1e01ca23b 100644 --- a/chromium/net/base/isolation_info.h +++ b/chromium/net/base/isolation_info.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ #include "base/unguessable_token.h" #include "net/base/net_export.h" +#include "net/base/network_anonymization_key.h" #include "net/base/network_isolation_key.h" #include "net/cookies/site_for_cookies.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -142,6 +143,11 @@ class NET_EXPORT IsolationInfo { RequestType request_type, const net::NetworkIsolationKey& network_isolation_key); + // TODO(crbug/1372769): Remove this and create a safer way to ensure NIKs + // created from NAKs aren't used by accident. + static IsolationInfo DoNotUseCreatePartialFromNak( + const net::NetworkAnonymizationKey& network_anonymization_key); + // Returns nullopt if the arguments are not consistent. Otherwise, returns a // fully populated IsolationInfo. Any IsolationInfo that can be created by // the other construction methods, including the 0-argument constructor, is @@ -187,6 +193,10 @@ class NET_EXPORT IsolationInfo { return network_isolation_key_; } + const NetworkAnonymizationKey& network_anonymization_key() const { + return network_anonymization_key_; + } + const absl::optional<base::UnguessableToken>& nonce() const { return nonce_; } // The value that should be consulted for the third-party cookie blocking @@ -197,6 +207,11 @@ class NET_EXPORT IsolationInfo { // policy. It MUST NEVER be used for any kind of SECURITY check. const SiteForCookies& site_for_cookies() const { return site_for_cookies_; } + // Do not use outside of testing. Returns the `frame_origin_` if + // `kForceIsolationInfoFrameOriginToTopLevelFrame` is disabled. Else it + // returns the `top_frame_origin_` value. + const absl::optional<url::Origin>& frame_origin_for_testing() const; + // Return |party_context| which exclude the top frame origin and the frame // origin. // TODO(mmenke): Make this function PartyContextForTesting() after switching @@ -208,6 +223,11 @@ class NET_EXPORT IsolationInfo { bool IsEqualForTesting(const IsolationInfo& other) const; + NetworkAnonymizationKey CreateNetworkAnonymizationKeyForIsolationInfo( + const absl::optional<url::Origin>& top_frame_origin, + const absl::optional<url::Origin>& frame_origin, + const base::UnguessableToken* nonce) const; + // Serialize the `IsolationInfo` into a string. Fails if transient, returning // an empty string. std::string Serialize() const; @@ -231,7 +251,9 @@ class NET_EXPORT IsolationInfo { // This can be deduced from the two origins above, but keep a cached version // to avoid repeated eTLD+1 calculations, when this is using eTLD+1. - net::NetworkIsolationKey network_isolation_key_; + NetworkIsolationKey network_isolation_key_; + + NetworkAnonymizationKey network_anonymization_key_; SiteForCookies site_for_cookies_; diff --git a/chromium/net/base/isolation_info.proto b/chromium/net/base/isolation_info.proto index 252b738245d..9a769ab079c 100644 --- a/chromium/net/base/isolation_info.proto +++ b/chromium/net/base/isolation_info.proto @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/isolation_info_unittest.cc b/chromium/net/base/isolation_info_unittest.cc index 43c1b718a5c..2b5b8a2cdc4 100644 --- a/chromium/net/base/isolation_info_unittest.cc +++ b/chromium/net/base/isolation_info_unittest.cc @@ -1,13 +1,16 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/isolation_info.h" -#include <optional> +#include <iostream> +#include "base/test/gtest_util.h" #include "base/test/scoped_feature_list.h" #include "base/unguessable_token.h" +#include "isolation_info.h" #include "net/base/features.h" +#include "net/base/network_anonymization_key.h" #include "net/base/network_isolation_key.h" #include "net/base/schemeful_site.h" #include "net/cookies/site_for_cookies.h" @@ -19,22 +22,92 @@ namespace net { +// `IsolationInfoEnabledFeatureFlagsTestingParam ` allows enabling and disabling +// the feature flags that control the key schemes for IsolationInfo, +// NetworkIsolationKey and Network AnonymizationKey. This allows us to test the +// possible combinations of flags that will be allowed for experimentation. +// Those possible combinations are outlined below. When a property is `true` the +// flag that enables this scheme will be enabled for testing. When the bool +// parameter is `false` the flag that enables the scheme will be disabled. +struct IsolationInfoEnabledFeatureFlagsTestingParam { + const bool enableDoubleKeyNetworkAnonymizationKey; + const bool enableDoubleKeyIsolationInfo; + const bool enableDoubleKeyAndCrossSiteBitNetworkAnonymizationKey; +}; + +// The three cases we need to account for: +// 0. Triple-keying is enabled for both IsolationInfo and +// NetworkAnonymizationKey. +// 1. Double-keying is enabled for both IsolationInfo and +// NetworkAnonymizationKey. +// 2. Triple-keying is enabled for IsolationInfo and double-keying is enabled +// for NetworkAnonymizationKey. +// 3. Triple-keying is enabled for IsolationInfo and double-keying + +// cross-site-bit is enabled for NetworkAnonymizationKey. +// Note: At the current time double-keyed IsolationInfo is only supported when +// double-keying or double-keying + is cross site bit are enabled for +// NetworkAnonymizationKey. +const IsolationInfoEnabledFeatureFlagsTestingParam kFlagsParam[] = { + {/*enableDoubleKeyNetworkAnonymizationKey=*/false, + /*enableDoubleKeyIsolationInfo=*/false, + /*enableDoubleKeyAndCrossSiteBitNetworkAnonymizationKey=*/false}, + {/*enableDoubleKeyNetworkAnonymizationKey=*/true, + /*enableDoubleKeyIsolationInfo=*/true, + /*enableDoubleKeyAndCrossSiteBitNetworkAnonymizationKey=*/false}, + {/*enableDoubleKeyNetworkAnonymizationKey=*/true, + /*enableDoubleKeyIsolationInfo=*/false, + /*enableDoubleKeyAndCrossSiteBitNetworkAnonymizationKey=*/false}, + {/*enableDoubleKeyNetworkAnonymizationKey=*/false, + /*enableDoubleKeyIsolationInfo=*/false, + /*enableDoubleKeyAndCrossSiteBitNetworkAnonymizationKey=*/true}}; + namespace { class IsolationInfoTest : public testing::Test, - public testing::WithParamInterface<bool> { + public testing::WithParamInterface< + IsolationInfoEnabledFeatureFlagsTestingParam> { public: IsolationInfoTest() { - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - scoped_feature_list_.InitAndEnableFeature( + std::vector<base::test::FeatureRef> enabled_features = {}; + std::vector<base::test::FeatureRef> disabled_features = {}; + + if (IsDoubleKeyIsolationInfoEnabled()) { + enabled_features.push_back( net::features::kForceIsolationInfoFrameOriginToTopLevelFrame); } else { - scoped_feature_list_.InitAndDisableFeature( + disabled_features.push_back( net::features::kForceIsolationInfoFrameOriginToTopLevelFrame); } + + if (IsDoubleKeyNetworkAnonymizationKeyEnabled()) { + enabled_features.push_back( + net::features::kEnableDoubleKeyNetworkAnonymizationKey); + } else { + disabled_features.push_back( + net::features::kEnableDoubleKeyNetworkAnonymizationKey); + } + + if (IsDoubleKeyAndCrossSiteBitNetworkAnonymizationKeyEnabled()) { + enabled_features.push_back( + net::features::kEnableCrossSiteFlagNetworkAnonymizationKey); + } else { + disabled_features.push_back( + net::features::kEnableCrossSiteFlagNetworkAnonymizationKey); + } + + scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features); } - static bool ForceIsolationInfoFrameOriginToTopLevelFrameEnabled() { - return GetParam(); + + static bool IsDoubleKeyIsolationInfoEnabled() { + return GetParam().enableDoubleKeyIsolationInfo; + } + + static bool IsDoubleKeyNetworkAnonymizationKeyEnabled() { + return GetParam().enableDoubleKeyNetworkAnonymizationKey; + } + + static bool IsDoubleKeyAndCrossSiteBitNetworkAnonymizationKeyEnabled() { + return GetParam().enableDoubleKeyAndCrossSiteBitNetworkAnonymizationKey; } const url::Origin kOrigin1 = url::Origin::Create(GURL("https://a.foo.test")); @@ -65,19 +138,18 @@ class IsolationInfoTest : public testing::Test, base::test::ScopedFeatureList scoped_feature_list_; }; -INSTANTIATE_TEST_SUITE_P( - All, - IsolationInfoTest, - /*force_isolation_info_frame_origin_to_top_level_frame=*/testing::Bool()); +INSTANTIATE_TEST_SUITE_P(All, + IsolationInfoTest, + /*IsolationInfoEnabledFeatureFlagsTestingParam */ + testing::ValuesIn(kFlagsParam)); void DuplicateAndCompare(const IsolationInfo& isolation_info) { absl::optional<IsolationInfo> duplicate_isolation_info = IsolationInfo::CreateIfConsistent( isolation_info.request_type(), isolation_info.top_frame_origin(), - IsolationInfoTest:: - ForceIsolationInfoFrameOriginToTopLevelFrameEnabled() - ? absl::nullopt - : isolation_info.frame_origin(), + net::IsolationInfo::IsFrameSiteEnabled() + ? isolation_info.frame_origin() + : absl::nullopt, isolation_info.site_for_cookies(), isolation_info.party_context(), isolation_info.nonce().has_value() ? &isolation_info.nonce().value() : nullptr); @@ -87,19 +159,104 @@ void DuplicateAndCompare(const IsolationInfo& isolation_info) { } TEST_P(IsolationInfoTest, IsFrameSiteEnabled) { - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { + if (IsDoubleKeyIsolationInfoEnabled()) { EXPECT_FALSE(IsolationInfo::IsFrameSiteEnabled()); } else { EXPECT_TRUE(IsolationInfo::IsFrameSiteEnabled()); } } +TEST_P(IsolationInfoTest, CreateNetworkAnonymizationKeyForIsolationInfo) { + IsolationInfo isolation_info = IsolationInfo::Create( + IsolationInfo::RequestType::kMainFrame, kOrigin1, kOrigin2, + SiteForCookies::FromOrigin(kOrigin1), kPartyContextEmpty, &kNonce1); + NetworkAnonymizationKey nak = + isolation_info.CreateNetworkAnonymizationKeyForIsolationInfo( + kOrigin1, kOrigin2, &kNonce1); + + IsolationInfo same_site_isolation_info = IsolationInfo::Create( + IsolationInfo::RequestType::kMainFrame, kOrigin1, kOrigin1, + SiteForCookies::FromOrigin(kOrigin1), kPartyContextEmpty, &kNonce1); + + // Top frame should be populated regardless of scheme. + EXPECT_EQ(nak.GetTopFrameSite(), SchemefulSite(kOrigin1)); + EXPECT_EQ(isolation_info.top_frame_origin(), kOrigin1); + EXPECT_EQ(isolation_info.network_anonymization_key().GetTopFrameSite(), + SchemefulSite(kOrigin1)); + + // Nonce should be empty regardless of scheme + EXPECT_EQ(nak.GetNonce().value(), kNonce1); + EXPECT_EQ(isolation_info.network_anonymization_key().GetNonce().value(), + kNonce1); + EXPECT_EQ(isolation_info.nonce().value(), kNonce1); + + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() && + !IsDoubleKeyAndCrossSiteBitNetworkAnonymizationKeyEnabled() && + IsDoubleKeyIsolationInfoEnabled()) { + // Double-keyed IsolationInfo + double-keyed NetworkAnonymizationKey case. + EXPECT_DEATH_IF_SUPPORTED(nak.GetFrameSite(), ""); + EXPECT_EQ(absl::nullopt, nak.GetFrameSiteForTesting()); + EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); + EXPECT_DEATH_IF_SUPPORTED( + isolation_info.network_anonymization_key().GetFrameSite(), ""); + EXPECT_EQ( + absl::nullopt, + isolation_info.network_anonymization_key().GetFrameSiteForTesting()); + // EXPECT_DCHECK_DEATH( + // isolation_info.network_anonymization_key().GetIsCrossSite()); + } else if (!IsDoubleKeyIsolationInfoEnabled() && + !IsDoubleKeyAndCrossSiteBitNetworkAnonymizationKeyEnabled() && + IsDoubleKeyNetworkAnonymizationKeyEnabled()) { + // Triple-keyed IsolationInfo + double-keyed NetworkAnonymizationKey case. + EXPECT_DEATH_IF_SUPPORTED(nak.GetFrameSite(), ""); + EXPECT_EQ(absl::nullopt, nak.GetFrameSiteForTesting()); + EXPECT_DEATH_IF_SUPPORTED( + isolation_info.network_anonymization_key().GetFrameSite(), ""); + EXPECT_EQ( + absl::nullopt, + isolation_info.network_anonymization_key().GetFrameSiteForTesting()); + EXPECT_EQ(isolation_info.frame_origin(), kOrigin2); + // EXPECT_DCHECK_DEATH( + // isolation_info.network_anonymization_key().GetIsCrossSite()); + } else if (!IsDoubleKeyIsolationInfoEnabled() && + !IsDoubleKeyAndCrossSiteBitNetworkAnonymizationKeyEnabled() && + !IsDoubleKeyNetworkAnonymizationKeyEnabled()) { + // Triple-keyed IsolationInfo + triple-keyed NetworkAnonymizationKey case. + EXPECT_EQ(nak.GetFrameSite(), net::SchemefulSite(kOrigin2)); + EXPECT_EQ(isolation_info.network_anonymization_key().GetFrameSite(), + net::SchemefulSite(kOrigin2)); + EXPECT_EQ(isolation_info.frame_origin(), kOrigin2); + // EXPECT_DCHECK_DEATH( + // isolation_info.network_anonymization_key().GetIsCrossSite()); + } else if (!IsDoubleKeyIsolationInfoEnabled() && + IsDoubleKeyAndCrossSiteBitNetworkAnonymizationKeyEnabled() && + !IsDoubleKeyNetworkAnonymizationKeyEnabled()) { + // Triple-keyed IsolationInfo + double-keyed + cross site bit + // NetworkAnonymizationKey case. + EXPECT_DEATH_IF_SUPPORTED(nak.GetFrameSite(), ""); + EXPECT_EQ(absl::nullopt, nak.GetFrameSiteForTesting()); + EXPECT_DEATH_IF_SUPPORTED( + isolation_info.network_anonymization_key().GetFrameSite(), ""); + EXPECT_EQ( + absl::nullopt, + isolation_info.network_anonymization_key().GetFrameSiteForTesting()); + EXPECT_EQ(isolation_info.frame_origin(), kOrigin2); + EXPECT_EQ(isolation_info.network_anonymization_key().GetIsCrossSite(), + true); + EXPECT_EQ( + same_site_isolation_info.network_anonymization_key().GetIsCrossSite(), + false); + } +} + TEST_P(IsolationInfoTest, CreateDoubleKey) { IsolationInfo isolation_info = IsolationInfo::Create( IsolationInfo::RequestType::kMainFrame, kOrigin1, kOrigin1, SiteForCookies::FromOrigin(kOrigin1), kPartyContextEmpty); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { + if (IsDoubleKeyIsolationInfoEnabled()) { IsolationInfo double_key_isolation_info = IsolationInfo::CreateDoubleKey( IsolationInfo::RequestType::kMainFrame, kOrigin1, SiteForCookies::FromOrigin(kOrigin1), kPartyContextEmpty); @@ -107,7 +264,9 @@ TEST_P(IsolationInfoTest, CreateDoubleKey) { EXPECT_EQ(IsolationInfo::RequestType::kMainFrame, double_key_isolation_info.request_type()); EXPECT_EQ(kOrigin1, double_key_isolation_info.top_frame_origin()); - EXPECT_EQ(absl::nullopt, double_key_isolation_info.frame_origin()); + EXPECT_DEATH_IF_SUPPORTED(double_key_isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, + double_key_isolation_info.frame_origin_for_testing()); EXPECT_EQ( "https://foo.test https://foo.test", double_key_isolation_info.network_isolation_key().ToCacheKeyString()); @@ -116,8 +275,6 @@ TEST_P(IsolationInfoTest, CreateDoubleKey) { // When double keying is enabled Create and CreateDoubleKey should // create the same key. - EXPECT_EQ(isolation_info.frame_origin(), - double_key_isolation_info.frame_origin()); EXPECT_EQ(isolation_info.top_frame_origin(), double_key_isolation_info.top_frame_origin()); EXPECT_EQ(isolation_info.request_type(), @@ -146,11 +303,11 @@ TEST_P(IsolationInfoTest, RequestTypeMainFrame) { isolation_info.request_type()); EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); EXPECT_EQ("https://foo.test https://foo.test", isolation_info.network_isolation_key().ToCacheKeyString()); - } else { EXPECT_EQ(kOrigin1, isolation_info.frame_origin()); EXPECT_EQ("https://foo.test https://foo.test", @@ -170,15 +327,17 @@ TEST_P(IsolationInfoTest, RequestTypeMainFrame) { EXPECT_EQ(IsolationInfo::RequestType::kMainFrame, redirected_isolation_info.request_type()); EXPECT_EQ(kOrigin3, redirected_isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, redirected_isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(redirected_isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, + redirected_isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kOrigin3, redirected_isolation_info.frame_origin()); } EXPECT_TRUE( redirected_isolation_info.network_isolation_key().IsFullyPopulated()); EXPECT_FALSE(redirected_isolation_info.network_isolation_key().IsTransient()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { + if (IsDoubleKeyIsolationInfoEnabled()) { EXPECT_EQ( "https://baz.test https://baz.test", redirected_isolation_info.network_isolation_key().ToCacheKeyString()); @@ -200,8 +359,9 @@ TEST_P(IsolationInfoTest, RequestTypeSubFrame) { EXPECT_EQ(IsolationInfo::RequestType::kSubFrame, isolation_info.request_type()); EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); EXPECT_EQ("https://foo.test https://foo.test", isolation_info.network_isolation_key().ToCacheKeyString()); } else { @@ -224,8 +384,10 @@ TEST_P(IsolationInfoTest, RequestTypeSubFrame) { redirected_isolation_info.request_type()); EXPECT_EQ(kOrigin1, redirected_isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, redirected_isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(redirected_isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, + redirected_isolation_info.frame_origin_for_testing()); EXPECT_EQ( "https://foo.test https://foo.test", redirected_isolation_info.network_isolation_key().ToCacheKeyString()); @@ -251,8 +413,9 @@ TEST_P(IsolationInfoTest, RequestTypeMainFrameWithNonce) { EXPECT_EQ(IsolationInfo::RequestType::kMainFrame, isolation_info.request_type()); EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kOrigin1, isolation_info.frame_origin()); } @@ -272,8 +435,10 @@ TEST_P(IsolationInfoTest, RequestTypeMainFrameWithNonce) { EXPECT_EQ(IsolationInfo::RequestType::kMainFrame, redirected_isolation_info.request_type()); EXPECT_EQ(kOrigin3, redirected_isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, redirected_isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(redirected_isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, + redirected_isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kOrigin3, redirected_isolation_info.frame_origin()); } @@ -296,8 +461,9 @@ TEST_P(IsolationInfoTest, RequestTypeSubFrameWithNonce) { EXPECT_EQ(IsolationInfo::RequestType::kSubFrame, isolation_info.request_type()); EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kOrigin2, isolation_info.frame_origin()); } @@ -317,8 +483,10 @@ TEST_P(IsolationInfoTest, RequestTypeSubFrameWithNonce) { EXPECT_EQ(IsolationInfo::RequestType::kSubFrame, redirected_isolation_info.request_type()); EXPECT_EQ(kOrigin1, redirected_isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, redirected_isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(redirected_isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, + redirected_isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kOrigin3, redirected_isolation_info.frame_origin()); } @@ -338,8 +506,9 @@ TEST_P(IsolationInfoTest, RequestTypeOther) { IsolationInfo isolation_info; EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_FALSE(isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_FALSE(isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_FALSE(isolation_info.frame_origin_for_testing()); } else { EXPECT_FALSE(isolation_info.frame_origin()); } @@ -361,8 +530,9 @@ TEST_P(IsolationInfoTest, RequestTypeOtherWithSiteForCookies) { SiteForCookies::FromOrigin(kOrigin1), kPartyContextEmpty); EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); EXPECT_EQ("https://foo.test https://foo.test", isolation_info.network_isolation_key().ToCacheKeyString()); } else { @@ -392,8 +562,9 @@ TEST_P(IsolationInfoTest, RequestTypeOtherWithEmptySiteForCookies) { kOrigin2, SiteForCookies(), kPartyContext2); EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); EXPECT_EQ("https://foo.test https://foo.test", isolation_info.network_isolation_key().ToCacheKeyString()); } else { @@ -418,8 +589,9 @@ TEST_P(IsolationInfoTest, CreateTransient) { IsolationInfo isolation_info = IsolationInfo::CreateTransient(); EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_TRUE(isolation_info.top_frame_origin()->opaque()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_FALSE(isolation_info.frame_origin().has_value()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_FALSE(isolation_info.frame_origin_for_testing().has_value()); } else { EXPECT_TRUE(isolation_info.frame_origin()->opaque()); } @@ -441,8 +613,9 @@ TEST_P(IsolationInfoTest, CreateForInternalRequest) { IsolationInfo::CreateForInternalRequest(kOrigin1); EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_EQ(kOrigin1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); EXPECT_EQ("https://foo.test https://foo.test", isolation_info.network_isolation_key().ToCacheKeyString()); } else { @@ -472,8 +645,9 @@ TEST_P(IsolationInfoTest, CreatePartialUpdateTopFrame) { EXPECT_EQ(IsolationInfo::RequestType::kMainFrame, isolation_info.request_type()); EXPECT_EQ(kSite1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kSite1, isolation_info.frame_origin()); } @@ -493,8 +667,9 @@ TEST_P(IsolationInfoTest, CreatePartialUpdateFrameOnly) { EXPECT_EQ(IsolationInfo::RequestType::kSubFrame, isolation_info.request_type()); EXPECT_EQ(kSite1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kSite2, isolation_info.frame_origin()); } @@ -513,8 +688,9 @@ TEST_P(IsolationInfoTest, CreatePartialUpdateNothing) { IsolationInfo::CreatePartial(IsolationInfo::RequestType::kOther, kNIK); EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_EQ(kSite1, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); } else { EXPECT_EQ(kSite2, isolation_info.frame_origin()); } @@ -533,8 +709,14 @@ TEST_P(IsolationInfoTest, CreatePartialTransient) { EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_EQ(kNIK.GetTopFrameSite(), SchemefulSite(*isolation_info.top_frame_origin())); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(kNIK.GetFrameSite(), absl::nullopt); + EXPECT_EQ(kNIK.GetTopFrameSite(), + isolation_info.network_anonymization_key().GetTopFrameSite()); + + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(kNIK.GetFrameSite(), ""); + EXPECT_EQ(kNIK.GetFrameSiteForTesting(), absl::nullopt); + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(isolation_info.frame_origin_for_testing(), absl::nullopt); } else { EXPECT_EQ(kNIK.GetFrameSite(), SchemefulSite(*isolation_info.frame_origin())); @@ -543,7 +725,6 @@ TEST_P(IsolationInfoTest, CreatePartialTransient) { EXPECT_TRUE(isolation_info.site_for_cookies().IsNull()); EXPECT_FALSE(isolation_info.party_context()); EXPECT_FALSE(isolation_info.nonce()); - DuplicateAndCompare(isolation_info); } @@ -552,8 +733,9 @@ TEST_P(IsolationInfoTest, CreatePartialEmpty) { IsolationInfo::RequestType::kOther, NetworkIsolationKey()); EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_FALSE(isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_FALSE(isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_FALSE(isolation_info.frame_origin_for_testing()); } else { EXPECT_FALSE(isolation_info.frame_origin()); } @@ -568,8 +750,8 @@ TEST_P(IsolationInfoTest, CreatePartialEmpty) { // Test that in the UpdateNothing case, the SiteForCookies does not have to // match the frame origin, unlike in the HTTP/HTTPS case. TEST_P(IsolationInfoTest, CustomSchemeRequestTypeOther) { - // Have to register the scheme, or url::Origin::Create() will return an opaque - // origin. + // Have to register the scheme, or url::Origin::Create() will return an + // opaque origin. url::ScopedSchemeRegistryForTests scoped_registry; url::AddStandardScheme("foo", url::SCHEME_WITH_HOST); @@ -581,8 +763,9 @@ TEST_P(IsolationInfoTest, CustomSchemeRequestTypeOther) { SiteForCookies::FromOrigin(kCustomOrigin), kPartyContext1); EXPECT_EQ(IsolationInfo::RequestType::kOther, isolation_info.request_type()); EXPECT_EQ(kCustomOrigin, isolation_info.top_frame_origin()); - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, isolation_info.frame_origin()); + if (IsDoubleKeyIsolationInfoEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(isolation_info.frame_origin(), ""); + EXPECT_EQ(absl::nullopt, isolation_info.frame_origin_for_testing()); EXPECT_EQ("foo://a.foo.com foo://a.foo.com", isolation_info.network_isolation_key().ToCacheKeyString()); } else { @@ -636,9 +819,9 @@ TEST_P(IsolationInfoTest, CreateIfConsistentFails) { EXPECT_FALSE(IsolationInfo::CreateIfConsistent( IsolationInfo::RequestType::kSubFrame, absl::nullopt, kOrigin2, SiteForCookies())); - // Empty frame origins are ok when double keying is enabled but incorrect when - // triple key is enabled. - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { + // Empty frame origins are ok when double keying is enabled but incorrect + // when triple key is enabled. + if (IsDoubleKeyIsolationInfoEnabled()) { EXPECT_TRUE(IsolationInfo::CreateIfConsistent( IsolationInfo::RequestType::kOther, kOrigin1, absl::nullopt, SiteForCookies())); @@ -774,7 +957,7 @@ TEST_P(IsolationInfoTest, Serialization) { kOrigin2, SiteForCookies::FromOrigin(kOrigin1), kPartyContext1, &kNonce1), }; - if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { + if (IsDoubleKeyIsolationInfoEnabled()) { for (const auto& info : kNegativeWhenDoubleKeyEnabledTestCases) { EXPECT_TRUE(info.Serialize().empty()); } diff --git a/chromium/net/base/load_flags.h b/chromium/net/base/load_flags.h index 53b2d58d208..d26eaedf401 100644 --- a/chromium/net/base/load_flags.h +++ b/chromium/net/base/load_flags.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright 2010 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/load_flags_list.h b/chromium/net/base/load_flags_list.h index 96d1a51ec10..38062cfb932 100644 --- a/chromium/net/base/load_flags_list.h +++ b/chromium/net/base/load_flags_list.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/load_states.h b/chromium/net/base/load_states.h index 41a0339993e..049ce124296 100644 --- a/chromium/net/base/load_states.h +++ b/chromium/net/base/load_states.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/load_states_list.h b/chromium/net/base/load_states_list.h index a0e20bcb79d..4e468449979 100644 --- a/chromium/net/base/load_states_list.h +++ b/chromium/net/base/load_states_list.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/load_timing_info.cc b/chromium/net/base/load_timing_info.cc index 7471f5c5fee..7d95f48a0db 100644 --- a/chromium/net/base/load_timing_info.cc +++ b/chromium/net/base/load_timing_info.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/load_timing_info.h b/chromium/net/base/load_timing_info.h index 98e12259a83..cab6804225a 100644 --- a/chromium/net/base/load_timing_info.h +++ b/chromium/net/base/load_timing_info.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -29,8 +29,8 @@ namespace net { // service_worker_start_time // proxy_start // proxy_end -// dns_start -// dns_end +// domain_lookup_start +// domain_lookup_end // connect_start // ssl_start // ssl_end @@ -78,8 +78,8 @@ struct NET_EXPORT LoadTimingInfo { // Corresponds to |domainLookupStart| and |domainLookupEnd| in // ResourceTiming (http://www.w3.org/TR/resource-timing/) for Web-surfacing // requests. - base::TimeTicks dns_start; - base::TimeTicks dns_end; + base::TimeTicks domain_lookup_start; + base::TimeTicks domain_lookup_end; // The time spent establishing the connection. Connect time includes proxy // connect times (though not proxy_resolve or DNS lookup times), time spent diff --git a/chromium/net/base/load_timing_info_test_util.cc b/chromium/net/base/load_timing_info_test_util.cc index e84d4bd127b..eccb20299f3 100644 --- a/chromium/net/base/load_timing_info_test_util.cc +++ b/chromium/net/base/load_timing_info_test_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,8 +11,8 @@ namespace net { void ExpectConnectTimingHasNoTimes( const LoadTimingInfo::ConnectTiming& connect_timing) { - EXPECT_TRUE(connect_timing.dns_start.is_null()); - EXPECT_TRUE(connect_timing.dns_end.is_null()); + EXPECT_TRUE(connect_timing.domain_lookup_start.is_null()); + EXPECT_TRUE(connect_timing.domain_lookup_end.is_null()); EXPECT_TRUE(connect_timing.connect_start.is_null()); EXPECT_TRUE(connect_timing.connect_end.is_null()); EXPECT_TRUE(connect_timing.ssl_start.is_null()); @@ -26,12 +26,13 @@ void ExpectConnectTimingHasTimes( EXPECT_LE(connect_timing.connect_start, connect_timing.connect_end); if (!(connect_timing_flags & CONNECT_TIMING_HAS_DNS_TIMES)) { - EXPECT_TRUE(connect_timing.dns_start.is_null()); - EXPECT_TRUE(connect_timing.dns_end.is_null()); + EXPECT_TRUE(connect_timing.domain_lookup_start.is_null()); + EXPECT_TRUE(connect_timing.domain_lookup_end.is_null()); } else { - EXPECT_FALSE(connect_timing.dns_start.is_null()); - EXPECT_LE(connect_timing.dns_start, connect_timing.dns_end); - EXPECT_LE(connect_timing.dns_end, connect_timing.connect_start); + EXPECT_FALSE(connect_timing.domain_lookup_start.is_null()); + EXPECT_LE(connect_timing.domain_lookup_start, + connect_timing.domain_lookup_end); + EXPECT_LE(connect_timing.domain_lookup_end, connect_timing.connect_start); } if (!(connect_timing_flags & CONNECT_TIMING_HAS_SSL_TIMES)) { diff --git a/chromium/net/base/load_timing_info_test_util.h b/chromium/net/base/load_timing_info_test_util.h index 5c2fd172a77..7ce98b360fc 100644 --- a/chromium/net/base/load_timing_info_test_util.h +++ b/chromium/net/base/load_timing_info_test_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/logging_network_change_observer.cc b/chromium/net/base/logging_network_change_observer.cc index 0c83a0bc3f5..46d00954f62 100644 --- a/chromium/net/base/logging_network_change_observer.cc +++ b/chromium/net/base/logging_network_change_observer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/logging_network_change_observer.h b/chromium/net/base/logging_network_change_observer.h index 999354a3841..9359ea17ec2 100644 --- a/chromium/net/base/logging_network_change_observer.h +++ b/chromium/net/base/logging_network_change_observer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/lookup_string_in_fixed_set.cc b/chromium/net/base/lookup_string_in_fixed_set.cc index 8b08b2717dc..9956f1fd087 100644 --- a/chromium/net/base/lookup_string_in_fixed_set.cc +++ b/chromium/net/base/lookup_string_in_fixed_set.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/lookup_string_in_fixed_set.h b/chromium/net/base/lookup_string_in_fixed_set.h index 9d6e4ba6cc5..a8184e6924f 100644 --- a/chromium/net/base/lookup_string_in_fixed_set.h +++ b/chromium/net/base/lookup_string_in_fixed_set.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/lookup_string_in_fixed_set_fuzzer.cc b/chromium/net/base/lookup_string_in_fixed_set_fuzzer.cc index cf1ef25fe3d..de47fb06705 100644 --- a/chromium/net/base/lookup_string_in_fixed_set_fuzzer.cc +++ b/chromium/net/base/lookup_string_in_fixed_set_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/lookup_string_in_fixed_set_unittest.cc b/chromium/net/base/lookup_string_in_fixed_set_unittest.cc index e61510f8c0d..ba2f9646e52 100644 --- a/chromium/net/base/lookup_string_in_fixed_set_unittest.cc +++ b/chromium/net/base/lookup_string_in_fixed_set_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mac/url_conversions.h b/chromium/net/base/mac/url_conversions.h index 56f53a9d4a2..9894e8dec6d 100644 --- a/chromium/net/base/mac/url_conversions.h +++ b/chromium/net/base/mac/url_conversions.h @@ -1,4 +1,4 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mac/url_conversions.mm b/chromium/net/base/mac/url_conversions.mm index f8accab7c08..88b15642319 100644 --- a/chromium/net/base/mac/url_conversions.mm +++ b/chromium/net/base/mac/url_conversions.mm @@ -1,4 +1,4 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mac/url_conversions_unittest.mm b/chromium/net/base/mac/url_conversions_unittest.mm index 32e621048f6..8390f4d3bbc 100644 --- a/chromium/net/base/mac/url_conversions_unittest.mm +++ b/chromium/net/base/mac/url_conversions_unittest.mm @@ -1,4 +1,4 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mime_sniffer.cc b/chromium/net/base/mime_sniffer.cc index aa6ebbcd6ff..b57d5c3a35b 100644 --- a/chromium/net/base/mime_sniffer.cc +++ b/chromium/net/base/mime_sniffer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mime_sniffer.h b/chromium/net/base/mime_sniffer.h index 1d07aee9314..b323cb3e9f8 100644 --- a/chromium/net/base/mime_sniffer.h +++ b/chromium/net/base/mime_sniffer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mime_sniffer_fuzzer.cc b/chromium/net/base/mime_sniffer_fuzzer.cc index 91970d8a7dc..41ee83e0159 100644 --- a/chromium/net/base/mime_sniffer_fuzzer.cc +++ b/chromium/net/base/mime_sniffer_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mime_sniffer_perftest.cc b/chromium/net/base/mime_sniffer_perftest.cc index 9859f279833..b13feb2334f 100644 --- a/chromium/net/base/mime_sniffer_perftest.cc +++ b/chromium/net/base/mime_sniffer_perftest.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mime_sniffer_unittest.cc b/chromium/net/base/mime_sniffer_unittest.cc index cca0b6c2d17..ebd0e021908 100644 --- a/chromium/net/base/mime_sniffer_unittest.cc +++ b/chromium/net/base/mime_sniffer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mime_util.cc b/chromium/net/base/mime_util.cc index 1779ec4f965..eb9774d3617 100644 --- a/chromium/net/base/mime_util.cc +++ b/chromium/net/base/mime_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -165,7 +165,7 @@ static const MimeInfo kPrimaryMappings[] = { {"image/jpeg", "jpeg,jpg"}, {"image/jxl", "jxl"}, {"image/png", "png"}, - {"image/apng", "png"}, + {"image/apng", "png,apng"}, {"image/svg+xml", "svg,svgz"}, {"image/webp", "webp"}, {"multipart/related", "mht,mhtml"}, @@ -205,6 +205,10 @@ static const MimeInfo kSecondaryMappings[] = { {"application/vnd.android.package-archive", "apk"}, {"application/vnd.mozilla.xul+xml", "xul"}, {"application/vnd.ms-excel", "xls"}, + {"application/vnd.ms-powerpoint", "ppt"}, + {"application/" + "vnd.openxmlformats-officedocument.presentationml.presentation", + "pptx"}, {"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx"}, {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", diff --git a/chromium/net/base/mime_util.h b/chromium/net/base/mime_util.h index 55c93426b98..cf61dd77f2e 100644 --- a/chromium/net/base/mime_util.h +++ b/chromium/net/base/mime_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mime_util_unittest.cc b/chromium/net/base/mime_util_unittest.cc index 6c7a0ec4a1f..14e7ce31ad1 100644 --- a/chromium/net/base/mime_util_unittest.cc +++ b/chromium/net/base/mime_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -83,11 +83,19 @@ TEST(MimeUtilTest, ExtensionTest) { {FILE_PATH_LITERAL("avif"), {"image/avif"}}, {FILE_PATH_LITERAL("jxl"), {"image/jxl"}}, #if BUILDFLAG(IS_CHROMEOS_ASH) - // These are test cases for testing platform mime types on Chrome OS. + // These are test cases for testing platform mime types on ChromeOS. {FILE_PATH_LITERAL("epub"), {"application/epub+zip"}}, {FILE_PATH_LITERAL("apk"), {"application/vnd.android.package-archive"}}, - {FILE_PATH_LITERAL("cer"), {"application/x-x509-ca-cert"}}, - {FILE_PATH_LITERAL("crt"), {"application/x-x509-ca-cert"}}, + {FILE_PATH_LITERAL("cer"), + { + "application/x-x509-ca-cert", + "application/pkix-cert", // System override for ChromeOS. + }}, + {FILE_PATH_LITERAL("crt"), + { + "application/x-x509-ca-cert", + "application/pkix-cert", // System override for ChromeOS. + }}, {FILE_PATH_LITERAL("zip"), {"application/zip"}}, {FILE_PATH_LITERAL("ics"), {"text/calendar"}}, #endif @@ -96,7 +104,8 @@ TEST(MimeUtilTest, ExtensionTest) { "application/x-mpegurl", // Chrome's secondary mapping. "audio/x-mpegurl", // https://crbug.com/1273061, system override for // android-arm[64]-test and Linux. Possibly more. - "audio/mpegurl", // System override for mac. + "application/vnd.apple.mpegurl", // System override for ChromeOS. + "audio/mpegurl", // System override for mac. }}, {FILE_PATH_LITERAL("csv"), {"text/csv"}}, {FILE_PATH_LITERAL("not an extension / for sure"), {}}, diff --git a/chromium/net/base/mock_file_stream.cc b/chromium/net/base/mock_file_stream.cc index ba538639226..7b5ae67ba4b 100644 --- a/chromium/net/base/mock_file_stream.cc +++ b/chromium/net/base/mock_file_stream.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mock_file_stream.h b/chromium/net/base/mock_file_stream.h index 2811810a929..304552e5f53 100644 --- a/chromium/net/base/mock_file_stream.h +++ b/chromium/net/base/mock_file_stream.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/mock_network_change_notifier.cc b/chromium/net/base/mock_network_change_notifier.cc index af3944b48b5..c3aae7b8bab 100644 --- a/chromium/net/base/mock_network_change_notifier.cc +++ b/chromium/net/base/mock_network_change_notifier.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -84,6 +84,10 @@ void MockNetworkChangeNotifier::NotifyNetworkConnected( base::RunLoop().RunUntilIdle(); } +bool MockNetworkChangeNotifier::IsDefaultNetworkActiveInternal() { + return is_default_network_active_; +} + void MockNetworkChangeNotifier::SetConnectionTypeAndNotifyObservers( ConnectionType connection_type) { SetConnectionType(connection_type); diff --git a/chromium/net/base/mock_network_change_notifier.h b/chromium/net/base/mock_network_change_notifier.h index 60b14a94d1a..f16fc8ee186 100644 --- a/chromium/net/base/mock_network_change_notifier.h +++ b/chromium/net/base/mock_network_change_notifier.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -61,6 +61,12 @@ class MockNetworkChangeNotifier : public NetworkChangeNotifier { connection_cost_ = connection_cost; } + bool IsDefaultNetworkActiveInternal() override; + + void SetIsDefaultNetworkActiveInternalForTesting(bool is_active) { + is_default_network_active_ = is_active; + } + // Tells this class to ignore its cached connection cost value and instead // call the base class's implementation. This is intended to allow tests to // mock the product code's fallback to the default implementation in certain @@ -84,6 +90,7 @@ class MockNetworkChangeNotifier : public NetworkChangeNotifier { std::unique_ptr<SystemDnsConfigChangeNotifier> dns_config_notifier); bool force_network_handles_supported_ = false; + bool is_default_network_active_ = true; ConnectionType connection_type_ = CONNECTION_UNKNOWN; ConnectionCost connection_cost_ = CONNECTION_COST_UNKNOWN; bool use_default_connection_cost_implementation_ = false; diff --git a/chromium/net/base/net_error_details.h b/chromium/net/base/net_error_details.h index bdc9b66f6f6..3da3f325aa7 100644 --- a/chromium/net/base/net_error_details.h +++ b/chromium/net/base/net_error_details.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_error_list.h b/chromium/net/base/net_error_list.h index c7837efec56..20997e9af12 100644 --- a/chromium/net/base/net_error_list.h +++ b/chromium/net/base/net_error_list.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -112,7 +112,7 @@ NET_ERROR(CONTEXT_SHUT_DOWN, -26) // The request failed because the response was delivered along with requirements // which are not met ('X-Frame-Options' and 'Content-Security-Policy' ancestor -// checks and 'Cross-Origin-Resource-Policy', for instance). +// checks and 'Cross-Origin-Resource-Policy' for instance). NET_ERROR(BLOCKED_BY_RESPONSE, -27) // Error -28 was removed (BLOCKED_BY_XSS_AUDITOR). @@ -127,6 +127,9 @@ NET_ERROR(BLOCKED_BY_CSP, -30) // The request was blocked because of no H/2 or QUIC session. NET_ERROR(H2_OR_QUIC_REQUIRED, -31) +// The request was blocked by CORB or ORB. +NET_ERROR(BLOCKED_BY_ORB, -32) + // A connection was closed (corresponding to a TCP FIN). NET_ERROR(CONNECTION_CLOSED, -100) diff --git a/chromium/net/base/net_errors.cc b/chromium/net/base/net_errors.cc index 9011378b493..f4859f4d20a 100644 --- a/chromium/net/base/net_errors.cc +++ b/chromium/net/base/net_errors.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_errors.h b/chromium/net/base/net_errors.h index e146fc40724..074d9ff3cd2 100644 --- a/chromium/net/base/net_errors.h +++ b/chromium/net/base/net_errors.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_errors_posix.cc b/chromium/net/base/net_errors_posix.cc index 6e2b83ebadd..df49829735b 100644 --- a/chromium/net/base/net_errors_posix.cc +++ b/chromium/net/base/net_errors_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_errors_unittest.cc b/chromium/net/base/net_errors_unittest.cc index 38edd834489..ccd6aa20768 100644 --- a/chromium/net/base/net_errors_unittest.cc +++ b/chromium/net/base/net_errors_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_errors_win.cc b/chromium/net/base/net_errors_win.cc index 4bc968506ed..106dd92d612 100644 --- a/chromium/net/base/net_errors_win.cc +++ b/chromium/net/base/net_errors_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_export.h b/chromium/net/base/net_export.h index 55cf9861239..35e1773fca6 100644 --- a/chromium/net/base/net_export.h +++ b/chromium/net/base/net_export.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_info_source_list.h b/chromium/net/base/net_info_source_list.h index 4538566d864..38316c64726 100644 --- a/chromium/net/base/net_info_source_list.h +++ b/chromium/net/base/net_info_source_list.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_module.cc b/chromium/net/base/net_module.cc index f84c39b7ccf..c409a7d48a3 100644 --- a/chromium/net/base/net_module.cc +++ b/chromium/net/base/net_module.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright 2006-2008 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_module.h b/chromium/net/base/net_module.h index ce93920bba6..5f366eb0ad4 100644 --- a/chromium/net/base/net_module.h +++ b/chromium/net/base/net_module.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_string_util.h b/chromium/net/base/net_string_util.h index 204146c0b4b..cb455614799 100644 --- a/chromium/net/base/net_string_util.h +++ b/chromium/net/base/net_string_util.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_string_util_icu.cc b/chromium/net/base/net_string_util_icu.cc index c3b60449afc..67dcd9c0786 100644 --- a/chromium/net/base/net_string_util_icu.cc +++ b/chromium/net/base/net_string_util_icu.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_string_util_icu_alternatives_android.cc b/chromium/net/base/net_string_util_icu_alternatives_android.cc index 246018078dd..b18e00937c4 100644 --- a/chromium/net/base/net_string_util_icu_alternatives_android.cc +++ b/chromium/net/base/net_string_util_icu_alternatives_android.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_string_util_icu_alternatives_ios.mm b/chromium/net/base/net_string_util_icu_alternatives_ios.mm index bdc7c71395d..41497a3c411 100644 --- a/chromium/net/base/net_string_util_icu_alternatives_ios.mm +++ b/chromium/net/base/net_string_util_icu_alternatives_ios.mm @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/net_string_util_unittest.cc b/chromium/net/base/net_string_util_unittest.cc index d02bcc798fe..f4ca55b9dda 100644 --- a/chromium/net/base/net_string_util_unittest.cc +++ b/chromium/net/base/net_string_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_activity_monitor.cc b/chromium/net/base/network_activity_monitor.cc index e4ce7f08c9c..183f8968d64 100644 --- a/chromium/net/base/network_activity_monitor.cc +++ b/chromium/net/base/network_activity_monitor.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_activity_monitor.h b/chromium/net/base/network_activity_monitor.h index 6b24f306295..319e255b048 100644 --- a/chromium/net/base/network_activity_monitor.h +++ b/chromium/net/base/network_activity_monitor.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_activity_monitor_unittest.cc b/chromium/net/base/network_activity_monitor_unittest.cc index e28250d204b..0028c75c90b 100644 --- a/chromium/net/base/network_activity_monitor_unittest.cc +++ b/chromium/net/base/network_activity_monitor_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_anonymization_key.cc b/chromium/net/base/network_anonymization_key.cc index 254cd00430e..a707ec0b5ff 100644 --- a/chromium/net/base/network_anonymization_key.cc +++ b/chromium/net/base/network_anonymization_key.cc @@ -1,12 +1,15 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/network_anonymization_key.h" #include "base/feature_list.h" #include "base/unguessable_token.h" +#include "base/values.h" #include "net/base/features.h" #include "net/base/net_export.h" +#include "net/base/network_isolation_key.h" #include "net/base/schemeful_site.h" +#include "net/cookies/site_for_cookies.h" #include "third_party/abseil-cpp/absl/types/optional.h" namespace net { @@ -20,13 +23,68 @@ NetworkAnonymizationKey::NetworkAnonymizationKey( frame_site_(!IsFrameSiteEnabled() ? absl::nullopt : frame_site), is_cross_site_(IsCrossSiteFlagSchemeEnabled() ? is_cross_site : absl::nullopt), - nonce_(nonce) {} + nonce_(nonce) { + DCHECK(top_frame_site_.has_value()); + DCHECK(!IsFrameSiteEnabled() || frame_site_.has_value()); + // If `is_cross_site` is enabled but the value is not populated, and we have + // the information to calculate it, do calculate it. + if (IsCrossSiteFlagSchemeEnabled() && !is_cross_site_.has_value() && + frame_site.has_value()) { + SiteForCookies site_for_cookies = + net::SiteForCookies(top_frame_site_.value()); + is_cross_site_ = + !site_for_cookies.IsFirstParty(frame_site.value().GetURL()); + } + if (IsCrossSiteFlagSchemeEnabled()) { + // If `frame_site_` is populated, `is_cross_site_` must be as well. + DCHECK(is_cross_site_.has_value()); + } +} + +NetworkAnonymizationKey NetworkAnonymizationKey::CreateFromNetworkIsolationKey( + const net::NetworkIsolationKey& network_isolation_key) { + // If NIK is a double key, NAK must also be a double key. + DCHECK(NetworkIsolationKey::IsFrameSiteEnabled() || + (!NetworkIsolationKey::IsFrameSiteEnabled() && + !NetworkAnonymizationKey::IsFrameSiteEnabled())); + + // We cannot create a valid NetworkAnonymizationKey from a NetworkIsolationKey + // that is not fully populated. + if (!network_isolation_key.IsFullyPopulated()) { + return NetworkAnonymizationKey(); + } + + absl::optional<SchemefulSite> nak_frame_site = + NetworkAnonymizationKey::IsFrameSiteEnabled() + ? network_isolation_key.GetFrameSite() + : absl::nullopt; + + // If we are unable to determine the value of `is_cross_site` from the + // NetworkIsolationKey, we default the value to `nullopt`. Otherwise we + // calculate what the value will be. If the NetworkAnonymizationKey is being + // constructed in a scheme where the is cross site value is not used this + // value will be overridden in the constructor and set to `nullopt`. + absl::optional<bool> nak_is_cross_site = absl::nullopt; + if (NetworkAnonymizationKey::IsCrossSiteFlagSchemeEnabled()) { + SiteForCookies site_for_cookies = + net::SiteForCookies(network_isolation_key.GetTopFrameSite().value()); + nak_is_cross_site = !site_for_cookies.IsFirstParty( + network_isolation_key.GetFrameSite()->GetURL()); + } + + return NetworkAnonymizationKey( + network_isolation_key.GetTopFrameSite().value(), nak_frame_site, + nak_is_cross_site, network_isolation_key.GetNonce()); +} NetworkAnonymizationKey::NetworkAnonymizationKey() = default; NetworkAnonymizationKey::NetworkAnonymizationKey( const NetworkAnonymizationKey& network_anonymization_key) = default; +NetworkAnonymizationKey::NetworkAnonymizationKey( + NetworkAnonymizationKey&& network_anonymization_key) = default; + NetworkAnonymizationKey::~NetworkAnonymizationKey() = default; NetworkAnonymizationKey& NetworkAnonymizationKey::operator=( @@ -35,12 +93,20 @@ NetworkAnonymizationKey& NetworkAnonymizationKey::operator=( NetworkAnonymizationKey& NetworkAnonymizationKey::operator=( NetworkAnonymizationKey&& network_anonymization_key) = default; +NetworkAnonymizationKey NetworkAnonymizationKey::CreateTransient() { + SchemefulSite site_with_opaque_origin; + return NetworkAnonymizationKey(site_with_opaque_origin, + site_with_opaque_origin, false); +} + std::string NetworkAnonymizationKey::ToDebugString() const { std::string str = GetSiteDebugString(top_frame_site_); str += " " + GetSiteDebugString(frame_site_); std::string cross_site_str = IsCrossSiteFlagSchemeEnabled() - ? (GetIsCrossSite() ? " cross_site" : " same_site") + ? (!GetIsCrossSite().has_value() ? " with empty is_cross_site value" + : GetIsCrossSite().value() ? " cross_site" + : " same_site") : ""; str += cross_site_str; @@ -72,9 +138,16 @@ bool NetworkAnonymizationKey::IsTransient() const { (IsFrameSiteEnabled() && frame_site_->opaque()) || nonce_.has_value(); } -bool NetworkAnonymizationKey::GetIsCrossSite() const { - DCHECK(IsCrossSiteFlagSchemeEnabled() && is_cross_site_.has_value()); - return is_cross_site_.value(); +absl::optional<bool> NetworkAnonymizationKey::GetIsCrossSite() const { + DCHECK(IsCrossSiteFlagSchemeEnabled()); + return is_cross_site_; +} + +const absl::optional<SchemefulSite>& NetworkAnonymizationKey::GetFrameSite() + const { + // Frame site will be empty if double-keying is enabled. + CHECK(NetworkAnonymizationKey::IsFrameSiteEnabled()); + return frame_site_; } bool NetworkAnonymizationKey::IsFrameSiteEnabled() { @@ -99,9 +172,110 @@ bool NetworkAnonymizationKey::IsCrossSiteFlagSchemeEnabled() { net::features::kEnableCrossSiteFlagNetworkAnonymizationKey); } +bool NetworkAnonymizationKey::ToValue(base::Value* out_value) const { + if (IsEmpty()) { + *out_value = base::Value(base::Value::Type::LIST); + return true; + } + + if (IsTransient()) + return false; + + absl::optional<std::string> top_frame_value = + SerializeSiteWithNonce(*top_frame_site_); + if (!top_frame_value) + return false; + base::Value::List list; + list.Append(std::move(top_frame_value).value()); + + absl::optional<std::string> frame_value = + IsFrameSiteEnabled() ? SerializeSiteWithNonce(*frame_site_) + : absl::nullopt; + + // Append frame site for tripe key scheme or is_cross_site flag for double key + // with cross site flag scheme. + if (IsFrameSiteEnabled()) { + if (!frame_value.has_value()) { + return false; + } + list.Append(std::move(frame_value).value()); + } else if (IsCrossSiteFlagSchemeEnabled()) { + const absl::optional<bool> is_cross_site = GetIsCrossSite(); + if (is_cross_site.has_value()) { + list.Append(is_cross_site.value()); + } + } + + *out_value = base::Value(std::move(list)); + return true; +} + +bool NetworkAnonymizationKey::FromValue( + const base::Value& value, + NetworkAnonymizationKey* network_anonymization_key) { + if (!value.is_list()) + return false; + + const base::Value::List& list = value.GetList(); + if (list.empty()) { + *network_anonymization_key = NetworkAnonymizationKey(); + return true; + } + + // Check top_level_site is valid for any key scheme + if (list.size() < 1 || !list[0].is_string()) { + return false; + } + absl::optional<SchemefulSite> top_frame_site = + SchemefulSite::DeserializeWithNonce(list[0].GetString()); + if (!top_frame_site) { + return false; + } + + absl::optional<SchemefulSite> frame_site = absl::nullopt; + absl::optional<bool> is_cross_site = absl::nullopt; + + // If double key scheme is enabled `list` must be of length 1. list[0] will be + // top_frame_site. + if (IsDoubleKeySchemeEnabled()) { + if (list.size() != 1) { + return false; + } + } else if (IsCrossSiteFlagSchemeEnabled()) { + // If double key + is cross site scheme is enabled `list` must be of + // length 2. list[0] will be top_frame_site and list[1] will be + // is_cross_site. + if (list.size() != 2 || !list[1].is_bool()) { + return false; + } + is_cross_site = list[1].GetBool(); + } else { + // If neither alternative scheme is enabled we expect a valid triple keyed + // NetworkAnonymizationKey. `list` must be of length 2. list[0] will be + // top_frame_site and list[1] will be frame_site. + if (list.size() != 2 || !list[1].is_string()) { + return false; + } + frame_site = SchemefulSite::DeserializeWithNonce(list[1].GetString()); + if (!frame_site) { + return false; + } + } + + *network_anonymization_key = + NetworkAnonymizationKey(std::move(top_frame_site.value()), + std::move(frame_site), std::move(is_cross_site)); + return true; +} + std::string NetworkAnonymizationKey::GetSiteDebugString( const absl::optional<SchemefulSite>& site) const { return site ? site->GetDebugString() : "null"; } +absl::optional<std::string> NetworkAnonymizationKey::SerializeSiteWithNonce( + const SchemefulSite& site) { + return *(const_cast<SchemefulSite&>(site).SerializeWithNonce()); +} + } // namespace net diff --git a/chromium/net/base/network_anonymization_key.h b/chromium/net/base/network_anonymization_key.h index 1a783562124..a5f47e671e4 100644 --- a/chromium/net/base/network_anonymization_key.h +++ b/chromium/net/base/network_anonymization_key.h @@ -1,18 +1,24 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef NET_BASE_NETWORK_ANONYMIZATION_KEY_H_ #define NET_BASE_NETWORK_ANONYMIZATION_KEY_H_ +#include <cstddef> #include <string> #include <tuple> #include "base/unguessable_token.h" #include "net/base/net_export.h" +#include "net/base/network_isolation_key.h" #include "net/base/schemeful_site.h" #include "third_party/abseil-cpp/absl/types/optional.h" +namespace base { +class Value; +} + namespace net { // NetworkAnonymizationKey will be used to partition shared network state based @@ -54,9 +60,11 @@ namespace net { class NET_EXPORT NetworkAnonymizationKey { public: + // TODO(crbug/1372123): Consider having the constructor not pass + // `is_cross_site` since this may be unnecessary and confusing to consumers. NetworkAnonymizationKey( const SchemefulSite& top_frame_site, - const absl::optional<SchemefulSite>& frame_site, + const absl::optional<SchemefulSite>& frame_site = absl::nullopt, const absl::optional<bool> is_cross_site = absl::nullopt, const absl::optional<base::UnguessableToken> nonce = absl::nullopt); @@ -93,6 +101,31 @@ class NET_EXPORT NetworkAnonymizationKey { other.is_cross_site_, other.nonce_); } + // Creates a NetworkAnonymizationKey from a NetworkAnonymizationKey. This is + // possible because a NetworkAnonymizationKey must always be more granular + // than a NetworkAnonymizationKey. + static NetworkAnonymizationKey CreateFromNetworkIsolationKey( + const net::NetworkIsolationKey& network_isolation_key); + + // TODO(crbug/1372769) + // Intended for temporary use in locations that should be using main frame and + // frame origin, but are currently only using frame origin, because the + // creating object may be shared across main frame objects. Having a special + // constructor for these methods makes it easier to keep track of locating + // callsites that need to have their NetworkAnonymizationKey filled in. + static NetworkAnonymizationKey ToDoUseTopFrameOriginAsWell( + const url::Origin& incorrectly_used_frame_origin) { + net::SchemefulSite incorrectly_used_frame_site = + net::SchemefulSite(incorrectly_used_frame_origin); + return NetworkAnonymizationKey(incorrectly_used_frame_site, + incorrectly_used_frame_site); + } + + // Creates a transient non-empty NetworkAnonymizationKey by creating an opaque + // origin. This prevents the NetworkAnonymizationKey from sharing data with + // other NetworkAnonymizationKey. + static NetworkAnonymizationKey CreateTransient(); + // Returns the string representation of the key. std::string ToDebugString() const; @@ -111,17 +144,21 @@ class NET_EXPORT NetworkAnonymizationKey { bool IsTransient() const; // Getters for the top frame, frame site, nonce and is cross site flag. - // TODO @brgoldstein: create feature flags to wrap these properties so that - // the key can be modified for experimentation. const absl::optional<SchemefulSite>& GetTopFrameSite() const { return top_frame_site_; } - const absl::optional<SchemefulSite>& GetFrameSite() const { + const absl::optional<SchemefulSite>& GetFrameSite() const; + + // Do not use outside of testing. Returns the `frame_site_` if neither + // `kEnableCrossSiteFlagNetworkAnonymizationKey` or + // `kEnableDoubleKeyNetworkAnonymizationKey` are enabled. Else it + // returns nullopt. + const absl::optional<SchemefulSite>& GetFrameSiteForTesting() const { return frame_site_; } - bool GetIsCrossSite() const; + absl::optional<bool> GetIsCrossSite() const; const absl::optional<base::UnguessableToken>& GetNonce() const { return nonce_; @@ -150,9 +187,24 @@ class NET_EXPORT NetworkAnonymizationKey { // cross site from the top level site. static bool IsCrossSiteFlagSchemeEnabled(); + // Returns a representation of |this| as a base::Value. Returns false on + // failure. Succeeds if either IsEmpty() or !IsTransient(). + [[nodiscard]] bool ToValue(base::Value* out_value) const; + + // Inverse of ToValue(). Writes the result to |network_anonymization_key|. + // Returns false on failure. Fails on values that could not have been produced + // by ToValue(), like transient origins. + [[nodiscard]] static bool FromValue( + const base::Value& value, + NetworkAnonymizationKey* out_network_anonymization_key); + private: std::string GetSiteDebugString( const absl::optional<SchemefulSite>& site) const; + + static absl::optional<std::string> SerializeSiteWithNonce( + const SchemefulSite& site); + // The origin/etld+1 of the top frame of the page making the request. This // will always be populated unless all other fields are also nullopt. absl::optional<SchemefulSite> top_frame_site_; diff --git a/chromium/net/base/network_anonymization_key_unittest.cc b/chromium/net/base/network_anonymization_key_unittest.cc index 14e8883ba59..6ebf505595a 100644 --- a/chromium/net/base/network_anonymization_key_unittest.cc +++ b/chromium/net/base/network_anonymization_key_unittest.cc @@ -1,14 +1,16 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/network_anonymization_key.h" +#include "base/test/gtest_util.h" #include "base/test/scoped_feature_list.h" #include "base/unguessable_token.h" #include "base/values.h" #include "net/base/features.h" #include "net/base/schemeful_site.h" +#include "network_anonymization_key.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "url/gurl.h" @@ -17,30 +19,50 @@ namespace net { struct EnabledFeatureFlagsTestingParam { - bool enableDoubleKeyNetworkAnonymizationKeyEnabled; - bool enableCrossSiteFlagNetworkAnonymizationKey; + const bool enableDoubleKeyNetworkAnonymizationKeyEnabled; + const bool enableCrossSiteFlagNetworkAnonymizationKey; + const bool enableDoubleKeyNetworkIsolationKey; }; +// 0. Triple-keying is enabled for both IsolationInfo and +// NetworkAnonymizationKey. +// 1. Double-keying is enabled for both IsolationInfo and +// NetworkAnonymizationKey. +// 2. Triple-keying is enabled for IsolationInfo and double-keying is enabled +// for NetworkAnonymizationKey. +// 3. Triple-keying is enabled for IsolationInfo and double-keying + +// cross-site-bit is enabled for NetworkAnonymizationKey. const EnabledFeatureFlagsTestingParam kFlagsParam[] = { {/*enableDoubleKeyNetworkAnonymizationKeyEnabled=*/false, - /*enableCrossSiteFlagNetworkAnonymizationKey=*/false}, - {/*enableDoubleKeyNetworkAnonymizationKeyEnabled=*/false, - /*enableCrossSiteFlagNetworkAnonymizationKey=*/true}, + /*enableCrossSiteFlagNetworkAnonymizationKey=*/false, + /*enableDoubleKeyNetworkIsolationKey=*/false}, {/*enableDoubleKeyNetworkAnonymizationKeyEnabled=*/true, - /*enableCrossSiteFlagNetworkAnonymizationKey=*/false}, + /*enableCrossSiteFlagNetworkAnonymizationKey=*/false, + /*enableDoubleKeyNetworkIsolationKey=*/true}, {/*enableDoubleKeyNetworkAnonymizationKeyEnabled=*/true, - /*enableCrossSiteFlagNetworkAnonymizationKe=y*/ true}, -}; + /*enableCrossSiteFlagNetworkAnonymizationKey=*/false, + /*enableDoubleKeyNetworkIsolationKey=*/false}, + {/*enableDoubleKeyNetworkAnonymizationKeyEnabled=*/false, + /*enableCrossSiteFlagNetworkAnonymizationKey=*/true, + /*enableDoubleKeyNetworkIsolationKey=*/false}}; class NetworkAnonymizationKeyTest : public testing::Test, public testing::WithParamInterface<EnabledFeatureFlagsTestingParam> { public: void SetUp() override { - std::vector<base::Feature> enabled_features = {}; - std::vector<base::Feature> disabled_features = {}; + std::vector<base::test::FeatureRef> enabled_features = {}; + std::vector<base::test::FeatureRef> disabled_features = {}; + + if (IsDoubleKeyNetworkIsolationKeyEnabled()) { + enabled_features.push_back( + net::features::kForceIsolationInfoFrameOriginToTopLevelFrame); + } else { + disabled_features.push_back( + net::features::kForceIsolationInfoFrameOriginToTopLevelFrame); + } - if (IsDoubleKeyEnabled()) { + if (IsDoubleKeyNetworkAnonymizationKeyEnabled()) { enabled_features.push_back( net::features::kEnableDoubleKeyNetworkAnonymizationKey); } else { @@ -59,9 +81,14 @@ class NetworkAnonymizationKeyTest scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features); } - bool IsDoubleKeyEnabled() { + static bool IsDoubleKeyNetworkIsolationKeyEnabled() { + return GetParam().enableDoubleKeyNetworkIsolationKey; + } + + bool IsDoubleKeyNetworkAnonymizationKeyEnabled() { return GetParam().enableDoubleKeyNetworkAnonymizationKeyEnabled; } + bool IsCrossSiteFlagEnabled() { return GetParam().enableCrossSiteFlagNetworkAnonymizationKey; } @@ -82,7 +109,7 @@ INSTANTIATE_TEST_SUITE_P( /*kEnableDoubleKeyNetworkAnonymizationKey*/ testing::ValuesIn(kFlagsParam)); TEST_P(NetworkAnonymizationKeyTest, IsDoubleKeyingEnabled) { - if (IsDoubleKeyEnabled() || IsCrossSiteFlagEnabled()) { + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() || IsCrossSiteFlagEnabled()) { EXPECT_FALSE(NetworkAnonymizationKey::IsFrameSiteEnabled()); } else { EXPECT_TRUE(NetworkAnonymizationKey::IsFrameSiteEnabled()); @@ -93,7 +120,8 @@ TEST_P(NetworkAnonymizationKeyTest, IsDoubleKeySchemeEnabled) { // Double key scheme is enabled only when // `kEnableDoubleKeyNetworkAnonymizationKeyEnabled` is enabled but // `kEnableCrossSiteFlagNetworkAnonymizationKey` is not. - if (IsDoubleKeyEnabled() && !IsCrossSiteFlagEnabled()) { + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() && + !IsCrossSiteFlagEnabled()) { EXPECT_TRUE(NetworkAnonymizationKey::IsDoubleKeySchemeEnabled()); } else { EXPECT_FALSE(NetworkAnonymizationKey::IsDoubleKeySchemeEnabled()); @@ -112,6 +140,131 @@ TEST_P(NetworkAnonymizationKeyTest, IsCrossSiteFlagSchemeEnabled) { } } +TEST_P(NetworkAnonymizationKeyTest, CreateFromNetworkIsolationKey) { + SchemefulSite site_a = SchemefulSite(GURL("http://a.test/")); + SchemefulSite site_b = SchemefulSite(GURL("http://b.test/")); + base::UnguessableToken nik_nonce = base::UnguessableToken::Create(); + NetworkIsolationKey populated_cross_site_nik(site_a, site_b, &nik_nonce); + NetworkIsolationKey populated_same_site_nik(site_a, site_a, &nik_nonce); + NetworkIsolationKey empty_nik; + + NetworkAnonymizationKey nak_from_cross_site_nik = + NetworkAnonymizationKey::CreateFromNetworkIsolationKey( + populated_cross_site_nik); + NetworkAnonymizationKey nak_from_same_site_nik = + NetworkAnonymizationKey::CreateFromNetworkIsolationKey( + populated_same_site_nik); + NetworkAnonymizationKey nak_from_empty_nik = + NetworkAnonymizationKey::CreateFromNetworkIsolationKey(empty_nik); + + // NAKs created when there is no top frame site on the NIK should create an + // empty NAK. + EXPECT_TRUE(nak_from_empty_nik.IsEmpty()); + + // Double-keyed NetworkIsolationKey + double-keyed NetworkAnonymizationKey + // case. + if (IsDoubleKeyNetworkIsolationKeyEnabled() && + IsDoubleKeyNetworkAnonymizationKeyEnabled()) { + // Top site should be populated. + EXPECT_EQ(nak_from_cross_site_nik.GetTopFrameSite(), site_a); + EXPECT_EQ(nak_from_same_site_nik.GetTopFrameSite(), site_a); + + // Nonce should be populated. + EXPECT_EQ(nak_from_same_site_nik.GetNonce(), nik_nonce); + EXPECT_EQ(nak_from_cross_site_nik.GetNonce(), nik_nonce); + + // Frame site getter should CHECK. + EXPECT_DEATH_IF_SUPPORTED(nak_from_cross_site_nik.GetFrameSite(), ""); + EXPECT_DEATH_IF_SUPPORTED(nak_from_same_site_nik.GetFrameSite(), ""); + + // Double-keyed NAKs created from different third party cross site contexts + // should be equal. + EXPECT_TRUE(nak_from_same_site_nik == nak_from_cross_site_nik); + } + + // Triple-keyed NetworkIsolationKey + triple-keyed NetworkAnonymizationKey + // case. + if (!IsDoubleKeyNetworkIsolationKeyEnabled() && + !IsDoubleKeyNetworkAnonymizationKeyEnabled() && + !IsCrossSiteFlagEnabled()) { + // Top site should be populated correctly. + EXPECT_EQ(nak_from_cross_site_nik.GetTopFrameSite(), site_a); + EXPECT_EQ(nak_from_same_site_nik.GetTopFrameSite(), site_a); + + // Nonce should be populated correctly. + EXPECT_EQ(nak_from_same_site_nik.GetNonce(), nik_nonce); + EXPECT_EQ(nak_from_cross_site_nik.GetNonce(), nik_nonce); + + // Frame site getter should be populated correctly. + EXPECT_EQ(nak_from_cross_site_nik.GetFrameSite(), site_b); + EXPECT_EQ(nak_from_same_site_nik.GetFrameSite(), site_a); + + // Is cross site boolean should not be accessible when the feature is not + // enabled. + // EXPECT_DEATH_IF_SUPPORTED(nak_from_cross_site_nik.GetIsCrossSite(), ""); + // EXPECT_DEATH_IF_SUPPORTED(nak_from_same_site_nik.GetIsCrossSite(), ""); + + // Triple-keyed NAKs created from different third party cross site contexts + // should be different. + EXPECT_FALSE(nak_from_same_site_nik == nak_from_cross_site_nik); + } + + // Triple-keyed NetworkIsolationKey + double-keyed NetworkAnonymizationKey + // case. + if (!IsDoubleKeyNetworkIsolationKeyEnabled() && + IsDoubleKeyNetworkAnonymizationKeyEnabled() && + !IsCrossSiteFlagEnabled()) { + // Top site should be populated correctly. + EXPECT_EQ(nak_from_cross_site_nik.GetTopFrameSite(), site_a); + EXPECT_EQ(nak_from_same_site_nik.GetTopFrameSite(), site_a); + + // Nonce should be populated correctly. + EXPECT_EQ(nak_from_same_site_nik.GetNonce(), nik_nonce); + EXPECT_EQ(nak_from_cross_site_nik.GetNonce(), nik_nonce); + + // Frame site getter should not be accessible when the double keying is + // enabled. + EXPECT_DEATH_IF_SUPPORTED(nak_from_cross_site_nik.GetFrameSite(), ""); + EXPECT_DEATH_IF_SUPPORTED(nak_from_same_site_nik.GetFrameSite(), ""); + + // Is cross site boolean should not be accessible when the feature is not + // enabled. + // EXPECT_DEATH_IF_SUPPORTED(nak_from_cross_site_nik.GetIsCrossSite(), ""); + // EXPECT_DEATH_IF_SUPPORTED(nak_from_same_site_nik.GetIsCrossSite(), ""); + + // Double-keyed NAKs created from different third party cross site contexts + // should be the same. + EXPECT_TRUE(nak_from_same_site_nik == nak_from_cross_site_nik); + } + + // Triple-keyed NetworkIsolationKey + double-keyed + cross site bit + // NetworkAnonymizationKey case. + if (!IsDoubleKeyNetworkIsolationKeyEnabled() && + !IsDoubleKeyNetworkAnonymizationKeyEnabled() && + IsCrossSiteFlagEnabled()) { + // Top site should be populated correctly. + EXPECT_EQ(nak_from_cross_site_nik.GetTopFrameSite(), site_a); + EXPECT_EQ(nak_from_same_site_nik.GetTopFrameSite(), site_a); + + // Nonce should be populated correctly. + EXPECT_EQ(nak_from_same_site_nik.GetNonce(), nik_nonce); + EXPECT_EQ(nak_from_cross_site_nik.GetNonce(), nik_nonce); + + // Frame site getter should not be accessible when the double keying is + // enabled. + EXPECT_DEATH_IF_SUPPORTED(nak_from_cross_site_nik.GetFrameSite(), ""); + EXPECT_DEATH_IF_SUPPORTED(nak_from_same_site_nik.GetFrameSite(), ""); + + // Is cross site boolean should be populated correctly. + EXPECT_EQ(nak_from_same_site_nik.GetIsCrossSite(), false); + EXPECT_EQ(nak_from_cross_site_nik.GetIsCrossSite(), true); + + // Double-keyed + cross site bit NAKs created from different third party + // cross site contexts should be the different. + EXPECT_FALSE(nak_from_same_site_nik == nak_from_cross_site_nik); + } +} + TEST_P(NetworkAnonymizationKeyTest, IsEmpty) { NetworkAnonymizationKey empty_key; NetworkAnonymizationKey populated_key(/*top_frame_site=*/kTestSiteA, @@ -123,6 +276,17 @@ TEST_P(NetworkAnonymizationKeyTest, IsEmpty) { EXPECT_FALSE(populated_key.IsEmpty()); } +TEST_P(NetworkAnonymizationKeyTest, CreateTransient) { + NetworkAnonymizationKey transient_key1 = + NetworkAnonymizationKey::CreateTransient(); + NetworkAnonymizationKey transient_key2 = + NetworkAnonymizationKey::CreateTransient(); + + EXPECT_TRUE(transient_key1.IsTransient()); + EXPECT_TRUE(transient_key2.IsTransient()); + EXPECT_FALSE(transient_key1 == transient_key2); +} + TEST_P(NetworkAnonymizationKeyTest, IsTransient) { NetworkAnonymizationKey empty_key; NetworkAnonymizationKey populated_key(/*top_frame_site=*/kTestSiteA, @@ -140,23 +304,25 @@ TEST_P(NetworkAnonymizationKeyTest, IsTransient) { /*frame_site=*/kDataSite, /*is_cross_site=*/false, /*nonce=*/absl::nullopt); - NetworkAnonymizationKey populated_double_key(/*top_frame_site=*/kTestSiteA, - /*frame_site=*/absl::nullopt, - /*is_cross_site=*/false, - /*nonce=*/absl::nullopt); + + NetworkAnonymizationKey from_create_transient = + NetworkAnonymizationKey::CreateTransient(); EXPECT_TRUE(empty_key.IsTransient()); EXPECT_FALSE(populated_key.IsTransient()); EXPECT_TRUE(data_top_frame_key.IsTransient()); - EXPECT_TRUE(data_top_frame_key.IsTransient()); EXPECT_TRUE(populated_key_with_nonce.IsTransient()); + EXPECT_TRUE(from_create_transient.IsTransient()); - if (IsDoubleKeyEnabled() || IsCrossSiteFlagEnabled()) { + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() || IsCrossSiteFlagEnabled()) { + NetworkAnonymizationKey populated_double_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/absl::nullopt, + /*is_cross_site=*/false, + /*nonce=*/absl::nullopt); EXPECT_FALSE(data_frame_key.IsTransient()); EXPECT_FALSE(populated_double_key.IsTransient()); } else { EXPECT_TRUE(data_frame_key.IsTransient()); - EXPECT_TRUE(populated_double_key.IsTransient()); } } @@ -166,10 +332,6 @@ TEST_P(NetworkAnonymizationKeyTest, IsFullyPopulated) { /*frame_site=*/kTestSiteB, /*is_cross_site=*/false, /*nonce=*/absl::nullopt); - NetworkAnonymizationKey empty_frame_site_key(/*top_frame_site=*/kTestSiteA, - /*frame_site=*/absl::nullopt, - /*is_cross_site=*/false, - /*nonce=*/absl::nullopt); NetworkAnonymizationKey empty_cross_site_flag_key( /*top_frame_site=*/kTestSiteA, /*frame_site=*/kTestSiteB, @@ -177,18 +339,47 @@ TEST_P(NetworkAnonymizationKeyTest, IsFullyPopulated) { /*nonce=*/absl::nullopt); EXPECT_TRUE(populated_key.IsFullyPopulated()); EXPECT_FALSE(empty_key.IsFullyPopulated()); - if (IsDoubleKeyEnabled() || IsCrossSiteFlagEnabled()) { + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() || IsCrossSiteFlagEnabled()) { + NetworkAnonymizationKey empty_frame_site_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/absl::nullopt, + /*is_cross_site=*/false, + /*nonce=*/absl::nullopt); EXPECT_TRUE(empty_frame_site_key.IsFullyPopulated()); - } else { - EXPECT_FALSE(empty_frame_site_key.IsFullyPopulated()); } // is_cross_site is required when // `kEnableCrossSiteFlagNetworkAnonymizationKey` is enabled. + // Since we have both the top_frame_site and frame_site values the constructor + // should calculate and set `is_cross_site`. + EXPECT_TRUE(empty_cross_site_flag_key.IsFullyPopulated()); +} + +TEST_P(NetworkAnonymizationKeyTest, IsCrossSiteFlagCalculatedInConstructor) { if (IsCrossSiteFlagEnabled()) { - EXPECT_FALSE(empty_cross_site_flag_key.IsFullyPopulated()); - } else { - EXPECT_TRUE(empty_cross_site_flag_key.IsFullyPopulated()); + NetworkAnonymizationKey cross_site_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteB, + /*is_cross_site=*/true); + NetworkAnonymizationKey equal_cross_site_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteB); + + NetworkAnonymizationKey same_site_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteA, + /*is_cross_site=*/false); + NetworkAnonymizationKey equal_same_site_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteA); + + NetworkAnonymizationKey double_key_cross_site(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/absl::nullopt, + true); + EXPECT_EQ(cross_site_key.GetIsCrossSite().value(), true); + EXPECT_EQ(equal_cross_site_key.GetIsCrossSite().value(), true); + EXPECT_EQ(cross_site_key, equal_cross_site_key); + + EXPECT_EQ(same_site_key.GetIsCrossSite().value(), false); + EXPECT_EQ(equal_same_site_key.GetIsCrossSite().value(), false); + EXPECT_EQ(same_site_key, equal_same_site_key); + + EXPECT_EQ(double_key_cross_site.GetIsCrossSite().value(), true); } } @@ -203,8 +394,9 @@ TEST_P(NetworkAnonymizationKeyTest, Getters) { // frame_site should be empty if any double key scheme is enabled. This // includes when `kEnableCrossSiteFlagNetworkAnonymizationKey` or // `kEnableDoubleKeyNetworkAnonymizationKey` are enabled. - if (IsDoubleKeyEnabled() || IsCrossSiteFlagEnabled()) { - EXPECT_EQ(key.GetFrameSite(), absl::nullopt); + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() || IsCrossSiteFlagEnabled()) { + EXPECT_DEATH_IF_SUPPORTED(key.GetFrameSite(), ""); + EXPECT_EQ(key.GetFrameSiteForTesting(), absl::nullopt); } else { EXPECT_EQ(key.GetFrameSite(), kTestSiteB); } @@ -213,8 +405,6 @@ TEST_P(NetworkAnonymizationKeyTest, Getters) { // `kEnableCrossSiteFlagNetworkAnonymizationKey` is enabled. if (IsCrossSiteFlagEnabled()) { EXPECT_TRUE(key.GetIsCrossSite()); - } else { - EXPECT_DEATH_IF_SUPPORTED(key.GetIsCrossSite(), ""); } } @@ -224,7 +414,8 @@ TEST_P(NetworkAnonymizationKeyTest, ToDebugString) { /*is_cross_site=*/true, kNonce); NetworkAnonymizationKey empty_key; - if (IsDoubleKeyEnabled() && !IsCrossSiteFlagEnabled()) { + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() && + !IsCrossSiteFlagEnabled()) { // When double key scheme is enabled, the `is_cross_site` flag is always // forced to false. std::string double_key_expected_string_value = kTestSiteA.GetDebugString() + @@ -240,9 +431,10 @@ TEST_P(NetworkAnonymizationKeyTest, ToDebugString) { kNonce.ToString() + ")"; EXPECT_EQ(key.ToDebugString(), double_key_with_cross_site_flag_expected_string_value); - // is_cross_site_ must be populated if - // `kEnableCrossSiteFlagNetworkAnonymizationKey` is enabled. - EXPECT_DEATH_IF_SUPPORTED(empty_key.ToDebugString(), ""); + // is_cross_site_ will be stored as nullopt when it's not populated even if + // IsCrossSiteFlagEnabled is enabled. + EXPECT_EQ(empty_key.ToDebugString(), + "null null with empty is_cross_site value"); } else { // When neither `kEnableDoubleKeyNetworkAnonymizationKey` or // `kEnableCrossSiteFlagNetworkAnonymizationKey` is enabled, @@ -303,7 +495,7 @@ TEST_P(NetworkAnonymizationKeyTest, Equality) { /*top_frame_site=*/kTestSiteA, /*frame_site=*/kTestSiteA, /*is_cross_site=*/false, kNonce); - if (IsDoubleKeyEnabled() || IsCrossSiteFlagEnabled()) { + if (IsDoubleKeyNetworkAnonymizationKeyEnabled() || IsCrossSiteFlagEnabled()) { EXPECT_TRUE(key == key_different_frame_site); EXPECT_FALSE(key != key_different_frame_site); } else { @@ -330,4 +522,184 @@ TEST_P(NetworkAnonymizationKeyTest, Equality) { EXPECT_TRUE(empty_key < key); } -} // namespace net
\ No newline at end of file +TEST_P(NetworkAnonymizationKeyTest, ValueRoundTripCrossSite) { + const SchemefulSite kOpaqueSite = SchemefulSite(GURL("data:text/html,junk")); + NetworkAnonymizationKey original_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteB, + /*is_cross_site=*/true); + base::Value value; + ASSERT_TRUE(original_key.ToValue(&value)); + + // Fill initial value with opaque data, to make sure it's overwritten. + NetworkAnonymizationKey from_value_key = NetworkAnonymizationKey(); + EXPECT_TRUE(NetworkAnonymizationKey::FromValue(value, &from_value_key)); + EXPECT_EQ(original_key, from_value_key); +} + +TEST_P(NetworkAnonymizationKeyTest, ValueRoundTripSameSite) { + const SchemefulSite kOpaqueSite = SchemefulSite(GURL("data:text/html,junk")); + NetworkAnonymizationKey original_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteA, + /*is_cross_site=*/false); + base::Value value; + ASSERT_TRUE(original_key.ToValue(&value)); + + // Fill initial value with opaque data, to make sure it's overwritten. + NetworkAnonymizationKey from_value_key = NetworkAnonymizationKey(); + EXPECT_TRUE(NetworkAnonymizationKey::FromValue(value, &from_value_key)); + EXPECT_EQ(original_key, from_value_key); +} + +TEST_P(NetworkAnonymizationKeyTest, ValueRoundTripOpaqueFrameSite) { + const SchemefulSite kOpaqueSite = SchemefulSite(GURL("data:text/html,junk")); + NetworkAnonymizationKey original_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kOpaqueSite, + /*is_cross_site=*/false); + base::Value value; + if (!NetworkAnonymizationKey::IsFrameSiteEnabled()) { + ASSERT_TRUE(original_key.ToValue(&value)); + NetworkAnonymizationKey from_value_key = NetworkAnonymizationKey(); + EXPECT_TRUE(NetworkAnonymizationKey::FromValue(value, &from_value_key)); + EXPECT_EQ(original_key, from_value_key); + } else { + // If we expect a valid frame site we should fail to serialize the garbage + // value. + ASSERT_FALSE(original_key.ToValue(&value)); + } +} + +TEST_P(NetworkAnonymizationKeyTest, DeserializeValueWIthGarbageFrameSite) { + const SchemefulSite kOpaqueSite = SchemefulSite(GURL("data:text/html,junk")); + base::Value::List invalid_value; + invalid_value.Append("http://a.test/"); + invalid_value.Append("data:text/html,junk"); + + // If we expect a valid frame site we should fail to deserialize the garbage + // value. + if (NetworkAnonymizationKey::IsFrameSiteEnabled()) { + NetworkAnonymizationKey from_value_key = NetworkAnonymizationKey(); + EXPECT_FALSE(NetworkAnonymizationKey::FromValue( + base::Value(std::move(invalid_value)), &from_value_key)); + } +} + +TEST_P(NetworkAnonymizationKeyTest, TransientValueRoundTrip) { + const SchemefulSite kOpaqueSite = SchemefulSite(GURL("data:text/html,junk")); + NetworkAnonymizationKey original_key = + NetworkAnonymizationKey::CreateTransient(); + base::Value value; + ASSERT_FALSE(original_key.ToValue(&value)); +} + +TEST_P(NetworkAnonymizationKeyTest, EmptyValueRoundTrip) { + const SchemefulSite kOpaqueSite = SchemefulSite(GURL("data:text/html,junk")); + NetworkAnonymizationKey original_key; + base::Value value; + ASSERT_TRUE(original_key.ToValue(&value)); + + // Fill initial value with opaque data, to make sure it's overwritten. + NetworkAnonymizationKey from_value_key = NetworkAnonymizationKey(); + EXPECT_TRUE(NetworkAnonymizationKey::FromValue(value, &from_value_key)); + EXPECT_EQ(original_key, from_value_key); +} + +TEST(NetworkAnonymizationKeyFeatureShiftTest, + ValueRoundTripKeySchemeMissmatch) { + base::test::ScopedFeatureList scoped_feature_list_; + const SchemefulSite kOpaqueSite = SchemefulSite(GURL("data:text/html,junk")); + const SchemefulSite kTestSiteA = SchemefulSite(GURL("http://a.test/")); + const SchemefulSite kTestSiteB = SchemefulSite(GURL("http://b.test/")); + NetworkAnonymizationKey expected_failure_nak = NetworkAnonymizationKey(); + + // Turn double keying off. + scoped_feature_list_.InitAndDisableFeature( + net::features::kForceIsolationInfoFrameOriginToTopLevelFrame); + + // Create a triple key. + NetworkAnonymizationKey original_triple_key(/*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteB); + + // Serialize key to value while triple keying is enabled. + base::Value triple_key_value; + ASSERT_TRUE(original_triple_key.ToValue(&triple_key_value)); + + // Convert it back to a triple keyed NetworkAnonymizationKey. + NetworkAnonymizationKey from_value_triple_key = NetworkAnonymizationKey(); + EXPECT_TRUE(NetworkAnonymizationKey::FromValue(triple_key_value, + &from_value_triple_key)); + EXPECT_EQ(original_triple_key, from_value_triple_key); + + // Turn double keying on. + scoped_feature_list_.Reset(); + scoped_feature_list_.InitAndEnableFeature( + net::features::kEnableDoubleKeyNetworkAnonymizationKey); + + // Check that deserializing the triple keyed value fails. + EXPECT_FALSE(NetworkAnonymizationKey::FromValue(triple_key_value, + &expected_failure_nak)); + + // Create a double keyed NetworkAnonymizationKey. + NetworkAnonymizationKey original_double_key(/*top_frame_site=*/kTestSiteA); + // Serialize key to value while double keying is enabled. + base::Value double_key_value; + ASSERT_TRUE(original_double_key.ToValue(&double_key_value)); + + // Convert it back to a double keyed NetworkAnonymizationKey. + NetworkAnonymizationKey from_value_double_key = NetworkAnonymizationKey(); + EXPECT_TRUE(NetworkAnonymizationKey::FromValue(double_key_value, + &from_value_double_key)); + EXPECT_EQ(original_double_key, from_value_double_key); + + // Turn double keying + cross site flag on. + scoped_feature_list_.Reset(); + scoped_feature_list_.InitAndEnableFeature( + net::features::kEnableCrossSiteFlagNetworkAnonymizationKey); + + // Check that deserializing the triple keyed value fails. + EXPECT_FALSE(NetworkAnonymizationKey::FromValue(triple_key_value, + &expected_failure_nak)); + + // Check that deserializing the double keyed value fails. + EXPECT_FALSE(NetworkAnonymizationKey::FromValue(double_key_value, + &expected_failure_nak)); + + // Create a cross site double key + cross site flag NetworkAnonymizationKey. + NetworkAnonymizationKey original_cross_site_double_key( + /*top_frame_site=*/kTestSiteA, + /*frame_site=*/kTestSiteB, false); + // Serialize key to value while double key + cross site flag is enabled. + base::Value cross_site_double_key_value; + ASSERT_TRUE( + original_cross_site_double_key.ToValue(&cross_site_double_key_value)); + + // Convert it back to a double keyed NetworkAnonymizationKey. + NetworkAnonymizationKey from_value_cross_site_double_key = + NetworkAnonymizationKey(); + EXPECT_TRUE(NetworkAnonymizationKey::FromValue( + cross_site_double_key_value, &from_value_cross_site_double_key)); + EXPECT_EQ(original_cross_site_double_key, from_value_cross_site_double_key); + + // Turn double keying on. + scoped_feature_list_.Reset(); + scoped_feature_list_.InitAndEnableFeature( + net::features::kEnableDoubleKeyNetworkAnonymizationKey); + + // Check that deserializing the cross site double keyed value fails. + EXPECT_FALSE(NetworkAnonymizationKey::FromValue(cross_site_double_key_value, + &expected_failure_nak)); + + // Turn triple keying back on. + scoped_feature_list_.Reset(); + scoped_feature_list_.InitAndDisableFeature( + net::features::kEnableDoubleKeyNetworkAnonymizationKey); + + // Check that deserializing the double keyed value fails. + EXPECT_FALSE(NetworkAnonymizationKey::FromValue(double_key_value, + &expected_failure_nak)); + + // Check that deserializing the cross site double keyed value fails. + EXPECT_FALSE(NetworkAnonymizationKey::FromValue(cross_site_double_key_value, + &expected_failure_nak)); +} + +} // namespace net diff --git a/chromium/net/base/network_change_notifier.cc b/chromium/net/base/network_change_notifier.cc index 1a993852691..cc8d2bcbf32 100644 --- a/chromium/net/base/network_change_notifier.cc +++ b/chromium/net/base/network_change_notifier.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -248,11 +248,6 @@ class NetworkChangeNotifier::ObserverList { const scoped_refptr< base::ObserverListThreadSafe<DefaultNetworkActiveObserver>> default_network_active_observer_list_; - - // Indicates if connection cost observer was added before - // network_change_notifier was initialized, if so ConnectionCostObserverAdded - // is invoked from constructor. - std::atomic_bool connection_cost_observers_added_ = false; }; class NetworkChangeNotifier::SystemDnsConfigObserver @@ -687,13 +682,8 @@ void NetworkChangeNotifier::AddNetworkObserver(NetworkObserver* observer) { void NetworkChangeNotifier::AddConnectionCostObserver( ConnectionCostObserver* observer) { DCHECK(!observer->observer_list_); - GetObserverList().connection_cost_observers_added_ = true; observer->observer_list_ = GetObserverList().connection_cost_observer_list_; observer->observer_list_->AddObserver(observer); - base::AutoLock auto_lock(NetworkChangeNotifierCreationLock()); - if (g_network_change_notifier) { - g_network_change_notifier->ConnectionCostObserverAdded(); - } } void NetworkChangeNotifier::AddDefaultNetworkActiveObserver( @@ -852,9 +842,6 @@ NetworkChangeNotifier::NetworkChangeNotifier( g_network_change_notifier = this; system_dns_config_notifier_->AddObserver(system_dns_config_observer_.get()); - if (GetObserverList().connection_cost_observers_added_) { - g_network_change_notifier->ConnectionCostObserverAdded(); - } } if (!omit_observers_in_constructor_for_testing) { network_change_calculator_ = diff --git a/chromium/net/base/network_change_notifier.h b/chromium/net/base/network_change_notifier.h index b04f7deb7ab..c79374c9a8e 100644 --- a/chromium/net/base/network_change_notifier.h +++ b/chromium/net/base/network_change_notifier.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -670,13 +670,6 @@ class NET_EXPORT NetworkChangeNotifier { // as early as possible in the destructor to prevent races. void ClearGlobalPointer(); - // Called whenever a new ConnectionCostObserver is added. This method is - // needed so that the implementation class can be notified and - // potentially take action when an observer gets added. Since the act of - // adding an observer and the observer list itself are both static, the - // implementation class has no direct capability to watch for changes. - virtual void ConnectionCostObserverAdded() {} - // Listening for notifications of this type is expensive as they happen // frequently. For this reason, we report {de}registration to the // implementation class, so that it can decide to only listen to this type of diff --git a/chromium/net/base/network_change_notifier_factory.h b/chromium/net/base/network_change_notifier_factory.h index 96bd6a2fbdc..31ec69ecd4d 100644 --- a/chromium/net/base/network_change_notifier_factory.h +++ b/chromium/net/base/network_change_notifier_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_fuchsia.cc b/chromium/net/base/network_change_notifier_fuchsia.cc index 329dd3feca5..fc7a165ef9c 100644 --- a/chromium/net/base/network_change_notifier_fuchsia.cc +++ b/chromium/net/base/network_change_notifier_fuchsia.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_fuchsia.h b/chromium/net/base/network_change_notifier_fuchsia.h index 20c97a1cf78..db880127dbe 100644 --- a/chromium/net/base/network_change_notifier_fuchsia.h +++ b/chromium/net/base/network_change_notifier_fuchsia.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_fuchsia_unittest.cc b/chromium/net/base/network_change_notifier_fuchsia_unittest.cc index da00416653c..e36cb347358 100644 --- a/chromium/net/base/network_change_notifier_fuchsia_unittest.cc +++ b/chromium/net/base/network_change_notifier_fuchsia_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_linux.cc b/chromium/net/base/network_change_notifier_linux.cc index 5a21d362f44..793ed8d6114 100644 --- a/chromium/net/base/network_change_notifier_linux.cc +++ b/chromium/net/base/network_change_notifier_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_linux.h b/chromium/net/base/network_change_notifier_linux.h index d4ba080b1c1..6c4a71aa373 100644 --- a/chromium/net/base/network_change_notifier_linux.h +++ b/chromium/net/base/network_change_notifier_linux.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_mac.h b/chromium/net/base/network_change_notifier_mac.h index dc69ac9af7a..b40c825d673 100644 --- a/chromium/net/base/network_change_notifier_mac.h +++ b/chromium/net/base/network_change_notifier_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_mac.mm b/chromium/net/base/network_change_notifier_mac.mm index ece759f667b..f8ff5193d04 100644 --- a/chromium/net/base/network_change_notifier_mac.mm +++ b/chromium/net/base/network_change_notifier_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_posix.cc b/chromium/net/base/network_change_notifier_posix.cc index 6bc215cf893..c7b5c965293 100644 --- a/chromium/net/base/network_change_notifier_posix.cc +++ b/chromium/net/base/network_change_notifier_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_posix.h b/chromium/net/base/network_change_notifier_posix.h index 611f0536c10..92e1c76beed 100644 --- a/chromium/net/base/network_change_notifier_posix.h +++ b/chromium/net/base/network_change_notifier_posix.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_posix_unittest.cc b/chromium/net/base/network_change_notifier_posix_unittest.cc index 2649ecf64fc..a5c6967c153 100644 --- a/chromium/net/base/network_change_notifier_posix_unittest.cc +++ b/chromium/net/base/network_change_notifier_posix_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_change_notifier_unittest.cc b/chromium/net/base/network_change_notifier_unittest.cc index 9ff65e0bb3d..89013ac4b11 100644 --- a/chromium/net/base/network_change_notifier_unittest.cc +++ b/chromium/net/base/network_change_notifier_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,7 @@ #include "build/build_config.h" #include "net/base/mock_network_change_notifier.h" #include "net/base/network_interfaces.h" +#include "net/test/test_connection_cost_observer.h" #include "net/test/test_with_task_environment.h" #include "testing/gtest/include/gtest/gtest.h" @@ -226,37 +227,17 @@ TEST_F(NetworkChangeNotifierMockedTest, TriggerNonSystemDnsChange) { NetworkChangeNotifier::RemoveDNSObserver(&observer); } -class TestConnectionCostObserver - : public NetworkChangeNotifier::ConnectionCostObserver { - public: - void OnConnectionCostChanged( - NetworkChangeNotifier::ConnectionCost cost) override { - cost_changed_inputs_.push_back(cost); - ++cost_changed_calls_; - } - - int cost_changed_calls() const { return cost_changed_calls_; } - std::vector<NetworkChangeNotifier::ConnectionCost> cost_changed_inputs() - const { - return cost_changed_inputs_; - } - - private: - int cost_changed_calls_ = 0; - std::vector<NetworkChangeNotifier::ConnectionCost> cost_changed_inputs_; -}; - TEST_F(NetworkChangeNotifierMockedTest, TriggerConnectionCostChange) { TestConnectionCostObserver observer; NetworkChangeNotifier::AddConnectionCostObserver(&observer); - ASSERT_EQ(0, observer.cost_changed_calls()); + ASSERT_EQ(0u, observer.cost_changed_calls()); NetworkChangeNotifier::NotifyObserversOfConnectionCostChangeForTests( NetworkChangeNotifier::CONNECTION_COST_METERED); base::RunLoop().RunUntilIdle(); - EXPECT_EQ(1, observer.cost_changed_calls()); + EXPECT_EQ(1u, observer.cost_changed_calls()); EXPECT_EQ(NetworkChangeNotifier::CONNECTION_COST_METERED, observer.cost_changed_inputs()[0]); @@ -265,7 +246,7 @@ TEST_F(NetworkChangeNotifierMockedTest, TriggerConnectionCostChange) { NetworkChangeNotifier::CONNECTION_COST_UNMETERED); base::RunLoop().RunUntilIdle(); - EXPECT_EQ(1, observer.cost_changed_calls()); + EXPECT_EQ(1u, observer.cost_changed_calls()); } TEST_F(NetworkChangeNotifierMockedTest, ConnectionCostDefaultsToCellular) { diff --git a/chromium/net/base/network_change_notifier_win.cc b/chromium/net/base/network_change_notifier_win.cc index 2a1563eeaca..e12985be7e4 100644 --- a/chromium/net/base/network_change_notifier_win.cc +++ b/chromium/net/base/network_change_notifier_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,7 +21,7 @@ #include "base/threading/thread.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" -#include "base/win/windows_version.h" +#include "net/base/network_cost_change_notifier_win.h" #include "net/base/winsock_init.h" #include "net/base/winsock_util.h" @@ -32,88 +32,8 @@ namespace { // Time between NotifyAddrChange retries, on failure. const int kWatchForAddressChangeRetryIntervalMs = 500; -HRESULT GetConnectionPoints(IUnknown* manager, - REFIID IIDSyncInterface, - IConnectionPoint** connection_point_raw) { - *connection_point_raw = nullptr; - Microsoft::WRL::ComPtr<IConnectionPointContainer> connection_point_container; - HRESULT hr = - manager->QueryInterface(IID_PPV_ARGS(&connection_point_container)); - if (FAILED(hr)) - return hr; - - // Find the interface - Microsoft::WRL::ComPtr<IConnectionPoint> connection_point; - hr = connection_point_container->FindConnectionPoint(IIDSyncInterface, - &connection_point); - if (FAILED(hr)) - return hr; - - *connection_point_raw = connection_point.Get(); - (*connection_point_raw)->AddRef(); - - return hr; -} - } // namespace -// This class is used as an event sink to register for notifications from the -// INetworkCostManagerEvents interface. In particular, we are focused on getting -// notified when the Connection Cost changes. This is only supported on Win10+. -class NetworkCostManagerEventSink - : public Microsoft::WRL::RuntimeClass< - Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, - INetworkCostManagerEvents> { - public: - using CostChangedCallback = base::RepeatingCallback<void()>; - - NetworkCostManagerEventSink(INetworkCostManager* cost_manager, - const CostChangedCallback& callback) - : network_cost_manager_(cost_manager), cost_changed_callback_(callback) {} - ~NetworkCostManagerEventSink() override = default; - - // INetworkCostManagerEvents members - IFACEMETHODIMP CostChanged(_In_ DWORD cost, - _In_opt_ NLM_SOCKADDR* /*pSockAddr*/) override { - cost_changed_callback_.Run(); - return S_OK; - } - - IFACEMETHODIMP DataPlanStatusChanged( - _In_opt_ NLM_SOCKADDR* /*pSockAddr*/) override { - return S_OK; - } - - HRESULT RegisterForNotifications() { - Microsoft::WRL::ComPtr<IUnknown> unknown; - HRESULT hr = QueryInterface(IID_PPV_ARGS(&unknown)); - if (hr != S_OK) - return hr; - - hr = GetConnectionPoints(network_cost_manager_.Get(), - IID_INetworkCostManagerEvents, &connection_point_); - if (hr != S_OK) - return hr; - - hr = connection_point_->Advise(unknown.Get(), &cookie_); - return hr; - } - - void UnRegisterForNotifications() { - if (connection_point_) { - connection_point_->Unadvise(cookie_); - connection_point_ = nullptr; - cookie_ = 0; - } - } - - private: - Microsoft::WRL::ComPtr<INetworkCostManager> network_cost_manager_; - Microsoft::WRL::ComPtr<IConnectionPoint> connection_point_; - DWORD cookie_ = 0; - CostChangedCallback cost_changed_callback_; -}; - NetworkChangeNotifierWin::NetworkChangeNotifierWin() : NetworkChangeNotifier(NetworkChangeCalculatorParamsWin()), blocking_task_runner_( @@ -125,6 +45,10 @@ NetworkChangeNotifierWin::NetworkChangeNotifierWin() base::SequencedTaskRunnerHandle::Get()) { memset(&addr_overlapped_, 0, sizeof addr_overlapped_); addr_overlapped_.hEvent = WSACreateEvent(); + + cost_change_notifier_ = NetworkCostChangeNotifierWin::CreateInstance( + base::BindRepeating(&NetworkChangeNotifierWin::OnCostChanged, + weak_factory_.GetWeakPtr())); } NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { @@ -135,11 +59,6 @@ NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { addr_watcher_.StopWatching(); } WSACloseEvent(addr_overlapped_.hEvent); - - if (network_cost_manager_event_sink_) { - network_cost_manager_event_sink_->UnRegisterForNotifications(); - network_cost_manager_event_sink_ = nullptr; - } } // static @@ -281,115 +200,23 @@ void NetworkChangeNotifierWin::RecomputeCurrentConnectionTypeOnBlockingSequence( NetworkChangeNotifier::ConnectionCost NetworkChangeNotifierWin::GetCurrentConnectionCost() { - InitializeConnectionCost(); - - // Pre-Win10 use the default logic. - if (base::win::GetVersion() < base::win::Version::WIN10) + if (last_computed_connection_cost_ == + ConnectionCost::CONNECTION_COST_UNKNOWN) { + // Use the default logic when the Windows OS APIs do not have a cost for the + // current connection. return NetworkChangeNotifier::GetCurrentConnectionCost(); - - // If we don't have the event sink we aren't registered for automatic updates. - // In that case, we need to update the value at the time it is requested. - if (!network_cost_manager_event_sink_) - UpdateConnectionCostFromCostManager(); - - return last_computed_connection_cost_; -} - -bool NetworkChangeNotifierWin::InitializeConnectionCostOnce() { - // Pre-Win10 this information cannot be retrieved and cached. - if (base::win::GetVersion() < base::win::Version::WIN10) { - SetCurrentConnectionCost(CONNECTION_COST_UNKNOWN); - return true; - } - - HRESULT hr = - ::CoCreateInstance(CLSID_NetworkListManager, nullptr, CLSCTX_ALL, - IID_INetworkCostManager, &network_cost_manager_); - if (FAILED(hr)) { - SetCurrentConnectionCost(CONNECTION_COST_UNKNOWN); - return true; } - - UpdateConnectionCostFromCostManager(); - - return true; -} - -void NetworkChangeNotifierWin::InitializeConnectionCost() { - static bool g_connection_cost_initialized = InitializeConnectionCostOnce(); - DCHECK(g_connection_cost_initialized); -} - -HRESULT NetworkChangeNotifierWin::UpdateConnectionCostFromCostManager() { - if (!network_cost_manager_) - return E_ABORT; - - DWORD cost = NLM_CONNECTION_COST_UNKNOWN; - HRESULT hr = network_cost_manager_->GetCost(&cost, nullptr); - if (FAILED(hr)) { - SetCurrentConnectionCost(CONNECTION_COST_UNKNOWN); - } else { - SetCurrentConnectionCost( - ConnectionCostFromNlmCost((NLM_CONNECTION_COST)cost)); - } - return hr; -} - -// static -NetworkChangeNotifier::ConnectionCost -NetworkChangeNotifierWin::ConnectionCostFromNlmCost(NLM_CONNECTION_COST cost) { - if (cost == NLM_CONNECTION_COST_UNKNOWN) - return CONNECTION_COST_UNKNOWN; - else if ((cost & NLM_CONNECTION_COST_UNRESTRICTED) != 0) - return CONNECTION_COST_UNMETERED; - else - return CONNECTION_COST_METERED; + return last_computed_connection_cost_; } -void NetworkChangeNotifierWin::SetCurrentConnectionCost( - ConnectionCost connection_cost) { - last_computed_connection_cost_ = connection_cost; -} +void NetworkChangeNotifierWin::OnCostChanged( + NetworkChangeNotifier::ConnectionCost new_cost) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); -void NetworkChangeNotifierWin::OnCostChanged() { - ConnectionCost old_cost = last_computed_connection_cost_; - // It is possible to get multiple notifications in a short period of time. - // Rather than worrying about whether this notification represents the latest, - // just get the current value from the CostManager so we know that we're - // actually getting the correct value. - UpdateConnectionCostFromCostManager(); // Only notify if there's actually a change. - if (old_cost != GetCurrentConnectionCost()) + if (last_computed_connection_cost_ != new_cost) { + last_computed_connection_cost_ = new_cost; NotifyObserversOfConnectionCostChange(); -} - -void NetworkChangeNotifierWin::ConnectionCostObserverAdded() { - sequence_runner_for_registration_->PostTask( - FROM_HERE, - base::BindOnce(&NetworkChangeNotifierWin::OnConnectionCostObserverAdded, - weak_factory_.GetWeakPtr())); -} - -void NetworkChangeNotifierWin::OnConnectionCostObserverAdded() { - DCHECK(sequence_runner_for_registration_->RunsTasksInCurrentSequence()); - InitializeConnectionCost(); - - // No need to register if we don't have a cost manager or if we're already - // registered. - if (!network_cost_manager_ || network_cost_manager_event_sink_) - return; - - network_cost_manager_event_sink_ = - Microsoft::WRL::Make<net::NetworkCostManagerEventSink>( - network_cost_manager_.Get(), - base::BindRepeating(&NetworkChangeNotifierWin::OnCostChanged, - weak_factory_.GetWeakPtr())); - HRESULT hr = network_cost_manager_event_sink_->RegisterForNotifications(); - if (hr != S_OK) { - // If registration failed for any reason, just destroy the event sink. The - // observer will remain connected but will not receive any updates. If - // another observer gets added later, we can re-attempt registration. - network_cost_manager_event_sink_ = nullptr; } } @@ -491,8 +318,8 @@ void NetworkChangeNotifierWin::NotifyParentOfConnectionTypeChangeImpl( offline_polls_++; // If we continue to appear offline, delay sending out the notification in // case we appear to go online within 20 seconds. UMA histogram data shows - // we may not detect the transition to online state after 1 second but within - // 20 seconds we generally do. + // we may not detect the transition to online state after 1 second but + // within 20 seconds we generally do. if (last_announced_offline_ && current_offline && offline_polls_ <= 20) { timer_.Start(FROM_HERE, base::Seconds(1), this, &NetworkChangeNotifierWin::NotifyParentOfConnectionTypeChange); diff --git a/chromium/net/base/network_change_notifier_win.h b/chromium/net/base/network_change_notifier_win.h index f1989cb7315..c89af0359c8 100644 --- a/chromium/net/base/network_change_notifier_win.h +++ b/chromium/net/base/network_change_notifier_win.h @@ -1,17 +1,13 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ -#include <netlistmgr.h> -#include <ocidl.h> #include <windows.h> -#include <wrl.h> -#include <wrl/client.h> -#include <memory> +#include <atomic> #include "base/callback.h" #include "base/compiler_specific.h" @@ -19,6 +15,7 @@ #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "base/thread_annotations.h" +#include "base/threading/sequence_bound.h" #include "base/timer/timer.h" #include "base/win/object_watcher.h" #include "net/base/net_export.h" @@ -30,7 +27,7 @@ class SequencedTaskRunner; namespace net { -class NetworkCostManagerEventSink; +class NetworkCostChangeNotifierWin; // NetworkChangeNotifierWin uses a SequenceChecker, as all its internal // notification code must be called on the sequence it is created and destroyed @@ -100,25 +97,7 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsWin(); - // Gets the current network connection cost (if possible) and caches it. - void InitializeConnectionCost(); - // Does the work of initializing for thread safety. - bool InitializeConnectionCostOnce(); - // Retrieves the current network connection cost from the OS's Cost Manager. - HRESULT UpdateConnectionCostFromCostManager(); - // Converts the OS enum values to the enum values used in our code. - static ConnectionCost ConnectionCostFromNlmCost(NLM_CONNECTION_COST cost); - // Sets the cached network connection cost value. - void SetCurrentConnectionCost(ConnectionCost connection_cost); - // Callback method for the notification event sink. - void OnCostChanged(); - // Tells this class that an observer was added and therefore this class needs - // to register for notifications. - void ConnectionCostObserverAdded() override; - // Since ConnectionCostObserverAdded() can be called on any thread and we - // don't want to do a bunch of work on an arbitrary thread, this method used - // to post task to do the work. - void OnConnectionCostObserverAdded(); + void OnCostChanged(NetworkChangeNotifier::ConnectionCost new_cost); // All member variables may only be accessed on the sequence |this| was // created on. @@ -141,8 +120,13 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin mutable base::Lock last_computed_connection_type_lock_; ConnectionType last_computed_connection_type_; - std::atomic<ConnectionCost> last_computed_connection_cost_ = - ConnectionCost::CONNECTION_COST_UNKNOWN; + std::atomic<NetworkChangeNotifier::ConnectionCost> + last_computed_connection_cost_ = + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN; + + // Provides the cost of the current connection. Uses the Windows OS APIs to + // monitor and determine cost. + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier_; // Result of IsOffline() when NotifyObserversOfConnectionTypeChange() // was last called. @@ -150,10 +134,6 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin // Number of times polled to check if still offline. int offline_polls_; - Microsoft::WRL::ComPtr<INetworkCostManager> network_cost_manager_; - Microsoft::WRL::ComPtr<NetworkCostManagerEventSink> - network_cost_manager_event_sink_; - // Used to ensure that all registration actions are properly sequenced on the // same thread regardless of which thread was used to call into the // NetworkChangeNotifier API. diff --git a/chromium/net/base/network_change_notifier_win_unittest.cc b/chromium/net/base/network_change_notifier_win_unittest.cc index 8566136762d..cbb1b24ba63 100644 --- a/chromium/net/base/network_change_notifier_win_unittest.cc +++ b/chromium/net/base/network_change_notifier_win_unittest.cc @@ -1,19 +1,25 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/network_change_notifier_win.h" +#include <memory> #include <utility> +#include <vector> #include "base/bind.h" #include "base/run_loop.h" +#include "base/sequence_checker.h" #include "base/task/single_thread_task_runner.h" +#include "base/test/scoped_os_info_override_win.h" #include "base/threading/thread_task_runner_handle.h" #include "base/win/windows_version.h" #include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier_factory.h" +#include "net/test/test_connection_cost_observer.h" #include "net/test/test_with_task_environment.h" +#include "net/test/win/fake_network_cost_manager.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -31,7 +37,6 @@ class TestNetworkChangeNotifierWin : public NetworkChangeNotifierWin { TestNetworkChangeNotifierWin() { last_computed_connection_type_ = NetworkChangeNotifier::CONNECTION_UNKNOWN; last_announced_offline_ = false; - last_computed_connection_cost_ = ConnectionCost::CONNECTION_COST_UNKNOWN; sequence_runner_for_registration_ = base::SequencedTaskRunnerHandle::Get(); } @@ -55,18 +60,23 @@ class TestNetworkChangeNotifierWin : public NetworkChangeNotifierWin { // From NetworkChangeNotifierWin. MOCK_METHOD0(WatchForAddressChangeInternal, bool()); + + // Allow tests to compare results with the default implementation that does + // not depend on the INetworkCostManager Windows OS API. The default + // implementation is used as a fall back when INetworkCostManager fails. + ConnectionCost GetCurrentConnectionCostFromDefaultImplementation() { + return NetworkChangeNotifier::GetCurrentConnectionCost(); + } }; class TestIPAddressObserver : public NetworkChangeNotifier::IPAddressObserver { public: - TestIPAddressObserver() { - NetworkChangeNotifier::AddIPAddressObserver(this); - } + TestIPAddressObserver() { NetworkChangeNotifier::AddIPAddressObserver(this); } TestIPAddressObserver(const TestIPAddressObserver&) = delete; TestIPAddressObserver& operator=(const TestIPAddressObserver&) = delete; - ~TestIPAddressObserver() { + ~TestIPAddressObserver() override { NetworkChangeNotifier::RemoveIPAddressObserver(this); } @@ -182,7 +192,8 @@ class NetworkChangeNotifierWinTest : public TestWithTaskEnvironment { .Times(1) .WillOnce(Invoke(&run_loop, &base::RunLoop::QuitWhenIdle)); EXPECT_CALL(network_change_notifier_, WatchForAddressChangeInternal()) - .Times(1).WillOnce(Return(true)); + .Times(1) + .WillOnce(Return(true)); run_loop.Run(); @@ -219,22 +230,18 @@ class NetworkChangeNotifierWinTest : public TestWithTaskEnvironment { base::RunLoop().RunUntilIdle(); } - bool HasNetworkCostManager() { - return network_change_notifier_.network_cost_manager_.Get() != nullptr; - } - - bool HasNetworkCostManagerEventSink() { - return network_change_notifier_.network_cost_manager_event_sink_.Get() != - nullptr; + NetworkChangeNotifier::ConnectionCost GetCurrentConnectionCost() { + return network_change_notifier_.GetCurrentConnectionCost(); } - NetworkChangeNotifier::ConnectionCost LastComputedConnectionCost() { - return network_change_notifier_.last_computed_connection_cost_; + NetworkChangeNotifier::ConnectionCost + GetCurrentConnectionCostFromDefaultImplementation() { + return network_change_notifier_ + .GetCurrentConnectionCostFromDefaultImplementation(); } - NetworkChangeNotifier::ConnectionCost GetCurrentConnectionCost() { - return network_change_notifier_.GetCurrentConnectionCost(); - } + protected: + FakeNetworkCostManagerEnvironment fake_network_cost_manager_environment_; private: // Note that the order of declaration here is important. @@ -287,58 +294,102 @@ TEST_F(NetworkChangeNotifierWinTest, NetChangeWinFailSignalTwice) { RetryAndSucceed(); } -class TestConnectionCostObserver - : public NetworkChangeNotifier::ConnectionCostObserver { - public: - TestConnectionCostObserver() {} +TEST_F(NetworkChangeNotifierWinTest, GetCurrentCost) { + if (base::win::GetVersion() < base::win::Version::WIN10) + return; - TestConnectionCostObserver(const TestConnectionCostObserver&) = delete; - TestConnectionCostObserver& operator=(const TestConnectionCostObserver&) = - delete; + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); - ~TestConnectionCostObserver() override { - NetworkChangeNotifier::RemoveConnectionCostObserver(this); - } + // Wait for NetworkCostChangeNotifierWin to finish initializing. + RunUntilIdle(); - void OnConnectionCostChanged(NetworkChangeNotifier::ConnectionCost) override { - } + EXPECT_EQ(GetCurrentConnectionCost(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); - void Register() { NetworkChangeNotifier::AddConnectionCostObserver(this); } -}; + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_METERED); + + // Wait for NetworkCostChangeNotifierWin to handle the cost changed event. + RunUntilIdle(); + + EXPECT_EQ(GetCurrentConnectionCost(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_METERED); +} -TEST_F(NetworkChangeNotifierWinTest, NetworkCostManagerIntegration) { - // NetworkCostManager integration only exist on Win10+. +TEST_F(NetworkChangeNotifierWinTest, CostChangeObserver) { if (base::win::GetVersion() < base::win::Version::WIN10) return; - // Upon creation, none of the NetworkCostManager integration should be - // initialized yet. - ASSERT_FALSE(HasNetworkCostManager()); - ASSERT_FALSE(HasNetworkCostManagerEventSink()); - ASSERT_EQ(NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN, - LastComputedConnectionCost()); - - // Asking for the current connection cost should initialize the - // NetworkCostManager integration, but not the event sink. - // Note that the actual ConnectionCost value return is irrelevant beyond the - // fact that it shouldn't be UNKNOWN anymore if the integration is initialized - // properly. - NetworkChangeNotifier::ConnectionCost current_connection_cost = - GetCurrentConnectionCost(); - EXPECT_NE(NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN, - current_connection_cost); - EXPECT_EQ(current_connection_cost, LastComputedConnectionCost()); - EXPECT_TRUE(HasNetworkCostManager()); - EXPECT_FALSE(HasNetworkCostManagerEventSink()); - - // Adding a ConnectionCostObserver should initialize the event sink. If the - // subsequent registration for updates fails, the event sink will get - // destroyed. - TestConnectionCostObserver test_connection_cost_observer; - test_connection_cost_observer.Register(); - // The actual registration happens on a callback, so need to run until idle. - base::RunLoop().RunUntilIdle(); - EXPECT_TRUE(HasNetworkCostManagerEventSink()); + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + // Wait for NetworkCostChangeNotifierWin to finish initializing. + RunUntilIdle(); + + TestConnectionCostObserver cost_observer; + NetworkChangeNotifier::AddConnectionCostObserver(&cost_observer); + + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_METERED); + + cost_observer.WaitForConnectionCostChanged(); + + ASSERT_EQ(cost_observer.cost_changed_calls(), 1u); + EXPECT_EQ(cost_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_METERED); + + NetworkChangeNotifier::RemoveConnectionCostObserver(&cost_observer); +} + +// Uses the fake implementation of INetworkCostManager to simulate GetCost() +// returning an error HRESULT. +class NetworkChangeNotifierWinCostErrorTest + : public NetworkChangeNotifierWinTest { + void SetUp() override { + if (base::win::GetVersion() < base::win::Version::WIN10) { + GTEST_SKIP(); + } + + fake_network_cost_manager_environment_.SimulateError( + NetworkCostManagerStatus::kErrorGetCostFailed); + + NetworkChangeNotifierWinTest::SetUp(); + } +}; + +TEST_F(NetworkChangeNotifierWinCostErrorTest, CostError) { + // Wait for NetworkCostChangeNotifierWin to finish initializing, which should + // fail with an error. + RunUntilIdle(); + + // NetworkChangeNotifierWin must use the default implementation when + // NetworkCostChangeNotifierWin returns an unknown cost. + EXPECT_EQ(GetCurrentConnectionCost(), + GetCurrentConnectionCostFromDefaultImplementation()); +} + +// Override the Windows OS version to simulate running on an OS that does not +// support INetworkCostManager. +class NetworkChangeNotifierWinCostUnsupportedOsTest + : public NetworkChangeNotifierWinTest { + public: + NetworkChangeNotifierWinCostUnsupportedOsTest() + : os_override_(base::test::ScopedOSInfoOverride::Type::kWin81Pro) {} + + protected: + base::test::ScopedOSInfoOverride os_override_; +}; + +TEST_F(NetworkChangeNotifierWinCostUnsupportedOsTest, CostWithUnsupportedOS) { + // Wait for NetworkCostChangeNotifierWin to finish initializing, which should + // initialize with an unknown cost on an unsupported OS. + RunUntilIdle(); + + // NetworkChangeNotifierWin must use the default implementation when + // NetworkCostChangeNotifierWin returns an unknown cost. + EXPECT_EQ(GetCurrentConnectionCost(), + GetCurrentConnectionCostFromDefaultImplementation()); } } // namespace net diff --git a/chromium/net/base/network_config_watcher_mac.cc b/chromium/net/base/network_config_watcher_mac.cc index efa7481dd5f..608996333f0 100644 --- a/chromium/net/base/network_config_watcher_mac.cc +++ b/chromium/net/base/network_config_watcher_mac.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_config_watcher_mac.h b/chromium/net/base/network_config_watcher_mac.h index 8c01b7a1ed4..1e50e3a6e3d 100644 --- a/chromium/net/base/network_config_watcher_mac.h +++ b/chromium/net/base/network_config_watcher_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_cost_change_notifier_win.cc b/chromium/net/base/network_cost_change_notifier_win.cc new file mode 100644 index 00000000000..abc56a415f9 --- /dev/null +++ b/chromium/net/base/network_cost_change_notifier_win.cc @@ -0,0 +1,271 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/network_cost_change_notifier_win.h" + +#include <wrl.h> +#include <wrl/client.h> + +#include "base/check.h" +#include "base/no_destructor.h" +#include "base/task/bind_post_task.h" +#include "base/task/thread_pool.h" +#include "base/threading/scoped_thread_priority.h" +#include "base/threading/thread_task_runner_handle.h" +#include "base/win/com_init_util.h" +#include "base/win/windows_version.h" + +using Microsoft::WRL::ComPtr; + +namespace net { + +namespace { + +NetworkChangeNotifier::ConnectionCost ConnectionCostFromNlmConnectionCost( + DWORD connection_cost_flags) { + if (connection_cost_flags == NLM_CONNECTION_COST_UNKNOWN) + return NetworkChangeNotifier::CONNECTION_COST_UNKNOWN; + else if ((connection_cost_flags & NLM_CONNECTION_COST_UNRESTRICTED) != 0) + return NetworkChangeNotifier::CONNECTION_COST_UNMETERED; + else + return NetworkChangeNotifier::CONNECTION_COST_METERED; +} + +NetworkCostChangeNotifierWin::CoCreateInstanceCallback& +GetCoCreateInstanceOverride() { + static base::NoDestructor< + NetworkCostChangeNotifierWin::CoCreateInstanceCallback> + callback_for_testing; + return *callback_for_testing; +} + +} // namespace + +// This class is used as an event sink to register for notifications from the +// INetworkCostManagerEvents interface. In particular, we are focused on getting +// notified when the connection cost changes. This is only supported on Win10+. +class NetworkCostManagerEventSinkWin final + : public Microsoft::WRL::RuntimeClass< + Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, + INetworkCostManagerEvents> { + public: + static HRESULT CreateInstance( + INetworkCostManager* network_cost_manager, + base::RepeatingClosure cost_changed_callback, + ComPtr<NetworkCostManagerEventSinkWin>* result) { + ComPtr<NetworkCostManagerEventSinkWin> instance = + Microsoft::WRL::Make<net::NetworkCostManagerEventSinkWin>( + cost_changed_callback); + HRESULT hr = instance->RegisterForNotifications(network_cost_manager); + if (hr != S_OK) { + return hr; + } + + *result = instance; + return S_OK; + } + + void UnRegisterForNotifications() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + if (event_sink_connection_point_) { + event_sink_connection_point_->Unadvise(event_sink_connection_cookie_); + event_sink_connection_point_.Reset(); + } + } + + // Implement the INetworkCostManagerEvents interface. + HRESULT __stdcall CostChanged(DWORD /*cost*/, + NLM_SOCKADDR* /*socket_address*/) final { + // It is possible to get multiple notifications in a short period of time. + // Rather than worrying about whether this notification represents the + // latest, just notify the owner who can get the current value from the + // INetworkCostManager so we know that we're actually getting the correct + // value. + cost_changed_callback_.Run(); + return S_OK; + } + + HRESULT __stdcall DataPlanStatusChanged( + NLM_SOCKADDR* /*socket_address*/) final { + return S_OK; + } + + NetworkCostManagerEventSinkWin(base::RepeatingClosure cost_changed_callback) + : cost_changed_callback_(cost_changed_callback) {} + + NetworkCostManagerEventSinkWin(const NetworkCostManagerEventSinkWin&) = + delete; + NetworkCostManagerEventSinkWin& operator=( + const NetworkCostManagerEventSinkWin&) = delete; + + private: + ~NetworkCostManagerEventSinkWin() final = default; + + HRESULT RegisterForNotifications(INetworkCostManager* cost_manager) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK_GE(base::win::GetVersion(), base::win::Version::WIN10); + + base::win::AssertComInitialized(); + base::win::AssertComApartmentType(base::win::ComApartmentType::STA); + + ComPtr<IUnknown> this_event_sink_unknown; + HRESULT hr = QueryInterface(IID_PPV_ARGS(&this_event_sink_unknown)); + + // `NetworkCostManagerEventSinkWin::QueryInterface` for `IUnknown` must + // succeed since it is implemented by this class. + DCHECK_EQ(hr, S_OK); + + ComPtr<IConnectionPointContainer> connection_point_container; + hr = + cost_manager->QueryInterface(IID_PPV_ARGS(&connection_point_container)); + if (hr != S_OK) { + return hr; + } + + Microsoft::WRL::ComPtr<IConnectionPoint> event_sink_connection_point; + hr = connection_point_container->FindConnectionPoint( + IID_INetworkCostManagerEvents, &event_sink_connection_point); + if (hr != S_OK) { + return hr; + } + + hr = event_sink_connection_point->Advise(this_event_sink_unknown.Get(), + &event_sink_connection_cookie_); + if (hr != S_OK) { + return hr; + } + + DCHECK_EQ(event_sink_connection_point_, nullptr); + event_sink_connection_point_ = event_sink_connection_point; + return S_OK; + } + + base::RepeatingClosure cost_changed_callback_; + + // The following members must be accessed on the sequence from + // `sequence_checker_` + SEQUENCE_CHECKER(sequence_checker_); + DWORD event_sink_connection_cookie_ = 0; + Microsoft::WRL::ComPtr<IConnectionPoint> event_sink_connection_point_; +}; + +// static +base::SequenceBound<NetworkCostChangeNotifierWin> +NetworkCostChangeNotifierWin::CreateInstance( + CostChangedCallback cost_changed_callback) { + scoped_refptr<base::SequencedTaskRunner> com_best_effort_task_runner = + base::ThreadPool::CreateCOMSTATaskRunner( + {base::MayBlock(), base::TaskPriority::BEST_EFFORT, + base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}); + + return base::SequenceBound<NetworkCostChangeNotifierWin>( + com_best_effort_task_runner, + // Ensure `cost_changed_callback` runs on the sequence of the creator and + // owner of `NetworkCostChangeNotifierWin`. + base::BindPostTask(base::SequencedTaskRunnerHandle::Get(), + cost_changed_callback)); +} + +NetworkCostChangeNotifierWin::NetworkCostChangeNotifierWin( + CostChangedCallback cost_changed_callback) + : cost_changed_callback_(cost_changed_callback) { + StartWatching(); +} + +NetworkCostChangeNotifierWin::~NetworkCostChangeNotifierWin() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + StopWatching(); +} + +void NetworkCostChangeNotifierWin::StartWatching() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + if (base::win::GetComApartmentTypeForThread() == + base::win::ComApartmentType::NONE) { + // TODO(crbug.com/1367360): INetworkCostManager inaccessible in network + // sandbox. Currently, the network sandbox does not allow COM. + return; + } + + base::win::AssertComInitialized(); + base::win::AssertComApartmentType(base::win::ComApartmentType::STA); + + if (base::win::GetVersion() < base::win::Version::WIN10) { + // INetworkCostManager requires Win10 or higher. + return; + } + + SCOPED_MAY_LOAD_LIBRARY_AT_BACKGROUND_PRIORITY(); + + // Create INetworkListManager using CoCreateInstance, but allow tests to + // provide an fake implementation of INetworkListManager through an override. + CoCreateInstanceCallback co_create_instance_callback = + base::BindRepeating(&CoCreateInstance); + if (GetCoCreateInstanceOverride()) { + co_create_instance_callback = GetCoCreateInstanceOverride(); + } + + ComPtr<INetworkCostManager> cost_manager; + HRESULT hr = co_create_instance_callback.Run( + CLSID_NetworkListManager, /*unknown_outer=*/nullptr, CLSCTX_ALL, + IID_INetworkCostManager, &cost_manager); + if (hr != S_OK) { + return; + } + + // Subscribe to cost changed events. + hr = NetworkCostManagerEventSinkWin::CreateInstance( + cost_manager.Get(), + // Cost changed callbacks must run on this sequence to get the new cost + // from `INetworkCostManager`. + base::BindPostTask( + base::SequencedTaskRunnerHandle::Get(), + base::BindRepeating(&NetworkCostChangeNotifierWin::HandleCostChanged, + weak_ptr_factory_.GetWeakPtr())), + &cost_manager_event_sink_); + + if (hr != S_OK) { + return; + } + + // Set the initial cost and inform observers of the initial value. + cost_manager_ = cost_manager; + HandleCostChanged(); +} + +void NetworkCostChangeNotifierWin::StopWatching() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + if (cost_manager_event_sink_) { + cost_manager_event_sink_->UnRegisterForNotifications(); + cost_manager_event_sink_.Reset(); + } + + cost_manager_.Reset(); +} + +void NetworkCostChangeNotifierWin::HandleCostChanged() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + DWORD connection_cost_flags; + HRESULT hr = cost_manager_->GetCost(&connection_cost_flags, + /*destination_ip_address=*/nullptr); + if (hr != S_OK) { + connection_cost_flags = NLM_CONNECTION_COST_UNKNOWN; + } + + NetworkChangeNotifier::ConnectionCost changed_cost = + ConnectionCostFromNlmConnectionCost(connection_cost_flags); + + cost_changed_callback_.Run(changed_cost); +} + +// static +void NetworkCostChangeNotifierWin::OverrideCoCreateInstanceForTesting( + CoCreateInstanceCallback callback_for_testing) { + GetCoCreateInstanceOverride() = callback_for_testing; +} + +} // namespace net diff --git a/chromium/net/base/network_cost_change_notifier_win.h b/chromium/net/base/network_cost_change_notifier_win.h new file mode 100644 index 00000000000..7868cd28b85 --- /dev/null +++ b/chromium/net/base/network_cost_change_notifier_win.h @@ -0,0 +1,83 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_BASE_NETWORK_COST_CHANGE_NOTIFIER_WIN_H_ +#define NET_BASE_NETWORK_COST_CHANGE_NOTIFIER_WIN_H_ + +#include <netlistmgr.h> +#include <wrl/client.h> + +#include "base/callback_forward.h" +#include "base/memory/weak_ptr.h" +#include "base/sequence_checker.h" +#include "base/threading/sequence_bound.h" +#include "net/base/net_export.h" +#include "net/base/network_change_notifier.h" + +namespace net { +class NetworkCostManagerEventSinkWin; + +// Uses the `INetworkCostManager` Windows OS API to monitor the cost of the +// current connection. `INetworkCostManager` performs blocking IO and +// synchronous RPC and must be accessed through a thread pool COM STA single +// threaded task runner. NetworkCostChangeNotifierWin uses +// `base::SequenceBound` to prevent these expensive operations from happening on +// the UI thread. +class NET_EXPORT_PRIVATE NetworkCostChangeNotifierWin final { + public: + using CostChangedCallback = + base::RepeatingCallback<void(NetworkChangeNotifier::ConnectionCost)>; + + // Constructs a new instance using a new COM STA single threaded task runner + // to post the task that creates NetworkCostChangeNotifierWin and subscribes + // to cost change events. + static base::SequenceBound<NetworkCostChangeNotifierWin> CreateInstance( + CostChangedCallback cost_changed_callback); + + // Tests use this hook to provide a fake implementation of the OS APIs. + // The fake implementation enables tests to simulate different cost values, + // cost changed events and OS errors. + using CoCreateInstanceCallback = base::RepeatingCallback< + HRESULT(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID*)>; + static void OverrideCoCreateInstanceForTesting( + CoCreateInstanceCallback callback_for_testing); + + NetworkCostChangeNotifierWin(const NetworkCostChangeNotifierWin&) = delete; + NetworkCostChangeNotifierWin& operator=(const NetworkCostChangeNotifierWin&) = + delete; + + private: + friend class base::SequenceBound<NetworkCostChangeNotifierWin>; + + explicit NetworkCostChangeNotifierWin( + CostChangedCallback cost_changed_callback); + ~NetworkCostChangeNotifierWin(); + + // Creates `INetworkCostManager` and subscribe to cost change events. + void StartWatching(); + + // Stops monitoring the cost of the current connection by unsubscribing to + // `INetworkCostManager` events and releasing all members. + void StopWatching(); + + // Gets the current cost from `cost_manager_` and then runs + // `cost_changed_callback_`. + void HandleCostChanged(); + + // All members must be accessed on the sequence from `sequence_checker_` + SEQUENCE_CHECKER(sequence_checker_); + + CostChangedCallback cost_changed_callback_; + + Microsoft::WRL::ComPtr<INetworkCostManager> cost_manager_; + + Microsoft::WRL::ComPtr<NetworkCostManagerEventSinkWin> + cost_manager_event_sink_; + + base::WeakPtrFactory<NetworkCostChangeNotifierWin> weak_ptr_factory_{this}; +}; + +} // namespace net + +#endif // NET_BASE_NETWORK_COST_CHANGE_NOTIFIER_WIN_H_ diff --git a/chromium/net/base/network_cost_change_notifier_win_unittest.cc b/chromium/net/base/network_cost_change_notifier_win_unittest.cc new file mode 100644 index 00000000000..ae35acc6c88 --- /dev/null +++ b/chromium/net/base/network_cost_change_notifier_win_unittest.cc @@ -0,0 +1,236 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/network_cost_change_notifier_win.h" + +#include "base/run_loop.h" +#include "base/sequence_checker.h" +#include "base/test/scoped_os_info_override_win.h" +#include "base/win/windows_version.h" +#include "net/base/network_change_notifier.h" +#include "net/test/test_connection_cost_observer.h" +#include "net/test/test_with_task_environment.h" +#include "net/test/win/fake_network_cost_manager.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace net { + +class NetworkCostChangeNotifierWinTest : public TestWithTaskEnvironment { + public: + void SetUp() override { + if (base::win::GetVersion() < base::win::Version::WIN10) { + GTEST_SKIP(); + } + } + + protected: + FakeNetworkCostManagerEnvironment fake_network_cost_manager_environment_; +}; + +TEST_F(NetworkCostChangeNotifierWinTest, InitialCostUnknown) { + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN); + + TestConnectionCostObserver cost_change_observer; + auto cost_change_callback = + base::BindRepeating(&TestConnectionCostObserver::OnConnectionCostChanged, + base::Unretained(&cost_change_observer)); + + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier = + NetworkCostChangeNotifierWin::CreateInstance(cost_change_callback); + + // Wait for `NetworkCostChangeNotifierWin` to finish initializing. + cost_change_observer.WaitForConnectionCostChanged(); + + // `NetworkCostChangeNotifierWin` must report an unknown cost after + // initializing. + EXPECT_EQ(cost_change_observer.cost_changed_calls(), 1u); + EXPECT_EQ(cost_change_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN); +} + +TEST_F(NetworkCostChangeNotifierWinTest, InitialCostKnown) { + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + TestConnectionCostObserver cost_change_observer; + auto cost_change_callback = + base::BindRepeating(&TestConnectionCostObserver::OnConnectionCostChanged, + base::Unretained(&cost_change_observer)); + + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier = + NetworkCostChangeNotifierWin::CreateInstance(cost_change_callback); + + // Initializing changes the cost from unknown to unmetered. + cost_change_observer.WaitForConnectionCostChanged(); + + ASSERT_EQ(cost_change_observer.cost_changed_calls(), 1u); + EXPECT_EQ(cost_change_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); +} + +TEST_F(NetworkCostChangeNotifierWinTest, MultipleCostChangedEvents) { + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + TestConnectionCostObserver cost_change_observer; + auto cost_change_callback = + base::BindRepeating(&TestConnectionCostObserver::OnConnectionCostChanged, + base::Unretained(&cost_change_observer)); + + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier = + NetworkCostChangeNotifierWin::CreateInstance(cost_change_callback); + + // Initializing changes the cost from unknown to unmetered. + cost_change_observer.WaitForConnectionCostChanged(); + + ASSERT_EQ(cost_change_observer.cost_changed_calls(), 1u); + EXPECT_EQ(cost_change_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_METERED); + + // The simulated event changes the cost from unmetered to metered. + cost_change_observer.WaitForConnectionCostChanged(); + + ASSERT_EQ(cost_change_observer.cost_changed_calls(), 2u); + EXPECT_EQ(cost_change_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_METERED); + + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN); + + // The simulated event changes the cost from metered to unknown. + cost_change_observer.WaitForConnectionCostChanged(); + + ASSERT_EQ(cost_change_observer.cost_changed_calls(), 3u); + EXPECT_EQ(cost_change_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN); +} + +TEST_F(NetworkCostChangeNotifierWinTest, DuplicateEvents) { + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + TestConnectionCostObserver cost_change_observer; + auto cost_change_callback = + base::BindRepeating(&TestConnectionCostObserver::OnConnectionCostChanged, + base::Unretained(&cost_change_observer)); + + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier = + NetworkCostChangeNotifierWin::CreateInstance(cost_change_callback); + + // Initializing changes the cost from unknown to unmetered. + cost_change_observer.WaitForConnectionCostChanged(); + ASSERT_EQ(cost_change_observer.cost_changed_calls(), 1u); + + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + cost_change_observer.WaitForConnectionCostChanged(); + + // Changing from unmetered to unmetered must dispatch a cost changed event. + ASSERT_EQ(cost_change_observer.cost_changed_calls(), 2u); + EXPECT_EQ(cost_change_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); +} + +TEST_F(NetworkCostChangeNotifierWinTest, ShutdownImmediately) { + TestConnectionCostObserver cost_change_observer; + auto cost_change_callback = + base::BindRepeating(&TestConnectionCostObserver::OnConnectionCostChanged, + base::Unretained(&cost_change_observer)); + + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier = + NetworkCostChangeNotifierWin::CreateInstance(cost_change_callback); + + // Shutting down immediately must not crash. + cost_change_notifier.Reset(); + + // Wait for `NetworkCostChangeNotifierWin` to finish initializing and shutting + // down. + RunUntilIdle(); + + // `NetworkCostChangeNotifierWin` reports a connection change after + // initializing. + EXPECT_EQ(cost_change_observer.cost_changed_calls(), 1u); + + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_METERED); + + // Wait for `NetworkCostChangeNotifierWin` to handle the cost changed event. + RunUntilIdle(); + + // After shutdown, cost changed events must have no effect. + EXPECT_EQ(cost_change_observer.cost_changed_calls(), 1u); +} + +TEST_F(NetworkCostChangeNotifierWinTest, ErrorHandling) { + // Simulate the failure of each OS API while initializing + // `NetworkCostChangeNotifierWin`. + constexpr const NetworkCostManagerStatus kErrorList[] = { + NetworkCostManagerStatus::kErrorCoCreateInstanceFailed, + NetworkCostManagerStatus::kErrorQueryInterfaceFailed, + NetworkCostManagerStatus::kErrorFindConnectionPointFailed, + NetworkCostManagerStatus::kErrorAdviseFailed, + NetworkCostManagerStatus::kErrorGetCostFailed, + }; + for (auto error : kErrorList) { + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + fake_network_cost_manager_environment_.SimulateError(error); + + TestConnectionCostObserver cost_change_observer; + auto cost_change_callback = base::BindRepeating( + &TestConnectionCostObserver::OnConnectionCostChanged, + base::Unretained(&cost_change_observer)); + + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier = + NetworkCostChangeNotifierWin::CreateInstance(cost_change_callback); + + if (error == NetworkCostManagerStatus::kErrorGetCostFailed) { + // `NetworkCostChangeNotifierWin` must report an unknown cost after + // `INetworkCostManager::GetCost()` fails. + cost_change_observer.WaitForConnectionCostChanged(); + + EXPECT_EQ(cost_change_observer.cost_changed_calls(), 1u); + EXPECT_EQ(cost_change_observer.last_cost_changed_input(), + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNKNOWN); + } else { + // Wait for `NetworkCostChangeNotifierWin` to finish initializing. + RunUntilIdle(); + + // `NetworkCostChangeNotifierWin` must NOT report a changed cost after + // failing to initialize. + EXPECT_EQ(cost_change_observer.cost_changed_calls(), 0u); + } + } +} + +TEST_F(NetworkCostChangeNotifierWinTest, UnsupportedOS) { + base::test::ScopedOSInfoOverride os_override( + base::test::ScopedOSInfoOverride::Type::kWin81Pro); + + fake_network_cost_manager_environment_.SetCost( + NetworkChangeNotifier::ConnectionCost::CONNECTION_COST_UNMETERED); + + TestConnectionCostObserver cost_change_observer; + auto cost_change_callback = + base::BindRepeating(&TestConnectionCostObserver::OnConnectionCostChanged, + base::Unretained(&cost_change_observer)); + + base::SequenceBound<NetworkCostChangeNotifierWin> cost_change_notifier = + NetworkCostChangeNotifierWin::CreateInstance(cost_change_callback); + + // Wait for `NetworkCostChangeNotifierWin` to finish initializing. + RunUntilIdle(); + + // `NetworkCostChangeNotifierWin` must NOT report a changed cost for + // unsupported OSes. + EXPECT_EQ(cost_change_observer.cost_changed_calls(), 0u); +} + +} // namespace net diff --git a/chromium/net/base/network_delegate.cc b/chromium/net/base/network_delegate.cc index 6a5a4e253dc..e119ca3d789 100644 --- a/chromium/net/base/network_delegate.cc +++ b/chromium/net/base/network_delegate.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -103,11 +103,13 @@ void NetworkDelegate::NotifyPACScriptError(int line_number, bool NetworkDelegate::AnnotateAndMoveUserBlockedCookies( const URLRequest& request, + const net::FirstPartySetMetadata& first_party_set_metadata, net::CookieAccessResultList& maybe_included_cookies, net::CookieAccessResultList& excluded_cookies) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); bool allowed = OnAnnotateAndMoveUserBlockedCookies( - request, maybe_included_cookies, excluded_cookies); + request, first_party_set_metadata, maybe_included_cookies, + excluded_cookies); cookie_util::DCheckIncludedAndExcludedCookieLists(maybe_included_cookies, excluded_cookies); return allowed; @@ -165,6 +167,16 @@ bool NetworkDelegate::CanUseReportingClient(const url::Origin& origin, return OnCanUseReportingClient(origin, endpoint); } +absl::optional<FirstPartySetsCacheFilter::MatchInfo> +NetworkDelegate::GetFirstPartySetsCacheFilterMatchInfoMaybeAsync( + const SchemefulSite& request_site, + base::OnceCallback<void(FirstPartySetsCacheFilter::MatchInfo)> callback) + const { + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + return OnGetFirstPartySetsCacheFilterMatchInfoMaybeAsync(request_site, + std::move(callback)); +} + // static void NetworkDelegate::ExcludeAllCookies( net::CookieInclusionStatus::ExclusionReason reason, diff --git a/chromium/net/base/network_delegate.h b/chromium/net/base/network_delegate.h index 3297b067cfd..1012d26bbaa 100644 --- a/chromium/net/base/network_delegate.h +++ b/chromium/net/base/network_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,8 +18,10 @@ #include "net/base/net_export.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/cookie_inclusion_status.h" -#include "net/cookies/same_party_context.h" #include "net/cookies/site_for_cookies.h" +#include "net/first_party_sets/first_party_set_metadata.h" +#include "net/first_party_sets/first_party_sets_cache_filter.h" +#include "net/first_party_sets/same_party_context.h" #include "net/proxy_resolution/proxy_retry_info.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -45,6 +47,7 @@ class CookieOptions; class HttpRequestHeaders; class HttpResponseHeaders; class IPEndPoint; +class SchemefulSite; class URLRequest; class NET_EXPORT NetworkDelegate { @@ -78,6 +81,7 @@ class NET_EXPORT NetworkDelegate { void NotifyPACScriptError(int line_number, const std::u16string& error); bool AnnotateAndMoveUserBlockedCookies( const URLRequest& request, + const net::FirstPartySetMetadata& first_party_set_metadata, CookieAccessResultList& maybe_included_cookies, CookieAccessResultList& excluded_cookies); bool CanSetCookie(const URLRequest& request, @@ -119,6 +123,20 @@ class NET_EXPORT NetworkDelegate { bool CanUseReportingClient(const url::Origin& origin, const GURL& endpoint) const; + // Gets the First-Party Sets cache filter info, which is used to mark the + // cache and determine if the previously stored cache of `request_site` can be + // accessed. + // + // The result may be returned synchronously, or `callback` may be invoked + // asynchronously with the result. The callback will be invoked iff the return + // value is nullopt; i.e. a result will be provided via return value or + // callback, but not both, and not neither. + absl::optional<FirstPartySetsCacheFilter::MatchInfo> + GetFirstPartySetsCacheFilterMatchInfoMaybeAsync( + const SchemefulSite& request_site, + base::OnceCallback<void(FirstPartySetsCacheFilter::MatchInfo)> callback) + const; + protected: // Adds the given ExclusionReason to all cookies in // `mayble_included_cookies`, and moves the contents of @@ -246,6 +264,7 @@ class NET_EXPORT NetworkDelegate { // otherwise. virtual bool OnAnnotateAndMoveUserBlockedCookies( const URLRequest& request, + const net::FirstPartySetMetadata& first_party_set_metadata, net::CookieAccessResultList& maybe_included_cookies, net::CookieAccessResultList& excluded_cookies) = 0; @@ -284,6 +303,12 @@ class NET_EXPORT NetworkDelegate { virtual bool OnCanUseReportingClient(const url::Origin& origin, const GURL& endpoint) const = 0; + + virtual absl::optional<FirstPartySetsCacheFilter::MatchInfo> + OnGetFirstPartySetsCacheFilterMatchInfoMaybeAsync( + const SchemefulSite& request_site, + base::OnceCallback<void(FirstPartySetsCacheFilter::MatchInfo)> callback) + const = 0; }; } // namespace net diff --git a/chromium/net/base/network_delegate_impl.cc b/chromium/net/base/network_delegate_impl.cc index e460c9d7fa7..56546418738 100644 --- a/chromium/net/base/network_delegate_impl.cc +++ b/chromium/net/base/network_delegate_impl.cc @@ -1,11 +1,11 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/network_delegate_impl.h" #include "net/base/net_errors.h" -#include "net/cookies/same_party_context.h" +#include "net/first_party_sets/same_party_context.h" namespace net { @@ -50,6 +50,7 @@ void NetworkDelegateImpl::OnPACScriptError(int line_number, bool NetworkDelegateImpl::OnAnnotateAndMoveUserBlockedCookies( const URLRequest& request, + const net::FirstPartySetMetadata& first_party_set_metadata, net::CookieAccessResultList& maybe_included_cookies, net::CookieAccessResultList& excluded_cookies) { return true; @@ -97,4 +98,12 @@ bool NetworkDelegateImpl::OnCanUseReportingClient(const url::Origin& origin, return true; } +absl::optional<FirstPartySetsCacheFilter::MatchInfo> +NetworkDelegateImpl::OnGetFirstPartySetsCacheFilterMatchInfoMaybeAsync( + const SchemefulSite& request_site, + base::OnceCallback<void(FirstPartySetsCacheFilter::MatchInfo)> callback) + const { + return {FirstPartySetsCacheFilter::MatchInfo()}; +} + } // namespace net diff --git a/chromium/net/base/network_delegate_impl.h b/chromium/net/base/network_delegate_impl.h index 7a796545e16..071dec14652 100644 --- a/chromium/net/base/network_delegate_impl.h +++ b/chromium/net/base/network_delegate_impl.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,7 +14,9 @@ #include "net/base/net_export.h" #include "net/base/network_delegate.h" #include "net/cookies/canonical_cookie.h" -#include "net/cookies/same_party_context.h" +#include "net/first_party_sets/first_party_set_metadata.h" +#include "net/first_party_sets/first_party_sets_cache_filter.h" +#include "net/first_party_sets/same_party_context.h" #include "net/proxy_resolution/proxy_retry_info.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -26,6 +28,7 @@ class Origin; namespace net { +class SchemefulSite; class CookieOptions; class HttpRequestHeaders; class HttpResponseHeaders; @@ -68,6 +71,7 @@ class NET_EXPORT NetworkDelegateImpl : public NetworkDelegate { bool OnAnnotateAndMoveUserBlockedCookies( const URLRequest& request, + const net::FirstPartySetMetadata& first_party_set_metadata, net::CookieAccessResultList& maybe_included_cookies, net::CookieAccessResultList& excluded_cookies) override; @@ -97,6 +101,12 @@ class NET_EXPORT NetworkDelegateImpl : public NetworkDelegate { bool OnCanUseReportingClient(const url::Origin& origin, const GURL& endpoint) const override; + + absl::optional<FirstPartySetsCacheFilter::MatchInfo> + OnGetFirstPartySetsCacheFilterMatchInfoMaybeAsync( + const SchemefulSite& request_site, + base::OnceCallback<void(FirstPartySetsCacheFilter::MatchInfo)> callback) + const override; }; } // namespace net diff --git a/chromium/net/base/network_delegate_unittest.cc b/chromium/net/base/network_delegate_unittest.cc index 733cff80b8b..869b23c0b88 100644 --- a/chromium/net/base/network_delegate_unittest.cc +++ b/chromium/net/base/network_delegate_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_handle.h b/chromium/net/base/network_handle.h index 40a6364eb59..0ce8cba019f 100644 --- a/chromium/net/base/network_handle.h +++ b/chromium/net/base/network_handle.h @@ -1,4 +1,4 @@ -// Copyright (c) 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces.cc b/chromium/net/base/network_interfaces.cc index de9b0e5d2a3..a89c65d2217 100644 --- a/chromium/net/base/network_interfaces.cc +++ b/chromium/net/base/network_interfaces.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,14 +28,16 @@ NetworkInterface::NetworkInterface(const std::string& name, NetworkChangeNotifier::ConnectionType type, const IPAddress& address, uint32_t prefix_length, - int ip_address_attributes) + int ip_address_attributes, + absl::optional<Eui48MacAddress> mac_address) : name(name), friendly_name(friendly_name), interface_index(interface_index), type(type), address(address), prefix_length(prefix_length), - ip_address_attributes(ip_address_attributes) {} + ip_address_attributes(ip_address_attributes), + mac_address(mac_address) {} NetworkInterface::NetworkInterface(const NetworkInterface& other) = default; diff --git a/chromium/net/base/network_interfaces.h b/chromium/net/base/network_interfaces.h index 94a9fe923ad..75e25c323a8 100644 --- a/chromium/net/base/network_interfaces.h +++ b/chromium/net/base/network_interfaces.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include <stdint.h> +#include <array> #include <memory> #include <string> #include <vector> @@ -15,6 +16,8 @@ #include "net/base/net_export.h" #include "net/base/network_change_notifier.h" +#include "third_party/abseil-cpp/absl/types/optional.h" + namespace net { // A subset of IP address attributes which are actionable by the @@ -47,6 +50,8 @@ enum IPAddressAttributes { IP_ADDRESS_ATTRIBUTE_DETACHED = 1 << 5, }; +using Eui48MacAddress = std::array<uint8_t, 6>; + // struct that is used by GetNetworkList() to represent a network // interface. struct NET_EXPORT NetworkInterface { @@ -57,7 +62,8 @@ struct NET_EXPORT NetworkInterface { NetworkChangeNotifier::ConnectionType type, const IPAddress& address, uint32_t prefix_length, - int ip_address_attributes); + int ip_address_attributes, + absl::optional<Eui48MacAddress> mac_address = absl::nullopt); NetworkInterface(const NetworkInterface& other); ~NetworkInterface(); @@ -68,6 +74,7 @@ struct NET_EXPORT NetworkInterface { IPAddress address; uint32_t prefix_length; int ip_address_attributes; // Combination of |IPAddressAttributes|. + absl::optional<Eui48MacAddress> mac_address; }; typedef std::vector<NetworkInterface> NetworkInterfaceList; diff --git a/chromium/net/base/network_interfaces_fuchsia.cc b/chromium/net/base/network_interfaces_fuchsia.cc index 48db0c3566b..84ed06e797b 100644 --- a/chromium/net/base/network_interfaces_fuchsia.cc +++ b/chromium/net/base/network_interfaces_fuchsia.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_fuchsia.h b/chromium/net/base/network_interfaces_fuchsia.h index 3a0d7e234fc..6ecc25d2f11 100644 --- a/chromium/net/base/network_interfaces_fuchsia.h +++ b/chromium/net/base/network_interfaces_fuchsia.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_getifaddrs.cc b/chromium/net/base/network_interfaces_getifaddrs.cc index e4260e4cd57..aad8986da2e 100644 --- a/chromium/net/base/network_interfaces_getifaddrs.cc +++ b/chromium/net/base/network_interfaces_getifaddrs.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_getifaddrs.h b/chromium/net/base/network_interfaces_getifaddrs.h index 668dc2503da..0b5cfeca157 100644 --- a/chromium/net/base/network_interfaces_getifaddrs.h +++ b/chromium/net/base/network_interfaces_getifaddrs.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_getifaddrs_android.cc b/chromium/net/base/network_interfaces_getifaddrs_android.cc index 983865c003a..b097742bf6e 100644 --- a/chromium/net/base/network_interfaces_getifaddrs_android.cc +++ b/chromium/net/base/network_interfaces_getifaddrs_android.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_getifaddrs_android.h b/chromium/net/base/network_interfaces_getifaddrs_android.h index 022f2aae1e7..c29873d7c22 100644 --- a/chromium/net/base/network_interfaces_getifaddrs_android.h +++ b/chromium/net/base/network_interfaces_getifaddrs_android.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_getifaddrs_unittest.cc b/chromium/net/base/network_interfaces_getifaddrs_unittest.cc index fd31375a767..c50d1113b8c 100644 --- a/chromium/net/base/network_interfaces_getifaddrs_unittest.cc +++ b/chromium/net/base/network_interfaces_getifaddrs_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_linux.cc b/chromium/net/base/network_interfaces_linux.cc index aa28e7a6bb2..ff43b4e0656 100644 --- a/chromium/net/base/network_interfaces_linux.cc +++ b/chromium/net/base/network_interfaces_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_linux.h b/chromium/net/base/network_interfaces_linux.h index abb9d383fb3..4b9ba9e0681 100644 --- a/chromium/net/base/network_interfaces_linux.h +++ b/chromium/net/base/network_interfaces_linux.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_linux_unittest.cc b/chromium/net/base/network_interfaces_linux_unittest.cc index 7f4d7391156..0f7cc94f2f5 100644 --- a/chromium/net/base/network_interfaces_linux_unittest.cc +++ b/chromium/net/base/network_interfaces_linux_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_posix.cc b/chromium/net/base/network_interfaces_posix.cc index 9f7681d8acd..ef4b5bf6934 100644 --- a/chromium/net/base/network_interfaces_posix.cc +++ b/chromium/net/base/network_interfaces_posix.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_posix.h b/chromium/net/base/network_interfaces_posix.h index a3074f7ee8b..e92cbfe05b9 100644 --- a/chromium/net/base/network_interfaces_posix.h +++ b/chromium/net/base/network_interfaces_posix.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_unittest.cc b/chromium/net/base/network_interfaces_unittest.cc index d3fa86aebfc..40cad1d47e1 100644 --- a/chromium/net/base/network_interfaces_unittest.cc +++ b/chromium/net/base/network_interfaces_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_win.cc b/chromium/net/base/network_interfaces_win.cc index 68f4458599d..6f6f32a54bb 100644 --- a/chromium/net/base/network_interfaces_win.cc +++ b/chromium/net/base/network_interfaces_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -152,6 +152,15 @@ bool GetNetworkListImpl(NetworkInterfaceList* networks, continue; } + absl::optional<Eui48MacAddress> mac_address; + mac_address.emplace(); + if (adapter->PhysicalAddressLength == mac_address->size()) { + std::copy_n(reinterpret_cast<const uint8_t*>(adapter->PhysicalAddress), + mac_address->size(), mac_address->begin()); + } else { + mac_address.reset(); + } + for (IP_ADAPTER_UNICAST_ADDRESS* address = adapter->FirstUnicastAddress; address; address = address->Next) { int family = address->Address.lpSockaddr->sa_family; @@ -188,7 +197,7 @@ bool GetNetworkListImpl(NetworkInterfaceList* networks, adapter->AdapterName, base::SysWideToNativeMB(adapter->FriendlyName), index, GetNetworkInterfaceType(adapter->IfType), endpoint.address(), - prefix_length, ip_address_attributes)); + prefix_length, ip_address_attributes, mac_address)); } } } diff --git a/chromium/net/base/network_interfaces_win.h b/chromium/net/base/network_interfaces_win.h index c2619d74455..d77d6760234 100644 --- a/chromium/net/base/network_interfaces_win.h +++ b/chromium/net/base/network_interfaces_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_interfaces_win_unittest.cc b/chromium/net/base/network_interfaces_win_unittest.cc index 32763aa95d2..75a73ea4f5c 100644 --- a/chromium/net/base/network_interfaces_win_unittest.cc +++ b/chromium/net/base/network_interfaces_win_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -53,6 +53,14 @@ bool FillAdapterAddress(IP_ADAPTER_ADDRESSES* adapter_address, adapter_address->FirstUnicastAddress->PreferredLifetime = 100; adapter_address->FirstUnicastAddress->ValidLifetime = 1000; + DCHECK(sizeof(adapter_address->PhysicalAddress) > 5); + // Generate 06:05:04:03:02:01 + adapter_address->PhysicalAddressLength = 6; + for (unsigned long i = 0; i < adapter_address->PhysicalAddressLength; i++) { + adapter_address->PhysicalAddress[i] = + adapter_address->PhysicalAddressLength - i; + } + socklen_t sock_len = sizeof(sockaddr_storage); // Convert to sockaddr for next check. @@ -188,6 +196,54 @@ TEST(NetworkInterfacesTest, NetworkListTrimmingWindows) { results.clear(); } +TEST(NetworkInterfacesTest, NetworkListExtractMacAddress) { + IPAddress ipv6_local_address(kIPv6LocalAddr); + IPAddress ipv6_address(kIPv6Addr); + IPAddress ipv6_prefix(kIPv6AddrPrefix); + + NetworkInterfaceList results; + sockaddr_storage addresses[2]; + IP_ADAPTER_ADDRESSES adapter_address = {}; + IP_ADAPTER_UNICAST_ADDRESS address = {}; + IP_ADAPTER_PREFIX adapter_prefix = {}; + adapter_address.FirstUnicastAddress = &address; + adapter_address.FirstPrefix = &adapter_prefix; + + ASSERT_TRUE(FillAdapterAddress(&adapter_address, kIfnameEm1, ipv6_address, + ipv6_prefix, addresses)); + + Eui48MacAddress expected_mac_address = {0x6, 0x5, 0x4, 0x3, 0x2, 0x1}; + + EXPECT_TRUE(internal::GetNetworkListImpl( + &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, &adapter_address)); + ASSERT_EQ(results.size(), 1ul); + ASSERT_EQ(results[0].mac_address, expected_mac_address); +} + +TEST(NetworkInterfacesTest, NetworkListExtractMacAddressInvalidLength) { + IPAddress ipv6_local_address(kIPv6LocalAddr); + IPAddress ipv6_address(kIPv6Addr); + IPAddress ipv6_prefix(kIPv6AddrPrefix); + + NetworkInterfaceList results; + sockaddr_storage addresses[2]; + IP_ADAPTER_ADDRESSES adapter_address = {}; + IP_ADAPTER_UNICAST_ADDRESS address = {}; + IP_ADAPTER_PREFIX adapter_prefix = {}; + adapter_address.FirstUnicastAddress = &address; + adapter_address.FirstPrefix = &adapter_prefix; + + ASSERT_TRUE(FillAdapterAddress(&adapter_address, kIfnameEm1, ipv6_address, + ipv6_prefix, addresses)); + // Not EUI-48 Mac address, so it is not extracted. + adapter_address.PhysicalAddressLength = 8; + + EXPECT_TRUE(internal::GetNetworkListImpl( + &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, &adapter_address)); + ASSERT_EQ(results.size(), 1ul); + EXPECT_FALSE(results[0].mac_address.has_value()); +} + bool read_int_or_bool(DWORD data_size, PVOID data) { switch (data_size) { case 1: diff --git a/chromium/net/base/network_isolation_key.cc b/chromium/net/base/network_isolation_key.cc index 9c68715db79..0000f73725d 100644 --- a/chromium/net/base/network_isolation_key.cc +++ b/chromium/net/base/network_isolation_key.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -205,8 +205,8 @@ bool NetworkIsolationKey::FromValue( } const absl::optional<SchemefulSite>& NetworkIsolationKey::GetFrameSite() const { - // TODO: @brgoldstein, add CHECK that - // `kForceIsolationInfoFrameOriginToTopLevelFrame` is not enabled. + // Frame site will be empty if double-keying is enabled. + CHECK(NetworkIsolationKey::IsFrameSiteEnabled()); return frame_site_; } diff --git a/chromium/net/base/network_isolation_key.h b/chromium/net/base/network_isolation_key.h index be4f992f2f7..049f4a3cf54 100644 --- a/chromium/net/base/network_isolation_key.h +++ b/chromium/net/base/network_isolation_key.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -118,8 +118,16 @@ class NET_EXPORT NetworkIsolationKey { const absl::optional<SchemefulSite>& GetTopFrameSite() const { return top_frame_site_; } + const absl::optional<SchemefulSite>& GetFrameSite() const; + // Do not use outside of testing. Returns the `frame_site_` if + // `kForceIsolationInfoFrameOriginToTopLevelFrame` is disabled. Else it + // returns nullopt. + const absl::optional<SchemefulSite>& GetFrameSiteForTesting() const { + return frame_site_; + } + // Getter for the nonce. const absl::optional<base::UnguessableToken>& GetNonce() const { return nonce_; diff --git a/chromium/net/base/network_isolation_key_unittest.cc b/chromium/net/base/network_isolation_key_unittest.cc index 9fbd0a39510..919720fca8a 100644 --- a/chromium/net/base/network_isolation_key_unittest.cc +++ b/chromium/net/base/network_isolation_key_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -419,7 +419,7 @@ TEST_P(NetworkIsolationKeyTest, CreateWithNewFrameSite) { net::NetworkIsolationKey key(site_a, site_b); NetworkIsolationKey key_c = key.CreateWithNewFrameSite(site_c); if (ForceIsolationInfoFrameOriginToTopLevelFrameEnabled()) { - EXPECT_EQ(absl::nullopt, key_c.GetFrameSite()); + EXPECT_DEATH_IF_SUPPORTED(key_c.GetFrameSite(), ""); } else { EXPECT_EQ(site_c, key_c.GetFrameSite()); } @@ -479,12 +479,7 @@ TEST(NetworkIsolationKeyFeatureShiftTest, ValueRoundTripDoubleToTriple) { NetworkIsolationKey created_double_key( SchemefulSite(GURL("https://foo.test/")), SchemefulSite(GURL("https://bar.test/"))); - EXPECT_EQ(absl::nullopt, created_double_key.GetFrameSite()); - - // Assert the triple key still has the frame_site it was created with when - // frame site was enabled. - EXPECT_EQ(SchemefulSite(GURL("https://bar.test/")), - created_triple_key.GetFrameSite()); + EXPECT_DEATH_IF_SUPPORTED(created_double_key.GetFrameSite(), ""); // Test round trip of key created when frame site was disabled. base::Value created_double_key_value; diff --git a/chromium/net/base/network_notification_thread_mac.cc b/chromium/net/base/network_notification_thread_mac.cc index 105c3bb3269..3fccae82c17 100644 --- a/chromium/net/base/network_notification_thread_mac.cc +++ b/chromium/net/base/network_notification_thread_mac.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/network_notification_thread_mac.h b/chromium/net/base/network_notification_thread_mac.h index 6f97243a792..ccd963ad75d 100644 --- a/chromium/net/base/network_notification_thread_mac.h +++ b/chromium/net/base/network_notification_thread_mac.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/parse_number.cc b/chromium/net/base/parse_number.cc index 5c2af5137db..4859bffe972 100644 --- a/chromium/net/base/parse_number.cc +++ b/chromium/net/base/parse_number.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/parse_number.h b/chromium/net/base/parse_number.h index 4e49ab71121..d6adf388e6f 100644 --- a/chromium/net/base/parse_number.h +++ b/chromium/net/base/parse_number.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/parse_number_unittest.cc b/chromium/net/base/parse_number_unittest.cc index 47cce60e29e..ccde98f8f7d 100644 --- a/chromium/net/base/parse_number_unittest.cc +++ b/chromium/net/base/parse_number_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/parse_url_hostname_to_address_fuzzer.cc b/chromium/net/base/parse_url_hostname_to_address_fuzzer.cc index 2ca87e9e17c..a96ab059760 100644 --- a/chromium/net/base/parse_url_hostname_to_address_fuzzer.cc +++ b/chromium/net/base/parse_url_hostname_to_address_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/platform_mime_util.h b/chromium/net/base/platform_mime_util.h index bc2bf5509c6..6277aca961f 100644 --- a/chromium/net/base/platform_mime_util.h +++ b/chromium/net/base/platform_mime_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/platform_mime_util_fuchsia.cc b/chromium/net/base/platform_mime_util_fuchsia.cc index 3ed266f7e05..4605dd3533e 100644 --- a/chromium/net/base/platform_mime_util_fuchsia.cc +++ b/chromium/net/base/platform_mime_util_fuchsia.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/platform_mime_util_linux.cc b/chromium/net/base/platform_mime_util_linux.cc index 6c079a420f9..faf1ab72106 100644 --- a/chromium/net/base/platform_mime_util_linux.cc +++ b/chromium/net/base/platform_mime_util_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,8 @@ #if BUILDFLAG(IS_ANDROID) #include "net/android/network_library.h" +#elif BUILDFLAG(IS_CHROMEOS) +#include "third_party/xdg_shared_mime_info/mime_cache.h" #else #include "base/nix/mime_util_xdg.h" #endif @@ -23,11 +25,11 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( std::string* result) const { return android::GetMimeTypeFromExtension(ext, result); } -#elif BUILDFLAG(IS_CHROMEOS_ASH) +#elif BUILDFLAG(IS_CHROMEOS) bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( const base::FilePath::StringType& ext, std::string* result) const { - return false; + return xdg_shared_mime_info::GetMimeCacheTypeFromExtension(ext, result); } #else bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( diff --git a/chromium/net/base/platform_mime_util_mac.mm b/chromium/net/base/platform_mime_util_mac.mm index 1b630903ce3..a45e5d639c8 100644 --- a/chromium/net/base/platform_mime_util_mac.mm +++ b/chromium/net/base/platform_mime_util_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/platform_mime_util_win.cc b/chromium/net/base/platform_mime_util_win.cc index 33d00d81264..c92468db628 100644 --- a/chromium/net/base/platform_mime_util_win.cc +++ b/chromium/net/base/platform_mime_util_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/port_util.cc b/chromium/net/base/port_util.cc index 84babee6f6a..a2344f66ca0 100644 --- a/chromium/net/base/port_util.cc +++ b/chromium/net/base/port_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/port_util.h b/chromium/net/base/port_util.h index 4f6537091df..e2718097ae4 100644 --- a/chromium/net/base/port_util.h +++ b/chromium/net/base/port_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/port_util_unittest.cc b/chromium/net/base/port_util_unittest.cc index 0fa1872853b..eb80ef7fde0 100644 --- a/chromium/net/base/port_util_unittest.cc +++ b/chromium/net/base/port_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/prioritized_dispatcher.cc b/chromium/net/base/prioritized_dispatcher.cc index 38ca35f98d5..67fadc6277c 100644 --- a/chromium/net/base/prioritized_dispatcher.cc +++ b/chromium/net/base/prioritized_dispatcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/prioritized_dispatcher.h b/chromium/net/base/prioritized_dispatcher.h index 283c8bc72e3..c14f5da24bd 100644 --- a/chromium/net/base/prioritized_dispatcher.h +++ b/chromium/net/base/prioritized_dispatcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/prioritized_dispatcher_unittest.cc b/chromium/net/base/prioritized_dispatcher_unittest.cc index 419be5da7f8..404914f16cd 100644 --- a/chromium/net/base/prioritized_dispatcher_unittest.cc +++ b/chromium/net/base/prioritized_dispatcher_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/prioritized_task_runner.cc b/chromium/net/base/prioritized_task_runner.cc index 5c1e8aff4a5..4ab92139f94 100644 --- a/chromium/net/base/prioritized_task_runner.cc +++ b/chromium/net/base/prioritized_task_runner.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,6 @@ #include "base/bind.h" #include "base/task/task_runner.h" -#include "base/task/task_runner_util.h" #include "base/task/thread_pool.h" namespace net { diff --git a/chromium/net/base/prioritized_task_runner.h b/chromium/net/base/prioritized_task_runner.h index 086f8c70d92..31a845e5cfd 100644 --- a/chromium/net/base/prioritized_task_runner.h +++ b/chromium/net/base/prioritized_task_runner.h @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/prioritized_task_runner_unittest.cc b/chromium/net/base/prioritized_task_runner_unittest.cc index 6f77f11cb6d..c33c3321a62 100644 --- a/chromium/net/base/prioritized_task_runner_unittest.cc +++ b/chromium/net/base/prioritized_task_runner_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/priority_queue.h b/chromium/net/base/priority_queue.h index 73cb6d72655..66e1a00d67c 100644 --- a/chromium/net/base/priority_queue.h +++ b/chromium/net/base/priority_queue.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/priority_queue_unittest.cc b/chromium/net/base/priority_queue_unittest.cc index 88974bcefe2..738fe844fb2 100644 --- a/chromium/net/base/priority_queue_unittest.cc +++ b/chromium/net/base/priority_queue_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/privacy_mode.cc b/chromium/net/base/privacy_mode.cc index 9578848e547..1bb15b0ba7c 100644 --- a/chromium/net/base/privacy_mode.cc +++ b/chromium/net/base/privacy_mode.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/privacy_mode.h b/chromium/net/base/privacy_mode.h index 0b7c5d3778f..171fb190a90 100644 --- a/chromium/net/base/privacy_mode.h +++ b/chromium/net/base/privacy_mode.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_delegate.h b/chromium/net/base/proxy_delegate.h index 92e622e7511..6ae0f2ef7c4 100644 --- a/chromium/net/base/proxy_delegate.h +++ b/chromium/net/base/proxy_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_server.cc b/chromium/net/base/proxy_server.cc index 3b09f37a48a..c2a3e48f409 100644 --- a/chromium/net/base/proxy_server.cc +++ b/chromium/net/base/proxy_server.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright 2010 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_server.h b/chromium/net/base/proxy_server.h index 9e4fe232b4d..cf62c2c8a53 100644 --- a/chromium/net/base/proxy_server.h +++ b/chromium/net/base/proxy_server.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_server_unittest.cc b/chromium/net/base/proxy_server_unittest.cc index 441fc0aa75c..8cf21d00c46 100644 --- a/chromium/net/base/proxy_server_unittest.cc +++ b/chromium/net/base/proxy_server_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright 2010 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_string_util.cc b/chromium/net/base/proxy_string_util.cc index 4cda416ab64..81328620503 100644 --- a/chromium/net/base/proxy_string_util.cc +++ b/chromium/net/base/proxy_string_util.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_string_util.h b/chromium/net/base/proxy_string_util.h index e6a7f3c2ca3..8388a2ff8d2 100644 --- a/chromium/net/base/proxy_string_util.h +++ b/chromium/net/base/proxy_string_util.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_string_util_mac.cc b/chromium/net/base/proxy_string_util_mac.cc index d6ce12c2853..c41b52e220c 100644 --- a/chromium/net/base/proxy_string_util_mac.cc +++ b/chromium/net/base/proxy_string_util_mac.cc @@ -1,4 +1,4 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/proxy_string_util_unittest.cc b/chromium/net/base/proxy_string_util_unittest.cc index 67f6333efed..1759e55d6bd 100644 --- a/chromium/net/base/proxy_string_util_unittest.cc +++ b/chromium/net/base/proxy_string_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/rand_callback.h b/chromium/net/base/rand_callback.h index f001c887d1c..e9d60c2f566 100644 --- a/chromium/net/base/rand_callback.h +++ b/chromium/net/base/rand_callback.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/registry_controlled_domains/BUILD.gn b/chromium/net/base/registry_controlled_domains/BUILD.gn index c9eb94fb6ad..a39438129bd 100644 --- a/chromium/net/base/registry_controlled_domains/BUILD.gn +++ b/chromium/net/base/registry_controlled_domains/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2014 The Chromium Authors. All rights reserved. +# Copyright 2014 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/net/base/registry_controlled_domains/OWNERS b/chromium/net/base/registry_controlled_domains/OWNERS index 33ed6c7e349..242a9936d16 100644 --- a/chromium/net/base/registry_controlled_domains/OWNERS +++ b/chromium/net/base/registry_controlled_domains/OWNERS @@ -1,3 +1,2 @@ cfredric@chromium.org -pam@chromium.org pkasting@chromium.org diff --git a/chromium/net/base/registry_controlled_domains/effective_tld_names.gperf b/chromium/net/base/registry_controlled_domains/effective_tld_names.gperf index 490782dff4e..4e222cfdb3b 100644 --- a/chromium/net/base/registry_controlled_domains/effective_tld_names.gperf +++ b/chromium/net/base/registry_controlled_domains/effective_tld_names.gperf @@ -1,5 +1,5 @@ %{ -// Copyright 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest1.gperf b/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest1.gperf index 0246f17bebe..1237e142f66 100644 --- a/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest1.gperf +++ b/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest1.gperf @@ -1,5 +1,5 @@ %{ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Test file used by registry_controlled_domain_unittest. diff --git a/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest2.gperf b/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest2.gperf index 03c2e2a909f..439546a1b89 100644 --- a/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest2.gperf +++ b/chromium/net/base/registry_controlled_domains/effective_tld_names_unittest2.gperf @@ -1,5 +1,5 @@ %{ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Test file used by registry_controlled_domain_unittest. diff --git a/chromium/net/base/registry_controlled_domains/get_domain_and_registry_fuzzer.cc b/chromium/net/base/registry_controlled_domains/get_domain_and_registry_fuzzer.cc index e71c7dc26a7..31caf31dde3 100644 --- a/chromium/net/base/registry_controlled_domains/get_domain_and_registry_fuzzer.cc +++ b/chromium/net/base/registry_controlled_domains/get_domain_and_registry_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc index e330feb408f..be72914e011 100644 --- a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc +++ b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h index ce6a2201ed8..076215b3920 100644 --- a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h +++ b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc b/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc index 9417f839fa4..6d43956e61f 100644 --- a/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc +++ b/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/request_priority.cc b/chromium/net/base/request_priority.cc index 4492758d37f..30d93aebb15 100644 --- a/chromium/net/base/request_priority.cc +++ b/chromium/net/base/request_priority.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/request_priority.h b/chromium/net/base/request_priority.h index cd2fa11cbf8..0c2ef5fb442 100644 --- a/chromium/net/base/request_priority.h +++ b/chromium/net/base/request_priority.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/scheme_host_port_matcher.cc b/chromium/net/base/scheme_host_port_matcher.cc index 2b6a57f0238..ff00fb214ae 100644 --- a/chromium/net/base/scheme_host_port_matcher.cc +++ b/chromium/net/base/scheme_host_port_matcher.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,13 @@ namespace net { +SchemeHostPortMatcher::SchemeHostPortMatcher() = default; +SchemeHostPortMatcher::SchemeHostPortMatcher(SchemeHostPortMatcher&& rhs) = + default; +SchemeHostPortMatcher& SchemeHostPortMatcher::operator=( + SchemeHostPortMatcher&& rhs) = default; +SchemeHostPortMatcher::~SchemeHostPortMatcher() = default; + // Declares SchemeHostPortMatcher::kParseRuleListDelimiterList[], not a // redefinition. This is needed for link. // static diff --git a/chromium/net/base/scheme_host_port_matcher.h b/chromium/net/base/scheme_host_port_matcher.h index 5896ee4af41..8de3dc83ea9 100644 --- a/chromium/net/base/scheme_host_port_matcher.h +++ b/chromium/net/base/scheme_host_port_matcher.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -27,10 +27,10 @@ class NET_EXPORT SchemeHostPortMatcher { using RuleList = std::vector<std::unique_ptr<SchemeHostPortMatcherRule>>; // Note: This class is movable but not copiable. - SchemeHostPortMatcher() = default; - SchemeHostPortMatcher(SchemeHostPortMatcher&& rhs) = default; - SchemeHostPortMatcher& operator=(SchemeHostPortMatcher&& rhs) = default; - ~SchemeHostPortMatcher() = default; + SchemeHostPortMatcher(); + SchemeHostPortMatcher(SchemeHostPortMatcher&& rhs); + SchemeHostPortMatcher& operator=(SchemeHostPortMatcher&& rhs); + ~SchemeHostPortMatcher(); // The delimiter used by |ToString()|. constexpr static char kPrintRuleListDelimiter = ';'; diff --git a/chromium/net/base/scheme_host_port_matcher_result.h b/chromium/net/base/scheme_host_port_matcher_result.h index 6de07ec06cc..3dc5dad4241 100644 --- a/chromium/net/base/scheme_host_port_matcher_result.h +++ b/chromium/net/base/scheme_host_port_matcher_result.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/scheme_host_port_matcher_rule.cc b/chromium/net/base/scheme_host_port_matcher_rule.cc index cb02c0522c2..e3e6ae5c93e 100644 --- a/chromium/net/base/scheme_host_port_matcher_rule.cc +++ b/chromium/net/base/scheme_host_port_matcher_rule.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/scheme_host_port_matcher_rule.h b/chromium/net/base/scheme_host_port_matcher_rule.h index 8c9aedc98b1..19f7588188b 100644 --- a/chromium/net/base/scheme_host_port_matcher_rule.h +++ b/chromium/net/base/scheme_host_port_matcher_rule.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/scheme_host_port_matcher_rule_unittest.cc b/chromium/net/base/scheme_host_port_matcher_rule_unittest.cc index 6623ff9a649..97330d05de3 100644 --- a/chromium/net/base/scheme_host_port_matcher_rule_unittest.cc +++ b/chromium/net/base/scheme_host_port_matcher_rule_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/scheme_host_port_matcher_unittest.cc b/chromium/net/base/scheme_host_port_matcher_unittest.cc index b8e58e14426..8f74b3dddb1 100644 --- a/chromium/net/base/scheme_host_port_matcher_unittest.cc +++ b/chromium/net/base/scheme_host_port_matcher_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/schemeful_site.cc b/chromium/net/base/schemeful_site.cc index 51df09e13fc..5920a306f78 100644 --- a/chromium/net/base/schemeful_site.cc +++ b/chromium/net/base/schemeful_site.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/schemeful_site.h b/chromium/net/base/schemeful_site.h index dbccfc7f1a3..a4449fc20e6 100644 --- a/chromium/net/base/schemeful_site.h +++ b/chromium/net/base/schemeful_site.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -150,11 +150,18 @@ class NET_EXPORT SchemefulSite { // use opaque origins. friend class NetworkIsolationKey; + // Needed to serialize opaque and non-transient NetworkAnonymizationKeys, + // which use opaque origins. + friend class NetworkAnonymizationKey; + // Needed to create a bogus origin from a site. // TODO(https://crbug.com/1148927): Give IsolationInfos empty origins instead, // in this case, and unfriend IsolationInfo. friend class IsolationInfo; + // Needed to create a bogus origin from a site. + friend class URLRequest; + // Needed because cookies do not account for scheme. friend class CookieMonster; diff --git a/chromium/net/base/schemeful_site_fuzzer.cc b/chromium/net/base/schemeful_site_fuzzer.cc index 2e6cd2e6471..15c25bdbbce 100644 --- a/chromium/net/base/schemeful_site_fuzzer.cc +++ b/chromium/net/base/schemeful_site_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/schemeful_site_unittest.cc b/chromium/net/base/schemeful_site_unittest.cc index 53197d1292b..06086d4efb9 100644 --- a/chromium/net/base/schemeful_site_unittest.cc +++ b/chromium/net/base/schemeful_site_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/sockaddr_storage.cc b/chromium/net/base/sockaddr_storage.cc index 2822e07a707..21f6bf157c1 100644 --- a/chromium/net/base/sockaddr_storage.cc +++ b/chromium/net/base/sockaddr_storage.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/sockaddr_storage.h b/chromium/net/base/sockaddr_storage.h index de60176bccb..61459288301 100644 --- a/chromium/net/base/sockaddr_storage.h +++ b/chromium/net/base/sockaddr_storage.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/sockaddr_util_posix.cc b/chromium/net/base/sockaddr_util_posix.cc index c184cbe2a15..583b15a23ac 100644 --- a/chromium/net/base/sockaddr_util_posix.cc +++ b/chromium/net/base/sockaddr_util_posix.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/sockaddr_util_posix.h b/chromium/net/base/sockaddr_util_posix.h index a12c967a8b5..01eb72ec67f 100644 --- a/chromium/net/base/sockaddr_util_posix.h +++ b/chromium/net/base/sockaddr_util_posix.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/sockaddr_util_posix_unittest.cc b/chromium/net/base/sockaddr_util_posix_unittest.cc index f75e1fa35c3..765064044f0 100644 --- a/chromium/net/base/sockaddr_util_posix_unittest.cc +++ b/chromium/net/base/sockaddr_util_posix_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/sys_addrinfo.h b/chromium/net/base/sys_addrinfo.h index d91169668bf..ca6dd1f0313 100644 --- a/chromium/net/base/sys_addrinfo.h +++ b/chromium/net/base/sys_addrinfo.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright 2009 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/test_completion_callback.cc b/chromium/net/base/test_completion_callback.cc index 2727128373e..abdf6f664ef 100644 --- a/chromium/net/base/test_completion_callback.cc +++ b/chromium/net/base/test_completion_callback.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/test_completion_callback.h b/chromium/net/base/test_completion_callback.h index d2453921ddf..3d051c24b53 100644 --- a/chromium/net/base/test_completion_callback.h +++ b/chromium/net/base/test_completion_callback.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/test_completion_callback_unittest.cc b/chromium/net/base/test_completion_callback_unittest.cc index 0ba7462e25d..48ec07842b9 100644 --- a/chromium/net/base/test_completion_callback_unittest.cc +++ b/chromium/net/base/test_completion_callback_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/test_data_stream.cc b/chromium/net/base/test_data_stream.cc index 052d8cc9f6e..0d723827f01 100644 --- a/chromium/net/base/test_data_stream.cc +++ b/chromium/net/base/test_data_stream.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/test_data_stream.h b/chromium/net/base/test_data_stream.h index 7c4c758d261..14a7ad54527 100644 --- a/chromium/net/base/test_data_stream.h +++ b/chromium/net/base/test_data_stream.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/test_proxy_delegate.cc b/chromium/net/base/test_proxy_delegate.cc index b7dfe0436d4..da92cf617d8 100644 --- a/chromium/net/base/test_proxy_delegate.cc +++ b/chromium/net/base/test_proxy_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/test_proxy_delegate.h b/chromium/net/base/test_proxy_delegate.h index aed0c323d67..4a2f33350b4 100644 --- a/chromium/net/base/test_proxy_delegate.h +++ b/chromium/net/base/test_proxy_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/trace_constants.h b/chromium/net/base/trace_constants.h index e57b561bf5e..0b770240cff 100644 --- a/chromium/net/base/trace_constants.h +++ b/chromium/net/base/trace_constants.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/transport_info.cc b/chromium/net/base/transport_info.cc index 6b0debc40d6..c35bb9bfbca 100644 --- a/chromium/net/base/transport_info.cc +++ b/chromium/net/base/transport_info.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/transport_info.h b/chromium/net/base/transport_info.h index adcaf78b4b9..21fd94a7db5 100644 --- a/chromium/net/base/transport_info.h +++ b/chromium/net/base/transport_info.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/unescape_url_component_fuzzer.cc b/chromium/net/base/unescape_url_component_fuzzer.cc index 0bebc228d88..257b66e04a2 100644 --- a/chromium/net/base/unescape_url_component_fuzzer.cc +++ b/chromium/net/base/unescape_url_component_fuzzer.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_bytes_element_reader.cc b/chromium/net/base/upload_bytes_element_reader.cc index 312b0069ad9..19b195e1a7d 100644 --- a/chromium/net/base/upload_bytes_element_reader.cc +++ b/chromium/net/base/upload_bytes_element_reader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_bytes_element_reader.h b/chromium/net/base/upload_bytes_element_reader.h index 71c5a4bde35..bb8459bec32 100644 --- a/chromium/net/base/upload_bytes_element_reader.h +++ b/chromium/net/base/upload_bytes_element_reader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_bytes_element_reader_unittest.cc b/chromium/net/base/upload_bytes_element_reader_unittest.cc index 42710ea89cd..4f5c274d0c2 100644 --- a/chromium/net/base/upload_bytes_element_reader_unittest.cc +++ b/chromium/net/base/upload_bytes_element_reader_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_data_stream.cc b/chromium/net/base/upload_data_stream.cc index 3444b89f92f..2038f39c745 100644 --- a/chromium/net/base/upload_data_stream.cc +++ b/chromium/net/base/upload_data_stream.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_data_stream.h b/chromium/net/base/upload_data_stream.h index 0f9b0c2f7bf..ae538f86201 100644 --- a/chromium/net/base/upload_data_stream.h +++ b/chromium/net/base/upload_data_stream.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_element_reader.cc b/chromium/net/base/upload_element_reader.cc index 2a95eb816ae..bc45006989f 100644 --- a/chromium/net/base/upload_element_reader.cc +++ b/chromium/net/base/upload_element_reader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_element_reader.h b/chromium/net/base/upload_element_reader.h index b774c08cf00..8877532f316 100644 --- a/chromium/net/base/upload_element_reader.h +++ b/chromium/net/base/upload_element_reader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_file_element_reader.cc b/chromium/net/base/upload_file_element_reader.cc index d12c03b2530..8aabd901e79 100644 --- a/chromium/net/base/upload_file_element_reader.cc +++ b/chromium/net/base/upload_file_element_reader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,7 +10,6 @@ #include "base/files/file_util.h" #include "base/location.h" #include "base/task/task_runner.h" -#include "base/task/task_runner_util.h" #include "net/base/file_stream.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" diff --git a/chromium/net/base/upload_file_element_reader.h b/chromium/net/base/upload_file_element_reader.h index 89e108afd34..197ef313204 100644 --- a/chromium/net/base/upload_file_element_reader.h +++ b/chromium/net/base/upload_file_element_reader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_file_element_reader_unittest.cc b/chromium/net/base/upload_file_element_reader_unittest.cc index 45664d4b1f3..df5c3be23b6 100644 --- a/chromium/net/base/upload_file_element_reader_unittest.cc +++ b/chromium/net/base/upload_file_element_reader_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/upload_progress.h b/chromium/net/base/upload_progress.h index 25194aa1504..e5807e6840c 100644 --- a/chromium/net/base/upload_progress.h +++ b/chromium/net/base/upload_progress.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/url_util.cc b/chromium/net/base/url_util.cc index 093d325a388..d2a28b09b3c 100644 --- a/chromium/net/base/url_util.cc +++ b/chromium/net/base/url_util.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,6 +20,7 @@ #include "base/strings/utf_string_conversions.h" #include "net/base/ip_address.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "url/gurl.h" #include "url/scheme_host_port.h" #include "url/url_canon.h" @@ -77,10 +78,14 @@ GURL AppendQueryParameter(const GURL& url, GURL AppendOrReplaceQueryParameter(const GURL& url, const std::string& name, - const std::string& value) { + absl::optional<base::StringPiece> value) { bool replaced = false; std::string param_name = base::EscapeQueryParamValue(name, true); - std::string param_value = base::EscapeQueryParamValue(value, true); + bool should_keep_param = value.has_value(); + + std::string param_value; + if (should_keep_param) + param_value = base::EscapeQueryParamValue(value.value(), true); const std::string input = url.query(); url::Component cursor(0, input.size()); @@ -94,7 +99,11 @@ GURL AppendOrReplaceQueryParameter(const GURL& url, // Check |replaced| as only the first pair should be replaced. if (!replaced && key == param_name) { replaced = true; + if (!should_keep_param) + continue; + key_value_pair = (param_name + "=" + param_value); + } else { key_value_pair.assign(input, key_range.begin, value_range.end() - key_range.begin); @@ -104,7 +113,7 @@ GURL AppendOrReplaceQueryParameter(const GURL& url, output += key_value_pair; } - if (!replaced) { + if (!replaced && should_keep_param) { if (!output.empty()) output += "&"; diff --git a/chromium/net/base/url_util.h b/chromium/net/base/url_util.h index 1ae5998c2b0..bc1f761a543 100644 --- a/chromium/net/base/url_util.h +++ b/chromium/net/base/url_util.h @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,6 +14,7 @@ #include "base/strings/string_piece.h" #include "net/base/net_export.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "url/third_party/mozilla/url_parse.h" class GURL; @@ -40,9 +41,10 @@ NET_EXPORT GURL AppendQueryParameter(const GURL& url, const std::string& value); // Returns a new GURL by appending or replacing the given query parameter name -// and the value. If |name| appears more than once, only the first name-value +// and the value. If `name` appears more than once, only the first name-value // pair is replaced. Unsafe characters in the name and the value are escaped // like %XX%XX. The original query component is preserved if it's present. +// Using `absl::nullopt` for `value` will remove the `name` parameter. // // Examples: // @@ -52,9 +54,13 @@ NET_EXPORT GURL AppendQueryParameter(const GURL& url, // AppendOrReplaceQueryParameter( // GURL("http://example.com?x=y&name=old"), "name", "new").spec() // => "http://example.com?x=y&name=new" -NET_EXPORT GURL AppendOrReplaceQueryParameter(const GURL& url, - const std::string& name, - const std::string& value); +// AppendOrReplaceQueryParameter( +// GURL("http://example.com?x=y&name=old"), "name", absl::nullopt).spec() +// => "http://example.com?x=y&" +NET_EXPORT GURL +AppendOrReplaceQueryParameter(const GURL& url, + const std::string& name, + absl::optional<base::StringPiece> value); // Iterates over the key-value pairs in the query portion of |url|. // NOTE: QueryIterator stores reference to |url| and creates base::StringPiece diff --git a/chromium/net/base/url_util_unittest.cc b/chromium/net/base/url_util_unittest.cc index a77f8bc8cce..3c5ee049e6b 100644 --- a/chromium/net/base/url_util_unittest.cc +++ b/chromium/net/base/url_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,6 +9,7 @@ #include "base/format_macros.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "url/gurl.h" #include "url/scheme_host_port.h" #include "url/url_util.h" @@ -80,7 +81,7 @@ TEST(UrlUtilTest, AppendOrReplaceQueryParameter) { GURL("http://example.com/path?name=old&existing=one&name=old"), "name", "new").spec()); - // Preserve the content of the original params regarless of our failure to + // Preserve the content of the original params regardless of our failure to // interpret them correctly. EXPECT_EQ("http://example.com/path?bar&name=new&left=&" "=right&=&&name=again", @@ -88,6 +89,78 @@ TEST(UrlUtilTest, AppendOrReplaceQueryParameter) { GURL("http://example.com/path?bar&name=old&left=&" "=right&=&&name=again"), "name", "new").spec()); + + // ----- Removing the key using nullopt value ----- + + // Removes the name-value pair from the URL preserving other query parameters. + EXPECT_EQ("http://example.com/path?abc=xyz", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?name=value&abc=xyz"), "name", + absl::nullopt) + .spec()); + + // Removes the name-value pair from the URL. + EXPECT_EQ("http://example.com/path?", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?existing=one"), "existing", + absl::nullopt) + .spec()); + + // Removes the first name-value pair. + EXPECT_EQ("http://example.com/path?c=d&e=f", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?a=b&c=d&e=f"), "a", absl::nullopt) + .spec()); + + // Removes a name-value pair in between two query params. + EXPECT_EQ( + "http://example.com/path?existing=one&hello=world", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?existing=one&replace=sure&hello=world"), + "replace", absl::nullopt) + .spec()); + + // Removes the last name-value pair. + EXPECT_EQ("http://example.com/path?existing=one", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?existing=one&replace=sure"), + "replace", absl::nullopt) + .spec()); + + // Removing a name-value pair with unsafe characters included. The + // unsafe characters should be escaped. + EXPECT_EQ("http://example.com/path?existing=one&hello=world", + AppendOrReplaceQueryParameter( + GURL("http://example.com/" + "path?existing=one&na+me=v.alue%3D&hello=world"), + "na me", absl::nullopt) + .spec()); + + // Does nothing if the provided query param key does not exist. + EXPECT_EQ("http://example.com/path?existing=one&name=old", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?existing=one&name=old"), "old", + absl::nullopt) + .spec()); + + // Remove the value of first parameter with this name only. + EXPECT_EQ( + "http://example.com/path?existing=one&name=old", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?name=something&existing=one&name=old"), + "name", absl::nullopt) + .spec()); + + // Preserve the content of the original params regardless of our failure to + // interpret them correctly. + EXPECT_EQ( + "http://example.com/path?bar&left=&" + "=right&=&&name=again", + AppendOrReplaceQueryParameter( + GURL("http://example.com/path?bar&name=old&left=&" + "=right&=&&name=again"), + "name", absl::nullopt) + .spec()); } TEST(UrlUtilTest, GetValueForKeyInQuery) { diff --git a/chromium/net/base/winsock_init.cc b/chromium/net/base/winsock_init.cc index 55c56161201..946f5c3d59a 100644 --- a/chromium/net/base/winsock_init.cc +++ b/chromium/net/base/winsock_init.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/winsock_init.h b/chromium/net/base/winsock_init.h index c33de9dbfbe..d6e295c38e7 100644 --- a/chromium/net/base/winsock_init.h +++ b/chromium/net/base/winsock_init.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/winsock_util.cc b/chromium/net/base/winsock_util.cc index 2e90e7a269b..aff59bcfabd 100644 --- a/chromium/net/base/winsock_util.cc +++ b/chromium/net/base/winsock_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/net/base/winsock_util.h b/chromium/net/base/winsock_util.h index 1e555af3fde..35bde234af6 100644 --- a/chromium/net/base/winsock_util.h +++ b/chromium/net/base/winsock_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. |