|
|
@ -14,6 +14,9 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
/* jshint esnext:true */ |
|
|
|
|
|
|
|
/* globals Components, Services, XPCOMUtils, NetUtil, PrivateBrowsingUtils, |
|
|
|
|
|
|
|
dump */ |
|
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
@ -24,7 +27,7 @@ const Ci = Components.interfaces; |
|
|
|
const Cr = Components.results; |
|
|
|
const Cr = Components.results; |
|
|
|
const Cu = Components.utils; |
|
|
|
const Cu = Components.utils; |
|
|
|
// True only if this is the version of pdf.js that is included with firefox.
|
|
|
|
// True only if this is the version of pdf.js that is included with firefox.
|
|
|
|
const MOZ_CENTRAL = PDFJSSCRIPT_MOZ_CENTRAL; |
|
|
|
const MOZ_CENTRAL = JSON.parse('PDFJSSCRIPT_MOZ_CENTRAL'); |
|
|
|
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 PREF_PREFIX = 'PDFJSSCRIPT_PREF_PREFIX'; |
|
|
|
const PREF_PREFIX = 'PDFJSSCRIPT_PREF_PREFIX'; |
|
|
@ -38,7 +41,7 @@ Cu.import('resource://gre/modules/NetUtil.jsm'); |
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'PrivateBrowsingUtils', |
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'PrivateBrowsingUtils', |
|
|
|
'resource://gre/modules/PrivateBrowsingUtils.jsm'); |
|
|
|
'resource://gre/modules/PrivateBrowsingUtils.jsm'); |
|
|
|
|
|
|
|
|
|
|
|
let Svc = {}; |
|
|
|
var Svc = {}; |
|
|
|
XPCOMUtils.defineLazyServiceGetter(Svc, 'mime', |
|
|
|
XPCOMUtils.defineLazyServiceGetter(Svc, 'mime', |
|
|
|
'@mozilla.org/mime;1', |
|
|
|
'@mozilla.org/mime;1', |
|
|
|
'nsIMIMEService'); |
|
|
|
'nsIMIMEService'); |
|
|
@ -68,7 +71,7 @@ function getIntPref(pref, def) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setStringPref(pref, value) { |
|
|
|
function setStringPref(pref, value) { |
|
|
|
let str = Cc['@mozilla.org/supports-string;1'] |
|
|
|
var str = Cc['@mozilla.org/supports-string;1'] |
|
|
|
.createInstance(Ci.nsISupportsString); |
|
|
|
.createInstance(Ci.nsISupportsString); |
|
|
|
str.data = value; |
|
|
|
str.data = value; |
|
|
|
Services.prefs.setComplexValue(pref, Ci.nsISupportsString, str); |
|
|
|
Services.prefs.setComplexValue(pref, Ci.nsISupportsString, str); |
|
|
@ -85,7 +88,7 @@ function getStringPref(pref, def) { |
|
|
|
function log(aMsg) { |
|
|
|
function log(aMsg) { |
|
|
|
if (!getBoolPref(PREF_PREFIX + '.pdfBugEnabled', false)) |
|
|
|
if (!getBoolPref(PREF_PREFIX + '.pdfBugEnabled', false)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
let msg = 'PdfStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg); |
|
|
|
var msg = 'PdfStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg); |
|
|
|
Services.console.logStringMessage(msg); |
|
|
|
Services.console.logStringMessage(msg); |
|
|
|
dump(msg + '\n'); |
|
|
|
dump(msg + '\n'); |
|
|
|
} |
|
|
|
} |
|
|
@ -107,7 +110,7 @@ function isEnabled() { |
|
|
|
// selected in the Application preferences.
|
|
|
|
// selected in the Application preferences.
|
|
|
|
var handlerInfo = Svc.mime |
|
|
|
var handlerInfo = Svc.mime |
|
|
|
.getFromTypeAndExtension('application/pdf', 'pdf'); |
|
|
|
.getFromTypeAndExtension('application/pdf', 'pdf'); |
|
|
|
return handlerInfo.alwaysAskBeforeHandling == false && |
|
|
|
return !handlerInfo.alwaysAskBeforeHandling && |
|
|
|
handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally; |
|
|
|
handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally; |
|
|
|
} |
|
|
|
} |
|
|
|
// Always returns true for the extension since enabling/disabling is handled
|
|
|
|
// Always returns true for the extension since enabling/disabling is handled
|
|
|
@ -189,6 +192,9 @@ PdfDataListener.prototype = { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
onprogress: function() {}, |
|
|
|
onprogress: function() {}, |
|
|
|
|
|
|
|
get oncomplete() { |
|
|
|
|
|
|
|
return this.oncompleteCallback; |
|
|
|
|
|
|
|
}, |
|
|
|
set oncomplete(value) { |
|
|
|
set oncomplete(value) { |
|
|
|
this.oncompleteCallback = value; |
|
|
|
this.oncompleteCallback = value; |
|
|
|
if (this.isDataReady) { |
|
|
|
if (this.isDataReady) { |
|
|
@ -209,7 +215,7 @@ function ChromeActions(domWindow, dataListener, contentDispositionFilename) { |
|
|
|
|
|
|
|
|
|
|
|
ChromeActions.prototype = { |
|
|
|
ChromeActions.prototype = { |
|
|
|
isInPrivateBrowsing: function() { |
|
|
|
isInPrivateBrowsing: function() { |
|
|
|
let docIsPrivate; |
|
|
|
var docIsPrivate, privateBrowsing; |
|
|
|
try { |
|
|
|
try { |
|
|
|
docIsPrivate = PrivateBrowsingUtils.isWindowPrivate(this.domWindow); |
|
|
|
docIsPrivate = PrivateBrowsingUtils.isWindowPrivate(this.domWindow); |
|
|
|
} catch (x) { |
|
|
|
} catch (x) { |
|
|
@ -218,8 +224,8 @@ ChromeActions.prototype = { |
|
|
|
if (typeof docIsPrivate === 'undefined') { |
|
|
|
if (typeof docIsPrivate === 'undefined') { |
|
|
|
// per-window Private Browsing is not supported, trying global service
|
|
|
|
// per-window Private Browsing is not supported, trying global service
|
|
|
|
try { |
|
|
|
try { |
|
|
|
let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1'] |
|
|
|
privateBrowsing = Cc['@mozilla.org/privatebrowsing;1'] |
|
|
|
.getService(Ci.nsIPrivateBrowsingService); |
|
|
|
.getService(Ci.nsIPrivateBrowsingService); |
|
|
|
docIsPrivate = privateBrowsing.privateBrowsingEnabled; |
|
|
|
docIsPrivate = privateBrowsing.privateBrowsingEnabled; |
|
|
|
} catch (x) { |
|
|
|
} catch (x) { |
|
|
|
// unable to get nsIPrivateBrowsingService (e.g. not Firefox)
|
|
|
|
// unable to get nsIPrivateBrowsingService (e.g. not Firefox)
|
|
|
@ -245,8 +251,8 @@ ChromeActions.prototype = { |
|
|
|
var frontWindow = Cc['@mozilla.org/embedcomp/window-watcher;1']. |
|
|
|
var frontWindow = Cc['@mozilla.org/embedcomp/window-watcher;1']. |
|
|
|
getService(Ci.nsIWindowWatcher).activeWindow; |
|
|
|
getService(Ci.nsIWindowWatcher).activeWindow; |
|
|
|
|
|
|
|
|
|
|
|
let docIsPrivate = this.isInPrivateBrowsing(); |
|
|
|
var docIsPrivate = this.isInPrivateBrowsing(); |
|
|
|
let netChannel = NetUtil.newChannel(blobUri); |
|
|
|
var netChannel = NetUtil.newChannel(blobUri); |
|
|
|
if ('nsIPrivateBrowsingChannel' in Ci && |
|
|
|
if ('nsIPrivateBrowsingChannel' in Ci && |
|
|
|
netChannel instanceof Ci.nsIPrivateBrowsingChannel) { |
|
|
|
netChannel instanceof Ci.nsIPrivateBrowsingChannel) { |
|
|
|
netChannel.setPrivate(docIsPrivate); |
|
|
|
netChannel.setPrivate(docIsPrivate); |
|
|
@ -259,7 +265,7 @@ ChromeActions.prototype = { |
|
|
|
} |
|
|
|
} |
|
|
|
// Create a nsIInputStreamChannel so we can set the url on the channel
|
|
|
|
// Create a nsIInputStreamChannel so we can set the url on the channel
|
|
|
|
// so the filename will be correct.
|
|
|
|
// so the filename will be correct.
|
|
|
|
let channel = Cc['@mozilla.org/network/input-stream-channel;1']. |
|
|
|
var channel = Cc['@mozilla.org/network/input-stream-channel;1']. |
|
|
|
createInstance(Ci.nsIInputStreamChannel); |
|
|
|
createInstance(Ci.nsIInputStreamChannel); |
|
|
|
channel.QueryInterface(Ci.nsIChannel); |
|
|
|
channel.QueryInterface(Ci.nsIChannel); |
|
|
|
channel.contentDisposition = Ci.nsIChannel.DISPOSITION_ATTACHMENT; |
|
|
|
channel.contentDisposition = Ci.nsIChannel.DISPOSITION_ATTACHMENT; |
|
|
@ -472,7 +478,7 @@ RequestListener.prototype.receive = function(event) { |
|
|
|
var listener = doc.createEvent('HTMLEvents'); |
|
|
|
var listener = doc.createEvent('HTMLEvents'); |
|
|
|
listener.initEvent('pdf.js.response', true, false); |
|
|
|
listener.initEvent('pdf.js.response', true, false); |
|
|
|
return message.dispatchEvent(listener); |
|
|
|
return message.dispatchEvent(listener); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
actions[action].call(this.actions, data, response); |
|
|
|
actions[action].call(this.actions, data, response); |
|
|
|
} |
|
|
|
} |
|
|
@ -623,9 +629,9 @@ PdfStreamConverter.prototype = { |
|
|
|
var domWindow = getDOMWindow(channel); |
|
|
|
var domWindow = getDOMWindow(channel); |
|
|
|
// Double check the url is still the correct one.
|
|
|
|
// Double check the url is still the correct one.
|
|
|
|
if (domWindow.document.documentURIObject.equals(aRequest.URI)) { |
|
|
|
if (domWindow.document.documentURIObject.equals(aRequest.URI)) { |
|
|
|
let actions = new ChromeActions(domWindow, dataListener, |
|
|
|
var actions = new ChromeActions(domWindow, dataListener, |
|
|
|
contentDispositionFilename); |
|
|
|
contentDispositionFilename); |
|
|
|
let requestListener = new RequestListener(actions); |
|
|
|
var requestListener = new RequestListener(actions); |
|
|
|
domWindow.addEventListener(PDFJS_EVENT_ID, function(event) { |
|
|
|
domWindow.addEventListener(PDFJS_EVENT_ID, function(event) { |
|
|
|
requestListener.receive(event); |
|
|
|
requestListener.receive(event); |
|
|
|
}, false, true); |
|
|
|
}, false, true); |
|
|
|