mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Allow resetting options
This commit is contained in:
parent
2b410acbf9
commit
c97f068efa
2 changed files with 10 additions and 30 deletions
|
@ -19,6 +19,7 @@ use std::io::{self, Read, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
|
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
|
||||||
|
use std::sync::{RwLock, RwLockReadGuard};
|
||||||
use url::{self, Url};
|
use url::{self, Url};
|
||||||
|
|
||||||
/// Global flags for Servo, currently set on the command line.
|
/// Global flags for Servo, currently set on the command line.
|
||||||
|
@ -1049,7 +1050,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
|
||||||
clean_shutdown: opt_match.opt_present("clean-shutdown"),
|
clean_shutdown: opt_match.opt_present("clean-shutdown"),
|
||||||
};
|
};
|
||||||
|
|
||||||
set_defaults(opts);
|
set_options(opts);
|
||||||
|
|
||||||
// These must happen after setting the default options, since the prefs rely on
|
// These must happen after setting the default options, since the prefs rely on
|
||||||
// on the resource path.
|
// on the resource path.
|
||||||
|
@ -1084,34 +1085,18 @@ pub enum ArgumentParsingResult {
|
||||||
// Make Opts available globally. This saves having to clone and pass
|
// Make Opts available globally. This saves having to clone and pass
|
||||||
// opts everywhere it is used, which gets particularly cumbersome
|
// opts everywhere it is used, which gets particularly cumbersome
|
||||||
// when passing through the DOM structures.
|
// when passing through the DOM structures.
|
||||||
static mut DEFAULT_OPTIONS: *mut Opts = 0 as *mut Opts;
|
|
||||||
const INVALID_OPTIONS: *mut Opts = 0x01 as *mut Opts;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref OPTIONS: Opts = {
|
static ref OPTIONS: RwLock<Opts> = RwLock::new(default_opts());
|
||||||
unsafe {
|
|
||||||
let initial = if !DEFAULT_OPTIONS.is_null() {
|
|
||||||
let opts = Box::from_raw(DEFAULT_OPTIONS);
|
|
||||||
*opts
|
|
||||||
} else {
|
|
||||||
default_opts()
|
|
||||||
};
|
|
||||||
DEFAULT_OPTIONS = INVALID_OPTIONS;
|
|
||||||
initial
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_defaults(opts: Opts) {
|
pub fn set_options(opts: Opts) {
|
||||||
// Set the static to the new default value.
|
|
||||||
MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst);
|
MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst);
|
||||||
|
*OPTIONS.write().unwrap() = opts;
|
||||||
|
}
|
||||||
|
|
||||||
unsafe {
|
#[inline]
|
||||||
assert!(DEFAULT_OPTIONS.is_null());
|
pub fn get() -> RwLockReadGuard<'static, Opts> {
|
||||||
assert_ne!(DEFAULT_OPTIONS, INVALID_OPTIONS);
|
OPTIONS.read().unwrap()
|
||||||
let box_opts = Box::new(opts);
|
|
||||||
DEFAULT_OPTIONS = Box::into_raw(box_opts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_pref_from_command_line(pref: &str) {
|
pub fn parse_pref_from_command_line(pref: &str) {
|
||||||
|
@ -1128,11 +1113,6 @@ pub fn parse_pref_from_command_line(pref: &str) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get() -> &'static Opts {
|
|
||||||
&OPTIONS
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<ServoUrl, ()> {
|
pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<ServoUrl, ()> {
|
||||||
match ServoUrl::parse(input) {
|
match ServoUrl::parse(input) {
|
||||||
Ok(url) => Ok(url),
|
Ok(url) => Ok(url),
|
||||||
|
|
|
@ -631,7 +631,7 @@ pub fn run_content_process(token: String) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let unprivileged_content = unprivileged_content_receiver.recv().unwrap();
|
let unprivileged_content = unprivileged_content_receiver.recv().unwrap();
|
||||||
opts::set_defaults(unprivileged_content.opts());
|
opts::set_options(unprivileged_content.opts());
|
||||||
PREFS.extend(unprivileged_content.prefs());
|
PREFS.extend(unprivileged_content.prefs());
|
||||||
set_logger(unprivileged_content.script_to_constellation_chan().clone());
|
set_logger(unprivileged_content.script_to_constellation_chan().clone());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue