From 1e0ddcedc16143881a15af3779ff62c674b8aa8b Mon Sep 17 00:00:00 2001 From: Larissa Smith Date: Wed, 20 Jul 2016 16:43:53 -0600 Subject: [PATCH 1/2] Added an option to addTiledImage to change the crossOriginPolicy. addTiledImage will also check the tileSource for crossOriginPolicy. --- src/viewer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/viewer.js b/src/viewer.js index fa9e33fe..f5654667 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1229,6 +1229,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * browsers that support the HTML5 canvas. * @param {Number} [options.opacity] Opacity the tiled image should be drawn at by default. * @param {String} [options.compositeOperation] How the image is composited onto other images. + * @param {String} [options.crossOriginPolicy] The crossOriginPolicy for this specific image, + * overriding viewer.crossOriginPolicy. * @param {Function} [options.success] A function that gets called when the image is * successfully added. It's passed the event object which contains a single property: * "item", the resulting TiledImage. @@ -1264,6 +1266,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, if (options.compositeOperation === undefined) { options.compositeOperation = this.compositeOperation; } + if (options.crossOriginPolicy === undefined) { + options.crossOriginPolicy = options.tileSource.crossOriginPolicy ? options.tileSource.crossOriginPolicy : this.crossOriginPolicy; + } var myQueueItem = { options: options @@ -1376,7 +1381,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, minPixelRatio: _this.minPixelRatio, smoothTileEdgesMinZoom: _this.smoothTileEdgesMinZoom, iOSDevice: _this.iOSDevice, - crossOriginPolicy: _this.crossOriginPolicy, + crossOriginPolicy: queueItem.options.crossOriginPolicy, debugMode: _this.debugMode }); From 4ccabe78de30cfa209fb90199cad5b40a3fa9d6e Mon Sep 17 00:00:00 2001 From: Larissa Smith Date: Thu, 28 Jul 2016 09:35:43 -0600 Subject: [PATCH 2/2] Passed options.crossOriginPolicy into getTileSource. Also changed checks on crossOriginPolicy to compare to undefined, and added tests for the addTiledImage crossOriginPolicy api. --- src/viewer.js | 15 ++++++----- test/modules/basic.js | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index f5654667..02556bcf 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1267,7 +1267,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, options.compositeOperation = this.compositeOperation; } if (options.crossOriginPolicy === undefined) { - options.crossOriginPolicy = options.tileSource.crossOriginPolicy ? options.tileSource.crossOriginPolicy : this.crossOriginPolicy; + options.crossOriginPolicy = options.tileSource.crossOriginPolicy !== undefined ? options.tileSource.crossOriginPolicy : this.crossOriginPolicy; } var myQueueItem = { @@ -1331,7 +1331,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, this._loadQueue.push(myQueueItem); - getTileSourceImplementation( this, options.tileSource, function( tileSource ) { + getTileSourceImplementation( this, options.tileSource, options, function( tileSource ) { myQueueItem.tileSource = tileSource; @@ -2115,7 +2115,7 @@ function _getSafeElemSize (oElement) { * @function * @private */ -function getTileSourceImplementation( viewer, tileSource, successCallback, +function getTileSourceImplementation( viewer, tileSource, imgOptions, successCallback, failCallback ) { var _this = viewer; @@ -2149,7 +2149,8 @@ function getTileSourceImplementation( viewer, tileSource, successCallback, //If its still a string it means it must be a url at this point tileSource = new $.TileSource({ url: tileSource, - crossOriginPolicy: viewer.crossOriginPolicy, + crossOriginPolicy: imgOptions.crossOriginPolicy !== undefined ? + imgOptions.crossOriginPolicy : viewer.crossOriginPolicy, ajaxWithCredentials: viewer.ajaxWithCredentials, useCanvas: viewer.useCanvas, success: function( event ) { @@ -2161,8 +2162,10 @@ function getTileSourceImplementation( viewer, tileSource, successCallback, } ); } else if ($.isPlainObject(tileSource) || tileSource.nodeType) { - if (!tileSource.crossOriginPolicy && viewer.crossOriginPolicy) { - tileSource.crossOriginPolicy = viewer.crossOriginPolicy; + if (tileSource.crossOriginPolicy === undefined && + (imgOptions.crossOriginPolicy !== undefined || viewer.crossOriginPolicy !== undefined)) { + tileSource.crossOriginPolicy = imgOptions.crossOriginPolicy !== undefined ? + imgOptions.crossOriginPolicy : viewer.crossOriginPolicy; } if (tileSource.ajaxWithCredentials === undefined) { tileSource.ajaxWithCredentials = viewer.ajaxWithCredentials; diff --git a/test/modules/basic.js b/test/modules/basic.js index 4ce56654..c6164560 100644 --- a/test/modules/basic.js +++ b/test/modules/basic.js @@ -365,4 +365,62 @@ } ); + asyncTest( 'CrossOriginPolicyOption', function () { + + browserSupportsImgCrossOrigin(function(supported) { + if (!supported) { + expect(0); + start(); + } else { + viewer.crossOriginPolicy = "Anonymous"; + viewer.smoothTileEdgesMinZoom = Infinity; + viewer.addTiledImage( { + tileSource: { + type: 'legacy-image-pyramid', + levels: [ { + url: corsImg, + width: 135, + height: 155 + } ] + }, + crossOriginPolicy : false + } ); + viewer.addHandler('tile-drawn', function() { + ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), + "Canvas should be tainted."); + start(); + }); + } + }); + + } ); + asyncTest( 'CrossOriginPolicyTileSource', function () { + + browserSupportsImgCrossOrigin(function(supported) { + if (!supported) { + expect(0); + start(); + } else { + viewer.crossOriginPolicy = false; + viewer.smoothTileEdgesMinZoom = Infinity; + viewer.addTiledImage( { + tileSource: { + type: 'legacy-image-pyramid', + levels: [ { + url: corsImg, + width: 135, + height: 155 + } ], + crossOriginPolicy : "Anonymous" + } + } ); + viewer.addHandler('tile-drawn', function() { + ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), + "Canvas should not be tainted."); + start(); + }); + } + }); + + } ); })();