Skip to content

Commit

Permalink
Shorten the name of SharedDictionaryStorageIsolationKey
Browse files Browse the repository at this point in the history
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
horo-t authored and Chromium LUCI CQ committed Jun 16, 2023
1 parent 04dbb6d commit 7b19613
Show file tree
Hide file tree
Showing 25 changed files with 355 additions and 374 deletions.
6 changes: 3 additions & 3 deletions net/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1806,8 +1806,8 @@ component("extras") {
sources = [
"extras/shared_dictionary/shared_dictionary_info.cc",
"extras/shared_dictionary/shared_dictionary_info.h",
"extras/shared_dictionary/shared_dictionary_storage_isolation_key.cc",
"extras/shared_dictionary/shared_dictionary_storage_isolation_key.h",
"extras/shared_dictionary/shared_dictionary_isolation_key.cc",
"extras/shared_dictionary/shared_dictionary_isolation_key.h",
"extras/sqlite/cookie_crypto_delegate.h",
"extras/sqlite/sqlite_persistent_cookie_store.cc",
"extras/sqlite/sqlite_persistent_cookie_store.h",
Expand Down Expand Up @@ -2844,7 +2844,7 @@ test("net_unittests") {

if (!is_cronet_build) {
sources += [
"extras/shared_dictionary/shared_dictionary_storage_isolation_key_unittest.cc",
"extras/shared_dictionary/shared_dictionary_isolation_key_unittest.cc",
"extras/sqlite/sqlite_persistent_cookie_store_unittest.cc",
"extras/sqlite/sqlite_persistent_shared_dictionary_store_unittest.cc",
"log/trace_net_log_observer_unittest.cc",
Expand Down
46 changes: 46 additions & 0 deletions net/extras/shared_dictionary/shared_dictionary_isolation_key.cc
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 net/extras/shared_dictionary/shared_dictionary_isolation_key.h
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_
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

This file was deleted.

This file was deleted.

0 comments on commit 7b19613

Please sign in to comment.