mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Script: removed a few opts::get()
This commit is contained in:
parent
57205318c5
commit
42569280e2
17 changed files with 238 additions and 45 deletions
|
@ -66,7 +66,7 @@ pub struct Opts {
|
|||
|
||||
pub output_file: Option<String>,
|
||||
|
||||
/// Replace unpaires surrogates in DOM strings with U+FFFD.
|
||||
/// Replace unpaired surrogates in DOM strings with U+FFFD.
|
||||
/// See <https://github.com/servo/servo/issues/6564>
|
||||
pub replace_surrogates: bool,
|
||||
|
||||
|
|
|
@ -559,6 +559,17 @@ impl UnprivilegedPipelineContent {
|
|||
layout_is_busy: layout_thread_busy_flag.clone(),
|
||||
},
|
||||
self.load_data.clone(),
|
||||
self.opts.profile_script_events,
|
||||
self.opts.print_pwm,
|
||||
self.opts.relayout_event,
|
||||
self.opts.output_file.is_some() ||
|
||||
self.opts.exit_after_load ||
|
||||
self.opts.webdriver_port.is_some(),
|
||||
self.opts.unminify_js,
|
||||
self.opts.userscripts,
|
||||
self.opts.headless,
|
||||
self.opts.replace_surrogates,
|
||||
self.opts.user_agent,
|
||||
);
|
||||
|
||||
LTF::create(
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()..]));
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -135,8 +135,8 @@ use script_traits::{ScriptToConstellationChan, TimerEvent, TimerSchedulerMsg};
|
|||
use script_traits::{TimerSource, TouchEventType, TouchId, UntrustedNodeAddress, WheelDelta};
|
||||
use script_traits::{UpdatePipelineIdReason, WindowSizeData, WindowSizeType};
|
||||
use servo_atoms::Atom;
|
||||
use servo_config::opts;
|
||||
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{hash_map, HashMap, HashSet};
|
||||
|
@ -644,6 +644,36 @@ pub struct ScriptThread {
|
|||
|
||||
/// FIXME(victor):
|
||||
webrender_api_sender: RenderApiSender,
|
||||
|
||||
/// Periodically print out on which events script threads spend their processing time.
|
||||
profile_script_events: bool,
|
||||
|
||||
/// Print Progressive Web Metrics to console.
|
||||
print_pwm: bool,
|
||||
|
||||
/// 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>,
|
||||
|
||||
/// True if headless mode.
|
||||
headless: bool,
|
||||
|
||||
/// Replace unpaired surrogates in DOM strings with U+FFFD.
|
||||
/// See <https://github.com/servo/servo/issues/6564>
|
||||
replace_surrogates: bool,
|
||||
|
||||
/// An optional string allowing the user agent to be set for testing.
|
||||
user_agent: Cow<'static, str>,
|
||||
}
|
||||
|
||||
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
||||
|
@ -681,6 +711,15 @@ impl ScriptThreadFactory for ScriptThread {
|
|||
fn create(
|
||||
state: InitialScriptState,
|
||||
load_data: LoadData,
|
||||
profile_script_events: bool,
|
||||
print_pwm: bool,
|
||||
relayout_event: bool,
|
||||
prepare_for_screenshot: bool,
|
||||
unminify_js: bool,
|
||||
userscripts_path: Option<String>,
|
||||
headless: bool,
|
||||
replace_surrogates: bool,
|
||||
user_agent: Cow<'static, str>,
|
||||
) -> (Sender<message::Msg>, Receiver<message::Msg>) {
|
||||
let (script_chan, script_port) = unbounded();
|
||||
|
||||
|
@ -703,7 +742,20 @@ impl ScriptThreadFactory for ScriptThread {
|
|||
let window_size = state.window_size;
|
||||
let layout_is_busy = state.layout_is_busy.clone();
|
||||
|
||||
let script_thread = ScriptThread::new(state, script_port, script_chan.clone());
|
||||
let script_thread = ScriptThread::new(
|
||||
state,
|
||||
script_port,
|
||||
script_chan.clone(),
|
||||
profile_script_events,
|
||||
print_pwm,
|
||||
relayout_event,
|
||||
prepare_for_screenshot,
|
||||
unminify_js,
|
||||
userscripts_path,
|
||||
headless,
|
||||
replace_surrogates,
|
||||
user_agent,
|
||||
);
|
||||
|
||||
SCRIPT_THREAD_ROOT.with(|root| {
|
||||
root.set(Some(&script_thread as *const _));
|
||||
|
@ -963,6 +1015,8 @@ impl ScriptThread {
|
|||
to_constellation_sender: script_thread.script_sender.clone(),
|
||||
scheduler_chan: script_thread.scheduler_chan.clone(),
|
||||
image_cache: script_thread.image_cache.clone(),
|
||||
is_headless: script_thread.headless,
|
||||
user_agent: script_thread.user_agent.clone(),
|
||||
};
|
||||
Rc::new(WorkletThreadPool::spawn(init))
|
||||
})
|
||||
|
@ -1056,6 +1110,15 @@ impl ScriptThread {
|
|||
state: InitialScriptState,
|
||||
port: Receiver<MainThreadScriptMsg>,
|
||||
chan: Sender<MainThreadScriptMsg>,
|
||||
profile_script_events: bool,
|
||||
print_pwm: bool,
|
||||
relayout_event: bool,
|
||||
prepare_for_screenshot: bool,
|
||||
unminify_js: bool,
|
||||
userscripts_path: Option<String>,
|
||||
headless: bool,
|
||||
replace_surrogates: bool,
|
||||
user_agent: Cow<'static, str>,
|
||||
) -> ScriptThread {
|
||||
let runtime = new_rt_and_cx();
|
||||
let cx = runtime.cx();
|
||||
|
@ -1159,6 +1222,18 @@ impl ScriptThread {
|
|||
|
||||
webrender_document: state.webrender_document,
|
||||
webrender_api_sender: state.webrender_api_sender,
|
||||
|
||||
profile_script_events,
|
||||
print_pwm,
|
||||
|
||||
relayout_event,
|
||||
prepare_for_screenshot,
|
||||
unminify_js,
|
||||
|
||||
userscripts_path,
|
||||
headless,
|
||||
replace_surrogates,
|
||||
user_agent,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1537,7 +1612,7 @@ impl ScriptThread {
|
|||
{
|
||||
self.notify_activity_to_hang_monitor(&category);
|
||||
let start = precise_time_ns();
|
||||
let value = if opts::get().profile_script_events {
|
||||
let value = if self.profile_script_events {
|
||||
let profiler_cat = match category {
|
||||
ScriptThreadEventCategory::AttachLayout => ProfilerCategory::ScriptAttachLayout,
|
||||
ScriptThreadEventCategory::ConstellationMsg => {
|
||||
|
@ -1586,7 +1661,7 @@ impl ScriptThread {
|
|||
for (doc_id, doc) in self.documents.borrow().iter() {
|
||||
if let Some(pipeline_id) = pipeline_id {
|
||||
if pipeline_id == doc_id && end - start > MAX_TASK_NS {
|
||||
if opts::get().print_pwm {
|
||||
if self.print_pwm {
|
||||
println!(
|
||||
"Task took longer than max allowed ({:?}) {:?}",
|
||||
category,
|
||||
|
@ -2897,6 +2972,13 @@ impl ScriptThread {
|
|||
self.webrender_document,
|
||||
self.webrender_api_sender.clone(),
|
||||
incomplete.layout_is_busy,
|
||||
self.relayout_event,
|
||||
self.prepare_for_screenshot,
|
||||
self.unminify_js,
|
||||
self.userscripts_path.clone(),
|
||||
self.headless,
|
||||
self.replace_surrogates,
|
||||
self.user_agent.clone(),
|
||||
);
|
||||
|
||||
// Initialize the browsing context for the window.
|
||||
|
|
|
@ -49,6 +49,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|||
use servo_atoms::Atom;
|
||||
use servo_url::ImmutableOrigin;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
@ -644,6 +645,15 @@ pub trait ScriptThreadFactory {
|
|||
fn create(
|
||||
state: InitialScriptState,
|
||||
load_data: LoadData,
|
||||
profile_script_events: bool,
|
||||
print_pwm: bool,
|
||||
relayout_event: bool,
|
||||
prepare_for_screenshot: bool,
|
||||
unminify_js: bool,
|
||||
userscripts_path: Option<String>,
|
||||
headless: bool,
|
||||
replace_surrogates: bool,
|
||||
user_agent: Cow<'static, str>,
|
||||
) -> (Sender<Self::Message>, Receiver<Self::Message>);
|
||||
}
|
||||
|
||||
|
@ -878,6 +888,10 @@ pub struct WorkerGlobalScopeInit {
|
|||
pub pipeline_id: PipelineId,
|
||||
/// The origin
|
||||
pub origin: ImmutableOrigin,
|
||||
/// True if headless mode
|
||||
pub is_headless: bool,
|
||||
/// An optional string allowing the user agnet to be set for testing.
|
||||
pub user_agent: Cow<'static, str>,
|
||||
}
|
||||
|
||||
/// Common entities representing a network load origin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue