#include "content/browser/interest_group/auction_worklet_manager.h"
#include <stdint.h>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/hash/hash.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/not_fatal_until.h"
#include "base/strings/strcat.h"
#include "content/browser/interest_group/auction_metrics_recorder.h"
#include "content/browser/interest_group/auction_process_manager.h"
#include "content/browser/interest_group/auction_shared_storage_host.h"
#include "content/browser/interest_group/auction_url_loader_factory_proxy.h"
#include "content/browser/interest_group/debuggable_auction_worklet.h"
#include "content/browser/interest_group/subresource_url_authorizations.h"
#include "content/browser/interest_group/subresource_url_builder.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/common/content_export.h"
#include "content/services/auction_worklet/public/mojom/auction_network_events_handler.mojom-forward.h"
#include "content/services/auction_worklet/public/mojom/auction_shared_storage_host.mojom.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "content/services/auction_worklet/public/mojom/seller_worklet.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/mojom/client_security_state.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
BASE_FEATURE(…);
HandleKey;
auction_worklet::mojom::AuctionWorkletPermissionsPolicyStatePtr
GetAuctionWorkletPermissionsPolicyState(RenderFrameHostImpl* auction_runner_rfh,
const GURL& worklet_script_url) { … }
}
const size_t AuctionWorkletManager::kBatchSize;
int AuctionWorkletManager::GetFrameTreeNodeID() { … }
class AuctionWorkletManager::WorkletOwner
: public base::RefCounted<AuctionWorkletManager::WorkletOwner> { … };
AuctionWorkletManager::WorkletOwner::WorkletOwner(
AuctionWorkletManager* worklet_manager,
WorkletKey worklet_info,
size_t number_of_bidder_threads)
: … { … }
void AuctionWorkletManager::WorkletOwner::RegisterHandle(HandleKey handle) { … }
void AuctionWorkletManager::WorkletOwner::UnregisterHandle(HandleKey handle) { … }
std::vector<std::string>
AuctionWorkletManager::WorkletOwner::ComputeDevtoolsAuctionIds() { … }
void AuctionWorkletManager::WorkletOwner::NotifyAuctionMetricsRecorderWhenReady(
AuctionMetricsRecorder* auction_metrics_recorder) { … }
AuctionWorkletManager::WorkletOwner::~WorkletOwner() { … }
void AuctionWorkletManager::WorkletOwner::MaybeQueueNotifications() { … }
void AuctionWorkletManager::WorkletOwner::DispatchSomeNotifications() { … }
void AuctionWorkletManager::WorkletOwner::DispatchSomeFailureNotifications() { … }
void AuctionWorkletManager::WorkletOwner::DispatchSomeSuccessNotifications() { … }
void AuctionWorkletManager::WorkletOwner::WorkletNoLongerUsable() { … }
void AuctionWorkletManager::WorkletOwner::OnProcessAssigned(
size_t number_of_bidder_threads) { … }
void AuctionWorkletManager::WorkletOwner::OnThreadReady(
base::ProcessId unused_pid) { … }
void AuctionWorkletManager::WorkletOwner::OnWorkletDisconnected(
uint32_t ,
const std::string& description) { … }
std::vector<std::string>
AuctionWorkletManager::WorkletOwner::GetDevtoolsAuctionIds(
base::WeakPtr<WorkletOwner> self) { … }
AuctionWorkletManager::WorkletKey::WorkletKey(
WorkletType type,
const GURL& script_url,
const std::optional<GURL>& wasm_url,
const std::optional<GURL>& signals_url,
bool needs_cors_for_additional_bid,
std::optional<uint16_t> experiment_group_id,
const std::string& trusted_bidding_signals_slot_size_param,
const std::optional<url::Origin>& trusted_signals_coordinator)
: … { … }
AuctionWorkletManager::WorkletKey::WorkletKey(const WorkletKey&) = default;
AuctionWorkletManager::WorkletKey::WorkletKey(WorkletKey&&) = default;
AuctionWorkletManager::WorkletKey::~WorkletKey() = default;
namespace {
size_t CombineHash(size_t hash, size_t new_value) { … }
}
size_t AuctionWorkletManager::WorkletKey::GetHash() const { … }
bool AuctionWorkletManager::WorkletKey::WorkletKey::operator<(
const WorkletKey& other) const { … }
AuctionWorkletManager::WorkletHandle::~WorkletHandle() { … }
auction_worklet::mojom::BidderWorklet*
AuctionWorkletManager::WorkletHandle::GetBidderWorklet() { … }
auction_worklet::mojom::SellerWorklet*
AuctionWorkletManager::WorkletHandle::GetSellerWorklet() { … }
const SubresourceUrlAuthorizations& AuctionWorkletManager::WorkletHandle::
GetSubresourceUrlAuthorizationsForTesting() { … }
std::vector<std::string>
AuctionWorkletManager::WorkletHandle::GetDevtoolsAuctionIdsForTesting() { … }
AuctionWorkletManager::WorkletHandle::WorkletHandle(
std::string devtools_auction_id,
scoped_refptr<WorkletOwner> worklet_owner,
base::OnceClosure worklet_available_callback,
FatalErrorCallback fatal_error_callback)
: … { … }
void AuctionWorkletManager::WorkletHandle::OnWorkletAvailable() { … }
void AuctionWorkletManager::WorkletHandle::OnFatalError(
FatalErrorType type,
const std::vector<std::string>& errors) { … }
void AuctionWorkletManager::WorkletHandle::AuthorizeSubresourceUrls(
const SubresourceUrlBuilder& subresource_url_builder) { … }
bool AuctionWorkletManager::WorkletHandle::worklet_created() const { … }
AuctionWorkletManager::AuctionWorkletManager(
AuctionProcessManager* auction_process_manager,
url::Origin top_window_origin,
url::Origin frame_origin,
Delegate* delegate)
: … { … }
AuctionWorkletManager::~AuctionWorkletManager() = default;
AuctionWorkletManager::WorkletKey AuctionWorkletManager::BidderWorkletKey(
const GURL& bidding_logic_url,
const std::optional<GURL>& wasm_url,
const std::optional<GURL>& trusted_bidding_signals_url,
bool needs_cors_for_additional_bid,
std::optional<uint16_t> experiment_group_id,
const std::string& trusted_bidding_signals_slot_size_param,
const std::optional<url::Origin>& trusted_bidding_signals_coordinator) { … }
void AuctionWorkletManager::RequestBidderWorklet(
std::string devtools_auction_id,
const GURL& bidding_logic_url,
const std::optional<GURL>& wasm_url,
const std::optional<GURL>& trusted_bidding_signals_url,
bool needs_cors_for_additional_bid,
std::optional<uint16_t> experiment_group_id,
const std::string& trusted_bidding_signals_slot_size_param,
const std::optional<url::Origin>& trusted_bidding_signals_coordinator,
base::OnceClosure worklet_available_callback,
FatalErrorCallback fatal_error_callback,
std::unique_ptr<WorkletHandle>& out_worklet_handle,
AuctionMetricsRecorder* auction_metrics_recorder) { … }
void AuctionWorkletManager::RequestSellerWorklet(
std::string devtools_auction_id,
const GURL& decision_logic_url,
const std::optional<GURL>& trusted_scoring_signals_url,
std::optional<uint16_t> experiment_group_id,
base::OnceClosure worklet_available_callback,
FatalErrorCallback fatal_error_callback,
std::unique_ptr<WorkletHandle>& out_worklet_handle,
AuctionMetricsRecorder* auction_metrics_recorder) { … }
void AuctionWorkletManager::RequestWorkletByKey(
WorkletKey worklet_info,
std::string devtools_auction_id,
base::OnceClosure worklet_available_callback,
FatalErrorCallback fatal_error_callback,
std::unique_ptr<WorkletHandle>& out_worklet_handle,
size_t number_of_bidder_threads,
AuctionMetricsRecorder* auction_metrics_recorder) { … }
void AuctionWorkletManager::OnWorkletNoLongerUsable(WorkletOwner* worklet) { … }
mojo::PendingRemote<auction_worklet::mojom::AuctionSharedStorageHost>
AuctionWorkletManager::MaybeBindAuctionSharedStorageHost(
RenderFrameHostImpl* auction_runner_rfh,
const url::Origin& worklet_origin) { … }
}