#include "third_party/blink/renderer/modules/shared_storage/shared_storage.h"
#include <memory>
#include <tuple>
#include <utility>
#include "base/check.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/shared_storage/shared_storage_utils.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom-blink.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage_worklet_service.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_worklet_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_binding_for_modules.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_shared_storage_private_aggregation_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_shared_storage_run_operation_method_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_shared_storage_set_method_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_shared_storage_url_with_metadata.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_shared_storage_worklet_options.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/modules/shared_storage/shared_storage_window_supplement.h"
#include "third_party/blink/renderer/modules/shared_storage/shared_storage_worklet.h"
#include "third_party/blink/renderer/modules/shared_storage/shared_storage_worklet_global_scope.h"
#include "third_party/blink/renderer/modules/shared_storage/util.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_deque.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
namespace {
enum class GlobalScope { … };
enum class SharedStorageSetterMethod { … };
void LogTimingHistogramForSetterMethod(SharedStorageSetterMethod method,
GlobalScope global_scope,
base::TimeTicks start_time) { … }
void OnSetterMethodFinished(ScriptPromiseResolver<IDLAny>* resolver,
SharedStorage* shared_storage,
SharedStorageSetterMethod method,
GlobalScope global_scope,
base::TimeTicks start_time,
bool success,
const String& error_message) { … }
mojom::blink::SharedStorageDocumentService* GetSharedStorageDocumentService(
ExecutionContext* execution_context) { … }
mojom::blink::SharedStorageWorkletServiceClient*
GetSharedStorageWorkletServiceClient(ExecutionContext* execution_context) { … }
bool CanGetOutsideWorklet(ScriptState* script_state) { … }
SharedStorageDataOrigin ParseDataOrigin(const String& data_origin_value) { … }
}
class SharedStorage::IterationSource final
: public PairAsyncIterable<SharedStorage>::IterationSource,
public mojom::blink::SharedStorageEntriesListener { … };
SharedStorage::SharedStorage() = default;
SharedStorage::~SharedStorage() = default;
void SharedStorage::Trace(Visitor* visitor) const { … }
ScriptPromise<IDLAny> SharedStorage::set(ScriptState* script_state,
const String& key,
const String& value,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SharedStorage::set(
ScriptState* script_state,
const String& key,
const String& value,
const SharedStorageSetMethodOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SharedStorage::append(ScriptState* script_state,
const String& key,
const String& value,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SharedStorage::Delete(ScriptState* script_state,
const String& key,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SharedStorage::clear(ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<IDLString> SharedStorage::get(ScriptState* script_state,
const String& key,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUnsignedLong> SharedStorage::length(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<IDLDouble> SharedStorage::remainingBudget(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptValue SharedStorage::context(ScriptState* script_state,
ExceptionState& exception_state) const { … }
ScriptPromise<V8SharedStorageResponse> SharedStorage::selectURL(
ScriptState* script_state,
const String& name,
HeapVector<Member<SharedStorageUrlWithMetadata>> urls,
ExceptionState& exception_state) { … }
ScriptPromise<V8SharedStorageResponse> SharedStorage::selectURL(
ScriptState* script_state,
const String& name,
HeapVector<Member<SharedStorageUrlWithMetadata>> urls,
const SharedStorageRunOperationMethodOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SharedStorage::run(ScriptState* script_state,
const String& name,
ExceptionState& exception_state) { … }
ScriptPromise<IDLAny> SharedStorage::run(
ScriptState* script_state,
const String& name,
const SharedStorageRunOperationMethodOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<SharedStorageWorklet> SharedStorage::createWorklet(
ScriptState* script_state,
const String& module_url,
const SharedStorageWorkletOptions* options,
ExceptionState& exception_state) { … }
SharedStorageWorklet* SharedStorage::worklet(ScriptState* script_state,
ExceptionState& exception_state) { … }
PairAsyncIterable<SharedStorage>::IterationSource*
SharedStorage::CreateIterationSource(
ScriptState* script_state,
typename PairAsyncIterable<SharedStorage>::IterationSource::Kind kind,
ExceptionState& exception_state) { … }
}