File: privacy_sandbox_settings.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (370 lines) | stat: -rw-r--r-- 17,292 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// 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.

#ifndef COMPONENTS_PRIVACY_SANDBOX_PRIVACY_SANDBOX_SETTINGS_H_
#define COMPONENTS_PRIVACY_SANDBOX_PRIVACY_SANDBOX_SETTINGS_H_

#include "components/browsing_topics/common/common_types.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/privacy_sandbox/tpcd_experiment_eligibility.h"
#include "content/public/browser/interest_group_api_operation.h"

#include "base/time/time.h"

class GURL;

namespace content {
class RenderFrameHost;
}

namespace url {
class Origin;
}

namespace privacy_sandbox {

class CanonicalTopic;

// When a new enum value is added:
// 1. Update kMaxValue to match it.
// 2. Update `PrivacySandboxAttestationsGatedAPIProto` in
//    `privacy_sandbox_attestations.proto`.
// 3. Update `InsertAPI` in `privacy_sandbox_attestations_parser.cc`.
enum class PrivacySandboxAttestationsGatedAPI {
  kTopics,
  kProtectedAudience,
  kPrivateAggregation,
  kAttributionReporting,
  kSharedStorage,
  kFencedStorageRead,

  kMaxValue = kFencedStorageRead,
};

// A service which acts as a intermediary between Privacy Sandbox APIs and
// the preferences and content settings which define when they are allowed
// to be accessed. Privacy Sandbox APIs, regardless of where they live
// (renderer, browser, network etc), must consult this service to determine
// when they are allowed to run. While a basic on/off control is provided by
// this service, embedders are expected to achieve fine-grained control
// though the underlying preferences and content settings separately.
class PrivacySandboxSettings : public KeyedService {
 public:
  class Observer {
   public:
    virtual void OnTopicsDataAccessibleSinceUpdated() {}

    // Fired when the Related Website Sets changes to being `enabled` as a
    // result of the kPrivacySandboxRelatedWebsiteSets preference changing.
    virtual void OnRelatedWebsiteSetsEnabledChanged(bool enabled) {}
  };

  class Delegate {
   public:
    virtual ~Delegate() = default;

    // Allows the delegate to restrict access to the Privacy Sandbox. When
    // the Privacy Sandbox is restricted, all API access is disabled. This
    // is consulted on every access check, and it is acceptable for this to
    // change return value over the life of the service.
    virtual bool IsPrivacySandboxRestricted() const = 0;

    // Allows the delegate to query in real time if Privacy Sandbox is currently
    // unrestricted. Unlike IsPrivacySandboxRestricted, does NOT
    // restrict/unrestrict access to the Privacy Sandbox.
    virtual bool IsPrivacySandboxCurrentlyUnrestricted() const = 0;

    // Whether the current profile is Incognito or not. For Incognito, the
    // privacy sandbox APIs are restricted.
    virtual bool IsIncognitoProfile() const = 0;

    // Whether there is an appropriate level of consent for the Topics API.
    // When this returns false, access control functions for Topics will
    // return as not allowed.
    virtual bool HasAppropriateTopicsConsent() const = 0;

    // Whether the profile is subject to being given notice of restrictions to
    // the standard set of Privacy Sandbox APIs.
    virtual bool IsSubjectToM1NoticeRestricted() const = 0;

    // Whether the Privacy Sandbox is partially enabled based on
    // restrictions.
    virtual bool IsRestrictedNoticeEnabled() const = 0;

    // Whether the profile is eligible for 3PCD experiment. The eligibility
    // applies for both mode A and mode B experiments.
    virtual bool IsCookieDeprecationExperimentEligible() const = 0;

    // Returns the profile's computed eligibility for 3PCD experiment. The
    // eligibility applies for both mode A and mode B experiments. Unlike
    // `IsCookieDeprecationExperimentEligible` this method returns the real time
    // eligibility.
    virtual TpcdExperimentEligibility
    GetCookieDeprecationExperimentCurrentEligibility() const = 0;

