mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Initial work on job queues for service workers
This commit is contained in:
parent
6cc1976cca
commit
114c491111
11 changed files with 462 additions and 68 deletions
|
@ -10,10 +10,11 @@ use dom::bindings::str::USVString;
|
|||
use dom::eventtarget::EventTarget;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::serviceworker::ServiceWorker;
|
||||
use dom::serviceworkercontainer::Controllable;
|
||||
use dom::workerglobalscope::prepare_workerscope_init;
|
||||
use script_traits::{WorkerScriptLoadOrigin, ScopeThings};
|
||||
use servo_url::ServoUrl;
|
||||
use std::cell::Cell;
|
||||
|
||||
|
||||
#[dom_struct]
|
||||
pub struct ServiceWorkerRegistration {
|
||||
|
@ -21,7 +22,8 @@ pub struct ServiceWorkerRegistration {
|
|||
active: Option<JS<ServiceWorker>>,
|
||||
installing: Option<JS<ServiceWorker>>,
|
||||
waiting: Option<JS<ServiceWorker>>,
|
||||
scope: String
|
||||
scope: ServoUrl,
|
||||
uninstalling: Cell<bool>
|
||||
}
|
||||
|
||||
impl ServiceWorkerRegistration {
|
||||
|
@ -31,17 +33,16 @@ impl ServiceWorkerRegistration {
|
|||
active: Some(JS::from_ref(active_sw)),
|
||||
installing: None,
|
||||
waiting: None,
|
||||
scope: scope.as_str().to_owned(),
|
||||
scope: scope,
|
||||
uninstalling: Cell::new(false)
|
||||
}
|
||||
}
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(global: &GlobalScope,
|
||||
script_url: ServoUrl,
|
||||
scope: ServoUrl,
|
||||
container: &Controllable) -> Root<ServiceWorkerRegistration> {
|
||||
script_url: &ServoUrl,
|
||||
scope: ServoUrl) -> Root<ServiceWorkerRegistration> {
|
||||
let active_worker = ServiceWorker::install_serviceworker(global, script_url.clone(), scope.clone(), true);
|
||||
active_worker.set_transition_state(ServiceWorkerState::Installed);
|
||||
container.set_controller(&*active_worker.clone());
|
||||
reflect_dom_object(box ServiceWorkerRegistration::new_inherited(&*active_worker, scope), global, Wrap)
|
||||
}
|
||||
|
||||
|
@ -49,6 +50,14 @@ impl ServiceWorkerRegistration {
|
|||
self.active.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn get_uninstalling(&self) -> bool {
|
||||
self.uninstalling.get()
|
||||
}
|
||||
|
||||
pub fn set_uninstalling(&self, flag: bool) {
|
||||
self.uninstalling.set(flag)
|
||||
}
|
||||
|
||||
pub fn create_scope_things(global: &GlobalScope, script_url: ServoUrl) -> ScopeThings {
|
||||
let worker_load_origin = WorkerScriptLoadOrigin {
|
||||
referrer_url: None,
|
||||
|
@ -58,7 +67,7 @@ impl ServiceWorkerRegistration {
|
|||
|
||||
let worker_id = global.get_next_worker_id();
|
||||
let devtools_chan = global.devtools_chan().cloned();
|
||||
let init = prepare_workerscope_init(global, None);
|
||||
let init = prepare_workerscope_init(&global, None);
|
||||
ScopeThings {
|
||||
script_url: script_url,
|
||||
init: init,
|
||||
|
@ -67,6 +76,17 @@ impl ServiceWorkerRegistration {
|
|||
worker_id: worker_id
|
||||
}
|
||||
}
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#get-newest-worker-algorithm
|
||||
pub fn get_newest_worker(&self) -> Option<Root<ServiceWorker>> {
|
||||
if self.installing.as_ref().is_some() {
|
||||
self.installing.as_ref().map(|sw| Root::from_ref(&**sw))
|
||||
} else if self.waiting.as_ref().is_some() {
|
||||
self.waiting.as_ref().map(|sw| Root::from_ref(&**sw))
|
||||
} else {
|
||||
self.active.as_ref().map(|sw| Root::from_ref(&**sw))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn longest_prefix_match(stored_scope: &ServoUrl, potential_match: &ServoUrl) -> bool {
|
||||
|
@ -100,6 +120,6 @@ impl ServiceWorkerRegistrationMethods for ServiceWorkerRegistration {
|
|||
|
||||
// https://w3c.github.io/ServiceWorker/#service-worker-registration-scope-attribute
|
||||
fn Scope(&self) -> USVString {
|
||||
USVString(self.scope.clone())
|
||||
USVString(self.scope.as_str().to_owned())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue