servo_constellation/
serviceworker.rs1#[cfg(feature = "multiprocess")]
6use ipc_channel::IpcError;
7use serde::{Deserialize, Serialize};
8use servo_base::generic_channel::GenericSender;
9#[cfg(feature = "multiprocess")]
10use servo_config::opts::{self, Opts};
11#[cfg(feature = "multiprocess")]
12use servo_config::{prefs, prefs::Preferences};
13use servo_constellation_traits::{SWManagerSenders, ServiceWorkerManagerFactory};
14use servo_url::ImmutableOrigin;
15
16#[cfg(feature = "multiprocess")]
17use crate::process_manager::Process;
18#[cfg(feature = "multiprocess")]
19use crate::sandboxing::UnprivilegedContent;
20#[cfg(feature = "multiprocess")]
21use crate::sandboxing::spawn_multiprocess;
22
23#[derive(Deserialize, Serialize)]
26pub struct ServiceWorkerUnprivilegedContent {
27 #[cfg(feature = "multiprocess")]
28 pub opts: Opts,
29 #[cfg(feature = "multiprocess")]
30 pub prefs: Box<Preferences>,
31 senders: SWManagerSenders,
32 origin: ImmutableOrigin,
33 lifeline_sender: Option<GenericSender<()>>,
34}
35
36impl ServiceWorkerUnprivilegedContent {
37 pub fn new(
38 senders: SWManagerSenders,
39 origin: ImmutableOrigin,
40 lifeline_sender: Option<GenericSender<()>>,
41 ) -> ServiceWorkerUnprivilegedContent {
42 ServiceWorkerUnprivilegedContent {
43 #[cfg(feature = "multiprocess")]
44 opts: (*opts::get()).clone(),
45 #[cfg(feature = "multiprocess")]
46 prefs: Box::new(prefs::get().clone()),
47 senders,
48 origin,
49 lifeline_sender,
50 }
51 }
52
53 pub fn start<SWF>(self)
55 where
56 SWF: ServiceWorkerManagerFactory,
57 {
58 SWF::create(self.senders, self.origin);
59 }
60
61 #[cfg(feature = "multiprocess")]
63 pub fn spawn_multiprocess(self) -> Result<Process, IpcError> {
64 spawn_multiprocess(UnprivilegedContent::ServiceWorker(self))
65 }
66}