diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/global.rs | 11 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 9cac7d9b940..e50f8ace9d0 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -143,6 +143,17 @@ impl<'a> GlobalRef<'a> { } } + /// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url) + /// for this global scope. + pub fn api_base_url(&self) -> Url { + match *self { + // https://html.spec.whatwg.org/multipage/#script-settings-for-browsing-contexts:api-base-url + GlobalRef::Window(ref window) => window.Document().base_url(), + // https://html.spec.whatwg.org/multipage/#script-settings-for-workers:api-base-url + GlobalRef::Worker(ref worker) => worker.get_url().clone(), + } + } + /// `ScriptChan` used to send messages to the event loop of this global's /// thread. pub fn script_chan(&self) -> Box<ScriptChan + Send> { diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 4569a9e7d4a..701deaa8189 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -352,7 +352,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest { } // Step 2 - let base = self.global().r().get_url(); + let base = self.global().r().api_base_url(); // Step 6 let mut parsed_url = match base.join(&url.0) { Ok(parsed) => parsed, |