script/dom/
workerlocation.rs1use dom_struct::dom_struct;
6use servo_url::{ImmutableOrigin, ServoUrl};
7
8use crate::dom::bindings::codegen::Bindings::WorkerLocationBinding::WorkerLocationMethods;
9use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::bindings::str::USVString;
12use crate::dom::urlhelper::UrlHelper;
13use crate::dom::workerglobalscope::WorkerGlobalScope;
14use crate::script_runtime::CanGc;
15
16#[dom_struct]
18pub(crate) struct WorkerLocation {
19 reflector_: Reflector,
20 #[no_trace]
21 url: ServoUrl,
22}
23
24impl WorkerLocation {
25 fn new_inherited(url: ServoUrl) -> WorkerLocation {
26 WorkerLocation {
27 reflector_: Reflector::new(),
28 url,
29 }
30 }
31
32 pub(crate) fn new(
33 global: &WorkerGlobalScope,
34 url: ServoUrl,
35 can_gc: CanGc,
36 ) -> DomRoot<WorkerLocation> {
37 reflect_dom_object(Box::new(WorkerLocation::new_inherited(url)), global, can_gc)
38 }
39
40 #[allow(dead_code)]
42 pub(crate) fn origin(&self) -> ImmutableOrigin {
43 self.url.origin()
44 }
45}
46
47impl WorkerLocationMethods<crate::DomTypeHolder> for WorkerLocation {
48 fn Hash(&self) -> USVString {
50 UrlHelper::Hash(&self.url)
51 }
52
53 fn Host(&self) -> USVString {
55 UrlHelper::Host(&self.url)
56 }
57
58 fn Hostname(&self) -> USVString {
60 UrlHelper::Hostname(&self.url)
61 }
62
63 fn Href(&self) -> USVString {
65 UrlHelper::Href(&self.url)
66 }
67
68 fn Origin(&self) -> USVString {
70 UrlHelper::Origin(&self.url)
71 }
72
73 fn Pathname(&self) -> USVString {
75 UrlHelper::Pathname(&self.url)
76 }
77
78 fn Port(&self) -> USVString {
80 UrlHelper::Port(&self.url)
81 }
82
83 fn Protocol(&self) -> USVString {
85 UrlHelper::Protocol(&self.url)
86 }
87
88 fn Search(&self) -> USVString {
90 UrlHelper::Search(&self.url)
91 }
92}