Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(iframe): remove inert synthetic Window surfaces

ldm0ba5cd6f5e590
diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rs
index da313ea20..cd55429f3 100644
--- a/moli-renderer-v8/src/context_bootstrap.rs
+++ b/moli-renderer-v8/src/context_bootstrap.rs
@@ -399,7 +399,6 @@ use self::range_live::{
update_live_ranges_for_text_split,
};
pub(super) use self::runtime_state::finish_context_bootstrap;
-pub(crate) use self::runtime_state::install_child_window_eval_runtime_state;
pub(crate) use self::runtime_state::install_webassembly_runtime_state;
#[cfg(feature = "wpt-extensions")]
pub(crate) use self::runtime_state::install_wpt_webdriver_runtime_state;
@@ -499,7 +498,6 @@ pub(crate) use self::window_lazy_surface::{
rematerialize_window_lazy_surface_if_cached,
};
use self::window_runtime::global_caches_getter_callback;
-pub(crate) use self::window_runtime::install_child_window_own_methods;
pub(crate) use self::window_template::install_window_own_template_bindings;
pub(crate) use self::worker_host::{
dispatch_worker_error_event_with_kind, dispatch_worker_event,
diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
index ca3cc94a9..c7d59354f 100644
--- a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
+++ b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
@@ -8,7 +8,7 @@ use super::{
css_runtime::install_css_runtime_state,
exposed_interfaces::is_lazy_exposed_interface,
indexed_db::ensure_indexed_db_runtime_state,
- location_runtime::{location_href_slot, sync_document_location_runtime_state_from_window},
+ location_runtime::sync_document_location_runtime_state_from_window,
navigation_bootstrap::install_window_location_history_navigation_runtime_state,
navigator_runtime::{bind_window_navigator_identity_seed, install_navigator_runtime_state},
performance_runtime::install_default_window_performance_seed,
@@ -20,7 +20,7 @@ use super::{
WINDOW_DOCUMENT_SLOT, window_document_getter_template, window_inner_width_getter,
window_length_getter, window_outer_height_getter,
},
- window_runtime::{build_legacy_storage_info_object, window_noop_callback},
+ window_runtime::build_legacy_storage_info_object,
window_template::install_window_named_properties_object,
};
use crate::web_api_interfaces;
@@ -36,20 +36,16 @@ use crate::{
network_host,
util::{
callback_data_index_value, callback_data_item, context_host_ptr_from_global_bridge,
- create_script_origin_with_base_url, get_private_value, script_base_url_continuation_data,
- set_private_value, throw_type_error, v8_string, v8str,
+ get_private_value, set_private_value, throw_type_error, v8_string, v8str,
},
webidl,
webidl_iterator::install_webidl_collection_iterator_intrinsics,
window_host,
};
-use anyhow::{Result, anyhow, bail};
+use anyhow::{Result, anyhow};
use moli_script::html_script_element_supports_type;
use moli_webapi_declare::WebApiObject;
-#[cfg(test)]
-mod tests;
-
pub(crate) const ORIGINAL_WEBASSEMBLY_INSTANCE_CONSTRUCTOR_SLOT: &str =
"__moliOriginalWebAssemblyInstanceConstructor";
pub(crate) const ORIGINAL_WEBASSEMBLY_COMPILE_ERROR_CONSTRUCTOR_SLOT: &str =
@@ -61,7 +57,6 @@ pub(crate) const ORIGINAL_WEBASSEMBLY_GLOBAL_VALUE_GETTER_SLOT: &str =
const WINDOW_INDEXED_DB_SURFACE_SLOT: &str = "moli.Window.indexedDB";
const WINDOW_ORIGIN_RUNTIME_SLOT: &str = "__moliWindowOriginRuntime";
const WINDOW_STATUS_RUNTIME_SLOT: &str = "__moliWindowStatusRuntime";
-const WINDOW_INTRINSIC_EVAL_SLOT: &str = "__moliWindowIntrinsicEval";
pub(in crate::context_bootstrap) const WINDOW_SECURE_CONTEXT_AVAILABLE_SLOT: &str =
"__moliWindowSecureContextAvailable";
@@ -1265,252 +1260,6 @@ fn dom_handle_from_value<'s>(
}
}
-fn child_window_eval_base_url<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
-) -> Option<url::Url> {
- // Child frames do not eagerly get their own native V8 Context in the
- // normal page lifecycle yet. The child Window shell still carries the
- // location state we need for eval/module resolution, including after the
- // iframe has been detached and author script only holds contentWindow.
- let location = object_own_hidden_value(scope, window, WINDOW_LOCATION_SLOT)
- .filter(|value| !value.is_undefined())
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())?;
- location_href_slot(scope, location).and_then(|href| url::Url::parse(&href).ok())
-}
-
-fn run_child_window_eval_expression<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
- handle: DomHandle,
- expression: &str,
-) -> Option<v8::Local<'s, v8::Value>> {
- let base_url = child_window_eval_base_url(scope, window);
- // This intentionally runs the saved child Window object directly instead
- // of resolving `handle` through the live child-frame registry. Blink keeps
- // an initialized detached WindowProxy usable by author-held references; in
- // our current single-context model, the closest owner boundary is the
- // retained child Window shell.
- //
- // Passing the expression as an eval argument is also deliberate: V8 parses
- // the author source, so dynamic import goes through the normal V8
- // HostImportModuleDynamically callback. Avoid source-string prefix checks
- // such as "import(" here.
- let source = v8_string(
- scope,
- r#"(function(window, __expr) {
- const document = window.document;
- return (function(window, document, globalThis) {
- with (window) {
- return eval(__expr);
- }
- }).call(window, window, document, window);
-})"#,
- )?;
- let origin = base_url.as_ref().map(|base_url| {
- create_script_origin_with_base_url(scope, base_url.as_str(), 0, Some(base_url))
- });
- let function = v8::Script::compile(scope, source, origin.as_ref())
- .and_then(|script| crate::script_execution::execute_compiled_script(scope, script))
- .and_then(|value| v8::Local::<v8::Function>::try_from(value).ok())?;
- let expression = v8_string(scope, expression)?;
-
- let previous_active_child = native_bridge::enter_active_child_window_scope(scope, Some(handle));
- let previous_active_child = v8::Global::new(scope, previous_active_child);
- let previous_continuation_data = scope.get_continuation_preserved_embedder_data();
- // The active child marker and continuation data are the bridge between the
- // child Window shell and module/network machinery that still runs in the
- // main native context. Restore both immediately after the eval call.
- if let Some(base_url) = base_url.as_ref()
- && let Some(value) = script_base_url_continuation_data(scope, base_url)
- {
- scope.set_continuation_preserved_embedder_data(value);
- }
- let result = crate::util::call_script_visible_function(
- scope,
- function,
- window.into(),
- &[window.into(), expression.into()],
- "child Window eval",
- );
- scope.set_continuation_preserved_embedder_data(previous_continuation_data);
- let previous_active_child = v8::Local::new(scope, &previous_active_child);
- native_bridge::restore_active_child_window_scope(scope, previous_active_child);
-
- result.map(|value| mark_detached_child_eval_promise_handled(scope, handle, value))
-}
-
-fn mark_detached_child_eval_promise_handled<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- handle: DomHandle,
- value: v8::Local<'s, v8::Value>,
-) -> v8::Local<'s, v8::Value> {
- // Detached child eval can still return the promise created by V8 for
- // import(). If the child browsing context is no longer live, treat that
- // promise as owned by the inactive context so a later rejected dynamic
- // import does not become a top-level unhandled rejection in the parent WPT
- // harness. Keep this limited to real V8 promises and detached children.
- let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {
- return value;
- };
- if unsafe { &*host_ptr }.child_browsing_context_is_live(handle) {
- return value;
- }
- let Ok(promise) = v8::Local::<v8::Promise>::try_from(value) else {
- return value;
- };
- let promise_value: v8::Local<'s, v8::Value> = promise.into();
- let Ok(promise_object) = v8::Local::<v8::Object>::try_from(promise_value) else {
- return value;
- };
- let Some(catch) = promise_object
- .get(scope, v8str(scope, "catch").into())
- .and_then(|value| v8::Local::<v8::Function>::try_from(value).ok())
- else {
- return value;
- };
- let Some(noop) = v8::Function::builder(window_noop_callback).build(scope) else {
- return value;
- };
- let _ = catch.call(scope, promise_object.into(), &[noop.into()]);
- value
-}
-
-fn evaluate_child_window_expression<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
- handle: DomHandle,
- expression: &str,
-) -> Result<v8::Local<'s, v8::Value>> {
- let eval_key = v8str(scope, "eval");
- let own_eval = window
- .get(scope, eval_key.into())
- .ok_or_else(|| anyhow!("failed to capture child Window eval"))?;
- let intrinsic_eval = get_private_value(scope, window, WINDOW_INTRINSIC_EVAL_SLOT)
- .ok_or_else(|| anyhow!("missing child Window intrinsic eval"))?;
- if !window
- .define_own_property(
- scope,
- eval_key.into(),
- intrinsic_eval,
- v8::PropertyAttribute::DONT_ENUM,
- )
- .unwrap_or(false)
- {
- bail!("failed to expose child Window intrinsic eval");
- }
-
- let result = {
- let try_catch = std::pin::pin!(v8::TryCatch::new(scope));
- let mut scope = try_catch.init();
- run_child_window_eval_expression(&mut scope, window, handle, expression)
- .map(|value| v8::Global::new(&scope, value))
- .ok_or_else(|| {
- let message = scope
- .message()
- .map(|message| message.get(&scope).to_rust_string_lossy(&scope))
- .or_else(|| {
- scope
- .exception()
- .and_then(|value| value.to_string(&scope))
- .map(|value| value.to_rust_string_lossy(&scope))
- })
- .unwrap_or_else(|| "failed to run child window eval source".to_owned());
- anyhow!(message)
- })
- };
-
- if !window
- .define_own_property(
- scope,
- eval_key.into(),
- own_eval,
- v8::PropertyAttribute::DONT_ENUM,
- )
- .unwrap_or(false)
- {
- bail!("failed to restore child Window eval");
- }
-
- result.map(|value| v8::Local::new(scope, &value))
-}
-
-fn child_window_eval_callback<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: v8::FunctionCallbackArguments<'s>,
- mut rv: v8::ReturnValue<'s, v8::Value>,
-) {
- if args.length() < 1 {
- rv.set_undefined();
- return;
- }
-
- let argument = args.get(0);
- if !argument.is_string() {
- rv.set(argument);
- return;
- }
-
- let receiver = callback_this_object(scope, &args);
- let Some(handle) = child_context_handle_from_owner(scope, receiver) else {
- rv.set(argument);
- return;
- };
- let Some(expression) = argument
- .to_string(scope)
- .map(|value| value.to_rust_string_lossy(scope))
- else {
- rv.set(argument);
- return;
- };
-
- match evaluate_child_window_expression(scope, receiver, handle, &expression) {
- Ok(value) => rv.set(value),
- Err(error) => {
- let exception = v8::Exception::error(
- scope,
- v8_string(scope, &error.to_string())
- .unwrap_or_else(|| v8str(scope, "child window eval failed")),
- );
- scope.throw_exception(exception);
- }
- }
-}
-
-pub(crate) fn install_child_window_eval_runtime_state<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
-) -> Result<()> {
- let inherited_or_intrinsic_eval = get_private_value(scope, window, WINDOW_INTRINSIC_EVAL_SLOT)
- .filter(|value| value.is_function())
- .or_else(|| {
- window
- .get(scope, v8str(scope, "eval").into())
- .filter(|value| value.is_function())
- })
- .or_else(|| {
- let global = scope.get_current_context().global(scope);
- get_private_value(scope, global, WINDOW_INTRINSIC_EVAL_SLOT)
- })
- .ok_or_else(|| anyhow!("failed to resolve child Window intrinsic eval"))?;
- set_private_value(
- scope,
- window,
- WINDOW_INTRINSIC_EVAL_SLOT,
- inherited_or_intrinsic_eval,
- );
- let eval = v8::Function::builder(child_window_eval_callback)
- .build(scope)
- .ok_or_else(|| anyhow!("failed to create child window eval callback"))?;
- let _ = window.define_own_property(
- scope,
- v8str(scope, "eval").into(),
- eval.into(),
- v8::PropertyAttribute::DONT_ENUM,
- );
- Ok(())
-}
-
fn define_legacy_unforgeable_document_property<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
@@ -2148,7 +1897,6 @@ fn install_window_runtime_state<'s>(
.get_real_named_property(scope, v8str(scope, "eval").into())
.filter(|value| value.is_function())
.ok_or_else(|| anyhow!("failed to resolve intrinsic eval"))?;
- set_private_value(scope, global, WINDOW_INTRINSIC_EVAL_SLOT, intrinsic_eval);
WindowEvalGlobalDeclaration::new(intrinsic_eval)
.initialize(scope, global)
.map_err(|error| anyhow!("failed to initialize Window intrinsic eval: {error}"))?;
diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state/tests.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state/tests.rs
deleted file mode 100644
index d096db0c3..000000000
--- a/moli-renderer-v8/src/context_bootstrap/runtime_state/tests.rs
+++ /dev/null
@@ -1,99 +0,0 @@
-use std::pin::pin;
-
-use super::*;
-
-#[test]
-fn failed_child_eval_capture_never_exposes_the_intrinsic_eval() {
- crate::ensure_v8_for_test();
- let mut isolate = v8::Isolate::new(Default::default());
- let scope = pin!(v8::HandleScope::new(&mut isolate));
- let scope = &mut scope.init();
- let context = v8::Context::new(scope, Default::default());
- let scope = &mut v8::ContextScope::new(scope, context);
-
- let source = v8str(
- scope,
- r#"Object.defineProperty({}, "eval", {
- configurable: true,
- get() { throw new Error("blocked eval read"); }
- })"#,
- );
- let window = v8::Script::compile(scope, source, None)
- .and_then(|script| crate::script_execution::execute_compiled_script(scope, script))
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
- .expect("Window-like object with a throwing eval getter");
- let eval_key = v8str(scope, "eval");
- let intrinsic_eval = context
- .global(scope)
- .get(scope, eval_key.into())
- .expect("intrinsic eval");
- set_private_value(scope, window, WINDOW_INTRINSIC_EVAL_SLOT, intrinsic_eval);
-
- let error = {
- let try_catch = pin!(v8::TryCatch::new(scope));
- let mut scope = try_catch.init();
- evaluate_child_window_expression(&mut scope, window, DomHandle::new(1), "1 + 1")
- .expect_err("the throwing eval getter must abort before mutation")
- };
- assert_eq!(error.to_string(), "failed to capture child Window eval");
-
- let descriptor = window
- .get_own_property_descriptor(scope, eval_key.into())
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
- .expect("eval accessor descriptor");
- assert!(
- descriptor
- .get(scope, v8str(scope, "get").into())
- .is_some_and(|value| value.is_function()),
- "the original accessor must remain installed"
- );
-}
-
-#[test]
-fn child_eval_error_restores_the_wrapper_before_returning() {
- crate::ensure_v8_for_test();
- let mut isolate = v8::Isolate::new(Default::default());
- let scope = pin!(v8::HandleScope::new(&mut isolate));
- let scope = &mut scope.init();
- let context = v8::Context::new(scope, Default::default());
- let scope = &mut v8::ContextScope::new(scope, context);
-
- let window = v8::Object::new(scope);
- let eval_key = v8str(scope, "eval");
- let intrinsic_eval = context
- .global(scope)
- .get(scope, eval_key.into())
- .expect("intrinsic eval");
- let wrapper = v8::Script::compile(
- scope,
- v8str(scope, "(function childEvalWrapper() {})"),
- None,
- )
- .and_then(|script| crate::script_execution::execute_compiled_script(scope, script))
- .expect("child eval wrapper");
- assert_eq!(
- window.define_own_property(
- scope,
- eval_key.into(),
- wrapper,
- v8::PropertyAttribute::DONT_ENUM,
- ),
- Some(true)
- );
- set_private_value(scope, window, WINDOW_INTRINSIC_EVAL_SLOT, intrinsic_eval);
-
- evaluate_child_window_expression(
- scope,
- window,
- DomHandle::new(1),
- "throw new Error('child eval failure')",
- )
- .expect_err("the author expression should fail");
-
- assert!(
- window
- .get(scope, eval_key.into())
- .is_some_and(|value| value.strict_equals(wrapper)),
- "the child eval wrapper must be restored on the error path"
- );
-}
diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime.rs
index 7a3e29639..73e8a501b 100644
--- a/moli-renderer-v8/src/context_bootstrap/window_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime.rs
@@ -8,8 +8,6 @@ mod performance;
mod service_worker;
mod structured_clone;
-use moli_webapi_declare::WebApiObject;
-
pub(super) use base64::{window_atob_callback, window_btoa_callback};
pub(super) use dialogs::entered_window_api_base_url;
pub(super) use dialogs::{window_alert_callback, window_confirm_callback, window_prompt_callback};
@@ -62,27 +60,3 @@ pub(super) use service_worker::{
navigator_service_worker_register_callback, service_worker_object_set_owner_scope,
};
pub(super) use structured_clone::window_structured_clone_callback;
-
-#[derive(Default, WebApiObject)]
-#[webapi(plain)]
-struct ChildWindowOwnMethodsDeclaration {
- #[webapi(method, length = 0, callback = window_open_callback)]
- open: (),
- #[webapi(method, length = 0, callback = window_noop_callback)]
- close: (),
- #[webapi(method, length = 0, callback = window_noop_callback)]
- blur: (),
- #[webapi(method, length = 0, callback = window_const_false_callback)]
- find: (),
- #[webapi(method, length = 0, callback = window_stop_callback)]
- stop: (),
- #[webapi(method, length = 0, callback = window_noop_callback)]
- print: (),
-}
-
-pub(crate) fn install_child_window_own_methods<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
-) -> std::result::Result<(), moli_webapi_declare::BindError> {
- ChildWindowOwnMethodsDeclaration::default().initialize(scope, window)
-}
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_documents/snapshots.rs b/moli-renderer-v8/src/native_bridge/context_host/child_documents/snapshots.rs
index 20e3c344b..879ec02bb 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_documents/snapshots.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_documents/snapshots.rs
@@ -1,8 +1,6 @@
use super::super::{ChildBrowsingContextBootstrap, ChildBrowsingContextSnapshot, JsContextHost};
-use super::configure_child_document_navigation_request;
use crate::document_response_decoder::decode_document_response;
use crate::document_runtime::{DocumentPolicyContainer, DomHandle};
-use moli_fetch::Request;
use moli_web_mime::{
is_html_document_mime, resource_mime_essence_for_url, response_document_content_type,
};
@@ -86,60 +84,6 @@ impl JsContextHost {
}
}
- pub(crate) fn materialize_child_snapshot_for_url_blocking(
- &self,
- owner_node: crate::document_runtime::DomHandle,
- url: &Url,
- ) -> Option<ChildBrowsingContextSnapshot> {
- if let Some(snapshot) = self.materialize_local_child_snapshot_for_url(url) {
- return Some(self.apply_page_csp_bypass_to_child_snapshot(snapshot));
- }
- if !matches!(url.scheme(), "http" | "https") {
- return None;
- }
- let dispatch_scope = self
- .owner_dispatch_scope_for_node(owner_node)
- .unwrap_or(crate::native_bridge::OwnerDispatchScope::Top);
- let loader = self
- .document_resource_loader_for_dispatch_scope(dispatch_scope)?
- .request_client()
- .clone();
- let initiator_url = self.document_url_for_child_context(owner_node);
- let browser_context = self.host_document().cookie_browser_context();
- let request = configure_child_document_navigation_request(
- Request::new("GET", url.as_str(), None, Vec::new()).ok()?,
- &initiator_url,
- &browser_context,
- )
- .with_page_network_policy();
- let response = loader.fetch_raw_for_blocking_boundary(request).ok()?;
- let head = response.head();
- let content_type = child_document_content_type_from_headers(&head.headers)
- .or_else(|| child_document_content_type_for_url(&head.final_url));
- let (markup, character_set) = decode_document_response(
- response.body_bytes(),
- &head.headers,
- content_type.as_deref(),
- &head.final_url,
- Some(self.document_character_set()),
- );
- let policy_container = DocumentPolicyContainer::from_navigation_response_headers(
- &head.headers,
- &head.final_url,
- );
- Some(
- self.apply_page_csp_bypass_to_child_snapshot(
- ChildBrowsingContextSnapshot::with_character_set(
- head.final_url,
- markup,
- content_type,
- character_set,
- )
- .with_policy_container(policy_container),
- ),
- )
- }
-
pub(in crate::native_bridge::context_host) fn materialize_local_child_snapshot_for_bootstrap(
&self,
handle: DomHandle,
diff --git a/moli-renderer-v8/src/native_bridge/document.rs b/moli-renderer-v8/src/native_bridge/document.rs
index 9408b5c8b..871f6a8c4 100644
--- a/moli-renderer-v8/src/native_bridge/document.rs
+++ b/moli-renderer-v8/src/native_bridge/document.rs
@@ -150,13 +150,11 @@ pub(in crate::native_bridge::document) use custom_element_options::{
CreateElementOptions, DocumentCreateElementArgs, DocumentCreateElementNsArgs,
parse_import_node_options,
};
-pub(crate) use detached_install::detached_iframe_current_content_document_handle;
pub(super) use detached_install::install_detached_bridge_methods;
pub(in crate::native_bridge) use detached_install::{
clear_detached_iframe_cached_context, clear_detached_iframe_cached_context_for_handle,
- detached_form_owner_object, detached_iframe_content_document, detached_iframe_content_window,
- detached_label_control_object, detached_shadow_root_for_host, set_detached_node_text_content,
- set_detached_text_replacement_value,
+ detached_form_owner_object, detached_label_control_object, detached_shadow_root_for_host,
+ set_detached_node_text_content, set_detached_text_replacement_value,
};
use detached_install::{
install_detached_character_data_instance_properties,
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install.rs b/moli-renderer-v8/src/native_bridge/document/detached_install.rs
index 11f8f2675..0e4e8691f 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_install.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_install.rs
@@ -9,12 +9,10 @@ mod accessors;
mod bridge_methods;
mod instance_properties;
-pub(crate) use accessors::detached_iframe_current_content_document_handle;
pub(in crate::native_bridge) use accessors::{
clear_detached_iframe_cached_context, clear_detached_iframe_cached_context_for_handle,
- detached_form_owner_object, detached_iframe_content_document, detached_iframe_content_window,
- detached_label_control_object, detached_shadow_root_for_host, set_detached_node_text_content,
- set_detached_text_replacement_value,
+ detached_form_owner_object, detached_label_control_object, detached_shadow_root_for_host,
+ set_detached_node_text_content, set_detached_text_replacement_value,
};
pub(in crate::native_bridge) use bridge_methods::install_detached_bridge_methods;
pub(in crate::native_bridge::document) use instance_properties::{
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rs
index 457e640e8..07a501bd6 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors.rs
@@ -2,25 +2,14 @@ mod attributes;
mod content;
mod document_tree_scan;
mod form_association;
-mod iframe_content;
mod iframe_content_cache;
-mod iframe_style;
-mod iframe_style_viewport;
-mod iframe_window;
-mod iframe_window_message_event;
-mod iframe_window_messaging;
mod node_text_content;
mod shadow;
-mod url_helpers;
pub(in crate::native_bridge) use self::content::set_detached_text_replacement_value;
pub(in crate::native_bridge) use self::form_association::{
detached_form_owner_object, detached_label_control_object,
};
-pub(in crate::native_bridge) use self::iframe_content::{
- detached_iframe_content_document, detached_iframe_content_window,
-};
-pub(crate) use self::iframe_content_cache::detached_iframe_current_content_document_handle;
pub(in crate::native_bridge) use self::iframe_content_cache::{
clear_detached_iframe_cached_context, clear_detached_iframe_cached_context_for_handle,
};
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content.rs
deleted file mode 100644
index d7d1be210..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content.rs
+++ /dev/null
@@ -1,166 +0,0 @@
-use crate::{
- parser::HtmlParser,
- util::{get_private_value, set_private_value, v8_string, v8str},
-};
-use url::Url;
-
-use super::super::super::{detached_owner_document_object, detached_state_object};
-use super::attributes::detached_element_attribute_value;
-use super::iframe_content_cache::{
- DETACHED_IFRAME_BASE_URL_SLOT, DETACHED_IFRAME_CONTENT_DOCUMENT_SLOT,
- DETACHED_IFRAME_CONTENT_WINDOW_SLOT, detached_iframe_cache_object,
- detached_iframe_has_cached_content_document, detached_iframe_runtime_and_handle,
- live_child_browsing_context_handle_for_detached_iframe,
-};
-use super::iframe_window::build_detached_iframe_content_window;
-use super::url_helpers::resolve_detached_url_attribute;
-
-pub(in crate::native_bridge) fn detached_iframe_content_document<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<v8::Local<'s, v8::Object>> {
- let cache_object = detached_iframe_cache_object(scope, iframe).unwrap_or(iframe);
- if let Some((runtime_ptr, handle)) = detached_iframe_runtime_and_handle(scope, iframe)
- && let Some(cached) =
- unsafe { &*runtime_ptr }.cached_detached_iframe_content_document(scope, handle)
- {
- return Some(cached);
- }
- if let Some(cached) =
- get_private_value(scope, cache_object, DETACHED_IFRAME_CONTENT_DOCUMENT_SLOT)
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
- {
- return Some(cached);
- }
- if let Some((runtime_ptr, handle)) =
- live_child_browsing_context_handle_for_detached_iframe(scope, iframe)
- {
- let runtime = unsafe { &mut *runtime_ptr };
- runtime.child_browsing_context_window_wrapper(scope, handle)?;
- return runtime.child_browsing_context_document_wrapper(scope, handle);
- }
- let snapshot = detached_iframe_snapshot(scope, iframe)?;
- let parsed_base_url = snapshot_base_url(snapshot.url.clone(), &snapshot.markup);
- let base_url =
- if moli_url::is_about_blank(&snapshot.url) && moli_url::is_about_blank(&parsed_base_url) {
- detached_iframe_srcdoc_base_url(scope, iframe)?
- } else {
- parsed_base_url
- };
- let document = crate::dom_parser::parse_browsing_context_document_projection_from_source(
- scope,
- snapshot.url.clone(),
- &snapshot.markup,
- snapshot.content_type.as_deref(),
- Some(&snapshot.character_set),
- HtmlParser::with_scripting_enabled(false),
- )?;
- if let Some(base_url) = v8_string(scope, base_url.as_str()) {
- set_private_value(
- scope,
- cache_object,
- DETACHED_IFRAME_BASE_URL_SLOT,
- base_url.into(),
- );
- if let Some(state) = detached_state_object(scope, document) {
- let _ = state.set(scope, v8str(scope, "baseURI").into(), base_url.into());
- }
- }
- set_private_value(
- scope,
- cache_object,
- DETACHED_IFRAME_CONTENT_DOCUMENT_SLOT,
- document.into(),
- );
- if let Some((runtime_ptr, handle)) = detached_iframe_runtime_and_handle(scope, iframe) {
- unsafe { &mut *runtime_ptr }
- .set_cached_detached_iframe_content_document(scope, handle, document);
- }
- Some(document)
-}
-
-pub(in crate::native_bridge) fn detached_iframe_content_window<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<v8::Local<'s, v8::Object>> {
- let cache_object = detached_iframe_cache_object(scope, iframe).unwrap_or(iframe);
- if let Some((runtime_ptr, handle)) = detached_iframe_runtime_and_handle(scope, iframe)
- && let Some(cached) =
- unsafe { &*runtime_ptr }.cached_detached_iframe_content_window(scope, handle)
- {
- return Some(cached);
- }
- if let Some(cached) =
- get_private_value(scope, cache_object, DETACHED_IFRAME_CONTENT_WINDOW_SLOT)
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
- {
- return Some(cached);
- }
- if !detached_iframe_has_cached_content_document(scope, iframe, cache_object)
- && let Some((runtime_ptr, handle)) =
- live_child_browsing_context_handle_for_detached_iframe(scope, iframe)
- {
- return unsafe { &mut *runtime_ptr }.child_browsing_context_window_wrapper(scope, handle);
- }
- let document = detached_iframe_content_document(scope, iframe)?;
- let base_url = get_private_value(scope, cache_object, DETACHED_IFRAME_BASE_URL_SLOT)
- .or_else(|| document.get(scope, v8str(scope, "baseURI").into()))
- .and_then(|value| value.to_string(scope))
- .map(|value| value.to_rust_string_lossy(scope))
- .and_then(|value| Url::parse(&value).ok())?;
- let window = build_detached_iframe_content_window(scope, iframe, document, &base_url)?;
- set_private_value(
- scope,
- cache_object,
- DETACHED_IFRAME_CONTENT_WINDOW_SLOT,
- window.into(),
- );
- if let Some((runtime_ptr, handle)) = detached_iframe_runtime_and_handle(scope, iframe) {
- unsafe { &mut *runtime_ptr }
- .set_cached_detached_iframe_content_window(scope, handle, window);
- }
- Some(window)
-}
-
-fn detached_iframe_snapshot<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<crate::native_bridge::ChildBrowsingContextSnapshot> {
- if let Some(srcdoc) =
- detached_element_attribute_value(scope, iframe, "srcdoc").filter(|value| !value.is_empty())
- {
- return Some(crate::native_bridge::ChildBrowsingContextSnapshot::html(
- detached_iframe_srcdoc_base_url(scope, iframe)?,
- srcdoc,
- ));
- }
- let target = detached_element_attribute_value(scope, iframe, "src")
- .filter(|src| !src.trim().is_empty())
- .map(|src| resolve_detached_url_attribute(scope, iframe, &src))
- .unwrap_or_else(|| "about:blank".to_owned());
- let url = Url::parse(&target).ok()?;
- let (host_ptr, handle) = detached_iframe_runtime_and_handle(scope, iframe)?;
- let host = unsafe { &*host_ptr };
- host.materialize_child_snapshot_for_url_blocking(handle, &url)
-}
-
-fn detached_iframe_srcdoc_base_url<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<Url> {
- detached_owner_document_object(scope, iframe)
- .and_then(|document| document.get(scope, v8str(scope, "baseURI").into()))
- .and_then(|value| value.to_string(scope))
- .map(|value| value.to_rust_string_lossy(scope))
- .and_then(|value| Url::parse(&value).ok())
- .or_else(|| Url::parse("about:blank").ok())
-}
-
-fn snapshot_base_url(document_url: Url, markup: &str) -> Url {
- let document =
- HtmlParser::with_scripting_enabled(false).parse(document_url.clone(), markup.to_owned());
- document
- .document()
- .map(|doc| doc.base_url().clone())
- .unwrap_or(document_url)
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content_cache.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content_cache.rs
index 2ff561f7e..8916bed83 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content_cache.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content_cache.rs
@@ -3,15 +3,11 @@ use crate::{
util::{context_host_ptr_from_global_bridge, get_private_value, set_private_value},
};
-use super::super::super::{
- detached_native_handle_for_runtime, detached_native_object_for_handle,
- detached_owner_document_object,
-};
+use super::super::super::{detached_native_handle_for_runtime, detached_native_object_for_handle};
pub(super) const DETACHED_IFRAME_CONTENT_DOCUMENT_SLOT: &str = "__lmDetachedIframeContentDocument";
pub(super) const DETACHED_IFRAME_BASE_URL_SLOT: &str = "__lmDetachedIframeBaseUrl";
pub(super) const DETACHED_IFRAME_CONTENT_WINDOW_SLOT: &str = "__lmDetachedIframeContentWindow";
-pub(super) const CHILD_DOCUMENT_CONTEXT_HANDLE_SLOT: &str = "__lmChildDocumentContextHandle";
pub(crate) fn detached_iframe_current_content_document_handle<'s>(
scope: &mut v8::PinScope<'s, '_>,
@@ -69,23 +65,6 @@ pub(in crate::native_bridge) fn clear_detached_iframe_cached_context_for_handle<
}
}
-pub(super) fn detached_iframe_has_cached_content_document<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
- cache_object: v8::Local<'s, v8::Object>,
-) -> bool {
- if let Some((runtime_ptr, handle)) = detached_iframe_runtime_and_handle(scope, iframe)
- && unsafe { &*runtime_ptr }
- .cached_detached_iframe_content_document(scope, handle)
- .is_some()
- {
- return true;
- }
- get_private_value(scope, cache_object, DETACHED_IFRAME_CONTENT_DOCUMENT_SLOT)
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
- .is_some()
-}
-
pub(super) fn detached_iframe_cache_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
iframe: v8::Local<'s, v8::Object>,
@@ -106,31 +85,6 @@ pub(super) fn detached_iframe_runtime_and_handle<'s>(
Some((runtime_ptr, handle))
}
-pub(super) fn live_child_browsing_context_handle_for_detached_iframe<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<(*mut crate::native_bridge::JsContextHost, DomHandle)> {
- let owner_document = detached_owner_document_object(scope, iframe)?;
- get_private_value(scope, owner_document, CHILD_DOCUMENT_CONTEXT_HANDLE_SLOT)?;
- let runtime_ptr = context_host_ptr_from_global_bridge(scope)?;
- let handle = detached_native_handle_for_runtime(scope, runtime_ptr, iframe)?;
- let runtime = unsafe { &mut *runtime_ptr };
- if !runtime.child_browsing_context_is_live(handle) {
- return None;
- }
- if runtime
- .existing_child_browsing_context_window_wrapper(scope, handle)
- .is_none()
- && runtime
- .child_browsing_context_document_handle(handle)
- .is_none()
- {
- return None;
- }
- runtime.refresh_child_browsing_context(scope, handle);
- Some((runtime_ptr, handle))
-}
-
fn clear_cached_detached_iframe_content_surfaces<'s>(
scope: &mut v8::PinScope<'s, '_>,
iframe: v8::Local<'s, v8::Object>,
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_style.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_style.rs
deleted file mode 100644
index d7f119b46..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_style.rs
+++ /dev/null
@@ -1,147 +0,0 @@
-use crate::{
- native_bridge::{
- ComputedStyleDescriptor, ComputedStyleTargetKey,
- element::{
- STYLE_DECLARATION_FORCED_EMPTY_COMPUTED_SLOT, STYLE_DECLARATION_PSEUDO_ELEMENT_SLOT,
- STYLE_DECLARATION_READ_DOCUMENT_SLOT, STYLE_DECLARATION_SCREEN_HEIGHT_SLOT,
- STYLE_DECLARATION_SCREEN_WIDTH_SLOT, STYLE_DECLARATION_TARGET_CONTEXT_EPOCH_SLOT,
- STYLE_DECLARATION_TARGET_EMPTY_COMPUTED_SLOT, STYLE_DECLARATION_VIEWPORT_WIDTH_SLOT,
- },
- },
- util::{context_host_ptr_from_global_bridge, set_private_value, v8_string},
-};
-use moli_webapi_declare::WebApiObject;
-
-use super::super::super::detached_native_handle_for_runtime;
-use super::iframe_style_viewport::detached_iframe_viewport_width;
-
-#[derive(WebApiObject)]
-#[webapi(plain)]
-struct DetachedIframeWindowComputedStyleMethodDeclaration<'scope> {
- iframe: v8::Local<'scope, v8::Object>,
- #[webapi(
- method,
- length = 1,
- callback = detached_iframe_get_computed_style_callback,
- data = self.iframe
- )]
- get_computed_style: (),
-}
-
-pub(super) fn install_detached_iframe_get_computed_style<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
- iframe: v8::Local<'s, v8::Object>,
-) {
- let _ =
- DetachedIframeWindowComputedStyleMethodDeclaration::new(iframe).initialize(scope, window);
-}
-
-fn detached_iframe_get_computed_style_callback<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: v8::FunctionCallbackArguments<'s>,
- mut rv: v8::ReturnValue<'_, v8::Value>,
-) {
- let Some(parsed) =
- crate::webidl::parse_args::<crate::window_host::GetComputedStyleArgs>(scope, &args)
- else {
- return;
- };
- let Some(runtime_ptr) = context_host_ptr_from_global_bridge(scope) else {
- rv.set_null();
- return;
- };
- let Ok(iframe) = v8::Local::<v8::Object>::try_from(args.data()) else {
- rv.set_null();
- return;
- };
- let Some(target) = detached_native_handle_for_runtime(scope, runtime_ptr, parsed.element)
- else {
- rv.set_null();
- return;
- };
- let crate::window_host::ComputedStylePseudoArgument {
- forced_empty,
- pseudo_element,
- pseudo_key,
- } = parsed.pseudo_argument();
- let target_key = detached_native_handle_for_runtime(scope, runtime_ptr, iframe)
- .map(ComputedStyleTargetKey::DetachedIframe)
- .unwrap_or(ComputedStyleTargetKey::Dynamic);
- let descriptor = ComputedStyleDescriptor::new(pseudo_key, target_key);
- let read_document = unsafe { &*runtime_ptr }
- .dom_host()
- .node(target)
- .and_then(crate::dom::native::Node::owner_document);
- let host = unsafe { &mut *runtime_ptr };
- let Some(style) =
- host.native_bridge_mut()
- .create_computed_style(scope, runtime_ptr, target, descriptor)
- else {
- rv.set_null();
- return;
- };
- set_private_value(
- scope,
- style,
- STYLE_DECLARATION_FORCED_EMPTY_COMPUTED_SLOT,
- v8::Boolean::new(scope, forced_empty).into(),
- );
- set_private_value(
- scope,
- style,
- STYLE_DECLARATION_TARGET_EMPTY_COMPUTED_SLOT,
- v8::Boolean::new(scope, false).into(),
- );
- set_private_value(
- scope,
- style,
- STYLE_DECLARATION_TARGET_CONTEXT_EPOCH_SLOT,
- v8::undefined(scope).into(),
- );
- let read_document = read_document
- .map(|handle| v8::Integer::new_from_unsigned(scope, handle.index_u32()).into())
- .unwrap_or_else(|| v8::undefined(scope).into());
- set_private_value(
- scope,
- style,
- STYLE_DECLARATION_READ_DOCUMENT_SLOT,
- read_document,
- );
- let pseudo_value = pseudo_element
- .as_deref()
- .and_then(|pseudo_element| v8_string(scope, pseudo_element).map(Into::into))
- .unwrap_or_else(|| v8::undefined(scope).into());
- set_private_value(
- scope,
- style,
- STYLE_DECLARATION_PSEUDO_ELEMENT_SLOT,
- pseudo_value,
- );
- let width = detached_iframe_viewport_width(scope, iframe)
- .map(|width| v8::Number::new(scope, width).into())
- .unwrap_or_else(|| v8::undefined(scope).into());
- set_private_value(scope, style, STYLE_DECLARATION_VIEWPORT_WIDTH_SLOT, width);
- let viewport = host.style_viewport();
- let screen_width = viewport
- .screen_width
- .map(|width| v8::Number::new(scope, width).into())
- .unwrap_or_else(|| v8::undefined(scope).into());
- set_private_value(
- scope,
- style,
- STYLE_DECLARATION_SCREEN_WIDTH_SLOT,
- screen_width,
- );
- let screen_height = viewport
- .screen_height
- .map(|height| v8::Number::new(scope, height).into())
- .unwrap_or_else(|| v8::undefined(scope).into());
- set_private_value(
- scope,
- style,
- STYLE_DECLARATION_SCREEN_HEIGHT_SLOT,
- screen_height,
- );
- rv.set(style.into());
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_style_viewport.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_style_viewport.rs
deleted file mode 100644
index 52af560aa..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_style_viewport.rs
+++ /dev/null
@@ -1,115 +0,0 @@
-use crate::{
- css_style::parse_css_declaration_list,
- document_runtime::DomHandle,
- util::{context_host_ptr_from_global_bridge, get_private_value},
-};
-
-use super::super::super::detached_owner_document_object;
-use super::attributes::detached_element_attribute_value;
-use super::iframe_content_cache::CHILD_DOCUMENT_CONTEXT_HANDLE_SLOT;
-
-pub(super) fn detached_iframe_viewport_width<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<f64> {
- if let Some(width) = detached_numeric_attribute(scope, iframe, "width") {
- return Some(width);
- }
- let owner_width = detached_iframe_owner_viewport_width(scope, iframe);
- if let Some(width) = detached_style_width_px(scope, iframe) {
- return Some(width);
- }
- if let Some(percent) = detached_style_width_percent(scope, iframe)
- && let Some(owner_width) = owner_width
- {
- return Some(owner_width * percent / 100.0);
- }
- owner_width
-}
-
-fn detached_iframe_owner_viewport_width<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<f64> {
- let owner_document = detached_owner_document_object(scope, iframe)?;
- let child_handle_value =
- get_private_value(scope, owner_document, CHILD_DOCUMENT_CONTEXT_HANDLE_SLOT)?;
- let child_handle_bigint = v8::Local::<v8::BigInt>::try_from(child_handle_value).ok()?;
- let (child_handle_index, child_handle_lossless) = child_handle_bigint.u64_value();
- let child_handle =
- child_handle_lossless.then(|| DomHandle::new(child_handle_index as usize))?;
- let runtime_ptr = context_host_ptr_from_global_bridge(scope)?;
- unsafe { &*runtime_ptr }
- .dom_host()
- .get_attribute(child_handle, "width")
- .and_then(|value| parse_positive_css_number(&value))
-}
-
-fn detached_numeric_attribute<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- element: v8::Local<'s, v8::Object>,
- name: &str,
-) -> Option<f64> {
- detached_element_attribute_value(scope, element, name)
- .and_then(|value| parse_positive_css_number(&value))
-}
-
-fn detached_style_width_px<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- element: v8::Local<'s, v8::Object>,
-) -> Option<f64> {
- parse_css_px(&detached_style_width(scope, element)?)
-}
-
-fn detached_style_width_percent<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- element: v8::Local<'s, v8::Object>,
-) -> Option<f64> {
- parse_css_percent(&detached_style_width(scope, element)?)
-}
-
-fn detached_style_width<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- element: v8::Local<'s, v8::Object>,
-) -> Option<String> {
- let style = detached_element_attribute_value(scope, element, "style")?;
- parse_css_declaration_list(&style)
- .into_iter()
- .find_map(|entry| {
- entry
- .name
- .eq_ignore_ascii_case("width")
- .then_some(entry.value)
- })
-}
-
-fn parse_css_px(value: &str) -> Option<f64> {
- let value = value.trim();
- if value == "0" {
- return Some(0.0);
- }
- value
- .strip_suffix("px")?
- .trim()
- .parse::<f64>()
- .ok()
- .filter(|value| value.is_finite() && *value >= 0.0)
-}
-
-fn parse_css_percent(value: &str) -> Option<f64> {
- value
- .trim()
- .strip_suffix('%')?
- .trim()
- .parse::<f64>()
- .ok()
- .filter(|value| value.is_finite() && *value >= 0.0)
-}
-
-fn parse_positive_css_number(value: &str) -> Option<f64> {
- value
- .trim()
- .parse::<f64>()
- .ok()
- .filter(|value| value.is_finite() && *value > 0.0)
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window.rs
deleted file mode 100644
index 27de69593..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window.rs
+++ /dev/null
@@ -1,62 +0,0 @@
-use crate::util::v8str;
-use crate::web_api_interfaces;
-use moli_webapi_declare::WebApiObject;
-use url::Url;
-
-use crate::native_bridge::document::set_document_associated_window;
-
-use super::super::super::detached_owner_document_object;
-use super::iframe_style::install_detached_iframe_get_computed_style;
-use super::iframe_window_messaging::install_detached_iframe_window_messaging;
-
-#[derive(WebApiObject)]
-#[webapi(
- interface = web_api_interfaces::Window,
- prototype = "Object",
- own_to_string_tag = "Window"
-)]
-struct DetachedIframeWindowDeclaration<'scope> {
- #[webapi(data_property = "self", value = object)]
- self_value: (),
- #[webapi(data_property, value = object)]
- window: (),
- #[webapi(data_property, value = object)]
- frames: (),
- #[webapi(data_property)]
- parent: v8::Local<'scope, v8::Object>,
- #[webapi(data_property)]
- top: v8::Local<'scope, v8::Object>,
- #[webapi(data_property)]
- document: v8::Local<'scope, v8::Object>,
-}
-
-pub(super) fn build_detached_iframe_content_window<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
- document: v8::Local<'s, v8::Object>,
- base_url: &Url,
-) -> Option<v8::Local<'s, v8::Object>> {
- let parent = detached_iframe_parent_window(scope, iframe)
- .unwrap_or_else(|| scope.get_current_context().global(scope));
- let top = parent
- .get(scope, v8str(scope, "top").into())
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
- .unwrap_or(parent);
- let window = DetachedIframeWindowDeclaration::new(parent, top, document)
- .bind(scope)
- .ok()?;
- set_document_associated_window(scope, document, window);
- crate::network_host::install_fetch_constructors_for_base_url(scope, window, base_url);
- install_detached_iframe_window_messaging(scope, window);
- install_detached_iframe_get_computed_style(scope, window, iframe);
- Some(window)
-}
-
-fn detached_iframe_parent_window<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- iframe: v8::Local<'s, v8::Object>,
-) -> Option<v8::Local<'s, v8::Object>> {
- detached_owner_document_object(scope, iframe)?
- .get(scope, v8str(scope, "defaultView").into())
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window_message_event.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window_message_event.rs
deleted file mode 100644
index 5819d9ab6..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window_message_event.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-use crate::util::v8str;
-use url::Url;
-
-pub(super) fn detached_window_origin(
- scope: &mut v8::PinScope<'_, '_>,
- window: v8::Local<'_, v8::Object>,
-) -> Option<String> {
- let document = window
- .get(scope, v8str(scope, "document").into())
- .and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())?;
- let url = document
- .get(scope, v8str(scope, "URL").into())
- .or_else(|| document.get(scope, v8str(scope, "baseURI").into()))
- .and_then(|value| value.to_string(scope))
- .map(|value| value.to_rust_string_lossy(scope))
- .and_then(|value| Url::parse(&value).ok())?;
- Some(moli_url::origin_ascii_serialization(&url))
-}
-
-pub(super) fn detached_window_message_event<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- event_type: &str,
- data: v8::Local<'s, v8::Value>,
- source: v8::Local<'s, v8::Value>,
- origin: &str,
- ports: v8::Local<'s, v8::Array>,
-) -> Option<v8::Local<'s, v8::Object>> {
- crate::context_bootstrap::construct_original_message_event(
- scope,
- event_type,
- data,
- origin,
- &[],
- source,
- ports,
- )
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window_messaging.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window_messaging.rs
deleted file mode 100644
index 5021d2952..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_window_messaging.rs
+++ /dev/null
@@ -1,133 +0,0 @@
-use crate::{
- context_bootstrap::{
- dispatch_simple_event_target_event, install_child_window_eval_runtime_state,
- install_child_window_own_methods, install_simple_event_target_methods,
- install_simple_window_event_handlers,
- },
- util::v8str,
-};
-use moli_webapi_declare::WebApiObject;
-
-use super::iframe_window_message_event::{detached_window_message_event, detached_window_origin};
-
-#[derive(Default, WebApiObject)]
-#[webapi(plain)]
-struct DetachedIframeWindowMethodsDeclaration {
- #[webapi(method, length = 1, callback = detached_iframe_window_post_message)]
- post_message: (),
-}
-
-pub(super) fn install_detached_iframe_window_messaging<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
-) {
- install_simple_event_target_methods(scope, window);
- install_simple_window_event_handlers(scope, window);
- let _ = DetachedIframeWindowMethodsDeclaration::default().initialize(scope, window);
- let _ = install_child_window_own_methods(scope, window);
- let _ = install_child_window_eval_runtime_state(scope, window);
-}
-
-fn detached_iframe_window_post_message<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- args: v8::FunctionCallbackArguments<'s>,
- mut rv: v8::ReturnValue<'_, v8::Value>,
-) {
- let target = args.this();
- let target_origin_arg = args.get(1);
- let options = (target_origin_arg.is_object() && !target_origin_arg.is_null_or_undefined())
- .then(|| v8::Local::<v8::Object>::try_from(target_origin_arg).ok())
- .flatten();
- let requested_target_origin = if let Some(options) = options {
- options
- .get(scope, v8str(scope, "targetOrigin").into())
- .and_then(|value| {
- if value.is_undefined() {
- None
- } else {
- value
- .to_string(scope)
- .map(|value| value.to_rust_string_lossy(scope))
- }
- })
- .unwrap_or_else(|| "/".to_owned())
- } else if target_origin_arg.is_undefined() {
- "/".to_owned()
- } else {
- target_origin_arg
- .to_string(scope)
- .map(|value| value.to_rust_string_lossy(scope))
- .unwrap_or_else(|| "*".to_owned())
- };
- let source = target
- .get(scope, v8str(scope, "parent").into())
- .unwrap_or_else(|| scope.get_current_context().global(scope).into());
- let source_origin = v8::Local::<v8::Object>::try_from(source)
- .ok()
- .and_then(|source| detached_window_origin(scope, source))
- .unwrap_or_default();
- let target_origin = detached_window_origin(scope, target).unwrap_or_default();
- let source_security =
- crate::context_bootstrap::RuntimeMessageSourceSecurity::window(source_origin.clone());
- let Some(target_origin_match) =
- crate::window_host::normalized_window_post_message_target_origin(
- scope,
- &requested_target_origin,
- &source_origin,
- )
- else {
- return;
- };
- if !crate::window_host::target_origin_matches(target_origin_match.as_deref(), &target_origin) {
- rv.set_undefined();
- return;
- }
- let data = if options.is_some() {
- crate::context_bootstrap::structured_serialize_value_for_window_post_message_options(
- scope,
- args.get(0),
- args.get(1),
- source_security,
- )
- } else {
- crate::context_bootstrap::structured_serialize_value_for_window_post_message(
- scope,
- args.get(0),
- (args.length() > 2).then(|| args.get(2)),
- source_security,
- )
- };
- let Some(data) = data else {
- return;
- };
- let target_accepts_data =
- crate::context_bootstrap::wasm_module_message_allowed_for_target_origin(
- &data,
- Some(&target_origin),
- );
- let (event_type, data, ports) = if target_accepts_data {
- match crate::context_bootstrap::structured_deserialize_value_for_message_event(scope, &data)
- {
- Some((data, ports)) => ("message", data, ports),
- None => (
- "messageerror",
- v8::null(scope).into(),
- v8::Array::new(scope, 0),
- ),
- }
- } else {
- (
- "messageerror",
- v8::null(scope).into(),
- v8::Array::new(scope, 0),
- )
- };
- let Some(event) =
- detached_window_message_event(scope, event_type, data, source, &source_origin, ports)
- else {
- rv.set_undefined();
- return;
- };
- dispatch_simple_event_target_event(scope, target, event_type, event);
- rv.set_undefined();
-}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/url_helpers.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/url_helpers.rs
deleted file mode 100644
index e1a9c37d0..000000000
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/url_helpers.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-use super::super::super::detached_owner_document_object;
-
-pub(super) fn resolve_detached_url_attribute<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- element: v8::Local<'s, v8::Object>,
- value: &str,
-) -> String {
- let base = detached_owner_document_object(scope, element)
- .map(|document| {
- super::super::super::detached_document_state_string(
- scope,
- document,
- "baseURI",
- "about:blank",
- )
- })
- .unwrap_or_else(|| "about:blank".to_owned());
- let base = url::Url::parse(&base).ok();
- url::Url::options()
- .base_url(base.as_ref())
- .parse(value)
- .map(|url| url.to_string())
- .unwrap_or_else(|_| value.to_owned())
-}
diff --git a/moli-renderer-v8/src/native_bridge/element.rs b/moli-renderer-v8/src/native_bridge/element.rs
index 20d1a3835..6beab4440 100644
--- a/moli-renderer-v8/src/native_bridge/element.rs
+++ b/moli-renderer-v8/src/native_bridge/element.rs
@@ -185,7 +185,6 @@ pub(crate) use styles::{
use super::document::{
clear_detached_iframe_cached_context, clear_detached_iframe_cached_context_for_handle,
- detached_iframe_content_document, detached_iframe_content_window,
detached_shadow_root_selection_value, node_shadow_root_element_from_point_callback,
node_shadow_root_elements_from_point_callback,
};
@@ -664,10 +663,10 @@ pub(super) use tree_mutation::{
pub(in crate::native_bridge) use url_attributes::parse_url_with_document_query_encoding;
pub(super) use url_attributes::update_iframe_snapshot_navigation;
use url_attributes::{
- disconnected_iframe_can_materialize_detached_content, iframe_has_inactive_child_context,
- iframe_is_in_own_child_document, iframe_is_inside_its_own_child_context_document,
- iframe_uses_detached_content_cache, parsed_url_like_attribute, resolve_url_like_attribute,
- set_resolved_url_attribute, should_block_dangling_markup_subresource,
+ iframe_has_inactive_child_context, iframe_is_in_own_child_document,
+ iframe_is_inside_its_own_child_context_document, iframe_uses_detached_content_cache,
+ parsed_url_like_attribute, resolve_url_like_attribute, set_resolved_url_attribute,
+ should_block_dangling_markup_subresource,
};
pub(in crate::native_bridge) fn set_live_element_attribute_appending_to_current_reaction_queue(
diff --git a/moli-renderer-v8/src/native_bridge/element/resource_elements.rs b/moli-renderer-v8/src/native_bridge/element/resource_elements.rs
index 560842184..7a080265d 100644
--- a/moli-renderer-v8/src/native_bridge/element/resource_elements.rs
+++ b/moli-renderer-v8/src/native_bridge/element/resource_elements.rs
@@ -1349,13 +1349,7 @@ fn frame_owner_content_document<'s>(
if iframe_uses_detached_content_cache(runtime, handle)
|| !runtime.dom_host().is_connected(handle)
{
- return if iframe_uses_detached_content_cache(runtime, handle)
- || disconnected_iframe_can_materialize_detached_content(runtime, handle)
- {
- detached_iframe_content_document(scope, receiver)
- } else {
- None
- };
+ return None;
}
unsafe { &mut *runtime_ptr }.frame_owner_content_document_wrapper(scope, handle)
}
@@ -1387,16 +1381,7 @@ pub(super) fn frame_owner_content_window_getter_function<'s>(
if iframe_uses_detached_content_cache(runtime, handle)
|| !runtime.dom_host().is_connected(handle)
{
- if iframe_uses_detached_content_cache(runtime, handle)
- || disconnected_iframe_can_materialize_detached_content(runtime, handle)
- {
- match detached_iframe_content_window(scope, receiver) {
- Some(window) => rv.set(window.into()),
- None => rv.set_null(),
- }
- } else {
- rv.set_null();
- }
+ rv.set_null();
return;
}
let runtime = unsafe { &mut *runtime_ptr };
diff --git a/moli-renderer-v8/src/native_bridge/element/styles.rs b/moli-renderer-v8/src/native_bridge/element/styles.rs
index 69e7bb316..f783440a0 100644
--- a/moli-renderer-v8/src/native_bridge/element/styles.rs
+++ b/moli-renderer-v8/src/native_bridge/element/styles.rs
@@ -127,15 +127,6 @@ fn style_object_forces_empty_computed<'s>(
cache_computed_viewport(scope, style, (!empty).then(|| context.viewport(runtime)));
empty
}
- ComputedStyleTargetKey::DetachedIframe(frame_handle) => {
- !detached_iframe_target_document_is_current(
- scope,
- runtime_ptr,
- style,
- handle,
- frame_handle,
- )
- }
ComputedStyleTargetKey::PopupDocument(document_handle) => {
!popup_document_target_is_current(unsafe { &*runtime_ptr }, handle, document_handle)
}
@@ -167,28 +158,6 @@ fn popup_document_target_is_current(
.is_some_and(|popup_id| runtime.lightweight_popup_is_open(popup_id))
}
-fn detached_iframe_target_document_is_current<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- runtime_ptr: *mut JsContextHost,
- style: v8::Local<'s, v8::Object>,
- target: DomHandle,
- frame_handle: DomHandle,
-) -> bool {
- let runtime = unsafe { &*runtime_ptr };
- let read_document = style_object_read_document(scope, style);
- let owner_document = runtime
- .dom_host()
- .node(target)
- .and_then(crate::dom::native::Node::owner_document);
- let target_document = read_document.or(owner_document);
- crate::native_bridge::document::detached_iframe_current_content_document_handle(
- scope,
- runtime_ptr,
- frame_handle,
- )
- .is_some_and(|document| Some(document) == target_document)
-}
-
fn target_context_epoch_is_current<'s>(
scope: &mut v8::PinScope<'s, '_>,
runtime: &JsContextHost,
@@ -373,9 +342,7 @@ fn live_computed_style_viewport<'s>(
let document = runtime.dom_host().owner_document_handle(handle)?;
Some(style_viewport_for_document(runtime, document))
}
- ComputedStyleTargetKey::DetachedIframe(_) | ComputedStyleTargetKey::PopupDocument(_) => {
- None
- }
+ ComputedStyleTargetKey::PopupDocument(_) => None,
}
}
diff --git a/moli-renderer-v8/src/native_bridge/element/url_attributes.rs b/moli-renderer-v8/src/native_bridge/element/url_attributes.rs
index aada64160..1c41a07af 100644
--- a/moli-renderer-v8/src/native_bridge/element/url_attributes.rs
+++ b/moli-renderer-v8/src/native_bridge/element/url_attributes.rs
@@ -8,7 +8,6 @@ pub(super) use self::helpers::{
};
pub(in crate::native_bridge) use self::iframe::update_iframe_snapshot_navigation;
pub(super) use self::iframe::{
- disconnected_iframe_can_materialize_detached_content, iframe_has_inactive_child_context,
- iframe_is_in_own_child_document, iframe_is_inside_its_own_child_context_document,
- iframe_uses_detached_content_cache,
+ iframe_has_inactive_child_context, iframe_is_in_own_child_document,
+ iframe_is_inside_its_own_child_context_document, iframe_uses_detached_content_cache,
};
diff --git a/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs b/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs
index bde955ffa..de9199f5b 100644
--- a/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs
+++ b/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs
@@ -85,13 +85,6 @@ fn iframe_navigation_target(runtime: &JsContextHost, handle: DomHandle) -> Strin
}
}
-pub(in crate::native_bridge::element) fn disconnected_iframe_can_materialize_detached_content(
- runtime: &JsContextHost,
- handle: DomHandle,
-) -> bool {
- !runtime.dom_host().is_connected(handle) && iframe_uses_detached_content_cache(runtime, handle)
-}
-
pub(in crate::native_bridge::element) fn iframe_uses_detached_content_cache(
runtime: &JsContextHost,
handle: DomHandle,
diff --git a/moli-renderer-v8/src/native_bridge/identity.rs b/moli-renderer-v8/src/native_bridge/identity.rs
index cd18509b0..950aebcc5 100644
--- a/moli-renderer-v8/src/native_bridge/identity.rs
+++ b/moli-renderer-v8/src/native_bridge/identity.rs
@@ -144,7 +144,6 @@ fn functional_pseudo_name<'a>(pseudo_element: &'a str, function_name: &str) -> O
pub(crate) enum ComputedStyleTargetKey {
Dynamic,
ChildFrame(DomHandle),
- DetachedIframe(DomHandle),
PopupDocument(DomHandle),
}
diff --git a/moli-renderer-v8/src/network/request_client.rs b/moli-renderer-v8/src/network/request_client.rs
index e5fc6d993..4fdec45a5 100644
--- a/moli-renderer-v8/src/network/request_client.rs
+++ b/moli-renderer-v8/src/network/request_client.rs
@@ -909,25 +909,6 @@ impl ResourceRequestClient {
.context("worker script fetch thread dropped response channel")?
}
- pub(crate) fn fetch_raw_for_blocking_boundary(&self, request: Request) -> Result<RawResponse> {
- let request_client = self.clone();
- let (response_tx, response_rx) = mpsc::sync_channel(1);
- thread::Builder::new()
- .name("lm-blocking-raw-fetch".to_owned())
- .spawn(move || {
- let result = tokio::runtime::Builder::new_current_thread()
- .enable_all()
- .build()
- .context("failed to build blocking raw fetch runtime")
- .and_then(|runtime| runtime.block_on(request_client.fetch_raw(request)));
- let _ = response_tx.send(result);
- })
- .context("failed to spawn blocking raw fetch thread")?;
- response_rx
- .recv()
- .context("blocking raw fetch thread dropped response channel")?
- }
-
async fn fetch_with_optional_cancel(
&self,
request: Request,
diff --git a/moli-renderer-v8/src/network_host.rs b/moli-renderer-v8/src/network_host.rs
index 350ee40f1..a8c61ccdc 100644
--- a/moli-renderer-v8/src/network_host.rs
+++ b/moli-renderer-v8/src/network_host.rs
@@ -22,7 +22,6 @@ mod url_helpers;
mod xhr;
use moli_fetch::{Request, Response, observe_cookie_access_report_for_request};
-use moli_webapi_declare::WebApiObject;
use crate::network::ResourceRequestClient;
@@ -88,7 +87,7 @@ pub(in crate::network_host) use self::fetch_surface::{
REQUEST_IS_HISTORY_NAVIGATION_SLOT, REQUEST_IS_RELOAD_NAVIGATION_SLOT, REQUEST_KEEPALIVE_SLOT,
REQUEST_METHOD_SLOT, REQUEST_MODE_SLOT, REQUEST_PRIORITY_SLOT, REQUEST_REDIRECT_SLOT,
REQUEST_REFERRER_POLICY_SLOT, REQUEST_REFERRER_SLOT, REQUEST_SIGNAL_SLOT,
- constructor_prototype, new_abort_signal_for_request_with_source,
+ new_abort_signal_for_request_with_source,
};
pub(crate) use self::fetch_surface::{
REQUEST_URL_SLOT, is_branded_request_object, request_headers_entries, request_method,
@@ -207,85 +206,6 @@ pub(crate) const FAILED_ERROR_TEXT: &str = "net::ERR_FAILED";
pub(crate) use crate::protocol_types::extract_subresource_auth_challenge;
pub(crate) use moli_fetch::NET_ERR_ABORTED_ERROR_TEXT as ABORTED_ERROR_TEXT;
-#[derive(WebApiObject)]
-#[webapi(fragment, prototype = "Response")]
-struct ChildResponseConstructorDeclaration<'scope> {
- data: v8::Local<'scope, v8::Value>,
-
- #[webapi(
- method = "redirect",
- length = 1,
- callback = self::fetch_surface::response_static_redirect_callback,
- data = self.data
- )]
- redirect: (),
-}
-
-pub(crate) fn install_fetch_constructors_for_base_url<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
- base_url: &url::Url,
-) {
- let Some(data) = v8_string(scope, base_url.as_str()).map(Into::into) else {
- return;
- };
- install_fetch_constructors_with_data(scope, window, data);
-}
-
-fn install_fetch_constructors_with_data<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- window: v8::Local<'s, v8::Object>,
- data: v8::Local<'s, v8::Value>,
-) {
- let global = scope.get_current_context().global(scope);
- let parent_request = window
- .get(scope, v8str(scope, "Request").into())
- .or_else(|| global.get(scope, v8str(scope, "Request").into()))
- .and_then(|value| v8::Local::<v8::Function>::try_from(value).ok());
- if let Some(request) = v8::Function::builder(request_constructor_callback)
- .length(1)
- .data(data)
- .build(scope)
- {
- let prototype = parent_request
- .and_then(|parent_request| parent_request.get(scope, v8str(scope, "prototype").into()))
- .or_else(|| constructor_prototype(scope, global, "Request").map(Into::into));
- if let Some(prototype) = prototype {
- let _ = request.set(scope, v8str(scope, "prototype").into(), prototype);
- }
- let _ = window.set(scope, v8str(scope, "Request").into(), request.into());
- }
-
- let parent_response = window
- .get(scope, v8str(scope, "Response").into())
- .or_else(|| global.get(scope, v8str(scope, "Response").into()))
- .and_then(|value| v8::Local::<v8::Function>::try_from(value).ok());
- if let Some(response) = v8::Function::builder(response_constructor_callback)
- .data(data)
- .build(scope)
- {
- let prototype = parent_response
- .and_then(|parent_response| {
- parent_response.get(scope, v8str(scope, "prototype").into())
- })
- .or_else(|| constructor_prototype(scope, global, "Response").map(Into::into));
- if let Some(prototype) = prototype {
- let _ = response.set(scope, v8str(scope, "prototype").into(), prototype);
- }
- if let Some(parent_response) = parent_response {
- for name in ["error", "json"] {
- if let Some(value) = parent_response.get(scope, v8str(scope, name).into()) {
- let _ = response.set(scope, v8str(scope, name).into(), value);
- }
- }
- }
- ChildResponseConstructorDeclaration::new(data)
- .initialize(scope, response.into())
- .expect("child Response constructor declaration should initialize");
- let _ = window.set(scope, v8str(scope, "Response").into(), response.into());
- }
-}
-
use super::{
blob,
context_bootstrap::{new_readable_stream_from_array_buffer, new_readable_stream_from_source},
diff --git a/moli-renderer-v8/src/network_host/fetch_surface.rs b/moli-renderer-v8/src/network_host/fetch_surface.rs
index 3440c8844..5830986b7 100644
--- a/moli-renderer-v8/src/network_host/fetch_surface.rs
+++ b/moli-renderer-v8/src/network_host/fetch_surface.rs
@@ -2,7 +2,6 @@ use super::headers::{build_headers_object, headers_entries, headers_list, mark_h
use super::response::{ParsedResponseInit, install_response_body_methods};
use super::*;
use crate::context_bootstrap::readable_stream_disturbed;
-pub(in crate::network_host) use crate::util::constructor_prototype;
use crate::util::{
callback_data_index_value, callback_data_item, get_private_value, set_private_value,
throw_range_error, v8_string,
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/simple_event_target_handlers.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/simple_event_target_handlers.rs
index ac3f3ee29..809e91878 100644
--- a/moli-renderer-v8/src/script_vm/tests/browser_api/simple_event_target_handlers.rs
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/simple_event_target_handlers.rs
@@ -117,18 +117,15 @@ fn simple_window_handlers_share_dispatch_and_mutation_semantics() {
assert_eq!(
vm.eval(
r#"(() => {
- const popup = open();
- const doc = document.implementation.createHTMLDocument('');
- const frame = doc.createElement('iframe');
- doc.body.appendChild(frame);
+ const popups = [open(), open()];
try {
- for (const target of [popup, frame.contentWindow]) {
+ for (const target of popups) {
checkHandlerDispatch(target, 'message');
checkUnregisteredHandler(target);
}
- checkListenerIsolation([popup, frame.contentWindow]);
+ checkListenerIsolation(popups);
return true;
- } finally { popup.close(); }
+ } finally { for (const popup of popups) popup.close(); }
})()"#,
)
.unwrap(),
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rs
index d2b71fdac..0753f39e3 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rs
@@ -779,7 +779,7 @@ fn domparser_xml_preserves_content_type_and_document_interface_for_success_and_e
}
#[test]
-fn detached_iframe_windows_do_not_change_document_visibility() {
+fn inert_iframes_do_not_create_windows_or_change_document_visibility() {
let mut vm = new_storage_test_vm("https://detached-iframe-visibility.test/");
let result = vm
@@ -801,24 +801,10 @@ fn detached_iframe_windows_do_not_change_document_visibility() {
outer.documentElement.appendChild(frame);
const label = `${name}/${first}`;
check(outer.defaultView === null, `${label}: windowless owner`);
- let child;
- if (first === "document") {
- child = frame.contentDocument;
- check(child.hidden && child.visibilityState === "hidden", `${label}: before contentWindow`);
- }
- const view = frame.contentWindow;
- child ||= frame.contentDocument;
- check(view !== null && view.document === child, `${label}: synthetic window`);
- check(child.defaultView === view, `${label}: associated window retained`);
- check(child.hidden && child.visibilityState === "hidden", `${label}: after contentWindow`);
+ check(frame.contentDocument === null, `${label}: no child Document`);
+ check(frame.contentWindow === null, `${label}: no child Window`);
check(outer.hidden && outer.visibilityState === "hidden", `${label}: owner stays hidden`);
- const nested = child.createElement("iframe");
- nested.srcdoc = "<p>nested</p>";
- child.body.appendChild(nested);
- const nestedChild = nested.contentDocument;
- check(nestedChild.hidden && nestedChild.visibilityState === "hidden", `${label}: nested before contentWindow`);
- check(nested.contentWindow.document === nestedChild, `${label}: nested window`);
- check(nestedChild.hidden && nestedChild.visibilityState === "hidden", `${label}: nested after contentWindow`);
+
}
}
return JSON.stringify(errors);
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/legacy_resources_and_document_mutations.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/legacy_resources_and_document_mutations.rs
index e42641058..71e4fa1e0 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/legacy_resources_and_document_mutations.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/legacy_resources_and_document_mutations.rs
@@ -697,17 +697,17 @@ fn detached_specialized_url_resource_properties_use_owner_prototypes() {
iframe.srcdoc = "<!doctype html><body><p id='marker'>first</p></body>";
const firstDocument = iframe.contentDocument;
const firstWindow = iframe.contentWindow;
- assert(firstDocument.body.textContent.trim() === "first", "first srcdoc document");
- assert(firstWindow.document === firstDocument, "first contentWindow document");
+ assert(firstDocument === null, "inert iframe has no content document");
+ assert(firstWindow === null, "inert iframe has no content window");
iframe.srcdoc = "<!doctype html><body><p id='marker'>second</p></body>";
const secondDocument = iframe.contentDocument;
- assert(secondDocument.body.textContent.trim() === "second", "srcdoc clears cached document");
- assert(secondDocument !== firstDocument, "srcdoc replacement materializes new document");
+ assert(secondDocument === null, "srcdoc must not materialize an inert child document");
+ assert(iframe.contentWindow === null, "srcdoc must not materialize an inert window");
for (const name of ["src", "srcdoc", "contentDocument", "contentWindow"]) {
assert(delete iframe[name], `delete iframe ${name}`);
assert(!own(iframe, name), `iframe ${name} should stay inherited`);
}
- assert(iframe.contentDocument.body.textContent.trim() === "second", "iframe after delete");
+ assert(iframe.contentDocument === null, "iframe after delete");
return "ok";
})()
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style/computed_style_access.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style/computed_style_access.rs
index ea601ba44..410e4b7d7 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style/computed_style_access.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style/computed_style_access.rs
@@ -1470,139 +1470,28 @@ fn live_iframe_attribute_mutation_targets_computed_style_cache() {
}
#[test]
-fn held_detached_iframe_computed_style_is_empty_after_srcdoc_navigation() {
- let mut vm = new_storage_test_vm("https://detached-iframe-srcdoc-computed-style.test/");
-
- let result = vm
- .eval(
- r#"
-(() => {
- const detachedDocument = document.implementation.createHTMLDocument('');
- const frame = detachedDocument.createElement('iframe');
- frame.id = 'detached-srcdoc-navigation-frame';
- frame.srcdoc = '<style>body { color: rgb(0, 128, 0); }</style><body>first</body>';
- detachedDocument.body.appendChild(frame);
- const firstDocument = frame.contentDocument;
- const held = frame.contentWindow.getComputedStyle(firstDocument.body);
- const before = `${held.length > 0}:${held.color}`;
-
- frame.srcdoc = '<style>body { color: rgb(1, 2, 3); }</style><body>second</body>';
- const oldHeld = `${held.length}:${held.color}`;
- const secondDocument = frame.contentDocument;
- const secondHeld = frame.contentWindow.getComputedStyle(secondDocument.body);
- const secondFresh = secondHeld.color;
-
- let symbolError = 'none';
- try {
- frame.srcdoc = Symbol('srcdoc');
- } catch (error) {
- symbolError = error.name;
- }
- const afterFailedSrcdoc = `${symbolError}:${secondHeld.length > 200}:${secondHeld.color}:${frame.contentDocument === secondDocument}`;
-
- frame.removeAttribute('srcdoc');
- const secondOldHeld = `${secondHeld.length}:${secondHeld.color}`;
- const blankDocument = frame.contentDocument;
- blankDocument.body.id = 'detached-srcdoc-final-body';
- const blankFresh = frame.contentWindow.getComputedStyle(blankDocument.body).color;
- return [
- before,
- oldHeld,
- secondFresh,
- firstDocument === secondDocument,
- afterFailedSrcdoc,
- secondOldHeld,
- blankFresh,
- secondDocument === blankDocument
- ].join('|');
-})()
-"#,
- )
- .expect("held detached iframe computed style srcdoc navigation should evaluate");
-
- assert_eq!(
- result,
- "true:rgb(0, 128, 0)|0:|rgb(1, 2, 3)|false|TypeError:true:rgb(1, 2, 3):true|0:|rgb(0, 0, 0)|false"
- );
- let child_document = owner_document_handle_for_element_id(&vm, "detached-srcdoc-final-body");
- assert_eq!(
- computed_style_cache_entry_count_for_document(&vm, child_document),
- 1
- );
-}
-
-#[test]
-fn held_detached_iframe_computed_style_is_empty_after_src_navigation() {
- let mut vm = new_storage_test_vm("https://detached-iframe-src-computed-style.test/");
-
- let result = vm
- .eval(
- r#"
-(() => {
- const detachedDocument = document.implementation.createHTMLDocument('');
- const frame = detachedDocument.createElement('iframe');
- frame.id = 'detached-src-navigation-frame';
- const first = 'data:text/html;charset=utf-8;base64,PGJvZHkgc3R5bGU9ImNvbG9yOiByZ2IoMCwgMTI4LCAwKSI+Zmlyc3Q8L2JvZHk+';
- const second = 'data:text/html;charset=utf-8;base64,PGJvZHkgc3R5bGU9ImNvbG9yOiByZ2IoMSwgMiwgMykiPnNlY29uZDwvYm9keT4=';
- const third = 'data:text/html;charset=utf-8;base64,PGJvZHkgc3R5bGU9ImNvbG9yOiByZ2IoNCwgNSwgNikiPnRoaXJkPC9ib2R5Pg==';
- frame.src = first;
- detachedDocument.body.appendChild(frame);
- const firstDocument = frame.contentDocument;
- const held = frame.contentWindow.getComputedStyle(firstDocument.body);
- const before = `${held.length > 0}:${held.color}`;
-
- frame.src = second;
- const oldHeld = `${held.length}:${held.color}`;
- const secondDocument = frame.contentDocument;
- const secondHeld = frame.contentWindow.getComputedStyle(secondDocument.body);
- const secondFresh = secondHeld.color;
-
- frame.setAttribute('src', third);
- const secondOldHeld = `${secondHeld.length}:${secondHeld.color}`;
- const thirdDocument = frame.contentDocument;
- const thirdHeld = frame.contentWindow.getComputedStyle(thirdDocument.body);
- const thirdFresh = thirdHeld.color;
-
- let symbolError = 'none';
- try {
- frame.src = Symbol('src');
- } catch (error) {
- symbolError = error.name;
- }
- const afterFailedSrc = `${symbolError}:${thirdHeld.length > 200}:${thirdHeld.color}:${frame.contentDocument === thirdDocument}`;
-
- frame.removeAttribute('src');
- const thirdOldHeld = `${thirdHeld.length}:${thirdHeld.color}`;
- const blankDocument = frame.contentDocument;
- blankDocument.body.id = 'detached-src-final-body';
- const blankFresh = frame.contentWindow.getComputedStyle(blankDocument.body).color;
- return [
- before,
- oldHeld,
- secondFresh,
- firstDocument === secondDocument,
- secondOldHeld,
- thirdFresh,
- secondDocument === thirdDocument,
- afterFailedSrc,
- thirdOldHeld,
- blankFresh,
- thirdDocument === blankDocument
- ].join('|');
-})()
-"#,
- )
- .expect("held detached iframe computed style src navigation should evaluate");
-
- assert_eq!(
- result,
- "true:rgb(0, 128, 0)|0:|rgb(1, 2, 3)|false|0:|rgb(4, 5, 6)|false|TypeError:true:rgb(4, 5, 6):true|0:|rgb(0, 0, 0)|false"
- );
- let child_document = owner_document_handle_for_element_id(&vm, "detached-src-final-body");
- assert_eq!(
- computed_style_cache_entry_count_for_document(&vm, child_document),
- 1
- );
+fn inert_iframes_remain_windowless_after_src_and_srcdoc_changes() {
+ let mut vm = new_storage_test_vm("https://inert-frame-navigation.test/");
+ assert_eq!(vm.eval(r#"
+ const owner = document.implementation.createHTMLDocument('');
+ const frame = owner.createElement('iframe');
+ owner.body.appendChild(frame);
+ const results = [];
+ const check = () => results.push(frame.contentDocument === null && frame.contentWindow === null && frame.getSVGDocument() === null);
+ check();
+ for (const src of ['about:blank', 'data:text/html,<p>opaque</p>', 'https://foreign.example/private']) {
+ frame.src = src;
+ check();
+ frame.srcdoc = '<p>srcdoc</p>';
+ check();
+ frame.removeAttribute('srcdoc');
+ check();
+ }
+ let error = '';
+ try { frame.srcdoc = Symbol('srcdoc'); } catch (caught) { error = caught.name; }
+ check();
+ JSON.stringify([results.every(Boolean), error, owner.defaultView, frames.length])
+ "#).unwrap(), r#"[true,"TypeError",null,0]"#);
}
#[test]
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/dom/elements_and_events.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/dom/elements_and_events.rs
index b7406b517..6bc5ef9f2 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/dom/elements_and_events.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/dom/elements_and_events.rs
@@ -244,51 +244,14 @@ fn dom_parser_detached_insertion_does_not_dispatch_iframe_load() {
}
#[test]
-fn dom_parser_detached_iframe_window_declares_own_methods() {
- let mut vm = new_storage_test_vm("https://dom-parser-detached-window-methods.test/");
-
- let result = vm
- .eval(
- r#"
-(() => {
- const doc = new DOMParser().parseFromString('<html><body></body></html>', 'text/html');
- const iframe = doc.createElement('iframe');
- doc.body.appendChild(iframe);
- const win = iframe.contentWindow;
- const shape = name => {
- const descriptor = Object.getOwnPropertyDescriptor(win, name);
- const value = descriptor && descriptor.value;
- return [
- typeof value,
- value && value.name,
- value && value.length,
- descriptor && descriptor.enumerable,
- descriptor && descriptor.configurable,
- descriptor && descriptor.writable,
- /\[native code\]/.test(String(value))
- ].join(':');
- };
- return [
- Object.prototype.toString.call(win),
- shape('postMessage'),
- shape('open'),
- shape('blur'),
- shape('find'),
- shape('stop'),
- shape('print'),
- win.find('needle'),
- String(win.blur()),
- String(win.print())
- ].join('|');
-})()
-"#,
- )
- .expect("DOMParser detached iframe window methods should evaluate");
-
- assert_eq!(
- result,
- "[object Window]|function:postMessage:1:false:true:true:true|function:open:0:false:true:true:true|function:blur:0:false:true:true:true|function:find:0:false:true:true:true|function:stop:0:false:true:true:true|function:print:0:false:true:true:true|false|undefined|undefined"
- );
+fn dom_parser_iframes_have_no_content_window_or_document() {
+ let mut vm = new_storage_test_vm("https://dom-parser-inert-window.test/");
+ assert_eq!(vm.eval(r#"
+ const doc = new DOMParser().parseFromString('<body><iframe src="data:text/html,<p>foreign</p>"></iframe></body>', 'text/html');
+ const frame = doc.querySelector('iframe');
+ const getter = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentDocument').get;
+ JSON.stringify([doc.defaultView, frame.contentWindow, frame.contentDocument, getter.call(frame), frame.getSVGDocument(), frames.length])
+ "#).unwrap(), "[null,null,null,null,null,0]");
}
#[test]
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/misc.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/misc.rs
index 9c93110b0..c13ef861b 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/misc.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/misc.rs
@@ -509,29 +509,37 @@ fn detached_document_shadow_root_inner_html_setter_updates_query_surface() {
#[test]
fn child_document_content_type_uses_resource_mime() {
let mut vm = new_storage_test_vm("https://child-content-type.test/");
-
- let result = vm
- .eval(
- r#"
-(() => {
- const parsed = new DOMParser().parseFromString(
- '<iframe id="html" src="data:text/html;charset=utf-8,<p>ok</p>"></iframe>' +
- '<iframe id="image" src="data:image/png;base64,AA=="></iframe>',
- 'text/html'
- );
- const htmlFrame = parsed.getElementById('html');
- const imageFrame = parsed.getElementById('image');
-
- return [
- htmlFrame.contentDocument && htmlFrame.contentDocument.contentType,
- imageFrame.contentDocument && imageFrame.contentDocument.contentType
- ].join('|');
-})()
-"#,
- )
- .expect("child document contentType should evaluate");
-
- assert_eq!(result, "text/html|image/png");
+ vm.eval(r#"
+ const root = document.documentElement || document.appendChild(document.createElement('html'));
+ const body = document.body || root.appendChild(document.createElement('body'));
+ for (const [id, src] of [
+ ['html', 'data:text/html;charset=utf-8,<p>ok</p>'],
+ ['image', 'data:image/png;base64,AA==']
+ ]) {
+ body.appendChild(Object.assign(document.createElement('iframe'), {id, src}));
+ }
+ 'created'
+ "#).unwrap();
+ vm.drain_pending_child_frame_work_for_test();
+ let frames = vm.child_browsing_context_frame_tree_snapshot();
+ let mut content_types = Vec::new();
+ for id in ["html", "image"] {
+ let frame = frames
+ .iter()
+ .find(|frame| frame.owner_element_id.as_deref() == Some(id))
+ .unwrap();
+ // These data URLs have opaque origins. Inspect their own Document in
+ // an isolated world rather than exposing it through the parent page.
+ let world = vm
+ .create_isolated_world_for_frame(&frame.frame_id, "mime-probe", false)
+ .unwrap();
+ content_types.push(
+ vm.eval_in_isolated_context(world, "document.contentType")
+ .unwrap(),
+ );
+ }
+ assert_eq!(content_types, ["text/html", "image/png"]);
+ assert_eq!(vm.eval("document.getElementById('html').contentDocument === null && document.getElementById('image').contentDocument === null").unwrap(), "true");
}
#[test]
diff --git a/moli-renderer-v8/src/script_vm/tests/extracted/child_realm_retention.rs b/moli-renderer-v8/src/script_vm/tests/extracted/child_realm_retention.rs
index e50a2e36a..993a5fbf9 100644
--- a/moli-renderer-v8/src/script_vm/tests/extracted/child_realm_retention.rs
+++ b/moli-renderer-v8/src/script_vm/tests/extracted/child_realm_retention.rs
@@ -174,24 +174,21 @@ fn promoted_child_content_surfaces_follow_author_reachability() {
}
#[test]
-fn detached_iframe_projection_keeps_its_cached_surfaces_across_gc() {
- let mut vm = new_storage_test_vm("https://detached-content-cache.test/");
- vm.eval(
- r#"
- (() => {
- const detached = document.implementation.createHTMLDocument('');
- globalThis.savedDetachedFrame = detached.createElement('iframe');
- detached.body.append(savedDetachedFrame);
- const child = savedDetachedFrame.contentDocument;
- const win = savedDetachedFrame.contentWindow;
- child.authorMarker = 42;
- win.authorMarker = 43;
- child.body.innerHTML = '<p>kept</p>';
- return 'cached';
- })()
- "#,
- )
- .unwrap();
+fn inert_iframe_remains_windowless_across_gc() {
+ let mut vm = new_storage_test_vm("https://inert-content-cache.test/");
+ assert_eq!(
+ vm.eval(
+ r#"
+ const detached = document.implementation.createHTMLDocument('');
+ globalThis.savedDetachedFrame = detached.createElement('iframe');
+ savedDetachedFrame.srcdoc = '<p>inert</p>';
+ detached.body.append(savedDetachedFrame);
+ JSON.stringify([savedDetachedFrame.contentDocument, savedDetachedFrame.contentWindow])
+ "#
+ )
+ .unwrap(),
+ "[null,null]"
+ );
for _ in 0..2 {
vm.collect_renderer_document_isolate_garbage().unwrap();
}
@@ -200,16 +197,21 @@ fn detached_iframe_projection_keeps_its_cached_surfaces_across_gc() {
assert_eq!(
vm.eval(
r#"
- JSON.stringify([
- savedDetachedFrame.contentDocument.authorMarker,
- savedDetachedFrame.contentWindow.authorMarker,
- savedDetachedFrame.contentWindow.document === savedDetachedFrame.contentDocument,
- savedDetachedFrame.contentDocument.body.textContent
- ])
- "#,
+ JSON.stringify([
+ savedDetachedFrame.contentDocument,
+ savedDetachedFrame.contentWindow,
+ savedDetachedFrame.ownerDocument.querySelector('iframe') === savedDetachedFrame
+ ])
+ "#
)
.unwrap(),
- r#"[42,43,true,"kept"]"#
+ "[null,null,true]"
+ );
+ assert_eq!(
+ vm._context_host
+ .borrow()
+ .detached_content_surface_cache_counts_for_test(),
+ [0; 6]
);
}
diff --git a/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs b/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs
index e98803e44..5cfa89fc6 100644
--- a/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs
+++ b/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs
@@ -183,11 +183,6 @@ const DIRECT_V8_CALL_ALLOWLIST: &[AllowedDirectCallFile] = &[
1,
DirectCallOwner::NativeForwardingOrScript,
),
- allowed(
- "context_bootstrap/runtime_state.rs",
- 1,
- DirectCallOwner::BrowserAlgorithm,
- ),
allowed(
"context_bootstrap/web_storage/interceptors.rs",
1,