chromium/content/services/auction_worklet/set_bid_bindings.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/services/auction_worklet/set_bid_bindings.h"

#include <cmath>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/bidder_worklet.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "content/services/auction_worklet/public/mojom/private_aggregation_request.mojom.h"
#include "content/services/auction_worklet/webidl_compat.h"
#include "gin/converter.h"
#include "gin/dictionary.h"
#include "third_party/blink/public/common/features_generated.h"
#include "third_party/blink/public/common/interest_group/ad_auction_constants.h"
#include "third_party/blink/public/common/interest_group/ad_auction_currencies.h"
#include "third_party/blink/public/common/interest_group/ad_display_size_utils.h"
#include "url/gurl.h"
#include "url/url_constants.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"

namespace auction_worklet {

namespace {

// Checks that `url` is a valid URL and is in `ads`. Appends an error to
// `out_errors` if not. `error_prefix` is used in output error messages
// only. Returns the associated `blink::InterestGroup::Ad` if one is found,
// or std::nullopt if not.
base::optional_ref<const blink::InterestGroup::Ad> FindAdForAssociatedAdUrl(
    const GURL& url,
    const std::string& error_prefix,
    const char* argument_name,
    const base::RepeatingCallback<bool(const std::string&)>& is_excluded,
    const std::vector<blink::InterestGroup::Ad>& ads,
    std::string& out_error) {}

struct AdRender {};

// Handles conversion of (DOMString or AdRender) IDL type.
IdlConvert::Status ConvertDomStringOrAdRender(
    AuctionV8Helper* v8_helper,
    AuctionV8Helper::TimeLimitScope& time_limit_scope,
    const std::string& error_prefix,
    v8::Local<v8::Value> value,
    AdRender& out) {}

// Parses an AdRender, either a top-level value of render: field in bid or
// as part of its components array. This is meant to run on the output
// of ConvertDomStringOrAdRender, which has already converted the string form
// into a struct matching the dictionary form, and represents the semantics
// step of the checking, which happens after all the IDL conversions take place.
//
// Return whether the parse is successful.
//
// The dictionary can be in one of two forms:
// 1. Contains only the url field:
//      {url: "https://example.test/"}
// 2. Contains the url and both width and height fields:
//      {url: "https://example.test/", width: "100sw", height: "50px"}
// Any other fields will be ignored.
//
// The size units are allowed to be specified as:
// 1. "px": pixels.
// 2. "sw": screenwidth.
//
// Note the parse is still considered successful even if the size unit ends up
// being invalid, for example:
// {url: "https://example.test/", width: "100ft", height: "50in"}
//
// This will be immediately handled by `IsValidAdSize`, so we know the reason
// for the failure in order to emit more accurate error messages.
bool TryToParseUrlWithSize(AuctionV8Helper* v8_helper,
                           AuctionV8Helper::TimeLimitScope& time_limit_scope,
                           const std::string& error_prefix,
                           const AdRender& value,
                           std::string& ad_url_out,
                           std::optional<blink::AdSize>& size_out,
                           std::string& error_out) {}

std::string RenderPrefix(const std::string& error_prefix) {}

std::string ComponentsPrefix(const std::string& error_prefix) {}

}  // namespace

SetBidBindings::BidAndWorkletOnlyMetadata::BidAndWorkletOnlyMetadata() =
    default;
SetBidBindings::BidAndWorkletOnlyMetadata::BidAndWorkletOnlyMetadata(
    BidAndWorkletOnlyMetadata&&) = default;
SetBidBindings::BidAndWorkletOnlyMetadata::~BidAndWorkletOnlyMetadata() =
    default;
SetBidBindings::BidAndWorkletOnlyMetadata&
SetBidBindings::BidAndWorkletOnlyMetadata::operator=(
    BidAndWorkletOnlyMetadata&&) = default;

std::vector<SetBidBindings::BidAndWorkletOnlyMetadata>
SetBidBindings::TakeBids() {}

// This basically corresponds to the GenerateBidOutput type in the spec,
// except the (DOMString or AdRender) unions are normalized to AdRender.
struct SetBidBindings::GenerateBidOutput {};

SetBidBindings::SetBidBindings(AuctionV8Helper* v8_helper)
    :{}

SetBidBindings::~SetBidBindings() = default;

void SetBidBindings::ReInitialize(
    base::TimeTicks start,
    bool has_top_level_seller_origin,
    const mojom::BidderWorkletNonSharedParams* bidder_worklet_non_shared_params,
    const std::optional<blink::AdCurrency>& per_buyer_currency,
    uint16_t multi_bid_limit,
    base::RepeatingCallback<bool(const std::string&)> is_ad_excluded,
    base::RepeatingCallback<bool(const std::string&)> is_component_ad_excluded,
    base::RepeatingCallback<bool(const std::string&,
                                 base::optional_ref<const std::string>,
                                 base::optional_ref<const std::string>,
                                 base::optional_ref<const std::string>)>
        is_reporting_id_set_excluded) {}

void SetBidBindings::AttachToContext(v8::Local<v8::Context> context) {}

void SetBidBindings::Reset() {}

IdlConvert::Status SetBidBindings::SetBidImpl(v8::Local<v8::Value> value,
                                              std::string error_prefix) {}

base::expected<SetBidBindings::GenerateBidOutput, IdlConvert::Status>
SetBidBindings::ConvertBidToIDL(
    AuctionV8Helper::TimeLimitScope& time_limit_scope,
    v8::Local<v8::Value> input,
    const std::string& error_prefix,
    const std::string& render_prefix,
    const std::string& components_prefix) {}

base::expected<SetBidBindings::BidAndWorkletOnlyMetadata, IdlConvert::Status>
SetBidBindings::SemanticCheckBid(
    AuctionV8Helper::TimeLimitScope& time_limit_scope,
    const GenerateBidOutput& idl,
    const std::string& error_prefix,
    const std::string& render_prefix,
    const std::string& components_prefix) {}

bool SetBidBindings::IsSelectedReportingIdValid(
    const blink::InterestGroup::Ad& ad,
    const std::string& selected_buyer_and_seller_reporting_id) {}

// static
void SetBidBindings::SetBid(const v8::FunctionCallbackInfo<v8::Value>& args) {}

}  // namespace auction_worklet