add is_online member to ScriptThread and GlobalScope, and make it an argument to GlobalScope::new_inherited, Window::new and DedicatedWorkerGlobalScope::new and anywhere else that transitively calls GlobalScope::new_inherited

Signed-off-by: TG <ebiritg@gmail.com>
This commit is contained in:
TG 2025-05-19 10:46:31 +01:00
parent 4c1a09e17b
commit 93dcf9bb86
6 changed files with 35 additions and 5 deletions

View file

@ -68,6 +68,7 @@ impl DissimilarOriginWindow {
global_to_clone_from.wgpu_id_hub(),
Some(global_to_clone_from.is_secure_context()),
false,
global_to_clone_from.is_online().clone(),
),
window_proxy: Dom::from_ref(window_proxy),
location: Default::default(),

View file

@ -374,6 +374,11 @@ pub(crate) struct GlobalScope {
#[ignore_malloc_size_of = "Rc<T> is hard"]
notification_permission_request_callback_map:
DomRefCell<HashMap<String, Rc<NotificationPermissionCallback>>>,
/// Switch offline and online events
#[no_trace]
#[ignore_malloc_size_of = "Arc<Mutex<bool>> does not implement MallocSizeOf"]
is_online: Arc<Mutex<bool>>,
}
/// A wrapper for glue-code between the ipc router and the event-loop.
@ -735,6 +740,7 @@ impl GlobalScope {
#[cfg(feature = "webgpu")] gpu_id_hub: Arc<IdentityHub>,
inherited_secure_context: Option<bool>,
unminify_js: bool,
is_online: Arc<Mutex<bool>>,
) -> Self {
Self {
task_manager: Default::default(),
@ -779,6 +785,7 @@ impl GlobalScope {
byte_length_queuing_strategy_size_function: OnceCell::new(),
count_queuing_strategy_size_function: OnceCell::new(),
notification_permission_request_callback_map: Default::default(),
is_online,
}
}
@ -3446,6 +3453,10 @@ impl GlobalScope {
unreachable!();
}
pub(crate) fn is_online(&self) -> Arc<Mutex<bool> {
Arc::clone(&self.is_online)
}
/// <https://www.w3.org/TR/CSP/#report-violation>
#[allow(unsafe_code)]
pub(crate) fn report_csp_violations(

View file

@ -398,6 +398,12 @@ pub(crate) struct Window {
/// <https://dom.spec.whatwg.org/#window-current-event>
current_event: DomRefCell<Option<Dom<Event>>>,
/// Switch offline and online events
#[no_trace]
#[ignore_malloc_size_of = "Arc<Mutex<bool>> does not implement MallocSizeOf"]
is_online: Arc<Mutex<bool>>,
}
impl Window {
@ -3033,6 +3039,7 @@ impl Window {
player_context: WindowGLContext,
#[cfg(feature = "webgpu")] gpu_id_hub: Arc<IdentityHub>,
inherited_secure_context: Option<bool>,
is_online: Arc<Mutex<bool>>,
) -> DomRoot<Self> {
let error_reporter = CSSErrorReporter {
pipelineid: pipeline_id,
@ -3060,6 +3067,8 @@ impl Window {
gpu_id_hub,
inherited_secure_context,
unminify_js,
is_online,
),
script_chan,
layout: RefCell::new(layout),
@ -3120,6 +3129,7 @@ impl Window {
current_event: DomRefCell::new(None),
theme: Cell::new(PrefersColorScheme::Light),
trusted_types: Default::default(),
is_online: Arc::new(Mutex::new(true)),
});
unsafe {

View file

@ -5,7 +5,7 @@
use std::cell::{RefCell, RefMut};
use std::default::Default;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
@ -174,6 +174,7 @@ impl WorkerGlobalScope {
gpu_id_hub,
init.inherited_secure_context,
false,
Arc::new(Mutex::new(true)),
),
worker_id: init.worker_id,
worker_name,

View file

@ -2,7 +2,7 @@
* 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::sync::Arc;
use std::sync::{Arc, Mutex};
use base::id::PipelineId;
use constellation_traits::{ScriptToConstellationChan, ScriptToConstellationMessage};
@ -110,6 +110,7 @@ impl WorkletGlobalScope {
init.gpu_id_hub.clone(),
init.inherited_secure_context,
false,
Arc::new(Mutex::new(true)),
),
base_url,
to_script_thread_sender: init.to_script_thread_sender.clone(),

View file

@ -1,5 +1,5 @@
/* 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
/* 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/. */
//! The script thread is the thread that owns the DOM in memory, runs JavaScript, and triggers
@ -23,7 +23,7 @@ use std::default::Default;
use std::option::Option;
use std::rc::Rc;
use std::result::Result;
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread;
use std::time::{Duration, Instant, SystemTime};
@ -336,6 +336,10 @@ pub struct ScriptThread {
/// The screen coordinates where the primary mouse button was pressed.
#[no_trace]
relative_mouse_down_point: Cell<Point2D<f32, DevicePixel>>,
/// Switch offline and online events
#[no_trace]
is_online: Arc<Mutex<bool>>,
}
struct BHMExitSignal {
@ -957,6 +961,7 @@ impl ScriptThread {
inherited_secure_context: state.inherited_secure_context,
layout_factory,
relative_mouse_down_point: Cell::new(Point2D::zero()),
is_online: Arc::new(Mutex::new(true)),
}
}
@ -3224,6 +3229,7 @@ impl ScriptThread {
#[cfg(feature = "webgpu")]
self.gpu_id_hub.clone(),
incomplete.load_data.inherited_secure_context,
self.is_online.clone(),
);
let _realm = enter_realm(&*window);