#include "content/browser/fenced_frame/fenced_frame_reporter.h"
#include <iterator>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/atomic_sequence_num.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/types/pass_key.h"
#include "content/browser/attribution_reporting/attribution_beacon_id.h"
#include "content/browser/attribution_reporting/attribution_data_host_manager.h"
#include "content/browser/attribution_reporting/attribution_host.h"
#include "content/browser/attribution_reporting/attribution_manager.h"
#include "content/browser/attribution_reporting/attribution_suitable_context.h"
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/devtools/network_service_devtools_observer.h"
#include "content/browser/devtools/protocol/network_handler.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h"
#include "content/browser/fenced_frame/fenced_frame_config.h"
#include "content/browser/interest_group/interest_group_pa_report_util.h"
#include "content/browser/private_aggregation/private_aggregation_budget_key.h"
#include "content/browser/private_aggregation/private_aggregation_manager.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
#include "content/services/auction_worklet/public/mojom/private_aggregation_request.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/http/http_response_headers.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/redirect_info.h"
#include "services/network/public/cpp/attribution_utils.h"
#include "services/network/public/cpp/devtools_observer_util.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/attribution.mojom.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/fenced_frame/fenced_frame_utils.h"
#include "third_party/blink/public/common/fenced_frame/redacted_fenced_frame_config.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-shared.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"
namespace content {
namespace {
constexpr net::NetworkTrafficAnnotationTag kReportingBeaconNetworkTag = …;
std::string_view ReportingDestinationAsString(
const blink::FencedFrame::ReportingDestination& destination) { … }
std::string_view InvokingAPIAsString(
const PrivacySandboxInvokingAPI invoking_api) { … }
std::string AutomaticBeaconTypeAsString(
const blink::mojom::AutomaticBeaconType type) { … }
blink::FencedFrameBeaconReportingResult CreateBeaconReportingResultEnum(
const FencedFrameReporter::DestinationVariant& event_variant,
std::optional<int> http_response_code) { … }
void RecordBeaconReportingResultHistogram(
const FencedFrameReporter::DestinationVariant& event_variant,
net::HttpResponseHeaders* headers) { … }
}
FencedFrameReporter::PendingEvent::PendingEvent(
const DestinationVariant& event,
const url::Origin& request_initiator,
std::optional<AttributionReportingData> attribution_reporting_data,
int initiator_frame_tree_node_id)
: … { … }
FencedFrameReporter::PendingEvent::PendingEvent(const PendingEvent&) = default;
FencedFrameReporter::PendingEvent::PendingEvent(PendingEvent&&) = default;
FencedFrameReporter::PendingEvent& FencedFrameReporter::PendingEvent::operator=(
const PendingEvent&) = default;
FencedFrameReporter::PendingEvent& FencedFrameReporter::PendingEvent::operator=(
PendingEvent&&) = default;
FencedFrameReporter::PendingEvent::~PendingEvent() = default;
FencedFrameReporter::ReportingDestinationInfo::ReportingDestinationInfo(
std::optional<url::Origin> reporting_url_declarer_origin,
std::optional<ReportingUrlMap> reporting_url_map)
: … { … }
FencedFrameReporter::ReportingDestinationInfo::ReportingDestinationInfo(
ReportingDestinationInfo&&) = default;
FencedFrameReporter::ReportingDestinationInfo::~ReportingDestinationInfo() =
default;
FencedFrameReporter::ReportingDestinationInfo&
FencedFrameReporter::ReportingDestinationInfo::operator=(
ReportingDestinationInfo&&) = default;
scoped_refptr<FencedFrameReporter> FencedFrameReporter::CreateForSharedStorage(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
BrowserContext* browser_context,
const std::optional<url::Origin>& reporting_url_declarer_origin,
ReportingUrlMap reporting_url_map,
const url::Origin& main_frame_origin) { … }
scoped_refptr<FencedFrameReporter> FencedFrameReporter::CreateForFledge(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
BrowserContext* browser_context,
bool direct_seller_is_seller,
PrivateAggregationManager* private_aggregation_manager,
const url::Origin& main_frame_origin,
const url::Origin& winner_origin,
const std::optional<url::Origin>& aggregation_coordinator_origin,
const std::optional<std::vector<url::Origin>>& allowed_reporting_origins) { … }
FencedFrameReporter::FencedFrameReporter(
base::PassKey<FencedFrameReporter> pass_key,
PrivacySandboxInvokingAPI invoking_api,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
BrowserContext* browser_context,
const url::Origin& main_frame_origin,
PrivateAggregationManager* private_aggregation_manager,
const std::optional<url::Origin>& winner_origin,
const std::optional<url::Origin>& winner_aggregation_coordinator_origin,
const std::optional<std::vector<url::Origin>>& allowed_reporting_origins)
: … { … }
FencedFrameReporter::~FencedFrameReporter() { … }
void FencedFrameReporter::OnUrlMappingReady(
blink::FencedFrame::ReportingDestination reporting_destination,
const std::optional<url::Origin>& reporting_url_declarer_origin,
ReportingUrlMap reporting_url_map,
std::optional<ReportingMacros> reporting_ad_macros) { … }
bool FencedFrameReporter::SendReport(
const DestinationVariant& event_variant,
blink::FencedFrame::ReportingDestination reporting_destination,
RenderFrameHostImpl* request_initiator_frame,
std::string& error_message,
blink::mojom::ConsoleMessageLevel& console_message_level,
int initiator_frame_tree_node_id,
std::optional<int64_t> navigation_id,
std::optional<url::Origin> ad_root_origin) { … }
bool FencedFrameReporter::SendReportInternal(
const ReportingDestinationInfo& reporting_destination_info,
const DestinationVariant& event_variant,
blink::FencedFrame::ReportingDestination reporting_destination,
const url::Origin& request_initiator,
const std::optional<AttributionReportingData>& attribution_reporting_data,
int initiator_frame_tree_node_id,
std::string& error_message,
blink::mojom::ConsoleMessageLevel& console_message_level,
const std::string& devtools_request_id) { … }
void FencedFrameReporter::AddObserverForTesting(ObserverForTesting* observer) { … }
void FencedFrameReporter::RemoveObserverForTesting(
const ObserverForTesting* observer) { … }
void FencedFrameReporter::OnForEventPrivateAggregationRequestsReceived(
std::map<std::string, PrivateAggregationRequests>
private_aggregation_event_map) { … }
void FencedFrameReporter::SendPrivateAggregationRequestsForEvent(
const std::string& pa_event_type) { … }
void FencedFrameReporter::SendPrivateAggregationRequestsForEventInternal(
const std::string& pa_event_type) { … }
const std::vector<blink::FencedFrame::ReportingDestination>
FencedFrameReporter::ReportingDestinations() { … }
base::flat_map<blink::FencedFrame::ReportingDestination, url::Origin>
FencedFrameReporter::GetReportingUrlDeclarerOriginsForTesting() { … }
base::flat_map<blink::FencedFrame::ReportingDestination,
FencedFrameReporter::ReportingUrlMap>
FencedFrameReporter::GetAdBeaconMapForTesting() { … }
base::flat_map<blink::FencedFrame::ReportingDestination,
FencedFrameReporter::ReportingMacros>
FencedFrameReporter::GetAdMacrosForTesting() { … }
std::set<std::string> FencedFrameReporter::GetReceivedPaEventsForTesting()
const { … }
std::map<std::string, FencedFrameReporter::PrivateAggregationRequests>
FencedFrameReporter::GetPrivateAggregationEventMapForTesting() { … }
void FencedFrameReporter::NotifyFencedFrameReportingBeaconFailed(
const std::optional<AttributionReportingData>& attribution_reporting_data) { … }
void FencedFrameReporter::NotifyIsBeaconQueued(
const DestinationVariant& event_variant,
bool is_queued) { … }
}