Add API base url method to global objects

This commit is contained in:
Keith Yeung 2016-04-09 17:07:18 -04:00
parent 32e53b80e2
commit c75079eff3
4 changed files with 12 additions and 11 deletions

View file

@ -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> {

View file

@ -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,

View file

@ -1,5 +0,0 @@
[open-url-base.htm]
type: testharness
[XMLHttpRequest: open() resolving URLs - ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[send-non-same-origin.sub.htm]
type: testharness
[XMLHttpRequest: send() - non same-origin (folder.txt)]
expected: FAIL