#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/containers/contains.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_id_helper.h"
#include "base/trace_event/typed_macros.h"
#include "build/build_config.h"
#include "cc/input/snap_selection_strategy.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/storage_access_api/status.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/navigation/impression.h"
#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom-blink.h"
#include "third_party/blink/public/mojom/frame/frame.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/policy_disposition.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/scheduler/web_agent_group_scheduler.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/web_picture_in_picture_window_options.h"
#include "third_party/blink/renderer/bindings/core/v8/binding_security.h"
#include "third_party/blink/renderer/bindings/core/v8/capture_source_location.h"
#include "third_party/blink/renderer/bindings/core/v8/isolated_world_csp.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_scroll_to_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_void_function.h"
#include "third_party/blink/renderer/bindings/core/v8/window_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/window_proxy_manager.h"
#include "third_party/blink/renderer/core/accessibility/ax_context.h"
#include "third_party/blink/renderer/core/aom/computed_accessible_node.h"
#include "third_party/blink/renderer/core/css/css_computed_style_declaration.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/dom_window_css.h"
#include "third_party/blink/renderer/core/css/media_query_list.h"
#include "third_party/blink/renderer/core/css/media_query_matcher.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/css/style_media.h"
#include "third_party/blink/renderer/core/display_lock/display_lock_document_state.h"
#include "third_party/blink/renderer/core/dom/document_init.h"
#include "third_party/blink/renderer/core/dom/events/add_event_listener_options_resolved.h"
#include "third_party/blink/renderer/core/dom/events/event_dispatch_forbidden_scope.h"
#include "third_party/blink/renderer/core/dom/events/scoped_event_queue.h"
#include "third_party/blink/renderer/core/dom/frame_request_callback_collection.h"
#include "third_party/blink/renderer/core/dom/scriptable_document_parser.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/ime/input_method_controller.h"
#include "third_party/blink/renderer/core/editing/spellcheck/spell_checker.h"
#include "third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.h"
#include "third_party/blink/renderer/core/events/hash_change_event.h"
#include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/core/events/page_transition_event.h"
#include "third_party/blink/renderer/core/events/pop_state_event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/execution_context/window_agent.h"
#include "third_party/blink/renderer/core/frame/attribution_src_loader.h"
#include "third_party/blink/renderer/core/frame/bar_prop.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/document_policy_violation_report_body.h"
#include "third_party/blink/renderer/core/frame/dom_viewport.h"
#include "third_party/blink/renderer/core/frame/dom_visual_viewport.h"
#include "third_party/blink/renderer/core/frame/event_handler_registry.h"
#include "third_party/blink/renderer/core/frame/external.h"
#include "third_party/blink/renderer/core/frame/frame_console.h"
#include "third_party/blink/renderer/core/frame/history.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/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/frame/permissions_policy_violation_report_body.h"
#include "third_party/blink/renderer/core/frame/report.h"
#include "third_party/blink/renderer/core/frame/reporting_context.h"
#include "third_party/blink/renderer/core/frame/screen.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/viewport_data.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
#include "third_party/blink/renderer/core/html/custom/custom_element_registry.h"
#include "third_party/blink/renderer/core/html/fenced_frame/fence.h"
#include "third_party/blink/renderer/core/html/forms/form_controller.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/plugin_document.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/inspector_audits_issue.h"
#include "third_party/blink/renderer/core/inspector/inspector_issue_storage.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
#include "third_party/blink/renderer/core/inspector/main_thread_debugger.h"
#include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/frame_load_request.h"
#include "third_party/blink/renderer/core/navigation_api/navigation_api.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/create_window.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/scrolling/scrolling_coordinator.h"
#include "third_party/blink/renderer/core/page/scrolling/sync_scroll_attempt_heuristic.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/scheduler/scripted_idle_task_controller.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h"
#include "third_party/blink/renderer/core/scroll/scrollbar_theme.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
#include "third_party/blink/renderer/core/timing/soft_navigation_heuristics.h"
#include "third_party/blink/renderer/core/timing/window_performance.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_type_policy_factory.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_types_util.h"
#include "third_party/blink/renderer/core/view_transition/view_transition_supplement.h"
#include "third_party/blink/renderer/platform/back_forward_cache_buffer_limit_tracker.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/source_location.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/dummy_schedulers.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/task_attribution_tracker.h"
#include "third_party/blink/renderer/platform/storage/blink_storage_key.h"
#include "third_party/blink/renderer/platform/timer.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/widget/frame_widget.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/uuid.h"
#include "ui/display/screen_info.h"
#include "v8/include/v8.h"
namespace blink {
namespace {
bool IsRunningMicrotasks(ScriptState* script_state) { … }
void SetCurrentTaskAsCallbackParent(
CallbackFunctionWithTaskAttributionBase* callback) { … }
int RequestAnimationFrame(Document* document,
V8FrameRequestCallback* callback,
bool legacy) { … }
}
class LocalDOMWindow::NetworkStateObserver final
: public GarbageCollected<LocalDOMWindow::NetworkStateObserver>,
public NetworkStateNotifier::NetworkStateObserver,
public ExecutionContextLifecycleObserver { … };
LocalDOMWindow::LocalDOMWindow(LocalFrame& frame, WindowAgent* agent)
: … { … }
void LocalDOMWindow::BindContentSecurityPolicy() { … }
void LocalDOMWindow::Initialize() { … }
void LocalDOMWindow::ClearForReuse() { … }
void LocalDOMWindow::ResetWindowAgent(WindowAgent* agent) { … }
void LocalDOMWindow::AcceptLanguagesChanged() { … }
ScriptValue LocalDOMWindow::event(ScriptState* script_state) { … }
Event* LocalDOMWindow::CurrentEvent() const { … }
void LocalDOMWindow::SetCurrentEvent(Event* new_event) { … }
TrustedTypePolicyFactory* LocalDOMWindow::GetTrustedTypesForWorld(
const DOMWrapperWorld& world) const { … }
TrustedTypePolicyFactory* LocalDOMWindow::trustedTypes(
ScriptState* script_state) const { … }
bool LocalDOMWindow::IsCrossSiteSubframe() const { … }
bool LocalDOMWindow::IsCrossSiteSubframeIncludingScheme() const { … }
LocalDOMWindow* LocalDOMWindow::From(const ScriptState* script_state) { … }
mojom::blink::V8CacheOptions LocalDOMWindow::GetV8CacheOptions() const { … }
bool LocalDOMWindow::IsContextThread() const { … }
bool LocalDOMWindow::ShouldInstallV8Extensions() const { … }
ContentSecurityPolicy* LocalDOMWindow::GetContentSecurityPolicyForWorld(
const DOMWrapperWorld* world) { … }
const KURL& LocalDOMWindow::Url() const { … }
const KURL& LocalDOMWindow::BaseURL() const { … }
KURL LocalDOMWindow::CompleteURL(const String& url) const { … }
void LocalDOMWindow::DisableEval(const String& error_message) { … }
void LocalDOMWindow::SetWasmEvalErrorMessage(const String& error_message) { … }
String LocalDOMWindow::UserAgent() const { … }
UserAgentMetadata LocalDOMWindow::GetUserAgentMetadata() const { … }
HttpsState LocalDOMWindow::GetHttpsState() const { … }
ResourceFetcher* LocalDOMWindow::Fetcher() { … }
bool LocalDOMWindow::CanExecuteScripts(
ReasonForCallingCanExecuteScripts reason) { … }
String LocalDOMWindow::CheckAndGetJavascriptUrl(
const DOMWrapperWorld* world,
const KURL& url,
Element* element,
network::mojom::CSPDisposition csp_disposition) { … }
void LocalDOMWindow::ExceptionThrown(ErrorEvent* event) { … }
String LocalDOMWindow::OutgoingReferrer() const { … }
CoreProbeSink* LocalDOMWindow::GetProbeSink() { … }
const BrowserInterfaceBrokerProxy& LocalDOMWindow::GetBrowserInterfaceBroker()
const { … }
FrameOrWorkerScheduler* LocalDOMWindow::GetScheduler() { … }
scoped_refptr<base::SingleThreadTaskRunner> LocalDOMWindow::GetTaskRunner(
TaskType type) { … }
void LocalDOMWindow::ReportPermissionsPolicyViolation(
mojom::blink::PermissionsPolicyFeature feature,
mojom::blink::PolicyDisposition disposition,
const std::optional<String>& reporting_endpoint,
const String& message) const { … }
void LocalDOMWindow::ReportDocumentPolicyViolation(
mojom::blink::DocumentPolicyFeature feature,
mojom::blink::PolicyDisposition disposition,
const String& message,
const String& source_file) const { … }
void LocalDOMWindow::AddConsoleMessageImpl(ConsoleMessage* console_message,
bool discard_duplicates) { … }
scoped_refptr<base::SingleThreadTaskRunner>
LocalDOMWindow::GetAgentGroupSchedulerCompositorTaskRunner() { … }
void LocalDOMWindow::AddInspectorIssue(AuditsIssue issue) { … }
void LocalDOMWindow::CountUse(mojom::WebFeature feature) { … }
void LocalDOMWindow::CountWebDXFeature(mojom::blink::WebDXFeature feature) { … }
void LocalDOMWindow::CountPermissionsPolicyUsage(
mojom::blink::PermissionsPolicyFeature feature,
UseCounterImpl::PermissionsPolicyUsageType type) { … }
void LocalDOMWindow::CountUseOnlyInCrossOriginIframe(
mojom::blink::WebFeature feature) { … }
void LocalDOMWindow::CountUseOnlyInSameOriginIframe(
mojom::blink::WebFeature feature) { … }
void LocalDOMWindow::CountUseOnlyInCrossSiteIframe(
mojom::blink::WebFeature feature) { … }
bool LocalDOMWindow::HasInsecureContextInAncestors() const { … }
Document* LocalDOMWindow::InstallNewDocument(const DocumentInit& init) { … }
void LocalDOMWindow::EnqueueWindowEvent(Event& event, TaskType task_type) { … }
void LocalDOMWindow::EnqueueDocumentEvent(Event& event, TaskType task_type) { … }
void LocalDOMWindow::DispatchWindowLoadEvent() { … }
void LocalDOMWindow::DocumentWasClosed() { … }
void LocalDOMWindow::EnqueueNonPersistedPageshowEvent() { … }
void LocalDOMWindow::DispatchPersistedPageshowEvent(
base::TimeTicks navigation_start) { … }
void LocalDOMWindow::DispatchPagehideEvent(
PageTransitionEventPersistence persistence) { … }
void LocalDOMWindow::EnqueueHashchangeEvent(const String& old_url,
const String& new_url) { … }
void LocalDOMWindow::DispatchPopstateEvent(
scoped_refptr<SerializedScriptValue> state_object,
scheduler::TaskAttributionInfo* parent_task) { … }
LocalDOMWindow::~LocalDOMWindow() = default;
void LocalDOMWindow::Dispose() { … }
ExecutionContext* LocalDOMWindow::GetExecutionContext() const { … }
const LocalDOMWindow* LocalDOMWindow::ToLocalDOMWindow() const { … }
LocalDOMWindow* LocalDOMWindow::ToLocalDOMWindow() { … }
MediaQueryList* LocalDOMWindow::matchMedia(const String& media) { … }
void LocalDOMWindow::FrameDestroyed() { … }
void LocalDOMWindow::RegisterEventListenerObserver(
EventListenerObserver* event_listener_observer) { … }
void LocalDOMWindow::Reset() { … }
void LocalDOMWindow::SendOrientationChangeEvent() { … }
int LocalDOMWindow::orientation() const { … }
Screen* LocalDOMWindow::screen() { … }
History* LocalDOMWindow::history() { … }
BarProp* LocalDOMWindow::locationbar() { … }
BarProp* LocalDOMWindow::menubar() { … }
BarProp* LocalDOMWindow::personalbar() { … }
BarProp* LocalDOMWindow::scrollbars() { … }
BarProp* LocalDOMWindow::statusbar() { … }
BarProp* LocalDOMWindow::toolbar() { … }
FrameConsole* LocalDOMWindow::GetFrameConsole() const { … }
Navigator* LocalDOMWindow::navigator() { … }
NavigationApi* LocalDOMWindow::navigation() { … }
void LocalDOMWindow::SchedulePostMessage(PostedMessage* posted_message) { … }
void LocalDOMWindow::DispatchPostMessage(
MessageEvent* event,
scoped_refptr<const SecurityOrigin> intended_target_origin,
std::unique_ptr<SourceLocation> location,
const base::UnguessableToken& source_agent_cluster_id) { … }
void LocalDOMWindow::DispatchMessageEventWithOriginCheck(
const SecurityOrigin* intended_target_origin,
MessageEvent* event,
std::unique_ptr<SourceLocation> location,
const base::UnguessableToken& source_agent_cluster_id) { … }
DOMSelection* LocalDOMWindow::getSelection() { … }
Element* LocalDOMWindow::frameElement() const { … }
void LocalDOMWindow::print(ScriptState* script_state) { … }
void LocalDOMWindow::stop() { … }
void LocalDOMWindow::alert(ScriptState* script_state, const String& message) { … }
bool LocalDOMWindow::confirm(ScriptState* script_state, const String& message) { … }
String LocalDOMWindow::prompt(ScriptState* script_state,
const String& message,
const String& default_value) { … }
bool LocalDOMWindow::find(const String& string,
bool case_sensitive,
bool backwards,
bool wrap,
bool whole_word,
bool ,
bool ) const { … }
bool LocalDOMWindow::offscreenBuffering() const { … }
int LocalDOMWindow::outerHeight() const { … }
int LocalDOMWindow::outerWidth() const { … }
gfx::Size LocalDOMWindow::GetViewportSize() const { … }
int LocalDOMWindow::innerHeight() const { … }
int LocalDOMWindow::innerWidth() const { … }
int LocalDOMWindow::screenX() const { … }
int LocalDOMWindow::screenY() const { … }
double LocalDOMWindow::scrollX() const { … }
double LocalDOMWindow::scrollY() const { … }
DOMViewport* LocalDOMWindow::viewport() { … }
DOMVisualViewport* LocalDOMWindow::visualViewport() { … }
const AtomicString& LocalDOMWindow::name() const { … }
void LocalDOMWindow::setName(const AtomicString& name) { … }
void LocalDOMWindow::setStatus(const String& string) { … }
void LocalDOMWindow::setDefaultStatus(const String& string) { … }
String LocalDOMWindow::origin() const { … }
Document* LocalDOMWindow::document() const { … }
StyleMedia* LocalDOMWindow::styleMedia() { … }
CSSStyleDeclaration* LocalDOMWindow::getComputedStyle(
Element* elt,
const String& pseudo_elt) const { … }
ScriptPromise<ComputedAccessibleNode> LocalDOMWindow::getComputedAccessibleNode(
ScriptState* script_state,
Element* element) { … }
double LocalDOMWindow::devicePixelRatio() const { … }
void LocalDOMWindow::scrollBy(double x, double y) const { … }
void LocalDOMWindow::scrollBy(const ScrollToOptions* scroll_to_options) const { … }
void LocalDOMWindow::scrollTo(double x, double y) const { … }
void LocalDOMWindow::scrollTo(const ScrollToOptions* scroll_to_options) const { … }
void LocalDOMWindow::moveBy(int x, int y) const { … }
void LocalDOMWindow::moveTo(int x, int y) const { … }
void LocalDOMWindow::resizeBy(int x,
int y,
ExceptionState& exception_state) const { … }
void LocalDOMWindow::resizeTo(int width,
int height,
ExceptionState& exception_state) const { … }
int LocalDOMWindow::requestAnimationFrame(V8FrameRequestCallback* callback) { … }
int LocalDOMWindow::webkitRequestAnimationFrame(
V8FrameRequestCallback* callback) { … }
void LocalDOMWindow::cancelAnimationFrame(int id) { … }
void LocalDOMWindow::queueMicrotask(V8VoidFunction* callback) { … }
bool LocalDOMWindow::originAgentCluster() const { … }
CustomElementRegistry* LocalDOMWindow::customElements(
ScriptState* script_state) const { … }
CustomElementRegistry* LocalDOMWindow::customElements() const { … }
CustomElementRegistry* LocalDOMWindow::MaybeCustomElements() const { … }
External* LocalDOMWindow::external() { … }
bool LocalDOMWindow::isSecureContext() const { … }
void LocalDOMWindow::ClearIsolatedWorldCSPForTesting(int32_t world_id) { … }
bool IsSuddenTerminationDisablerEvent(const AtomicString& event_type) { … }
void LocalDOMWindow::AddedEventListener(
const AtomicString& event_type,
RegisteredEventListener& registered_listener) { … }
void LocalDOMWindow::RemovedEventListener(
const AtomicString& event_type,
const RegisteredEventListener& registered_listener) { … }
void LocalDOMWindow::DispatchLoadEvent() { … }
DispatchEventResult LocalDOMWindow::DispatchEvent(Event& event,
EventTarget* target) { … }
void LocalDOMWindow::RemoveAllEventListeners() { … }
void LocalDOMWindow::FinishedLoading(FrameLoader::NavigationFinishState state) { … }
void LocalDOMWindow::PrintErrorMessage(const String& message) const { … }
DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
const String& url_string,
const AtomicString& target,
const String& features,
ExceptionState& exception_state) { … }
DOMWindow* LocalDOMWindow::openPictureInPictureWindow(
v8::Isolate* isolate,
const WebPictureInPictureWindowOptions& options) { … }
void LocalDOMWindow::Trace(Visitor* visitor) const { … }
bool LocalDOMWindow::CrossOriginIsolatedCapability() const { … }
bool LocalDOMWindow::IsIsolatedContext() const { … }
ukm::UkmRecorder* LocalDOMWindow::UkmRecorder() { … }
ukm::SourceId LocalDOMWindow::UkmSourceID() const { … }
void LocalDOMWindow::SetStorageKey(const BlinkStorageKey& storage_key) { … }
bool LocalDOMWindow::IsPaymentRequestTokenActive() const { … }
bool LocalDOMWindow::ConsumePaymentRequestToken() { … }
bool LocalDOMWindow::IsFullscreenRequestTokenActive() const { … }
bool LocalDOMWindow::ConsumeFullscreenRequestToken() { … }
bool LocalDOMWindow::IsDisplayCaptureRequestTokenActive() const { … }
bool LocalDOMWindow::ConsumeDisplayCaptureRequestToken() { … }
void LocalDOMWindow::SetIsInBackForwardCache(bool is_in_back_forward_cache) { … }
void LocalDOMWindow::DidBufferLoadWhileInBackForwardCache(
bool update_process_wide_count,
size_t num_bytes) { … }
bool LocalDOMWindow::credentialless() const { … }
bool LocalDOMWindow::IsInFencedFrame() const { … }
Fence* LocalDOMWindow::fence() { … }
bool LocalDOMWindow::IsPictureInPictureWindow() const { … }
void LocalDOMWindow::SetIsPictureInPictureWindow() { … }
net::StorageAccessApiStatus LocalDOMWindow::GetStorageAccessApiStatus() const { … }
void LocalDOMWindow::SetStorageAccessApiStatus(
net::StorageAccessApiStatus status) { … }
void LocalDOMWindow::GenerateNewNavigationId() { … }
void LocalDOMWindow::SetHasBeenRevealed(bool revealed) { … }
void LocalDOMWindow::UpdateEventListenerCountsToDocumentForReuseIfNeeded() { … }
}