aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/globalscope.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r--components/script/dom/globalscope.rs19
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 {