File: url_info.cc

package info (click to toggle)
chromium 141.0.7390.107-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,254,812 kB
  • sloc: cpp: 35,264,957; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,636; asm: 950,788; xml: 751,751; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,319; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (183 lines) | stat: -rw-r--r-- 6,200 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// 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.

#include "content/browser/url_info.h"

#include <sstream>

#include "content/browser/isolation_context.h"

namespace content {

// We use NavigationRequest::navigation_id_ to provide sandbox id values; this
// function never returns a negative value, so we distinguish unused sandbox ids
// with the following constant.
const int64_t UrlInfo::kInvalidUniqueSandboxId = -1;

UrlInfo::UrlInfo() = default;

UrlInfo::UrlInfo(const UrlInfo& other) = default;

UrlInfo::UrlInfo(const UrlInfoInit& init)
    : url(init.url_),
      oac_header_request(init.oac_header_request_),
      is_coop_isolation_requested(init.requests_coop_isolation_),
      is_prefetch_with_cross_site_contamination(
          init.is_prefetch_with_cross_site_contamination_),
      origin(init.origin_),
      is_sandboxed(init.is_sandboxed_),
      unique_sandbox_id(init.unique_sandbox_id_),
      storage_partition_config(init.storage_partition_config_),
      web_exposed_isolation_info(init.web_exposed_isolation_info_),
      is_pdf(init.is_pdf_),
      cross_origin_isolation_key(init.cross_origin_isolation_key_) {
  DCHECK(init.is_sandboxed_ ||
         init.unique_sandbox_id_ == kInvalidUniqueSandboxId);
}

UrlInfo::~UrlInfo() = default;

// static
UrlInfo UrlInfo::CreateForTesting(
    const GURL& url_in,
    std::optional<StoragePartitionConfig> storage_partition_config) {
  return UrlInfo(
      UrlInfoInit(url_in).WithStoragePartitionConfig(storage_partition_config));
}

bool UrlInfo::IsIsolated() const {
  bool is_isolated = false;
  if (web_exposed_isolation_info) {
    is_isolated |= web_exposed_isolation_info->is_isolated();
  }

  if (cross_origin_isolation_key) {
    is_isolated |= cross_origin_isolation_key->cross_origin_isolation_mode ==
                   CrossOriginIsolationMode::kConcrete;
  }

  return is_isolated;
}

bool UrlInfo::RequestsOriginKeyedProcess(
    const IsolationContext& context) const {
  // An origin-keyed process should be used if (1) the UrlInfo requires it or
  // (2) the UrlInfo would have used an origin agent cluster based on the lack
  // of header, and the given IsolationContext is in a mode that uses
  // origin-keyed processes by default (i.e., kOriginKeyedProcessesByDefault).
  return (oac_header_request.has_value() &&
          oac_header_request->requires_origin_keyed_process()) ||
         (!oac_header_request.has_value() &&
          context.default_isolation_state().requires_origin_keyed_process());
}

void UrlInfo::WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const {
  proto->set_url(url.possibly_invalid_spec());
  if (origin.has_value()) {
    proto->set_origin(origin->GetDebugString());
  }
  proto->set_is_sandboxed(is_sandboxed);
  proto->set_is_pdf(is_pdf);
  proto->set_is_coop_isolation_requested(is_coop_isolation_requested);
  int origin_isolation_request = 0;
  if (oac_header_request &&
      oac_header_request->logical_oac_status() ==
          AgentClusterKey::OACStatus::kSiteKeyedByHeader) {
    origin_isolation_request = (1 << 0);
  } else if (oac_header_request &&
             oac_header_request->is_origin_agent_cluster()) {
    origin_isolation_request = (1 << 1);
    if (oac_header_request->requires_origin_keyed_process()) {
      origin_isolation_request += (1 << 2);
    }
  }
  proto->set_origin_isolation_request(origin_isolation_request);
  proto->set_is_prefetch_with_cross_site_contamination(
      is_prefetch_with_cross_site_contamination);
  if (web_exposed_isolation_info.has_value()) {
    proto.Set(TraceProto::kWebExposedIsolationInfo,
              *web_exposed_isolation_info);
  }
  if (storage_partition_config.has_value()) {
    std::stringstream ss;
    ss << *storage_partition_config;
    proto->set_storage_partition_config(ss.str());
  }
}

UrlInfoInit::UrlInfoInit(UrlInfoInit&) = default;

UrlInfoInit::UrlInfoInit(const GURL& url) : url_(url) {}

UrlInfoInit::UrlInfoInit(const UrlInfo& base)
    : url_(base.url),
      oac_header_request_(base.oac_header_request),
      requests_coop_isolation_(base.is_coop_isolation_requested),
      origin_(base.origin),
      is_sandboxed_(base.is_sandboxed),
      unique_sandbox_id_(base.unique_sandbox_id),
      storage_partition_config_(base.storage_partition_config),
      web_exposed_isolation_info_(base.web_exposed_isolation_info),
      is_pdf_(base.is_pdf),
      cross_origin_isolation_key_(base.cross_origin_isolation_key) {}

UrlInfoInit::~UrlInfoInit() = default;

UrlInfoInit& UrlInfoInit::WithOACHeaderRequest(
    std::optional<OriginAgentClusterIsolationState> oac_header_request) {
  oac_header_request_ = oac_header_request;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithCOOPSiteIsolation(bool requests_coop_isolation) {
  requests_coop_isolation_ = requests_coop_isolation;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithCrossSitePrefetchContamination(
    bool contaminated) {
  is_prefetch_with_cross_site_contamination_ = contaminated;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithOrigin(const url::Origin& origin) {
  origin_ = origin;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithSandbox(bool is_sandboxed) {
  is_sandboxed_ = is_sandboxed;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithUniqueSandboxId(int unique_sandbox_id) {
  unique_sandbox_id_ = unique_sandbox_id;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithStoragePartitionConfig(
    std::optional<StoragePartitionConfig> storage_partition_config) {
  storage_partition_config_ = storage_partition_config;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithWebExposedIsolationInfo(
    std::optional<WebExposedIsolationInfo> web_exposed_isolation_info) {
  web_exposed_isolation_info_ = web_exposed_isolation_info;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithIsPdf(bool is_pdf) {
  is_pdf_ = is_pdf;
  return *this;
}

UrlInfoInit& UrlInfoInit::WithCrossOriginIsolationKey(
    const std::optional<AgentClusterKey::CrossOriginIsolationKey>&
        cross_origin_isolation_key) {
  cross_origin_isolation_key_ = cross_origin_isolation_key;
  return *this;
}

}  // namespace content