#include "content/services/auction_worklet/private_aggregation_bindings.h"
#include <stdint.h>
#include <cmath>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/auction_v8_logger.h"
#include "content/services/auction_worklet/public/cpp/private_aggregation_reporting.h"
#include "content/services/auction_worklet/public/mojom/private_aggregation_request.mojom.h"
#include "content/services/auction_worklet/webidl_compat.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom.h"
#include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-exception.h"
#include "v8/include/v8-external.h"
#include "v8/include/v8-function-callback.h"
#include "v8/include/v8-function.h"
#include "v8/include/v8-isolate.h"
#include "v8/include/v8-local-handle.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
namespace auction_worklet {
namespace {
struct PASignalValue { … };
bool ConvertToPASignalValue(AuctionV8Helper* v8_helper,
AuctionV8Helper::TimeLimitScope& time_limit_scope,
std::string error_prefix,
v8::Local<v8::Value> value,
DictConverter& report_errors_to,
PASignalValue& out) { … }
template <typename T>
bool ConvertToPASignalValueOr(AuctionV8Helper* v8_helper,
AuctionV8Helper::TimeLimitScope& time_limit_scope,
std::string error_prefix,
std::string_view field_name,
v8::Local<v8::Value> value,
DictConverter& report_errors_to,
absl::variant<PASignalValue, T>& out) { … }
std::optional<auction_worklet::mojom::BaseValue> BaseValueStringToEnum(
const std::string& base_value) { … }
std::optional<absl::uint128> ConvertBigIntToUint128(
v8::Local<v8::BigInt> bigint,
std::string* error) { … }
std::optional<auction_worklet::mojom::BucketOffsetPtr>
ConvertBigIntToBucketOffset(v8::Local<v8::BigInt> bigint, std::string* error) { … }
std::optional<auction_worklet::mojom::SignalBucketPtr> GetSignalBucket(
v8::Isolate* isolate,
const PASignalValue& input,
std::string* error) { … }
std::optional<auction_worklet::mojom::SignalValuePtr> GetSignalValue(
v8::Isolate* isolate,
const PASignalValue& input,
std::string* error) { … }
auction_worklet::mojom::ForEventSignalBucketPtr GetBucket(
v8::Isolate* isolate,
const absl::variant<PASignalValue, v8::Local<v8::BigInt>>& idl_bucket,
std::string* error) { … }
auction_worklet::mojom::ForEventSignalValuePtr GetValue(
v8::Isolate* isolate,
const absl::variant<PASignalValue, int32_t>& idl_value,
std::string* error) { … }
bool GetFilteringId(v8::Isolate* isolate,
std::optional<v8::Local<v8::BigInt>> idl_filtering_id,
std::optional<uint64_t>* out_filtering_id,
std::string* error) { … }
auction_worklet::mojom::AggregatableReportForEventContributionPtr
ParseForEventContribution(
v8::Isolate* isolate,
auction_worklet::mojom::EventTypePtr event_type,
absl::variant<PASignalValue, v8::Local<v8::BigInt>> idl_bucket,
absl::variant<PASignalValue, int32_t> idl_value,
std::optional<v8::Local<v8::BigInt>> idl_filtering_id,
std::string* error) { … }
std::optional<uint64_t> ParseDebugKey(v8::Local<v8::BigInt> js_debug_key,
std::string* error) { … }
}
PrivateAggregationBindings::PrivateAggregationBindings(
AuctionV8Helper* v8_helper,
AuctionV8Logger* v8_logger,
bool private_aggregation_permissions_policy_allowed)
: … { … }
PrivateAggregationBindings::~PrivateAggregationBindings() = default;
void PrivateAggregationBindings::AttachToContext(
v8::Local<v8::Context> context) { … }
void PrivateAggregationBindings::Reset() { … }
std::vector<auction_worklet::mojom::PrivateAggregationRequestPtr>
PrivateAggregationBindings::TakePrivateAggregationRequests() { … }
void PrivateAggregationBindings::ContributeToHistogram(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void PrivateAggregationBindings::ContributeToHistogramOnEvent(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void PrivateAggregationBindings::EnableDebugMode(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
}