diff options
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 7bd0e28be6a..385939000bc 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -58,6 +58,7 @@ use profile_traits::{mem as profile_mem, time as profile_time}; use script_traits::{MsDuration, ScriptToConstellationChan, TimerEvent}; use script_traits::{TimerEventId, TimerSchedulerMsg, TimerSource}; use servo_url::{MutableOrigin, ServoUrl}; +use std::borrow::Cow; use std::cell::Cell; use std::collections::hash_map::Entry; use std::collections::HashMap; @@ -157,6 +158,12 @@ pub struct GlobalScope { /// <https://html.spec.whatwg.org/multipage/#outstanding-rejected-promises-weak-set> #[ignore_malloc_size_of = "mozjs"] consumed_rejections: DomRefCell<Vec<Box<Heap<*mut JSObject>>>>, + + /// True if headless mode. + is_headless: bool, + + /// An optional string allowing the user agent to be set for testing. + user_agent: Cow<'static, str>, } impl GlobalScope { @@ -171,6 +178,8 @@ impl GlobalScope { timer_event_chan: IpcSender<TimerEvent>, origin: MutableOrigin, microtask_queue: Rc<MicrotaskQueue>, + is_headless: bool, + user_agent: Cow<'static, str>, ) -> Self { Self { eventtarget: EventTarget::new_inherited(), @@ -193,6 +202,8 @@ impl GlobalScope { event_source_tracker: DOMTracker::new(), uncaught_rejections: Default::default(), consumed_rejections: Default::default(), + is_headless, + user_agent, } } @@ -799,6 +810,14 @@ impl GlobalScope { } unreachable!(); } + + pub fn is_headless(&self) -> bool { + self.is_headless + } + + pub fn get_user_agent(&self) -> Cow<'static, str> { + self.user_agent.clone() + } } fn timestamp_in_ms(time: Timespec) -> u64 { |