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
Родитель ecf49e7e77
Коммит 6be7372f93
6 изменённых файлов: 18 добавлений и 47 удалений

Просмотреть файл

@ -26,8 +26,6 @@ var ReaderParent = {
"Reader:ArticleGet",
"Reader:FaviconRequest",
"Reader:UpdateReaderButton",
"Reader:SetIntPref",
"Reader:SetCharPref",
],
init: function() {
@ -76,18 +74,6 @@ var ReaderParent = {
this.updateReaderButton(browser);
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;
}
}
},

Просмотреть файл

@ -152,18 +152,6 @@ var Reader = {
this.updatePageAction(tab);
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;
}
}
},

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -12,10 +12,11 @@ Cu.import("resource://gre/modules/ReaderMode.jsm");
Cu.import("resource://gre/modules/Services.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, "Task", "resource://gre/modules/Task.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");
@ -269,11 +270,7 @@ AboutReader.prototype = {
this._fontSize = newFontSize;
containerClasses.add("font-size" + this._fontSize);
this._mm.sendAsyncMessage("Reader:SetIntPref", {
name: "reader.font_size",
value: this._fontSize
});
return AsyncPrefs.set("reader.font_size", this._fontSize);
},
_setupFontSizeButtons: function() {
@ -425,10 +422,7 @@ AboutReader.prototype = {
this._enableAmbientLighting(colorSchemePref === "auto");
this._setColorScheme(colorSchemePref);
this._mm.sendAsyncMessage("Reader:SetCharPref", {
name: "reader.color_scheme",
value: colorSchemePref
});
AsyncPrefs.set("reader.color_scheme", colorSchemePref);
},
_setFontType: function(newFontType) {
@ -443,10 +437,7 @@ AboutReader.prototype = {
this._fontType = newFontType;
bodyClasses.add(this._fontType);
this._mm.sendAsyncMessage("Reader:SetCharPref", {
name: "reader.font_type",
value: this._fontType
});
AsyncPrefs.set("reader.font_type", this._fontType);
},
_setSystemUIVisibility: function(visible) {

Просмотреть файл

@ -13,9 +13,18 @@ Cu.import("resource://gre/modules/Task.jsm");
const kInChildProcess = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
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-char-pref",
"testing.allowed-prefs.some-int-pref",
"narrate.rate",
"narrate.voice",
"reader.font_size",
"reader.font_type",
"reader.color_scheme",
]);
const kPrefTypeMap = new Map([