зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1351690
, part 1 - Split out pdf.js stream registration into another jsm. r=bdahl
The goal of these patches is to load neither PdfJs.jsm nor PdfStreamConverter.jsm in a content process unless the user is viewing a PDF, to save memory. This first patch creates a small stub JSM to do the stream registration, and calls it directly in the content process, avoiding one way we load PdfJs.jsm. The existing registration methods are kept for the main process. MozReview-Commit-ID: 5GH8tjHXfLb --HG-- extra : rebase_source : f4819b4ae9a406c95aa7fd6a757b0331c9963946
This commit is contained in:
Родитель
2649bf8a95
Коммит
47ae0fa03b
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
var EXPORTED_SYMBOLS = ["PdfJs"];
|
var EXPORTED_SYMBOLS = ["PdfJs"];
|
||||||
|
|
||||||
const Cm = Components.manager;
|
|
||||||
|
|
||||||
const PREF_PREFIX = "pdfjs";
|
const PREF_PREFIX = "pdfjs";
|
||||||
const PREF_DISABLED = PREF_PREFIX + ".disabled";
|
const PREF_DISABLED = PREF_PREFIX + ".disabled";
|
||||||
const PREF_MIGRATION_VERSION = PREF_PREFIX + ".migrationVersion";
|
const PREF_MIGRATION_VERSION = PREF_PREFIX + ".migrationVersion";
|
||||||
|
@ -51,6 +49,8 @@ ChromeUtils.defineModuleGetter(this, "PdfjsContentUtils",
|
||||||
"resource://pdf.js/PdfjsContentUtils.jsm");
|
"resource://pdf.js/PdfjsContentUtils.jsm");
|
||||||
ChromeUtils.defineModuleGetter(this, "PdfJsDefaultPreferences",
|
ChromeUtils.defineModuleGetter(this, "PdfJsDefaultPreferences",
|
||||||
"resource://pdf.js/PdfJsDefaultPreferences.jsm");
|
"resource://pdf.js/PdfJsDefaultPreferences.jsm");
|
||||||
|
ChromeUtils.defineModuleGetter(this, "PdfJsRegistration",
|
||||||
|
"resource://pdf.js/PdfJsRegistration.jsm");
|
||||||
|
|
||||||
function getBoolPref(aPref, aDefaultValue) {
|
function getBoolPref(aPref, aDefaultValue) {
|
||||||
try {
|
try {
|
||||||
|
@ -95,40 +95,8 @@ function initializeDefaultPreferences() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register/unregister a constructor as a factory.
|
|
||||||
function Factory() {}
|
|
||||||
Factory.prototype = {
|
|
||||||
register: function register(targetConstructor) {
|
|
||||||
var proto = targetConstructor.prototype;
|
|
||||||
this._classID = proto.classID;
|
|
||||||
|
|
||||||
var factory = XPCOMUtils._getFactory(targetConstructor);
|
|
||||||
this._factory = factory;
|
|
||||||
|
|
||||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
|
||||||
registrar.registerFactory(proto.classID, proto.classDescription,
|
|
||||||
proto.contractID, factory);
|
|
||||||
|
|
||||||
if (proto.classID2) {
|
|
||||||
this._classID2 = proto.classID2;
|
|
||||||
registrar.registerFactory(proto.classID2, proto.classDescription,
|
|
||||||
proto.contractID2, factory);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
unregister: function unregister() {
|
|
||||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
|
||||||
registrar.unregisterFactory(this._classID, this._factory);
|
|
||||||
if (this._classID2) {
|
|
||||||
registrar.unregisterFactory(this._classID2, this._factory);
|
|
||||||
}
|
|
||||||
this._factory = null;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
var PdfJs = {
|
var PdfJs = {
|
||||||
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver]),
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver]),
|
||||||
_registered: false,
|
|
||||||
_initialized: false,
|
_initialized: false,
|
||||||
|
|
||||||
init: function init(remote) {
|
init: function init(remote) {
|
||||||
|
@ -333,25 +301,11 @@ var PdfJs = {
|
||||||
},
|
},
|
||||||
|
|
||||||
ensureRegistered: function ensureRegistered() {
|
ensureRegistered: function ensureRegistered() {
|
||||||
if (this._registered) {
|
PdfJsRegistration.ensureRegistered();
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._pdfStreamConverterFactory = new Factory();
|
|
||||||
ChromeUtils.import("resource://pdf.js/PdfStreamConverter.jsm");
|
|
||||||
this._pdfStreamConverterFactory.register(PdfStreamConverter);
|
|
||||||
|
|
||||||
this._registered = true;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
ensureUnregistered: function ensureUnregistered() {
|
ensureUnregistered: function ensureUnregistered() {
|
||||||
if (!this._registered) {
|
PdfJsRegistration.ensureUnregistered();
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._pdfStreamConverterFactory.unregister();
|
|
||||||
Cu.unload("resource://pdf.js/PdfStreamConverter.jsm");
|
|
||||||
delete this._pdfStreamConverterFactory;
|
|
||||||
|
|
||||||
this._registered = false;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/* Copyright 2018 Mozilla Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var EXPORTED_SYMBOLS = ["PdfJsRegistration"];
|
||||||
|
|
||||||
|
const Cm = Components.manager;
|
||||||
|
|
||||||
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
|
|
||||||
|
// Register/unregister a constructor as a factory.
|
||||||
|
function Factory() {}
|
||||||
|
Factory.prototype = {
|
||||||
|
register: function register(targetConstructor) {
|
||||||
|
var proto = targetConstructor.prototype;
|
||||||
|
this._classID = proto.classID;
|
||||||
|
|
||||||
|
var factory = XPCOMUtils._getFactory(targetConstructor);
|
||||||
|
this._factory = factory;
|
||||||
|
|
||||||
|
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||||
|
registrar.registerFactory(proto.classID, proto.classDescription,
|
||||||
|
proto.contractID, factory);
|
||||||
|
|
||||||
|
if (proto.classID2) {
|
||||||
|
this._classID2 = proto.classID2;
|
||||||
|
registrar.registerFactory(proto.classID2, proto.classDescription,
|
||||||
|
proto.contractID2, factory);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
unregister: function unregister() {
|
||||||
|
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||||
|
registrar.unregisterFactory(this._classID, this._factory);
|
||||||
|
if (this._classID2) {
|
||||||
|
registrar.unregisterFactory(this._classID2, this._factory);
|
||||||
|
}
|
||||||
|
this._factory = null;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
var PdfJsRegistration = {
|
||||||
|
_registered: false,
|
||||||
|
|
||||||
|
ensureRegistered: function ensureRegistered() {
|
||||||
|
if (this._registered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._pdfStreamConverterFactory = new Factory();
|
||||||
|
ChromeUtils.import("resource://pdf.js/PdfStreamConverter.jsm");
|
||||||
|
this._pdfStreamConverterFactory.register(PdfStreamConverter);
|
||||||
|
|
||||||
|
this._registered = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
ensureUnregistered: function ensureUnregistered() {
|
||||||
|
if (!this._registered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._pdfStreamConverterFactory.unregister();
|
||||||
|
Cu.unload("resource://pdf.js/PdfStreamConverter.jsm");
|
||||||
|
delete this._pdfStreamConverterFactory;
|
||||||
|
|
||||||
|
this._registered = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
|
@ -118,12 +118,12 @@ var PdfjsContentUtils = {
|
||||||
// Only react to this if we are remote.
|
// Only react to this if we are remote.
|
||||||
if (Services.appinfo.processType ===
|
if (Services.appinfo.processType ===
|
||||||
Services.appinfo.PROCESS_TYPE_CONTENT) {
|
Services.appinfo.PROCESS_TYPE_CONTENT) {
|
||||||
let jsm = "resource://pdf.js/PdfJs.jsm";
|
let jsm = "resource://pdf.js/PdfJsRegistration.jsm";
|
||||||
let pdfjs = ChromeUtils.import(jsm, {}).PdfJs;
|
let pdfjsr = ChromeUtils.import(jsm, {}).PdfJsRegistration;
|
||||||
if (aMsg.data.enabled) {
|
if (aMsg.data.enabled) {
|
||||||
pdfjs.ensureRegistered();
|
pdfjsr.ensureRegistered();
|
||||||
} else {
|
} else {
|
||||||
pdfjs.ensureUnregistered();
|
pdfjsr.ensureUnregistered();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||||
ChromeUtils.import("resource://pdf.js/PdfJs.jsm");
|
ChromeUtils.import("resource://pdf.js/PdfJsRegistration.jsm");
|
||||||
|
|
||||||
if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
|
if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
|
||||||
// register various pdfjs factories that hook us into content loading.
|
// register various pdfjs factories that hook us into content loading.
|
||||||
PdfJs.ensureRegistered();
|
PdfJsRegistration.ensureRegistered();
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче