mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Add global pref to enable/disable. Control pdf.js in application preferences. Add Artur's mochi tests.
This commit is contained in:
parent
2a9efa8acc
commit
3d7f01d9ca
8 changed files with 250 additions and 8 deletions
|
@ -9,6 +9,7 @@ const Cc = Components.classes;
|
|||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
const MOZ_CENTRAL = PDFJSSCRIPT_MOZ_CENTRAL;
|
||||
const PDFJS_EVENT_ID = 'pdf.js.message';
|
||||
const PDF_CONTENT_TYPE = 'application/pdf';
|
||||
const PREF_PREFIX = 'PDFJSSCRIPT_PREF_PREFIX';
|
||||
|
@ -19,11 +20,12 @@ const SEAMONKEY_ID = '{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}';
|
|||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
Cu.import('resource://gre/modules/NetUtil.jsm');
|
||||
Cu.import('resource://gre/modules/AddonManager.jsm');
|
||||
|
||||
let appInfo = Cc['@mozilla.org/xre/app-info;1']
|
||||
.getService(Ci.nsIXULAppInfo);
|
||||
let privateBrowsing, inPrivateBrowsing;
|
||||
let mimeService = Cc['@mozilla.org/mime;1']
|
||||
.getService(Ci.nsIMIMEService);
|
||||
|
||||
if (appInfo.ID === FIREFOX_ID) {
|
||||
privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
|
||||
|
@ -71,6 +73,23 @@ function getDOMWindow(aChannel) {
|
|||
return win;
|
||||
}
|
||||
|
||||
function isEnabled() {
|
||||
if (MOZ_CENTRAL) {
|
||||
var enabled = getBoolPref(PREF_PREFIX + '.enabled', false);
|
||||
if (!enabled)
|
||||
return false;
|
||||
// To also be considered enabled the "Preview in Firefox" option must be
|
||||
// selected in the Application preferences.
|
||||
var handlerInfo = mimeService.
|
||||
getFromTypeAndExtension('application/pdf', 'pdf');
|
||||
return handlerInfo && (handlerInfo.alwaysAskBeforeHandling == false &&
|
||||
handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally);
|
||||
}
|
||||
// Always returns true for the extension since enabling/disabling is handled
|
||||
// by the add-on manager.
|
||||
return true;
|
||||
}
|
||||
|
||||
function getLocalizedStrings(path) {
|
||||
var stringBundle = Cc['@mozilla.org/intl/stringbundle;1'].
|
||||
getService(Ci.nsIStringBundleService).
|
||||
|
@ -248,6 +267,8 @@ PdfStreamConverter.prototype = {
|
|||
|
||||
// nsIStreamConverter::asyncConvertData
|
||||
asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
|
||||
if (!isEnabled())
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
// Ignoring HTTP POST requests -- pdf.js has to repeat the request.
|
||||
var skipConversion = false;
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue