Make the add-on truly restartless.
This commit is contained in:
parent
9a1741f466
commit
1af9a72011
2
Makefile
2
Makefile
@ -223,14 +223,12 @@ FIREFOX_CONTENT_DIR := $(EXTENSION_SRC)/firefox/$(CONTENT_DIR)/
|
|||||||
FIREFOX_EXTENSION_FILES_TO_COPY = \
|
FIREFOX_EXTENSION_FILES_TO_COPY = \
|
||||||
*.js \
|
*.js \
|
||||||
*.rdf \
|
*.rdf \
|
||||||
chrome.manifest \
|
|
||||||
components \
|
components \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
FIREFOX_EXTENSION_FILES = \
|
FIREFOX_EXTENSION_FILES = \
|
||||||
content \
|
content \
|
||||||
*.js \
|
*.js \
|
||||||
install.rdf \
|
install.rdf \
|
||||||
chrome.manifest \
|
|
||||||
components \
|
components \
|
||||||
content \
|
content \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
72
extensions/firefox/bootstrap.js
vendored
72
extensions/firefox/bootstrap.js
vendored
@ -3,8 +3,9 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const RESOURCE_NAME = 'pdf.js';
|
||||||
const EXT_PREFIX = 'extensions.uriloader@pdf.js';
|
const EXT_PREFIX = 'extensions.uriloader@pdf.js';
|
||||||
const PDFJS_EVENT_ID = 'pdf.js.message';
|
|
||||||
let Cc = Components.classes;
|
let Cc = Components.classes;
|
||||||
let Ci = Components.interfaces;
|
let Ci = Components.interfaces;
|
||||||
let Cm = Components.manager;
|
let Cm = Components.manager;
|
||||||
@ -16,24 +17,71 @@ function log(str) {
|
|||||||
dump(str + '\n');
|
dump(str + '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register/unregister a class as a component.
|
||||||
|
let Factory = {
|
||||||
|
registrar: null,
|
||||||
|
aClass: null,
|
||||||
|
register: function(aClass) {
|
||||||
|
if (this.aClass) {
|
||||||
|
log('Cannot register more than one class');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||||
|
this.aClass = aClass;
|
||||||
|
var proto = aClass.prototype;
|
||||||
|
this.registrar.registerFactory(proto.classID, proto.classDescription,
|
||||||
|
proto.contractID, this);
|
||||||
|
},
|
||||||
|
unregister: function() {
|
||||||
|
if (!this.aClass) {
|
||||||
|
log('Class was never registered.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var proto = this.aClass.prototype;
|
||||||
|
this.registrar.unregisterFactory(proto.classID, this);
|
||||||
|
this.aClass = null;
|
||||||
|
},
|
||||||
|
// nsIFactory::createInstance
|
||||||
|
createInstance: function(outer, iid) {
|
||||||
|
if (outer !== null)
|
||||||
|
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||||
|
return (new (this.aClass)).QueryInterface(iid);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// As of Firefox 13 bootstrapped add-ons don't support automatic registering and
|
||||||
|
// unregistering of resource urls and components/contracts. Until then we do
|
||||||
|
// it programatically. See ManifestDirective ManifestParser.cpp for support.
|
||||||
|
|
||||||
function startup(aData, aReason) {
|
function startup(aData, aReason) {
|
||||||
let manifestPath = 'chrome.manifest';
|
// Setup the resource url.
|
||||||
let manifest = Cc['@mozilla.org/file/local;1']
|
var ioService = Services.io;
|
||||||
.createInstance(Ci.nsILocalFile);
|
var resProt = ioService.getProtocolHandler('resource')
|
||||||
try {
|
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||||
manifest.initWithPath(aData.installPath.path);
|
var aliasFile = Cc['@mozilla.org/file/local;1']
|
||||||
manifest.append(manifestPath);
|
.createInstance(Ci.nsILocalFile);
|
||||||
Cm.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(manifest);
|
var componentPath = aData.installPath.clone();
|
||||||
Services.prefs.setBoolPref('extensions.pdf.js.active', true);
|
componentPath.append('content');
|
||||||
} catch (e) {
|
aliasFile.initWithPath(componentPath.path);
|
||||||
log(e);
|
var aliasURI = ioService.newFileURI(aliasFile);
|
||||||
}
|
resProt.setSubstitution(RESOURCE_NAME, aliasURI);
|
||||||
|
|
||||||
|
// Load the component and register it.
|
||||||
|
Cu.import(aData.resourceURI.spec + 'components/PdfStreamConverter.js');
|
||||||
|
Factory.register(PdfStreamConverter);
|
||||||
|
Services.prefs.setBoolPref('extensions.pdf.js.active', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function shutdown(aData, aReason) {
|
function shutdown(aData, aReason) {
|
||||||
if (Services.prefs.getBoolPref('extensions.pdf.js.active'))
|
if (Services.prefs.getBoolPref('extensions.pdf.js.active'))
|
||||||
Services.prefs.setBoolPref('extensions.pdf.js.active', false);
|
Services.prefs.setBoolPref('extensions.pdf.js.active', false);
|
||||||
|
var ioService = Services.io;
|
||||||
|
var resProt = ioService.getProtocolHandler('resource')
|
||||||
|
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||||
|
// Remove the resource url.
|
||||||
|
resProt.setSubstitution(RESOURCE_NAME, null);
|
||||||
|
// Remove the contract/component.
|
||||||
|
Factory.unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
function install(aData, aReason) {
|
function install(aData, aReason) {
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
resource pdf.js content/
|
|
||||||
|
|
||||||
component {6457a96b-2d68-439a-bcfa-44465fbcdbb1} components/PdfStreamConverter.js
|
|
||||||
contract @mozilla.org/streamconv;1?from=application/pdf&to=*/* {6457a96b-2d68-439a-bcfa-44465fbcdbb1}
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var EXPORTED_SYMBOLS = ['PdfStreamConverter'];
|
||||||
|
|
||||||
const Cc = Components.classes;
|
const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
const Cr = Components.results;
|
const Cr = Components.results;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user