Bug 1353029 - Pass PdfJs.enabled into child on change r=bdahl

isDefaultHandler in PdfJs.jsm appears to only be called on
startup and when the settings for pdfs (either the pref or the
setting in about:preferences) are changed. During startup, it's
only the parent process which makes this call, which it uses
to conditionally load a script in the content process. On change,
the parent process controls notifying the content process, so
it can simply pass along the enabled boolean. This change simply
shifts to pass this boolean along to the child, and adds some
guards to assert that we're only checking the actual values in
the parent process.

MozReview-Commit-ID: 9JSEJqHR2Ni

--HG--
extra : rebase_source : f4c0790a76e7d31525d2016f8917d8301b67e677
This commit is contained in:
Doug Thayer 2017-05-30 16:34:53 -07:00
Родитель 1b12c351f2
Коммит 24ad7bda2a
3 изменённых файлов: 21 добавлений и 24 удалений

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

@ -67,10 +67,10 @@ function getIntPref(aPref, aDefaultValue) {
}
function isDefaultHandler() {
if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
return PdfjsContentUtils.isDefaultHandlerApp();
}
return PdfjsChromeUtils.isDefaultHandlerApp();
if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) {
throw new Error("isDefaultHandler should only get called in the parent process.");
}
return PdfjsChromeUtils.isDefaultHandlerApp();
}
function initializeDefaultPreferences() {
@ -269,13 +269,14 @@ var PdfJs = {
// nsIObserver
observe: function observe(aSubject, aTopic, aData) {
this.updateRegistration();
if (Services.appinfo.processType ===
Services.appinfo.PROCESS_TYPE_DEFAULT) {
let jsm = "resource://pdf.js/PdfjsChromeUtils.jsm";
let PdfjsChromeUtils = Components.utils.import(jsm, {}).PdfjsChromeUtils;
PdfjsChromeUtils.notifyChildOfSettingsChange();
if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) {
throw new Error("Only the parent process should be observing PDF handler changes.");
}
this.updateRegistration();
let jsm = "resource://pdf.js/PdfjsChromeUtils.jsm";
let PdfjsChromeUtils = Components.utils.import(jsm, {}).PdfjsChromeUtils;
PdfjsChromeUtils.notifyChildOfSettingsChange(this.enabled);
},
/**

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

@ -124,7 +124,7 @@ var PdfjsChromeUtils = {
* instruct the child to refresh its configuration and (possibly)
* the module's registration.
*/
notifyChildOfSettingsChange() {
notifyChildOfSettingsChange(enabled) {
if (Services.appinfo.processType ===
Services.appinfo.PROCESS_TYPE_DEFAULT && this._ppmm) {
// XXX kinda bad, we want to get the parent process mm associated
@ -132,7 +132,7 @@ var PdfjsChromeUtils = {
// manager, which means this is going to fire to every child process
// we have open. Unfortunately I can't find a way to get at that
// process specific mm from js.
this._ppmm.broadcastAsyncMessage("PDFJS:Child:refreshSettings", {});
this._ppmm.broadcastAsyncMessage("PDFJS:Child:updateSettings", {enabled});
}
},

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

@ -43,7 +43,7 @@ var PdfjsContentUtils = {
if (!this._mm) {
this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].
getService(Ci.nsISyncMessageSender);
this._mm.addMessageListener("PDFJS:Child:refreshSettings", this);
this._mm.addMessageListener("PDFJS:Child:updateSettings", this);
Services.obs.addObserver(this, "quit-application");
}
@ -51,7 +51,7 @@ var PdfjsContentUtils = {
uninit() {
if (this._mm) {
this._mm.removeMessageListener("PDFJS:Child:refreshSettings", this);
this._mm.removeMessageListener("PDFJS:Child:updateSettings", this);
Services.obs.removeObserver(this, "quit-application");
}
this._mm = null;
@ -97,14 +97,6 @@ var PdfjsContentUtils = {
});
},
/*
* Forwards default app query to the parent where we check various
* handler app settings only available in the parent process.
*/
isDefaultHandlerApp() {
return this._mm.sendSyncMessage("PDFJS:Parent:isDefaultHandlerApp")[0];
},
/*
* Request the display of a notification warning in the associated window
* when the renderer isn't sure a pdf displayed correctly.
@ -134,13 +126,17 @@ var PdfjsContentUtils = {
receiveMessage(aMsg) {
switch (aMsg.name) {
case "PDFJS:Child:refreshSettings":
case "PDFJS:Child:updateSettings":
// Only react to this if we are remote.
if (Services.appinfo.processType ===
Services.appinfo.PROCESS_TYPE_CONTENT) {
let jsm = "resource://pdf.js/PdfJs.jsm";
let pdfjs = Components.utils.import(jsm, {}).PdfJs;
pdfjs.updateRegistration();
if (aMsg.data.enabled) {
pdfjs.ensureRegistered();
} else {
pdfjs.ensureUnregistered();
}
}
break;
}