/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::cell::Cell; use std::ptr::{self, NonNull}; use std::rc::Rc; use content_security_policy::sandboxing_directive::SandboxingFlagSet; use dom_struct::dom_struct; use html5ever::local_name; use indexmap::map::IndexMap; use itertools::Either; use js::JSCLASS_IS_GLOBAL; use js::context::JSContext; use js::gc::{HandleId, HandleObject, HandleValue, MutableHandleObject}; use js::glue::{ CreateWrapperProxyHandler, DeleteWrapperProxyHandler, GetProxyPrivate, GetProxyReservedSlot, ProxyTraps, SetProxyReservedSlot, }; use js::jsapi::{ GCContext, Handle as RawHandle, HandleId as RawHandleId, HandleObject as RawHandleObject, HandleValue as RawHandleValue, JS_DefinePropertyById, JS_DeletePropertyById, JS_ForwardSetPropertyTo, JSContext as RawJSContext, JSErrNum, JSITER_HIDDEN, JSITER_OWNONLY, JSITER_SYMBOLS, JSObject, JSPROP_ENUMERATE, JSPROP_READONLY, JSTracer, MutableHandle as RawMutableHandle, MutableHandleIdVector as RawMutableHandleIdVector, MutableHandleObject as RawMutableHandleObject, MutableHandleValue as RawMutableHandleValue, ObjectOpResult, PropertyDescriptor, jsid, }; use js::jsval::{NullValue, PrivateValue, UndefinedValue}; use js::realm::{AutoRealm, CurrentRealm}; use js::rust::wrappers2::{ AppendToIdVector, GetPropertyKeys, JS_ForwardGetPropertyTo, JS_GetOwnPropertyDescriptorById, JS_HasOwnPropertyById, JS_HasPropertyById, JS_TransplantObject, NewWindowProxy, SetWindowProxy, int_to_jsid, }; use js::rust::{Handle, MutableHandle, MutableHandleValue, get_object_class}; use js::typedarray::JSObjectStorage; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use net_traits::ReferrerPolicy; use net_traits::request::Referrer; use script_bindings::cell::DomRefCell; use script_bindings::codegen::GenericBindings::DissimilarOriginWindowBinding::{ self, DissimilarOriginWindowMethods, }; use script_bindings::codegen::GenericBindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use script_bindings::codegen::GenericBindings::WindowBinding::{ self, GetProtoObject, WindowMethods, }; use script_bindings::conversions::jsid_to_string; use script_bindings::proxyhandler::{ self, CROSS_ORIGIN_PROPERTY_HOLDER_WEAK_MAP_SLOT, CrossOriginProperties, cross_origin_get_own_property_helper, cross_origin_own_property_keys, cross_origin_property_fallback, cross_origin_set, is_extensible, is_platform_object_same_origin, maybe_cross_origin_get_prototype, maybe_cross_origin_set_prototype_rawcx, prevent_extensions, report_cross_origin_denial, set_property_descriptor, }; use script_bindings::reflector::{DomObject, MutDomObject, Reflector}; use script_traits::{NewPipelineInfo, WebViewState}; use serde::{Deserialize, Serialize}; use servo_base::generic_channel; use servo_base::generic_channel::GenericSend; use servo_base::id::{BrowsingContextId, PipelineId, WebViewId}; use servo_constellation_traits::{ AuxiliaryWebViewCreationRequest, LoadData, LoadOrigin, NavigationHistoryBehavior, ScriptToConstellationMessage, TargetSnapshotParams, }; use servo_url::{ImmutableOrigin, OriginSnapshot, ServoUrl}; use storage_traits::webstorage_thread::WebStorageThreadMsg; use style::attr::parse_integer; use crate::DomTypeHolder; use crate::dom::bindings::conversions::{ToJSValConvertible, root_from_handleobject}; use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::DomGlobal; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::settings_stack::maybe_entry_global; use crate::dom::bindings::str::{DOMString, USVString}; use crate::dom::bindings::trace::JSTraceable; use crate::dom::bindings::utils::get_array_index_from_id; use crate::dom::dissimilaroriginwindow::DissimilarOriginWindow; use crate::dom::document::Document; use crate::dom::element::Element; use crate::dom::globalscope::GlobalScope; use crate::dom::node::node::NodeTraits; use crate::dom::window::Window; use crate::event_loop::script_thread::{ScriptThread, with_script_thread}; use crate::event_loop::script_window_proxies::ScriptWindowProxies; use crate::navigation::navigate; #[dom_struct] // NOTE: the browsing context for a window is managed in two places: // here, in script, but also in the constellation. The constellation // manages the session history, which in script is accessed through // History objects, messaging the constellation. pub(crate) struct WindowProxy { /// The JS WindowProxy object. /// Unlike other reflectors, we mutate this field because /// we have to brain-transplant the reflector when the WindowProxy /// changes Window. reflector: Reflector, /// The id of the browsing context. /// In the case that this is a nested browsing context, this is the id /// of the container. #[no_trace] browsing_context_id: BrowsingContextId, // https://html.spec.whatwg.org/multipage/#opener-browsing-context #[no_trace] opener: Option, /// The frame id of the top-level ancestor browsing context. /// In the case that this is a top-level window, this is our id. #[no_trace] webview_id: WebViewId, /// The name of the browsing context (sometimes, but not always, /// equal to the name of a container element) name: DomRefCell, /// The pipeline id of the currently active document. /// May be None, when the currently active document is in another script thread. /// We do not try to keep the pipeline id for documents in other threads, /// as this would require the constellation notifying many script threads about /// the change, which could be expensive. #[no_trace] currently_active: Cell>, /// Has the browsing context been discarded? discarded: Cell, /// Has the browsing context been disowned? disowned: Cell, /// is_closing: Cell, /// If the containing `