    // Whether cookie deprecation label is allowed.
    virtual bool IsCookieDeprecationLabelAllowed() const = 0;

    // Whether third-party cookies are blocked due to cookie deprecation
    // experiment. Also returns false if users explicitly block third-party
    // cookies.
    virtual bool AreThirdPartyCookiesBlockedByCookieDeprecationExperiment()
        const = 0;
  };

  // Returns whether the Topics API is allowed at all. If false, Topics API
  // calculations should not occur. If true, the more specific function,
  // IsTopicsApiAllowedForContext(), should be consulted for the relevant
  // context.
  virtual bool IsTopicsAllowed() const = 0;

  // Determines whether the Topics API is allowable in a particular context.
  // |top_frame_origin| is used to check for content settings which could both
  // affect 1P and 3P contexts.
  // If provided, `console_frame` is used to log errors to the console upon
  // attestation failure.
  virtual bool IsTopicsAllowedForContext(
      const url::Origin& top_frame_origin,
      const GURL& url,
      content::RenderFrameHost* console_frame = nullptr) const = 0;

  // Returns whether |topic| can be either considered as a top topic for the
  // current epoch, or provided to a website as a previous / current epochs
  // site assigned topic.
  virtual bool IsTopicAllowed(const CanonicalTopic& topic) = 0;

  // Returns whether |topic| is prioritized by Finch settings.
  virtual bool IsTopicPrioritized(const CanonicalTopic& topic) = 0;

  // Sets |topic| to |allowed|. Whether a topic is allowed or not is made
  // available through IsTopicAllowed().
  virtual void SetTopicAllowed(const CanonicalTopic& topic, bool allowed) = 0;

  // Removes all Topic settings with creation times between |start_time|
  // and |end_time|. This allows for integration with the existing browsing data
  // remover, such as the one powering Clear Browser Data.
  virtual void ClearTopicSettings(base::Time start_time,
                                  base::Time end_time) = 0;

  // Returns the point in time from which history is eligible to be used when
  // calculating a user's Topics API topics. Reset when a user clears all
  // cookies, or when the browser restarts with "Clear on exit" enabled. The
  // returned time will have been fuzzed for local privacy, and so may be in the
  // future, in which case no history is eligible.
  virtual base::Time TopicsDataAccessibleSince() const = 0;

  // Returns whether any Attribution Reporting operation would ever be allowed.
  // If false, no attribution reporting operation is allowed (e.g. because the
  // user has disabled the setting). If true, the appropriate context specific
  // check must also be made.
  virtual bool IsAttributionReportingEverAllowed() const = 0;

  // Determines whether Attribution Reporting is allowable in a particular
  // context. Should be called at both source and trigger registration. At each
  // of these points |top_frame_origin| is the same as either the source origin
  // or the destination origin respectively.
  // If provided, `console_frame` is used to log errors to the console upon
  // attestation failure.
  virtual bool IsAttributionReportingAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& reporting_origin,
      content::RenderFrameHost* console_frame = nullptr) const = 0;

  // Called before sending the associated attribution report to
  // |reporting_origin|. Re-checks that |reporting_origin| is allowable as a 3P
  // on both |source_origin| and |destination_origin|.
  // If provided, `console_frame` is used to log errors to the console upon
  // attestation failure.
  virtual bool MaySendAttributionReport(
      const url::Origin& source_origin,
      const url::Origin& destination_origin,
      const url::Origin& reporting_origin,
      content::RenderFrameHost* console_frame = nullptr) const = 0;

