File: util.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; 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 (97 lines) | stat: -rw-r--r-- 4,143 bytes parent folder | download | duplicates (5)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SHARED_STORAGE_UTIL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SHARED_STORAGE_UTIL_H_

#include "base/memory/scoped_refptr.h"
#include "services/network/public/mojom/shared_storage.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom-blink-forward.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "v8/include/v8-isolate.h"

namespace WTF {
class String;
}

namespace blink {

class ExecutionContext;
class ExceptionState;
class ScriptState;
class ScriptPromiseResolverBase;
class SharedStorageRunOperationMethodOptions;

static constexpr size_t kMaximumFilteringIdMaxBytes = 8;

static constexpr char kOpaqueContextOriginCheckErrorMessage[] =
    "The shared storage method is not allowed in an opaque origin context";

static constexpr char kOpaqueDataOriginCheckErrorMessage[] =
    "The shared storage method is not allowed to have an opaque data origin";

static constexpr char kInvalidKeyParameterLengthErrorMessage[] =
    "Length of the \"key\" parameter is not valid";

static constexpr char kInvalidValueParameterLengthErrorMessage[] =
    "Length of the \"value\" parameter is not valid";

// This enum classifies the value of `dataOrigin` in
// shared_storage_worklet_options.idl.
enum class SharedStorageDataOrigin {
  kContextOrigin = 0,
  kScriptOrigin = 1,
  kCustomOrigin = 2,
  kInvalid = 3,
};

// Helper method to convert v8 string to WTF::String.
bool StringFromV8(v8::Isolate* isolate,
                  v8::Local<v8::Value> val,
                  WTF::String* out);

// Whether `lock_name` is a reserved lock resource name.
// See https://w3c.github.io/web-locks/#resource-name
bool IsReservedLockName(const String& lock_name);

// Whether `methods_with_options` is a valid batchUpdate() argument: according
// to the specification (https://wicg.github.io/shared-storage/#batch-update),
// none of the inner methods should specify the `with_lock` option.
bool IsValidSharedStorageBatchUpdateMethodsArgument(
    const Vector<
        network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>&
        methods_with_options);

// Return if there is a valid browsing context associated with `script_state`.
// Throw an error via `exception_state` if invalid.
bool CheckBrowsingContextIsValid(ScriptState& script_state,
                                 ExceptionState& exception_state);

// Return if the shared-storage permissions policy is allowed in
// `execution_context`. Throw an error via `exception_state` if disallowed.
bool CheckSharedStoragePermissionsPolicy(ExecutionContext& execution_context,
                                         ExceptionState& exception_state);

// Returns true if a valid privateAggregationConfig is provided or if no config
// is provided. A config is invalid if an invalid (i.e. too long) context_id
// string is provided or an invalid (i.e. not on the allowlist)
// aggregationCoordinatorOrigin is provided. If the config is invalid, returns
// false and rejects the `resolver` with an error. Always populates
// `out_private_aggregation_config` with a new config object. If a valid
// context_id string was provided, `out_private_aggregation_config->context_id`
// is populated with it; otherwise, it's left default (a null String). If a
// valid aggregation coordinator is provided,
// `out_private_aggregation_config->aggregation_coodinator_origin` is populated
// with it; otherwise, it's left default (nullptr). If a valid
// filteringIdMaxBytes is provided, `out_filtering_id_max_bytes` is populated
// with it; otherwise, it's populated with the default of 1.
bool CheckPrivateAggregationConfig(
    const SharedStorageRunOperationMethodOptions& options,
    ScriptState& script_state,
    ScriptPromiseResolverBase& resolver,
    mojom::blink::PrivateAggregationConfigPtr& out_private_aggregation_config);

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_SHARED_STORAGE_UTIL_H_