#include "third_party/blink/renderer/core/frame/attribution_src_loader.h"
#include <stdint.h>
#include <optional>
#include <utility>
#include "base/check.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/overloaded.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/types/expected.h"
#include "base/unguessable_token.h"
#include "components/attribution_reporting/data_host.mojom-blink.h"
#include "components/attribution_reporting/eligibility.h"
#include "components/attribution_reporting/os_registration.h"
#include "components/attribution_reporting/os_registration_error.mojom-shared.h"
#include "components/attribution_reporting/registrar.h"
#include "components/attribution_reporting/registrar_info.h"
#include "components/attribution_reporting/registration_eligibility.mojom-shared.h"
#include "components/attribution_reporting/registration_header_error.h"
#include "components/attribution_reporting/registration_info.h"
#include "components/attribution_reporting/source_registration.h"
#include "components/attribution_reporting/source_registration_error.mojom-shared.h"
#include "components/attribution_reporting/source_type.mojom-shared.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/trigger_registration.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-shared.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/shared_remote.h"
#include "services/network/public/cpp/attribution_utils.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/attribution.mojom-forward.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/navigation/impression.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/conversions/conversions.mojom-blink.h"
#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom-blink.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_vector.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/space_split_string.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/html/html_anchor_element.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/inspector_audits_issue.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/heap/self_keep_alive.h"
#include "third_party/blink/renderer/platform/loader/cors/cors.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_utils.h"
#include "third_party/blink/renderer/platform/loader/fetch/raw_resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_error.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_response.h"
#include "third_party/blink/renderer/platform/network/encoded_form_data.h"
#include "third_party/blink/renderer/platform/network/http_names.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
namespace {
IssueType;
RegistrationEligibility;
SourceType;
AttributionReportingEligibility;
AttributionReportingIssueType;
enum class AttributionSrcRequestStatus { … };
void RecordAttributionSrcRequestStatus(AttributionSrcRequestStatus status) { … }
void LogAuditIssue(ExecutionContext* execution_context,
AttributionReportingIssueType issue_type,
HTMLElement* element,
std::optional<uint64_t> request_id,
const String& invalid_parameter) { … }
base::expected<attribution_reporting::RegistrationInfo,
attribution_reporting::RegistrationInfoError>
GetRegistrationInfo(const HTTPHeaderMap& map,
ExecutionContext* execution_context,
uint64_t request_id,
bool cross_app_web_enabled) { … }
template <typename Container>
Vector<KURL> ParseAttributionSrcUrls(AttributionSrcLoader& loader,
LocalDOMWindow* window,
const Container& strings,
HTMLElement* element) { … }
bool KeepaliveResponsesHandledInBrowser() { … }
bool ResponseHandledInBrowser(const ResourceRequestHead& request,
const ResourceResponse& response) { … }
}
struct AttributionSrcLoader::AttributionHeaders { … };
class AttributionSrcLoader::ResourceClient
: public GarbageCollected<AttributionSrcLoader::ResourceClient>,
public RawResourceClient { … };
AttributionSrcLoader::AttributionSrcLoader(LocalFrame* frame)
: … { … }
AttributionSrcLoader::~AttributionSrcLoader() = default;
void AttributionSrcLoader::Trace(Visitor* visitor) const { … }
void AttributionSrcLoader::RecordAttributionFeatureAllowed(bool enabled) { … }
Vector<KURL> AttributionSrcLoader::ParseAttributionSrc(
const AtomicString& attribution_src,
HTMLElement* element) { … }
void AttributionSrcLoader::Register(
const AtomicString& attribution_src,
HTMLElement* element,
network::mojom::ReferrerPolicy referrer_policy) { … }
std::optional<Impression> AttributionSrcLoader::RegisterNavigationInternal(
const KURL& navigation_url,
Vector<KURL> attribution_src_urls,
HTMLAnchorElement* element,
bool has_transient_user_activation,
network::mojom::ReferrerPolicy referrer_policy) { … }
std::optional<Impression> AttributionSrcLoader::RegisterNavigation(
const KURL& navigation_url,
const AtomicString& attribution_src,
HTMLAnchorElement* element,
bool has_transient_user_activation,
network::mojom::ReferrerPolicy referrer_policy) { … }
std::optional<Impression> AttributionSrcLoader::RegisterNavigation(
const KURL& navigation_url,
const WebVector<WebString>& attribution_srcs,
bool has_transient_user_activation,
network::mojom::ReferrerPolicy referrer_policy) { … }
bool AttributionSrcLoader::CreateAndSendRequests(
Vector<KURL> urls,
std::optional<AttributionSrcToken> attribution_src_token,
network::mojom::ReferrerPolicy referrer_policy) { … }
bool AttributionSrcLoader::DoRegistration(
const Vector<KURL>& urls,
const std::optional<AttributionSrcToken> attribution_src_token,
network::mojom::ReferrerPolicy referrer_policy) { … }
std::optional<attribution_reporting::SuitableOrigin>
AttributionSrcLoader::ReportingOriginForUrlIfValid(
const KURL& url,
HTMLElement* element,
std::optional<uint64_t> request_id,
bool log_issues) { … }
bool AttributionSrcLoader::CanRegister(const KURL& url,
HTMLElement* element,
std::optional<uint64_t> request_id,
bool log_issues) { … }
network::mojom::AttributionSupport AttributionSrcLoader::GetSupport() const { … }
bool AttributionSrcLoader::MaybeRegisterAttributionHeaders(
const ResourceRequest& request,
const ResourceResponse& response) { … }
void AttributionSrcLoader::RegisterAttributionHeaders(
RegistrationEligibility registration_eligibility,
network::mojom::AttributionSupport support,
attribution_reporting::SuitableOrigin reporting_origin,
const AttributionHeaders& headers,
const attribution_reporting::RegistrationInfo& registration_info,
bool was_fetched_via_service_worker) { … }
String AttributionSrcLoader::ResourceClient::DebugName() const { … }
void AttributionSrcLoader::ResourceClient::ResponseReceived(
Resource* resource,
const ResourceResponse& response) { … }
bool AttributionSrcLoader::ResourceClient::RedirectReceived(
Resource* resource,
const ResourceRequest& request,
const ResourceResponse& response) { … }
void AttributionSrcLoader::ResourceClient::NotifyFinished(Resource* resource) { … }
void AttributionSrcLoader::ResourceClient::Finish() { … }
void AttributionSrcLoader::ResourceClient::HandleResponseHeaders(
Resource* resource,
const ResourceResponse& response,
uint64_t request_id) { … }
void AttributionSrcLoader::ResourceClient::HandleResponseHeaders(
attribution_reporting::SuitableOrigin reporting_origin,
const AttributionHeaders& headers,
const attribution_reporting::RegistrationInfo& registration_info,
bool was_fetched_via_service_worker) { … }
void AttributionSrcLoader::ResourceClient::HandleSourceRegistration(
const AttributionHeaders& headers,
attribution_reporting::SuitableOrigin reporting_origin,
const attribution_reporting::RegistrationInfo& registration_info,
bool was_fetched_via_service_worker) { … }
void AttributionSrcLoader::ResourceClient::HandleTriggerRegistration(
const AttributionHeaders& headers,
attribution_reporting::SuitableOrigin reporting_origin,
const attribution_reporting::RegistrationInfo& registration_info,
bool was_fetched_via_service_worker) { … }
void AttributionSrcLoader::ResourceClient::
LogAuditIssueAndMaybeReportHeaderError(
const AttributionHeaders& headers,
bool report_header_errors,
attribution_reporting::RegistrationHeaderErrorDetails error_details,
attribution_reporting::SuitableOrigin reporting_origin) { … }
}