pub struct ServiceWorkerHandle {
pub script_url: String,
pub scope: String,
pub closing: Arc<AtomicBool>,
pub terminated: Arc<AtomicBool>,
pub state: Arc<Mutex<ServiceWorkerRegistrationState>>,
pub fetch_intercept_mode: Arc<Mutex<ServiceWorkerFetchInterceptMode>>,
pub stealth_profile: Option<StealthProfile>,
}Expand description
A Send+Sync handle to a ServiceWorker’s lifecycle state.
Does NOT hold JSObject references — only atomic flags and IDs. This is safe to store across threads (unlike ServiceWorker DOM objects).
@trace REQ-BRW-004 [entity:ServiceWorker]
Fields§
§script_url: StringServiceWorker script URL.
scope: StringRegistration scope.
closing: Arc<AtomicBool>Whether the ServiceWorker’s closing flag is set. Set by terminate() or when the registration is unregistered.
terminated: Arc<AtomicBool>Whether the ServiceWorker thread has fully exited.
state: Arc<Mutex<ServiceWorkerRegistrationState>>Current registration state.
fetch_intercept_mode: Arc<Mutex<ServiceWorkerFetchInterceptMode>>Current fetch interception mode.
stealth_profile: Option<StealthProfile>StealthProfile inherited from the registering page. Per DF-WK-10: “ServiceWorkerGlobalScope 首次解析 stealth getter → 按 D7 机制 从 bao-stealth REALM_PROFILES 继承注册页 profile” Per SPEC criterion #19: “SW 持久生命周期(跨页存活)下 profile 继承注册页且 terminate 后正确注销” @trace REQ-BRW-004 [entity:ServiceWorker] [criterion:19] DF-WK-10
Implementations§
Source§impl ServiceWorkerHandle
impl ServiceWorkerHandle
Sourcepub fn new(
script_url: String,
scope: String,
stealth_profile: Option<StealthProfile>,
) -> Self
pub fn new( script_url: String, scope: String, stealth_profile: Option<StealthProfile>, ) -> Self
Create a new ServiceWorkerHandle in the installing state.
@trace REQ-BRW-004 [entity:ServiceWorker] DF-WK-8
Sourcepub fn id(&self) -> ServiceWorkerRegistrationId
pub fn id(&self) -> ServiceWorkerRegistrationId
Returns the ServiceWorkerRegistrationId for this handle.
@trace REQ-BRW-004 [entity:ServiceWorker]
Sourcepub fn is_closing(&self) -> bool
pub fn is_closing(&self) -> bool
Returns true if the closing flag has been set.
@trace REQ-BRW-004 [entity:ServiceWorker]
Sourcepub fn is_terminated(&self) -> bool
pub fn is_terminated(&self) -> bool
Returns true if the ServiceWorker thread has fully exited.
@trace REQ-BRW-004 [entity:ServiceWorker]
Sourcepub fn registration_state(&self) -> ServiceWorkerRegistrationState
pub fn registration_state(&self) -> ServiceWorkerRegistrationState
Returns the current registration state.
@trace REQ-BRW-004 [entity:ServiceWorker]
Sourcepub fn fetch_intercept_mode(&self) -> ServiceWorkerFetchInterceptMode
pub fn fetch_intercept_mode(&self) -> ServiceWorkerFetchInterceptMode
Returns the current fetch interception mode.
@trace REQ-BRW-004 [entity:ServiceWorker] [criterion:19]
Sourcepub fn is_intercepting_fetch(&self) -> bool
pub fn is_intercepting_fetch(&self) -> bool
Returns true if the ServiceWorker is actively intercepting fetch requests.
@trace REQ-BRW-004 [entity:ServiceWorker] [criterion:19]
Sourcepub fn transition_state(&self, new_state: ServiceWorkerRegistrationState)
pub fn transition_state(&self, new_state: ServiceWorkerRegistrationState)
Transition the registration state to a new state.
Valid transitions: Installing → Installed → Activating → Activated → Redundant
@trace REQ-BRW-004 [entity:ServiceWorker] DF-WK-8
Sourcepub fn enable_fetch_interception(&self)
pub fn enable_fetch_interception(&self)
Enable fetch interception mode.
Called when the ServiceWorker becomes activated and starts intercepting fetch events within its scope. Per SPEC criterion #19, intercepted fetch requests MUST use the registering page’s stealth TLS/HTTP2 profile.
@trace REQ-BRW-004 [entity:ServiceWorker] [criterion:19]
Sourcepub fn disable_fetch_interception(&self)
pub fn disable_fetch_interception(&self)
Disable fetch interception mode.
Called when the ServiceWorker becomes redundant or is terminated. Per SPEC criterion #19: “terminate 后正确注销”.
@trace REQ-BRW-004 [entity:ServiceWorker] [criterion:19]
Sourcepub fn terminate(&self)
pub fn terminate(&self)
Signal the ServiceWorker to terminate. Idempotent — calling multiple times is safe.
@trace REQ-BRW-004 [entity:ServiceWorker]
Sourcepub fn mark_terminated(&self)
pub fn mark_terminated(&self)
Mark the ServiceWorker as fully terminated (called after thread join).
@trace REQ-BRW-004 [entity:ServiceWorker]
Trait Implementations§
Source§impl Clone for ServiceWorkerHandle
impl Clone for ServiceWorkerHandle
Source§fn clone(&self) -> ServiceWorkerHandle
fn clone(&self) -> ServiceWorkerHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for ServiceWorkerHandle
impl RefUnwindSafe for ServiceWorkerHandle
impl Send for ServiceWorkerHandle
impl Sync for ServiceWorkerHandle
impl Unpin for ServiceWorkerHandle
impl UnsafeUnpin for ServiceWorkerHandle
impl UnwindSafe for ServiceWorkerHandle
Blanket Implementations§
Source§impl<T> AsCtxPtr for Twhere
T: ?Sized,
impl<T> AsCtxPtr for Twhere
T: ?Sized,
Source§fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
self’s address as *mut Self for deferred-task / scopeguard /
ref_guard ctx slots. The closures/trampolines deref it as shared
(&*p) — every method they reach is &self post-R-2, so no write
provenance is required; the *mut spelling is purely to match the
existing DerefOnDrop / HasAutoFlush / RefCount ABI.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more