aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/serviceworkerregistration.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-06-02 06:18:59 -0500
committerbors-servo <lbergstrom+bors@mozilla.com>2016-06-02 06:18:59 -0500
commitcc017fc0b8619726f0c82649f41fdcf5595b19e4 (patch)
treee77fdc04eef71792a28898da24eb564f48432fe5 /components/script/dom/serviceworkerregistration.rs
parent196adaff07201deb273077213fa63c460cc11629 (diff)
parent15a2064c0d7b468724b43d1cb6157d506ad19093 (diff)
downloadservo-cc017fc0b8619726f0c82649f41fdcf5595b19e4.tar.gz
servo-cc017fc0b8619726f0c82649f41fdcf5595b19e4.zip
Auto merge of #11114 - creativcoder:nav-sw, r=jdm
implement related service worker interface and register method Fixes #11091 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11114) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/serviceworkerregistration.rs')
-rw-r--r--components/script/dom/serviceworkerregistration.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/components/script/dom/serviceworkerregistration.rs b/components/script/dom/serviceworkerregistration.rs
new file mode 100644
index 00000000000..358331afffc
--- /dev/null
+++ b/components/script/dom/serviceworkerregistration.rs
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use dom::bindings::codegen::Bindings::ServiceWorkerBinding::ServiceWorkerState;
+use dom::bindings::codegen::Bindings::ServiceWorkerRegistrationBinding::{ServiceWorkerRegistrationMethods, Wrap};
+use dom::bindings::global::GlobalRef;
+use dom::bindings::js::{JS, Root};
+use dom::bindings::reflector::reflect_dom_object;
+use dom::bindings::str::USVString;
+use dom::eventtarget::EventTarget;
+use dom::serviceworker::ServiceWorker;
+use dom::serviceworkercontainer::Controllable;
+use url::Url;
+
+#[dom_struct]
+pub struct ServiceWorkerRegistration {
+ eventtarget: EventTarget,
+ active: Option<JS<ServiceWorker>>,
+ installing: Option<JS<ServiceWorker>>,
+ waiting: Option<JS<ServiceWorker>>,
+ scope: String,
+}
+
+impl ServiceWorkerRegistration {
+ fn new_inherited(active_sw: &ServiceWorker, scope: String) -> ServiceWorkerRegistration {
+ ServiceWorkerRegistration {
+ eventtarget: EventTarget::new_inherited(),
+ active: Some(JS::from_ref(active_sw)),
+ installing: None,
+ waiting: None,
+ scope: scope
+ }
+ }
+ #[allow(unrooted_must_root)]
+ pub fn new(global: GlobalRef,
+ script_url: Url,
+ scope: String,
+ container: &Controllable) -> Root<ServiceWorkerRegistration> {
+ let active_worker = ServiceWorker::init_service_worker(global, script_url, 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)
+ }
+}
+
+impl ServiceWorkerRegistrationMethods for ServiceWorkerRegistration {
+ // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-registration-installing-attribute
+ fn GetInstalling(&self) -> Option<Root<ServiceWorker>> {
+ self.installing.as_ref().map(|sw| Root::from_ref(&**sw))
+ }
+
+ // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-registration-active-attribute
+ fn GetActive(&self) -> Option<Root<ServiceWorker>> {
+ self.active.as_ref().map(|sw| Root::from_ref(&**sw))
+ }
+
+ // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-registration-waiting-attribute
+ fn GetWaiting(&self) -> Option<Root<ServiceWorker>> {
+ self.waiting.as_ref().map(|sw| Root::from_ref(&**sw))
+ }
+
+ // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-registration-scope-attribute
+ fn Scope(&self) -> USVString {
+ USVString(self.scope.clone())
+ }
+}