Merge pull request #1184 from brendandahl/amo2
Address AMO Review Concerns Round 2
This commit is contained in:
commit
4cdd2ad7b1
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,24 +3,43 @@
|
|||||||
|
|
||||||
'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;
|
||||||
const Cu = Components.utils;
|
const Cu = Components.utils;
|
||||||
const PDFJS_EVENT_ID = 'pdf.js.message';
|
const PDFJS_EVENT_ID = 'pdf.js.message';
|
||||||
const PDF_CONTENT_TYPE = 'application/pdf';
|
const PDF_CONTENT_TYPE = 'application/pdf';
|
||||||
const NS_ERROR_NOT_IMPLEMENTED = 0x80004001;
|
|
||||||
const EXT_PREFIX = 'extensions.uriloader@pdf.js';
|
const EXT_PREFIX = 'extensions.uriloader@pdf.js';
|
||||||
|
const MAX_DATABASE_LENGTH = 4096;
|
||||||
|
|
||||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||||
Cu.import('resource://gre/modules/Services.jsm');
|
Cu.import('resource://gre/modules/Services.jsm');
|
||||||
|
|
||||||
function log(aMsg) {
|
function log(aMsg) {
|
||||||
let msg = 'PdfStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
let msg = 'PdfStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
||||||
Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
|
Services.console.logStringMessage(msg);
|
||||||
.logStringMessage(msg);
|
|
||||||
dump(msg + '\n');
|
dump(msg + '\n');
|
||||||
}
|
}
|
||||||
|
function getWindow(top, id) {
|
||||||
|
return top.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils)
|
||||||
|
.getOuterWindowWithId(id);
|
||||||
|
}
|
||||||
|
function windowID(win) {
|
||||||
|
return win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils)
|
||||||
|
.outerWindowID;
|
||||||
|
}
|
||||||
|
function topWindow(win) {
|
||||||
|
return win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
||||||
|
.rootTreeItem
|
||||||
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindow);
|
||||||
|
}
|
||||||
let application = Cc['@mozilla.org/fuel/application;1']
|
let application = Cc['@mozilla.org/fuel/application;1']
|
||||||
.getService(Ci.fuelIApplication);
|
.getService(Ci.fuelIApplication);
|
||||||
let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
|
let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
|
||||||
@ -38,6 +57,9 @@ ChromeActions.prototype = {
|
|||||||
setDatabase: function(data) {
|
setDatabase: function(data) {
|
||||||
if (this.inPrivateBrowswing)
|
if (this.inPrivateBrowswing)
|
||||||
return;
|
return;
|
||||||
|
// Protect against something sending tons of data to setDatabase.
|
||||||
|
if (data.length > MAX_DATABASE_LENGTH)
|
||||||
|
return;
|
||||||
application.prefs.setValue(EXT_PREFIX + '.database', data);
|
application.prefs.setValue(EXT_PREFIX + '.database', data);
|
||||||
},
|
},
|
||||||
getDatabase: function() {
|
getDatabase: function() {
|
||||||
@ -95,13 +117,13 @@ PdfStreamConverter.prototype = {
|
|||||||
|
|
||||||
// nsIStreamConverter::convert
|
// nsIStreamConverter::convert
|
||||||
convert: function(aFromStream, aFromType, aToType, aCtxt) {
|
convert: function(aFromStream, aFromType, aToType, aCtxt) {
|
||||||
return aFromStream;
|
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||||
},
|
},
|
||||||
|
|
||||||
// nsIStreamConverter::asyncConvertData
|
// nsIStreamConverter::asyncConvertData
|
||||||
asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
|
asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
|
||||||
if (!Services.prefs.getBoolPref('extensions.pdf.js.active'))
|
if (!Services.prefs.getBoolPref('extensions.pdf.js.active'))
|
||||||
throw NS_ERROR_NOT_IMPLEMENTED;
|
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||||
// Store the listener passed to us
|
// Store the listener passed to us
|
||||||
this.listener = aListener;
|
this.listener = aListener;
|
||||||
},
|
},
|
||||||
@ -121,8 +143,7 @@ PdfStreamConverter.prototype = {
|
|||||||
aRequest.cancel(Cr.NS_BINDING_ABORTED);
|
aRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||||
|
|
||||||
// Create a new channel that is viewer loaded as a resource.
|
// Create a new channel that is viewer loaded as a resource.
|
||||||
var ioService = Cc['@mozilla.org/network/io-service;1']
|
var ioService = Services.io;
|
||||||
.getService(Ci.nsIIOService);
|
|
||||||
var channel = ioService.newChannel(
|
var channel = ioService.newChannel(
|
||||||
'resource://pdf.js/web/viewer.html', null, null);
|
'resource://pdf.js/web/viewer.html', null, null);
|
||||||
|
|
||||||
@ -133,21 +154,31 @@ PdfStreamConverter.prototype = {
|
|||||||
// Setup a global listener waiting for the next DOM to be created and verfiy
|
// Setup a global listener waiting for the next DOM to be created and verfiy
|
||||||
// that its the one we want by its URL. When the correct DOM is found create
|
// that its the one we want by its URL. When the correct DOM is found create
|
||||||
// an event listener on that window for the pdf.js events that require
|
// an event listener on that window for the pdf.js events that require
|
||||||
// chrome priviledges.
|
// chrome priviledges. Code snippet from John Galt.
|
||||||
var url = aRequest.URI.spec;
|
let window = aRequest.loadGroup.groupObserver
|
||||||
var gb = Services.wm.getMostRecentWindow('navigator:browser');
|
.QueryInterface(Ci.nsIWebProgress)
|
||||||
var domListener = function domListener(event) {
|
.DOMWindow;
|
||||||
var doc = event.originalTarget;
|
let top = topWindow(window);
|
||||||
var win = doc.defaultView;
|
let id = windowID(window);
|
||||||
if (doc.location.href === url) {
|
window = null;
|
||||||
gb.removeEventListener('DOMContentLoaded', domListener);
|
|
||||||
var requestListener = new RequestListener(new ChromeActions());
|
top.addEventListener('DOMWindowCreated', function onDOMWinCreated(event) {
|
||||||
|
let doc = event.originalTarget;
|
||||||
|
let win = doc.defaultView;
|
||||||
|
|
||||||
|
if (id == windowID(win)) {
|
||||||
|
top.removeEventListener('DOMWindowCreated', onDOMWinCreated, true);
|
||||||
|
if (!doc.documentURIObject.equals(aRequest.URI))
|
||||||
|
return;
|
||||||
|
|
||||||
|
let requestListener = new RequestListener(new ChromeActions);
|
||||||
win.addEventListener(PDFJS_EVENT_ID, function(event) {
|
win.addEventListener(PDFJS_EVENT_ID, function(event) {
|
||||||
requestListener.receive(event);
|
requestListener.receive(event);
|
||||||
}, false, true);
|
}, false, true);
|
||||||
|
} else if (!getWindow(top, id)) {
|
||||||
|
top.removeEventListener('DOMWindowCreated', onDOMWinCreated, true);
|
||||||
}
|
}
|
||||||
};
|
}, true);
|
||||||
gb.addEventListener('DOMContentLoaded', domListener, false);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// nsIRequestObserver::onStopRequest
|
// nsIRequestObserver::onStopRequest
|
||||||
|
@ -109,7 +109,7 @@ var Settings = (function SettingsClosure() {
|
|||||||
var database = null;
|
var database = null;
|
||||||
var index;
|
var index;
|
||||||
if (isFirefoxExtension)
|
if (isFirefoxExtension)
|
||||||
database = FirefoxCom.request('getDatabase', null);
|
database = FirefoxCom.request('getDatabase', null) || '{}';
|
||||||
else if (isLocalStorageEnabled)
|
else if (isLocalStorageEnabled)
|
||||||
database = localStorage.getItem('database') || '{}';
|
database = localStorage.getItem('database') || '{}';
|
||||||
else
|
else
|
||||||
@ -131,8 +131,6 @@ var Settings = (function SettingsClosure() {
|
|||||||
index = database.files.push({fingerprint: fingerprint}) - 1;
|
index = database.files.push({fingerprint: fingerprint}) - 1;
|
||||||
this.file = database.files[index];
|
this.file = database.files[index];
|
||||||
this.database = database;
|
this.database = database;
|
||||||
if (isLocalStorageEnabled)
|
|
||||||
localStorage.setItem('database', JSON.stringify(database));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.prototype = {
|
Settings.prototype = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user