зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1334363 - Update pdf.js to version 1.7.227. r=bdahl
This commit is contained in:
Родитель
988ca917d4
Коммит
2ca2a9b0df
|
@ -1,3 +1,3 @@
|
|||
This is the pdf.js project output, https://github.com/mozilla/pdf.js
|
||||
|
||||
Current extension version is: 1.6.467
|
||||
Current extension version is: 1.7.227
|
||||
|
|
|
@ -21,30 +21,14 @@ Components.utils.import('resource://gre/modules/Services.jsm');
|
|||
var EXPORTED_SYMBOLS = ['NetworkManager'];
|
||||
|
||||
function log(aMsg) {
|
||||
var msg = 'network.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
||||
var msg = 'PdfJsNetwork.jsm: ' + (aMsg.join ? aMsg.join('') : aMsg);
|
||||
Services.console.logStringMessage(msg);
|
||||
}
|
||||
|
||||
var NetworkManager = (function NetworkManagerClosure() {
|
||||
|
||||
var OK_RESPONSE = 200;
|
||||
var PARTIAL_CONTENT_RESPONSE = 206;
|
||||
|
||||
function NetworkManager(url, args) {
|
||||
this.url = url;
|
||||
args = args || {};
|
||||
this.isHttp = /^https?:/i.test(url);
|
||||
this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
|
||||
this.withCredentials = args.withCredentials || false;
|
||||
this.getXhr = args.getXhr ||
|
||||
function NetworkManager_getXhr() {
|
||||
return new XMLHttpRequest();
|
||||
};
|
||||
|
||||
this.currXhrId = 0;
|
||||
this.pendingRequests = Object.create(null);
|
||||
this.loadedRequests = Object.create(null);
|
||||
}
|
||||
const OK_RESPONSE = 200;
|
||||
const PARTIAL_CONTENT_RESPONSE = 206;
|
||||
|
||||
function getArrayBuffer(xhr) {
|
||||
var data = xhr.response;
|
||||
|
@ -59,27 +43,43 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||
return array.buffer;
|
||||
}
|
||||
|
||||
NetworkManager.prototype = {
|
||||
requestRange: function NetworkManager_requestRange(begin, end, listeners) {
|
||||
class NetworkManagerClass {
|
||||
constructor(url, args) {
|
||||
this.url = url;
|
||||
args = args || {};
|
||||
this.isHttp = /^https?:/i.test(url);
|
||||
this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
|
||||
this.withCredentials = args.withCredentials || false;
|
||||
this.getXhr = args.getXhr ||
|
||||
function NetworkManager_getXhr() {
|
||||
return new XMLHttpRequest();
|
||||
};
|
||||
|
||||
this.currXhrId = 0;
|
||||
this.pendingRequests = Object.create(null);
|
||||
this.loadedRequests = Object.create(null);
|
||||
}
|
||||
|
||||
requestRange(begin, end, listeners) {
|
||||
var args = {
|
||||
begin: begin,
|
||||
end: end
|
||||
begin,
|
||||
end,
|
||||
};
|
||||
for (var prop in listeners) {
|
||||
args[prop] = listeners[prop];
|
||||
}
|
||||
return this.request(args);
|
||||
},
|
||||
}
|
||||
|
||||
requestFull: function NetworkManager_requestFull(listeners) {
|
||||
requestFull(listeners) {
|
||||
return this.request(listeners);
|
||||
},
|
||||
}
|
||||
|
||||
request: function NetworkManager_request(args) {
|
||||
request(args) {
|
||||
var xhr = this.getXhr();
|
||||
var xhrId = this.currXhrId++;
|
||||
var pendingRequest = this.pendingRequests[xhrId] = {
|
||||
xhr: xhr
|
||||
xhr,
|
||||
};
|
||||
|
||||
xhr.open('GET', this.url);
|
||||
|
@ -124,9 +124,9 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||
xhr.send(null);
|
||||
|
||||
return xhrId;
|
||||
},
|
||||
}
|
||||
|
||||
onProgress: function NetworkManager_onProgress(xhrId, evt) {
|
||||
onProgress(xhrId, evt) {
|
||||
var pendingRequest = this.pendingRequests[xhrId];
|
||||
if (!pendingRequest) {
|
||||
// Maybe abortRequest was called...
|
||||
|
@ -142,9 +142,9 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||
if (onProgress) {
|
||||
onProgress(evt);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
|
||||
onStateChange(xhrId, evt) {
|
||||
var pendingRequest = this.pendingRequests[xhrId];
|
||||
if (!pendingRequest) {
|
||||
// Maybe abortRequest was called...
|
||||
|
@ -201,57 +201,57 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||
var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
|
||||
var begin = parseInt(matches[1], 10);
|
||||
pendingRequest.onDone({
|
||||
begin: begin,
|
||||
chunk: chunk
|
||||
begin,
|
||||
chunk,
|
||||
});
|
||||
} else if (pendingRequest.onProgressiveData) {
|
||||
pendingRequest.onDone(null);
|
||||
} else if (chunk) {
|
||||
pendingRequest.onDone({
|
||||
begin: 0,
|
||||
chunk: chunk
|
||||
chunk,
|
||||
});
|
||||
} else if (pendingRequest.onError) {
|
||||
pendingRequest.onError(xhr.status);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
hasPendingRequests: function NetworkManager_hasPendingRequests() {
|
||||
hasPendingRequests() {
|
||||
for (var xhrId in this.pendingRequests) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}
|
||||
|
||||
getRequestXhr: function NetworkManager_getXhr(xhrId) {
|
||||
getRequestXhr(xhrId) {
|
||||
return this.pendingRequests[xhrId].xhr;
|
||||
},
|
||||
}
|
||||
|
||||
isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
|
||||
isStreamingRequest(xhrId) {
|
||||
return !!(this.pendingRequests[xhrId].onProgressiveData);
|
||||
},
|
||||
}
|
||||
|
||||
isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
|
||||
isPendingRequest(xhrId) {
|
||||
return xhrId in this.pendingRequests;
|
||||
},
|
||||
}
|
||||
|
||||
isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
|
||||
isLoadedRequest(xhrId) {
|
||||
return xhrId in this.loadedRequests;
|
||||
},
|
||||
}
|
||||
|
||||
abortAllRequests: function NetworkManager_abortAllRequests() {
|
||||
abortAllRequests() {
|
||||
for (var xhrId in this.pendingRequests) {
|
||||
this.abortRequest(xhrId | 0);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
abortRequest: function NetworkManager_abortRequest(xhrId) {
|
||||
abortRequest(xhrId) {
|
||||
var xhr = this.pendingRequests[xhrId].xhr;
|
||||
delete this.pendingRequests[xhrId];
|
||||
xhr.abort();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return NetworkManager;
|
||||
return NetworkManagerClass;
|
||||
})();
|
||||
|
||||
|
|
|
@ -23,47 +23,47 @@ const Cu = Components.utils;
|
|||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
|
||||
this.PdfJsTelemetry = {
|
||||
onViewerIsUsed: function () {
|
||||
onViewerIsUsed() {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_USED');
|
||||
histogram.add(true);
|
||||
},
|
||||
onFallback: function () {
|
||||
onFallback() {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FALLBACK_SHOWN');
|
||||
histogram.add(true);
|
||||
},
|
||||
onDocumentSize: function (size) {
|
||||
onDocumentSize(size) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_SIZE_KB');
|
||||
histogram.add(size / 1024);
|
||||
},
|
||||
onDocumentVersion: function (versionId) {
|
||||
onDocumentVersion(versionId) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_VERSION');
|
||||
histogram.add(versionId);
|
||||
},
|
||||
onDocumentGenerator: function (generatorId) {
|
||||
onDocumentGenerator(generatorId) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_GENERATOR');
|
||||
histogram.add(generatorId);
|
||||
},
|
||||
onEmbed: function (isObject) {
|
||||
onEmbed(isObject) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_EMBED');
|
||||
histogram.add(isObject);
|
||||
},
|
||||
onFontType: function (fontTypeId) {
|
||||
onFontType(fontTypeId) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FONT_TYPES');
|
||||
histogram.add(fontTypeId);
|
||||
},
|
||||
onForm: function (isAcroform) {
|
||||
onForm(isAcroform) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FORM');
|
||||
histogram.add(isAcroform);
|
||||
},
|
||||
onPrint: function () {
|
||||
onPrint() {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_PRINT');
|
||||
histogram.add(true);
|
||||
},
|
||||
onStreamType: function (streamTypeId) {
|
||||
onStreamType(streamTypeId) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_STREAM_TYPES');
|
||||
histogram.add(streamTypeId);
|
||||
},
|
||||
onTimeToView: function (ms) {
|
||||
onTimeToView(ms) {
|
||||
let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_TIME_TO_VIEW_MS');
|
||||
histogram.add(ms);
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ PdfDataListener.prototype = {
|
|||
this.oncompleteCallback(null, errorCode);
|
||||
}
|
||||
},
|
||||
onprogress: function() {},
|
||||
onprogress() {},
|
||||
get oncomplete() {
|
||||
return this.oncompleteCallback;
|
||||
},
|
||||
|
@ -205,24 +205,27 @@ PdfDataListener.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
// All the priviledged actions.
|
||||
function ChromeActions(domWindow, contentDispositionFilename) {
|
||||
this.domWindow = domWindow;
|
||||
this.contentDispositionFilename = contentDispositionFilename;
|
||||
this.telemetryState = {
|
||||
documentInfo: false,
|
||||
firstPageInfo: false,
|
||||
streamTypesUsed: [],
|
||||
fontTypesUsed: [],
|
||||
startAt: Date.now()
|
||||
};
|
||||
}
|
||||
/**
|
||||
* All the privileged actions.
|
||||
*/
|
||||
class ChromeActions {
|
||||
constructor(domWindow, contentDispositionFilename) {
|
||||
this.domWindow = domWindow;
|
||||
this.contentDispositionFilename = contentDispositionFilename;
|
||||
this.telemetryState = {
|
||||
documentInfo: false,
|
||||
firstPageInfo: false,
|
||||
streamTypesUsed: [],
|
||||
fontTypesUsed: [],
|
||||
startAt: Date.now()
|
||||
};
|
||||
}
|
||||
|
||||
ChromeActions.prototype = {
|
||||
isInPrivateBrowsing: function() {
|
||||
isInPrivateBrowsing() {
|
||||
return PrivateBrowsingUtils.isContentWindowPrivate(this.domWindow);
|
||||
},
|
||||
download: function(data, sendResponse) {
|
||||
}
|
||||
|
||||
download(data, sendResponse) {
|
||||
var self = this;
|
||||
var originalUrl = data.originalUrl;
|
||||
var blobUrl = data.blobUrl || originalUrl;
|
||||
|
@ -279,7 +282,7 @@ ChromeActions.prototype = {
|
|||
|
||||
var listener = {
|
||||
extListener: null,
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
onStartRequest(aRequest, aContext) {
|
||||
var loadContext = self.domWindow
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
|
@ -290,7 +293,7 @@ ChromeActions.prototype = {
|
|||
aRequest, loadContext, false);
|
||||
this.extListener.onStartRequest(aRequest, aContext);
|
||||
},
|
||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
if (this.extListener) {
|
||||
this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
|
||||
}
|
||||
|
@ -299,20 +302,21 @@ ChromeActions.prototype = {
|
|||
sendResponse(false);
|
||||
}
|
||||
},
|
||||
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset,
|
||||
aCount) {
|
||||
this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
|
||||
onDataAvailable(aRequest, aContext, aDataInputStream, aOffset, aCount) {
|
||||
this.extListener.onDataAvailable(aRequest, aContext, aDataInputStream,
|
||||
aOffset, aCount);
|
||||
}
|
||||
};
|
||||
|
||||
channel.asyncOpen2(listener);
|
||||
});
|
||||
},
|
||||
getLocale: function() {
|
||||
}
|
||||
|
||||
getLocale() {
|
||||
return getStringPref('general.useragent.locale', 'en-US');
|
||||
},
|
||||
getStrings: function(data) {
|
||||
}
|
||||
|
||||
getStrings(data) {
|
||||
try {
|
||||
// Lazy initialization of localizedStrings
|
||||
if (!('localizedStrings' in this)) {
|
||||
|
@ -324,8 +328,9 @@ ChromeActions.prototype = {
|
|||
log('Unable to retrieve localized strings: ' + e);
|
||||
return 'null';
|
||||
}
|
||||
},
|
||||
supportsIntegratedFind: function() {
|
||||
}
|
||||
|
||||
supportsIntegratedFind() {
|
||||
// Integrated find is only supported when we're not in a frame
|
||||
if (this.domWindow.frameElement !== null) {
|
||||
return false;
|
||||
|
@ -339,22 +344,26 @@ ChromeActions.prototype = {
|
|||
// ... or when the new find events code exists.
|
||||
var findBar = getFindBar(this.domWindow);
|
||||
return !!findBar && ('updateControlState' in findBar);
|
||||
},
|
||||
supportsDocumentFonts: function() {
|
||||
}
|
||||
|
||||
supportsDocumentFonts() {
|
||||
var prefBrowser = getIntPref('browser.display.use_document_fonts', 1);
|
||||
var prefGfx = getBoolPref('gfx.downloadable_fonts.enabled', true);
|
||||
return (!!prefBrowser && prefGfx);
|
||||
},
|
||||
supportsDocumentColors: function() {
|
||||
}
|
||||
|
||||
supportsDocumentColors() {
|
||||
return getIntPref('browser.display.document_color_use', 0) !== 2;
|
||||
},
|
||||
supportedMouseWheelZoomModifierKeys: function() {
|
||||
}
|
||||
|
||||
supportedMouseWheelZoomModifierKeys() {
|
||||
return {
|
||||
ctrlKey: getIntPref('mousewheel.with_control.action', 3) === 3,
|
||||
metaKey: getIntPref('mousewheel.with_meta.action', 1) === 3,
|
||||
};
|
||||
},
|
||||
reportTelemetry: function (data) {
|
||||
}
|
||||
|
||||
reportTelemetry(data) {
|
||||
var probeInfo = JSON.parse(data);
|
||||
switch (probeInfo.type) {
|
||||
case 'documentInfo':
|
||||
|
@ -409,12 +418,15 @@ ChromeActions.prototype = {
|
|||
PdfJsTelemetry.onPrint();
|
||||
break;
|
||||
}
|
||||
},
|
||||
fallback: function(args, sendResponse) {
|
||||
var featureId = args.featureId;
|
||||
var url = args.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} args - Object with `featureId` and `url` properties.
|
||||
* @param {function} sendResponse - Callback function.
|
||||
*/
|
||||
fallback(args, sendResponse) {
|
||||
var featureId = args.featureId;
|
||||
|
||||
var self = this;
|
||||
var domWindow = this.domWindow;
|
||||
var strings = getLocalizedStrings('chrome.properties');
|
||||
var message;
|
||||
|
@ -441,8 +453,9 @@ ChromeActions.prototype = {
|
|||
winmm.removeMessageListener('PDFJS:Child:fallbackDownload',
|
||||
fallbackDownload);
|
||||
});
|
||||
},
|
||||
updateFindControlState: function(data) {
|
||||
}
|
||||
|
||||
updateFindControlState(data) {
|
||||
if (!this.supportsIntegratedFind()) {
|
||||
return;
|
||||
}
|
||||
|
@ -461,8 +474,9 @@ ChromeActions.prototype = {
|
|||
.getInterface(Ci.nsIContentFrameMessageManager);
|
||||
|
||||
winmm.sendAsyncMessage('PDFJS:Parent:updateControlState', data);
|
||||
},
|
||||
setPreferences: function(prefs, sendResponse) {
|
||||
}
|
||||
|
||||
setPreferences(prefs, sendResponse) {
|
||||
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + '.');
|
||||
var numberOfPrefs = 0;
|
||||
var prefValue, prefName;
|
||||
|
@ -496,8 +510,9 @@ ChromeActions.prototype = {
|
|||
if (sendResponse) {
|
||||
sendResponse(true);
|
||||
}
|
||||
},
|
||||
getPreferences: function(prefs, sendResponse) {
|
||||
}
|
||||
|
||||
getPreferences(prefs, sendResponse) {
|
||||
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + '.');
|
||||
var currentPrefs = {}, numberOfPrefs = 0;
|
||||
var prefValue, prefName;
|
||||
|
@ -529,17 +544,16 @@ ChromeActions.prototype = {
|
|||
return JSON.stringify(currentPrefs);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var RangedChromeActions = (function RangedChromeActionsClosure() {
|
||||
/**
|
||||
* This is for range requests
|
||||
*/
|
||||
function RangedChromeActions(
|
||||
domWindow, contentDispositionFilename, originalRequest,
|
||||
/**
|
||||
* This is for range requests.
|
||||
*/
|
||||
class RangedChromeActions extends ChromeActions {
|
||||
constructor(domWindow, contentDispositionFilename, originalRequest,
|
||||
rangeEnabled, streamingEnabled, dataListener) {
|
||||
|
||||
ChromeActions.call(this, domWindow, contentDispositionFilename);
|
||||
super(domWindow, contentDispositionFilename);
|
||||
this.dataListener = dataListener;
|
||||
this.originalRequest = originalRequest;
|
||||
this.rangeEnabled = rangeEnabled;
|
||||
|
@ -551,7 +565,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||
// Pass all the headers from the original request through
|
||||
var httpHeaderVisitor = {
|
||||
headers: {},
|
||||
visitHeader: function(aHeader, aValue) {
|
||||
visitHeader(aHeader, aValue) {
|
||||
if (aHeader === 'Range') {
|
||||
// When loading the PDF from cache, firefox seems to set the Range
|
||||
// request header to fetch only the unfetched portions of the file
|
||||
|
@ -587,7 +601,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||
|
||||
this.networkManager = new NetworkManager(this.pdfUrl, {
|
||||
httpHeaders: httpHeaderVisitor.headers,
|
||||
getXhr: getXhr
|
||||
getXhr,
|
||||
});
|
||||
|
||||
// If we are in range request mode, this means we manually issued xhr
|
||||
|
@ -598,12 +612,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||
});
|
||||
}
|
||||
|
||||
RangedChromeActions.prototype = Object.create(ChromeActions.prototype);
|
||||
var proto = RangedChromeActions.prototype;
|
||||
proto.constructor = RangedChromeActions;
|
||||
|
||||
proto.initPassiveLoading = function RangedChromeActions_initPassiveLoading() {
|
||||
var self = this;
|
||||
initPassiveLoading() {
|
||||
var data;
|
||||
if (!this.streamingEnabled) {
|
||||
this.originalRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||
|
@ -613,16 +622,16 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||
} else {
|
||||
data = this.dataListener.readData();
|
||||
|
||||
this.dataListener.onprogress = function (loaded, total) {
|
||||
self.domWindow.postMessage({
|
||||
this.dataListener.onprogress = (loaded, total) => {
|
||||
this.domWindow.postMessage({
|
||||
pdfjsLoadAction: 'progressiveRead',
|
||||
loaded: loaded,
|
||||
total: total,
|
||||
chunk: self.dataListener.readData()
|
||||
loaded,
|
||||
total,
|
||||
chunk: this.dataListener.readData(),
|
||||
}, '*');
|
||||
};
|
||||
this.dataListener.oncomplete = function () {
|
||||
self.dataListener = null;
|
||||
this.dataListener.oncomplete = () => {
|
||||
this.dataListener = null;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -632,13 +641,13 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||
streamingEnabled: this.streamingEnabled,
|
||||
pdfUrl: this.pdfUrl,
|
||||
length: this.contentLength,
|
||||
data: data
|
||||
data,
|
||||
}, '*');
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
proto.requestDataRange = function RangedChromeActions_requestDataRange(args) {
|
||||
requestDataRange(args) {
|
||||
if (!this.rangeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
@ -650,11 +659,11 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||
// errors from chrome code for non-range requests, so this doesn't
|
||||
// seem high-pri
|
||||
this.networkManager.requestRange(begin, end, {
|
||||
onDone: function RangedChromeActions_onDone(args) {
|
||||
onDone: function RangedChromeActions_onDone(aArgs) {
|
||||
domWindow.postMessage({
|
||||
pdfjsLoadAction: 'range',
|
||||
begin: args.begin,
|
||||
chunk: args.chunk
|
||||
begin: aArgs.begin,
|
||||
chunk: aArgs.chunk,
|
||||
}, '*');
|
||||
},
|
||||
onProgress: function RangedChromeActions_onProgress(evt) {
|
||||
|
@ -664,162 +673,155 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||
}, '*');
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
proto.abortLoading = function RangedChromeActions_abortLoading() {
|
||||
abortLoading() {
|
||||
this.networkManager.abortAllRequests();
|
||||
if (this.originalRequest) {
|
||||
this.originalRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||
this.originalRequest = null;
|
||||
}
|
||||
this.dataListener = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return RangedChromeActions;
|
||||
})();
|
||||
|
||||
var StandardChromeActions = (function StandardChromeActionsClosure() {
|
||||
|
||||
/**
|
||||
* This is for a single network stream
|
||||
*/
|
||||
function StandardChromeActions(domWindow, contentDispositionFilename,
|
||||
originalRequest, dataListener) {
|
||||
|
||||
ChromeActions.call(this, domWindow, contentDispositionFilename);
|
||||
/**
|
||||
* This is for a single network stream.
|
||||
*/
|
||||
class StandardChromeActions extends ChromeActions {
|
||||
constructor(domWindow, contentDispositionFilename, originalRequest,
|
||||
dataListener) {
|
||||
super(domWindow, contentDispositionFilename);
|
||||
this.originalRequest = originalRequest;
|
||||
this.dataListener = dataListener;
|
||||
}
|
||||
|
||||
StandardChromeActions.prototype = Object.create(ChromeActions.prototype);
|
||||
var proto = StandardChromeActions.prototype;
|
||||
proto.constructor = StandardChromeActions;
|
||||
|
||||
proto.initPassiveLoading =
|
||||
function StandardChromeActions_initPassiveLoading() {
|
||||
|
||||
initPassiveLoading() {
|
||||
if (!this.dataListener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
this.dataListener.onprogress = function ChromeActions_dataListenerProgress(
|
||||
loaded, total) {
|
||||
self.domWindow.postMessage({
|
||||
this.dataListener.onprogress = (loaded, total) => {
|
||||
this.domWindow.postMessage({
|
||||
pdfjsLoadAction: 'progress',
|
||||
loaded: loaded,
|
||||
total: total
|
||||
loaded,
|
||||
total,
|
||||
}, '*');
|
||||
};
|
||||
|
||||
this.dataListener.oncomplete =
|
||||
function StandardChromeActions_dataListenerComplete(data, errorCode) {
|
||||
self.domWindow.postMessage({
|
||||
this.dataListener.oncomplete = (data, errorCode) => {
|
||||
this.domWindow.postMessage({
|
||||
pdfjsLoadAction: 'complete',
|
||||
data: data,
|
||||
errorCode: errorCode
|
||||
data,
|
||||
errorCode,
|
||||
}, '*');
|
||||
|
||||
self.dataListener = null;
|
||||
self.originalRequest = null;
|
||||
this.dataListener = null;
|
||||
this.originalRequest = null;
|
||||
};
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
proto.abortLoading = function StandardChromeActions_abortLoading() {
|
||||
abortLoading() {
|
||||
if (this.originalRequest) {
|
||||
this.originalRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||
this.originalRequest = null;
|
||||
}
|
||||
this.dataListener = null;
|
||||
};
|
||||
|
||||
return StandardChromeActions;
|
||||
})();
|
||||
|
||||
// Event listener to trigger chrome privileged code.
|
||||
function RequestListener(actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
// Receive an event and synchronously or asynchronously responds.
|
||||
RequestListener.prototype.receive = function(event) {
|
||||
var message = event.target;
|
||||
var doc = message.ownerDocument;
|
||||
var action = event.detail.action;
|
||||
var data = event.detail.data;
|
||||
var sync = event.detail.sync;
|
||||
var actions = this.actions;
|
||||
if (!(action in actions)) {
|
||||
log('Unknown action: ' + action);
|
||||
return;
|
||||
}
|
||||
var response;
|
||||
if (sync) {
|
||||
response = actions[action].call(this.actions, data);
|
||||
event.detail.response = Cu.cloneInto(response, doc.defaultView);
|
||||
} else {
|
||||
if (!event.detail.responseExpected) {
|
||||
doc.documentElement.removeChild(message);
|
||||
response = null;
|
||||
} else {
|
||||
response = function sendResponse(response) {
|
||||
try {
|
||||
var listener = doc.createEvent('CustomEvent');
|
||||
let detail = Cu.cloneInto({ response: response }, doc.defaultView);
|
||||
listener.initCustomEvent('pdf.js.response', true, false, detail);
|
||||
return message.dispatchEvent(listener);
|
||||
} catch (e) {
|
||||
// doc is no longer accessible because the requestor is already
|
||||
// gone. unloaded content cannot receive the response anyway.
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener to trigger chrome privileged code.
|
||||
*/
|
||||
class RequestListener {
|
||||
constructor(actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
// Receive an event and synchronously or asynchronously responds.
|
||||
receive(event) {
|
||||
var message = event.target;
|
||||
var doc = message.ownerDocument;
|
||||
var action = event.detail.action;
|
||||
var data = event.detail.data;
|
||||
var sync = event.detail.sync;
|
||||
var actions = this.actions;
|
||||
if (!(action in actions)) {
|
||||
log('Unknown action: ' + action);
|
||||
return;
|
||||
}
|
||||
var response;
|
||||
if (sync) {
|
||||
response = actions[action].call(this.actions, data);
|
||||
event.detail.response = Cu.cloneInto(response, doc.defaultView);
|
||||
} else {
|
||||
if (!event.detail.responseExpected) {
|
||||
doc.documentElement.removeChild(message);
|
||||
response = null;
|
||||
} else {
|
||||
response = function sendResponse(aResponse) {
|
||||
try {
|
||||
var listener = doc.createEvent('CustomEvent');
|
||||
let detail = Cu.cloneInto({ response: aResponse }, doc.defaultView);
|
||||
listener.initCustomEvent('pdf.js.response', true, false, detail);
|
||||
return message.dispatchEvent(listener);
|
||||
} catch (e) {
|
||||
// doc is no longer accessible because the requestor is already
|
||||
// gone. unloaded content cannot receive the response anyway.
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
actions[action].call(this.actions, data, response);
|
||||
}
|
||||
actions[action].call(this.actions, data, response);
|
||||
}
|
||||
};
|
||||
|
||||
// Forwards events from the eventElement to the contentWindow only if the
|
||||
// content window matches the currently selected browser window.
|
||||
function FindEventManager(contentWindow) {
|
||||
this.contentWindow = contentWindow;
|
||||
this.winmm = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDocShell)
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIContentFrameMessageManager);
|
||||
}
|
||||
|
||||
FindEventManager.prototype.bind = function() {
|
||||
var unload = function(e) {
|
||||
this.unbind();
|
||||
this.contentWindow.removeEventListener(e.type, unload);
|
||||
}.bind(this);
|
||||
this.contentWindow.addEventListener('unload', unload);
|
||||
/**
|
||||
* Forwards events from the eventElement to the contentWindow only if the
|
||||
* content window matches the currently selected browser window.
|
||||
*/
|
||||
class FindEventManager {
|
||||
constructor(contentWindow) {
|
||||
this.contentWindow = contentWindow;
|
||||
this.winmm = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDocShell)
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIContentFrameMessageManager);
|
||||
}
|
||||
|
||||
// We cannot directly attach listeners to for the find events
|
||||
// since the FindBar is in the parent process. Instead we're
|
||||
// asking the PdfjsChromeUtils to do it for us and forward
|
||||
// all the find events to us.
|
||||
this.winmm.sendAsyncMessage('PDFJS:Parent:addEventListener');
|
||||
this.winmm.addMessageListener('PDFJS:Child:handleEvent', this);
|
||||
};
|
||||
bind() {
|
||||
var unload = function(e) {
|
||||
this.unbind();
|
||||
this.contentWindow.removeEventListener(e.type, unload);
|
||||
}.bind(this);
|
||||
this.contentWindow.addEventListener('unload', unload);
|
||||
|
||||
FindEventManager.prototype.receiveMessage = function(msg) {
|
||||
var detail = msg.data.detail;
|
||||
var type = msg.data.type;
|
||||
var contentWindow = this.contentWindow;
|
||||
// We cannot directly attach listeners to for the find events
|
||||
// since the FindBar is in the parent process. Instead we're
|
||||
// asking the PdfjsChromeUtils to do it for us and forward
|
||||
// all the find events to us.
|
||||
this.winmm.sendAsyncMessage('PDFJS:Parent:addEventListener');
|
||||
this.winmm.addMessageListener('PDFJS:Child:handleEvent', this);
|
||||
}
|
||||
|
||||
detail = Cu.cloneInto(detail, contentWindow);
|
||||
var forward = contentWindow.document.createEvent('CustomEvent');
|
||||
forward.initCustomEvent(type, true, true, detail);
|
||||
contentWindow.dispatchEvent(forward);
|
||||
};
|
||||
receiveMessage(msg) {
|
||||
var detail = msg.data.detail;
|
||||
var type = msg.data.type;
|
||||
var contentWindow = this.contentWindow;
|
||||
|
||||
FindEventManager.prototype.unbind = function() {
|
||||
this.winmm.sendAsyncMessage('PDFJS:Parent:removeEventListener');
|
||||
};
|
||||
detail = Cu.cloneInto(detail, contentWindow);
|
||||
var forward = contentWindow.document.createEvent('CustomEvent');
|
||||
forward.initCustomEvent(type, true, true, detail);
|
||||
contentWindow.dispatchEvent(forward);
|
||||
}
|
||||
|
||||
unbind() {
|
||||
this.winmm.sendAsyncMessage('PDFJS:Parent:removeEventListener');
|
||||
}
|
||||
}
|
||||
|
||||
function PdfStreamConverter() {
|
||||
}
|
||||
|
@ -858,18 +860,18 @@ PdfStreamConverter.prototype = {
|
|||
*/
|
||||
|
||||
// nsIStreamConverter::convert
|
||||
convert: function(aFromStream, aFromType, aToType, aCtxt) {
|
||||
convert(aFromStream, aFromType, aToType, aCtxt) {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
|
||||
// nsIStreamConverter::asyncConvertData
|
||||
asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
|
||||
asyncConvertData(aFromType, aToType, aListener, aCtxt) {
|
||||
// Store the listener passed to us
|
||||
this.listener = aListener;
|
||||
},
|
||||
|
||||
// nsIStreamListener::onDataAvailable
|
||||
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
if (!this.dataListener) {
|
||||
return;
|
||||
}
|
||||
|
@ -881,7 +883,7 @@ PdfStreamConverter.prototype = {
|
|||
},
|
||||
|
||||
// nsIRequestObserver::onStartRequest
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
onStartRequest(aRequest, aContext) {
|
||||
// Setup the request so we can use it below.
|
||||
var isHttpRequest = false;
|
||||
try {
|
||||
|
@ -960,14 +962,14 @@ PdfStreamConverter.prototype = {
|
|||
// request(aRequest) below so we don't overwrite the original channel and
|
||||
// trigger an assertion.
|
||||
var proxy = {
|
||||
onStartRequest: function(request, context) {
|
||||
onStartRequest(request, context) {
|
||||
listener.onStartRequest(aRequest, aContext);
|
||||
},
|
||||
onDataAvailable: function(request, context, inputStream, offset, count) {
|
||||
onDataAvailable(request, context, inputStream, offset, count) {
|
||||
listener.onDataAvailable(aRequest, aContext, inputStream,
|
||||
offset, count);
|
||||
},
|
||||
onStopRequest: function(request, context, statusCode) {
|
||||
onStopRequest(request, context, statusCode) {
|
||||
// We get the DOM window here instead of before the request since it
|
||||
// may have changed during a redirect.
|
||||
var domWindow = getDOMWindow(channel);
|
||||
|
@ -1017,7 +1019,7 @@ PdfStreamConverter.prototype = {
|
|||
},
|
||||
|
||||
// nsIRequestObserver::onStopRequest
|
||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
if (!this.dataListener) {
|
||||
// Do nothing
|
||||
return;
|
||||
|
|
|
@ -67,7 +67,7 @@ var PdfjsChromeUtils = {
|
|||
* Public API
|
||||
*/
|
||||
|
||||
init: function () {
|
||||
init() {
|
||||
this._browsers = new WeakSet();
|
||||
if (!this._ppmm) {
|
||||
// global parent process message manager (PPMM)
|
||||
|
@ -94,7 +94,7 @@ var PdfjsChromeUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
uninit: function () {
|
||||
uninit() {
|
||||
if (this._ppmm) {
|
||||
this._ppmm.removeMessageListener('PDFJS:Parent:clearUserPref', this);
|
||||
this._ppmm.removeMessageListener('PDFJS:Parent:setIntPref', this);
|
||||
|
@ -123,7 +123,7 @@ var PdfjsChromeUtils = {
|
|||
* instruct the child to refresh its configuration and (possibly)
|
||||
* the module's registration.
|
||||
*/
|
||||
notifyChildOfSettingsChange: function () {
|
||||
notifyChildOfSettingsChange() {
|
||||
if (Services.appinfo.processType ===
|
||||
Services.appinfo.PROCESS_TYPE_DEFAULT && this._ppmm) {
|
||||
// XXX kinda bad, we want to get the parent process mm associated
|
||||
|
@ -139,13 +139,13 @@ var PdfjsChromeUtils = {
|
|||
* Events
|
||||
*/
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
observe(aSubject, aTopic, aData) {
|
||||
if (aTopic === 'quit-application') {
|
||||
this.uninit();
|
||||
}
|
||||
},
|
||||
|
||||
receiveMessage: function (aMsg) {
|
||||
receiveMessage(aMsg) {
|
||||
switch (aMsg.name) {
|
||||
case 'PDFJS:Parent:clearUserPref':
|
||||
this._clearUserPref(aMsg.data.name);
|
||||
|
@ -182,20 +182,20 @@ var PdfjsChromeUtils = {
|
|||
* Internal
|
||||
*/
|
||||
|
||||
_findbarFromMessage: function(aMsg) {
|
||||
_findbarFromMessage(aMsg) {
|
||||
let browser = aMsg.target;
|
||||
let tabbrowser = browser.getTabBrowser();
|
||||
let tab = tabbrowser.getTabForBrowser(browser);
|
||||
return tabbrowser.getFindBar(tab);
|
||||
},
|
||||
|
||||
_updateControlState: function (aMsg) {
|
||||
_updateControlState(aMsg) {
|
||||
let data = aMsg.data;
|
||||
this._findbarFromMessage(aMsg)
|
||||
.updateControlState(data.result, data.findPrevious);
|
||||
},
|
||||
|
||||
handleEvent: function(aEvent) {
|
||||
handleEvent(aEvent) {
|
||||
// To avoid forwarding the message as a CPOW, create a structured cloneable
|
||||
// version of the event for both performance, and ease of usage, reasons.
|
||||
let type = aEvent.type;
|
||||
|
@ -213,8 +213,7 @@ var PdfjsChromeUtils = {
|
|||
}
|
||||
// Only forward the events if the current browser is a registered browser.
|
||||
let mm = browser.messageManager;
|
||||
mm.sendAsyncMessage('PDFJS:Child:handleEvent',
|
||||
{ type: type, detail: detail });
|
||||
mm.sendAsyncMessage('PDFJS:Child:handleEvent', { type, detail, });
|
||||
aEvent.preventDefault();
|
||||
},
|
||||
|
||||
|
@ -223,7 +222,7 @@ var PdfjsChromeUtils = {
|
|||
'findhighlightallchange',
|
||||
'findcasesensitivitychange'],
|
||||
|
||||
_addEventListener: function (aMsg) {
|
||||
_addEventListener(aMsg) {
|
||||
let browser = aMsg.target;
|
||||
if (this._browsers.has(browser)) {
|
||||
throw new Error('FindEventManager was bound 2nd time ' +
|
||||
|
@ -242,7 +241,7 @@ var PdfjsChromeUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
_removeEventListener: function (aMsg) {
|
||||
_removeEventListener(aMsg) {
|
||||
let browser = aMsg.target;
|
||||
if (!this._browsers.has(browser)) {
|
||||
throw new Error('FindEventManager was unbound without binding it first.');
|
||||
|
@ -258,7 +257,7 @@ var PdfjsChromeUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
_ensurePreferenceAllowed: function (aPrefName) {
|
||||
_ensurePreferenceAllowed(aPrefName) {
|
||||
let unPrefixedName = aPrefName.split(PREF_PREFIX + '.');
|
||||
if (unPrefixedName[0] !== '' ||
|
||||
this._allowedPrefNames.indexOf(unPrefixedName[1]) === -1) {
|
||||
|
@ -268,27 +267,27 @@ var PdfjsChromeUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
_clearUserPref: function (aPrefName) {
|
||||
_clearUserPref(aPrefName) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.clearUserPref(aPrefName);
|
||||
},
|
||||
|
||||
_setIntPref: function (aPrefName, aPrefValue) {
|
||||
_setIntPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.setIntPref(aPrefName, aPrefValue);
|
||||
},
|
||||
|
||||
_setBoolPref: function (aPrefName, aPrefValue) {
|
||||
_setBoolPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.setBoolPref(aPrefName, aPrefValue);
|
||||
},
|
||||
|
||||
_setCharPref: function (aPrefName, aPrefValue) {
|
||||
_setCharPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.setCharPref(aPrefName, aPrefValue);
|
||||
},
|
||||
|
||||
_setStringPref: function (aPrefName, aPrefValue) {
|
||||
_setStringPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
let str = Cc['@mozilla.org/supports-string;1']
|
||||
.createInstance(Ci.nsISupportsString);
|
||||
|
@ -301,7 +300,7 @@ var PdfjsChromeUtils = {
|
|||
* we bounce this pdfjs enabled configuration check over to the
|
||||
* parent.
|
||||
*/
|
||||
isDefaultHandlerApp: function () {
|
||||
isDefaultHandlerApp() {
|
||||
var handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, 'pdf');
|
||||
return (!handlerInfo.alwaysAskBeforeHandling &&
|
||||
handlerInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally);
|
||||
|
@ -311,7 +310,7 @@ var PdfjsChromeUtils = {
|
|||
* Display a notification warning when the renderer isn't sure
|
||||
* a pdf displayed correctly.
|
||||
*/
|
||||
_displayWarning: function (aMsg) {
|
||||
_displayWarning(aMsg) {
|
||||
let data = aMsg.data;
|
||||
let browser = aMsg.target;
|
||||
|
||||
|
@ -324,13 +323,12 @@ var PdfjsChromeUtils = {
|
|||
let messageSent = false;
|
||||
function sendMessage(download) {
|
||||
let mm = browser.messageManager;
|
||||
mm.sendAsyncMessage('PDFJS:Child:fallbackDownload',
|
||||
{ download: download });
|
||||
mm.sendAsyncMessage('PDFJS:Child:fallbackDownload', { download, });
|
||||
}
|
||||
let buttons = [{
|
||||
label: data.label,
|
||||
accessKey: data.accessKey,
|
||||
callback: function() {
|
||||
callback() {
|
||||
messageSent = true;
|
||||
sendMessage(true);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ var PdfjsContentUtils = {
|
|||
Services.appinfo.PROCESS_TYPE_CONTENT);
|
||||
},
|
||||
|
||||
init: function () {
|
||||
init() {
|
||||
// child *process* mm, or when loaded into the parent for in-content
|
||||
// support the psuedo child process mm 'child PPMM'.
|
||||
if (!this._mm) {
|
||||
|
@ -49,7 +49,7 @@ var PdfjsContentUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
uninit: function () {
|
||||
uninit() {
|
||||
if (this._mm) {
|
||||
this._mm.removeMessageListener('PDFJS:Child:refreshSettings', this);
|
||||
Services.obs.removeObserver(this, 'quit-application');
|
||||
|
@ -63,34 +63,34 @@ var PdfjsContentUtils = {
|
|||
* approved pdfjs prefs in chrome utils.
|
||||
*/
|
||||
|
||||
clearUserPref: function (aPrefName) {
|
||||
clearUserPref(aPrefName) {
|
||||
this._mm.sendSyncMessage('PDFJS:Parent:clearUserPref', {
|
||||
name: aPrefName
|
||||
});
|
||||
},
|
||||
|
||||
setIntPref: function (aPrefName, aPrefValue) {
|
||||
setIntPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage('PDFJS:Parent:setIntPref', {
|
||||
name: aPrefName,
|
||||
value: aPrefValue
|
||||
});
|
||||
},
|
||||
|
||||
setBoolPref: function (aPrefName, aPrefValue) {
|
||||
setBoolPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage('PDFJS:Parent:setBoolPref', {
|
||||
name: aPrefName,
|
||||
value: aPrefValue
|
||||
});
|
||||
},
|
||||
|
||||
setCharPref: function (aPrefName, aPrefValue) {
|
||||
setCharPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage('PDFJS:Parent:setCharPref', {
|
||||
name: aPrefName,
|
||||
value: aPrefValue
|
||||
});
|
||||
},
|
||||
|
||||
setStringPref: function (aPrefName, aPrefValue) {
|
||||
setStringPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage('PDFJS:Parent:setStringPref', {
|
||||
name: aPrefName,
|
||||
value: aPrefValue
|
||||
|
@ -101,7 +101,7 @@ var PdfjsContentUtils = {
|
|||
* Forwards default app query to the parent where we check various
|
||||
* handler app settings only available in the parent process.
|
||||
*/
|
||||
isDefaultHandlerApp: function () {
|
||||
isDefaultHandlerApp() {
|
||||
return this._mm.sendSyncMessage('PDFJS:Parent:isDefaultHandlerApp')[0];
|
||||
},
|
||||
|
||||
|
@ -109,7 +109,7 @@ var PdfjsContentUtils = {
|
|||
* Request the display of a notification warning in the associated window
|
||||
* when the renderer isn't sure a pdf displayed correctly.
|
||||
*/
|
||||
displayWarning: function (aWindow, aMessage, aLabel, accessKey) {
|
||||
displayWarning(aWindow, aMessage, aLabel, aAccessKey) {
|
||||
// the child's dom frame mm associated with the window.
|
||||
let winmm = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDocShell)
|
||||
|
@ -118,7 +118,7 @@ var PdfjsContentUtils = {
|
|||
winmm.sendAsyncMessage('PDFJS:Parent:displayWarning', {
|
||||
message: aMessage,
|
||||
label: aLabel,
|
||||
accessKey: accessKey
|
||||
accessKey: aAccessKey,
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -126,13 +126,13 @@ var PdfjsContentUtils = {
|
|||
* Events
|
||||
*/
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
observe(aSubject, aTopic, aData) {
|
||||
if (aTopic === 'quit-application') {
|
||||
this.uninit();
|
||||
}
|
||||
},
|
||||
|
||||
receiveMessage: function (aMsg) {
|
||||
receiveMessage(aMsg) {
|
||||
switch (aMsg.name) {
|
||||
case 'PDFJS:Child:refreshSettings':
|
||||
// Only react to this if we are remote.
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
}
|
||||
}(this, function (exports) {
|
||||
'use strict';
|
||||
var pdfjsVersion = '1.6.467';
|
||||
var pdfjsBuild = '54d55e8b';
|
||||
var pdfjsVersion = '1.7.227';
|
||||
var pdfjsBuild = 'e132fa97';
|
||||
var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
|
||||
var pdfjsLibs = {};
|
||||
(function pdfjsWrapper() {
|
||||
|
@ -1434,6 +1434,7 @@
|
|||
var warn = sharedUtil.warn;
|
||||
var deprecated = sharedUtil.deprecated;
|
||||
var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
|
||||
var DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
||||
var CustomStyle = function CustomStyleClosure() {
|
||||
var prefixes = [
|
||||
'ms',
|
||||
|
@ -1559,7 +1560,7 @@
|
|||
globalSettings.externalLinkTarget = LinkTarget.NONE;
|
||||
return LinkTarget.NONE;
|
||||
case 'externalLinkRel':
|
||||
return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
|
||||
return globalSettings ? globalSettings.externalLinkRel : DEFAULT_LINK_REL;
|
||||
case 'enableStats':
|
||||
return !!(globalSettings && globalSettings.enableStats);
|
||||
default:
|
||||
|
@ -1591,6 +1592,7 @@
|
|||
exports.LinkTarget = LinkTarget;
|
||||
exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
|
||||
exports.getDefaultSetting = getDefaultSetting;
|
||||
exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
|
||||
}));
|
||||
(function (root, factory) {
|
||||
factory(root.pdfjsDisplayFontLoader = {}, root.pdfjsSharedUtil);
|
||||
|
@ -5084,15 +5086,13 @@
|
|||
}
|
||||
return pattern;
|
||||
},
|
||||
setStrokeColorN: function CanvasGraphics_setStrokeColorN()
|
||||
{
|
||||
this.current.strokeColor = this.getColorN_Pattern(arguments);
|
||||
},
|
||||
setFillColorN: function CanvasGraphics_setFillColorN()
|
||||
{
|
||||
this.current.fillColor = this.getColorN_Pattern(arguments);
|
||||
this.current.patternFill = true;
|
||||
},
|
||||
setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
|
||||
this.current.strokeColor = this.getColorN_Pattern(arguments);
|
||||
},
|
||||
setFillColorN: function CanvasGraphics_setFillColorN() {
|
||||
this.current.fillColor = this.getColorN_Pattern(arguments);
|
||||
this.current.patternFill = true;
|
||||
},
|
||||
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
|
||||
var color = Util.makeCssRgb(r, g, b);
|
||||
this.ctx.strokeStyle = color;
|
||||
|
@ -6824,7 +6824,7 @@
|
|||
return;
|
||||
}
|
||||
if (this.task.onContinue) {
|
||||
this.task.onContinue.call(this.task, this._scheduleNextBound);
|
||||
this.task.onContinue(this._scheduleNextBound);
|
||||
} else {
|
||||
this._scheduleNext();
|
||||
}
|
||||
|
@ -6886,6 +6886,7 @@
|
|||
var deprecated = sharedUtil.deprecated;
|
||||
var warn = sharedUtil.warn;
|
||||
var LinkTarget = displayDOMUtils.LinkTarget;
|
||||
var DEFAULT_LINK_REL = displayDOMUtils.DEFAULT_LINK_REL;
|
||||
var isWorker = typeof window === 'undefined';
|
||||
if (!globalScope.PDFJS) {
|
||||
globalScope.PDFJS = {};
|
||||
|
@ -6953,7 +6954,7 @@
|
|||
PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL;
|
||||
PDFJS.disableWebGL = PDFJS.disableWebGL === undefined ? true : PDFJS.disableWebGL;
|
||||
PDFJS.externalLinkTarget = PDFJS.externalLinkTarget === undefined ? LinkTarget.NONE : PDFJS.externalLinkTarget;
|
||||
PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? 'noreferrer' : PDFJS.externalLinkRel;
|
||||
PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? DEFAULT_LINK_REL : PDFJS.externalLinkRel;
|
||||
PDFJS.isEvalSupported = PDFJS.isEvalSupported === undefined ? true : PDFJS.isEvalSupported;
|
||||
PDFJS.getDocument = displayAPI.getDocument;
|
||||
PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
}
|
||||
}(this, function (exports) {
|
||||
'use strict';
|
||||
var pdfjsVersion = '1.6.467';
|
||||
var pdfjsBuild = '54d55e8b';
|
||||
var pdfjsVersion = '1.7.227';
|
||||
var pdfjsBuild = 'e132fa97';
|
||||
var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
|
||||
var pdfjsLibs = {};
|
||||
(function pdfjsWrapper() {
|
||||
|
@ -38197,7 +38197,7 @@
|
|||
var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
|
||||
if (op >= 0x71 && op <= 0x75) {
|
||||
n = stack.pop();
|
||||
if (n === n) {
|
||||
if (!isNaN(n)) {
|
||||
stackDelta = -n * 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,617 +0,0 @@
|
|||
/* Copyright 2012 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// NOTE: Be careful what goes in this file, as it is also used from the context
|
||||
// of the addon. So using warn/error in here will break the addon.
|
||||
|
||||
'use strict';
|
||||
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define('pdfjs/core/network', ['exports', 'pdfjs/shared/util',
|
||||
'pdfjs/core/worker'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
factory(exports, require('../shared/util.js'), require('./worker.js'));
|
||||
} else {
|
||||
factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
|
||||
root.pdfjsCoreWorker);
|
||||
}
|
||||
}(this, function (exports, sharedUtil, coreWorker) {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
throw new Error('Module "pdfjs/core/network" shall not ' +
|
||||
'be used with FIREFOX or MOZCENTRAL build.');
|
||||
}
|
||||
|
||||
var OK_RESPONSE = 200;
|
||||
var PARTIAL_CONTENT_RESPONSE = 206;
|
||||
|
||||
function NetworkManager(url, args) {
|
||||
this.url = url;
|
||||
args = args || {};
|
||||
this.isHttp = /^https?:/i.test(url);
|
||||
this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
|
||||
this.withCredentials = args.withCredentials || false;
|
||||
this.getXhr = args.getXhr ||
|
||||
function NetworkManager_getXhr() {
|
||||
return new XMLHttpRequest();
|
||||
};
|
||||
|
||||
this.currXhrId = 0;
|
||||
this.pendingRequests = Object.create(null);
|
||||
this.loadedRequests = Object.create(null);
|
||||
}
|
||||
|
||||
function getArrayBuffer(xhr) {
|
||||
var data = xhr.response;
|
||||
if (typeof data !== 'string') {
|
||||
return data;
|
||||
}
|
||||
var length = data.length;
|
||||
var array = new Uint8Array(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
array[i] = data.charCodeAt(i) & 0xFF;
|
||||
}
|
||||
return array.buffer;
|
||||
}
|
||||
|
||||
var supportsMozChunked =
|
||||
typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME') ? false :
|
||||
(function supportsMozChunkedClosure() {
|
||||
try {
|
||||
var x = new XMLHttpRequest();
|
||||
// Firefox 37- required .open() to be called before setting responseType.
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=707484
|
||||
// Even though the URL is not visited, .open() could fail if the URL is
|
||||
// blocked, e.g. via the connect-src CSP directive or the NoScript addon.
|
||||
// When this error occurs, this feature detection method will mistakenly
|
||||
// report that moz-chunked-arraybuffer is not supported in Firefox 37-.
|
||||
x.open('GET', 'https://example.com');
|
||||
x.responseType = 'moz-chunked-arraybuffer';
|
||||
return x.responseType === 'moz-chunked-arraybuffer';
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
NetworkManager.prototype = {
|
||||
requestRange: function NetworkManager_requestRange(begin, end, listeners) {
|
||||
var args = {
|
||||
begin: begin,
|
||||
end: end
|
||||
};
|
||||
for (var prop in listeners) {
|
||||
args[prop] = listeners[prop];
|
||||
}
|
||||
return this.request(args);
|
||||
},
|
||||
|
||||
requestFull: function NetworkManager_requestFull(listeners) {
|
||||
return this.request(listeners);
|
||||
},
|
||||
|
||||
request: function NetworkManager_request(args) {
|
||||
var xhr = this.getXhr();
|
||||
var xhrId = this.currXhrId++;
|
||||
var pendingRequest = this.pendingRequests[xhrId] = {
|
||||
xhr: xhr
|
||||
};
|
||||
|
||||
xhr.open('GET', this.url);
|
||||
xhr.withCredentials = this.withCredentials;
|
||||
for (var property in this.httpHeaders) {
|
||||
var value = this.httpHeaders[property];
|
||||
if (typeof value === 'undefined') {
|
||||
continue;
|
||||
}
|
||||
xhr.setRequestHeader(property, value);
|
||||
}
|
||||
if (this.isHttp && 'begin' in args && 'end' in args) {
|
||||
var rangeStr = args.begin + '-' + (args.end - 1);
|
||||
xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
|
||||
pendingRequest.expectedStatus = 206;
|
||||
} else {
|
||||
pendingRequest.expectedStatus = 200;
|
||||
}
|
||||
|
||||
var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
|
||||
if (useMozChunkedLoading) {
|
||||
xhr.responseType = 'moz-chunked-arraybuffer';
|
||||
pendingRequest.onProgressiveData = args.onProgressiveData;
|
||||
pendingRequest.mozChunked = true;
|
||||
} else {
|
||||
xhr.responseType = 'arraybuffer';
|
||||
}
|
||||
|
||||
if (args.onError) {
|
||||
xhr.onerror = function(evt) {
|
||||
args.onError(xhr.status);
|
||||
};
|
||||
}
|
||||
xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
|
||||
xhr.onprogress = this.onProgress.bind(this, xhrId);
|
||||
|
||||
pendingRequest.onHeadersReceived = args.onHeadersReceived;
|
||||
pendingRequest.onDone = args.onDone;
|
||||
pendingRequest.onError = args.onError;
|
||||
pendingRequest.onProgress = args.onProgress;
|
||||
|
||||
xhr.send(null);
|
||||
|
||||
return xhrId;
|
||||
},
|
||||
|
||||
onProgress: function NetworkManager_onProgress(xhrId, evt) {
|
||||
var pendingRequest = this.pendingRequests[xhrId];
|
||||
if (!pendingRequest) {
|
||||
// Maybe abortRequest was called...
|
||||
return;
|
||||
}
|
||||
|
||||
if (pendingRequest.mozChunked) {
|
||||
var chunk = getArrayBuffer(pendingRequest.xhr);
|
||||
pendingRequest.onProgressiveData(chunk);
|
||||
}
|
||||
|
||||
var onProgress = pendingRequest.onProgress;
|
||||
if (onProgress) {
|
||||
onProgress(evt);
|
||||
}
|
||||
},
|
||||
|
||||
onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
|
||||
var pendingRequest = this.pendingRequests[xhrId];
|
||||
if (!pendingRequest) {
|
||||
// Maybe abortRequest was called...
|
||||
return;
|
||||
}
|
||||
|
||||
var xhr = pendingRequest.xhr;
|
||||
if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
|
||||
pendingRequest.onHeadersReceived();
|
||||
delete pendingRequest.onHeadersReceived;
|
||||
}
|
||||
|
||||
if (xhr.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(xhrId in this.pendingRequests)) {
|
||||
// The XHR request might have been aborted in onHeadersReceived()
|
||||
// callback, in which case we should abort request
|
||||
return;
|
||||
}
|
||||
|
||||
delete this.pendingRequests[xhrId];
|
||||
|
||||
// success status == 0 can be on ftp, file and other protocols
|
||||
if (xhr.status === 0 && this.isHttp) {
|
||||
if (pendingRequest.onError) {
|
||||
pendingRequest.onError(xhr.status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var xhrStatus = xhr.status || OK_RESPONSE;
|
||||
|
||||
// From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
|
||||
// "A server MAY ignore the Range header". This means it's possible to
|
||||
// get a 200 rather than a 206 response from a range request.
|
||||
var ok_response_on_range_request =
|
||||
xhrStatus === OK_RESPONSE &&
|
||||
pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
|
||||
|
||||
if (!ok_response_on_range_request &&
|
||||
xhrStatus !== pendingRequest.expectedStatus) {
|
||||
if (pendingRequest.onError) {
|
||||
pendingRequest.onError(xhr.status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadedRequests[xhrId] = true;
|
||||
|
||||
var chunk = getArrayBuffer(xhr);
|
||||
if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
|
||||
var rangeHeader = xhr.getResponseHeader('Content-Range');
|
||||
var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
|
||||
var begin = parseInt(matches[1], 10);
|
||||
pendingRequest.onDone({
|
||||
begin: begin,
|
||||
chunk: chunk
|
||||
});
|
||||
} else if (pendingRequest.onProgressiveData) {
|
||||
pendingRequest.onDone(null);
|
||||
} else if (chunk) {
|
||||
pendingRequest.onDone({
|
||||
begin: 0,
|
||||
chunk: chunk
|
||||
});
|
||||
} else if (pendingRequest.onError) {
|
||||
pendingRequest.onError(xhr.status);
|
||||
}
|
||||
},
|
||||
|
||||
hasPendingRequests: function NetworkManager_hasPendingRequests() {
|
||||
for (var xhrId in this.pendingRequests) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
getRequestXhr: function NetworkManager_getXhr(xhrId) {
|
||||
return this.pendingRequests[xhrId].xhr;
|
||||
},
|
||||
|
||||
isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
|
||||
return !!(this.pendingRequests[xhrId].onProgressiveData);
|
||||
},
|
||||
|
||||
isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
|
||||
return xhrId in this.pendingRequests;
|
||||
},
|
||||
|
||||
isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
|
||||
return xhrId in this.loadedRequests;
|
||||
},
|
||||
|
||||
abortAllRequests: function NetworkManager_abortAllRequests() {
|
||||
for (var xhrId in this.pendingRequests) {
|
||||
this.abortRequest(xhrId | 0);
|
||||
}
|
||||
},
|
||||
|
||||
abortRequest: function NetworkManager_abortRequest(xhrId) {
|
||||
var xhr = this.pendingRequests[xhrId].xhr;
|
||||
delete this.pendingRequests[xhrId];
|
||||
xhr.abort();
|
||||
}
|
||||
};
|
||||
|
||||
var assert = sharedUtil.assert;
|
||||
var createPromiseCapability = sharedUtil.createPromiseCapability;
|
||||
var isInt = sharedUtil.isInt;
|
||||
var MissingPDFException = sharedUtil.MissingPDFException;
|
||||
var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
|
||||
|
||||
/** @implements {IPDFStream} */
|
||||
function PDFNetworkStream(options) {
|
||||
this._options = options;
|
||||
var source = options.source;
|
||||
this._manager = new NetworkManager(source.url, {
|
||||
httpHeaders: source.httpHeaders,
|
||||
withCredentials: source.withCredentials
|
||||
});
|
||||
this._rangeChunkSize = source.rangeChunkSize;
|
||||
this._fullRequestReader = null;
|
||||
this._rangeRequestReaders = [];
|
||||
}
|
||||
|
||||
PDFNetworkStream.prototype = {
|
||||
_onRangeRequestReaderClosed:
|
||||
function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
|
||||
var i = this._rangeRequestReaders.indexOf(reader);
|
||||
if (i >= 0) {
|
||||
this._rangeRequestReaders.splice(i, 1);
|
||||
}
|
||||
},
|
||||
|
||||
getFullReader: function PDFNetworkStream_getFullReader() {
|
||||
assert(!this._fullRequestReader);
|
||||
this._fullRequestReader =
|
||||
new PDFNetworkStreamFullRequestReader(this._manager, this._options);
|
||||
return this._fullRequestReader;
|
||||
},
|
||||
|
||||
getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
|
||||
var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
|
||||
begin, end);
|
||||
reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
|
||||
this._rangeRequestReaders.push(reader);
|
||||
return reader;
|
||||
},
|
||||
|
||||
cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
|
||||
if (this._fullRequestReader) {
|
||||
this._fullRequestReader.cancel(reason);
|
||||
}
|
||||
var readers = this._rangeRequestReaders.slice(0);
|
||||
readers.forEach(function (reader) {
|
||||
reader.cancel(reason);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/** @implements {IPDFStreamReader} */
|
||||
function PDFNetworkStreamFullRequestReader(manager, options) {
|
||||
this._manager = manager;
|
||||
|
||||
var source = options.source;
|
||||
var args = {
|
||||
onHeadersReceived: this._onHeadersReceived.bind(this),
|
||||
onProgressiveData: source.disableStream ? null :
|
||||
this._onProgressiveData.bind(this),
|
||||
onDone: this._onDone.bind(this),
|
||||
onError: this._onError.bind(this),
|
||||
onProgress: this._onProgress.bind(this)
|
||||
};
|
||||
this._url = source.url;
|
||||
this._fullRequestId = manager.requestFull(args);
|
||||
this._headersReceivedCapability = createPromiseCapability();
|
||||
this._disableRange = options.disableRange || false;
|
||||
this._contentLength = source.length; // optional
|
||||
this._rangeChunkSize = source.rangeChunkSize;
|
||||
if (!this._rangeChunkSize && !this._disableRange) {
|
||||
this._disableRange = true;
|
||||
}
|
||||
|
||||
this._isStreamingSupported = false;
|
||||
this._isRangeSupported = false;
|
||||
|
||||
this._cachedChunks = [];
|
||||
this._requests = [];
|
||||
this._done = false;
|
||||
this._storedError = undefined;
|
||||
|
||||
this.onProgress = null;
|
||||
}
|
||||
|
||||
PDFNetworkStreamFullRequestReader.prototype = {
|
||||
_validateRangeRequestCapabilities: function
|
||||
PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
|
||||
|
||||
if (this._disableRange) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var networkManager = this._manager;
|
||||
if (!networkManager.isHttp) {
|
||||
return false;
|
||||
}
|
||||
var fullRequestXhrId = this._fullRequestId;
|
||||
var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
|
||||
if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var contentEncoding =
|
||||
fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
|
||||
if (contentEncoding !== 'identity') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var length = fullRequestXhr.getResponseHeader('Content-Length');
|
||||
length = parseInt(length, 10);
|
||||
if (!isInt(length)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._contentLength = length; // setting right content length
|
||||
|
||||
if (length <= 2 * this._rangeChunkSize) {
|
||||
// The file size is smaller than the size of two chunks, so it does
|
||||
// not make any sense to abort the request and retry with a range
|
||||
// request.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
_onHeadersReceived:
|
||||
function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
|
||||
|
||||
if (this._validateRangeRequestCapabilities()) {
|
||||
this._isRangeSupported = true;
|
||||
}
|
||||
|
||||
var networkManager = this._manager;
|
||||
var fullRequestXhrId = this._fullRequestId;
|
||||
if (networkManager.isStreamingRequest(fullRequestXhrId)) {
|
||||
// We can continue fetching when progressive loading is enabled,
|
||||
// and we don't need the autoFetch feature.
|
||||
this._isStreamingSupported = true;
|
||||
} else if (this._isRangeSupported) {
|
||||
// NOTE: by cancelling the full request, and then issuing range
|
||||
// requests, there will be an issue for sites where you can only
|
||||
// request the pdf once. However, if this is the case, then the
|
||||
// server should not be returning that it can support range
|
||||
// requests.
|
||||
networkManager.abortRequest(fullRequestXhrId);
|
||||
}
|
||||
|
||||
this._headersReceivedCapability.resolve();
|
||||
},
|
||||
|
||||
_onProgressiveData:
|
||||
function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
|
||||
if (this._requests.length > 0) {
|
||||
var requestCapability = this._requests.shift();
|
||||
requestCapability.resolve({value: chunk, done: false});
|
||||
} else {
|
||||
this._cachedChunks.push(chunk);
|
||||
}
|
||||
},
|
||||
|
||||
_onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
|
||||
if (args) {
|
||||
this._onProgressiveData(args.chunk);
|
||||
}
|
||||
this._done = true;
|
||||
if (this._cachedChunks.length > 0) {
|
||||
return;
|
||||
}
|
||||
this._requests.forEach(function (requestCapability) {
|
||||
requestCapability.resolve({value: undefined, done: true});
|
||||
});
|
||||
this._requests = [];
|
||||
},
|
||||
|
||||
_onError: function PDFNetworkStreamFullRequestReader_onError(status) {
|
||||
var url = this._url;
|
||||
var exception;
|
||||
if (status === 404 || status === 0 && /^file:/.test(url)) {
|
||||
exception = new MissingPDFException('Missing PDF "' + url + '".');
|
||||
} else {
|
||||
exception = new UnexpectedResponseException(
|
||||
'Unexpected server response (' + status +
|
||||
') while retrieving PDF "' + url + '".', status);
|
||||
}
|
||||
this._storedError = exception;
|
||||
this._headersReceivedCapability.reject(exception);
|
||||
this._requests.forEach(function (requestCapability) {
|
||||
requestCapability.reject(exception);
|
||||
});
|
||||
this._requests = [];
|
||||
this._cachedChunks = [];
|
||||
},
|
||||
|
||||
_onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
|
||||
if (this.onProgress) {
|
||||
this.onProgress({
|
||||
loaded: data.loaded,
|
||||
total: data.lengthComputable ? data.total : this._contentLength
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get isRangeSupported() {
|
||||
return this._isRangeSupported;
|
||||
},
|
||||
|
||||
get isStreamingSupported() {
|
||||
return this._isStreamingSupported;
|
||||
},
|
||||
|
||||
get contentLength() {
|
||||
return this._contentLength;
|
||||
},
|
||||
|
||||
get headersReady() {
|
||||
return this._headersReceivedCapability.promise;
|
||||
},
|
||||
|
||||
read: function PDFNetworkStreamFullRequestReader_read() {
|
||||
if (this._storedError) {
|
||||
return Promise.reject(this._storedError);
|
||||
}
|
||||
if (this._cachedChunks.length > 0) {
|
||||
var chunk = this._cachedChunks.shift();
|
||||
return Promise.resolve(chunk);
|
||||
}
|
||||
if (this._done) {
|
||||
return Promise.resolve({value: undefined, done: true});
|
||||
}
|
||||
var requestCapability = createPromiseCapability();
|
||||
this._requests.push(requestCapability);
|
||||
return requestCapability.promise;
|
||||
},
|
||||
|
||||
cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
|
||||
this._done = true;
|
||||
this._headersReceivedCapability.reject(reason);
|
||||
this._requests.forEach(function (requestCapability) {
|
||||
requestCapability.resolve({value: undefined, done: true});
|
||||
});
|
||||
this._requests = [];
|
||||
if (this._manager.isPendingRequest(this._fullRequestId)) {
|
||||
this._manager.abortRequest(this._fullRequestId);
|
||||
}
|
||||
this._fullRequestReader = null;
|
||||
}
|
||||
};
|
||||
|
||||
/** @implements {IPDFStreamRangeReader} */
|
||||
function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
|
||||
this._manager = manager;
|
||||
var args = {
|
||||
onDone: this._onDone.bind(this),
|
||||
onProgress: this._onProgress.bind(this)
|
||||
};
|
||||
this._requestId = manager.requestRange(begin, end, args);
|
||||
this._requests = [];
|
||||
this._queuedChunk = null;
|
||||
this._done = false;
|
||||
|
||||
this.onProgress = null;
|
||||
this.onClosed = null;
|
||||
}
|
||||
|
||||
PDFNetworkStreamRangeRequestReader.prototype = {
|
||||
_close: function PDFNetworkStreamRangeRequestReader_close() {
|
||||
if (this.onClosed) {
|
||||
this.onClosed(this);
|
||||
}
|
||||
},
|
||||
|
||||
_onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
|
||||
var chunk = data.chunk;
|
||||
if (this._requests.length > 0) {
|
||||
var requestCapability = this._requests.shift();
|
||||
requestCapability.resolve({value: chunk, done: false});
|
||||
} else {
|
||||
this._queuedChunk = chunk;
|
||||
}
|
||||
this._done = true;
|
||||
this._requests.forEach(function (requestCapability) {
|
||||
requestCapability.resolve({value: undefined, done: true});
|
||||
});
|
||||
this._requests = [];
|
||||
this._close();
|
||||
},
|
||||
|
||||
_onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
|
||||
if (!this.isStreamingSupported && this.onProgress) {
|
||||
this.onProgress({
|
||||
loaded: evt.loaded
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get isStreamingSupported() {
|
||||
return false; // TODO allow progressive range bytes loading
|
||||
},
|
||||
|
||||
read: function PDFNetworkStreamRangeRequestReader_read() {
|
||||
if (this._queuedChunk !== null) {
|
||||
var chunk = this._queuedChunk;
|
||||
this._queuedChunk = null;
|
||||
return Promise.resolve({value: chunk, done: false});
|
||||
}
|
||||
if (this._done) {
|
||||
return Promise.resolve({value: undefined, done: true});
|
||||
}
|
||||
var requestCapability = createPromiseCapability();
|
||||
this._requests.push(requestCapability);
|
||||
return requestCapability.promise;
|
||||
},
|
||||
|
||||
cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
|
||||
this._done = true;
|
||||
this._requests.forEach(function (requestCapability) {
|
||||
requestCapability.resolve({value: undefined, done: true});
|
||||
});
|
||||
this._requests = [];
|
||||
if (this._manager.isPendingRequest(this._requestId)) {
|
||||
this._manager.abortRequest(this._requestId);
|
||||
}
|
||||
this._close();
|
||||
}
|
||||
};
|
||||
|
||||
coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
|
||||
|
||||
exports.PDFNetworkStream = PDFNetworkStream;
|
||||
exports.NetworkManager = NetworkManager;
|
||||
}));
|
||||
|
|
@ -121,12 +121,12 @@
|
|||
get: translateString,
|
||||
|
||||
// get the document language
|
||||
getLanguage: function() {
|
||||
getLanguage() {
|
||||
return gLanguage;
|
||||
},
|
||||
|
||||
// get the direction (ltr|rtl) of the current language
|
||||
getDirection: function() {
|
||||
getDirection() {
|
||||
// http://www.w3.org/International/questions/qa-scripts
|
||||
// Arabic, Hebrew, Farsi, Pashto, Urdu
|
||||
var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
|
||||
|
@ -137,9 +137,11 @@
|
|||
return (rtlList.indexOf(shortCode) >= 0) ? 'rtl' : 'ltr';
|
||||
},
|
||||
|
||||
getReadyState: function() { return gReadyState; },
|
||||
getReadyState() {
|
||||
return gReadyState;
|
||||
},
|
||||
|
||||
setExternalLocalizerServices: function (externalLocalizerServices) {
|
||||
setExternalLocalizerServices(externalLocalizerServices) {
|
||||
gExternalLocalizerServices = externalLocalizerServices;
|
||||
|
||||
// ... in case if we missed DOMContentLoaded above.
|
||||
|
|
|
@ -2478,8 +2478,8 @@ var pdfjsWebLibs;
|
|||
};
|
||||
this.anchor = anchor;
|
||||
var div = document.createElement('div');
|
||||
div.id = 'thumbnailContainer' + id;
|
||||
div.className = 'thumbnail';
|
||||
div.setAttribute('data-page-number', this.id);
|
||||
this.div = div;
|
||||
if (id === 1) {
|
||||
div.classList.add('selected');
|
||||
|
@ -3873,7 +3873,7 @@ var pdfjsWebLibs;
|
|||
this.annotationLayerFactory = annotationLayerFactory;
|
||||
this.renderer = options.renderer || RendererType.CANVAS;
|
||||
this.paintTask = null;
|
||||
this.paintedViewport = null;
|
||||
this.paintedViewportMap = new WeakMap();
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.resume = null;
|
||||
this.error = null;
|
||||
|
@ -3883,7 +3883,6 @@ var pdfjsWebLibs;
|
|||
this.zoomLayer = null;
|
||||
this.annotationLayer = null;
|
||||
var div = document.createElement('div');
|
||||
div.id = 'pageContainer' + this.id;
|
||||
div.className = 'page';
|
||||
div.style.width = Math.floor(this.viewport.width) + 'px';
|
||||
div.style.height = Math.floor(this.viewport.height) + 'px';
|
||||
|
@ -3929,16 +3928,15 @@ var pdfjsWebLibs;
|
|||
this.annotationLayer = null;
|
||||
}
|
||||
if (this.canvas && !currentZoomLayerNode) {
|
||||
this.paintedViewportMap.delete(this.canvas);
|
||||
this.canvas.width = 0;
|
||||
this.canvas.height = 0;
|
||||
delete this.canvas;
|
||||
}
|
||||
if (this.svg) {
|
||||
this.paintedViewportMap.delete(this.svg);
|
||||
delete this.svg;
|
||||
}
|
||||
if (!currentZoomLayerNode) {
|
||||
this.paintedViewport = null;
|
||||
}
|
||||
this.loadingIconDiv = document.createElement('div');
|
||||
this.loadingIconDiv.className = 'loadingIcon';
|
||||
div.appendChild(this.loadingIconDiv);
|
||||
|
@ -4013,7 +4011,7 @@ var pdfjsWebLibs;
|
|||
var div = this.div;
|
||||
target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + 'px';
|
||||
target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + 'px';
|
||||
var relativeRotation = this.viewport.rotation - this.paintedViewport.rotation;
|
||||
var relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
|
||||
var absRotation = Math.abs(relativeRotation);
|
||||
var scaleX = 1, scaleY = 1;
|
||||
if (absRotation === 90 || absRotation === 270) {
|
||||
|
@ -4131,6 +4129,7 @@ var pdfjsWebLibs;
|
|||
}
|
||||
if (self.zoomLayer) {
|
||||
var zoomLayerCanvas = self.zoomLayer.firstChild;
|
||||
self.paintedViewportMap.delete(zoomLayerCanvas);
|
||||
zoomLayerCanvas.width = 0;
|
||||
zoomLayerCanvas.height = 0;
|
||||
if (div.contains(self.zoomLayer)) {
|
||||
|
@ -4238,7 +4237,7 @@ var pdfjsWebLibs;
|
|||
canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
|
||||
canvas.style.width = roundToDivide(viewport.width, sfx[1]) + 'px';
|
||||
canvas.style.height = roundToDivide(viewport.height, sfy[1]) + 'px';
|
||||
this.paintedViewport = viewport;
|
||||
this.paintedViewportMap.set(canvas, viewport);
|
||||
var transform = !outputScale.scaled ? null : [
|
||||
outputScale.sx,
|
||||
0,
|
||||
|
@ -4324,7 +4323,7 @@ var pdfjsWebLibs;
|
|||
if (selected) {
|
||||
selected.classList.remove('selected');
|
||||
}
|
||||
var thumbnail = document.getElementById('thumbnailContainer' + page);
|
||||
var thumbnail = document.querySelector('div.thumbnail[data-page-number="' + page + '"]');
|
||||
if (thumbnail) {
|
||||
thumbnail.classList.add('selected');
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче