Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ActionScript 3.0
- // package com
- // package skype
- // package detection
- // class Detection
- package com.skype.detection
- {
- import flash.display.*;
- import flash.events.*;
- import flash.external.*;
- import flash.net.*;
- import flash.system.*;
- import flash.text.*;
- import flash.utils.*;
- public class Detection extends flash.display.MovieClip
- {
- public function Detection()
- {
- ourDomains = ["*.skype.com", "*.skype.test", "*.skype.net"];
- super();
- setupStage();
- setupSecurity();
- addEventListener(Event.ENTER_FRAME, onEnterFrame);
- return;
- }
- private function setupStage():void
- {
- var loc1:*;
- try
- {
- stage.align = StageAlign.TOP_LEFT;
- stage.scaleMode = StageScaleMode.NO_SCALE;
- }
- catch (e:Error)
- {
- };
- revisionText.appendText(REVISION.slice(11, -2));
- return;
- }
- private function cloneObject(arg1:Object):Object
- {
- var loc2:*;
- loc2 = null;
- var loc1:*;
- loc1 = {};
- var loc3:*;
- loc3 = 0;
- var loc4:*;
- loc4 = arg1;
- for (loc2 in loc4)
- {
- loc1[loc2] = arg1[loc2];
- }
- return loc1;
- }
- private function initRest():void
- {
- context = getLoaderContext();
- setupExternalInterface();
- detect();
- notify();
- fixCorruption();
- return;
- }
- private function debugData():void
- {
- var loc1:*;
- loc1 = ["installed: " + this.installed, "version: " + this.version, "language: " + this.language, "platform: " + this.platform, "segment: " + this.segment];
- myTrace(loc1.join(", "));
- detailsText.text = loc1.join("\n");
- return;
- }
- public function getData():Object
- {
- var loc1:*;
- loc1 = {};
- loc1.version = version;
- loc1.platform = platform;
- loc1.language = language;
- loc1.segment = segment;
- return loc1;
- }
- private function detect():void
- {
- var loc2:*;
- loc2 = null;
- var loc1:*;
- loc1 = SharedObject.getLocal("ui/preferences", "/");
- installed = !(loc1.data.ui_version == undefined);
- segment = getUserSegment();
- if (installed)
- {
- version = loc1.data.ui_version;
- language = loc1.data.ui_language;
- loc2 = loc1.data.os_version;
- if (loc2.indexOf("Macintosh") == -1)
- {
- if (loc2.indexOf("Linux") == -1)
- {
- if (!(loc2.indexOf("Windows") == -1) || !(loc2.indexOf("Service Pack ") == -1) || !(loc2.indexOf("5.01.2600") == -1) || !(loc2.indexOf("6.00.600") == -1) || !(loc2.indexOf("6.01.") == -1))
- {
- platform = "windows";
- }
- else
- {
- platform = "unknown";
- }
- }
- else
- {
- platform = "linux";
- }
- }
- else
- {
- platform = "mac";
- }
- }
- loc1.flush();
- debugData();
- return;
- }
- private function isOurDomain(arg1:String):Boolean
- {
- var loc2:*;
- loc2 = null;
- var loc1:*;
- loc1 = "";
- if (arg1 && (arg1.indexOf("http://") == 0 || arg1.indexOf("https://") == 0))
- {
- loc1 = arg1.split("/")[2].split(":")[0];
- myTrace("Using domain name " + loc1 + " in checks");
- }
- if (!loc1.length)
- {
- return false;
- }
- var loc3:*;
- loc3 = 0;
- while (loc3 < ourDomains.length)
- {
- loc2 = ourDomains[loc3];
- if (loc2.indexOf("*") != 0)
- {
- if (loc1 == loc2)
- {
- myTrace("Our domain " + loc2 + " matched exactly");
- return true;
- }
- }
- else
- {
- loc2 = loc2.substring(1, loc2.length);
- if (loc1.lastIndexOf(loc2) == loc1.length - loc2.length || loc1 == loc2.substring(1, loc2.length))
- {
- myTrace("Our domain " + ourDomains[loc3] + " wildcard matched");
- return true;
- }
- }
- loc3 = (loc3 + 1);
- }
- return false;
- }
- public function getSessionData():Object
- {
- if (context != CONTEXT_OUR)
- {
- return {};
- }
- var loc1:*;
- loc1 = SharedObject.getLocal("user/session", "/");
- var loc2:*;
- loc2 = cloneObject(loc1.data);
- loc2.segment = getUserSegment();
- return loc2;
- }
- public function setUserSegment(arg1:String):Boolean
- {
- if (context != CONTEXT_OUR)
- {
- return false;
- }
- arg1 = arg1.replace(new RegExp("[^-a-z]", "g"), "");
- var loc1:*;
- loc1 = SharedObject.getLocal("user/segment", "/");
- loc1.data.segment = arg1;
- segment = arg1;
- return true;
- }
- private function setupExternalInterface():void
- {
- var loc1:*;
- if (!ExternalInterface.available)
- {
- return;
- }
- try
- {
- ExternalInterface.addCallback("isInstalled", isInstalled);
- ExternalInterface.addCallback("getData", getData);
- if (context == CONTEXT_OUR)
- {
- ExternalInterface.addCallback("getSharedObjectData", getSharedObjectData);
- ExternalInterface.addCallback("getSessionData", getSessionData);
- ExternalInterface.addCallback("clearSessionData", clearSessionData);
- ExternalInterface.addCallback("getUserSegment", getUserSegment);
- ExternalInterface.addCallback("setUserSegment", setUserSegment);
- }
- }
- catch (e:SecurityError)
- {
- myTrace("ExternalInterface addCallback calls failed, likely Flash Player security sandbox issue. " + undefined.message);
- }
- catch (e:Error)
- {
- myTrace("ExternalInterface addCallback calls failed. " + undefined.message);
- }
- return;
- }
- public function getUserSegment():String
- {
- if (context != CONTEXT_OUR)
- {
- return "";
- }
- var loc1:*;
- loc1 = SharedObject.getLocal("user/segment", "/");
- return loc1.data && loc1.data.segment ? loc1.data.segment : "";
- }
- private function onEnterFrame(arg1:flash.events.Event):void
- {
- removeEventListener(Event.ENTER_FRAME, onEnterFrame);
- initRest();
- return;
- }
- public function downloadSkype(arg1:flash.display.DisplayObjectContainer, arg2:Function=null):Boolean
- {
- var callbackFunction:Function=null;
- var loader:flash.display.Loader;
- var root:flash.display.DisplayObjectContainer;
- var loc1:*;
- loader = null;
- root = arg1;
- callbackFunction = arg2;
- if (installed)
- {
- return false;
- }
- try
- {
- loader = new Loader();
- loader.load(new URLRequest(INSTALL_SWF_URL));
- root.addChild(loader);
- startCheckingSkypeInstalled(callbackFunction);
- }
- catch (e:Error)
- {
- myTrace("Could not load installer swf: " + undefined);
- return false;
- }
- return true;
- }
- private function getHostingPageURL():String
- {
- var result:String;
- var loc1:*;
- result = "";
- if (ExternalInterface.available)
- {
- try
- {
- result = ExternalInterface.call("window.location.href.toString");
- }
- catch (e:Error)
- {
- };
- }
- return result;
- }
- public function getSharedObjectData():Object
- {
- if (context != CONTEXT_OUR)
- {
- return {};
- }
- var loc1:*;
- loc1 = SharedObject.getLocal("ui/preferences", "/");
- return cloneObject(loc1.data);
- }
- private function startCheckingSkypeInstalled(arg1:Function=null):void
- {
- installCallback = arg1;
- installTimer = new Timer(1000);
- installTimer.addEventListener(TimerEvent.TIMER, checkSkypeInstalled);
- installTimer.start();
- return;
- }
- private function notify():void
- {
- var i:int;
- var jsMethods:Array;
- var loc1:*;
- jsMethods = null;
- i = 0;
- jsMethods = new Array("SkypeDetection.setReady", "SKYPE.util.ClientDetection.ready");
- if (ExternalInterface.available && (context == CONTEXT_OUR || context == CONTEXT_TOP))
- {
- i = 0;
- while (i < jsMethods.length)
- {
- try
- {
- ExternalInterface.call(jsMethods[i]);
- }
- catch (e:Error)
- {
- myTrace("Could not notify JS method " + jsMethods[i]);
- }
- i = (i + 1);
- }
- }
- return;
- }
- public function clearSessionData():Boolean
- {
- if (context != CONTEXT_OUR)
- {
- return false;
- }
- var loc1:*;
- loc1 = SharedObject.getLocal("user/session", "/");
- loc1.clear();
- return true;
- }
- private function fixCorruption():void
- {
- var loc1:*;
- loc1 = SharedObject.getLocal("ui/preferences", "/");
- if (loc1.data.download_date && loc1.data.ui_version == undefined)
- {
- myTrace("Clearing corrupted sharedobject!");
- loc1.clear();
- }
- else
- {
- if (loc1.data.download_date && loc1.data.ui_version.length)
- {
- myTrace("Removing download_date botched data");
- delete loc1.data.download_date;
- }
- }
- loc1.flush();
- return;
- }
- private function setupSecurity():void
- {
- Security.exactSettings = false;
- Security.allowDomain("*");
- return;
- }
- private function getLoaderContext():String
- {
- var loc1:*;
- loc1 = null;
- if (loaderInfo.loaderURL != loaderInfo.url)
- {
- if (isOurDomain(loaderInfo.loaderURL))
- {
- myTrace("Loaded from our domain swf");
- loc1 = CONTEXT_OUR;
- }
- else
- {
- myTrace("Loaded inside other domain swf: " + loaderInfo.loaderURL);
- loc1 = CONTEXT_OTHER;
- }
- }
- else
- {
- if (isOurDomain(getHostingPageURL()))
- {
- myTrace("Loaded from our domain html");
- loc1 = CONTEXT_OUR;
- }
- else
- {
- myTrace("Loaded as top level swf");
- loc1 = CONTEXT_TOP;
- }
- }
- return loc1;
- }
- private function checkSkypeInstalled(arg1:flash.events.TimerEvent):void
- {
- detect();
- if (installed && !(installCallback == null))
- {
- installTimer.stop();
- myTrace("Skype is now installed, running callback.");
- installCallback();
- }
- return;
- }
- public function isInstalled():Boolean
- {
- return installed;
- }
- private function myTrace(arg1:String):void
- {
- trace("[SkypeDetection AS3] " + arg1);
- return;
- }
- private const CONTEXT_TOP:String="top";
- private const INSTALL_SWF_URL:String="http://api.skype.com/detection/installskype_as3.swf";
- private const CONTEXT_OTHER:String="other";
- public const REVISION:String="$Revision: 28581 $";
- private const CONTEXT_OUR:String="our";
- private var installCallback:Function;
- public var detailsText:flash.text.TextField;
- public var revisionText:flash.text.TextField;
- private var context:String;
- public var segment:String="";
- private var ourDomains:*;
- public var version:String="";
- public var language:String="";
- private var installTimer:flash.utils.Timer;
- public var platform:String="";
- public var installed:Boolean=false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement