api: Flatten and simplify Servo preferences (#34966)

Flatten and simplify Servo's preferences code. In addition, have both
preferences and options passed in as arguments to `Servo::new()` and
make sure not to use the globally set preferences in `servoshell` (as
much as possible now).

Instead of a complex procedural macro to generate preferences, just
expose a very simple derive macro that adds string based getters and
setters.

- All command-line parsing is moved to servoshell.
- There is no longer the concept of a missing preference.
- Preferences no longer have to be part of the resources bundle because
  they now have reasonable default values.
- servoshell specific preferences are no longer part of the preferences
  exposed by the Servo API.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-01-14 14:54:06 +01:00 committed by GitHub
parent c4c85affb5
commit 0e616e0c5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
316 changed files with 2088 additions and 3235 deletions

26
Cargo.lock generated
View file

@ -949,7 +949,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
dependencies = [
"lazy_static",
"windows-sys 0.59.0",
"windows-sys 0.48.0",
]
[[package]]
@ -1854,7 +1854,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
dependencies = [
"libc",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -2375,7 +2375,7 @@ dependencies = [
"gobject-sys",
"libc",
"system-deps",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -4160,7 +4160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [
"cfg-if",
"windows-targets 0.52.6",
"windows-targets 0.48.5",
]
[[package]]
@ -6025,7 +6025,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -6619,29 +6619,24 @@ dependencies = [
name = "servo_config"
version = "0.0.1"
dependencies = [
"dirs",
"embedder_traits",
"euclid",
"getopts",
"log",
"num_cpus",
"serde",
"serde_json",
"servo_config_plugins",
"servo_config_macro",
"servo_geometry",
"servo_url",
"style_config",
"url",
]
[[package]]
name = "servo_config_plugins"
name = "servo_config_macro"
version = "0.0.1"
dependencies = [
"itertools 0.13.0",
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
@ -6721,6 +6716,7 @@ dependencies = [
"backtrace",
"cc",
"cfg-if",
"dirs",
"egui",
"egui-winit",
"egui_glow",
@ -7312,7 +7308,7 @@ dependencies = [
"getrandom",
"once_cell",
"rustix",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -8595,7 +8591,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.48.0",
]
[[package]]

View file

@ -76,7 +76,7 @@ pub trait BluetoothThreadFactory {
impl BluetoothThreadFactory for IpcSender<BluetoothRequest> {
fn new(embedder_proxy: EmbedderProxy) -> IpcSender<BluetoothRequest> {
let (sender, receiver) = ipc::channel().unwrap();
let adapter = if pref!(dom.bluetooth.enabled) {
let adapter = if pref!(dom_bluetooth_enabled) {
BluetoothAdapter::new()
} else {
BluetoothAdapter::new_mock()

View file

@ -2303,7 +2303,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
self.assert_gl_framebuffer_complete();
// Set the viewport background based on prefs.
let color = servo_config::pref!(shell.background_color.rgba);
let color = servo_config::pref!(shell_background_color_rgba);
gl.clear_color(
color[0] as f32,
color[1] as f32,

View file

@ -12,18 +12,11 @@ name = "servo_config"
path = "lib.rs"
[dependencies]
embedder_traits = { workspace = true }
euclid = { workspace = true }
getopts = { workspace = true }
log = { workspace = true }
num_cpus = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
servo_config_plugins = { path = "../config_plugins" }
servo_config_macro = { path = "macro" }
servo_geometry = { path = "../geometry" }
servo_url = { path = "../url" }
style_config = { workspace = true }
url = { workspace = true }
[target.'cfg(not(any(target_os = "android", target_env = "ohos")))'.dependencies]
dirs = "5.0"

View file

@ -1,44 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Contains routines for retrieving default config directories.
//! For linux based platforms, it uses the XDG base directory spec but provides
//! similar abstractions for non-linux platforms.
use std::path::PathBuf;
#[cfg(all(
unix,
not(target_os = "macos"),
not(target_os = "ios"),
not(target_os = "android"),
not(target_env = "ohos")
))]
pub fn default_config_dir() -> Option<PathBuf> {
let mut config_dir = ::dirs::config_dir().unwrap();
config_dir.push("servo");
config_dir.push("default");
Some(config_dir)
}
#[cfg(any(target_os = "android", target_env = "ohos"))]
pub fn default_config_dir() -> Option<PathBuf> {
None
}
#[cfg(target_os = "macos")]
pub fn default_config_dir() -> Option<PathBuf> {
// FIXME: use `config_dir()` ($HOME/Library/Preferences)
// instead of `data_dir()` ($HOME/Library/Application Support) ?
let mut config_dir = ::dirs::data_dir().unwrap();
config_dir.push("Servo");
Some(config_dir)
}
#[cfg(target_os = "windows")]
pub fn default_config_dir() -> Option<PathBuf> {
let mut config_dir = ::dirs::config_dir().unwrap();
config_dir.push("Servo");
Some(config_dir)
}

View file

@ -4,9 +4,6 @@
#![deny(unsafe_code)]
pub mod opts;
pub mod pref_util;
pub mod prefs;
pub mod basedir;
#[allow(unsafe_code)]
pub mod opts;

View file

@ -1,5 +1,5 @@
[package]
name = "servo_config_plugins"
name = "servo_config_macro"
version.workspace = true
authors.workspace = true
license.workspace = true
@ -8,12 +8,12 @@ publish.workspace = true
rust-version.workspace = true
[lib]
name = "servo_config_plugins"
name = "servo_config_macro"
proc-macro = true
path = "lib.rs"
[dependencies]
itertools = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { workspace = true }
synstructure = { workspace = true }

View file

@ -0,0 +1,55 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Data, Fields};
use synstructure::decl_derive;
decl_derive!([ServoPreferences] => servo_preferences_derive);
/// A derive macro that adds string-based getter and setter for each field of this struct
/// (enums and other types are not supported). Each field must be able to be convertable
/// (with `into()`) into a `PrefValue`.
fn servo_preferences_derive(input: synstructure::Structure) -> TokenStream {
let ast = input.ast();
let Data::Struct(ref data) = ast.data else {
unimplemented!();
};
let Fields::Named(ref named_fields) = data.fields else {
unimplemented!()
};
let mut get_match_cases = quote!();
for field in named_fields.named.iter() {
let name = field.ident.as_ref().unwrap();
get_match_cases.extend(quote!(stringify!(#name) => self.#name.clone().into(),))
}
let mut set_match_cases = quote!();
for field in named_fields.named.iter() {
let name = field.ident.as_ref().unwrap();
set_match_cases.extend(quote!(stringify!(#name) => self.#name = value.try_into().unwrap(),))
}
let structure_name = &ast.ident;
quote! {
impl #structure_name {
pub fn get_value(&self, name: &str) -> PrefValue {
match name {
#get_match_cases
_ => { panic!("Unknown preference: {:?}", name); }
}
}
pub fn set_value(&mut self, name: &str, value: PrefValue) {
match name {
#set_match_cases
_ => { panic!("Unknown preference: {:?}", name); }
}
}
}
}
}

View file

@ -6,22 +6,13 @@
//! from command line arguments.
use std::default::Default;
use std::fs::{self, File};
use std::io::Read;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::path::PathBuf;
use std::sync::{LazyLock, RwLock, RwLockReadGuard};
use std::{env, process};
use euclid::Size2D;
use getopts::{Matches, Options};
use log::error;
use serde::{Deserialize, Serialize};
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
use url::{self, Url};
use crate::{pref, set_pref};
/// Global flags for Servo, currently set on the command line.
#[derive(Clone, Debug, Deserialize, Serialize)]
@ -69,13 +60,6 @@ pub struct Opts {
/// behavior for debugging purposes.
pub debug: DebugOptions,
/// Port number to start a server to listen to remote Firefox devtools connections.
/// 0 for random port.
pub devtools_port: u16,
/// Start the devtools server at startup
pub devtools_server_enabled: bool,
/// `None` to disable WebDriver or `Some` with a port number to start a server to listen to
/// remote WebDriver commands.
pub webdriver_port: Option<u16>,
@ -113,9 +97,6 @@ pub struct Opts {
/// Directory for a default config directory
pub config_dir: Option<PathBuf>,
/// Print the version and exit.
pub is_printing_version: bool,
/// Path to PEM encoded SSL CA certificate store.
pub certificate_path: Option<String>,
@ -137,14 +118,6 @@ pub struct Opts {
pub print_pwm: bool,
}
fn print_usage(app: &str, opts: &Options) {
let message = format!(
"Usage: {} [ options ... ] [URL]\n\twhere options include",
app
);
println!("{}", opts.usage(&message));
}
/// Debug options for Servo, currently set on the command line with -Z
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct DebugOptions {
@ -278,104 +251,6 @@ impl DebugOptions {
Ok(())
}
fn print_usage(app: &str) {
fn print_option(name: &str, description: &str) {
println!("\t{:<35} {}", name, description);
}
println!(
"Usage: {} debug option,[options,...]\n\twhere options include\n\nOptions:",
app
);
print_option(
"bubble-inline-sizes-separately",
"Bubble intrinsic widths separately like other engines.",
);
print_option(
"convert-mouse-to-touch",
"Send touch events instead of mouse events",
);
print_option(
"disable-canvas-aa",
"Disable antialiasing on the HTML canvas element.",
);
print_option(
"disable-share-style-cache",
"Disable the style sharing cache.",
);
print_option(
"disable-subpixel-aa",
"Disable subpixel text antialiasing overriding preference.",
);
print_option("disable-text-aa", "Disable antialiasing of rendered text.");
print_option(
"dump-stacking-context-tree",
"Print the stacking context tree after each layout.",
);
print_option(
"dump-display-list",
"Print the display list after each layout.",
);
print_option(
"dump-display-list-json",
"Print the display list in JSON form.",
);
print_option(
"dump-flow-tree",
"Print the flow tree (Layout 2013) or fragment tree (Layout 2020) after each layout.",
);
print_option(
"dump-rule-tree",
"Print the style rule tree after each layout.",
);
print_option(
"dump-style-tree",
"Print the DOM with computed styles after each restyle.",
);
print_option("dump-style-stats", "Print style statistics each restyle.");
print_option("gc-profile", "Log GC passes and their durations.");
print_option(
"load-webfonts-synchronously",
"Load web fonts synchronously to avoid non-deterministic network-driven reflows",
);
print_option(
"parallel-display-list-building",
"Build display lists in parallel.",
);
print_option("precache-shaders", "Compile all shaders during init.");
print_option(
"profile-script-events",
"Enable profiling of script-related events.",
);
print_option(
"relayout-event",
"Print notifications when there is a relayout.",
);
print_option("replace-surrogates", "Replace unpaires surrogates in DOM strings with U+FFFD. See https://github.com/servo/servo/issues/6564");
print_option(
"show-fragment-borders",
"Paint borders along fragment boundaries.",
);
print_option(
"show-parallel-layout",
"Mark which thread laid each flow out with colors.",
);
print_option(
"signpost",
"Emit native OS signposts for profile events (currently macOS only)",
);
print_option(
"trace-layout",
"Write layout trace to an external file for debugging.",
);
print_option("wr-stats", "Show WebRender profiler on screen.");
println!();
process::exit(0)
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
@ -385,18 +260,6 @@ pub enum OutputOptions {
Stdout(f64),
}
fn args_fail(msg: &str) -> ! {
eprintln!("{}", msg);
process::exit(1)
}
static MULTIPROCESS: AtomicBool = AtomicBool::new(false);
#[inline]
pub fn multiprocess() -> bool {
MULTIPROCESS.load(Ordering::Relaxed)
}
pub fn default_opts() -> Opts {
Opts {
legacy_layout: false,
@ -410,8 +273,6 @@ pub fn default_opts() -> Opts {
output_file: None,
headless: false,
hard_fail: true,
devtools_port: 0,
devtools_server_enabled: false,
webdriver_port: None,
initial_window_size: Size2D::new(1024, 740),
screen_size_override: None,
@ -423,7 +284,6 @@ pub fn default_opts() -> Opts {
debug: Default::default(),
exit_after_load: false,
config_dir: None,
is_printing_version: false,
shaders_dir: None,
certificate_path: None,
ignore_certificate_errors: false,
@ -434,392 +294,12 @@ pub fn default_opts() -> Opts {
}
}
pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingResult {
let (app_name, args) = args.split_first().unwrap();
opts.optflag("", "legacy-layout", "Use the legacy layout engine");
opts.optopt("o", "output", "Output file", "output.png");
opts.optopt("s", "size", "Size of tiles", "512");
opts.optflagopt(
"p",
"profile",
"Time profiler flag and either a TSV output filename \
OR an interval for output to Stdout (blank for Stdout with interval of 5s)",
"10 \
OR time.tsv",
);
opts.optflagopt(
"",
"profiler-trace-path",
"Path to dump a self-contained HTML timeline of profiler traces",
"",
);
opts.optflagopt(
"m",
"memory-profile",
"Memory profiler flag and output interval",
"10",
);
opts.optflag("x", "exit", "Exit after load flag");
opts.optopt(
"y",
"layout-threads",
"Number of threads to use for layout",
"1",
);
opts.optflag(
"i",
"nonincremental-layout",
"Enable to turn off incremental layout.",
);
opts.optflagopt(
"",
"userscripts",
"Uses userscripts in resources/user-agent-js, or a specified full path",
"",
);
opts.optmulti(
"",
"user-stylesheet",
"A user stylesheet to be added to every document",
"file.css",
);
opts.optopt(
"",
"shaders",
"Shaders will be loaded from the specified directory instead of using the builtin ones.",
"",
);
opts.optflag("z", "headless", "Headless mode");
opts.optflag(
"f",
"hard-fail",
"Exit on thread failure instead of displaying about:failure",
);
opts.optflag(
"F",
"soft-fail",
"Display about:failure on thread failure instead of exiting",
);
opts.optflagopt("", "devtools", "Start remote devtools server on port", "0");
opts.optflagopt(
"",
"webdriver",
"Start remote WebDriver server on port",
"7000",
);
opts.optopt(
"",
"window-size",
"Set the initial window size in logical (device independenrt) pixels",
"1024x740",
);
opts.optopt(
"",
"screen-size",
"Override the screen resolution in logical (device independent) pixels",
"1024x768",
);
opts.optflag("M", "multiprocess", "Run in multiprocess mode");
opts.optflag("B", "bhm", "Background Hang Monitor enabled");
opts.optflag("S", "sandbox", "Run in a sandbox if multiprocess");
opts.optopt(
"",
"random-pipeline-closure-probability",
"Probability of randomly closing a pipeline (for testing constellation hardening).",
"0.0",
);
opts.optopt(
"",
"random-pipeline-closure-seed",
"A fixed seed for repeatbility of random pipeline closure.",
"",
);
opts.optmulti(
"Z",
"debug",
"A comma-separated string of debug options. Pass help to show available options.",
"",
);
opts.optflag("h", "help", "Print this message");
opts.optopt(
"",
"resources-path",
"Path to find static resources",
"/home/servo/resources",
);
opts.optopt(
"",
"certificate-path",
"Path to find SSL certificates",
"/home/servo/resources/certs",
);
opts.optflag(
"",
"ignore-certificate-errors",
"Whether or not to completely ignore certificate errors",
);
opts.optopt(
"",
"content-process",
"Run as a content process and connect to the given pipe",
"servo-ipc-channel.abcdefg",
);
opts.optopt(
"",
"config-dir",
"config directory following xdg spec on linux platform",
"",
);
opts.optflag("v", "version", "Display servo version information");
opts.optflag("", "unminify-js", "Unminify Javascript");
opts.optflag("", "print-pwm", "Print Progressive Web Metrics");
opts.optopt(
"",
"local-script-source",
"Directory root with unminified scripts",
"",
);
opts.optflag("", "unminify-css", "Unminify Css");
let opt_match = match opts.parse(args) {
Ok(m) => m,
Err(f) => args_fail(&f.to_string()),
};
if opt_match.opt_present("h") || opt_match.opt_present("help") {
print_usage(app_name, &opts);
process::exit(0);
};
// If this is the content process, we'll receive the real options over IPC. So just fill in
// some dummy options for now.
if let Some(content_process) = opt_match.opt_str("content-process") {
MULTIPROCESS.store(true, Ordering::SeqCst);
return ArgumentParsingResult::ContentProcess(opt_match, content_process);
}
let mut debug_options = DebugOptions::default();
for debug_string in opt_match.opt_strs("Z") {
if let Err(e) = debug_options.extend(debug_string) {
args_fail(&format!("error: unrecognized debug option: {}", e));
}
}
if debug_options.help {
DebugOptions::print_usage(app_name)
}
let tile_size: usize = match opt_match.opt_str("s") {
Some(tile_size_str) => tile_size_str
.parse()
.unwrap_or_else(|err| args_fail(&format!("Error parsing option: -s ({})", err))),
None => 512,
};
// If only the flag is present, default to a 5 second period for both profilers
let time_profiling = if opt_match.opt_present("p") {
match opt_match.opt_str("p") {
Some(argument) => match argument.parse::<f64>() {
Ok(interval) => Some(OutputOptions::Stdout(interval)),
Err(_) => match ServoUrl::parse(&argument) {
Ok(_) => panic!("influxDB isn't supported anymore"),
Err(_) => Some(OutputOptions::FileName(argument)),
},
},
None => Some(OutputOptions::Stdout(5.0)),
}
} else {
// if the p option doesn't exist:
None
};
if let Some(ref time_profiler_trace_path) = opt_match.opt_str("profiler-trace-path") {
let mut path = PathBuf::from(time_profiler_trace_path);
path.pop();
if let Err(why) = fs::create_dir_all(&path) {
error!(
"Couldn't create/open {:?}: {:?}",
Path::new(time_profiler_trace_path).to_string_lossy(),
why
);
}
}
let mem_profiler_period = opt_match.opt_default("m", "5").map(|period| {
period
.parse()
.unwrap_or_else(|err| args_fail(&format!("Error parsing option: -m ({})", err)))
});
let mut layout_threads: Option<usize> = opt_match.opt_str("y").map(|layout_threads_str| {
layout_threads_str
.parse()
.unwrap_or_else(|err| args_fail(&format!("Error parsing option: -y ({})", err)))
});
let nonincremental_layout = opt_match.opt_present("i");
let random_pipeline_closure_probability = opt_match
.opt_str("random-pipeline-closure-probability")
.map(|prob| {
prob.parse().unwrap_or_else(|err| {
args_fail(&format!(
"Error parsing option: --random-pipeline-closure-probability ({})",
err
))
})
});
let random_pipeline_closure_seed =
opt_match
.opt_str("random-pipeline-closure-seed")
.map(|seed| {
seed.parse().unwrap_or_else(|err| {
args_fail(&format!(
"Error parsing option: --random-pipeline-closure-seed ({})",
err
))
})
});
if debug_options.trace_layout {
layout_threads = Some(1);
}
let (devtools_server_enabled, devtools_port) = if opt_match.opt_present("devtools") {
let port = opt_match
.opt_str("devtools")
.map(|port| {
port.parse().unwrap_or_else(|err| {
args_fail(&format!("Error parsing option: --devtools ({})", err))
})
})
.unwrap_or(pref!(devtools.server.port));
(true, port as u16)
} else {
(
pref!(devtools.server.enabled),
pref!(devtools.server.port) as u16,
)
};
let webdriver_port = opt_match.opt_default("webdriver", "7000").map(|port| {
port.parse().unwrap_or_else(|err| {
args_fail(&format!("Error parsing option: --webdriver ({})", err))
})
});
let parse_resolution_string = |string: String| {
let components: Vec<u32> = string
.split('x')
.map(|component| {
component.parse().unwrap_or_else(|error| {
args_fail(&format!("Error parsing resolution '{string}': {error}"));
})
})
.collect();
Size2D::new(components[0], components[1])
};
let screen_size_override = opt_match
.opt_str("screen-size")
.map(parse_resolution_string);
// Make sure the default window size is not larger than any provided screen size.
let default_window_size = Size2D::new(1024, 740);
let default_window_size = screen_size_override
.map_or(default_window_size, |screen_size_override| {
default_window_size.min(screen_size_override)
});
let initial_window_size = opt_match
.opt_str("window-size")
.map_or(default_window_size, parse_resolution_string);
if opt_match.opt_present("M") {
MULTIPROCESS.store(true, Ordering::SeqCst)
}
let user_stylesheets = opt_match
.opt_strs("user-stylesheet")
.iter()
.map(|filename| {
let cwd = env::current_dir().unwrap();
let path = cwd.join(filename);
let url = ServoUrl::from_url(Url::from_file_path(&path).unwrap());
let mut contents = Vec::new();
File::open(path)
.unwrap_or_else(|err| args_fail(&format!("Couldn't open {}: {}", filename, err)))
.read_to_end(&mut contents)
.unwrap_or_else(|err| args_fail(&format!("Couldn't read {}: {}", filename, err)));
(contents, url)
})
.collect();
let is_printing_version = opt_match.opt_present("v") || opt_match.opt_present("version");
let legacy_layout = opt_match.opt_present("legacy-layout");
if legacy_layout {
set_pref!(layout.legacy_layout, true);
}
let opts = Opts {
debug: debug_options.clone(),
legacy_layout,
tile_size,
time_profiling,
time_profiler_trace_path: opt_match.opt_str("profiler-trace-path"),
mem_profiler_period,
nonincremental_layout,
userscripts: opt_match.opt_default("userscripts", ""),
user_stylesheets,
output_file: opt_match.opt_str("o"),
headless: opt_match.opt_present("z"),
hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"),
devtools_port,
devtools_server_enabled,
webdriver_port,
initial_window_size,
screen_size_override,
multiprocess: opt_match.opt_present("M"),
background_hang_monitor: opt_match.opt_present("B"),
sandbox: opt_match.opt_present("S"),
random_pipeline_closure_probability,
random_pipeline_closure_seed,
exit_after_load: opt_match.opt_present("x"),
config_dir: opt_match.opt_str("config-dir").map(Into::into),
is_printing_version,
shaders_dir: opt_match.opt_str("shaders").map(Into::into),
certificate_path: opt_match.opt_str("certificate-path"),
ignore_certificate_errors: opt_match.opt_present("ignore-certificate-errors"),
unminify_js: opt_match.opt_present("unminify-js"),
local_script_source: opt_match.opt_str("local-script-source"),
unminify_css: opt_match.opt_present("unminify-css"),
print_pwm: opt_match.opt_present("print-pwm"),
};
set_options(opts);
if let Some(layout_threads) = layout_threads {
set_pref!(layout.threads, layout_threads as i64);
}
ArgumentParsingResult::ChromeProcess(opt_match)
}
pub enum ArgumentParsingResult {
ChromeProcess(Matches),
ContentProcess(Matches, String),
}
// Make Opts available globally. This saves having to clone and pass
// opts everywhere it is used, which gets particularly cumbersome
// when passing through the DOM structures.
static OPTIONS: LazyLock<RwLock<Opts>> = LazyLock::new(|| RwLock::new(default_opts()));
pub fn set_options(opts: Opts) {
MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst);
*OPTIONS.write().unwrap() = opts;
}

View file

@ -2,11 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use std::fmt;
use std::str::FromStr;
use std::sync::RwLock;
use serde::{Deserialize, Serialize};
use serde_json::Value;
@ -17,70 +12,46 @@ pub enum PrefValue {
Str(String),
Bool(bool),
Array(Vec<PrefValue>),
Missing,
}
impl PrefValue {
pub fn as_str(&self) -> Option<&str> {
if let PrefValue::Str(val) = self {
Some(val)
} else {
None
}
}
pub fn as_i64(&self) -> Option<i64> {
if let PrefValue::Int(val) = self {
Some(*val)
} else {
None
}
}
pub fn as_f64(&self) -> Option<f64> {
if let PrefValue::Float(val) = self {
Some(*val)
} else {
None
}
}
pub fn as_bool(&self) -> Option<bool> {
if let PrefValue::Bool(val) = self {
Some(*val)
} else {
None
}
}
pub fn is_missing(&self) -> bool {
matches!(self, PrefValue::Missing)
}
pub fn from_json_value(value: &Value) -> Option<Self> {
match value {
Value::Bool(b) => Some(PrefValue::Bool(*b)),
Value::Number(n) if n.is_i64() => Some(PrefValue::Int(n.as_i64().unwrap())),
Value::Number(n) if n.is_f64() => Some(PrefValue::Float(n.as_f64().unwrap())),
Value::String(s) => Some(PrefValue::Str(s.to_owned())),
_ => None,
pub fn from_booleanish_str(input: &str) -> Self {
match input {
"false" => PrefValue::Bool(false),
"true" => PrefValue::Bool(true),
_ => input
.parse::<i64>()
.map(PrefValue::Int)
.or_else(|_| input.parse::<f64>().map(PrefValue::Float))
.unwrap_or_else(|_| PrefValue::from(input)),
}
}
}
impl FromStr for PrefValue {
type Err = PrefError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s == "false" {
Ok(PrefValue::Bool(false))
} else if s == "true" {
Ok(PrefValue::Bool(true))
} else if let Ok(float) = s.parse::<f64>() {
Ok(PrefValue::Float(float))
} else if let Ok(integer) = s.parse::<i64>() {
Ok(PrefValue::Int(integer))
} else {
Ok(PrefValue::from(s))
impl TryFrom<&Value> for PrefValue {
type Error = String;
fn try_from(value: &Value) -> Result<Self, Self::Error> {
match value {
Value::Null => Err("Cannot turn null into preference".into()),
Value::Bool(value) => Ok((*value).into()),
Value::Number(number) => number
.as_i64()
.map(Into::into)
.or_else(|| number.as_f64().map(Into::into))
.map(Ok)
.unwrap_or(Err("Could not parse number from JSON".into())),
Value::String(value) => Ok(value.clone().into()),
Value::Array(array) => {
let mut array = array.iter().map(TryInto::try_into);
if !array.all(|v| v.is_ok()) {
return Err(format!(
"Cannot turn all array avlues into preference: {array:?}"
));
}
Ok(PrefValue::Array(array.map(Result::unwrap).collect()))
},
Value::Object(_) => Err("Cannot turn object into preference".into()),
}
}
}
@ -94,37 +65,18 @@ macro_rules! impl_pref_from {
}
}
)+
$(
impl From<Option<$t>> for PrefValue {
fn from(other: Option<$t>) -> Self {
other.map(|val| $variant(val.into())).unwrap_or(PrefValue::Missing)
}
}
)+
}
}
macro_rules! impl_from_pref {
($($variant: path => $t: ty,)*) => {
$(
impl From<PrefValue> for $t {
#[allow(unsafe_code)]
fn from(other: PrefValue) -> Self {
if let $variant(value) = other {
value.into()
} else {
panic!("Cannot convert {:?} to {:?}", other, std::any::type_name::<$t>())
}
}
}
)+
$(
impl From<PrefValue> for Option<$t> {
fn from(other: PrefValue) -> Self {
if let PrefValue::Missing = other {
None
} else {
Some(other.into())
impl TryFrom<PrefValue> for $t {
type Error = String;
fn try_from(other: PrefValue) -> Result<Self, Self::Error> {
match other {
$variant(value) => Ok(value.into()),
_ => Err(format!("Cannot convert {other:?} to {}", std::any::type_name::<$t>())),
}
}
}
@ -157,9 +109,13 @@ impl From<PrefValue> for [f64; 4] {
fn from(other: PrefValue) -> [f64; 4] {
match other {
PrefValue::Array(values) if values.len() == 4 => {
let f = values.into_iter().map(Into::into).collect::<Vec<f64>>();
if f.len() == 4 {
[f[0], f[1], f[2], f[3]]
let values: Vec<f64> = values
.into_iter()
.map(TryFrom::try_from)
.filter_map(Result::ok)
.collect();
if values.len() == 4 {
[values[0], values[1], values[2], values[3]]
} else {
panic!(
"Cannot convert PrefValue to {:?}",
@ -176,144 +132,20 @@ impl From<PrefValue> for [f64; 4] {
}
}
#[derive(Debug)]
pub enum PrefError {
NoSuchPref(String),
InvalidValue(String),
JsonParseErr(serde_json::error::Error),
}
impl fmt::Display for PrefError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
PrefError::NoSuchPref(s) | PrefError::InvalidValue(s) => f.write_str(s),
PrefError::JsonParseErr(e) => e.fmt(f),
}
}
}
impl std::error::Error for PrefError {}
pub struct Accessor<P, V> {
pub getter: Box<dyn Fn(&P) -> V + Sync + Send>,
#[allow(clippy::type_complexity)]
pub setter: Box<dyn Fn(&mut P, V) + Sync + Send>,
}
impl<P, V> Accessor<P, V> {
pub fn new<G, S>(getter: G, setter: S) -> Self
where
G: Fn(&P) -> V + Sync + Send + 'static,
S: Fn(&mut P, V) + Sync + Send + 'static,
{
Accessor {
getter: Box::new(getter),
setter: Box::new(setter),
}
}
}
pub struct Preferences<'m, P> {
user_prefs: RwLock<P>,
default_prefs: P,
accessors: &'m HashMap<String, Accessor<P, PrefValue>>,
}
impl<'m, P: Clone> Preferences<'m, P> {
/// Create a new `Preferences` object. The values provided in `default_prefs` are immutable and
/// can always be restored using `reset` or `reset_all`.
pub fn new(default_prefs: P, accessors: &'m HashMap<String, Accessor<P, PrefValue>>) -> Self {
Self {
user_prefs: RwLock::new(default_prefs.clone()),
default_prefs,
accessors,
}
}
/// Access to the data structure holding the preference values.
pub fn values(&self) -> &RwLock<P> {
&self.user_prefs
}
/// Retrieve a preference using its key
pub fn get(&self, key: &str) -> PrefValue {
if let Some(accessor) = self.accessors.get(key) {
let prefs = self.user_prefs.read().unwrap();
(accessor.getter)(&prefs)
} else {
PrefValue::Missing
}
}
/// Has the preference been modified from its original value?
pub fn is_default(&self, key: &str) -> Result<bool, PrefError> {
if let Some(accessor) = self.accessors.get(key) {
let user = (accessor.getter)(&self.default_prefs);
let default = (accessor.getter)(&self.user_prefs.read().unwrap());
Ok(default == user)
} else {
Err(PrefError::NoSuchPref(String::from(key)))
}
}
/// Creates an iterator over all keys and values
pub fn iter(&self) -> impl Iterator<Item = (String, PrefValue)> + '_ {
let prefs = self.user_prefs.read().unwrap();
self.accessors
.iter()
.map(move |(k, accessor)| (k.clone(), (accessor.getter)(&prefs)))
}
/// Creates an iterator over all keys
pub fn keys(&self) -> impl Iterator<Item = &'_ str> {
self.accessors.keys().map(String::as_str)
}
fn set_inner<V>(&self, key: &str, prefs: &mut P, val: V) -> Result<(), PrefError>
where
V: Into<PrefValue>,
{
if let Some(accessor) = self.accessors.get(key) {
(accessor.setter)(prefs, val.into());
Ok(())
} else {
Err(PrefError::NoSuchPref(String::from(key)))
}
}
/// Set a new value for a preference, using its key.
pub fn set<V>(&self, key: &str, val: V) -> Result<(), PrefError>
where
V: Into<PrefValue>,
{
let mut prefs = self.user_prefs.write().unwrap();
self.set_inner(key, &mut prefs, val)
}
pub fn set_all<M>(&self, values: M) -> Result<(), PrefError>
where
M: IntoIterator<Item = (String, PrefValue)>,
{
let mut prefs = self.user_prefs.write().unwrap();
for (k, v) in values.into_iter() {
self.set_inner(&k, &mut prefs, v)?;
}
Ok(())
}
pub fn reset(&self, key: &str) -> Result<PrefValue, PrefError> {
if let Some(accessor) = self.accessors.get(key) {
let mut prefs = self.user_prefs.write().unwrap();
let old_pref = (accessor.getter)(&prefs);
let default_pref = (accessor.getter)(&self.default_prefs);
(accessor.setter)(&mut prefs, default_pref);
Ok(old_pref)
} else {
Err(PrefError::NoSuchPref(String::from(key)))
}
}
pub fn reset_all(&self) {
*self.user_prefs.write().unwrap() = self.default_prefs.clone();
}
#[test]
fn test_pref_value_from_str() {
let value = PrefValue::from_booleanish_str("21");
assert_eq!(value, PrefValue::Int(21));
let value = PrefValue::from_booleanish_str("12.5");
assert_eq!(value, PrefValue::Float(12.5));
let value = PrefValue::from_booleanish_str("a string");
assert_eq!(value, PrefValue::Str("a string".into()));
let value = PrefValue::from_booleanish_str("false");
assert_eq!(value, PrefValue::Bool(false));
let value = PrefValue::from_booleanish_str("true");
assert_eq!(value, PrefValue::Bool(true));
}

File diff suppressed because it is too large Load diff

View file

@ -1,333 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use std::error::Error;
use std::fs::{self, File};
use std::io::{Read, Write};
use servo_config::basedir;
use servo_config::pref_util::Preferences;
use servo_config::prefs::{read_prefs_map, PrefValue};
#[test]
fn test_create_prefs_map() {
let json_str = "{
\"layout.writing-mode.enabled\": true,
\"network.mime.sniff\": false,
\"shell.homepage\": \"https://servo.org\"
}";
let prefs = read_prefs_map(json_str);
assert!(prefs.is_ok());
let prefs = prefs.unwrap();
assert_eq!(prefs.len(), 3);
}
#[test]
fn test_generated_accessors_get() {
let prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR).unwrap();
let map: HashMap<String, PrefValue> = gen::TEST_PREF_ACCESSORS
.iter()
.map(move |(key, accessor)| {
let pref_value = (accessor.getter)(&prefs);
(key.clone(), pref_value)
})
.collect();
assert_eq!(&PrefValue::from("hello"), map.get("pref_string").unwrap());
assert_eq!(&PrefValue::from(23_i64), map.get("pref_i64").unwrap());
assert_eq!(&PrefValue::from(1.5_f64), map.get("pref_f64").unwrap());
assert_eq!(&PrefValue::from(true), map.get("pref_bool").unwrap());
assert_eq!(
&PrefValue::from(333_i64),
map.get("group.nested.nested_i64").unwrap()
);
assert_eq!(&PrefValue::from(42_i64), map.get("a.renamed.pref").unwrap());
}
#[test]
fn test_generated_accessors_set() {
let mut prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR).unwrap();
let setters: HashMap<String, _> = gen::TEST_PREF_ACCESSORS
.iter()
.map(|(key, accessor)| (key.clone(), &accessor.setter))
.collect();
(setters.get("pref_string").unwrap())(&mut prefs, PrefValue::Str(String::from("boo")));
(setters.get("pref_i64").unwrap())(&mut prefs, PrefValue::Int(-25));
(setters.get("pref_f64").unwrap())(&mut prefs, PrefValue::Float(-1.9));
(setters.get("pref_bool").unwrap())(&mut prefs, PrefValue::Bool(false));
(setters.get("group.nested.nested_i64").unwrap())(&mut prefs, PrefValue::Int(10));
(setters.get("a.renamed.pref").unwrap())(&mut prefs, PrefValue::Int(11));
assert_eq!("boo", prefs.pref_string);
assert_eq!(-25, prefs.pref_i64);
assert_eq!(-1.9, prefs.pref_f64);
assert_eq!(false, prefs.pref_bool);
assert_eq!(10, prefs.group.nested.nested_i64);
assert_eq!(11, prefs.group.nested.renamed);
}
#[test]
fn test_static_struct() {
let prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR).unwrap();
assert_eq!("hello", prefs.pref_string);
assert_eq!(23, prefs.pref_i64);
assert_eq!(1.5, prefs.pref_f64);
assert_eq!(true, prefs.pref_bool);
assert_eq!(333, prefs.group.nested.nested_i64);
assert_eq!(42, prefs.group.nested.renamed);
}
#[test]
fn test_set_pref() {
let prefs = Preferences::new(gen::TestPrefs::default(), &gen::TEST_PREF_ACCESSORS);
assert_eq!(Some(0), prefs.get("group.nested.nested_i64").as_i64());
let result = prefs.set("group.nested.nested_i64", 1);
assert_eq!(true, result.is_ok());
assert_eq!(Some(1), prefs.get("group.nested.nested_i64").as_i64());
assert_eq!(1, prefs.values().read().unwrap().group.nested.nested_i64);
}
#[test]
fn test_set_unknown_pref_is_err() -> Result<(), Box<dyn Error>> {
let prefs = Preferences::new(gen::TestPrefs::default(), &gen::TEST_PREF_ACCESSORS);
let result = prefs.set("unknown_pref", 1);
assert_eq!(true, result.is_err());
Ok(())
}
#[test]
fn test_reset_pref() -> Result<(), Box<dyn Error>> {
let mut def_prefs = gen::TestPrefs::default();
def_prefs.group.nested.nested_i64 = 999;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
assert_eq!(Some(999), prefs.get("group.nested.nested_i64").as_i64());
prefs.set("group.nested.nested_i64", 1)?;
assert_eq!(Some(1), prefs.get("group.nested.nested_i64").as_i64());
prefs.reset("group.nested.nested_i64")?;
assert_eq!(Some(999), prefs.get("group.nested.nested_i64").as_i64());
assert_eq!(999, prefs.values().read().unwrap().group.nested.nested_i64);
Ok(())
}
#[test]
fn test_default_values() -> Result<(), Box<dyn Error>> {
let def_prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR)?;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
assert_eq!(Some(0), prefs.get("default_value").as_i64());
assert_eq!(Some(555), prefs.get("computed_default_value").as_i64());
Ok(())
}
#[test]
fn test_override_default_values() -> Result<(), Box<dyn Error>> {
let def_prefs: gen::TestPrefs = serde_json::from_str(WITHOUT_DEFAULTS_JSON_STR)?;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
assert_eq!(Some(-1), prefs.get("default_value").as_i64());
assert_eq!(Some(-1), prefs.get("computed_default_value").as_i64());
Ok(())
}
#[test]
fn test_update_reset_default_values() -> Result<(), Box<dyn Error>> {
let def_prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR)?;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
prefs.set("default_value", 99)?;
prefs.set("computed_default_value", 199)?;
assert_eq!(Some(99), prefs.get("default_value").as_i64());
assert_eq!(Some(199), prefs.get("computed_default_value").as_i64());
prefs.reset("default_value")?;
prefs.reset("computed_default_value")?;
assert_eq!(Some(0), prefs.get("default_value").as_i64());
assert_eq!(Some(555), prefs.get("computed_default_value").as_i64());
Ok(())
}
#[test]
fn test_update_reset_overridden_default_values() -> Result<(), Box<dyn Error>> {
let def_prefs: gen::TestPrefs = serde_json::from_str(WITHOUT_DEFAULTS_JSON_STR)?;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
prefs.set("default_value", 99)?;
prefs.set("computed_default_value", 199)?;
assert_eq!(Some(99), prefs.get("default_value").as_i64());
assert_eq!(Some(199), prefs.get("computed_default_value").as_i64());
prefs.reset("default_value")?;
prefs.reset("computed_default_value")?;
assert_eq!(Some(-1), prefs.get("default_value").as_i64());
assert_eq!(Some(-1), prefs.get("computed_default_value").as_i64());
Ok(())
}
#[test]
fn test_user_prefs_override_and_reset() -> Result<(), Box<dyn Error>> {
let mut def_prefs = gen::TestPrefs::default();
def_prefs.group.nested.nested_i64 = 999;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
prefs.set("group.nested.nested_i64", 45)?;
assert_eq!(Some(45), prefs.get("group.nested.nested_i64").as_i64());
prefs.reset("group.nested.nested_i64")?;
assert_eq!(Some(999), prefs.get("group.nested.nested_i64").as_i64());
Ok(())
}
#[test]
fn test_reset_all() -> Result<(), Box<dyn Error>> {
let def_prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR)?;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
prefs.set_all(read_prefs_map(USER_JSON_STR)?)?;
let values = prefs.values();
assert_eq!("bye", values.read().unwrap().pref_string);
assert_eq!(-1, values.read().unwrap().pref_i64);
assert_eq!(-1.0, values.read().unwrap().pref_f64);
assert_eq!(false, values.read().unwrap().pref_bool);
assert_eq!(-1, values.read().unwrap().group.nested.nested_i64);
assert_eq!(-1, values.read().unwrap().group.nested.renamed);
prefs.reset_all();
let values = prefs.values();
assert_eq!("hello", values.read().unwrap().pref_string);
assert_eq!(23, values.read().unwrap().pref_i64);
assert_eq!(1.5, values.read().unwrap().pref_f64);
assert_eq!(true, values.read().unwrap().pref_bool);
assert_eq!(333, values.read().unwrap().group.nested.nested_i64);
assert_eq!(42, values.read().unwrap().group.nested.renamed);
Ok(())
}
#[test]
fn test_set_all_from_map() -> Result<(), Box<dyn Error>> {
let def_prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR)?;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
prefs.set_all(read_prefs_map(USER_JSON_STR)?)?;
let mut overrides = HashMap::new();
overrides.insert(String::from("pref_string"), PrefValue::from("new value"));
overrides.insert(
String::from("group.nested.nested_i64"),
PrefValue::from(1001),
);
overrides.insert(String::from("a.renamed.pref"), PrefValue::from(47));
let result = prefs.set_all(overrides.into_iter());
assert_eq!(true, result.is_ok());
let values = prefs.values();
assert_eq!("new value", values.read().unwrap().pref_string);
assert_eq!(1001, values.read().unwrap().group.nested.nested_i64);
assert_eq!(47, values.read().unwrap().group.nested.renamed);
Ok(())
}
#[test]
fn test_set_all_error_on_unknown_field() -> Result<(), Box<dyn Error>> {
let def_prefs: gen::TestPrefs = serde_json::from_str(DEF_JSON_STR)?;
let prefs = Preferences::new(def_prefs, &gen::TEST_PREF_ACCESSORS);
let mut overrides = HashMap::new();
overrides.insert(String::from("doesnt_exist"), PrefValue::from(1001));
let result = prefs.set_all(overrides.into_iter());
assert_eq!(true, result.is_err());
Ok(())
}
#[cfg(not(target_os = "android"))]
#[test]
fn test_default_config_dir_create_read_write() {
let json_str = "{\
\"layout.writing-mode.enabled\": true,\
\"extra.stuff\": false,\
\"shell.homepage\": \"https://google.com\"\
}";
let mut expected_json = String::new();
let config_path = basedir::default_config_dir().unwrap();
if !config_path.exists() {
fs::create_dir_all(&config_path).unwrap();
}
let json_path = config_path.join("test_config.json");
let mut fd = File::create(&json_path).unwrap();
assert_eq!(json_path.exists(), true);
fd.write_all(json_str.as_bytes()).unwrap();
let mut fd = File::open(&json_path).unwrap();
fd.read_to_string(&mut expected_json).unwrap();
assert_eq!(json_str, expected_json);
fs::remove_file(&json_path).unwrap();
}
static DEF_JSON_STR: &'static str = r#"{
"pref_string": "hello",
"pref_i64": 23,
"pref_f64": 1.5,
"pref_bool": true,
"group.nested.nested_i64": 333,
"a.renamed.pref": 42
}"#;
static USER_JSON_STR: &'static str = r#"{
"pref_string": "bye",
"pref_i64": -1,
"pref_f64": -1.0,
"pref_bool": false,
"group.nested.nested_i64": -1,
"a.renamed.pref": -1
}"#;
static WITHOUT_DEFAULTS_JSON_STR: &'static str = r#"{
"pref_string": "bye",
"pref_i64": -1,
"pref_f64": -1.0,
"pref_bool": false,
"group.nested.nested_i64": -1,
"a.renamed.pref": -1,
"computed_default_value": -1,
"default_value": -1
}"#;
mod gen {
use serde::{Deserialize, Serialize};
use servo_config::pref_util::{Accessor, PrefValue};
use servo_config_plugins::build_structs;
fn compute_default() -> i64 {
555
}
build_structs! {
accessor_type = Accessor::<TestPrefs, PrefValue>,
gen_accessors = TEST_PREF_ACCESSORS,
gen_types = TestPrefs {
pref_string: String,
pref_i64: i64,
pref_f64: f64,
pref_bool: bool,
#[serde(default)]
default_value: i64,
#[serde(default = "compute_default")]
computed_default_value: i64,
group: {
nested: {
nested_i64: i64,
#[serde(rename = "a.renamed.pref")]
renamed: i64,
}
}
}
}
}

View file

@ -1,206 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::{hash_map, HashMap};
use std::fmt::Write;
use std::iter;
use itertools::Itertools;
use proc_macro2::{Span, TokenStream};
use quote::*;
use syn::parse::Result;
use syn::spanned::Spanned;
use syn::{parse_macro_input, Attribute, Ident, LitStr, Path};
mod parse;
use parse::*;
#[proc_macro]
pub fn build_structs(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input: MacroInput = parse_macro_input!(tokens);
let out = Build::new(&input)
.build(&input.type_def)
.unwrap_or_else(|e| syn::Error::new(e.span(), e).to_compile_error());
out.into()
}
struct Build {
root_type_name: Ident,
gen_accessors: Ident,
accessor_type: Path,
output: TokenStream,
path_stack: Vec<Ident>,
path_map: HashMap<String, Vec<Ident>>,
}
impl Build {
fn new(input: &MacroInput) -> Self {
Build {
root_type_name: input.type_def.type_name.clone(),
gen_accessors: input.gen_accessors.clone(),
accessor_type: input.accessor_type.clone(),
output: TokenStream::new(),
path_stack: Vec::new(),
path_map: HashMap::new(),
}
}
fn build(mut self, type_def: &RootTypeDef) -> Result<TokenStream> {
self.walk(&type_def.type_def)?;
self.build_accessors();
Ok(self.output)
}
fn walk(&mut self, type_def: &NewTypeDef) -> Result<()> {
self.define_pref_struct(type_def)?;
for field in type_def.fields.iter() {
self.path_stack.push(field.name.clone());
if let FieldType::NewTypeDef(new_def) = &field.field_type {
self.walk(new_def)?;
} else {
let pref_name =
self.pref_name(field, &self.path_stack[..self.path_stack.len() - 1]);
if let hash_map::Entry::Vacant(slot) = self.path_map.entry(pref_name) {
slot.insert(self.path_stack.clone());
} else {
return Err(err(&field.name, "duplicate preference name"));
}
}
self.path_stack.pop();
}
Ok(())
}
fn define_pref_struct(&mut self, type_def: &NewTypeDef) -> Result<()> {
let struct_name = self.path_to_name(self.path_stack.iter());
let field_defs = type_def
.fields
.iter()
.map(|field| self.field_to_tokens(field, &self.path_stack))
.collect::<Result<Vec<_>>>()?;
self.output.extend(quote! {
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[allow(non_camel_case_types)]
pub struct #struct_name {
#(#field_defs), *
}
});
Ok(())
}
fn build_accessors(&mut self) {
let accessor_type = &self.accessor_type;
let values = self.path_map.iter().map(|(key, path)| {
quote! {
map.insert(String::from(#key),
#accessor_type::new(
|prefs| prefs #(.#path)*.clone().into(),
|prefs, value| prefs #(.#path)* = value.into()
)
);
}
});
let gen_accessors = &self.gen_accessors;
let num_prefs = self.path_map.len();
self.output.extend(quote! {
pub static #gen_accessors: std::sync::LazyLock<std::collections::HashMap<String, #accessor_type>> =
std::sync::LazyLock::new(|| {
let mut map = std::collections::HashMap::with_capacity(#num_prefs);
#(#values)*
map
});
});
}
fn pref_name(&self, field: &Field, path_stack: &[Ident]) -> String {
field
.get_field_name_mapping()
.map(|pref_attr| pref_attr.value())
.unwrap_or_else(|| {
Itertools::intersperse(
path_stack
.iter()
.chain(iter::once(&field.name))
.map(Ident::to_string),
String::from("."),
)
.collect()
})
}
fn field_to_tokens(&self, field: &Field, path_stack: &[Ident]) -> Result<TokenStream> {
let name = &field.name;
Ok(match &field.field_type {
FieldType::NewTypeDef(_) => {
let type_name = self.path_to_name(path_stack.iter().chain(iter::once(name)));
quote! {
#[serde(flatten)]
pub #name: #type_name
}
},
FieldType::Existing(type_name) => {
let pref_name = self.pref_name(field, path_stack);
let attributes = field.get_attributes(&pref_name);
quote! {
#attributes
pub #name: #type_name
}
},
})
}
fn path_to_name<'p, P: Iterator<Item = &'p Ident> + 'p>(&self, path: P) -> Ident {
let mut name = format!("{}", self.root_type_name);
for part in path {
name.write_fmt(format_args!("__{}", part)).unwrap();
}
Ident::new(&name, Span::call_site())
}
}
impl Field {
fn get_attributes(&self, pref_name: &str) -> TokenStream {
let mut tokens = TokenStream::new();
for attr in self
.attributes
.iter()
.filter(|attr| attr_to_pref_name(attr).is_none())
{
attr.to_tokens(&mut tokens);
}
tokens.extend(quote! {
#[serde(rename = #pref_name)]
});
tokens
}
fn get_field_name_mapping(&self) -> Option<LitStr> {
self.attributes.iter().filter_map(attr_to_pref_name).next()
}
}
fn attr_to_pref_name(attr: &Attribute) -> Option<LitStr> {
if attr.path().is_ident("serde") {
// If `parse_nested_meta()` fails, `result` will remain None.
let mut result = None;
let _ = attr.parse_nested_meta(|meta| {
if meta.path.is_ident("rename") {
result = Some(meta.value()?.parse()?);
}
Ok(())
});
result
} else {
None
}
}
fn err<S: Spanned>(s: S, msg: &str) -> syn::Error {
syn::Error::new(s.span(), msg)
}

View file

@ -1,151 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use proc_macro2::Span;
use syn::parse::{Parse, ParseStream, Result};
use syn::punctuated::Punctuated;
use syn::{braced, token, Attribute, Ident, Path, Token, Type};
#[allow(non_camel_case_types)]
mod kw {
syn::custom_keyword!(accessor_type);
syn::custom_keyword!(gen_accessors);
syn::custom_keyword!(gen_types);
}
pub struct MacroInput {
pub type_def: RootTypeDef,
pub gen_accessors: Ident,
pub accessor_type: Path,
}
enum MacroArg {
GenAccessors(ArgInner<kw::gen_accessors, Ident>),
AccessorType(ArgInner<kw::accessor_type, Path>),
Types(ArgInner<kw::gen_types, RootTypeDef>),
}
struct ArgInner<K, V> {
_field_kw: K,
_equals: Token![=],
value: V,
}
pub struct Field {
pub attributes: Vec<Attribute>,
pub name: Ident,
_colon: Token![:],
pub field_type: FieldType,
}
pub enum FieldType {
Existing(Type),
NewTypeDef(NewTypeDef),
}
pub struct NewTypeDef {
_braces: token::Brace,
pub fields: Punctuated<Field, Token![, ]>,
}
pub struct RootTypeDef {
pub type_name: Ident,
pub type_def: NewTypeDef,
}
impl Parse for MacroInput {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let fields: Punctuated<MacroArg, Token![, ]> =
Punctuated::parse_terminated_with(input, MacroArg::parse)?;
let mut gen_accessors = None;
let mut type_def = None;
let mut accessor_type = None;
for arg in fields.into_iter() {
match arg {
MacroArg::GenAccessors(ArgInner { value, .. }) => gen_accessors = Some(value),
MacroArg::AccessorType(ArgInner { value, .. }) => accessor_type = Some(value),
MacroArg::Types(ArgInner { value, .. }) => type_def = Some(value),
}
}
fn missing_attr(att_name: &str) -> syn::Error {
syn::Error::new(
Span::call_site(),
format!("Expected `{}` attribute", att_name),
)
}
Ok(MacroInput {
type_def: type_def.ok_or_else(|| missing_attr("gen_types"))?,
gen_accessors: gen_accessors.ok_or_else(|| missing_attr("gen_accessors"))?,
accessor_type: accessor_type.ok_or_else(|| missing_attr("accessor_type"))?,
})
}
}
impl Parse for MacroArg {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let lookahead = input.lookahead1();
if lookahead.peek(kw::gen_types) {
Ok(MacroArg::Types(input.parse()?))
} else if lookahead.peek(kw::gen_accessors) {
Ok(MacroArg::GenAccessors(input.parse()?))
} else if lookahead.peek(kw::accessor_type) {
Ok(MacroArg::AccessorType(input.parse()?))
} else {
Err(lookahead.error())
}
}
}
impl<K: Parse, V: Parse> Parse for ArgInner<K, V> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
Ok(ArgInner {
_field_kw: input.parse()?,
_equals: input.parse()?,
value: input.parse()?,
})
}
}
impl Parse for Field {
fn parse(input: ParseStream<'_>) -> Result<Self> {
Ok(Field {
attributes: input.call(Attribute::parse_outer)?,
name: input.parse()?,
_colon: input.parse()?,
field_type: input.parse()?,
})
}
}
impl Parse for RootTypeDef {
fn parse(input: ParseStream<'_>) -> Result<Self> {
Ok(RootTypeDef {
type_name: input.parse()?,
type_def: input.parse()?,
})
}
}
impl Parse for NewTypeDef {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let content;
#[allow(clippy::mixed_read_write_in_expression)]
Ok(NewTypeDef {
_braces: braced!(content in input),
fields: Punctuated::parse_terminated_with(&content, Field::parse)?,
})
}
}
impl Parse for FieldType {
fn parse(input: ParseStream<'_>) -> Result<Self> {
if input.peek(token::Brace) {
Ok(FieldType::NewTypeDef(input.parse()?))
} else {
Ok(FieldType::Existing(input.parse()?))
}
}
}

View file

@ -660,7 +660,7 @@ where
// a dedicated per-process hang monitor will be initialized later inside the content process.
// See run_content_process in servo/lib.rs
let (background_monitor_register, background_hang_monitor_control_ipc_senders) =
if opts::multiprocess() {
if opts::get().multiprocess {
(None, vec![])
} else {
let (
@ -2502,7 +2502,7 @@ where
};
let content = ServiceWorkerUnprivilegedContent::new(sw_senders, origin);
if opts::multiprocess() {
if opts::get().multiprocess {
if content.spawn_multiprocess().is_err() {
return warn!("Failed to spawn process for SW manager.");
}
@ -5034,7 +5034,7 @@ where
let pipelines_to_evict = {
let session_history = self.get_joint_session_history(top_level_browsing_context_id);
let history_length = pref!(session_history.max_length) as usize;
let history_length = pref!(session_history_max_length) as usize;
// The past is stored with older entries at the front.
// We reverse the iter so that newer entries are at the front and then

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::rc::Rc;
use std::sync::Arc;
@ -39,8 +39,7 @@ use script_traits::{
};
use serde::{Deserialize, Serialize};
use servo_config::opts::{self, Opts};
use servo_config::prefs;
use servo_config::prefs::PrefValue;
use servo_config::prefs::{self, Preferences};
use servo_url::ServoUrl;
use webrender_api::DocumentId;
use webrender_traits::CrossProcessCompositorApi;
@ -283,7 +282,7 @@ impl Pipeline {
load_data: state.load_data.clone(),
script_port,
opts: (*opts::get()).clone(),
prefs: prefs::pref_map().iter().collect(),
prefs: Box::new(prefs::get().clone()),
pipeline_namespace_id: state.pipeline_namespace_id,
webrender_document: state.webrender_document,
cross_process_compositor_api: state
@ -300,7 +299,7 @@ impl Pipeline {
// Spawn the child process.
//
// Yes, that's all there is to it!
let bhm_control_chan = if opts::multiprocess() {
let bhm_control_chan = if opts::get().multiprocess {
let (bhm_control_chan, bhm_control_port) =
ipc::channel().expect("Sampler chan");
unprivileged_pipeline_content.bhm_control_port = Some(bhm_control_port);
@ -490,7 +489,7 @@ pub struct UnprivilegedPipelineContent {
load_data: LoadData,
script_port: IpcReceiver<ConstellationControlMsg>,
opts: Opts,
prefs: HashMap<String, PrefValue>,
prefs: Box<Preferences>,
pipeline_namespace_id: PipelineNamespaceId,
cross_process_compositor_api: CrossProcessCompositorApi,
webrender_document: DocumentId,
@ -581,7 +580,7 @@ impl UnprivilegedPipelineContent {
self.opts.clone()
}
pub fn prefs(&self) -> HashMap<String, PrefValue> {
self.prefs.clone()
pub fn prefs(&self) -> &Preferences {
&self.prefs
}
}

View file

@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
#[cfg(not(windows))]
use std::env;
use std::ffi::OsStr;
@ -23,7 +22,7 @@ use gaol::profile::{Operation, PathPattern, Profile};
use ipc_channel::Error;
use serde::{Deserialize, Serialize};
use servo_config::opts::Opts;
use servo_config::prefs::PrefValue;
use servo_config::prefs::Preferences;
use crate::pipeline::UnprivilegedPipelineContent;
use crate::serviceworker::ServiceWorkerUnprivilegedContent;
@ -43,7 +42,7 @@ impl UnprivilegedContent {
}
}
pub fn prefs(&self) -> HashMap<String, PrefValue> {
pub fn prefs(&self) -> &Preferences {
match self {
UnprivilegedContent::Pipeline(content) => content.prefs(),
UnprivilegedContent::ServiceWorker(content) => content.prefs(),

View file

@ -2,13 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use ipc_channel::Error;
use script_traits::{SWManagerSenders, ServiceWorkerManagerFactory};
use serde::{Deserialize, Serialize};
use servo_config::opts::{self, Opts};
use servo_config::prefs::{self, PrefValue};
use servo_config::prefs;
use servo_config::prefs::Preferences;
use servo_url::ImmutableOrigin;
use crate::sandboxing::{spawn_multiprocess, UnprivilegedContent};
@ -18,7 +17,7 @@ use crate::sandboxing::{spawn_multiprocess, UnprivilegedContent};
#[derive(Deserialize, Serialize)]
pub struct ServiceWorkerUnprivilegedContent {
opts: Opts,
prefs: HashMap<String, PrefValue>,
prefs: Box<Preferences>,
senders: SWManagerSenders,
origin: ImmutableOrigin,
}
@ -30,7 +29,7 @@ impl ServiceWorkerUnprivilegedContent {
) -> ServiceWorkerUnprivilegedContent {
ServiceWorkerUnprivilegedContent {
opts: (*opts::get()).clone(),
prefs: prefs::pref_map().iter().collect(),
prefs: Box::new(prefs::get().clone()),
senders,
origin,
}
@ -53,7 +52,7 @@ impl ServiceWorkerUnprivilegedContent {
self.opts.clone()
}
pub fn prefs(&self) -> HashMap<String, PrefValue> {
self.prefs.clone()
pub fn prefs(&self) -> &Preferences {
&self.prefs
}
}

View file

@ -2,14 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
use std::net::TcpStream;
use log::warn;
use serde::Serialize;
use serde_json::{Map, Value};
use servo_config::pref_util::PrefValue;
use servo_config::prefs::pref_map;
use servo_config::pref;
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::protocol::JsonPacketStream;
@ -38,128 +36,93 @@ impl Actor for PreferenceActor {
stream: &mut TcpStream,
_id: StreamId,
) -> Result<ActorMessageStatus, ()> {
let Some(mut key) = msg.get("value").and_then(|v| v.as_str()) else {
let Some(key) = msg.get("value").and_then(|v| v.as_str()) else {
warn!("PreferenceActor: handle_message: value is not a string");
return Ok(ActorMessageStatus::Ignored);
};
// Mapping to translate a Firefox preference name onto the corresponding Servo preference name
let pref_name_mapping: HashMap<&str, &str> =
[("dom.serviceWorkers.enabled", "dom.serviceworker.enabled")]
.iter()
.copied()
.collect();
if pref_name_mapping.contains_key(key) {
key = pref_name_mapping.get(key).unwrap();
// TODO: Map more preferences onto their Servo values.
Ok(match key {
"dom.serviceWorkers.enabled" => {
self.write_bool(pref!(dom_serviceworker_enabled), stream)
},
_ => self.handle_missing_preference(msg_type, stream),
})
}
}
impl PreferenceActor {
fn handle_missing_preference(
&self,
msg_type: &str,
stream: &mut TcpStream,
) -> ActorMessageStatus {
match msg_type {
"getBoolPref" => self.write_bool(false, stream),
"getCharPref" => self.write_char("".into(), stream),
"getIntPref" => self.write_int(0, stream),
"getFloatPref" => self.write_float(0., stream),
_ => ActorMessageStatus::Ignored,
}
}
fn write_bool(&self, pref_value: bool, stream: &mut TcpStream) -> ActorMessageStatus {
#[derive(Serialize)]
struct BoolReply {
from: String,
value: bool,
}
let pref_value = pref_map().get(key);
Ok(handle_preference_value(
pref_value,
self.name(),
msg_type,
stream,
))
let reply = BoolReply {
from: self.name.clone(),
value: pref_value,
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
}
fn write_char(&self, pref_value: String, stream: &mut TcpStream) -> ActorMessageStatus {
#[derive(Serialize)]
struct CharReply {
from: String,
value: String,
}
let reply = CharReply {
from: self.name.clone(),
value: pref_value,
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
}
fn write_int(&self, pref_value: i64, stream: &mut TcpStream) -> ActorMessageStatus {
#[derive(Serialize)]
struct IntReply {
from: String,
value: i64,
}
let reply = IntReply {
from: self.name.clone(),
value: pref_value,
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
}
fn write_float(&self, pref_value: f64, stream: &mut TcpStream) -> ActorMessageStatus {
#[derive(Serialize)]
struct FloatReply {
from: String,
value: f64,
}
let reply = FloatReply {
from: self.name.clone(),
value: pref_value,
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
}
}
fn handle_preference_value(
pref_value: PrefValue,
name: String,
msg_type: &str,
stream: &mut TcpStream,
) -> ActorMessageStatus {
match pref_value {
PrefValue::Float(value) => {
let reply = FloatReply { from: name, value };
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
PrefValue::Int(value) => {
let reply = IntReply { from: name, value };
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
PrefValue::Str(value) => {
let reply = CharReply { from: name, value };
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
PrefValue::Bool(value) => {
let reply = BoolReply { from: name, value };
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
PrefValue::Array(values) => {
let mut result = ActorMessageStatus::Processed;
for value in values {
result = handle_preference_value(value, name.clone(), msg_type, stream);
}
result
},
PrefValue::Missing => handle_missing_preference(name, msg_type, stream),
}
}
// if the preferences are missing from pref_map then we return a
// fake preference response based on msg_type.
fn handle_missing_preference(
name: String,
msg_type: &str,
stream: &mut TcpStream,
) -> ActorMessageStatus {
match msg_type {
"getBoolPref" => {
let reply = BoolReply {
from: name,
value: false,
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
"getCharPref" => {
let reply = CharReply {
from: name,
value: "".to_owned(),
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
"getIntPref" => {
let reply = IntReply {
from: name,
value: 0,
};
let _ = stream.write_json_packet(&reply);
ActorMessageStatus::Processed
},
_ => ActorMessageStatus::Ignored,
}
}
#[derive(Serialize)]
struct BoolReply {
from: String,
value: bool,
}
#[derive(Serialize)]
struct CharReply {
from: String,
value: String,
}
#[derive(Serialize)]
struct IntReply {
from: String,
value: i64,
}
#[derive(Serialize)]
struct FloatReply {
from: String,
value: f64,
}

View file

@ -323,10 +323,10 @@ impl SystemFontService {
.get_or_init(|| {
// First check whether the font is set in the preferences.
let family_name = match generic {
GenericFontFamily::None => pref!(fonts.default),
GenericFontFamily::Serif => pref!(fonts.serif),
GenericFontFamily::SansSerif => pref!(fonts.sans_serif),
GenericFontFamily::Monospace => pref!(fonts.monospace),
GenericFontFamily::None => pref!(fonts_default),
GenericFontFamily::Serif => pref!(fonts_serif),
GenericFontFamily::SansSerif => pref!(fonts_sans_serif),
GenericFontFamily::Monospace => pref!(fonts_monospace),
_ => String::new(),
};

View file

@ -520,7 +520,7 @@ impl LayoutThread {
compositor_api.send_initial_transaction(id.into());
let mut font = Font::initial_values();
let default_font_size = pref!(fonts.default_size);
let default_font_size = pref!(fonts_default_size);
font.font_size = FontSize {
computed_size: NonNegativeLength::new(default_font_size as f32),
used_size: NonNegativeLength::new(default_font_size as f32),
@ -1519,8 +1519,8 @@ impl FontMetricsProvider for LayoutFontMetricsProvider {
fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length {
Length::new(match generic {
GenericFontFamily::Monospace => pref!(fonts.default_monospace_size),
_ => pref!(fonts.default_size),
GenericFontFamily::Monospace => pref!(fonts_default_monospace_size),
_ => pref!(fonts_default_size),
} as f32)
.max(Length::new(0.0))
}

View file

@ -495,7 +495,7 @@ impl LayoutThread {
compositor_api.send_initial_transaction(id.into());
let mut font = Font::initial_values();
let default_font_size = pref!(fonts.default_size);
let default_font_size = pref!(fonts_default_size);
font.font_size = FontSize {
computed_size: NonNegativeLength::new(default_font_size as f32),
used_size: NonNegativeLength::new(default_font_size as f32),
@ -1232,8 +1232,8 @@ impl FontMetricsProvider for LayoutFontMetricsProvider {
fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length {
Length::new(match generic {
GenericFontFamily::Monospace => pref!(fonts.default_monospace_size),
_ => pref!(fonts.default_size),
GenericFontFamily::Monospace => pref!(fonts_default_monospace_size),
_ => pref!(fonts_default_size),
} as f32)
.max(Length::new(0.0))
}

View file

@ -19,9 +19,9 @@ pub static HANDLE: LazyLock<Mutex<Option<Runtime>>> = LazyLock::new(|| {
.worker_threads(
thread::available_parallelism()
.map(|i| i.get())
.unwrap_or(servo_config::pref!(threadpools.fallback_worker_num) as usize)
.unwrap_or(servo_config::pref!(threadpools_fallback_worker_num) as usize)
.min(
servo_config::pref!(threadpools.async_runtime_workers.max).max(1) as usize,
servo_config::pref!(threadpools_async_runtime_workers_max).max(1) as usize,
),
)
.enable_io()

View file

@ -280,7 +280,7 @@ impl Stream for BodyStream {
.content_length
.map_or(false, |c| c.0 == self.total_read);
if self.is_secure_scheme &&
(all_content_read || pref!(network.tls.ignore_unexpected_eof))
(all_content_read || pref!(network_tls_ignore_unexpected_eof))
{
let source = err.source();
let is_unexpected_eof = source

View file

@ -602,7 +602,7 @@ impl FileManagerStore {
// Check if the select_files preference is enabled
// to ensure process-level security against compromised script;
// Then try applying opt_test_path directly for testing convenience
let opt_s = if pref!(dom.testing.html_input_element.select_files.enabled) {
let opt_s = if pref!(dom_testing_html_input_element_select_files_enabled) {
opt_test_path
} else {
self.query_files_from_embedder(patterns, false, embedder_proxy)
@ -632,7 +632,7 @@ impl FileManagerStore {
// Check if the select_files preference is enabled
// to ensure process-level security against compromised script;
// Then try applying opt_test_paths directly for testing convenience
let opt_v = if pref!(dom.testing.html_input_element.select_files.enabled) {
let opt_v = if pref!(dom_testing_html_input_element_select_files_enabled) {
opt_test_paths
} else {
self.query_files_from_embedder(patterns, true, embedder_proxy)

View file

@ -144,8 +144,8 @@ impl HstsList {
return;
}
let upgrade_scheme = if pref!(network.enforce_tls.enabled) {
if (!pref!(network.enforce_tls.localhost) &&
let upgrade_scheme = if pref!(network_enforce_tls_enabled) {
if (!pref!(network_enforce_tls_localhost) &&
match url.host() {
Some(Host::Domain(domain)) => {
domain.ends_with(".localhost") || domain == "localhost"
@ -154,7 +154,7 @@ impl HstsList {
Some(Host::Ipv6(ipv6)) => ipv6.is_loopback(),
_ => false,
}) ||
(!pref!(network.enforce_tls.onion) &&
(!pref!(network_enforce_tls_onion) &&
url.domain()
.is_some_and(|domain| domain.ends_with(".onion")))
{

View file

@ -756,7 +756,7 @@ impl HttpCache {
/// Storing Responses in Caches.
/// <https://tools.ietf.org/html/rfc7234#section-3>
pub fn store(&mut self, request: &Request, response: &Response) {
if pref!(network.http_cache.disabled) {
if pref!(network_http_cache_disabled) {
return;
}
if request.method != Method::GET {

View file

@ -17,6 +17,7 @@ use net_traits::image_cache::{
use net_traits::request::CorsSettings;
use net_traits::{FetchMetadata, FetchResponseMsg, FilteredMetadata, NetworkError};
use pixels::{load_from_memory, CorsStatus, Image, ImageMetadata, PixelFormat};
use servo_config::pref;
use servo_url::{ImmutableOrigin, ServoUrl};
use webrender_api::units::DeviceIntSize;
use webrender_api::{ImageDescriptor, ImageDescriptorFlags, ImageFormat};
@ -422,8 +423,8 @@ impl ImageCache for ImageCacheImpl {
// If no information can be obtained about the system, uses 4 threads as a default
let thread_count = thread::available_parallelism()
.map(|i| i.get())
.unwrap_or(servo_config::pref!(threadpools.fallback_worker_num) as usize)
.min(servo_config::pref!(threadpools.async_runtime_workers.max).max(1) as usize);
.unwrap_or(pref!(threadpools_fallback_worker_num) as usize)
.min(pref!(threadpools_async_runtime_workers_max).max(1) as usize);
ImageCacheImpl {
store: Arc::new(Mutex::new(ImageCacheStore {

View file

@ -16,7 +16,7 @@ use servo_url::ServoUrl;
use url::Url;
pub fn fetch(request: &mut Request, url: ServoUrl, path_buf: PathBuf) -> Response {
if !pref!(network.local_directory_listing.enabled) {
if !pref!(network_local_directory_listing_enabled) {
// If you want to be able to browse local directories, configure Servo prefs so that
// "network.local_directory_listing.enabled" is set to true.
return Response::network_error(NetworkError::Internal(

View file

@ -695,8 +695,8 @@ impl CoreResourceManager {
) -> CoreResourceManager {
let num_threads = thread::available_parallelism()
.map(|i| i.get())
.unwrap_or(servo_config::pref!(threadpools.fallback_worker_num) as usize)
.min(servo_config::pref!(threadpools.resource_workers.max).max(1) as usize);
.unwrap_or(servo_config::pref!(threadpools_fallback_worker_num) as usize)
.min(servo_config::pref!(threadpools_resource_workers_max).max(1) as usize);
let pool = CoreResourceThreadPool::new(num_threads, "CoreResourceThreadPool".to_string());
let pool_handle = Arc::new(pool);
CoreResourceManager {

View file

@ -15,16 +15,19 @@ use net_traits::blob_url_store::BlobURLStoreError;
use net_traits::filemanager_thread::{
FileManagerThreadError, FileManagerThreadMsg, ReadFileProgress,
};
use servo_config::set_pref;
use servo_config::prefs::Preferences;
use crate::create_embedder_proxy;
#[test]
fn test_filemanager() {
let mut preferences = Preferences::default();
preferences.dom_testing_html_input_element_select_files_enabled = true;
servo_config::prefs::set(preferences);
let pool = CoreResourceThreadPool::new(1, "CoreResourceTestPool".to_string());
let pool_handle = Arc::new(pool);
let filemanager = FileManager::new(create_embedder_proxy(), Arc::downgrade(&pool_handle));
set_pref!(dom.testing.html_input_element.select_files.enabled, true);
// Try to open a dummy file "components/net/tests/test.jpeg" in tree
let mut handler = File::open("tests/test.jpeg").expect("test.jpeg is stolen");

View file

@ -89,10 +89,31 @@ def generate(config, name, filename):
def add_css_properties_attributes(css_properties_json, parser):
def map_preference_name(preference_name: str):
"""Map between Stylo preference names and Servo preference names as the
`css-properties.json` file is generated by Stylo. This should be kept in sync with the
preference mapping done in `components/servo_config/prefs.rs`, which handles the runtime version of
these preferences."""
MAPPING = [
["layout.unimplemented", "layout_unimplemented"],
["layout.threads", "layout_threads"],
["layout.legacy_layout", "layout_legacy_layout"],
["layout.flexbox.enabled", "layout_flexbox_enabled"],
["layout.columns.enabled", "layout_columns_enabled"],
["layout.grid.enabled", "layout_grid_enabled"],
["layout.css.transition-behavior.enabled", "layout_css_transition_behavior_enabled"],
["layout.writing-mode.enabled", "layout_writing_mode_enabled"],
["layout.container-queries.enabled", "layout_container_queries_enabled"],
]
for mapping in MAPPING:
if mapping[0] == preference_name:
return mapping[1]
return preference_name
css_properties = json.load(open(css_properties_json, "rb"))
idl = "partial interface CSSStyleDeclaration {\n%s\n};\n" % "\n".join(
" [%sCEReactions, SetterThrows] attribute [LegacyNullToEmptyString] DOMString %s;" % (
('Pref="%s", ' % data["pref"] if data["pref"] else ""),
(f'Pref="{map_preference_name(data["pref"])}", ' if data["pref"] else ""),
attribute_name
)
for (kind, properties_list) in sorted(css_properties.items())

View file

@ -5,7 +5,7 @@
//! Machinery to conditionally expose things.
use js::rust::HandleObject;
use servo_config::prefs;
use servo_config::prefs::get;
use crate::dom::bindings::codegen::InterfaceObjectMap;
use crate::dom::bindings::interface::is_exposed_in;
@ -85,7 +85,7 @@ impl Condition {
global: HandleObject,
) -> bool {
match *self {
Condition::Pref(name) => prefs::pref_map().get(name).as_bool().unwrap_or(false),
Condition::Pref(name) => get().get_value(name).try_into().unwrap_or(false),
Condition::Func(f) => f(cx, obj),
Condition::Exposed(globals) => is_exposed_in(global, globals),
Condition::SecureContext() => is_secure_context(cx),

View file

@ -108,7 +108,7 @@ fn create_svg_element(
})
);
if !pref!(dom.svg.enabled) {
if !pref!(dom_svg_enabled) {
return Element::new(name.local, name.ns, prefix, document, proto, CanGc::note());
}

View file

@ -1356,8 +1356,8 @@ impl Document {
if let Some((last_time, last_pos)) = opt {
let DBL_CLICK_TIMEOUT =
Duration::from_millis(pref!(dom.document.dblclick_timeout) as u64);
let DBL_CLICK_DIST_THRESHOLD = pref!(dom.document.dblclick_dist) as u64;
Duration::from_millis(pref!(dom_document_dblclick_timeout) as u64);
let DBL_CLICK_DIST_THRESHOLD = pref!(dom_document_dblclick_dist) as u64;
// Calculate distance between this click and the previous click.
let line = click_pos - last_pos;
@ -2469,7 +2469,7 @@ impl Document {
// https://immersive-web.github.io/webxr/#user-intention
// https://github.com/immersive-web/navigation/issues/10
#[cfg(feature = "webxr")]
if pref!(dom.webxr.sessionavailable) && self.window.is_top_level() {
if pref!(dom_webxr_sessionavailable) && self.window.is_top_level() {
self.window.Navigator().Xr().dispatch_sessionavailable();
}
@ -2850,7 +2850,7 @@ impl Document {
local_name: &LocalName,
is: Option<&LocalName>,
) -> Option<Rc<CustomElementDefinition>> {
if !pref!(dom.custom_elements.enabled) {
if !pref!(dom_customelements_enabled) {
return None;
}
@ -3344,7 +3344,7 @@ impl Document {
#[cfg(feature = "webgpu")]
webgpu_contexts: Rc::new(RefCell::new(HashMapTracedValues::new())),
selection: MutNullableDom::new(None),
animation_timeline: if pref!(layout.animations.test.enabled) {
animation_timeline: if pref!(layout_animations_test_enabled) {
DomRefCell::new(AnimationTimeline::new_for_testing())
} else {
DomRefCell::new(AnimationTimeline::new())
@ -3826,7 +3826,7 @@ impl Document {
error = true;
}
if pref!(dom.fullscreen.test) {
if pref!(dom_fullscreen_test) {
// For reftests we just take over the current window,
// and don't try to really enter fullscreen.
info!("Tests don't really enter fullscreen.");
@ -4109,7 +4109,7 @@ impl Document {
/// An implementation of <https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events>.
pub(crate) fn update_animations_and_send_events(&self, can_gc: CanGc) {
// Only update the time if it isn't being managed by a test.
if !pref!(layout.animations.test.enabled) {
if !pref!(layout_animations_test_enabled) {
self.animation_timeline.borrow_mut().update();
}

View file

@ -1325,7 +1325,7 @@ impl HTMLMediaElement {
.render_poster_frame(image);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
if pref!(media.testing.enabled) {
if pref!(media_testing_enabled) {
self.owner_global()
.task_manager()
.media_element_task_source()

View file

@ -463,7 +463,7 @@ impl FetchResponseListener for ClassicContext {
/*
let options = unsafe { CompileOptionsWrapper::new(*cx, final_url.as_str(), 1) };
let can_compile_off_thread = pref!(dom.script.asynch) &&
let can_compile_off_thread = pref!(dom_script_asynch) &&
unsafe { CanCompileOffThread(*cx, options.ptr as *const _, source_text.len()) };
if can_compile_off_thread {

View file

@ -408,7 +408,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
// This returns the same result as current gecko.
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
fn Which(&self) -> i32 {
if pref!(dom.mouse_event.which.enabled) {
if pref!(dom_mouse_event_which_enabled) {
(self.button.get() + 1) as i32
} else {
0

View file

@ -421,7 +421,7 @@ impl PaintWorkletGlobalScope {
.expect("Locking a painter.")
.schedule_a_worklet_task(WorkletTask::Paint(task));
let timeout = pref!(dom.worklet.timeout_ms) as u64;
let timeout = pref!(dom_worklet_timeout_ms) as u64;
receiver
.recv_timeout(Duration::from_millis(timeout))

View file

@ -301,7 +301,7 @@ pub(crate) fn get_descriptor_permission_state(
// and let the user decide to grant the permission or not.
let state = if allowed_in_nonsecure_contexts(&permission_name) {
PermissionState::Prompt
} else if pref!(dom.permissions.testing.allowed_in_nonsecure_contexts) {
} else if pref!(dom_permissions_testing_allowed_in_nonsecure_contexts) {
PermissionState::Granted
} else {
globalscope

View file

@ -306,7 +306,7 @@ impl ServiceWorkerGlobalScope {
// Service workers are time limited
// https://w3c.github.io/ServiceWorker/#service-worker-lifetime
let sw_lifetime_timeout = pref!(dom.serviceworker.timeout_seconds) as u64;
let sw_lifetime_timeout = pref!(dom_serviceworker_timeout_seconds) as u64;
let time_out_port = after(Duration::new(sw_lifetime_timeout, 0));
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();

View file

@ -158,7 +158,7 @@ impl ServoParser {
url: ServoUrl,
can_gc: CanGc,
) {
let parser = if pref!(dom.servoparser.async_html_tokenizer.enabled) {
let parser = if pref!(dom_servoparser_async_html_tokenizer_enabled) {
ServoParser::new(
document,
Tokenizer::AsyncHtml(self::async_html::Tokenizer::new(document, url, None)),

View file

@ -880,17 +880,18 @@ impl TestBindingMethods<crate::DomTypeHolder> for TestBinding {
fn PassVariadicAny(&self, _: SafeJSContext, _: Vec<HandleValue>) {}
fn PassVariadicObject(&self, _: SafeJSContext, _: Vec<*mut JSObject>) {}
fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
prefs::pref_map()
.get(pref_name.as_ref())
.as_bool()
prefs::get()
.get_value(pref_name.as_ref())
.try_into()
.unwrap_or(false)
}
fn StringMozPreference(&self, pref_name: DOMString) -> DOMString {
prefs::pref_map()
.get(pref_name.as_ref())
.as_str()
.map(DOMString::from)
.unwrap_or_default()
DOMString::from_string(
prefs::get()
.get_value(pref_name.as_ref())
.try_into()
.unwrap_or_default(),
)
}
fn PrefControlledAttributeDisabled(&self) -> bool {
false

View file

@ -198,7 +198,7 @@ impl WebGL2RenderingContext {
#[allow(unsafe_code)]
pub(crate) fn is_webgl2_enabled(_cx: JSContext, global: HandleObject) -> bool {
if pref!(dom.webgl2.enabled) {
if pref!(dom_webgl2_enabled) {
return true;
}

View file

@ -222,7 +222,7 @@ impl WebGLRenderingContext {
size: Size2D<u32>,
attrs: GLContextAttributes,
) -> Result<WebGLRenderingContext, String> {
if pref!(webgl.testing.context_creation_error) {
if pref!(webgl_testing_context_creation_error) {
return Err("WebGL context creation error forced by pref `webgl.testing.context_creation_error`".into());
}

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://dom.spec.whatwg.org/#interface-abortcontroller
[Exposed=*, Pref="dom.abort_controller.enabled"]
[Exposed=*, Pref="dom_abort_controller_enabled"]
interface AbortController {
constructor();

View file

@ -7,9 +7,9 @@
// web pages.
[Exposed=(Window,Worker)]
interface mixin ActivatableElement {
[Throws, Pref="dom.testing.element.activation.enabled"]
[Throws, Pref="dom_testing_element_activation_enabled"]
undefined enterFormalActivationState();
[Throws, Pref="dom.testing.element.activation.enabled"]
[Throws, Pref="dom_testing_element_activation_enabled"]
undefined exitFormalActivationState();
};

View file

@ -25,7 +25,7 @@ dictionary RequestDeviceOptions {
boolean acceptAllDevices = false;
};
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface Bluetooth : EventTarget {
[SecureContext]
Promise<boolean> getAvailability();

View file

@ -10,7 +10,7 @@
interface BluetoothServiceDataMap {
readonly maplike<UUID, DataView>;
};*/
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothAdvertisingEvent : Event {
[Throws] constructor(DOMString type, BluetoothAdvertisingEventInit init);
[SameObject]

View file

@ -4,7 +4,7 @@
// https://webbluetoothcg.github.io/web-bluetooth/#characteristicproperties
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothCharacteristicProperties {
readonly attribute boolean broadcast;
readonly attribute boolean read;

View file

@ -4,7 +4,7 @@
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothDevice : EventTarget {
readonly attribute DOMString id;
readonly attribute DOMString? name;

View file

@ -12,7 +12,7 @@ dictionary BluetoothPermissionDescriptor : PermissionDescriptor {
boolean acceptAllDevices = false;
};
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothPermissionResult : PermissionStatus {
// attribute FrozenArray<BluetoothDevice> devices;
// Workaround until FrozenArray get implemented.

View file

@ -4,7 +4,7 @@
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothRemoteGATTCharacteristic : EventTarget {
[SameObject]
readonly attribute BluetoothRemoteGATTService service;

View file

@ -4,7 +4,7 @@
// http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothRemoteGATTDescriptor {
[SameObject]
readonly attribute BluetoothRemoteGATTCharacteristic characteristic;

View file

@ -4,7 +4,7 @@
//https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothRemoteGATTServer {
[SameObject]
readonly attribute BluetoothDevice device;

View file

@ -4,7 +4,7 @@
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothRemoteGATTService : EventTarget {
[SameObject]
readonly attribute BluetoothDevice device;

View file

@ -4,7 +4,7 @@
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothuuid
[Exposed=Window, Pref="dom.bluetooth.enabled"]
[Exposed=Window, Pref="dom_bluetooth_enabled"]
interface BluetoothUUID {
[Throws]
static UUID getService(BluetoothServiceUUID name);

View file

@ -20,5 +20,5 @@ partial interface CSS {
// https://drafts.css-houdini.org/css-paint-api-1/#paint-worklet
partial interface CSS {
[SameObject, Pref="dom.worklet.enabled"] static readonly attribute Worklet paintWorklet;
[SameObject, Pref="dom_worklet_enabled"] static readonly attribute Worklet paintWorklet;
};

View file

@ -4,7 +4,7 @@
// https://drafts.css-houdini.org/css-typed-om-1/#cssstylevalue
// NOTE: should this be exposed to Window?
[Pref="dom.worklet.enabled", Exposed=(Worklet)]
[Pref="dom_worklet_enabled", Exposed=(Worklet)]
interface CSSStyleValue {
stringifier;
};

View file

@ -139,12 +139,12 @@ interface mixin CanvasUserInterface {
interface mixin CanvasText {
// text (see also the CanvasPathDrawingStyles and CanvasTextDrawingStyles interfaces)
[Pref="dom.canvas_text.enabled"]
[Pref="dom_canvas_text_enabled"]
undefined fillText(DOMString text, unrestricted double x, unrestricted double y,
optional unrestricted double maxWidth);
//void strokeText(DOMString text, unrestricted double x, unrestricted double y,
// optional unrestricted double maxWidth);
[Pref="dom.canvas_text.enabled"]
[Pref="dom_canvas_text_enabled"]
TextMetrics measureText(DOMString text);
};

View file

@ -4,7 +4,7 @@
// https://w3c.github.io/ServiceWorker/#client
[Pref="dom.serviceworker.enabled", Exposed=ServiceWorker]
[Pref="dom_serviceworker_enabled", Exposed=ServiceWorker]
interface Client {
readonly attribute USVString url;
readonly attribute FrameType frameType;

View file

@ -8,7 +8,7 @@
*/
// https://w3c.github.io/uievents/#idl-compositionevent
[Exposed=Window, Pref="dom.composition_event.enabled"]
[Exposed=Window, Pref="dom_composition_event_enabled"]
interface CompositionEvent : UIEvent {
[Throws] constructor(DOMString type, optional CompositionEventInit eventInitDict = {});
readonly attribute DOMString data;

View file

@ -13,7 +13,7 @@ partial interface mixin WindowOrWorkerGlobalScope {
[Exposed=(Window,Worker)]
interface Crypto {
[SecureContext, Pref="dom.crypto.subtle.enabled"] readonly attribute SubtleCrypto subtle;
[SecureContext, Pref="dom_crypto_subtle_enabled"] readonly attribute SubtleCrypto subtle;
[Throws] ArrayBufferView getRandomValues(ArrayBufferView array);
[SecureContext] DOMString randomUUID();
};

View file

@ -8,7 +8,7 @@ enum KeyType { "public", "private", "secret" };
enum KeyUsage { "encrypt", "decrypt", "sign", "verify", "deriveKey", "deriveBits", "wrapKey", "unwrapKey" };
[SecureContext, Exposed=(Window,Worker), Serializable, Pref="dom.crypto.subtle.enabled"]
[SecureContext, Exposed=(Window,Worker), Serializable, Pref="dom_crypto_subtle_enabled"]
interface CryptoKey {
readonly attribute KeyType type;
readonly attribute boolean extractable;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://html.spec.whatwg.org/multipage/#customelementregistry
[Exposed=Window, Pref="dom.custom_elements.enabled"]
[Exposed=Window, Pref="dom_customelements_enabled"]
interface CustomElementRegistry {
[Throws, CEReactions]
undefined define(

View file

@ -83,7 +83,7 @@ interface Element : Node {
[CEReactions, Throws]
undefined insertAdjacentHTML(DOMString position, DOMString html);
[Throws, Pref="dom.shadowdom.enabled"] ShadowRoot attachShadow(ShadowRootInit init);
[Throws, Pref="dom_shadowdom_enabled"] ShadowRoot attachShadow(ShadowRootInit init);
readonly attribute ShadowRoot? shadowRoot;
};

View file

@ -5,7 +5,7 @@
// https://w3c.github.io/ServiceWorker/#extendable-event
[Exposed=ServiceWorker,
Pref="dom.serviceworker.enabled"]
Pref="dom_serviceworker_enabled"]
interface ExtendableEvent : Event {
[Throws] constructor(DOMString type,
optional ExtendableEventInit eventInitDict = {});

View file

@ -5,7 +5,7 @@
// https://w3c.github.io/ServiceWorker/#extendablemessage-event-section
[Exposed=ServiceWorker,
Pref="dom.serviceworker.enabled"]
Pref="dom_serviceworker_enabled"]
interface ExtendableMessageEvent : ExtendableEvent {
[Throws] constructor(DOMString type, optional ExtendableMessageEventInit eventInitDict = {});
readonly attribute any data;

View file

@ -6,7 +6,7 @@
// https://github.com/immersive-web/webxr-test-api/
[Exposed=Window, Pref="dom.webxr.test"]
[Exposed=Window, Pref="dom_webxr_test"]
interface FakeXRDevice {
// Sets the values to be used for subsequent requestAnimationFrame() callbacks.
[Throws] undefined setViews(sequence<FakeXRViewInit> views, optional sequence<FakeXRViewInit> secondaryViews);

View file

@ -6,7 +6,7 @@
// https://immersive-web.github.io/webxr-test-api/#fakexrinputcontroller
[Exposed=Window, Pref="dom.webxr.test"]
[Exposed=Window, Pref="dom_webxr_test"]
interface FakeXRInputController {
undefined setHandedness(XRHandedness handedness);
undefined setTargetRayMode(XRTargetRayMode targetRayMode);

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://html.spec.whatwg.org/multipage/#htmlcanvaselement
[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
[Exposed=(Window, DedicatedWorker), Pref="dom_webgpu_enabled"]
interface GPUCanvasContext {
readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas;
};

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/gamepad/#gamepad-interface
[Exposed=Window, Pref="dom.gamepad.enabled"]
[Exposed=Window, Pref="dom_gamepad_enabled"]
interface Gamepad {
readonly attribute DOMString id;
readonly attribute long index;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/gamepad/#gamepadbutton-interface
[Exposed=Window, Pref="dom.gamepad.enabled"]
[Exposed=Window, Pref="dom_gamepad_enabled"]
interface GamepadButton {
readonly attribute boolean pressed;
readonly attribute boolean touched;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/gamepad/#dom-gamepad-buttons
[Exposed=Window, Pref="dom.gamepad.enabled"]
[Exposed=Window, Pref="dom_gamepad_enabled"]
interface GamepadButtonList {
getter GamepadButton? item(unsigned long index);
readonly attribute unsigned long length;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/gamepad/#gamepadevent-interface
[Exposed=Window, Pref="dom.gamepad.enabled"]
[Exposed=Window, Pref="dom_gamepad_enabled"]
interface GamepadEvent : Event {
[Throws] constructor(DOMString type, GamepadEventInit eventInitDict);
readonly attribute Gamepad gamepad;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/gamepad/#gamepadhapticactuator-interface
[Exposed=Window, Pref="dom.gamepad.enabled"]
[Exposed=Window, Pref="dom_gamepad_enabled"]
interface GamepadHapticActuator {
/* [SameObject] */ readonly attribute /* FrozenArray<GamepadHapticEffectType> */ any effects;
[NewObject]

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/gamepad/extensions.html#gamepadpose-interface
[Exposed=Window, Pref="dom.gamepad.enabled"]
[Exposed=Window, Pref="dom_gamepad_enabled"]
interface GamepadPose {
readonly attribute boolean hasOrientation;
readonly attribute boolean hasPosition;

View file

@ -29,7 +29,7 @@ interface HTMLCanvasElement : HTMLElement {
};
partial interface HTMLCanvasElement {
[Pref="dom.canvas_capture.enabled"]
[Pref="dom_canvas_capture_enabled"]
MediaStream captureStream (optional double frameRequestRate);
};

View file

@ -24,9 +24,9 @@ interface HTMLElement : Element {
// attribute DOMString itemId;
//readonly attribute HTMLPropertiesCollection properties;
// attribute any itemValue; // acts as DOMString on setting
[Pref="dom.microdata.testing.enabled"]
[Pref="dom_microdata_testing_enabled"]
sequence<DOMString>? propertyNames();
[Pref="dom.microdata.testing.enabled"]
[Pref="dom_microdata_testing_enabled"]
sequence<DOMString>? itemtypes();
// user interaction

View file

@ -109,7 +109,7 @@ interface HTMLInputElement : HTMLElement {
// also has obsolete members
// Select with file-system paths for testing purpose
[Pref="dom.testing.htmlinputelement.select_files.enabled"]
[Pref="dom_testing_html_input_element_select_files_enabled"]
undefined selectFiles(sequence<DOMString> path);
};

View file

@ -17,6 +17,6 @@ interface HTMLVideoElement : HTMLMediaElement {
};
partial interface HTMLVideoElement {
[Pref="media.testing.enabled"]
[Pref="media_testing_enabled"]
attribute EventHandler onpostershown;
};

View file

@ -10,7 +10,7 @@
*/
//[Exposed=(Window,Worker), Serializable, Transferable]
[Exposed=(Window,Worker), Pref="dom.imagebitmap.enabled"]
[Exposed=(Window,Worker), Pref="dom_imagebitmap_enabled"]
interface ImageBitmap {
readonly attribute unsigned long width;
readonly attribute unsigned long height;

View file

@ -16,7 +16,7 @@ dictionary IntersectionObserverInit {
boolean trackVisibility = false;
};
[Pref="dom.intersection_observer.enabled", Exposed=(Window)]
[Pref="dom_intersection_observer_enabled", Exposed=(Window)]
interface IntersectionObserver {
constructor(IntersectionObserverCallback callback, optional IntersectionObserverInit options = {});
readonly attribute (Element or Document)? root;

View file

@ -4,7 +4,7 @@
// https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
[Pref="dom.intersection_observer.enabled", Exposed=(Window)]
[Pref="dom_intersection_observer_enabled", Exposed=(Window)]
interface IntersectionObserverEntry {
constructor(IntersectionObserverEntryInit intersectionObserverEntryInit);
readonly attribute DOMHighResTimeStamp time;

View file

@ -5,7 +5,7 @@
// https://w3c.github.io/mediacapture-main/#device-info
[Exposed=Window,
SecureContext, Pref="dom.webrtc.enabled"]
SecureContext, Pref="dom_webrtc_enabled"]
interface MediaDeviceInfo {
readonly attribute DOMString deviceId;
readonly attribute MediaDeviceKind kind;

View file

@ -5,7 +5,7 @@
// https://w3c.github.io/mediacapture-main/#dom-mediadevices
[Exposed=Window,
SecureContext, Pref="dom.webrtc.enabled"]
SecureContext, Pref="dom_webrtc_enabled"]
interface MediaDevices : EventTarget {
// attribute EventHandler ondevicechange;
Promise<sequence<MediaDeviceInfo>> enumerateDevices();
@ -13,7 +13,7 @@ interface MediaDevices : EventTarget {
partial interface Navigator {
// [SameObject, SecureContext]
[Pref="dom.webrtc.enabled"] readonly attribute MediaDevices mediaDevices;
[Pref="dom_webrtc_enabled"] readonly attribute MediaDevices mediaDevices;
};
partial interface MediaDevices {

View file

@ -26,7 +26,7 @@ interface MouseEvent : UIEvent {
readonly attribute unsigned short buttons;
//boolean getModifierState (DOMString keyArg);
[Pref="dom.mouseevent.which.enabled"]
[Pref="dom_mouse_event_which_enabled"]
readonly attribute long which;
};

View file

@ -7,7 +7,7 @@
*/
// https://dom.spec.whatwg.org/#mutationobserver
[Exposed=Window, Pref="dom.mutation_observer.enabled"]
[Exposed=Window, Pref="dom_mutation_observer_enabled"]
interface MutationObserver {
[Throws] constructor(MutationCallback callback);
[Throws]

View file

@ -7,7 +7,7 @@
*/
// https://dom.spec.whatwg.org/#mutationrecord
[Pref="dom.mutation_observer.enabled", Exposed=Window]
[Pref="dom_mutation_observer_enabled", Exposed=Window]
interface MutationRecord {
readonly attribute DOMString type;
[SameObject]

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/ServiceWorker/#navigation-preload-manager
[Pref="dom.serviceworker.enabled", SecureContext, Exposed=(Window,Worker)]
[Pref="dom_serviceworker_enabled", SecureContext, Exposed=(Window,Worker)]
interface NavigationPreloadManager {
Promise<undefined> enable();
Promise<undefined> disable();

View file

@ -33,12 +33,12 @@ interface mixin NavigatorID {
// https://webbluetoothcg.github.io/web-bluetooth/#navigator-extensions
partial interface Navigator {
[SameObject, Pref="dom.bluetooth.enabled"] readonly attribute Bluetooth bluetooth;
[SameObject, Pref="dom_bluetooth_enabled"] readonly attribute Bluetooth bluetooth;
};
// https://w3c.github.io/ServiceWorker/#navigator-service-worker
partial interface Navigator {
[SameObject, Pref="dom.serviceworker.enabled"] readonly attribute ServiceWorkerContainer serviceWorker;
[SameObject, Pref="dom_serviceworker_enabled"] readonly attribute ServiceWorkerContainer serviceWorker;
};
// https://html.spec.whatwg.org/multipage/#navigatorlanguage
@ -63,12 +63,12 @@ interface mixin NavigatorCookies {
// https://w3c.github.io/permissions/#navigator-and-workernavigator-extension
[Exposed=(Window)]
partial interface Navigator {
[Pref="dom.permissions.enabled"] readonly attribute Permissions permissions;
[Pref="dom_permissions_enabled"] readonly attribute Permissions permissions;
};
// https://w3c.github.io/gamepad/#navigator-interface-extension
partial interface Navigator {
[Pref="dom.gamepad.enabled"] sequence<Gamepad?> getGamepads();
[Pref="dom_gamepad_enabled"] sequence<Gamepad?> getGamepads();
};
// https://html.spec.whatwg.org/multipage/#navigatorconcurrenthardware

View file

@ -13,7 +13,7 @@ dictionary ImageEncodeOptions {
//enum OffscreenRenderingContextId { "2d", "webgl", "webgl2" };
[Exposed=(Window,Worker)/*, Transferable*/, Pref="dom.offscreen_canvas.enabled"]
[Exposed=(Window,Worker)/*, Transferable*/, Pref="dom_offscreen_canvas_enabled"]
interface OffscreenCanvas : EventTarget {
[Throws] constructor([EnforceRange] unsigned long long width, [EnforceRange] unsigned long long height);
attribute [EnforceRange] unsigned long long width;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://html.spec.whatwg.org/multipage/#the-offscreen-2d-rendering-context
[Exposed=(Window,Worker), Pref="dom.offscreen_canvas.enabled"]
[Exposed=(Window,Worker), Pref="dom_offscreen_canvas_enabled"]
interface OffscreenCanvasRenderingContext2D {
//void commit();
readonly attribute OffscreenCanvas canvas;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://drafts.css-houdini.org/css-paint-api/#paintrenderingcontext2d
[Pref="dom.worklet.enabled", Exposed=PaintWorklet]
[Pref="dom_worklet_enabled", Exposed=PaintWorklet]
interface PaintRenderingContext2D {
};
PaintRenderingContext2D includes CanvasState;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://drafts.css-houdini.org/css-paint-api/#paintsize
[Pref="dom.worklet.enabled", Exposed=PaintWorklet]
[Pref="dom_worklet_enabled", Exposed=PaintWorklet]
interface PaintSize {
readonly attribute double width;
readonly attribute double height;

View file

@ -3,11 +3,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://drafts.css-houdini.org/css-paint-api/#paintworkletglobalscope
[Global=(Worklet,PaintWorklet), Pref="dom.worklet.enabled", Exposed=PaintWorklet]
[Global=(Worklet,PaintWorklet), Pref="dom_worklet_enabled", Exposed=PaintWorklet]
interface PaintWorkletGlobalScope : WorkletGlobalScope {
[Throws] undefined registerPaint(DOMString name, VoidFunction paintCtor);
// This function is to be used only for testing, and should not be
// accessible outside of that use.
[Pref="dom.worklet.blockingsleep.enabled"]
[Pref="dom_worklet_blockingsleep_enabled"]
undefined sleep(unsigned long long ms);
};

View file

@ -27,6 +27,6 @@ interface PerformanceNavigationTiming : PerformanceResourceTiming {
readonly attribute unsigned short redirectCount;
[Default] object toJSON();
/* Servo-only attribute for measuring when the top-level document (not iframes) is complete. */
[Pref="dom.testperf.enabled"]
[Pref="dom_testperf_enabled"]
readonly attribute DOMHighResTimeStamp topLevelDomComplete;
};

View file

@ -28,7 +28,7 @@ enum PermissionName {
"persistent-storage",
};
[Pref="dom.permissions.enabled", Exposed=(Window,Worker)]
[Pref="dom_permissions_enabled", Exposed=(Window,Worker)]
interface PermissionStatus : EventTarget {
readonly attribute PermissionState state;
attribute EventHandler onchange;

View file

@ -4,7 +4,7 @@
// https://w3c.github.io/permissions/#permissions-interface
[Pref="dom.permissions.enabled", Exposed=(Window,Worker)]
[Pref="dom_permissions_enabled", Exposed=(Window,Worker)]
interface Permissions {
Promise<PermissionStatus> query(object permissionDesc);

View file

@ -4,7 +4,7 @@
// https://w3c.github.io/webrtc-pc/#dom-rtcdatachannel
[Exposed=Window, Pref="dom.webrtc.enabled"]
[Exposed=Window, Pref="dom_webrtc_enabled"]
interface RTCDataChannel : EventTarget {
readonly attribute USVString label;
readonly attribute boolean ordered;

Some files were not shown because too many files have changed in this diff Show more