#include "content/browser/shared_storage/shared_storage_worklet_host.h"
#include <stdint.h>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "components/services/storage/shared_storage/shared_storage_manager.h"
#include "content/browser/attribution_reporting/attribution_manager.h"
#include "content/browser/code_cache/generated_code_cache_context.h"
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/devtools/shared_storage_worklet_devtools_manager.h"
#include "content/browser/fenced_frame/fenced_frame_reporter.h"
#include "content/browser/private_aggregation/private_aggregation_budget_key.h"
#include "content/browser/private_aggregation/private_aggregation_host.h"
#include "content/browser/private_aggregation/private_aggregation_manager.h"
#include "content/browser/renderer_host/page_impl.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/shared_storage/shared_storage_code_cache_host_proxy.h"
#include "content/browser/shared_storage/shared_storage_document_service_impl.h"
#include "content/browser/shared_storage/shared_storage_render_thread_worklet_driver.h"
#include "content/browser/shared_storage/shared_storage_url_loader_factory_proxy.h"
#include "content/browser/shared_storage/shared_storage_worklet_driver.h"
#include "content/browser/shared_storage/shared_storage_worklet_host_manager.h"
#include "content/common/renderer.mojom.h"
#include "content/public/browser/browser_context.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "storage/browser/blob/blob_url_loader_factory.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/private_aggregation/private_aggregation_host.mojom.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage_worklet_service.mojom.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h"
#include "third_party/blink/public/mojom/worker/worklet_global_scope_creation_params.mojom.h"
#include "url/origin.h"
namespace content {
namespace {
AccessType;
constexpr base::TimeDelta kKeepAliveTimeout = …;
SharedStorageURNMappingResult;
OperationResult;
GetResult;
void LogSharedStorageWorkletErrorFromErrorMessage(
bool from_select_url,
const std::string& error_message) { … }
SharedStorageURNMappingResult CreateSharedStorageURNMappingResult(
StoragePartition* storage_partition,
BrowserContext* browser_context,
PageImpl* page,
const url::Origin& main_frame_origin,
const url::Origin& shared_storage_origin,
const net::SchemefulSite& shared_storage_site,
std::vector<blink::mojom::SharedStorageUrlWithMetadataPtr>
urls_with_metadata,
uint32_t index,
double budget_remaining,
blink::SharedStorageSelectUrlBudgetStatus& budget_status) { … }
bool IsValidFencedFrameReportingURL(const GURL& url) { … }
}
class SharedStorageWorkletHost::ScopedDevToolsHandle
: blink::mojom::WorkletDevToolsHost { … };
SharedStorageWorkletHost::SharedStorageWorkletHost(
SharedStorageDocumentServiceImpl& document_service,
const url::Origin& frame_origin,
const url::Origin& data_origin,
const GURL& script_source_url,
network::mojom::CredentialsMode credentials_mode,
const std::vector<blink::mojom::OriginTrialFeature>& origin_trial_features,
mojo::PendingAssociatedReceiver<blink::mojom::SharedStorageWorkletHost>
worklet_host,
blink::mojom::SharedStorageDocumentService::CreateWorkletCallback callback)
: … { … }
SharedStorageWorkletHost::~SharedStorageWorkletHost() { … }
void SharedStorageWorkletHost::SelectURL(
const std::string& name,
std::vector<blink::mojom::SharedStorageUrlWithMetadataPtr>
urls_with_metadata,
blink::CloneableMessage serialized_data,
bool keep_alive_after_operation,
blink::mojom::PrivateAggregationConfigPtr private_aggregation_config,
SelectURLCallback callback) { … }
void SharedStorageWorkletHost::Run(
const std::string& name,
blink::CloneableMessage serialized_data,
bool keep_alive_after_operation,
blink::mojom::PrivateAggregationConfigPtr private_aggregation_config,
RunCallback callback) { … }
bool SharedStorageWorkletHost::HasPendingOperations() { … }
void SharedStorageWorkletHost::EnterKeepAliveOnDocumentDestroyed(
KeepAliveFinishedCallback callback) { … }
void SharedStorageWorkletHost::SharedStorageSet(
const std::u16string& key,
const std::u16string& value,
bool ignore_if_present,
SharedStorageSetCallback callback) { … }
void SharedStorageWorkletHost::SharedStorageAppend(
const std::u16string& key,
const std::u16string& value,
SharedStorageAppendCallback callback) { … }
void SharedStorageWorkletHost::SharedStorageDelete(
const std::u16string& key,
SharedStorageDeleteCallback callback) { … }
void SharedStorageWorkletHost::SharedStorageClear(
SharedStorageClearCallback callback) { … }
void SharedStorageWorkletHost::SharedStorageGet(
const std::u16string& key,
SharedStorageGetCallback callback) { … }
void SharedStorageWorkletHost::SharedStorageKeys(
mojo::PendingRemote<blink::mojom::SharedStorageEntriesListener>
pending_listener) { … }
void SharedStorageWorkletHost::SharedStorageEntries(
mojo::PendingRemote<blink::mojom::SharedStorageEntriesListener>
pending_listener) { … }
void SharedStorageWorkletHost::SharedStorageLength(
SharedStorageLengthCallback callback) { … }
void SharedStorageWorkletHost::SharedStorageRemainingBudget(
SharedStorageRemainingBudgetCallback callback) { … }
void SharedStorageWorkletHost::DidAddMessageToConsole(
blink::mojom::ConsoleMessageLevel level,
const std::string& message) { … }
void SharedStorageWorkletHost::RecordUseCounters(
const std::vector<blink::mojom::WebFeature>& features) { … }
RenderProcessHost* SharedStorageWorkletHost::GetProcessHost() const { … }
RenderFrameHostImpl* SharedStorageWorkletHost::GetFrame() { … }
void SharedStorageWorkletHost::OnAddModuleOnWorkletFinished(
blink::mojom::SharedStorageDocumentService::CreateWorkletCallback callback,
bool success,
const std::string& error_message) { … }
void SharedStorageWorkletHost::OnRunOperationOnWorkletFinished(
base::TimeTicks start_time,
bool success,
const std::string& error_message) { … }
void SharedStorageWorkletHost::
OnRunURLSelectionOperationOnWorkletScriptExecutionFinished(
const GURL& urn_uuid,
base::TimeTicks start_time,
bool success,
const std::string& error_message,
uint32_t index) { … }
void SharedStorageWorkletHost::OnRunURLSelectionOperationOnWorkletFinished(
const GURL& urn_uuid,
base::TimeTicks start_time,
bool script_execution_succeeded,
const std::string& script_execution_error_message,
uint32_t index,
BudgetResult budget_result) { … }
void SharedStorageWorkletHost::ExpireWorklet() { … }
bool SharedStorageWorkletHost::IsInKeepAlivePhase() const { … }
void SharedStorageWorkletHost::FinishKeepAlive(bool timeout_reached) { … }
void SharedStorageWorkletHost::IncrementPendingOperationsCount() { … }
void SharedStorageWorkletHost::DecrementPendingOperationsCount() { … }
base::TimeDelta SharedStorageWorkletHost::GetKeepAliveTimeout() const { … }
blink::mojom::SharedStorageWorkletService*
SharedStorageWorkletHost::GetAndConnectToSharedStorageWorkletService() { … }
blink::mojom::PrivateAggregationOperationDetailsPtr
SharedStorageWorkletHost::MaybeConstructPrivateAggregationOperationDetails(
const blink::mojom::PrivateAggregationConfigPtr&
private_aggregation_config) { … }
bool SharedStorageWorkletHost::IsSharedStorageAllowed(
std::string* out_debug_message,
bool* out_block_is_site_setting_specific) { … }
bool SharedStorageWorkletHost::IsSharedStorageSelectURLAllowed(
std::string* out_debug_message,
bool* out_block_is_site_setting_specific) { … }
}