Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch a redirect in ImageLoader, set option to allow that domain and get... #619

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion source/feathers/controls/ImageLoader.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package feathers.controls

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.events.ErrorEvent;
import flash.events.Event;
Expand All @@ -22,6 +23,7 @@ package feathers.controls
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.system.ImageDecodingPolicy;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
Expand Down Expand Up @@ -769,6 +771,35 @@ package feathers.controls
this._paddingLeft = value;
this.invalidate(INVALIDATION_FLAG_STYLES);
}

/**
* @private
*/
protected var _firstTry:Boolean;

/**
* @private
*/
private static var _isBrowserSet:Boolean;

/**
* @private
*/
private static var _isBrowser:Boolean;

private static function isBrowser():Boolean
{
if(!_isBrowserSet)
{
switch (Capabilities.playerType) {
case 'PlugIn':
case 'ActiveX':
_isBrowser = true;
}
_isBrowserSet = true;
}
return _isBrowser;
}

/**
* @private
Expand Down Expand Up @@ -927,6 +958,7 @@ package feathers.controls
else if(sourceURL != this._lastURL)
{
this._lastURL = sourceURL;
this._firstTry = true;

if(this.urlLoader)
{
Expand Down Expand Up @@ -1183,7 +1215,44 @@ package feathers.controls
*/
protected function loader_completeHandler(event:flash.events.Event):void
{
const bitmap:Bitmap = Bitmap(this.loader.content);
var content:DisplayObject;
if(!isBrowser())
{
content = this.loader.content;
}
else
{
try
{
content = this.loader.content;
}
catch(error:SecurityError)
{
import flash.system.Security;

var loaderDomain:String = this.loader.contentLoaderInfo.url;
if(-1 == this._lastURL.indexOf(loaderDomain) && this._firstTry)
{
Security.loadPolicyFile(loaderDomain + 'crossdomain.xml');
if( 0 == loaderDomain.indexOf('https') )
{
Security.allowDomain(loaderDomain);
}
else
{
Security.allowInsecureDomain(loaderDomain)
}

this.loader.load(new URLRequest(this._lastURL), LOADER_CONTEXT);
this._firstTry = false;
return;
}
throw error;
}
}

const bitmap:Bitmap = Bitmap(content);

this.loader.contentLoaderInfo.removeEventListener(flash.events.Event.COMPLETE, loader_completeHandler);
this.loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, loader_errorHandler);
this.loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, loader_errorHandler);
Expand Down