mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Refactor util::prefs
operations to be methods on static struct.
This commit is contained in:
parent
307844a8c1
commit
22928f50ac
30 changed files with 166 additions and 162 deletions
|
@ -2250,7 +2250,7 @@ class CGConstructorEnabled(CGAbstractMethod):
|
|||
pref = iface.getExtendedAttribute("Pref")
|
||||
if pref:
|
||||
assert isinstance(pref, list) and len(pref) == 1
|
||||
conditions.append('prefs::get_pref("%s").as_boolean().unwrap_or(false)' % pref[0])
|
||||
conditions.append('PREFS.get("%s").as_boolean().unwrap_or(false)' % pref[0])
|
||||
func = iface.getExtendedAttribute("Func")
|
||||
if func:
|
||||
assert isinstance(func, list) and len(func) == 1
|
||||
|
@ -5605,7 +5605,7 @@ class CGBindingRoot(CGThing):
|
|||
'dom::browsingcontext::BrowsingContext',
|
||||
'mem::heap_size_of_raw_self_and_children',
|
||||
'libc',
|
||||
'util::prefs',
|
||||
'util::prefs::PREFS',
|
||||
'script_runtime::{store_panic_result, maybe_take_panic_result}',
|
||||
'std::borrow::ToOwned',
|
||||
'std::cmp',
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! Machinery to conditionally expose things.
|
||||
|
||||
use js::jsapi::{HandleObject, JSContext};
|
||||
use util::prefs::get_pref;
|
||||
use util::prefs::PREFS;
|
||||
|
||||
/// A container with a condition.
|
||||
pub struct Guard<T: Clone + Copy> {
|
||||
|
@ -47,7 +47,7 @@ pub enum Condition {
|
|||
impl Condition {
|
||||
unsafe fn is_satisfied(&self, cx: *mut JSContext, obj: HandleObject) -> bool {
|
||||
match *self {
|
||||
Condition::Pref(name) => get_pref(name).as_boolean().unwrap_or(false),
|
||||
Condition::Pref(name) => PREFS.get(name).as_boolean().unwrap_or(false),
|
||||
Condition::Func(f) => f(cx, obj),
|
||||
Condition::Satisfied => true,
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ use style::servo::Stylesheet;
|
|||
use time;
|
||||
use url::Url;
|
||||
use url::percent_encoding::percent_decode;
|
||||
use util::prefs::mozbrowser_enabled;
|
||||
use util::prefs::PREFS;
|
||||
use util::str::{split_html_space_chars, str_join};
|
||||
|
||||
#[derive(JSTraceable, PartialEq, HeapSizeOf)]
|
||||
|
@ -1262,7 +1262,7 @@ impl Document {
|
|||
}
|
||||
|
||||
pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) {
|
||||
if mozbrowser_enabled() {
|
||||
if PREFS.is_mozbrowser_enabled() {
|
||||
if let Some((containing_pipeline_id, subpage_id, _)) = self.window.parent_info() {
|
||||
let event = ConstellationMsg::MozBrowserEvent(containing_pipeline_id,
|
||||
subpage_id,
|
||||
|
|
|
@ -29,7 +29,7 @@ use std::default::Default;
|
|||
use string_cache::Atom;
|
||||
use style::attr::AttrValue;
|
||||
use url::Url;
|
||||
use util::prefs::mozbrowser_enabled;
|
||||
use util::prefs::PREFS;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLAnchorElement {
|
||||
|
@ -575,7 +575,7 @@ fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>) {
|
|||
|
||||
// Step 8: navigate to the URL.
|
||||
if let Some(target) = target {
|
||||
if mozbrowser_enabled() && !is_current_browsing_context(target.Value()) {
|
||||
if PREFS.is_mozbrowser_enabled() && !is_current_browsing_context(target.Value()) {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowseropenwindow
|
||||
// TODO: referrer and opener
|
||||
// TODO: should we send the normalized url or the non-normalized href?
|
||||
|
|
|
@ -48,7 +48,7 @@ use string_cache::Atom;
|
|||
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
|
||||
use style::context::ReflowGoal;
|
||||
use url::Url;
|
||||
use util::prefs::mozbrowser_enabled;
|
||||
use util::prefs::PREFS;
|
||||
use util::servo_version;
|
||||
|
||||
bitflags! {
|
||||
|
@ -145,7 +145,7 @@ impl HTMLIFrameElement {
|
|||
.send(ConstellationMsg::ScriptLoadedURLInIFrame(load_info))
|
||||
.unwrap();
|
||||
|
||||
if mozbrowser_enabled() {
|
||||
if PREFS.is_mozbrowser_enabled() {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserloadstart
|
||||
self.dispatch_mozbrowser_event(MozBrowserEvent::LoadStart);
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ impl HTMLIFrameElement {
|
|||
// TODO(gw): Support mozbrowser event types that have detail which is not a string.
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API
|
||||
// for a list of mozbrowser events.
|
||||
assert!(mozbrowser_enabled());
|
||||
assert!(PREFS.is_mozbrowser_enabled());
|
||||
|
||||
if self.Mozbrowser() {
|
||||
let window = window_from_node(self);
|
||||
|
|
|
@ -70,7 +70,7 @@ impl HTMLMetaElement {
|
|||
}
|
||||
|
||||
fn apply_viewport(&self) {
|
||||
if !::util::prefs::get_pref("layout.viewport.enabled").as_boolean().unwrap_or(false) {
|
||||
if !::util::prefs::PREFS.get("layout.viewport.enabled").as_boolean().unwrap_or(false) {
|
||||
return;
|
||||
}
|
||||
let element = self.upcast::<Element>();
|
||||
|
|
|
@ -17,7 +17,7 @@ use dom::uievent::UIEvent;
|
|||
use dom::window::Window;
|
||||
use std::cell::Cell;
|
||||
use std::default::Default;
|
||||
use util::prefs;
|
||||
use util::prefs::PREFS;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct MouseEvent {
|
||||
|
@ -157,7 +157,7 @@ impl MouseEventMethods 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 prefs::get_pref("dom.mouseevent.which.enabled").as_boolean().unwrap_or(false) {
|
||||
if PREFS.get("dom.mouseevent.which.enabled").as_boolean().unwrap_or(false) {
|
||||
(self.button.get() + 1) as i32
|
||||
} else {
|
||||
0
|
||||
|
|
|
@ -37,7 +37,7 @@ use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
use url::Url;
|
||||
use util::prefs;
|
||||
use util::prefs::PREFS;
|
||||
use util::thread::spawn_named;
|
||||
use util::thread_state;
|
||||
use util::thread_state::{IN_WORKER, SCRIPT};
|
||||
|
@ -225,7 +225,7 @@ impl ServiceWorkerGlobalScope {
|
|||
scope.mem_profiler_chan().run_with_memory_reporting(|| {
|
||||
// Service workers are time limited
|
||||
let sw_lifetime = Instant::now();
|
||||
let sw_lifetime_timeout = prefs::get_pref("dom.serviceworker.timeout_seconds").as_u64().unwrap();
|
||||
let sw_lifetime_timeout = PREFS.get("dom.serviceworker.timeout_seconds").as_u64().unwrap();
|
||||
while let Ok(event) = global.receive_event() {
|
||||
if scope.is_closing() {
|
||||
break;
|
||||
|
|
|
@ -29,7 +29,7 @@ use js::jsval::{JSVal, NullValue};
|
|||
use std::borrow::ToOwned;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use util::prefs::get_pref;
|
||||
use util::prefs::PREFS;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct TestBinding {
|
||||
|
@ -558,10 +558,10 @@ impl TestBindingMethods for TestBinding {
|
|||
fn PassVariadicAny(&self, _: *mut JSContext, _: Vec<HandleValue>) {}
|
||||
fn PassVariadicObject(&self, _: *mut JSContext, _: Vec<*mut JSObject>) {}
|
||||
fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
|
||||
get_pref(pref_name.as_ref()).as_boolean().unwrap_or(false)
|
||||
PREFS.get(pref_name.as_ref()).as_boolean().unwrap_or(false)
|
||||
}
|
||||
fn StringMozPreference(&self, pref_name: DOMString) -> DOMString {
|
||||
get_pref(pref_name.as_ref()).as_string().map(|s| DOMString::from(s)).unwrap_or_else(|| DOMString::new())
|
||||
PREFS.get(pref_name.as_ref()).as_string().map(|s| DOMString::from(s)).unwrap_or_else(|| DOMString::new())
|
||||
}
|
||||
fn PrefControlledAttributeDisabled(&self) -> bool { false }
|
||||
fn PrefControlledAttributeEnabled(&self) -> bool { false }
|
||||
|
|
|
@ -96,7 +96,7 @@ use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle, OneshotTimers
|
|||
use tinyfiledialogs::{self, MessageBoxIcon};
|
||||
use url::Url;
|
||||
use util::geometry::{self, MAX_RECT};
|
||||
use util::prefs::mozbrowser_enabled;
|
||||
use util::prefs::PREFS;
|
||||
use util::str::HTML_SPACE_CHARACTERS;
|
||||
use util::{breakpoint, opts};
|
||||
use webdriver_handlers::jsval_to_webdriver;
|
||||
|
@ -1581,7 +1581,7 @@ impl Window {
|
|||
|
||||
/// Returns whether this window is mozbrowser.
|
||||
pub fn is_mozbrowser(&self) -> bool {
|
||||
mozbrowser_enabled() && self.parent_info().is_none()
|
||||
PREFS.is_mozbrowser_enabled() && self.parent_info().is_none()
|
||||
}
|
||||
|
||||
/// Returns whether mozbrowser is enabled and `obj` has been created
|
||||
|
@ -1757,4 +1757,3 @@ fn debug_reflow_events(id: PipelineId, goal: &ReflowGoal, query_type: &ReflowQue
|
|||
|
||||
println!("{}", debug_msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ use string_cache::Atom;
|
|||
use time;
|
||||
use timers::{OneshotTimerCallback, OneshotTimerHandle};
|
||||
use url::{Url, Position};
|
||||
use util::prefs::mozbrowser_enabled;
|
||||
use util::prefs::PREFS;
|
||||
|
||||
#[derive(JSTraceable, PartialEq, Copy, Clone, HeapSizeOf)]
|
||||
enum XMLHttpRequestState {
|
||||
|
@ -581,8 +581,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
// story. See https://github.com/servo/servo/issues/9582
|
||||
if let GlobalRoot::Window(win) = self.global() {
|
||||
let is_root_pipeline = win.parent_info().is_none();
|
||||
let is_mozbrowser_enabled = mozbrowser_enabled();
|
||||
is_root_pipeline && is_mozbrowser_enabled
|
||||
is_root_pipeline && PREFS.is_mozbrowser_enabled()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue