diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2016-10-02 01:15:12 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2016-10-06 21:35:43 +0200 |
commit | 3302a53d38721fa18bcf0c3886f24f37cfd6bd13 (patch) | |
tree | 37cdd5aac3f9f5dd7abe06fbb219b8c277d52108 /components/script/dom/globalscope.rs | |
parent | cb02d7911a5dd98846ddf4a0c2dd6b2fc9032a07 (diff) | |
download | servo-3302a53d38721fa18bcf0c3886f24f37cfd6bd13.tar.gz servo-3302a53d38721fa18bcf0c3886f24f37cfd6bd13.zip |
Introduce GlobalScope::api_base_url
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index b455536ed1c..96787adb303 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -4,11 +4,15 @@ use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::reflector::Reflectable; use dom::bindings::str::DOMString; use dom::crypto::Crypto; use dom::eventtarget::EventTarget; +use dom::window::Window; +use dom::workerglobalscope::WorkerGlobalScope; use ipc_channel::ipc::IpcSender; use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext}; use msg::constellation_msg::PipelineId; @@ -18,6 +22,7 @@ use std::cell::Cell; use std::collections::HashMap; use std::collections::hash_map::Entry; use time::{Timespec, get_time}; +use url::Url; #[dom_struct] pub struct GlobalScope { @@ -160,6 +165,20 @@ impl GlobalScope { pub fn pipeline_id(&self) -> PipelineId { self.pipeline_id } + + /// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url) + /// for this global scope. + pub fn api_base_url(&self) -> Url { + if let Some(window) = self.downcast::<Window>() { + // https://html.spec.whatwg.org/multipage/#script-settings-for-browsing-contexts:api-base-url + return window.Document().base_url(); + } + if let Some(worker) = self.downcast::<WorkerGlobalScope>() { + // https://html.spec.whatwg.org/multipage/#script-settings-for-workers:api-base-url + return worker.get_url().clone(); + } + unreachable!(); + } } fn timestamp_in_ms(time: Timespec) -> u64 { |