diff options
Diffstat (limited to 'components/script/dom/client.rs')
-rw-r--r-- | components/script/dom/client.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/components/script/dom/client.rs b/components/script/dom/client.rs index bc763d41ea9..496a13d32dc 100644 --- a/components/script/dom/client.rs +++ b/components/script/dom/client.rs @@ -4,20 +4,20 @@ use dom::bindings::codegen::Bindings::ClientBinding::{ClientMethods, Wrap}; use dom::bindings::codegen::Bindings::ClientBinding::FrameType; -use dom::bindings::js::JS; -use dom::bindings::js::Root; +use dom::bindings::js::{JS, Root, MutNullableHeap}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString}; use dom::serviceworker::ServiceWorker; use dom::window::Window; use servo_url::ServoUrl; +use std::default::Default; use uuid::Uuid; #[dom_struct] pub struct Client { reflector_: Reflector, - active_worker: Option<JS<ServiceWorker>>, - url: USVString, + active_worker: MutNullableHeap<JS<ServiceWorker>>, + url: ServoUrl, frame_type: FrameType, #[ignore_heap_size_of = "Defined in uuid"] id: Uuid @@ -27,8 +27,8 @@ impl Client { fn new_inherited(url: ServoUrl) -> Client { Client { reflector_: Reflector::new(), - active_worker: None, - url: USVString(url.as_str().to_owned()), + active_worker: Default::default(), + url: url, frame_type: FrameType::None, id: Uuid::new_v4() } @@ -39,12 +39,24 @@ impl Client { window, Wrap) } + + pub fn creation_url(&self) -> ServoUrl { + self.url.clone() + } + + pub fn get_controller(&self) -> Option<Root<ServiceWorker>> { + self.active_worker.get() + } + + pub fn set_controller(&self, worker: &ServiceWorker) { + self.active_worker.set(Some(worker)); + } } impl ClientMethods for Client { // https://w3c.github.io/ServiceWorker/#client-url-attribute fn Url(&self) -> USVString { - self.url.clone() + USVString(self.url.as_str().to_owned()) } // https://w3c.github.io/ServiceWorker/#client-frametype |