#include "content/services/auction_worklet/trusted_signals.h"
#include <cstddef>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "content/common/features.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/public/cpp/auction_downloader.h"
#include "content/services/auction_worklet/public/cpp/auction_network_events_delegate.h"
#include "gin/converter.h"
#include "gin/dictionary.h"
#include "net/base/parse_number.h"
#include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
#include "url/gurl.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-json.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
namespace auction_worklet {
namespace {
std::string CreateQueryParam(const char* name,
const std::set<std::string>& keys) { … }
GURL SetQueryParam(const GURL& base_url, const std::string& new_query_params) { … }
std::map<std::string, AuctionV8Helper::SerializedValue> ParseKeyValueMap(
AuctionV8Helper* v8_helper,
v8::Local<v8::Object> v8_object,
const std::set<std::string>& keys) { … }
std::map<std::string, AuctionV8Helper::SerializedValue> ParseChildKeyValueMap(
AuctionV8Helper* v8_helper,
v8::Local<v8::Object> v8_object,
const char* name,
const std::set<std::string>& keys) { … }
TrustedSignals::Result::PerInterestGroupDataMap ParsePerInterestGroupMap(
AuctionV8Helper* v8_helper,
v8::Local<v8::Object> v8_object,
const std::set<std::string>& interest_group_names) { … }
v8::Local<v8::Object> CreateObjectFromMap(
const std::vector<std::string>& keys,
const std::map<std::string, AuctionV8Helper::SerializedValue>&
serialized_data,
AuctionV8Helper* v8_helper,
v8::Local<v8::Context> context) { … }
}
TrustedSignals::Result::PerGroupData::PerGroupData(
std::optional<PriorityVector> priority_vector,
std::optional<base::TimeDelta> update_if_older_than)
: … { … }
TrustedSignals::Result::PerGroupData::~PerGroupData() = default;
TrustedSignals::Result::PerGroupData::PerGroupData(PerGroupData&&) = default;
TrustedSignals::Result::PerGroupData&
TrustedSignals::Result::PerGroupData::operator=(PerGroupData&&) = default;
TrustedSignals::Result::Result(
PerInterestGroupDataMap per_interest_group_data,
std::map<std::string, AuctionV8Helper::SerializedValue> bidder_data,
std::optional<uint32_t> data_version)
: … { … }
TrustedSignals::Result::Result(
std::map<std::string, AuctionV8Helper::SerializedValue> render_url_data,
std::map<std::string, AuctionV8Helper::SerializedValue> ad_component_data,
std::optional<uint32_t> data_version)
: … { … }
const TrustedSignals::Result::PerGroupData*
TrustedSignals::Result::GetPerGroupData(
const std::string& interest_group_name) const { … }
v8::Local<v8::Object> TrustedSignals::Result::GetBiddingSignals(
AuctionV8Helper* v8_helper,
v8::Local<v8::Context> context,
const std::vector<std::string>& bidding_signals_keys) const { … }
v8::Local<v8::Object> TrustedSignals::Result::GetScoringSignals(
AuctionV8Helper* v8_helper,
v8::Local<v8::Context> context,
const GURL& render_url,
const std::vector<std::string>& ad_component_render_urls) const { … }
v8::Local<v8::Value> TrustedSignals::Result::WrapCrossOriginSignals(
AuctionV8Helper* v8_helper,
v8::Local<v8::Context> context,
const url::Origin& source_origin,
v8::Local<v8::Value> signals) { … }
TrustedSignals::Result::~Result() = default;
GURL TrustedSignals::BuildTrustedBiddingSignalsURL(
const std::string& hostname,
const GURL& trusted_bidding_signals_url,
const std::set<std::string>& interest_group_names,
const std::set<std::string>& bidding_signals_keys,
std::optional<uint16_t> experiment_group_id,
const std::string& trusted_bidding_signals_slot_size_param) { … }
GURL TrustedSignals::BuildTrustedScoringSignalsURL(
const std::string& hostname,
const GURL& trusted_scoring_signals_url,
const std::set<std::string>& render_urls,
const std::set<std::string>& ad_component_render_urls,
std::optional<uint16_t> experiment_group_id) { … }
std::unique_ptr<TrustedSignals> TrustedSignals::LoadBiddingSignals(
network::mojom::URLLoaderFactory* url_loader_factory,
mojo::PendingRemote<auction_worklet::mojom::AuctionNetworkEventsHandler>
devtools_pending_remote,
std::set<std::string> interest_group_names,
std::set<std::string> bidding_signals_keys,
const std::string& hostname,
const GURL& trusted_bidding_signals_url,
std::optional<uint16_t> experiment_group_id,
const std::string& trusted_bidding_signals_slot_size_param,
scoped_refptr<AuctionV8Helper> v8_helper,
LoadSignalsCallback load_signals_callback) { … }
std::unique_ptr<TrustedSignals> TrustedSignals::LoadScoringSignals(
network::mojom::URLLoaderFactory* url_loader_factory,
mojo::PendingRemote<auction_worklet::mojom::AuctionNetworkEventsHandler>
auction_network_events_handler,
std::set<std::string> render_urls,
std::set<std::string> ad_component_render_urls,
const std::string& hostname,
const GURL& trusted_scoring_signals_url,
std::optional<uint16_t> experiment_group_id,
scoped_refptr<AuctionV8Helper> v8_helper,
LoadSignalsCallback load_signals_callback) { … }
std::optional<TrustedSignals::Result::PriorityVector>
TrustedSignals::ParsePriorityVector(
AuctionV8Helper* v8_helper,
v8::Local<v8::Object> v8_per_interest_group_data) { … }
std::optional<base::TimeDelta> TrustedSignals::ParseUpdateIfOlderThan(
AuctionV8Helper* v8_helper,
v8::Local<v8::Object> v8_per_interest_group_data) { … }
TrustedSignals::TrustedSignals(
std::optional<std::set<std::string>> interest_group_names,
std::optional<std::set<std::string>> bidding_signals_keys,
std::optional<std::set<std::string>> render_urls,
std::optional<std::set<std::string>> ad_component_render_urls,
const GURL& trusted_signals_url,
mojo::PendingRemote<auction_worklet::mojom::AuctionNetworkEventsHandler>
auction_network_events_handler,
scoped_refptr<AuctionV8Helper> v8_helper,
LoadSignalsCallback load_signals_callback)
: … { … }
TrustedSignals::~TrustedSignals() = default;
void TrustedSignals::StartDownload(
network::mojom::URLLoaderFactory* url_loader_factory,
const GURL& full_signals_url) { … }
void TrustedSignals::OnDownloadComplete(
std::unique_ptr<std::string> body,
scoped_refptr<net::HttpResponseHeaders> headers,
std::optional<std::string> error_msg) { … }
void TrustedSignals::HandleDownloadResultOnV8Thread(
scoped_refptr<AuctionV8Helper> v8_helper,
const GURL& signals_url,
std::optional<std::set<std::string>> interest_group_names,
std::optional<std::set<std::string>> bidding_signals_keys,
std::optional<std::set<std::string>> render_urls,
std::optional<std::set<std::string>> ad_component_render_urls,
std::unique_ptr<std::string> body,
scoped_refptr<net::HttpResponseHeaders> headers,
std::optional<std::string> error_msg,
scoped_refptr<base::SequencedTaskRunner> user_thread_task_runner,
base::WeakPtr<TrustedSignals> weak_instance,
base::TimeDelta download_time) { … }
void TrustedSignals::PostCallbackToUserThread(
scoped_refptr<base::SequencedTaskRunner> user_thread_task_runner,
base::WeakPtr<TrustedSignals> weak_instance,
scoped_refptr<Result> result,
std::optional<std::string> error_msg) { … }
void TrustedSignals::DeliverCallbackOnUserThread(
scoped_refptr<Result> result,
std::optional<std::string> error_msg) { … }
}