aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/trace.rs3
-rw-r--r--components/script/dom/characterdata.rs27
-rw-r--r--components/script/dom/dissimilaroriginwindow.rs2
-rw-r--r--components/script/dom/globalscope.rs19
-rw-r--r--components/script/dom/htmlscriptelement.rs3
-rw-r--r--components/script/dom/navigator.rs2
-rw-r--r--components/script/dom/navigatorinfo.rs6
-rw-r--r--components/script/dom/permissions.rs30
-rw-r--r--components/script/dom/userscripts.rs5
-rw-r--r--components/script/dom/window.rs56
-rw-r--r--components/script/dom/workerglobalscope.rs4
-rw-r--r--components/script/dom/workernavigator.rs2
-rw-r--r--components/script/dom/workletglobalscope.rs7
13 files changed, 126 insertions, 40 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index b690687d034..97d440de4a0 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -109,6 +109,7 @@ use servo_media::streams::MediaStreamType;
use servo_media::webrtc::WebRtcController;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use smallvec::SmallVec;
+use std::borrow::Cow;
use std::cell::{Cell, RefCell, UnsafeCell};
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use std::hash::{BuildHasher, Hash};
@@ -164,6 +165,8 @@ unsafe_no_jsmanaged_fields!(TexDataType, TexFormat);
unsafe_no_jsmanaged_fields!(*mut JobQueue);
+unsafe_no_jsmanaged_fields!(Cow<'static, str>);
+
/// Trace a `JSVal`.
pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: &Heap<JSVal>) {
unsafe {
diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs
index 54f3ab0e360..87aa8bd59fa 100644
--- a/components/script/dom/characterdata.rs
+++ b/components/script/dom/characterdata.rs
@@ -24,7 +24,6 @@ use crate::dom::processinginstruction::ProcessingInstruction;
use crate::dom::text::Text;
use crate::dom::virtualmethods::vtable_for;
use dom_struct::dom_struct;
-use servo_config::opts;
use std::cell::Ref;
// https://dom.spec.whatwg.org/#characterdata
@@ -122,11 +121,16 @@ impl CharacterDataMethods for CharacterData {
// https://dom.spec.whatwg.org/#dom-characterdata-substringdata
fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString> {
+ let replace_surrogates = self
+ .upcast::<Node>()
+ .owner_doc()
+ .window()
+ .replace_surrogates();
let data = self.data.borrow();
// Step 1.
let mut substring = String::new();
let remaining;
- match split_at_utf16_code_unit_offset(&data, offset) {
+ match split_at_utf16_code_unit_offset(&data, offset, replace_surrogates) {
Ok((_, astral, s)) => {
// As if we had split the UTF-16 surrogate pair in half
// and then transcoded that to UTF-8 lossily,
@@ -139,7 +143,7 @@ impl CharacterDataMethods for CharacterData {
// Step 2.
Err(()) => return Err(Error::IndexSize),
}
- match split_at_utf16_code_unit_offset(remaining, count) {
+ match split_at_utf16_code_unit_offset(remaining, count, replace_surrogates) {
// Steps 3.
Err(()) => substring = substring + remaining,
// Steps 4.
@@ -176,11 +180,16 @@ impl CharacterDataMethods for CharacterData {
fn ReplaceData(&self, offset: u32, count: u32, arg: DOMString) -> ErrorResult {
let mut new_data;
{
+ let replace_surrogates = self
+ .upcast::<Node>()
+ .owner_doc()
+ .window()
+ .replace_surrogates();
let data = self.data.borrow();
let prefix;
let replacement_before;
let remaining;
- match split_at_utf16_code_unit_offset(&data, offset) {
+ match split_at_utf16_code_unit_offset(&data, offset, replace_surrogates) {
Ok((p, astral, r)) => {
prefix = p;
// As if we had split the UTF-16 surrogate pair in half
@@ -194,7 +203,7 @@ impl CharacterDataMethods for CharacterData {
};
let replacement_after;
let suffix;
- match split_at_utf16_code_unit_offset(remaining, count) {
+ match split_at_utf16_code_unit_offset(remaining, count, replace_surrogates) {
// Steps 3.
Err(()) => {
replacement_after = "";
@@ -305,7 +314,11 @@ impl LayoutCharacterDataHelpers for LayoutDom<CharacterData> {
/// Note that the third variant is only ever returned when the `-Z replace-surrogates`
/// command-line option is specified.
/// When it *would* be returned but the option is *not* specified, this function panics.
-fn split_at_utf16_code_unit_offset(s: &str, offset: u32) -> Result<(&str, Option<char>, &str), ()> {
+fn split_at_utf16_code_unit_offset(
+ s: &str,
+ offset: u32,
+ replace_surrogates: bool,
+) -> Result<(&str, Option<char>, &str), ()> {
let mut code_units = 0;
for (i, c) in s.char_indices() {
if code_units == offset {
@@ -315,7 +328,7 @@ fn split_at_utf16_code_unit_offset(s: &str, offset: u32) -> Result<(&str, Option
code_units += 1;
if c > '\u{FFFF}' {
if code_units == offset {
- if opts::get().replace_surrogates {
+ if replace_surrogates {
debug_assert_eq!(c.len_utf8(), 4);
return Ok((&s[..i], Some(c), &s[i + c.len_utf8()..]));
}
diff --git a/components/script/dom/dissimilaroriginwindow.rs b/components/script/dom/dissimilaroriginwindow.rs
index b66db40da3b..54523bb59ea 100644
--- a/components/script/dom/dissimilaroriginwindow.rs
+++ b/components/script/dom/dissimilaroriginwindow.rs
@@ -62,6 +62,8 @@ impl DissimilarOriginWindow {
// FIXME(nox): The microtask queue is probably not important
// here, but this whole DOM interface is a hack anyway.
global_to_clone_from.microtask_queue().clone(),
+ global_to_clone_from.is_headless(),
+ global_to_clone_from.get_user_agent(),
),
window_proxy: Dom::from_ref(window_proxy),
location: Default::default(),
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 {
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs
index 369f43b6019..4325add0212 100644
--- a/components/script/dom/htmlscriptelement.rs
+++ b/components/script/dom/htmlscriptelement.rs
@@ -38,7 +38,6 @@ use net_traits::request::{
use net_traits::{FetchMetadata, FetchResponseListener, Metadata, NetworkError};
use net_traits::{ResourceFetchTiming, ResourceTimingType};
use servo_atoms::Atom;
-use servo_config::opts;
use servo_url::ServoUrl;
use std::cell::Cell;
use std::fs::File;
@@ -533,7 +532,7 @@ impl HTMLScriptElement {
}
fn unminify_js(&self, script: &mut ClassicScript) {
- if !opts::get().unminify_js {
+ if !self.parser_document.window().unminify_js() {
return;
}
diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs
index 8a5524b437b..8a0f6a21d98 100644
--- a/components/script/dom/navigator.rs
+++ b/components/script/dom/navigator.rs
@@ -103,7 +103,7 @@ impl NavigatorMethods for Navigator {
// https://html.spec.whatwg.org/multipage/#dom-navigator-useragent
fn UserAgent(&self) -> DOMString {
- navigatorinfo::UserAgent()
+ navigatorinfo::UserAgent(self.global().get_user_agent())
}
// https://html.spec.whatwg.org/multipage/#dom-navigator-appversion
diff --git a/components/script/dom/navigatorinfo.rs b/components/script/dom/navigatorinfo.rs
index 117bfce87c1..0ebb9043765 100644
--- a/components/script/dom/navigatorinfo.rs
+++ b/components/script/dom/navigatorinfo.rs
@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::str::DOMString;
-use servo_config::opts;
+use std::borrow::Cow;
pub fn Product() -> DOMString {
DOMString::from("Gecko")
@@ -53,8 +53,8 @@ pub fn Platform() -> DOMString {
DOMString::from("iOS")
}
-pub fn UserAgent() -> DOMString {
- DOMString::from(&*opts::get().user_agent)
+pub fn UserAgent(user_agent: Cow<'static, str>) -> DOMString {
+ DOMString::from(&*user_agent)
}
pub fn AppVersion() -> DOMString {
diff --git a/components/script/dom/permissions.rs b/components/script/dom/permissions.rs
index e7d3b600814..87dc88636da 100644
--- a/components/script/dom/permissions.rs
+++ b/components/script/dom/permissions.rs
@@ -21,8 +21,6 @@ use dom_struct::dom_struct;
use js::conversions::ConversionResult;
use js::jsapi::{JSContext, JSObject};
use js::jsval::{ObjectValue, UndefinedValue};
-#[cfg(target_os = "linux")]
-use servo_config::opts;
use servo_config::pref;
use std::rc::Rc;
#[cfg(target_os = "linux")]
@@ -269,14 +267,15 @@ impl PermissionAlgorithm for Permissions {
// Step 3.
PermissionState::Prompt => {
let perm_name = status.get_query();
- // https://w3c.github.io/permissions/#request-permission-to-use (Step 3 - 4)
- let state = prompt_user(&format!(
- "{} {} ?",
- REQUEST_DIALOG_MESSAGE,
- perm_name.clone()
- ));
let globalscope = GlobalScope::current().expect("No current global object");
+
+ // https://w3c.github.io/permissions/#request-permission-to-use (Step 3 - 4)
+ let state = prompt_user(
+ &format!("{} {} ?", REQUEST_DIALOG_MESSAGE, perm_name.clone()),
+ globalscope.is_headless(),
+ );
+
globalscope
.as_window()
.permission_state_invocation_results()
@@ -322,10 +321,11 @@ pub fn get_descriptor_permission_state(
.permission_state_invocation_results()
.borrow_mut()
.remove(&permission_name.to_string());
- prompt_user(&format!(
- "The {} {}",
- permission_name, NONSECURE_DIALOG_MESSAGE
- ))
+
+ prompt_user(
+ &format!("The {} {}", permission_name, NONSECURE_DIALOG_MESSAGE),
+ settings.is_headless(),
+ )
}
};
@@ -351,8 +351,8 @@ pub fn get_descriptor_permission_state(
}
#[cfg(target_os = "linux")]
-fn prompt_user(message: &str) -> PermissionState {
- if opts::get().headless {
+fn prompt_user(message: &str, headless: bool) -> PermissionState {
+ if headless {
return PermissionState::Denied;
}
match tinyfiledialogs::message_box_yes_no(
@@ -367,7 +367,7 @@ fn prompt_user(message: &str) -> PermissionState {
}
#[cfg(not(target_os = "linux"))]
-fn prompt_user(_message: &str) -> PermissionState {
+fn prompt_user(_message: &str, _headless: bool) -> PermissionState {
// TODO popup only supported on linux
PermissionState::Denied
}
diff --git a/components/script/dom/userscripts.rs b/components/script/dom/userscripts.rs
index 1ba79ac5b69..af7c2b6d3f1 100644
--- a/components/script/dom/userscripts.rs
+++ b/components/script/dom/userscripts.rs
@@ -8,17 +8,16 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlheadelement::HTMLHeadElement;
use crate::dom::node::document_from_node;
use js::jsval::UndefinedValue;
-use servo_config::opts;
use std::fs::{read_dir, File};
use std::io::Read;
use std::path::PathBuf;
pub fn load_script(head: &HTMLHeadElement) {
- let path_str = match opts::get().userscripts.clone() {
+ let doc = document_from_node(head);
+ let path_str = match doc.window().get_userscripts_path() {
Some(p) => p,
None => return,
};
- let doc = document_from_node(head);
let win = Trusted::new(doc.window());
doc.add_delayed_task(task!(UserScriptExecute: move || {
let win = win.root();
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index ed87fa5e949..a1afdc34a82 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -106,9 +106,9 @@ use script_traits::{ConstellationControlMsg, DocumentState, LoadData};
use script_traits::{ScriptMsg, ScriptToConstellationChan, ScrollState, TimerEvent, TimerEventId};
use script_traits::{TimerSchedulerMsg, WindowSizeData, WindowSizeType};
use selectors::attr::CaseSensitivity;
-use servo_config::opts;
use servo_geometry::{f32_rect_to_au_rect, MaxRect};
use servo_url::{Host, ImmutableOrigin, MutableOrigin, ServoUrl};
+use std::borrow::Cow;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::collections::hash_map::Entry;
@@ -299,6 +299,24 @@ pub struct Window {
/// Flag that indicates if the layout thread is busy handling a request.
#[ignore_malloc_size_of = "Arc<T> is hard"]
layout_is_busy: Arc<AtomicBool>,
+
+ /// Emits notifications when there is a relayout.
+ relayout_event: bool,
+
+ /// True if it is safe to write to the image.
+ prepare_for_screenshot: bool,
+
+ /// Unminify Javascript.
+ unminify_js: bool,
+
+ /// Where to load userscripts from, if any. An empty string will load from
+ /// the resources/user-agent-js directory, and if the option isn't passed userscripts
+ /// won't be loaded.
+ userscripts_path: Option<String>,
+
+ /// Replace unpaired surrogates in DOM strings with U+FFFD.
+ /// See <https://github.com/servo/servo/issues/6564>
+ replace_surrogates: bool,
}
impl Window {
@@ -450,6 +468,18 @@ impl Window {
pub fn get_webrender_api_sender(&self) -> RenderApiSender {
self.webrender_api_sender.clone()
}
+
+ pub fn get_userscripts_path(&self) -> Option<String> {
+ self.userscripts_path.clone()
+ }
+
+ pub fn replace_surrogates(&self) -> bool {
+ self.replace_surrogates
+ }
+
+ pub fn unminify_js(&self) -> bool {
+ self.unminify_js
+ }
}
// https://html.spec.whatwg.org/multipage/#atob
@@ -1402,7 +1432,7 @@ impl Window {
let (join_chan, join_port) = unbounded();
// On debug mode, print the reflow event information.
- if opts::get().relayout_event {
+ if self.relayout_event {
debug_reflow_events(
self.upcast::<GlobalScope>().pipeline_id(),
&reflow_goal,
@@ -1540,11 +1570,7 @@ impl Window {
// When all these conditions are met, notify the constellation
// that this pipeline is ready to write the image (from the script thread
// perspective at least).
- if (opts::get().output_file.is_some() ||
- opts::get().exit_after_load ||
- opts::get().webdriver_port.is_some()) &&
- for_display
- {
+ if self.prepare_for_screenshot && for_display {
let document = self.Document();
// Checks if the html element has reftest-wait attribute present.
@@ -1704,7 +1730,7 @@ impl Window {
assert!(self.document.get().is_none());
assert!(document.window() == self);
self.document.set(Some(&document));
- if !opts::get().unminify_js {
+ if !self.unminify_js {
return;
}
// Create a folder for the document host to store unminified scripts.
@@ -2043,6 +2069,13 @@ impl Window {
webrender_document: DocumentId,
webrender_api_sender: RenderApiSender,
layout_is_busy: Arc<AtomicBool>,
+ relayout_event: bool,
+ prepare_for_screenshot: bool,
+ unminify_js: bool,
+ userscripts_path: Option<String>,
+ is_headless: bool,
+ replace_surrogates: bool,
+ user_agent: Cow<'static, str>,
) -> DomRoot<Self> {
let layout_rpc: Box<dyn LayoutRPC + Send> = {
let (rpc_send, rpc_recv) = unbounded();
@@ -2065,6 +2098,8 @@ impl Window {
timer_event_chan,
origin,
microtask_queue,
+ is_headless,
+ user_agent,
),
script_chan,
task_manager,
@@ -2116,6 +2151,11 @@ impl Window {
webrender_api_sender,
has_sent_idle_message: Cell::new(false),
layout_is_busy,
+ relayout_event,
+ prepare_for_screenshot,
+ unminify_js,
+ userscripts_path,
+ replace_surrogates,
});
unsafe { WindowBinding::Wrap(runtime.cx(), win) }
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index 87722f2358e..04aabe6db17 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -73,6 +73,8 @@ pub fn prepare_workerscope_init(
worker_id: global.get_next_worker_id(),
pipeline_id: global.pipeline_id(),
origin: global.origin().immutable().clone(),
+ is_headless: global.is_headless(),
+ user_agent: global.get_user_agent(),
};
init
@@ -132,6 +134,8 @@ impl WorkerGlobalScope {
timer_event_chan,
MutableOrigin::new(init.origin),
runtime.microtask_queue.clone(),
+ init.is_headless,
+ init.user_agent,
),
worker_id: init.worker_id,
worker_name,
diff --git a/components/script/dom/workernavigator.rs b/components/script/dom/workernavigator.rs
index 6c4867eda9d..92dfa9951e5 100644
--- a/components/script/dom/workernavigator.rs
+++ b/components/script/dom/workernavigator.rs
@@ -79,7 +79,7 @@ impl WorkerNavigatorMethods for WorkerNavigator {
// https://html.spec.whatwg.org/multipage/#dom-navigator-useragent
fn UserAgent(&self) -> DOMString {
- navigatorinfo::UserAgent()
+ navigatorinfo::UserAgent(self.global().get_user_agent())
}
// https://html.spec.whatwg.org/multipage/#dom-navigator-appversion
diff --git a/components/script/dom/workletglobalscope.rs b/components/script/dom/workletglobalscope.rs
index 7532ff1aca8..20f99c76ee2 100644
--- a/components/script/dom/workletglobalscope.rs
+++ b/components/script/dom/workletglobalscope.rs
@@ -30,6 +30,7 @@ use servo_atoms::Atom;
use servo_url::ImmutableOrigin;
use servo_url::MutableOrigin;
use servo_url::ServoUrl;
+use std::borrow::Cow;
use std::sync::Arc;
#[dom_struct]
@@ -72,6 +73,8 @@ impl WorkletGlobalScope {
timer_event_chan,
MutableOrigin::new(ImmutableOrigin::new_opaque()),
Default::default(),
+ init.is_headless,
+ init.user_agent.clone(),
),
base_url,
to_script_thread_sender: init.to_script_thread_sender.clone(),
@@ -153,6 +156,10 @@ pub struct WorkletGlobalScopeInit {
pub scheduler_chan: IpcSender<TimerSchedulerMsg>,
/// The image cache
pub image_cache: Arc<dyn ImageCache>,
+ /// True if in headless mode
+ pub is_headless: bool,
+ /// An optional string allowing the user agent to be set for testing
+ pub user_agent: Cow<'static, str>,
}
/// <https://drafts.css-houdini.org/worklets/#worklet-global-scope-type>