diff --git a/Cargo.lock b/Cargo.lock index 654f6bf2b08..f8bcf052113 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1144,6 +1144,7 @@ dependencies = [ "serde", "servo_url", "time", + "uuid", ] [[package]] @@ -3141,6 +3142,7 @@ dependencies = [ "thin-slice", "time", "url", + "uuid", "void", "webrender_api", "xml5ever", diff --git a/components/devtools_traits/Cargo.toml b/components/devtools_traits/Cargo.toml index 4750e3708fe..53287d05b33 100644 --- a/components/devtools_traits/Cargo.toml +++ b/components/devtools_traits/Cargo.toml @@ -20,3 +20,4 @@ msg = {path = "../msg"} serde = "1.0" servo_url = {path = "../url"} time = "0.1" +uuid = {version = "0.8", features = ["v4", "serde"]} diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 0e0872e7663..5396d64fade 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -25,6 +25,7 @@ use msg::constellation_msg::PipelineId; use servo_url::ServoUrl; use std::net::TcpStream; use time::{self, Duration, Tm}; +use uuid::Uuid; // Information would be attached to NewGlobal to be received and show in devtools. // Extend these fields if we need more information. @@ -357,4 +358,4 @@ impl PreciseTime { } #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] -pub struct WorkerId(pub u32); +pub struct WorkerId(pub Uuid); diff --git a/components/malloc_size_of/Cargo.toml b/components/malloc_size_of/Cargo.toml index 2e112805067..d2068a30e9b 100644 --- a/components/malloc_size_of/Cargo.toml +++ b/components/malloc_size_of/Cargo.toml @@ -22,6 +22,7 @@ servo = [ "webrender_api", "xml5ever", "content-security-policy", + "uuid" ] [dependencies] @@ -47,3 +48,4 @@ url = { version = "2.0", optional = true } webrender_api = { git = "https://github.com/servo/webrender", optional = true } xml5ever = { version = "0.16", optional = true } void = "1.0.2" +uuid = {version = "0.8", features = ["v4"], optional = true} diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index 1d5cbeaff1e..8593ccc3622 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -75,6 +75,8 @@ extern crate thin_slice; extern crate time; #[cfg(feature = "url")] extern crate url; +#[cfg(feature = "servo")] +extern crate uuid; extern crate void; #[cfg(feature = "webrender_api")] extern crate webrender_api; @@ -90,6 +92,8 @@ use std::mem::size_of; use std::ops::Range; use std::ops::{Deref, DerefMut}; use std::os::raw::c_void; +#[cfg(feature = "servo")] +use uuid::Uuid; use void::Void; /// A C function that takes a pointer to a heap allocation and returns its size. @@ -840,6 +844,9 @@ malloc_size_of_is_0!(cssparser::RGBA, cssparser::TokenSerializationType); #[cfg(feature = "servo")] malloc_size_of_is_0!(csp::Destination); +#[cfg(feature = "servo")] +malloc_size_of_is_0!(Uuid); + #[cfg(feature = "url")] impl MallocSizeOf for url::Host { fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index cfa02f3363e..3889402a346 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -110,7 +110,7 @@ time = "0.1.12" unicode-segmentation = "1.1.0" url = "2.0" utf-8 = "0.7" -uuid = {version = "0.8", features = ["v4"]} +uuid = {version = "0.8", features = ["v4", "serde"]} xml5ever = "0.16" webdriver = "0.40" webgpu = {path = "../webgpu"} diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index acf75c08ea8..1e3371968e9 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -46,7 +46,7 @@ use crate::task_source::TaskSourceName; use crate::timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle}; use crate::timers::{OneshotTimers, TimerCallback}; use content_security_policy::CspList; -use devtools_traits::{PageError, ScriptToDevtoolsControlMsg, WorkerId}; +use devtools_traits::{PageError, ScriptToDevtoolsControlMsg}; use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; @@ -94,7 +94,6 @@ impl Drop for AutoCloseWorker { pub struct GlobalScope { eventtarget: EventTarget, crypto: MutNullableDom, - next_worker_id: Cell, /// The message-port router id for this global, if it is managing ports. message_port_state: DomRefCell, @@ -347,7 +346,6 @@ impl GlobalScope { message_port_state: DomRefCell::new(MessagePortState::UnManaged), eventtarget: EventTarget::new_inherited(), crypto: Default::default(), - next_worker_id: Cell::new(WorkerId(0)), pipeline_id, devtools_wants_updates: Default::default(), console_timers: DomRefCell::new(Default::default()), @@ -926,14 +924,6 @@ impl GlobalScope { self.crypto.or_init(|| Crypto::new(self)) } - /// Get next worker id. - pub fn get_next_worker_id(&self) -> WorkerId { - let worker_id = self.next_worker_id.get(); - let WorkerId(id_num) = worker_id; - self.next_worker_id.set(WorkerId(id_num + 1)); - worker_id - } - pub fn live_devtools_updates(&self) -> bool { self.devtools_wants_updates.get() } diff --git a/components/script/dom/serviceworkerregistration.rs b/components/script/dom/serviceworkerregistration.rs index a2165a82115..00f65f3f2a0 100644 --- a/components/script/dom/serviceworkerregistration.rs +++ b/components/script/dom/serviceworkerregistration.rs @@ -16,10 +16,12 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::navigationpreloadmanager::NavigationPreloadManager; use crate::dom::serviceworker::ServiceWorker; use crate::dom::workerglobalscope::prepare_workerscope_init; +use devtools_traits::WorkerId; use dom_struct::dom_struct; use script_traits::{ScopeThings, WorkerScriptLoadOrigin}; use servo_url::ServoUrl; use std::cell::Cell; +use uuid::Uuid; #[dom_struct] pub struct ServiceWorkerRegistration { @@ -111,7 +113,7 @@ impl ServiceWorkerRegistration { pipeline_id: Some(global.pipeline_id()), }; - let worker_id = global.get_next_worker_id(); + let worker_id = WorkerId(Uuid::new_v4()); let devtools_chan = global.devtools_chan().cloned(); let init = prepare_workerscope_init(&global, None); ScopeThings { diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index f08bdcab79e..9cec5edf72d 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -26,7 +26,7 @@ use crate::dom::workerglobalscope::prepare_workerscope_init; use crate::script_runtime::JSContext; use crate::task::TaskOnce; use crossbeam_channel::{unbounded, Sender}; -use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg}; +use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg, WorkerId}; use dom_struct::dom_struct; use ipc_channel::ipc; use js::jsapi::{Heap, JSObject, JS_RequestInterruptCallback}; @@ -36,6 +36,7 @@ use script_traits::{StructuredSerializedData, WorkerScriptLoadOrigin}; use std::cell::Cell; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use uuid::Uuid; pub type TrustedWorkerAddress = Trusted; @@ -100,7 +101,7 @@ impl Worker { }; let (devtools_sender, devtools_receiver) = ipc::channel().unwrap(); - let worker_id = global.get_next_worker_id(); + let worker_id = WorkerId(Uuid::new_v4()); if let Some(ref chan) = global.devtools_chan() { let pipeline_id = global.pipeline_id(); let title = format!("Worker for {}", worker_url); diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index e943b6b0ef4..8624208423e 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -58,6 +58,7 @@ use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use time::precise_time_ns; +use uuid::Uuid; pub fn prepare_workerscope_init( global: &GlobalScope, @@ -71,7 +72,7 @@ pub fn prepare_workerscope_init( from_devtools_sender: devtools_sender, script_to_constellation_chan: global.script_to_constellation_chan().clone(), scheduler_chan: global.scheduler_chan().clone(), - worker_id: global.get_next_worker_id(), + worker_id: WorkerId(Uuid::new_v4()), pipeline_id: global.pipeline_id(), origin: global.origin().immutable().clone(), is_headless: global.is_headless(),