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