script/dom/
urlhelper.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 std::borrow::ToOwned;
6
7use servo_url::ServoUrl;
8use url::quirks;
9
10use crate::dom::bindings::str::USVString;
11
12#[derive(MallocSizeOf)]
13pub(crate) struct UrlHelper;
14
15#[allow(non_snake_case)]
16impl UrlHelper {
17    pub(crate) fn Origin(url: &ServoUrl) -> USVString {
18        USVString(quirks::origin(url.as_url()).to_owned())
19    }
20    pub(crate) fn Href(url: &ServoUrl) -> USVString {
21        USVString(quirks::href(url.as_url()).to_owned())
22    }
23    pub(crate) fn Hash(url: &ServoUrl) -> USVString {
24        USVString(quirks::hash(url.as_url()).to_owned())
25    }
26    pub(crate) fn Host(url: &ServoUrl) -> USVString {
27        USVString(quirks::host(url.as_url()).to_owned())
28    }
29    pub(crate) fn Port(url: &ServoUrl) -> USVString {
30        USVString(quirks::port(url.as_url()).to_owned())
31    }
32    pub(crate) fn Search(url: &ServoUrl) -> USVString {
33        USVString(quirks::search(url.as_url()).to_owned())
34    }
35    pub(crate) fn Hostname(url: &ServoUrl) -> USVString {
36        USVString(quirks::hostname(url.as_url()).to_owned())
37    }
38    pub(crate) fn Password(url: &ServoUrl) -> USVString {
39        USVString(quirks::password(url.as_url()).to_owned())
40    }
41    pub(crate) fn Pathname(url: &ServoUrl) -> USVString {
42        USVString(quirks::pathname(url.as_url()).to_owned())
43    }
44    pub(crate) fn Protocol(url: &ServoUrl) -> USVString {
45        USVString(quirks::protocol(url.as_url()).to_owned())
46    }
47    pub(crate) fn Username(url: &ServoUrl) -> USVString {
48        USVString(quirks::username(url.as_url()).to_owned())
49    }
50    pub(crate) fn SetHash(url: &mut ServoUrl, value: USVString) {
51        quirks::set_hash(url.as_mut_url(), &value.0)
52    }
53    pub(crate) fn SetHost(url: &mut ServoUrl, value: USVString) {
54        let _ = quirks::set_host(url.as_mut_url(), &value.0);
55    }
56    pub(crate) fn SetPort(url: &mut ServoUrl, value: USVString) {
57        let _ = quirks::set_port(url.as_mut_url(), &value.0);
58    }
59    pub(crate) fn SetSearch(url: &mut ServoUrl, value: USVString) {
60        quirks::set_search(url.as_mut_url(), &value.0)
61    }
62    pub(crate) fn SetPathname(url: &mut ServoUrl, value: USVString) {
63        quirks::set_pathname(url.as_mut_url(), &value.0)
64    }
65    pub(crate) fn SetHostname(url: &mut ServoUrl, value: USVString) {
66        let _ = quirks::set_hostname(url.as_mut_url(), &value.0);
67    }
68    pub(crate) fn SetPassword(url: &mut ServoUrl, value: USVString) {
69        let _ = quirks::set_password(url.as_mut_url(), &value.0);
70    }
71    pub(crate) fn SetProtocol(url: &mut ServoUrl, value: USVString) {
72        let _ = quirks::set_protocol(url.as_mut_url(), &value.0);
73    }
74    pub(crate) fn SetUsername(url: &mut ServoUrl, value: USVString) {
75        let _ = quirks::set_username(url.as_mut_url(), &value.0);
76    }
77}