Bug 1252855 - make reader mode use AsyncPrefs, r=margaret

MozReview-Commit-ID: U6ZTyQQSHG

--HG--
extra : rebase_source : bf2aa2f40777611f2b89e9d2f57d2f4f2544f53b
This commit is contained in:
Gijs Kruitbosch 2016-03-15 20:40:14 +00:00
parent ecf49e7e77
commit 6be7372f93
6 changed files with 18 additions and 47 deletions

View file

@ -26,8 +26,6 @@ var ReaderParent = {
"Reader:ArticleGet", "Reader:ArticleGet",
"Reader:FaviconRequest", "Reader:FaviconRequest",
"Reader:UpdateReaderButton", "Reader:UpdateReaderButton",
"Reader:SetIntPref",
"Reader:SetCharPref",
], ],
init: function() { init: function() {
@ -76,18 +74,6 @@ var ReaderParent = {
this.updateReaderButton(browser); this.updateReaderButton(browser);
break; break;
} }
case "Reader:SetIntPref": {
if (message.data && message.data.name !== undefined) {
Services.prefs.setIntPref(message.data.name, message.data.value);
}
break;
}
case "Reader:SetCharPref": {
if (message.data && message.data.name !== undefined) {
Services.prefs.setCharPref(message.data.name, message.data.value);
}
break;
}
} }
}, },

View file

@ -152,18 +152,6 @@ var Reader = {
this.updatePageAction(tab); this.updatePageAction(tab);
break; break;
} }
case "Reader:SetIntPref": {
if (message.data && message.data.name !== undefined) {
Services.prefs.setIntPref(message.data.name, message.data.value);
}
break;
}
case "Reader:SetCharPref": {
if (message.data && message.data.name !== undefined) {
Services.prefs.setCharPref(message.data.name, message.data.value);
}
break;
}
} }
}, },

View file

@ -196,8 +196,6 @@ lazilyLoadedObserverScripts.forEach(function (aScript) {
["Reader:ToolbarHidden", false], ["Reader:ToolbarHidden", false],
["Reader:SystemUIVisibility", false], ["Reader:SystemUIVisibility", false],
["Reader:UpdateReaderButton", false], ["Reader:UpdateReaderButton", false],
["Reader:SetIntPref", false],
["Reader:SetCharPref", false],
], "chrome://browser/content/Reader.js"], ], "chrome://browser/content/Reader.js"],
].forEach(aScript => { ].forEach(aScript => {
let [name, messages, script] = aScript; let [name, messages, script] = aScript;

View file

@ -9,6 +9,7 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/narrate/VoiceSelect.jsm"); Cu.import("resource://gre/modules/narrate/VoiceSelect.jsm");
Cu.import("resource://gre/modules/narrate/Narrator.jsm"); Cu.import("resource://gre/modules/narrate/Narrator.jsm");
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AsyncPrefs.jsm");
this.EXPORTED_SYMBOLS = ["NarrateControls"]; this.EXPORTED_SYMBOLS = ["NarrateControls"];
@ -119,16 +120,14 @@ NarrateControls.prototype = {
_onRateInput: function(evt) { _onRateInput: function(evt) {
if (!this._rateMousedown) { if (!this._rateMousedown) {
this._mm.sendAsyncMessage("Reader:SetIntPref", AsyncPrefs.set("narrate.rate", parseInt(evt.target.value, 10));
{ name: "narrate.rate", value: evt.target.value });
this.narrator.setRate(this._convertRate(evt.target.value)); this.narrator.setRate(this._convertRate(evt.target.value));
} }
}, },
_onVoiceChange: function() { _onVoiceChange: function() {
let voice = this.voice; let voice = this.voice;
this._mm.sendAsyncMessage("Reader:SetCharPref", AsyncPrefs.set("narrate.voice", voice);
{ name: "narrate.voice", value: voice });
this.narrator.setVoice(voice); this.narrator.setVoice(voice);
}, },
@ -149,7 +148,7 @@ NarrateControls.prototype = {
this.narrator.start(options).then(() => { this.narrator.start(options).then(() => {
this._updateSpeechControls(false); this._updateSpeechControls(false);
}, err => { }, err => {
Cu.reportError(`Narrate failed: ${err}.`) Cu.reportError(`Narrate failed: ${err}.`);
this._updateSpeechControls(false); this._updateSpeechControls(false);
}); });
} }

View file

@ -12,10 +12,11 @@ Cu.import("resource://gre/modules/ReaderMode.jsm");
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AsyncPrefs", "resource://gre/modules/AsyncPrefs.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NarrateControls", "resource://gre/modules/narrate/NarrateControls.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Rect", "resource://gre/modules/Geometry.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Rect", "resource://gre/modules/Geometry.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry", "resource://gre/modules/UITelemetry.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry", "resource://gre/modules/UITelemetry.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NarrateControls", "resource://gre/modules/narrate/NarrateControls.jsm");
var gStrings = Services.strings.createBundle("chrome://global/locale/aboutReader.properties"); var gStrings = Services.strings.createBundle("chrome://global/locale/aboutReader.properties");
@ -269,11 +270,7 @@ AboutReader.prototype = {
this._fontSize = newFontSize; this._fontSize = newFontSize;
containerClasses.add("font-size" + this._fontSize); containerClasses.add("font-size" + this._fontSize);
return AsyncPrefs.set("reader.font_size", this._fontSize);
this._mm.sendAsyncMessage("Reader:SetIntPref", {
name: "reader.font_size",
value: this._fontSize
});
}, },
_setupFontSizeButtons: function() { _setupFontSizeButtons: function() {
@ -425,10 +422,7 @@ AboutReader.prototype = {
this._enableAmbientLighting(colorSchemePref === "auto"); this._enableAmbientLighting(colorSchemePref === "auto");
this._setColorScheme(colorSchemePref); this._setColorScheme(colorSchemePref);
this._mm.sendAsyncMessage("Reader:SetCharPref", { AsyncPrefs.set("reader.color_scheme", colorSchemePref);
name: "reader.color_scheme",
value: colorSchemePref
});
}, },
_setFontType: function(newFontType) { _setFontType: function(newFontType) {
@ -443,10 +437,7 @@ AboutReader.prototype = {
this._fontType = newFontType; this._fontType = newFontType;
bodyClasses.add(this._fontType); bodyClasses.add(this._fontType);
this._mm.sendAsyncMessage("Reader:SetCharPref", { AsyncPrefs.set("reader.font_type", this._fontType);
name: "reader.font_type",
value: this._fontType
});
}, },
_setSystemUIVisibility: function(visible) { _setSystemUIVisibility: function(visible) {

View file

@ -13,9 +13,18 @@ Cu.import("resource://gre/modules/Task.jsm");
const kInChildProcess = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT; const kInChildProcess = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
const kAllowedPrefs = new Set([ const kAllowedPrefs = new Set([
// NB: please leave the testing prefs at the top, and sort the rest alphabetically if you add
// anything.
"testing.allowed-prefs.some-bool-pref", "testing.allowed-prefs.some-bool-pref",
"testing.allowed-prefs.some-char-pref", "testing.allowed-prefs.some-char-pref",
"testing.allowed-prefs.some-int-pref", "testing.allowed-prefs.some-int-pref",
"narrate.rate",
"narrate.voice",
"reader.font_size",
"reader.font_type",
"reader.color_scheme",
]); ]);
const kPrefTypeMap = new Map([ const kPrefTypeMap = new Map([