Skip to main content

script/dom/
client.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use script_bindings::reflector::Reflector;
7use servo_url::ServoUrl;
8use uuid::Uuid;
9
10use crate::dom::bindings::codegen::Bindings::ClientBinding::{ClientMethods, FrameType};
11use crate::dom::bindings::root::MutNullableDom;
12use crate::dom::bindings::str::{DOMString, USVString};
13use crate::dom::serviceworker::ServiceWorker;
14
15#[dom_struct]
16pub(crate) struct Client {
17    reflector_: Reflector,
18    active_worker: MutNullableDom<ServiceWorker>,
19    #[no_trace]
20    url: ServoUrl,
21    frame_type: FrameType,
22    #[no_trace]
23    id: Uuid,
24}
25
26impl ClientMethods<crate::DomTypeHolder> for Client {
27    /// <https://w3c.github.io/ServiceWorker/#client-url-attribute>
28    fn Url(&self) -> USVString {
29        USVString(self.url.as_str().to_owned())
30    }
31
32    /// <https://w3c.github.io/ServiceWorker/#client-frametype>
33    fn FrameType(&self) -> FrameType {
34        self.frame_type
35    }
36
37    /// <https://w3c.github.io/ServiceWorker/#client-id>
38    fn Id(&self) -> DOMString {
39        format!("{}", self.id).into()
40    }
41}