aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-07-03 08:19:04 -0700
committerGitHub <noreply@github.com>2016-07-03 08:19:04 -0700
commitb0a8ce5341f5148e36523fee0b0fcbc2684c0a68 (patch)
treef7c3746dbfa55e7ba5d863a921b7a89211974858 /components/script/dom
parenta9c58c99fb897f95f37d893ecb3994864ef58da9 (diff)
parentd9c9d4ab369c09dae378cb886b9dc7409f114c8f (diff)
downloadservo-b0a8ce5341f5148e36523fee0b0fcbc2684c0a68.tar.gz
servo-b0a8ce5341f5148e36523fee0b0fcbc2684c0a68.zip
Auto merge of #12178 - frewsxcv:prefs, r=emilio
Refactor `util::prefs` operations to be methods on static struct. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12178) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py4
-rw-r--r--components/script/dom/bindings/guard.rs4
-rw-r--r--components/script/dom/document.rs4
-rw-r--r--components/script/dom/htmlanchorelement.rs4
-rw-r--r--components/script/dom/htmliframeelement.rs6
-rw-r--r--components/script/dom/htmlmetaelement.rs2
-rw-r--r--components/script/dom/mouseevent.rs4
-rw-r--r--components/script/dom/serviceworkerglobalscope.rs4
-rw-r--r--components/script/dom/testbinding.rs6
-rw-r--r--components/script/dom/window.rs5
-rw-r--r--components/script/dom/xmlhttprequest.rs5
11 files changed, 23 insertions, 25 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 76aab6b9b53..ac53221cb8a 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -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',
diff --git a/components/script/dom/bindings/guard.rs b/components/script/dom/bindings/guard.rs
index 40faebbd4f2..114045a62e8 100644
--- a/components/script/dom/bindings/guard.rs
+++ b/components/script/dom/bindings/guard.rs
@@ -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,
}
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 23c50075068..4b4805695da 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -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,
diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs
index 161a7d43eaf..713aa0a92cb 100644
--- a/components/script/dom/htmlanchorelement.rs
+++ b/components/script/dom/htmlanchorelement.rs
@@ -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?
diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs
index 2c71488c5dc..f1f3c0e29de 100644
--- a/components/script/dom/htmliframeelement.rs
+++ b/components/script/dom/htmliframeelement.rs
@@ -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);
diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs
index 160b4a9c68e..3a289b6c1bc 100644
--- a/components/script/dom/htmlmetaelement.rs
+++ b/components/script/dom/htmlmetaelement.rs
@@ -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>();
diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs
index d6b5316f2d2..78b1a33005f 100644
--- a/components/script/dom/mouseevent.rs
+++ b/components/script/dom/mouseevent.rs
@@ -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
diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs
index 4039be05403..6f395863f2f 100644
--- a/components/script/dom/serviceworkerglobalscope.rs
+++ b/components/script/dom/serviceworkerglobalscope.rs
@@ -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;
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index 8cd53ee57fb..ffe8afc0b89 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -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 }
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index b58fc901316..6f012e9c31e 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -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);
}
-
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs
index af424fb83d7..7b51e76a37f 100644
--- a/components/script/dom/xmlhttprequest.rs
+++ b/components/script/dom/xmlhttprequest.rs
@@ -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
}