Merge pull request #6698 from yurydelendik/rm-UnsupportedManager

[api-minor] Replaces UnsupportedManager with callback.
This commit is contained in:
Brendan Dahl 2015-12-02 10:57:44 -08:00
commit 376788f2b2
7 changed files with 66 additions and 47 deletions

View File

@ -19,9 +19,8 @@
MurmurHash3_64, Name, Parser, Pattern, PDFImage, PDFJS, serifFonts,
stdFontMap, symbolsFonts, getTilingPatternIR, warn, Util, Promise,
RefSetCache, isRef, TextRenderingMode, IdentityToUnicodeMap,
OPS, UNSUPPORTED_FEATURES, UnsupportedManager, NormalizedUnicodes,
IDENTITY_MATRIX, reverseIfRtl, createPromiseCapability, ToUnicodeMap,
getFontType */
OPS, UNSUPPORTED_FEATURES, NormalizedUnicodes, IDENTITY_MATRIX,
reverseIfRtl, createPromiseCapability, ToUnicodeMap, getFontType */
'use strict';
@ -322,6 +321,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
then(function () {
return translated;
}, function (reason) {
// Error in the font data -- sending unsupported feature notification.
self.handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.font});
return new TranslatedFont('g_font_error',
new ErrorFont('Type3 font load error: ' + reason), translated.font);
});
@ -546,6 +548,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
translatedPromise = Promise.reject(e);
}
var self = this;
translatedPromise.then(function (translatedFont) {
if (translatedFont.fontType !== undefined) {
var xrefFontStats = xref.stats.fontTypes;
@ -556,7 +559,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
translatedFont, font));
}, function (reason) {
// TODO fontCapability.reject?
UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
// Error in the font data -- sending unsupported feature notification.
self.handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.font});
try {
// error, but it's still nice to have font type reported
@ -609,7 +614,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} else if (typeNum === SHADING_PATTERN) {
var shading = dict.get('Shading');
var matrix = dict.get('Matrix');
pattern = Pattern.parseShading(shading, matrix, xref, resources);
pattern = Pattern.parseShading(shading, matrix, xref, resources,
this.handler);
operatorList.addOp(fn, pattern.getIR());
return Promise.resolve();
} else {
@ -846,7 +852,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
var shadingFill = Pattern.parseShading(shading, null, xref,
resources);
resources, self.handler);
var patternIR = shadingFill.getIR();
args = [patternIR];
fn = OPS.shadingFill;

View File

@ -13,8 +13,7 @@
* limitations under the License.
*/
/* globals ColorSpace, PDFFunction, Util, error, warn, info, isArray, isStream,
assert, isPDFFunction, UnsupportedManager, UNSUPPORTED_FEATURES,
MissingDataException */
assert, isPDFFunction, UNSUPPORTED_FEATURES, MissingDataException */
'use strict';
@ -43,7 +42,7 @@ var Pattern = (function PatternClosure() {
};
Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
res) {
res, handler) {
var dict = isStream(shading) ? shading.dict : shading;
var type = dict.get('ShadingType');
@ -66,7 +65,8 @@ var Pattern = (function PatternClosure() {
if (ex instanceof MissingDataException) {
throw ex;
}
UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.shadingPattern});
warn(ex);
return new Shadings.Dummy();
}

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
/* globals PDFJS, createPromiseCapability, LocalPdfManager, NetworkPdfManager,
NetworkManager, isInt, MissingPDFException,
NetworkManager, isInt, MissingPDFException, UNSUPPORTED_FEATURES,
UnexpectedResponseException, PasswordException, Promise, warn,
PasswordResponses, InvalidPDFException, UnknownErrorException,
XRefParseException, Ref, info, globalScope, error, MessageHandler */
@ -482,6 +482,11 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
return; // ignoring errors from the terminated thread
}
// For compatibility with older behavior, generating unknown
// unsupported feature notification on errors.
handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.unknown});
var minimumStackMessage =
'worker.js: while trying to getPage() and getOperatorList()';
@ -616,15 +621,6 @@ if (typeof window === 'undefined') {
globalScope.console = workerConsole;
}
// Listen for unsupported features so we can pass them on to the main thread.
PDFJS.UnsupportedManager.listen(function (msg) {
globalScope.postMessage({
targetName: 'main',
action: '_unsupported_feature',
data: msg
});
});
var handler = new MessageHandler('worker', 'main', this);
WorkerMessageHandler.setup(handler, this);
}

