Skip to content

Commit

Permalink
adding swf file to add domain security
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Wang committed Apr 1, 2012
1 parent f304852 commit a76e72a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion js/youtube-downloader.js
Expand Up @@ -47,7 +47,9 @@ ytdl.init = function(loadedSwfCallback) {
var params = {
allowScriptAccess: 'always'
};
swfobject.embedSWF("swf/HTTPGet.swf", httpGetDiv.id, "0", "0", "9.0.0", null, flashVars, params, null, loadedCallback);
var width = "400";
var height = "400";
swfobject.embedSWF("swf/HTTPGet.swf", httpGetDiv.id, width, height, "9.0.0", null, flashVars, params, null, loadedCallback);
};


Expand Down
47 changes: 44 additions & 3 deletions src/HTTPGet.as
Expand Up @@ -41,6 +41,7 @@ package {

public function HTTPGet() {
try {
configureListeners(loader);
var font:TextFormat = new TextFormat();
font.font = "Arial";
font.size = 40;
Expand All @@ -58,7 +59,8 @@ package {
errorCallback = params.errorCallback;

ExternalInterface.addCallback("get", function(url:String, functionName:String):void {
var request:URLRequest = new URLRequest("http://localhost:8000");
Security.allowDomain('google.com');
var request:URLRequest = new URLRequest(url);
try {
jsCallbackFunctionName = functionName;
loader.load(request);
Expand All @@ -71,13 +73,52 @@ package {
ExternalInterface.addCallback("ping", function():Boolean {
return true;
});
callJs('HTTPGetLoadedCallback', 'true');
} catch(e:Error) {
callJs('HTTPGetLoadedCallback', 'false');
handleError(this, e);
}

callJs('HTTPGetLoadedCallback', 'true');
}

private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}

private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
callJs("foo", loader.data);
}

private function openHandler(event:Event):void {
trace("openHandler: " + event);
callJs("foo", "openHandler: " + event);
}

private function progressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}

private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
callJs("foo", "securityErrorHandler: " + event);
}

private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
callJs("foo", "httpStatusHandler: " + event);
}

private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
callJs("foo", "ioErrorHandler: " + event);
}

public static function handleError(source:Object, e:Error):void {
try {
var objError:Object = {};
Expand Down
Binary file modified swf/HTTPGet.swf
Binary file not shown.

0 comments on commit a76e72a

Please sign in to comment.