diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index 63e4c7aea15..cc37ed7c4b0 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -307,7 +307,7 @@ fn run_server( let worker = WorkerActor { name: actors.new_name("worker"), console: console.name(), - id: id, + id: id.clone(), }; actor_workers.insert((pipeline, id), worker.name.clone()); actors.register(Box::new(worker)); diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 0e0872e7663..c71693dff40 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. @@ -356,5 +357,5 @@ impl PreciseTime { } } -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] -pub struct WorkerId(pub u32); +#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] +pub struct WorkerId(pub String); 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 8af14654342..067cf6cc009 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -80,6 +80,7 @@ use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use time::{get_time, Timespec}; +use uuid::Uuid; #[derive(JSTraceable)] pub struct AutoCloseWorker(Arc); @@ -94,7 +95,7 @@ impl Drop for AutoCloseWorker { pub struct GlobalScope { eventtarget: EventTarget, crypto: MutNullableDom, - next_worker_id: Cell, + next_worker_id: WorkerId, /// The message-port router id for this global, if it is managing ports. message_port_state: DomRefCell, @@ -347,7 +348,7 @@ impl GlobalScope { message_port_state: DomRefCell::new(MessagePortState::UnManaged), eventtarget: EventTarget::new_inherited(), crypto: Default::default(), - next_worker_id: Cell::new(WorkerId(0)), + next_worker_id: WorkerId(Uuid::new_v4().to_string()), pipeline_id, devtools_wants_updates: Default::default(), console_timers: DomRefCell::new(Default::default()), @@ -928,9 +929,7 @@ impl GlobalScope { /// 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)); + let worker_id = self.next_worker_id.clone(); worker_id } diff --git a/components/script/serviceworker_manager.rs b/components/script/serviceworker_manager.rs index 109628ae94e..4323ef45f59 100644 --- a/components/script/serviceworker_manager.rs +++ b/components/script/serviceworker_manager.rs @@ -98,8 +98,9 @@ impl ServiceWorkerManager { title: title, url: scope_things.script_url.clone(), }; + let worker_id = scope_things.worker_id.clone(); let _ = chan.send(ScriptToDevtoolsControlMsg::NewGlobal( - (scope_things.init.pipeline_id, Some(scope_things.worker_id)), + (scope_things.init.pipeline_id, Some(worker_id)), devtools_sender, page_info, ));