View File

@ -17,7 +17,7 @@
Promise, PasswordResponses, PasswordException, InvalidPDFException,
MissingPDFException, UnknownErrorException, FontFaceObject,
loadJpegStream, createScratchCanvas, CanvasGraphics, stringToBytes,
UnexpectedResponseException, deprecated, UnsupportedManager */
UnexpectedResponseException, deprecated */
'use strict';
@ -447,6 +447,12 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
* an {Object} with the properties: {number} loaded and {number} total.
*/
this.onProgress = null;
/**
* Callback to when unsupported feature is used. The callback receives
* an {PDFJS.UNSUPPORTED_FEATURES} argument.
*/
this.onUnsupportedFeature = null;
}
PDFDocumentLoadingTask.prototype =
@ -1214,9 +1220,6 @@ var PDFWorker = (function PDFWorkerClosure() {
messageHandler.on('console_error', function (data) {
console.error.apply(console, data);
});
messageHandler.on('_unsupported_feature', function (data) {
UnsupportedManager.notify(data);
});
var testObj = new Uint8Array([PDFJS.postMessageTransfers ? 255 : 0]);
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
@ -1584,6 +1587,19 @@ var WorkerTransport = (function WorkerTransportClosure() {
}
}, this);
messageHandler.on('UnsupportedFeature',
function transportUnsupportedFeature(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
var featureId = data.featureId;
var loadingTask = this.loadingTask;
if (loadingTask.onUnsupportedFeature) {
loadingTask.onUnsupportedFeature(featureId);
}
PDFJS.UnsupportedManager.notify(featureId);
}, this);
messageHandler.on('JpegDecode', function(data) {
if (this.destroyed) {
return Promise.reject('Worker was terminated');
@ -2000,3 +2016,23 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
return InternalRenderTask;
})();
/**
* (Deprecated) Global observer of unsupported feature usages. Use
* onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
*/
PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
var listeners = [];
return {
listen: function (cb) {
deprecated('Global UnsupportedManager.listen is used: ' +
' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
listeners.push(cb);
},
notify: function (featureId) {
for (var i = 0, ii = listeners.length; i < ii; i++) {
listeners[i](featureId);
}
}
};
})();

View File

@ -15,7 +15,7 @@
/* globals IDENTITY_MATRIX, FONT_IDENTITY_MATRIX, TextRenderingMode, ImageData,
ImageKind, PDFJS, Uint32ArrayView, error, WebGLUtils, OPS, warn,
shadow, isNum, Util, TilingPattern, getShadingPatternFromIR, isArray,
info, assert, UnsupportedManager, UNSUPPORTED_FEATURES */
info, assert */
'use strict';
@ -2092,7 +2092,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
},
paintXObject: function CanvasGraphics_paintXObject() {
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
warn('Unsupported \'paintXObject\' command.');
},

View File

@ -236,7 +236,6 @@ function error(msg) {
console.log('Error: ' + msg);
console.log(backtrace());
}
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
throw new Error(msg);
}
@ -263,22 +262,6 @@ var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
font: 'font'
};
var UnsupportedManager = PDFJS.UnsupportedManager =
(function UnsupportedManagerClosure() {
var listeners = [];
return {
listen: function (cb) {
listeners.push(cb);
},
notify: function (featureId) {
warn('Unsupported feature "' + featureId + '"');
for (var i = 0, ii = listeners.length; i < ii; i++) {
listeners[i](featureId);
}
}
};
})();
// Combines two URLs. The baseUrl shall be absolute URL. If the url is an
// absolute URL, it will be returned as is.
function combineUrl(baseUrl, url) {

View File

@ -599,6 +599,9 @@ var PDFViewerApplication = {
self.progress(progressData.loaded / progressData.total);
};
// Listen for unsupported features to trigger the fallback UI.
loadingTask.onUnsupportedFeature = this.fallback.bind(this);
var result = loadingTask.promise.then(
function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
@ -1465,10 +1468,6 @@ function webViewerInitialized() {
document.getElementById('viewFind').classList.add('hidden');
}
// Listen for unsupported features to trigger the fallback UI.
PDFJS.UnsupportedManager.listen(
PDFViewerApplication.fallback.bind(PDFViewerApplication));
// Suppress context menus for some controls
document.getElementById('scaleSelect').oncontextmenu = noContextMenuHandler;