chromium/components/page_load_metrics/browser/observers/ad_metrics/ads_page_load_metrics_observer.cc

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

#include "components/page_load_metrics/browser/observers/ad_metrics/ads_page_load_metrics_observer.h"

#include <algorithm>
#include <limits>
#include <string>
#include <string_view>
#include <utility>

#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/notreached.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/heavy_ad_intervention/heavy_ad_blocklist.h"
#include "components/heavy_ad_intervention/heavy_ad_features.h"
#include "components/heavy_ad_intervention/heavy_ad_helper.h"
#include "components/heavy_ad_intervention/heavy_ad_service.h"
#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
#include "components/page_load_metrics/browser/page_load_metrics_memory_tracker.h"
#include "components/page_load_metrics/browser/page_load_metrics_util.h"
#include "components/page_load_metrics/browser/resource_tracker.h"
#include "components/page_load_metrics/common/page_end_reason.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_web_contents_helper.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "components/subresource_filter/core/common/common_features.h"
#include "components/subresource_filter/core/common/load_policy.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "content/public/browser/global_request_id.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/reload_type.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "net/base/net_errors.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom-shared.h"
#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h"
#include "ui/base/page_transition_types.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"

namespace page_load_metrics {

namespace features {

// Enables or disables the restricted navigation ad tagging feature. When
// enabled, the AdTagging heuristic is modified to additional information to
// determine if a frame is an ad. If the frame's navigation url matches an allow
// list rule, it is not an ad.
//
// If a frame's navigation url does not match a blocked rule, but was created by
// ad script and is same domain to the top-level frame, it is not an ad.
//
// Currently this feature only changes AdTagging behavior for metrics recorded
// in AdsPageLoadMetricsObserver, and for triggering the Heavy Ad Intervention.
BASE_FEATURE();

}  // namespace features

namespace {

RectId;
RectType;

#define ADS_HISTOGRAM(suffix, hist_macro, visibility, value)

std::string GetHeavyAdReportMessage(const FrameTreeData& frame_data,
                                    bool will_unload_adframe) {}

const char kDisallowedByBlocklistHistogramName[] =;

void RecordHeavyAdInterventionDisallowedByBlocklist(bool disallowed) {}

ResourceMimeType;

blink::mojom::HeavyAdReason GetHeavyAdReason(HeavyAdStatus status) {}

int64_t GetExponentialBucketForDistributionMoment(double sample) {}

void RecordPageLoadInitiatorForAdTaggingUkm(
    content::NavigationHandle* navigation_handle) {}

}  // namespace

// static
std::unique_ptr<AdsPageLoadMetricsObserver>
AdsPageLoadMetricsObserver::CreateIfNeeded(
    content::WebContents* web_contents,
    heavy_ad_intervention::HeavyAdService* heavy_ad_service,
    const ApplicationLocaleGetter& application_locale_getter) {}

// static
bool AdsPageLoadMetricsObserver::IsFrameSameOriginToOutermostMainFrame(
    content::RenderFrameHost* host) {}

AdsPageLoadMetricsObserver::FrameInstance::FrameInstance()
    :{}

AdsPageLoadMetricsObserver::FrameInstance::FrameInstance(
    std::unique_ptr<FrameTreeData> frame_data)
    :{}

AdsPageLoadMetricsObserver::FrameInstance::FrameInstance(
    base::WeakPtr<FrameTreeData> frame_data)
    :{}

AdsPageLoadMetricsObserver::FrameInstance::~FrameInstance() = default;

FrameTreeData* AdsPageLoadMetricsObserver::FrameInstance::Get() {}

FrameTreeData* AdsPageLoadMetricsObserver::FrameInstance::GetOwnedFrame() {}

AdsPageLoadMetricsObserver::HeavyAdThresholdNoiseProvider::
    HeavyAdThresholdNoiseProvider(bool use_noise)
    :{}

int AdsPageLoadMetricsObserver::HeavyAdThresholdNoiseProvider::
    GetNetworkThresholdNoiseForFrame() const {}

AdsPageLoadMetricsObserver::AdsPageLoadMetricsObserver(
    heavy_ad_intervention::HeavyAdService* heavy_ad_service,
    const ApplicationLocaleGetter& application_locale_getter,
    base::TickClock* clock,
    heavy_ad_intervention::HeavyAdBlocklist* blocklist)
    :{}

AdsPageLoadMetricsObserver::~AdsPageLoadMetricsObserver() = default;

const char* AdsPageLoadMetricsObserver::GetObserverName() const {}

PageLoadMetricsObserver::ObservePolicy AdsPageLoadMetricsObserver::OnStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url,
    bool started_in_foreground) {}

PageLoadMetricsObserver::ObservePolicy
AdsPageLoadMetricsObserver::OnPrerenderStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url) {}

PageLoadMetricsObserver::ObservePolicy
AdsPageLoadMetricsObserver::OnFencedFramesStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url) {}

PageLoadMetricsObserver::ObservePolicy AdsPageLoadMetricsObserver::OnCommit(
    content::NavigationHandle* navigation_handle) {}

void AdsPageLoadMetricsObserver::OnTimingUpdate(
    content::RenderFrameHost* frame_rfh,
    const mojom::PageLoadTiming& timing) {}

void AdsPageLoadMetricsObserver::OnCpuTimingUpdate(
    content::RenderFrameHost* subframe_rfh,
    const mojom::CpuTiming& timing) {}

// Given an ad being triggered for a frame or navigation, get its FrameTreeData
// and record it into the appropriate data structures.
void AdsPageLoadMetricsObserver::UpdateAdFrameData(
    content::NavigationHandle* navigation_handle,
    bool is_adframe,
    bool should_ignore_detected_ad) {}

