-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shorten the name of SharedDictionaryStorageIsolationKey
This CL just renames SharedDictionaryStorageIsolationKey to SharedDictionaryIsolationKey. Bug: 1413922 Change-Id: I94d6dc1718085a7d338217fc2039448a7641610b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4619791 Commit-Queue: Tsuyoshi Horo <horo@chromium.org> Reviewed-by: Adam Rice <ricea@chromium.org> Cr-Commit-Position: refs/heads/main@{#1158684}
- Loading branch information
Showing
25 changed files
with
355 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
net/extras/shared_dictionary/shared_dictionary_isolation_key.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2023 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/extras/shared_dictionary/shared_dictionary_isolation_key.h" | ||
|
||
#include "net/base/isolation_info.h" | ||
|
||
namespace net { | ||
|
||
// static | ||
absl::optional<SharedDictionaryIsolationKey> | ||
SharedDictionaryIsolationKey::MaybeCreate( | ||
const net::IsolationInfo& isolation_info) { | ||
if (!isolation_info.frame_origin() || | ||
isolation_info.frame_origin()->opaque() || | ||
!isolation_info.top_frame_origin() || | ||
isolation_info.top_frame_origin()->opaque() || | ||
isolation_info.nonce().has_value()) { | ||
return absl::nullopt; | ||
} | ||
return SharedDictionaryIsolationKey( | ||
*isolation_info.frame_origin(), | ||
net::SchemefulSite(*isolation_info.top_frame_origin())); | ||
} | ||
|
||
SharedDictionaryIsolationKey::SharedDictionaryIsolationKey( | ||
const url::Origin& frame_origin, | ||
const net::SchemefulSite& top_frame_site) | ||
: frame_origin_(frame_origin), top_frame_site_(top_frame_site) {} | ||
|
||
SharedDictionaryIsolationKey::~SharedDictionaryIsolationKey() = default; | ||
|
||
SharedDictionaryIsolationKey::SharedDictionaryIsolationKey( | ||
const SharedDictionaryIsolationKey& other) = default; | ||
|
||
SharedDictionaryIsolationKey::SharedDictionaryIsolationKey( | ||
SharedDictionaryIsolationKey&& other) = default; | ||
|
||
SharedDictionaryIsolationKey& SharedDictionaryIsolationKey::operator=( | ||
const SharedDictionaryIsolationKey& other) = default; | ||
|
||
SharedDictionaryIsolationKey& SharedDictionaryIsolationKey::operator=( | ||
SharedDictionaryIsolationKey&& other) = default; | ||
|
||
} // namespace net |
58 changes: 58 additions & 0 deletions
58
net/extras/shared_dictionary/shared_dictionary_isolation_key.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2023 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_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_ISOLATION_KEY_H_ | ||
#define NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_ISOLATION_KEY_H_ | ||
|
||
#include "base/component_export.h" | ||
#include "net/base/schemeful_site.h" | ||
#include "third_party/abseil-cpp/absl/types/optional.h" | ||
#include "url/origin.h" | ||
|
||
namespace net { | ||
class IsolationInfo; | ||
|
||
// Key used to isolate shared dictionary storages. | ||
class COMPONENT_EXPORT(NET_EXTRAS) SharedDictionaryIsolationKey { | ||
public: | ||
// Creates a SharedDictionaryIsolationKey. Returns nullopt when | ||
// `frame_origin` or `top_frame_origin` of `isolation_info` is not set or | ||
// opaque, or `nonce` is set. | ||
static absl::optional<SharedDictionaryIsolationKey> MaybeCreate( | ||
const net::IsolationInfo& isolation_info); | ||
|
||
SharedDictionaryIsolationKey(const url::Origin& frame_origin, | ||
const net::SchemefulSite& top_frame_site); | ||
|
||
const url::Origin& frame_origin() const { return frame_origin_; } | ||
const net::SchemefulSite top_frame_site() const { return top_frame_site_; } | ||
|
||
~SharedDictionaryIsolationKey(); | ||
|
||
SharedDictionaryIsolationKey(const SharedDictionaryIsolationKey& other); | ||
SharedDictionaryIsolationKey(SharedDictionaryIsolationKey&& other); | ||
SharedDictionaryIsolationKey& operator=( | ||
const SharedDictionaryIsolationKey& other); | ||
SharedDictionaryIsolationKey& operator=(SharedDictionaryIsolationKey&& other); | ||
|
||
bool operator==(const SharedDictionaryIsolationKey& other) const { | ||
return std::tie(frame_origin_, top_frame_site_) == | ||
std::tie(other.frame_origin_, other.top_frame_site_); | ||
} | ||
bool operator!=(const SharedDictionaryIsolationKey& other) const { | ||
return !(*this == other); | ||
} | ||
bool operator<(const SharedDictionaryIsolationKey& other) const { | ||
return std::tie(frame_origin_, top_frame_site_) < | ||
std::tie(other.frame_origin_, other.top_frame_site_); | ||
} | ||
|
||
private: | ||
url::Origin frame_origin_; | ||
net::SchemefulSite top_frame_site_; | ||
}; | ||
|
||
} // namespace net | ||
|
||
#endif // NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_ISOLATION_KEY_H_ |
79 changes: 79 additions & 0 deletions
79
net/extras/shared_dictionary/shared_dictionary_isolation_key_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2023 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/extras/shared_dictionary/shared_dictionary_isolation_key.h" | ||
|
||
#include "net/base/isolation_info.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "url/gurl.h" | ||
|
||
namespace net { | ||
|
||
namespace { | ||
const GURL kUrl1("https://origin1.test/"); | ||
const net::SchemefulSite kSite1(GURL("https://origin1.test/")); | ||
const net::SchemefulSite kSite2(GURL("https://origin2.test/")); | ||
} // namespace | ||
|
||
TEST(SharedDictionaryIsolationKeyTest, MaybeCreate) { | ||
url::Origin origin = url::Origin::Create(kUrl1); | ||
const absl::optional<SharedDictionaryIsolationKey> isolation_key = | ||
SharedDictionaryIsolationKey::MaybeCreate( | ||
net::IsolationInfo::Create(net::IsolationInfo::RequestType::kOther, | ||
origin, origin, net::SiteForCookies())); | ||
EXPECT_TRUE(isolation_key); | ||
} | ||
|
||
TEST(SharedDictionaryIsolationKeyTest, MaybeCreateOpaqueTopFrameOrigin) { | ||
const absl::optional<SharedDictionaryIsolationKey> isolation_key = | ||
SharedDictionaryIsolationKey::MaybeCreate(net::IsolationInfo::Create( | ||
net::IsolationInfo::RequestType::kOther, url::Origin(), | ||
url::Origin::Create(kUrl1), net::SiteForCookies())); | ||
EXPECT_FALSE(isolation_key); | ||
} | ||
|
||
TEST(SharedDictionaryIsolationKeyTest, MaybeCreateOpaqueFrameOrigin) { | ||
url::Origin origin = url::Origin::Create(kUrl1); | ||
const absl::optional<SharedDictionaryIsolationKey> isolation_key = | ||
SharedDictionaryIsolationKey::MaybeCreate(net::IsolationInfo::Create( | ||
net::IsolationInfo::RequestType::kOther, origin, url::Origin(), | ||
net::SiteForCookies())); | ||
EXPECT_FALSE(isolation_key); | ||
} | ||
|
||
TEST(SharedDictionaryIsolationKeyTest, MaybeCreateWithNonce) { | ||
const absl::optional<SharedDictionaryIsolationKey> isolation_key = | ||
SharedDictionaryIsolationKey::MaybeCreate(net::IsolationInfo::Create( | ||
net::IsolationInfo::RequestType::kOther, url::Origin::Create(kUrl1), | ||
url::Origin(), net::SiteForCookies(), | ||
/*party_context=*/absl::nullopt, | ||
/*nonce=*/base::UnguessableToken::Create())); | ||
EXPECT_FALSE(isolation_key); | ||
} | ||
|
||
TEST(SharedDictionaryIsolationKeyTest, SameFrameOriginSameTopFrameSite) { | ||
SharedDictionaryIsolationKey isolation_key1(url::Origin::Create(kUrl1), | ||
kSite1); | ||
SharedDictionaryIsolationKey isolation_key2(url::Origin::Create(kUrl1), | ||
kSite1); | ||
EXPECT_EQ(isolation_key1, isolation_key2); | ||
} | ||
|
||
TEST(SharedDictionaryIsolationKeyTest, DifferentFrameOriginSameTopFrameSite) { | ||
SharedDictionaryIsolationKey isolation_key1( | ||
url::Origin::Create(GURL("https://www1.origin1.test/")), kSite1); | ||
SharedDictionaryIsolationKey isolation_key2( | ||
url::Origin::Create(GURL("https://www2.origin1.test/")), kSite1); | ||
EXPECT_NE(isolation_key1, isolation_key2); | ||
} | ||
|
||
TEST(SharedDictionaryIsolationKeyTest, SameFrameOriginDifferentTopFrameSite) { | ||
SharedDictionaryIsolationKey isolation_key1(url::Origin::Create(kUrl1), | ||
kSite1); | ||
SharedDictionaryIsolationKey isolation_key2(url::Origin::Create(kUrl1), | ||
kSite2); | ||
EXPECT_NE(isolation_key1, isolation_key2); | ||
} | ||
|
||
} // namespace net |
49 changes: 0 additions & 49 deletions
49
net/extras/shared_dictionary/shared_dictionary_storage_isolation_key.cc
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
net/extras/shared_dictionary/shared_dictionary_storage_isolation_key.h
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.