script/dom/
dissimilaroriginlocation.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;
6
7use crate::dom::bindings::codegen::Bindings::DissimilarOriginLocationBinding::DissimilarOriginLocationMethods;
8use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
9use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
10use crate::dom::bindings::root::{Dom, DomRoot};
11use crate::dom::bindings::str::{DOMString, USVString};
12use crate::dom::dissimilaroriginwindow::DissimilarOriginWindow;
13use crate::script_runtime::CanGc;
14
15/// Represents a dissimilar-origin `Location` that exists in another script thread.
16///
17/// Since the `Location` is in a different script thread, we cannot access it
18/// directly, but some of its accessors (for example setting `location.href`)
19/// still need to function.
20
21#[dom_struct]
22pub(crate) struct DissimilarOriginLocation {
23    /// The reflector. Once we have XOWs, this will have a cross-origin
24    /// wrapper placed around it.
25    reflector: Reflector,
26
27    /// The window associated with this location.
28    window: Dom<DissimilarOriginWindow>,
29}
30
31impl DissimilarOriginLocation {
32    fn new_inherited(window: &DissimilarOriginWindow) -> DissimilarOriginLocation {
33        DissimilarOriginLocation {
34            reflector: Reflector::new(),
35            window: Dom::from_ref(window),
36        }
37    }
38
39    pub(crate) fn new(
40        window: &DissimilarOriginWindow,
41        can_gc: CanGc,
42    ) -> DomRoot<DissimilarOriginLocation> {
43        reflect_dom_object(
44            Box::new(DissimilarOriginLocation::new_inherited(window)),
45            window,
46            can_gc,
47        )
48    }
49}
50
51impl DissimilarOriginLocationMethods<crate::DomTypeHolder> for DissimilarOriginLocation {
52    /// <https://html.spec.whatwg.org/multipage/#dom-location-href>
53    fn GetHref(&self) -> Fallible<USVString> {
54        Err(Error::Security(None))
55    }
56
57    /// <https://html.spec.whatwg.org/multipage/#dom-location-href>
58    fn SetHref(&self, _: USVString) -> ErrorResult {
59        // TODO: setting href on a cross-origin window should succeed?
60        Err(Error::Security(None))
61    }
62
63    /// <https://html.spec.whatwg.org/multipage/#dom-location-assign>
64    fn Assign(&self, _: USVString) -> Fallible<()> {
65        // TODO: setting href on a cross-origin window should succeed?
66        Err(Error::Security(None))
67    }
68
69    /// <https://html.spec.whatwg.org/multipage/#dom-location-replace>
70    fn Replace(&self, _: USVString) -> Fallible<()> {
71        // TODO: replacing href on a cross-origin window should succeed?
72        Err(Error::Security(None))
73    }
74
75    /// <https://html.spec.whatwg.org/multipage/#dom-location-reload>
76    fn Reload(&self) -> Fallible<()> {
77        Err(Error::Security(None))
78    }
79
80    /// <https://html.spec.whatwg.org/multipage/#dom-location-href>
81    fn Stringifier(&self) -> Fallible<DOMString> {
82        Err(Error::Security(None))
83    }
84}