Update prefs API to return an Option<bool>.

This allows for situations where there is no reasonable default
to apply for the pref value e.g. when we are just listing values
This commit is contained in:
James Graham 2015-09-04 15:21:35 +01:00
parent cc1eb3f741
commit a208379f46
7 changed files with 12 additions and 12 deletions

View file

@ -891,7 +891,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
containing_pipeline_id: PipelineId, containing_pipeline_id: PipelineId,
subpage_id: SubpageId, subpage_id: SubpageId,
event: MozBrowserEvent) { event: MozBrowserEvent) {
assert!(prefs::get_pref("dom.mozbrowser.enabled", false)); assert!(prefs::get_pref("dom.mozbrowser.enabled").unwrap_or(false));
// Find the script channel for the given parent pipeline, // Find the script channel for the given parent pipeline,
// and pass the event to that script task. // and pass the event to that script task.
@ -1373,7 +1373,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserlocationchange // https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserlocationchange
fn trigger_mozbrowserlocationchange(&self, pipeline_id: PipelineId) { fn trigger_mozbrowserlocationchange(&self, pipeline_id: PipelineId) {
if prefs::get_pref("dom.mozbrowser.enabled", false) { if prefs::get_pref("dom.mozbrowser.enabled").unwrap_or(false) {
// Work around borrow checker // Work around borrow checker
let event_info = { let event_info = {
let pipeline = self.pipeline(pipeline_id); let pipeline = self.pipeline(pipeline_id);

View file

@ -269,7 +269,7 @@ impl Pipeline {
pub fn trigger_mozbrowser_event(&self, pub fn trigger_mozbrowser_event(&self,
subpage_id: SubpageId, subpage_id: SubpageId,
event: MozBrowserEvent) { event: MozBrowserEvent) {
assert!(prefs::get_pref("dom.mozbrowser.enabled", false)); assert!(prefs::get_pref("dom.mozbrowser.enabled").unwrap_or(false));
let event = ConstellationControlMsg::MozBrowserEvent(self.id, let event = ConstellationControlMsg::MozBrowserEvent(self.id,
subpage_id, subpage_id,

View file

@ -42,7 +42,7 @@ use url::{Url, UrlParser};
use util::str::{self, LengthOrPercentageOrAuto}; use util::str::{self, LengthOrPercentageOrAuto};
pub fn mozbrowser_enabled() -> bool { pub fn mozbrowser_enabled() -> bool {
prefs::get_pref("dom.mozbrowser.enabled", false) prefs::get_pref("dom.mozbrowser.enabled").unwrap_or(false)
} }
#[derive(HeapSizeOf)] #[derive(HeapSizeOf)]

View file

@ -171,7 +171,7 @@ impl MouseEventMethods for MouseEvent {
// This returns the same result as current gecko. // This returns the same result as current gecko.
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
fn Which(&self) -> i32 { fn Which(&self) -> i32 {
if prefs::get_pref("dom.mouseevent.which.enabled", false) { if prefs::get_pref("dom.mouseevent.which.enabled").unwrap_or(false) {
(self.button.get() + 1) as i32 (self.button.get() + 1) as i32
} else { } else {
0 0

View file

@ -494,7 +494,7 @@ pub mod longhands {
% for value in values[:-1]: % for value in values[:-1]:
"${value}" => { "${value}" => {
% if value in experimental_values: % if value in experimental_values:
if !::util::prefs::get_pref("layout.${value}.enabled", false) { if !::util::prefs::get_pref("layout.${value}.enabled").unwrap_or(false) {
return Err(()) return Err(())
} }
% endif % endif
@ -504,7 +504,7 @@ pub mod longhands {
% for value in values[-1:]: % for value in values[-1:]:
"${value}" => { "${value}" => {
% if value in experimental_values: % if value in experimental_values:
if !::util::prefs::get_pref("layout.${value}.enabled", false) { if !::util::prefs::get_pref("layout.${value}.enabled".unwrap_or(false) {
return Err(()) return Err(())
} }
% endif % endif
@ -5796,7 +5796,7 @@ impl PropertyDeclaration {
% if property.derived_from is None: % if property.derived_from is None:
"${property.name}" => { "${property.name}" => {
% if property.experimental: % if property.experimental:
if !::util::prefs::get_pref("${property.experimental}", false) { if !::util::prefs::get_pref("${property.experimental}").unwrap_or(false) {
return PropertyDeclarationParseResult::ExperimentalProperty return PropertyDeclarationParseResult::ExperimentalProperty
} }
% endif % endif
@ -5815,7 +5815,7 @@ impl PropertyDeclaration {
% for shorthand in SHORTHANDS: % for shorthand in SHORTHANDS:
"${shorthand.name}" => { "${shorthand.name}" => {
% if shorthand.experimental: % if shorthand.experimental:
if !::util::prefs::get_pref("${shorthand.experimental}", false) { if !::util::prefs::get_pref("${shorthand.experimental}").unwrap_or(false) {
return PropertyDeclarationParseResult::ExperimentalProperty return PropertyDeclarationParseResult::ExperimentalProperty
} }
% endif % endif

View file

@ -429,7 +429,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace)) Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
}, },
"viewport" => { "viewport" => {
if ::util::prefs::get_pref("layout.viewport.enabled", false) { if ::util::prefs::get_pref("layout.viewport.enabled").unwrap_or(false) {
Ok(AtRuleType::WithBlock(AtRulePrelude::Viewport)) Ok(AtRuleType::WithBlock(AtRulePrelude::Viewport))
} else { } else {
Err(()) Err(())

View file

@ -41,8 +41,8 @@ fn read_prefs() -> Result<HashMap<String, bool>, ()> {
Ok(prefs) Ok(prefs)
} }
pub fn get_pref(name: &str, default: bool) -> bool { pub fn get_pref(name: &str) -> Option<bool> {
*PREFS.lock().unwrap().get(name).unwrap_or(&default) PREFS.lock().unwrap().get(name).cloned()
} }
pub fn set_pref(name: &str, value: bool) { pub fn set_pref(name: &str, value: bool) {