Passed options.crossOriginPolicy into getTileSource. Also changed checks on crossOriginPolicy to compare to undefined, and added tests for the addTiledImage crossOriginPolicy api.

This commit is contained in:
Larissa Smith 2016-07-28 09:35:43 -06:00
parent 1e0ddcedc1
commit 4ccabe78de
2 changed files with 67 additions and 6 deletions

View File

@ -1267,7 +1267,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
options.compositeOperation = this.compositeOperation; options.compositeOperation = this.compositeOperation;
} }
if (options.crossOriginPolicy === undefined) { 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 = { var myQueueItem = {
@ -1331,7 +1331,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
this._loadQueue.push(myQueueItem); this._loadQueue.push(myQueueItem);
getTileSourceImplementation( this, options.tileSource, function( tileSource ) { getTileSourceImplementation( this, options.tileSource, options, function( tileSource ) {
myQueueItem.tileSource = tileSource; myQueueItem.tileSource = tileSource;
@ -2115,7 +2115,7 @@ function _getSafeElemSize (oElement) {
* @function * @function
* @private * @private
*/ */
function getTileSourceImplementation( viewer, tileSource, successCallback, function getTileSourceImplementation( viewer, tileSource, imgOptions, successCallback,
failCallback ) { failCallback ) {
var _this = viewer; 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 //If its still a string it means it must be a url at this point
tileSource = new $.TileSource({ tileSource = new $.TileSource({
url: tileSource, url: tileSource,
crossOriginPolicy: viewer.crossOriginPolicy, crossOriginPolicy: imgOptions.crossOriginPolicy !== undefined ?
imgOptions.crossOriginPolicy : viewer.crossOriginPolicy,
ajaxWithCredentials: viewer.ajaxWithCredentials, ajaxWithCredentials: viewer.ajaxWithCredentials,
useCanvas: viewer.useCanvas, useCanvas: viewer.useCanvas,
success: function( event ) { success: function( event ) {
@ -2161,8 +2162,10 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
} ); } );
} else if ($.isPlainObject(tileSource) || tileSource.nodeType) { } else if ($.isPlainObject(tileSource) || tileSource.nodeType) {
if (!tileSource.crossOriginPolicy && viewer.crossOriginPolicy) { if (tileSource.crossOriginPolicy === undefined &&
tileSource.crossOriginPolicy = viewer.crossOriginPolicy; (imgOptions.crossOriginPolicy !== undefined || viewer.crossOriginPolicy !== undefined)) {
tileSource.crossOriginPolicy = imgOptions.crossOriginPolicy !== undefined ?
imgOptions.crossOriginPolicy : viewer.crossOriginPolicy;
} }
if (tileSource.ajaxWithCredentials === undefined) { if (tileSource.ajaxWithCredentials === undefined) {
tileSource.ajaxWithCredentials = viewer.ajaxWithCredentials; tileSource.ajaxWithCredentials = viewer.ajaxWithCredentials;

View File

@ -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();
});
}
});
} );
})(); })();