Skip to content

Commit

Permalink
Revert "Merge pull request mozilla#6698 from yurydelendik/rm-Unsuppor…
Browse files Browse the repository at this point in the history
…tedManager"

This reverts commit 376788f, reversing
changes made to 5f56a20.
  • Loading branch information
brendandahl committed Dec 3, 2015
1 parent e93512f commit b294fd3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 66 deletions.
18 changes: 6 additions & 12 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
MurmurHash3_64, Name, Parser, Pattern, PDFImage, PDFJS, serifFonts,
stdFontMap, symbolsFonts, getTilingPatternIR, warn, Util, Promise,
RefSetCache, isRef, TextRenderingMode, IdentityToUnicodeMap,
OPS, UNSUPPORTED_FEATURES, NormalizedUnicodes, IDENTITY_MATRIX,
reverseIfRtl, createPromiseCapability, ToUnicodeMap, getFontType */
OPS, UNSUPPORTED_FEATURES, UnsupportedManager, NormalizedUnicodes,
IDENTITY_MATRIX, reverseIfRtl, createPromiseCapability, ToUnicodeMap,
getFontType */

'use strict';

Expand Down Expand Up @@ -321,9 +322,6 @@ 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);
});
Expand Down Expand Up @@ -548,7 +546,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
translatedPromise = Promise.reject(e);
}

var self = this;
translatedPromise.then(function (translatedFont) {
if (translatedFont.fontType !== undefined) {
var xrefFontStats = xref.stats.fontTypes;
Expand All @@ -559,9 +556,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
translatedFont, font));
}, function (reason) {
// TODO fontCapability.reject?
// Error in the font data -- sending unsupported feature notification.
self.handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.font});
UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);

try {
// error, but it's still nice to have font type reported
Expand Down Expand Up @@ -614,8 +609,7 @@ 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,
this.handler);
pattern = Pattern.parseShading(shading, matrix, xref, resources);
operatorList.addOp(fn, pattern.getIR());
return Promise.resolve();
} else {
Expand Down Expand Up @@ -852,7 +846,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}

var shadingFill = Pattern.parseShading(shading, null, xref,
resources, self.handler);
resources);
var patternIR = shadingFill.getIR();
args = [patternIR];
fn = OPS.shadingFill;
Expand Down
8 changes: 4 additions & 4 deletions src/core/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* limitations under the License.
*/
/* globals ColorSpace, PDFFunction, Util, error, warn, info, isArray, isStream,
assert, isPDFFunction, UNSUPPORTED_FEATURES, MissingDataException */
assert, isPDFFunction, UnsupportedManager, UNSUPPORTED_FEATURES,
MissingDataException */

'use strict';

Expand Down Expand Up @@ -42,7 +43,7 @@ var Pattern = (function PatternClosure() {
};

Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
res, handler) {
res) {

var dict = isStream(shading) ? shading.dict : shading;
var type = dict.get('ShadingType');
Expand All @@ -65,8 +66,7 @@ var Pattern = (function PatternClosure() {
if (ex instanceof MissingDataException) {
throw ex;
}
handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.shadingPattern});
UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
warn(ex);
return new Shadings.Dummy();
}
Expand Down
16 changes: 10 additions & 6 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/
/* globals PDFJS, createPromiseCapability, LocalPdfManager, NetworkPdfManager,
NetworkManager, isInt, MissingPDFException, UNSUPPORTED_FEATURES,
NetworkManager, isInt, MissingPDFException,
UnexpectedResponseException, PasswordException, Promise, warn,
PasswordResponses, InvalidPDFException, UnknownErrorException,
XRefParseException, Ref, info, globalScope, error, MessageHandler */
Expand Down Expand Up @@ -482,11 +482,6 @@ 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()';

Expand Down Expand Up @@ -621,6 +616,15 @@ 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);
}
44 changes: 4 additions & 40 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Promise, PasswordResponses, PasswordException, InvalidPDFException,
MissingPDFException, UnknownErrorException, FontFaceObject,
loadJpegStream, createScratchCanvas, CanvasGraphics, stringToBytes,
UnexpectedResponseException, deprecated */
UnexpectedResponseException, deprecated, UnsupportedManager */

'use strict';

Expand Down Expand Up @@ -447,12 +447,6 @@ 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 =
Expand Down Expand Up @@ -1220,6 +1214,9 @@ 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
Expand Down Expand Up @@ -1587,19 +1584,6 @@ 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');
Expand Down Expand Up @@ -2016,23 +2000,3 @@ 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);
}
}
};
})();
3 changes: 2 additions & 1 deletion src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
info, assert, UnsupportedManager, UNSUPPORTED_FEATURES */

'use strict';

Expand Down Expand Up @@ -2092,6 +2092,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
},

paintXObject: function CanvasGraphics_paintXObject() {
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
warn('Unsupported \'paintXObject\' command.');
},

Expand Down
17 changes: 17 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ function error(msg) {
console.log('Error: ' + msg);
console.log(backtrace());
}
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
throw new Error(msg);
}

Expand All @@ -262,6 +263,22 @@ 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) {
Expand Down
7 changes: 4 additions & 3 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,6 @@ 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);
Expand Down Expand Up @@ -1468,6 +1465,10 @@ 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;

Expand Down

0 comments on commit b294fd3

Please sign in to comment.