aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorKeith Yeung <kungfukeith11@gmail.com>2016-04-09 17:07:18 -0400
committerKeith Yeung <kungfukeith11@gmail.com>2016-04-11 07:49:31 -0400
commitc75079eff30c577a6f3fd6bf25f52fde31e82207 (patch)
treece2874654a7a2ef466ac8d75d6994dc18b5a9234 /components
parent32e53b80e28731cd05ddbe561f99e9570a34ff07 (diff)
downloadservo-c75079eff30c577a6f3fd6bf25f52fde31e82207.tar.gz
servo-c75079eff30c577a6f3fd6bf25f52fde31e82207.zip
Add API base url method to global objects
Diffstat (limited to 'components')
-rw-r--r--components/script/dom/bindings/global.rs11
-rw-r--r--components/script/dom/xmlhttprequest.rs2
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,