Fixes pdf application switching in FF22/23 (redo)
This commit is contained in:
parent
71a31b01f2
commit
853e4625bf
@ -101,23 +101,6 @@ function getDOMWindow(aChannel) {
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEnabled() {
|
|
||||||
if (MOZ_CENTRAL) {
|
|
||||||
var disabled = getBoolPref(PREF_PREFIX + '.disabled', false);
|
|
||||||
if (disabled)
|
|
||||||
return false;
|
|
||||||
// To also be considered enabled the "Preview in Firefox" option must be
|
|
||||||
// selected in the Application preferences.
|
|
||||||
var handlerInfo = Svc.mime
|
|
||||||
.getFromTypeAndExtension('application/pdf', 'pdf');
|
|
||||||
return !handlerInfo.alwaysAskBeforeHandling &&
|
|
||||||
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) {
|
function getLocalizedStrings(path) {
|
||||||
var stringBundle = Cc['@mozilla.org/intl/stringbundle;1'].
|
var stringBundle = Cc['@mozilla.org/intl/stringbundle;1'].
|
||||||
getService(Ci.nsIStringBundleService).
|
getService(Ci.nsIStringBundleService).
|
||||||
@ -580,9 +563,6 @@ PdfStreamConverter.prototype = {
|
|||||||
|
|
||||||
// nsIStreamConverter::asyncConvertData
|
// nsIStreamConverter::asyncConvertData
|
||||||
asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
|
asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
|
||||||
if (!isEnabled())
|
|
||||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
// Store the listener passed to us
|
// Store the listener passed to us
|
||||||
this.listener = aListener;
|
this.listener = aListener;
|
||||||
},
|
},
|
||||||
|
@ -28,6 +28,8 @@ const PREF_PREVIOUS_ACTION = PREF_PREFIX + '.previousHandler.preferredAction';
|
|||||||
const PREF_PREVIOUS_ASK = PREF_PREFIX + '.previousHandler.alwaysAskBeforeHandling';
|
const PREF_PREVIOUS_ASK = PREF_PREFIX + '.previousHandler.alwaysAskBeforeHandling';
|
||||||
const PREF_DISABLED_PLUGIN_TYPES = 'plugin.disable_full_page_plugin_for_types';
|
const PREF_DISABLED_PLUGIN_TYPES = 'plugin.disable_full_page_plugin_for_types';
|
||||||
const TOPIC_PDFJS_HANDLER_CHANGED = 'pdfjs:handlerChanged';
|
const TOPIC_PDFJS_HANDLER_CHANGED = 'pdfjs:handlerChanged';
|
||||||
|
const TOPIC_PLUGINS_LIST_UPDATED = "plugins-list-updated";
|
||||||
|
const TOPIC_PLUGIN_INFO_UPDATED = "plugin-info-updated";
|
||||||
const PDF_CONTENT_TYPE = 'application/pdf';
|
const PDF_CONTENT_TYPE = 'application/pdf';
|
||||||
|
|
||||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||||
@ -112,7 +114,10 @@ let PdfJs = {
|
|||||||
// Listen for when pdf.js is completely disabled or a different pdf handler
|
// Listen for when pdf.js is completely disabled or a different pdf handler
|
||||||
// is chosen.
|
// is chosen.
|
||||||
Services.prefs.addObserver(PREF_DISABLED, this, false);
|
Services.prefs.addObserver(PREF_DISABLED, this, false);
|
||||||
|
Services.prefs.addObserver(PREF_DISABLED_PLUGIN_TYPES, this, false);
|
||||||
Services.obs.addObserver(this, TOPIC_PDFJS_HANDLER_CHANGED, false);
|
Services.obs.addObserver(this, TOPIC_PDFJS_HANDLER_CHANGED, false);
|
||||||
|
Services.obs.addObserver(this, TOPIC_PLUGINS_LIST_UPDATED, false);
|
||||||
|
Services.obs.addObserver(this, TOPIC_PLUGIN_INFO_UPDATED, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
_migrate: function migrate() {
|
_migrate: function migrate() {
|
||||||
@ -186,14 +191,39 @@ let PdfJs = {
|
|||||||
*/
|
*/
|
||||||
get enabled() {
|
get enabled() {
|
||||||
var disabled = getBoolPref(PREF_DISABLED, true);
|
var disabled = getBoolPref(PREF_DISABLED, true);
|
||||||
if (disabled)
|
if (disabled) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var handlerInfo = Svc.mime.
|
// the 'application/pdf' handler is selected as internal?
|
||||||
getFromTypeAndExtension('application/pdf', 'pdf');
|
var handlerInfo = Svc.mime
|
||||||
return handlerInfo.alwaysAskBeforeHandling == false &&
|
.getFromTypeAndExtension(PDF_CONTENT_TYPE, 'pdf');
|
||||||
handlerInfo.plugin == null &&
|
if (handlerInfo.alwaysAskBeforeHandling ||
|
||||||
handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally;
|
handlerInfo.preferredAction !== Ci.nsIHandlerInfo.handleInternally) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we also need to check if pdf plugin is not present or disabled...
|
||||||
|
let tags = Cc["@mozilla.org/plugin/host;1"].
|
||||||
|
getService(Ci.nsIPluginHost).
|
||||||
|
getPluginTags();
|
||||||
|
let enabledPluginFound = tags.some(function(tag) {
|
||||||
|
if (tag.disabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let mimeTypes = tag.getMimeTypes();
|
||||||
|
return mimeTypes.some(function(mimeType) {
|
||||||
|
return mimeType.type === PDF_CONTENT_TYPE;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (!enabledPluginFound) {
|
||||||
|
return true; // no plugins for this type, it's good
|
||||||
|
}
|
||||||
|
// ... and full page plugins list must have 'application/pdf' type,
|
||||||
|
// in case when enabled pdf plugin exists.
|
||||||
|
return Services.prefs.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES) ?
|
||||||
|
(Services.prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES).split(',').
|
||||||
|
indexOf(PDF_CONTENT_TYPE) >= 0) : false;
|
||||||
},
|
},
|
||||||
|
|
||||||
_ensureRegistered: function _ensureRegistered() {
|
_ensureRegistered: function _ensureRegistered() {
|
||||||
@ -205,7 +235,7 @@ let PdfJs = {
|
|||||||
|
|
||||||
this._pdfRedirectorFactory = new Factory();
|
this._pdfRedirectorFactory = new Factory();
|
||||||
this._pdfRedirectorFactory.register(PdfRedirector);
|
this._pdfRedirectorFactory.register(PdfRedirector);
|
||||||
Svc.pluginHost.registerPlayPreviewMimeType('application/pdf', true,
|
Svc.pluginHost.registerPlayPreviewMimeType(PDF_CONTENT_TYPE, true,
|
||||||
'data:application/x-moz-playpreview-pdfjs;,');
|
'data:application/x-moz-playpreview-pdfjs;,');
|
||||||
|
|
||||||
this._registered = true;
|
this._registered = true;
|
||||||
@ -220,7 +250,7 @@ let PdfJs = {
|
|||||||
|
|
||||||
this._pdfRedirectorFactory.unregister;
|
this._pdfRedirectorFactory.unregister;
|
||||||
delete this._pdfRedirectorFactory;
|
delete this._pdfRedirectorFactory;
|
||||||
Svc.pluginHost.unregisterPlayPreviewMimeType('application/pdf');
|
Svc.pluginHost.unregisterPlayPreviewMimeType(PDF_CONTENT_TYPE);
|
||||||
|
|
||||||
this._registered = false;
|
this._registered = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user