  // Determines whether Attribution Reporting API's transitional debug reporting
  // is allowable in a particular context. Note that
  // `IsAttributionReportingAllowed()` should be called prior to this.
  // |can_bypass| indicates whether the result can be bypassed which is set to
  // true when it's disallowed due to the cookie deprecation experiment.
  //
  // TODO(crbug.com/40941634): Clean up `can_bypass` after the cookie
  // deprecation experiment.
  virtual bool IsAttributionReportingTransitionalDebuggingAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& reporting_origin,
      bool& can_bypass) const = 0;

  // Sets the ability for |top_frame_etld_plus1| to join the profile to interest
  // groups to |allowed|. This information is stored in preferences, and is made
  // available to the API via IsFledgeJoiningAllowed(). |top_frame_etld_plus1|
  // should in most circumstances be a valid eTLD+1, but hosts are accepted to
  // allow for shifts in private registries. Entries are converted into wildcard
  // subdomain ContentSettingsPattern before comparison.
  virtual void SetFledgeJoiningAllowed(const std::string& top_frame_etld_plus1,
                                       bool allowed) = 0;

  // Clears any FLEDGE joining block settings with creation times between
  // |start_time| and |end_time|.
  virtual void ClearFledgeJoiningAllowedSettings(base::Time start_time,
                                                 base::Time end_time) = 0;

  // Determine whether |auction_party| can register an interest group, or sell
  // buy in an auction, on |top_frame_origin|.
  // If provided, `console_frame` is used to log errors to the console upon
  // attestation failure.
  virtual bool IsFledgeAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& auction_party,
      content::InterestGroupApiOperation interest_group_api_operation,
      content::RenderFrameHost* console_frame = nullptr) const = 0;

  // Determine whether |destination_origin| is allowed to receive events
  // (reportEvent(), automatic beacons) reported by an API like Protected
  // Audience or Shared Storage. This does not check if the API itself is
  // allowed by the calling context, since the corresponding registerAdBeacon
  // and selectUrl caller sites were also checked for attestation.
  virtual bool IsEventReportingDestinationAttested(
      const url::Origin& destination_origin,
      privacy_sandbox::PrivacySandboxAttestationsGatedAPI invoking_api)
      const = 0;

  // Determines whether Shared Storage is allowable in a particular context.
  // `top_frame_origin` can be the same as `accessing_origin` in the case of a
  // top-level document calling Shared Storage.
  //
  // If non-null, `out_debug_message` is updated in this call to relay details
  // back to the caller about how the returned boolean result was obtained.
  //
  // If provided, `console_frame` is used to log errors to the console upon
  // attestation failure.
  //
  // The out parameter `out_block_is_site_setting_specific` will be set to true
  // in the case that the return value is false and the failure to be allowed is
  // due to site-settings. Otherwise the parameter will be set to false (because
  // either the return value is true, or the failure is due to a
  // non-site-setting-specific reason).
  virtual bool IsSharedStorageAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& accessing_origin,
      std::string* out_debug_message,
      content::RenderFrameHost* console_frame,
      bool* out_block_is_site_setting_specific) const = 0;

  // Controls whether Shared Storage SelectURL is allowable for
  // `accessing_origin` in the context of `top_frame_origin`. Does not override
  // a false return value from IsSharedStorageAllowed.
  //
  // If non-null, `out_debug_message` is updated in this call to relay details
  // back to the caller about how the returned boolean result was obtained.
  //
  // The out parameter `out_block_is_site_setting_specific` will be set to true
  // in the case that the return value is false and the failure to be allowed is
  // due to site-settings. Otherwise the parameter will be set to false (because
  // either the return value is true, or the failure is due to a
  // non-site-setting-specific reason).
  virtual bool IsSharedStorageSelectURLAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& accessing_origin,
      std::string* out_debug_message,
      bool* out_block_is_site_setting_specific) const = 0;

  // Controls whether fenced storage read is allowable for `accessing_origin` in
  // the context of `top_frame_origin`.
  //
  // If provided, `console_frame` is used to log errors to the console upon
  // attestation failure.
  virtual bool IsFencedStorageReadAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& accessing_origin,
      content::RenderFrameHost* console_frame) const = 0;

  // Determines whether the Private Aggregation API is allowable in a particular
  // context. `top_frame_origin` is the associated top-frame origin of the
  // calling context. Applicable to all uses of Private Aggregation.
  //
  // The out parameter `out_block_is_site_setting_specific` will be set to true
  // in the case that the return value is false and the failure to be allowed is
  // due to site-settings. Otherwise the parameter will be set to false (because
  // either the return value is true, or the failure is due to a
  // non-site-setting-specific reason).
  virtual bool IsPrivateAggregationAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& reporting_origin,
      bool* out_block_is_site_setting_specific) const = 0;

  // Determines whether the Private Aggregation API's debug mode is allowable in
  // a particular context. Note that if IsPrivateAggregationAllowed() is false,
  // this will always be false too. `top_frame_origin` is the associated
  // top-frame origin of the calling context. Applicable to all uses of Private
  // Aggregation.
  virtual bool IsPrivateAggregationDebugModeAllowed(
      const url::Origin& top_frame_origin,
      const url::Origin& reporting_origin) const = 0;

  // Returns the profile computed eligibility for 3PCD experiments.
  // This consults the delegate for the real time eligibility of the profile.
  // The eligibility applies for both mode A and mode B experiments.
  virtual TpcdExperimentEligibility
  GetCookieDeprecationExperimentCurrentEligibility() const = 0;

  // Determines whether cookie deprecation label is allowable. This consults
  // whether the profile is eligible for 3PCD experiments. If true, the more
  // specific function, IsCookieDeprecationLabelAllowed(), should be consulted
  // for the relevant context.
  virtual bool IsCookieDeprecationLabelAllowed() const = 0;

  // Determines whether cookie deprecation label is allowable for
  // `context_origin` in the context of `top_frame_origin`.
  virtual bool IsCookieDeprecationLabelAllowedForContext(
      const url::Origin& top_frame_origin,
      const url::Origin& context_origin) const = 0;

  // Allows all Privacy Sandbox prefs for testing. This should be used if tests
  // don't depend on specific access control and just would like to have Privacy
  // Sandbox allowed. Doesn't affect other non-default settings which might
  // disallow APIs e.g. site data exceptions.
  virtual void SetAllPrivacySandboxAllowedForTesting() = 0;

  // Blocks Topics pref for testing.
  virtual void SetTopicsBlockedForTesting() = 0;

  // Returns whether the Privacy Sandbox is being restricted by the associated
  // delegate. Forwards directly to the corresponding delegate function.
  // Virtual to allow mocking in tests.
  virtual bool IsPrivacySandboxRestricted() const = 0;

  // Returns whether the Privacy Sandbox is being unrestricted by the associated
  // delegate. Forwards directly to the corresponding delegate function.
  // Virtual to allow mocking in tests. Unlike IsPrivacySandboxRestricted
  // this method always return the current restriction status.
  virtual bool IsPrivacySandboxCurrentlyUnrestricted() const = 0;

  // Returns whether the privacy sandbox restricted notice should be shown,
  // based on account characteristics. Forwards to the delegate. Virtual for
  // mocking in tests.
  virtual bool IsSubjectToM1NoticeRestricted() const = 0;

  // Returns whether the Privacy Sandbox is partially enabled based on
  // restrictions. Forwards to the delegate. Virtual for
  // mocking in tests.
  virtual bool IsRestrictedNoticeEnabled() const = 0;

  // Called when there's a broad cookies clearing action. For example, this
  // should be called on "Clear browsing data", but shouldn't be called on the
  // Clear-Site-Data header, as it's restricted to a specific site.
  virtual void OnCookiesCleared() = 0;

  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;

  // Overrides the internal delegate for test purposes.
  virtual void SetDelegateForTesting(std::unique_ptr<Delegate> delegate) = 0;

  // Source of truth for whether related website sets are enabled.
  virtual bool AreRelatedWebsiteSetsEnabled() const = 0;
};

}  // namespace privacy_sandbox

#endif  // COMPONENTS_PRIVACY_SANDBOX_PRIVACY_SANDBOX_SETTINGS_H_