#include "third_party/blink/renderer/core/timing/window_performance.h"
#include <algorithm>
#include <optional>
#include <string>
#include "base/feature_list.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/frame_timing_details.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/mojom/load_timing_info.mojom-blink.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_high_res_time_stamp.h"
#include "third_party/blink/renderer/core/dom/qualified_name.h"
#include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/core/events/input_event.h"
#include "third_party/blink/renderer/core/events/keyboard_event.h"
#include "third_party/blink/renderer/core/events/pointer_event.h"
#include "third_party/blink/renderer/core/frame/dom_window.h"
#include "third_party/blink/renderer/core/frame/frame.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/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/html_image_element.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/lcp_critical_path_predictor/lcp_critical_path_predictor.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/interactive_detector.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/page_hidden_state.h"
#include "third_party/blink/renderer/core/performance_entry_names.h"
#include "third_party/blink/renderer/core/timing/animation_frame_timing_info.h"
#include "third_party/blink/renderer/core/timing/largest_contentful_paint.h"
#include "third_party/blink/renderer/core/timing/layout_shift.h"
#include "third_party/blink/renderer/core/timing/performance_element_timing.h"
#include "third_party/blink/renderer/core/timing/performance_entry.h"
#include "third_party/blink/renderer/core/timing/performance_event_timing.h"
#include "third_party/blink/renderer/core/timing/performance_long_animation_frame_timing.h"
#include "third_party/blink/renderer/core/timing/performance_observer.h"
#include "third_party/blink/renderer/core/timing/performance_timing.h"
#include "third_party/blink/renderer/core/timing/performance_timing_for_reporting.h"
#include "third_party/blink/renderer/core/timing/responsiveness_metrics.h"
#include "third_party/blink/renderer/core/timing/soft_navigation_entry.h"
#include "third_party/blink/renderer/core/timing/visibility_state_entry.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_deque.h"
#include "third_party/blink/renderer/platform/heap/forward.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/wtf_size_t.h"
static constexpr base::TimeDelta kLongTaskObserverThreshold = …;
namespace blink {
namespace {
AtomicString GetFrameAttribute(HTMLFrameOwnerElement* frame_owner,
const QualifiedName& attr_name) { … }
AtomicString GetFrameOwnerType(HTMLFrameOwnerElement* frame_owner) { … }
AtomicString GetFrameSrc(HTMLFrameOwnerElement* frame_owner) { … }
const AtomicString& SelfKeyword() { … }
const AtomicString& SameOriginAncestorKeyword() { … }
const AtomicString& SameOriginDescendantKeyword() { … }
const AtomicString& SameOriginKeyword() { … }
AtomicString SameOriginAttribution(Frame* observer_frame,
Frame* culprit_frame) { … }
bool IsEventTypeForInteractionId(const AtomicString& type) { … }
}
constexpr size_t kDefaultVisibilityStateEntrySize = …;
static base::TimeTicks ToTimeOrigin(LocalDOMWindow* window) { … }
WindowPerformance::WindowPerformance(LocalDOMWindow* window)
: … { … }
WindowPerformance::~WindowPerformance() = default;
ExecutionContext* WindowPerformance::GetExecutionContext() const { … }
PerformanceTiming* WindowPerformance::timing() const { … }
PerformanceTimingForReporting* WindowPerformance::timingForReporting() const { … }
PerformanceNavigation* WindowPerformance::navigation() const { … }
MemoryInfo* WindowPerformance::memory(ScriptState* script_state) const { … }
namespace {
BASE_FEATURE(…);
enum class AdjustNavigationalPrefetchTimingBehavior { … };
constexpr base::FeatureParam<AdjustNavigationalPrefetchTimingBehavior>::Option
kAdjustNavigationalPrefetchTimingBehaviorOptions[] = …;
constexpr base::FeatureParam<AdjustNavigationalPrefetchTimingBehavior>
kAdjustNavigationalPrefetchTimingBehavior{ … };
network::mojom::blink::LoadTimingInfoPtr
AdjustLoadTimingForNavigationalPrefetch(
const DocumentLoadTiming& document_load_timing,
network::mojom::blink::LoadTimingInfoPtr timing) { … }
}
void WindowPerformance::CreateNavigationTimingInstance(
mojom::blink::ResourceTimingInfoPtr info) { … }
void WindowPerformance::OnBodyLoadFinished(int64_t encoded_body_size,
int64_t decoded_body_size) { … }
void WindowPerformance::BuildJSONValue(V8ObjectBuilder& builder) const { … }
void WindowPerformance::Trace(Visitor* visitor) const { … }
static bool CanAccessOrigin(Frame* frame1, Frame* frame2) { … }
std::pair<AtomicString, DOMWindow*> WindowPerformance::SanitizedAttribution(
ExecutionContext* task_context,
bool has_multiple_contexts,
LocalFrame* observer_frame) { … }
void WindowPerformance::ReportLongTask(base::TimeTicks start_time,
base::TimeTicks end_time,
ExecutionContext* task_context,
bool has_multiple_contexts) { … }
void WindowPerformance::RegisterEventTiming(const Event& event,
EventTarget* event_target,
base::TimeTicks start_time,
base::TimeTicks processing_start,
base::TimeTicks processing_end) { … }
void WindowPerformance::SetCommitFinishTimeStampForPendingEvents(
base::TimeTicks commit_finish_time) { … }
void WindowPerformance::OnPresentationPromiseResolved(
uint64_t presentation_index,
const viz::FrameTimingDetails& presentation_details) { … }
void WindowPerformance::FlushEventTimingsOnPageHidden() { … }
void WindowPerformance::ReportAllPendingEventTimingsOnPageHidden() { … }
void WindowPerformance::ReportEventTimings() { … }
void WindowPerformance::ReportEvent(
InteractiveDetector* interactive_detector,
Member<PerformanceEventTiming> event_timing_entry,
base::TimeTicks presentation_timestamp) { … }
void WindowPerformance::NotifyAndAddEventTimingBuffer(
PerformanceEventTiming* entry) { … }
void WindowPerformance::SetFallbackTime(PerformanceEventTiming* entry) { … }
bool WindowPerformance::SetInteractionIdAndRecordLatency(
PerformanceEventTiming* entry,
ResponsivenessMetrics::EventTimestamps event_timestamps) { … }
void WindowPerformance::ReportLongAnimationFrameTiming(
AnimationFrameTimingInfo* info) { … }
void WindowPerformance::AddElementTiming(const AtomicString& name,
const String& url,
const gfx::RectF& rect,
base::TimeTicks start_time,
base::TimeTicks load_time,
const AtomicString& identifier,
const gfx::Size& intrinsic_size,
const AtomicString& id,
Element* element) { … }
void WindowPerformance::DispatchFirstInputTiming(
PerformanceEventTiming* entry) { … }
void WindowPerformance::AddLayoutShiftEntry(LayoutShift* entry) { … }
void WindowPerformance::AddVisibilityStateEntry(bool is_visible,
base::TimeTicks timestamp) { … }
void WindowPerformance::AddSoftNavigationEntry(const AtomicString& name,
base::TimeTicks timestamp) { … }
void WindowPerformance::PageVisibilityChanged() { … }
void WindowPerformance::PageVisibilityChangedWithTimestamp(
base::TimeTicks visibility_change_timestamp) { … }
void WindowPerformance::WillShowModalDialog() { … }
EventCounts* WindowPerformance::eventCounts() { … }
uint64_t WindowPerformance::interactionCount() const { … }
void WindowPerformance::OnLargestContentfulPaintUpdated(
base::TimeTicks start_time,
base::TimeTicks render_time,
uint64_t paint_size,
base::TimeTicks load_time,
base::TimeTicks first_animated_frame_time,
const AtomicString& id,
const String& url,
Element* element,
bool is_triggered_by_soft_navigation) { … }
void WindowPerformance::OnPaintFinished() { … }
void WindowPerformance::NotifyPotentialDrag(PointerId pointer_id) { … }
}