aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/serviceworkerregistration.rs
diff options
context:
space:
mode:
authorRahul Sharma <rsconceptx@gmail.com>2016-10-04 23:57:36 +0530
committerRahul Sharma <rsconceptx@gmail.com>2016-11-22 01:29:37 +0530
commit114c49111138325f7cf1dacbe9d25fdd035ede86 (patch)
treeb535e703eb5f5f26785082efda94cf7be871bafd /components/script/dom/serviceworkerregistration.rs
parent6cc1976cca808cac2069b241885a9c102ee7424d (diff)
downloadservo-114c49111138325f7cf1dacbe9d25fdd035ede86.tar.gz
servo-114c49111138325f7cf1dacbe9d25fdd035ede86.zip
Initial work on job queues for service workers
Diffstat (limited to 'components/script/dom/serviceworkerregistration.rs')
-rw-r--r--components/script/dom/serviceworkerregistration.rs38
1 files changed, 29 insertions, 9 deletions
diff --git a/components/script/dom/serviceworkerregistration.rs b/components/script/dom/serviceworkerregistration.rs
index 58ca0933d69..869c8855676 100644
--- a/components/script/dom/serviceworkerregistration.rs
+++ b/components/script/dom/serviceworkerregistration.rs
@@ -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())
}
}