• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_ISOLATION_KEY_H_
6 #define NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_ISOLATION_KEY_H_
7 
8 #include "base/component_export.h"
9 #include "net/base/schemeful_site.h"
10 #include "third_party/abseil-cpp/absl/types/optional.h"
11 #include "url/origin.h"
12 
13 namespace net {
14 class IsolationInfo;
15 class NetworkIsolationKey;
16 
17 // Key used to isolate shared dictionary storages.
COMPONENT_EXPORT(NET_SHARED_DICTIONARY)18 class COMPONENT_EXPORT(NET_SHARED_DICTIONARY) SharedDictionaryIsolationKey {
19  public:
20   // Creates a SharedDictionaryIsolationKey. Returns nullopt when
21   // `frame_origin` or `top_frame_origin` of `isolation_info` is not set or
22   // opaque, or `nonce` is set.
23   static absl::optional<SharedDictionaryIsolationKey> MaybeCreate(
24       const net::IsolationInfo& isolation_info);
25 
26   // Creates a SharedDictionaryIsolationKey. Returns nullopt when
27   // `frame_origin` or `top_frame_origin` of `network_isolation_key` is not set
28   // or opaque, or `nonce` of `network_isolation_key` is set.
29   static absl::optional<SharedDictionaryIsolationKey> MaybeCreate(
30       const NetworkIsolationKey& network_isolation_key,
31       const absl::optional<url::Origin>& frame_origin);
32 
33   SharedDictionaryIsolationKey() = default;
34   SharedDictionaryIsolationKey(const url::Origin& frame_origin,
35                                const net::SchemefulSite& top_frame_site);
36 
37   const url::Origin& frame_origin() const { return frame_origin_; }
38   const net::SchemefulSite& top_frame_site() const { return top_frame_site_; }
39 
40   ~SharedDictionaryIsolationKey();
41 
42   SharedDictionaryIsolationKey(const SharedDictionaryIsolationKey& other);
43   SharedDictionaryIsolationKey(SharedDictionaryIsolationKey&& other);
44   SharedDictionaryIsolationKey& operator=(
45       const SharedDictionaryIsolationKey& other);
46   SharedDictionaryIsolationKey& operator=(SharedDictionaryIsolationKey&& other);
47 
48   bool operator==(const SharedDictionaryIsolationKey& other) const {
49     return std::tie(frame_origin_, top_frame_site_) ==
50            std::tie(other.frame_origin_, other.top_frame_site_);
51   }
52   bool operator!=(const SharedDictionaryIsolationKey& other) const {
53     return !(*this == other);
54   }
55   bool operator<(const SharedDictionaryIsolationKey& other) const {
56     return std::tie(frame_origin_, top_frame_site_) <
57            std::tie(other.frame_origin_, other.top_frame_site_);
58   }
59 
60  private:
61   url::Origin frame_origin_;
62   net::SchemefulSite top_frame_site_;
63 };
64 
65 }  // namespace net
66 
67 #endif  // NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_ISOLATION_KEY_H_
68