#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 {
BASE_FEATURE(…);
}
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) { … }
}
std::unique_ptr<AdsPageLoadMetricsObserver>
AdsPageLoadMetricsObserver::CreateIfNeeded(
content::WebContents* web_contents,
heavy_ad_intervention::HeavyAdService* heavy_ad_service,
const ApplicationLocaleGetter& application_locale_getter) { … }
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) { … }
void AdsPageLoadMetricsObserver::UpdateAdFrameData(
content::NavigationHandle* navigation_handle,
bool is_adframe,
bool should_ignore_detected_ad) { … }
void AdsPageLoadMetricsObserver::ReadyToCommitNextNavigation(
content::NavigationHandle* navigation_handle) { … }
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) { … }
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) { … }
}