void AdsPageLoadMetricsObserver::ReadyToCommitNextNavigation(
    content::NavigationHandle* navigation_handle) {}

// Determine if the frame is part of an existing ad, the root of a new ad, or a
// non-ad frame. Once a frame is labeled as an ad, it is always considered an
// ad, even if it navigates to a non-ad page. This function labels all of a
// page's frames, even those that fail to commit.
void AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation(
    content::NavigationHandle* navigation_handle) {}

void AdsPageLoadMetricsObserver::FrameReceivedUserActivation(
    content::RenderFrameHost* render_frame_host) {}

PageLoadMetricsObserver::ObservePolicy
AdsPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground(
    const mojom::PageLoadTiming& timing) {}

void AdsPageLoadMetricsObserver::OnComplete(
    const mojom::PageLoadTiming& timing) {}

void AdsPageLoadMetricsObserver::OnResourceDataUseObserved(
    content::RenderFrameHost* rfh,
    const std::vector<mojom::ResourceDataUpdatePtr>& resources) {}

void AdsPageLoadMetricsObserver::FrameDisplayStateChanged(
    content::RenderFrameHost* render_frame_host,
    bool is_display_none) {}

void AdsPageLoadMetricsObserver::FrameSizeChanged(
    content::RenderFrameHost* render_frame_host,
    const gfx::Size& frame_size) {}

void AdsPageLoadMetricsObserver::MediaStartedPlaying(
    const content::WebContentsObserver::MediaPlayerInfo& video_type,
    content::RenderFrameHost* render_frame_host) {}

void AdsPageLoadMetricsObserver::OnMainFrameIntersectionRectChanged(
    content::RenderFrameHost* render_frame_host,
    const gfx::Rect& main_frame_intersection_rect) {}

void AdsPageLoadMetricsObserver::OnMainFrameViewportRectChanged(
    const gfx::Rect& main_frame_viewport_rect) {}

void AdsPageLoadMetricsObserver::OnMainFrameImageAdRectsChanged(
    const base::flat_map<int, gfx::Rect>& main_frame_image_ad_rects) {}

// TODO(crbug.com/40727873): Evaluate imposing width requirements
// for ad density violations.
void AdsPageLoadMetricsObserver::CheckForAdDensityViolation() {}

void AdsPageLoadMetricsObserver::OnSubFrameDeleted(int frame_tree_node_id) {}

void AdsPageLoadMetricsObserver::OnV8MemoryChanged(
    const std::vector<MemoryUpdate>& memory_updates) {}

void AdsPageLoadMetricsObserver::OnAdAuctionComplete(
    bool is_server_auction,
    bool is_on_device_auction,
    content::AuctionResult result) {}

void AdsPageLoadMetricsObserver::OnSubresourceFilterGoingAway() {}

void AdsPageLoadMetricsObserver::OnPageActivationComputed(
    content::NavigationHandle* navigation_handle,
    const subresource_filter::mojom::ActivationState& activation_state) {}

int AdsPageLoadMetricsObserver::GetUnaccountedAdBytes(
    int process_id,
    const mojom::ResourceDataUpdatePtr& resource) const {}

void AdsPageLoadMetricsObserver::ProcessResourceForPage(
    content::RenderFrameHost* render_frame_host,
    const mojom::ResourceDataUpdatePtr& resource) {}

void AdsPageLoadMetricsObserver::ProcessResourceForFrame(
    content::RenderFrameHost* render_frame_host,
    const mojom::ResourceDataUpdatePtr& resource) {}

void AdsPageLoadMetricsObserver::RecordPageResourceTotalHistograms(
    ukm::SourceId source_id) {}

void AdsPageLoadMetricsObserver::RecordHistograms(ukm::SourceId source_id) {}

void AdsPageLoadMetricsObserver::RecordAggregateHistogramsForCpuUsage() {}

void AdsPageLoadMetricsObserver::RecordAggregateHistogramsForAdTagging(
    FrameVisibility visibility) {}

void AdsPageLoadMetricsObserver::RecordPerFrameMetrics(
    const FrameTreeData& ad_frame_data,
    ukm::SourceId source_id) {}

void AdsPageLoadMetricsObserver::RecordPerFrameHistogramsForCpuUsage(
    const FrameTreeData& ad_frame_data) {}

void AdsPageLoadMetricsObserver::RecordPerFrameHistogramsForAdTagging(
    const FrameTreeData& ad_frame_data) {}

void AdsPageLoadMetricsObserver::RecordPerFrameHistogramsForHeavyAds(
    const FrameTreeData& ad_frame_data) {}

void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource(
    content::NavigationHandle* navigation_handle) {}

FrameTreeData* AdsPageLoadMetricsObserver::FindFrameData(FrameTreeNodeId id) {}

void AdsPageLoadMetricsObserver::MaybeTriggerStrictHeavyAdIntervention() {}

void AdsPageLoadMetricsObserver::MaybeTriggerHeavyAdIntervention(
    content::RenderFrameHost* render_frame_host,
    FrameTreeData* frame_data) {}

bool AdsPageLoadMetricsObserver::IsBlocklisted(bool report) {}

heavy_ad_intervention::HeavyAdBlocklist*
AdsPageLoadMetricsObserver::GetHeavyAdBlocklist() {}

void AdsPageLoadMetricsObserver::UpdateAggregateMemoryUsage(
    int64_t delta_bytes,
    FrameVisibility frame_visibility) {}

void AdsPageLoadMetricsObserver::CleanupDeletedFrame(
    FrameTreeNodeId id,
    FrameTreeData* frame_data,
    bool update_density_tracker,
    bool record_metrics) {}

}  // namespace page_load_metrics