[Laszlo-checkins] r10927 - in openlaszlo/trunk/WEB-INF/lps/lfc: kernel/swf services

bargull@openlaszlo.org bargull at openlaszlo.org
Tue Sep 9 12:42:26 PDT 2008


Author: bargull
Date: 2008-09-09 12:42:21 -0700 (Tue, 09 Sep 2008)
New Revision: 10927

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoadQueue.as
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/services/LzURL.lzs
Log:
Change 20080909-bargull-gT6 by bargull at dell--p4--2-53 on 2008-09-09 18:53:18
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: "LoadObj" does not show url

New Features:

Bugs Fixed: LPP-6954

Technical Reviewer: hqm
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
LzLoader:
- removed duplicate "onerror" declaration
- fixed LzLoader.debugLoadObj(), so the url is shown again

LzMediaLoader:
- removed "removeLoadCheckerDel", instead call "removeLoadChecker" directly
- call "removeTimer" to 'unregister' errorcheck-delegate
- surround debug-statements with $debug
- removed swf7 code
- updated "testLoad", so both code-paths share common code 
- also in "testLoad": send "onloadration" after "onstreamstart"
- and some of LPP-2623 and LPP-3432...

LzLoadQueue:
- surround debug-statements with $debug
- updated "loadXML", so code-paths share common code

LzURL (part of LPP-6049):
- add typing
- add optional argument to constructor
- changed LzURL.merge() 
    

Tests:



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoadQueue.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoadQueue.as	2008-09-09 19:02:45 UTC (rev 10926)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoadQueue.as	2008-09-09 19:42:21 UTC (rev 10927)
@@ -38,7 +38,7 @@
             Debug.monitor(LzLoadQueue, 'openConx');
         }
     }
-        LzLoadQueue.__LZinit();
+    LzLoadQueue.__LZinit();
 }
 
 /**
@@ -93,9 +93,11 @@
     LzLoadQueue.unloadRequest(this);
 
     if (src == undefined) {
-        if (!this.proxied) {
-            Debug.warn("LzLoadQueue.XMLOnDataHandler load failed from URL %w, no data received.", this.url);
-            Debug.warn("Failure to load data in serverless apps may be caused by Flash player security policies. Check your data server crossdomain.xml file");
+        if ($debug) {
+            if (! this.proxied) {
+                Debug.warn("LzLoadQueue.XMLOnDataHandler load failed from URL %w, no data received.", this.url);
+                Debug.warn("Failure to load data in serverless apps may be caused by Flash player security policies. Check your data server crossdomain.xml file");
+            }
         }
         this.onload(false);
         //Debug.write("this.loader.onerror.ready =", this.loader.onerror.ready);
@@ -176,8 +178,8 @@
         }
     }
 
-    while( this.openConx < this.maxOpen && this.hasMoreInQueue() ){
-        this.makeRequest( this.getNextFromQueue() );
+    for (var next; this.openConx < this.maxOpen && (next = this.getNextFromQueue()); ) {
+        this.makeRequest( next );
     }
 
     if ( ! this.loading.length)  {
@@ -221,9 +223,10 @@
   * @access private
   */
 LzLoadQueue.getNextFromQueue = function( ){
-    for ( var i = 0; i < this.listofqs.length; i++ ){
-        if ( this.listofqs[ i ].length ) {
-            return this.listofqs[ i ].shift();
+    var loq = this.listofqs;
+    for ( var i = 0; i < loq.length; i++ ){
+        if ( loq[ i ].length ) {
+            return loq[ i ].shift();
         }
     }
 }
@@ -232,8 +235,9 @@
   * @access private
   */
 LzLoadQueue.hasMoreInQueue= function( ){
-    for ( var i = 0; i < this.listofqs.length; i++ ){
-        if ( this.listofqs[ i ].length ) {
+    var loq = this.listofqs;
+    for ( var i = 0; i < loq.length; i++ ){
+        if ( loq[ i ].length ) {
             return true;
         }
     }
@@ -245,15 +249,10 @@
   */
 LzLoadQueue.defaultPriorityAssignment = function( loadmc , prior ){
     if ( prior != null ) return prior;
-    if ( loadmc.lzt == "eval" ) return 2;
-    if ( loadmc.lzt == "data" ) return 4;
-    if ( loadmc.lzt == "media" ) {
-        return 6;
-        //PC?
-        //if ( loadmc.lzt == "media" ) return 6;
-    } else {
-        return 8;
-    }
+    else if ( loadmc.lzt == "eval" ) return 2;
+    else if ( loadmc.lzt == "data" ) return 4;
+    else if ( loadmc.lzt == "media" ) return 6;
+    else return 8;
 }
 
 /**
@@ -283,11 +282,15 @@
     if ( !loadobj.valid ) return;
 
     if (loadobj.loading || loadobj.loaded) {
-        Debug.error('duplicate request', loadobj);
+        if ($debug) {
+            Debug.error('duplicate request', loadobj);
+        }
         return;
     }
     if (loadobj.lzt == 'xmldata' && ! loadobj.url && ! loadobj.reqobj.url) {
-        Debug.error('no url to load', loadobj);
+        if ($debug) {
+            Debug.error('no url to load', loadobj);
+        }
         return;
     }
 
@@ -395,10 +398,10 @@
         loadobj.lmc = loadobj;
         //Debug.write('LzLoadQueue new lmc for loadobj', loadobj, loadobj.lmc);
     } else {
-    loadobj.lmcnum++;
-    //loadobj.attachMovie( "empty" , "lmc" + loadobj.lmcnum , 9 );
-    loadobj.createEmptyMovieClip( "lmc" + loadobj.lmcnum , 9 );
-    loadobj.lmc = loadobj[ 'lmc' + loadobj.lmcnum ];
+        loadobj.lmcnum++;
+        //loadobj.attachMovie( "empty" , "lmc" + loadobj.lmcnum , 9 );
+        loadobj.createEmptyMovieClip( "lmc" + loadobj.lmcnum , 9 );
+        loadobj.lmc = loadobj[ 'lmc' + loadobj.lmcnum ];
     }
 
     if ( dopost ){
@@ -416,11 +419,6 @@
   * @access private
   */
 LzLoadQueue.loadXML = function (loadobj) {
-    // Set the onData handler to intercept returning data
-    loadobj.onData = LzLoadQueue.XMLOnDataHandler;
-
-    var dopost = (loadobj.reqtype.toUpperCase() == 'POST');
-
     /*
       [1] If request is PROXIED, send the URL as given, with query string stripped off,
       parsed, and each arg is set as a property on the LoadVar object.
@@ -432,74 +430,50 @@
 
           [4] If it is a POST request, send to URL as given including query string.
             take the rawpostbody property from loadobj, parse it, and set as properties
-            on the LoadVars object. This is as close as we can get to doing a POST.
+            on the LoadVars object. 
 
-            We can't really post an arbitrary raw data string. The best we could do would
-            be to use XML sendAndLoad with a single  XML child text node, but that still
-            XML-escapes the text, so it isn't really much use.
+            We can't really post an arbitrary raw data string. The best we can do is 
+            to use XML sendAndLoad with a single XML child text node, but that still
+            XML-escapes the text.
 
     */
+    
+    // Set the onData handler to intercept returning data
+    loadobj.onData = LzLoadQueue.XMLOnDataHandler;
 
-    var url = loadobj.url;
-    var url_noquery = url;
+    var dopost = (loadobj.reqtype.toUpperCase() == 'POST');
     var lvar = new LoadVars();
+    var url = loadobj.url;
     var solo = !loadobj.proxied;
 
-    var marker = url.indexOf('?');
-    var uquery = "";
-    
-    // If it's proxied, or a SOLO GET, strip the query args from URL and set them as
-    // properties on LoadVars obj
-    if (loadobj.proxied || !dopost) {
+    // convert base url to absolute path, otherwise Flash is not happy
+    var reqstr;
+    if (solo && dopost) {
+        // For a SOLO POST, request the complete URL including query args
+        reqstr = lz.Browser.toAbsoluteURL( url, loadobj.secure );
+    } else {
+        // If it's proxied, or a SOLO GET, strip the query args from URL and set them as
+        // properties on LoadVars obj
+        var marker = url.indexOf('?');
         if (marker != -1) {
-            uquery = url.substring(marker+1, url.length);
-            url_noquery = url.substring(0,marker);
+            var uquery = url.substring(marker + 1, url.length);
+            url = url.substring(0, marker);
 
             var uitems = lz.Param.parseQueryString(uquery);
-            for ( var key in uitems) {
+            for (var key in uitems) {
                 lvar[key] = uitems[key];
             }
         }
+        
+        // get the url with the query string trimmed off
+        reqstr = lz.Browser.toAbsoluteURL( url, loadobj.secure );
     }
 
-    // convert base url to absolute path, otherwise Flash is not happy
-    var reqstr;
-
-    if (solo && dopost) {
-        // For a SOLO POST, request the complete URL including query args
-        reqstr = lz.Browser.toAbsoluteURL( loadobj.url, loadobj.secure );
-    } else {
-        // otherwise, get the url with the query string trimmed off
-        reqstr = lz.Browser.toAbsoluteURL( url_noquery, loadobj.secure );
-    }
-
-    if (loadobj.proxied) {
-        // PROXY request: proxy parameters have been stored on
-        // rawpostbody, get them out and append them to the LoadVars
-        // obj, to POST to LPS proxy server.
-
-        var content = loadobj.rawpostbody;
-        // Copy the postbody data onto the LoadVars, it will be POST'ed
-        var pdata = lz.Param.parseQueryString(content);
-        for ( var key in pdata) {
-            lvar[key] = pdata[key];
-        }
-
-        lvar.sendAndLoad(reqstr , loadobj, "POST" );
-    } else {
-        // SOLO request:
-
-        // Set any specified request headers
-        var header;
-        var headers = loadobj.loader.requestheaders;
-
-        if (dopost) {
-            for ( header in headers) {
-                lvar.addRequestHeader(header, headers[header]);
-            }
-            var lzpostbody = loadobj.rawpostbody;
-            var hasquerydata = loadobj.hasquerydata; // boolean
-            if (lzpostbody != null && !hasquerydata) {
+    var method = loadobj.proxied || dopost ? "POST" : "GET";
+    if (method == "POST") {
+        var lzpostbody = loadobj.rawpostbody;
+        if (lzpostbody != null) {
+            if (solo && !loadobj.hasquerydata) {
                 // This is supposed to be a "raw" data post. The best
                 // we can do is to use XML.sendAndLoad, with a Flash
                 // XML Text node as the data. This will still
@@ -507,28 +481,34 @@
                 // raw data.
                 var xmlraw = new XML();
                 xmlraw.parseXML(lzpostbody);
-                for ( header in headers) {
-                    xmlraw.addRequestHeader(header, headers[header]);
-                }
-                xmlraw.sendAndLoad(reqstr, loadobj);
+                // replace LoadVars with XML
+                lvar = xmlraw;
             } else {
-                var content = loadobj.rawpostbody;
+                // if PROXY request: proxy parameters have been stored on
+                // rawpostbody, get them out and append them to the LoadVars
+                // obj, to POST to LPS proxy server.
+                
                 // Copy the postbody data onto the LoadVars, it will be POST'ed
-                var pdata = lz.Param.parseQueryString(content);
-                for ( var key in pdata) {
+                var pdata = lz.Param.parseQueryString(lzpostbody);
+                for (var key in pdata) {
                     lvar[key] = pdata[key];
                 }
-                lvar.sendAndLoad(reqstr , loadobj , "POST");
             }
-        } else {
-            // For a GET request, all query args have been placed on
-            // the lvar object already.
-            for ( header in headers) {
-                lvar.addRequestHeader(header, headers[header]);
-            }
-            lvar.sendAndLoad(reqstr , loadobj, "GET" );
         }
+    } else {
+        // For a SOLO GET request, all query args have been placed on
+        // the lvar object already.
     }
+    
+    if (solo) {
+        // SOLO: Set any specified request headers
+        var headers = loadobj.loader.requestheaders;
+        for (var header in headers) {
+            lvar.addRequestHeader(header, headers[header]);
+        }
+    }
+    
+    lvar.sendAndLoad(reqstr, loadobj, method );
 }
 
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs	2008-09-09 19:02:45 UTC (rev 10926)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLoader.lzs	2008-09-09 19:42:21 UTC (rev 10927)
@@ -75,7 +75,6 @@
 }
 
 
-var onerror = LzDeclaredEvent;
 var ondata = LzDeclaredEvent;
 var oncontent = LzDeclaredEvent;
 var onrequest = LzDeclaredEvent;
@@ -161,15 +160,12 @@
     if (loadobj instanceof MovieClip) {
         // Nothing to do
     } else if (loadobj instanceof XMLNode) {
-
         // The raw XML response string was stashed here by LzLoadQueue.XMLOnDataHandler
         // TODO [2005-08-11 ptw] Is there not an issue that there
         // could be multiple requests?
         data.rawtext = this.rawtext;
-    } else {
-        if ($debug) {
-            Debug.error("%w.returnData: unhandled loadobj %w", this, loadobj);
-        }
+    } else if ($debug) {
+        Debug.error("%w.returnData: unhandled loadobj %w", this, loadobj);
     }
 
     // Ok, we have loaded this.  loadFinished changes state of loadobj
@@ -179,7 +175,7 @@
     // would have to worry about getLoadMovie trying to reuse the
     // loadobj before we have finished with it.
 
-    // this is done in LzLoadQueue.XMLOnDataHandler now, in order
+    // This is done in LzLoadQueue.XMLOnDataHandler now, in order
     // to pipeline a new load request while the data copy task is happening.
 
 
@@ -190,12 +186,14 @@
     this.lastloadtime = getTimer() - loadobj.loadtime;
 
     var err;
-    if ( data.childNodes[0].nodeName == "error") {
+    if (! data) {
+        // Nothing to do
+    } else if (data.childNodes[0].nodeName == "error") {
         err = data.childNodes[0].attributes.msg;
     } else if (data.nodeName == "error") {
         err = data.attributes.msg;
     } else if (data == "medialoaderror") {
-        err="Media load error";
+        err = "Media load error";
     }
 
     if ( err != null ){
@@ -228,7 +226,7 @@
     } else {
         if ( loadobj.timedout ){
             this.doTimeOut(loadobj);
-        } else if( data ){
+        } else if ( data ){
             if (this.ondata.ready) this.ondata.sendEvent( data );
         }
     }
@@ -716,18 +714,16 @@
     }
 /** @access private */
     loadobj._dbg_name = function () {
-        with (this) {
-            var state = valid?"initialized":"invalid";
-            // Decode boolean flags into state.  Order is important.
-            if (loading) { state = valid?"loading":"aborting"; }
-            if (loaded) { state = valid?"loaded":"aborted"; }
-            if (timedout) { state = "timedout"; }
-            // TODO: [2005-08-11 ptw] LzURL should be able to
-            // parse a relative URL
-            var url = (new LzURL(this.url)).file;
-            if (! url) { url = this.url; }
-            return Debug.formatToString("%s (%s)", url, state);
-        }
+        var state = this.valid ? "initialized" : "invalid";
+        // Decode boolean flags into state.  Order is important.
+        if (this.loading) { state = this.valid ? "loading" : "aborting"; }
+        if (this.loaded) { state = this.valid ? "loaded" : "aborted"; }
+        if (this.timedout) { state = "timedout"; }
+        // TODO: [2005-08-11 ptw] LzURL should be able to
+        // parse a relative URL
+        var url = (new LzURL(this.reqobj.url)).file;
+        if (! url) { url = this.reqobj.url; }
+        return Debug.formatToString("%s (%s)", url, state);
     };
     loadobj._dbg_typename = typename;
     // Monitor state variables if requested

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs	2008-09-09 19:02:45 UTC (rev 10926)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs	2008-09-09 19:42:21 UTC (rev 10927)
@@ -12,48 +12,55 @@
   * @access private
   */
 class LzMediaLoader extends LzLoader {
-    function LzMediaLoader ( owner , args ) {
-        super(owner, args);
 
-        this.owner.loadperc = 0;
+function LzMediaLoader (owner, args) {
+    super(owner, args);
 
-        this.loadChecker = new LzDelegate( this , "testLoad" );
-        this.errorChecker = new LzDelegate( this , "testError" );
-        this.errortimeout = 2000;
+    this.owner.loadperc = 0;
 
-        this.removeLoadCheckerDel = 
-            new LzDelegate( this, 
-                                  "removeLoadChecker", this, "onloaddone" );
+    this.loadCheckerDel = new LzDelegate( this, "testLoad" );
+    this.errorCheckerDel = new LzDelegate( this, "testError" );
 
-        this.timeout = canvas.medialoadtimeout;
+    this.errortimeout = 2000;
+    this.timeout = canvas.medialoadtimeout;
 
-        //setup loadmovie stuff that never changes
-        this.mc.loader = this;
-        this.mc.mc = this.mc;
-        this.mc.timeout = this.timeout;
-        this.lastrequest = this.mc;
-        // [2005-08-28] We use the view's clip as the loadobj, so
-        // monitor it (as we would in LzLoader if we created a new
-        // loadobj).
-        if ($debug) {
-            LzLoader.debugLoadObj(this.mc, 'MediaLoadObj');
-        }
+    //setup loadmovie stuff that never changes
+    this.mc.loader = this;
+    this.mc.mc = this.mc;
+    this.mc.timeout = this.timeout;
+    this.lastrequest = this.mc;
+    // [2005-08-28] We use the view's clip as the loadobj, so
+    // monitor it (as we would in LzLoader if we created a new
+    // loadobj).
+    if ($debug) {
+        LzLoader.debugLoadObj(this.mc, 'MediaLoadObj');
     }
+}
 
+/** @access private */
 var onstreamstart = LzDeclaredEvent;
+/** @access private */
 var onloaddone = LzDeclaredEvent;
 
-
+/** @access private */
 var LOADERDEPTH = 9;
 
 /**
   * @access private
   */
-function removeLoadChecker(ignore) {
+function startingLoad (loadmc) {
+    this.checkonce = false;
+    this.loadCheckerDel.register( lz.Idle, "onidle" );
+    lz.Timer.addTimer( this.errorCheckerDel, this.errortimeout );
+}
+
+/**
+  * @access private
+  */
+function removeLoadChecker (ignore) {
     // Remove loadChecker delegate
-    this.loadChecker.unregisterAll();
-    this.errorChecker.unregisterAll();
-    this.removeLoadCheckerDel.unregisterAll();
+    this.loadCheckerDel.unregisterAll();
+    lz.Timer.removeTimer( this.errorCheckerDel );
 }
 
 /**
@@ -62,7 +69,7 @@
   * media loader per view with a resource, so we use the view's
   * movieclip as the loadmovie, rather than creating another.
   */
-function getLoadMovie ( ){
+override function getLoadMovie () {
     // Abort any load in progress
     this.unload( this.mc );
     if (this.isaudio != true && this._oldmc != null) {
@@ -78,10 +85,7 @@
         if ($debug) {
             LzLoader.debugLoadObj(this.mc, 'MediaLoadObj');
         }
-        //Debug.warn('getLoadMovie lmc %w %w', this.mc, this.mc.lmc)
-    } else {
-        //Debug.warn('getLoadMovie not audio %2 %w', this.mc, this.mc.lmc)
-    } 
+    }
 
     // return the view's clip
     return this.mc;
@@ -90,7 +94,7 @@
 /**
   * @access private
   */
-function attachLoadMovie ( resc ){
+function attachLoadMovie (resc) {
     var mc = this.getLoadMovie();
     //Debug.warn('attachLoadMovie %w %w %w', resc, mc, this._oldmc)
     if (this.isaudio == true && this._oldmc != null) {
@@ -102,64 +106,48 @@
         mc = m;
     }
     if (resc) {
-        mc.attachMovie( resc , "lmc", this.LOADERDEPTH );
+        mc.attachMovie( resc, "lmc", this.LOADERDEPTH );
         if (this.mc.loading == true) {
-            Debug.error('already loading', this.mc);
+            if ($debug) {
+                Debug.error('already loading', this.mc);
+            }
             LzLoadQueue.loadFinished( mc );
-        }    
-    } else {
+        }
+    } else if ($debug) {
         Debug.error('%w.attachMovie(%w)', this, resc);
     }
 }
 
-/**
-  * @access private
-  */
-function startingLoad ( loadmc ){
-    this.checkonce = false;
-    this.loadChecker.register( lz.Idle, "onidle" );
-    this.errorChecker.unregisterAll();
-    lz.Timer.addTimer( this.errorChecker, this.errortimeout );
-    this.removeLoadCheckerDel.register( this, "onloaddone" );
-}
-
-//=============================================================================
-// Media types which cannot be loaded directly (serverless) at runtime.
-//
-// We use a blacklist instead of a whitelist, because the user may
-// want to access a URL which generates a supported format, but has an
-// suffix from which it is not possible to deduce the file type, like
-// .jsp or .php.
+/* Media types which cannot be loaded directly (serverless) at runtime.
+ *
+ * We use a blacklist instead of a whitelist, because the user may
+ * want to access a URL which generates a supported format, but has an
+ * suffix from which it is not possible to deduce the file type, like
+ * .jsp or .php.
+ * 
+ * @access private
+ */
 static var unsupportedMediaTypes = {
     "bmp": true,
     "tiff": true,
     "tif": true,
     "wmf": true,
     "wmv": true
-
-
 };
 
-static var unsupportedMediaTypesSWF7 = {
-    "png": true,
-    "gif": true
-}
-
-
-
 /**
   * @access private
   */
-function request( req , cache , headers, filetype ) {
-    var o = { url: req , lzt: "media", timeout: this.timeout };
+override function request (req, cache, headers, filetype) {
+    var o = { url: req, lzt: "media", timeout: this.timeout };
 
-    if ( cache == "none" ){
+    if (cache == "none") {
         o.cache = false;
         o.ccache = false;
-    } else if ( cache == "clientonly" ){
+    } else if (cache == "clientonly") {
         o.cache = false;
         o.ccache = true;
-    } else if ( cache == "serveronly" ){
+    } else if (cache == "serveronly") {
         o.cache = true;
         o.ccache = false;
     } else {
@@ -180,31 +168,24 @@
             var suffix = null;
             var si = req.lastIndexOf(".");
             if (si != -1) {
-                suffix = req.substring(si+1, si.length).toLowerCase();
+                suffix = req.substring(si + 1, si.length).toLowerCase();
             }
         } else {
             var suffix = filetype;
         }
         if ($debug) {
-            if (suffix != null && ((LzMediaLoader.unsupportedMediaTypes[suffix] == true)
-                                   ||
-                                   ((canvas.runtime == "swf7" || canvas.runtime == "swf6")
-                                    && (LzMediaLoader.unsupportedMediaTypesSWF7[suffix] == true)))) {
+            if (suffix != null && LzMediaLoader.unsupportedMediaTypes[suffix]) {
                 Debug.warn("serverless loading of resources with type '%s'" +
                            " is not supported by the Flash player. %w", suffix, req);
             }
         }
-        if (suffix == 'jpeg' || suffix == 'jpg') {
-            this.isjpeg = true;
-        } else if (suffix == 'mp3') {
-            this.isaudio = true;
-        } else {
-            this.isaudio = false;
-        }
-        //Debug.write('suffix', suffix, this.isaudio);
+        this.isjpeg = (suffix == 'jpeg' || suffix == 'jpg');
+        this.isaudio = (suffix == 'mp3');
     }
 
-    if ( headers != null ) o.headers = headers;
+    if (headers != null) {
+        o.headers = headers;
+    }
     super.request( o );
     this.owner.owner.resourceevent('loadratio', 0);
     this.owner.owner.resourceevent('framesloadratio', 0);
@@ -216,11 +197,11 @@
 function testError (ignore) {
     var lmc = this.mc.lmc;
 
-                  // not from another domain    
-    var iserror = this.checkonce && lmc.getBytesTotal != void 0 && 
+    // not from another domain
+    var iserror = this.checkonce && lmc.getBytesTotal != void 0 &&
                   lmc.getBytesTotal() <= 0 && lmc.getBytesLoaded() >= lmc.getBytesTotal();
-    if (iserror) {              
-        //Debug.error(iserror, lmc.getBytesLoaded(), lmc.getBytesTotal())
+    if (iserror) {
+        //Debug.error(this.owner.resource, lmc.getBytesLoaded(), lmc.getBytesTotal())
         this.doError(this.mc);
     }
 }
@@ -228,7 +209,7 @@
 /**
   * @access private
   */
-function testLoad (ignore){
+function testLoad (ignore) {
     //skip first check because this can get called before load starts, in 
     //which case load info is wrong
     //getBytesTotal is wrong before the header of the movie has loaded
@@ -242,117 +223,91 @@
                       lmc._currentframe, lmc._framesloaded, lmc._totalframes);
     */
 
-    if ( this.isjpeg && lmc._height <= 0) {
+    if (this.isjpeg && lmc._height <= 0) {
         //Debug.error('skipping 0 height jpeg');
         return;
     }    
 
-    if ( this.checkonce ){
-        var lr = lmc.getBytesLoaded() / lmc.getBytesTotal();
-        if (!isNaN(lr)) {
-            this.owner.owner.resourceevent('loadratio', lr);
-            //reset timeout for media which is streaming
-            this.mc.loadtime = getTimer();
-        }
-    }
+    if (this.checkonce) {
+        //a swf loaded from another domain will be sandboxed. no load
+        //information is available;
+        var xdomain = typeof(lmc.getBytesTotal) == "undefined";
 
-    if ( this.checkonce && lmc.getBytesTotal == void 0 
-         && lmc._totalframes > 0  ) {
-            //a swf loaded from another domain will be sandboxed. no load
-            //information is available;
-            if ( !this.sentLoadStart ){
+        if (xdomain ? lmc._totalframes > 0 : lmc._currentframe > 0 && lmc.getBytesTotal() > this.minHeader) {
+            if (! this.sentLoadStart) {
                 this.sentLoadStart = true;
-                if ( ! this.mc.loaded ) {
+                if (! this.mc.loaded) {
+                    //this assumes that an error swf will have already called back
+                    //into the LFC by the time the load is detected. If this is
+                    //wrong, then the view will send both onload and onerror.
                     if (this.onstreamstart.ready) this.onstreamstart.sendEvent( this );
                 }
             }
 
-            var nlp = lmc._framesloaded / 
-            lmc._totalframes;
+            if (! xdomain) {
+                var lr = lmc.getBytesLoaded() / lmc.getBytesTotal();
+                if (! isNaN(lr)) {
+                    this.owner.owner.resourceevent('loadratio', lr);
+                    // FIXME: [20080909 anba] if it's done this way, you'll never
+                    // get a timeout. By purpose?
+                    //reset timeout for media which is streaming
+                    this.mc.loadtime = getTimer();
+                }
+            }
 
-            if ( nlp >= this.owner.loadperc ){
-                //reset timeout for media which is streaming
-                //Debug.write( "here" , lmc._framesloaded , 
-                //lmc._totalframes );
+            if (lmc._totalframes > 0) {
+                var nlp = lmc._framesloaded / lmc._totalframes;
 
-                if (lmc._totalframes > 0) {
-                    var nlp = lmc._framesloaded / 
-                        lmc._totalframes;
+                if (xdomain) {
+                    if (! (nlp >= this.owner.loadperc)) {
+                        // woah, load percentage is less than before, retreat..
+                        return;
+                    }
 
-                    if ( nlp > this.owner.loadperc ){
+                    if (nlp > this.owner.loadperc) {
+                        this.owner.loadperc = nlp;
                         //reset timeout for media which is streaming
                         this.mc.loadtime = getTimer();
                     }
+                }
 
-                    this.owner.loadperc = nlp;
-                    // deprecated in view
-                    //if (this.owner.owner.onloadperc.ready) this.owner.owner.onloadperc.sendEvent( this.owner.loadperc );
-                    this.owner.owner.resourceevent('framesloadratio', nlp);
-                    // Sent above already...
-                    // this.owner.owner.resourceevent('loadratio', nlp);
+                this.owner.owner.resourceevent('framesloadratio', nlp);
+                // Sent above already...
+                // this.owner.owner.resourceevent('loadratio', nlp);
 
-                    if ( lmc._totalframes == lmc._framesloaded && lmc._currentframe > 0){
-                        if (!this.mc.loaded && this.onloaddone.ready) this.onloaddone.sendEvent( this );
+                if (xdomain) {
+                    var loaded = lmc._totalframes == lmc._framesloaded && lmc._currentframe > 0;
+                } else {
+                    var loaded = lmc.getBytesTotal() == lmc.getBytesLoaded();
+                }
+                if (loaded) {
+                    //if mc.loaded is set, means returnData has already been called
+                    //(probably by error swf.)
+                    if (! this.mc.loaded) {
+                        this.removeLoadChecker();
+                        if (this.onloaddone.ready) this.onloaddone.sendEvent( this );
+                    }
+                    
+                    // TODO: [20080909 anba] send always for crossdomain loading?
+                    if (! this.mc.loaded || xdomain) {
                         this.returnData( this.mc );
+                    }
                 }
             }
         }
-    }
-
-    if ( this.checkonce && lmc._currentframe > 0 
-         && typeof(lmc.getBytesTotal) != "undefined"
-         && lmc.getBytesTotal() > this.minHeader ) {
-        
-             if ( !this.sentLoadStart ){
-                 this.sentLoadStart = true;
-                 //this assumes that an error swf will have already called back
-                 //into the LFC by the time the load is detected. If this is
-                 //wrong, then the view will send both onload and onrror.
-                 if ( ! this.mc.loaded ) {
-                     if (this.onstreamstart.ready) this.onstreamstart.sendEvent( this );
-                 }
-             }
-
-             if (lmc._totalframes > 0) {
-                 var nlp = lmc._framesloaded / 
-                 lmc._totalframes;
-
-                 if ( nlp > this.owner.loadperc ){
-                     //reset timeout for media which is streaming
-                     this.mc.loadtime = getTimer();
-                 }
-
-                // deprecated in view
-                //if (this.owner.owner.onloadperc.ready) this.owner.owner.onloadperc.sendEvent( this.owner.loadperc );
-                this.owner.owner.resourceevent('framesloadratio', nlp);
-             }
-
-             if ( lmc.getBytesTotal() == lmc.getBytesLoaded() ){
-                 //load is done
-
-                 if (!this.mc.loaded && this.onloaddone.ready) this.onloaddone.sendEvent( this );
-                 //if mc.loaded is set, means returnData has already been called
-                 //(probably by error swf.)
-                 if ( !this.mc.loaded ){
-                     this.returnData( this.mc );
-                 }
-             }
-         }
-    
-    if ( !this.checkonce ){
+    } else {
         this.sentLoadStart = false;
         this.checkonce = true;
     }
 }
+
 /**
   * @access private
   */
-function unload ( loadobj ){
-    super.unload( loadobj );
+override function unload (loadobj) {
+    super.unload(loadobj);
 
     this.owner.loadperc = 0;
-    // deprecated in view
-    //if (this.owner.owner.onloadperc.ready) this.owner.owner.onloadperc.sendEvent( 0 );
     this.owner.owner.resourceevent('loadratio', 0);
     this.owner.owner.resourceevent('framesloadratio', 0);
 
@@ -362,7 +317,7 @@
 /**
   * @access private
   */
-function getLoadMC (){
+function getLoadMC () {
     return this.mc.lmc;
 }
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/services/LzURL.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/services/LzURL.lzs	2008-09-09 19:02:45 UTC (rev 10926)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/services/LzURL.lzs	2008-09-09 19:42:21 UTC (rev 10927)
@@ -16,8 +16,8 @@
   *     <canvas height="220" debug="true">
   *     <debug x="0" y="0" height="200" width="450"/>
   *     <script>
-  *         var urlstring = 'http://localhost:8080/lps/lzurl_example.lzx?lzt=swf';
-  *         var url = new LzURL(urlstring);
+  *         var urlstring:String = 'http://localhost:8080/lps/lzurl_example.lzx?lzt=swf';
+  *         var url:LzURL = new LzURL(urlstring);
   *
   *         // list each part of this url
   *         Debug.write("protocol: " + url.protocol);
@@ -43,11 +43,9 @@
   * ]]></example>
   *
   *
-  * @param String url: URL to parse
-  *
   * http://www.ietf.org/rfc/rfc2396.txt specifies the syntax for a URI
   *
-  * We also need to handle these cases that  OpenLaszlo allows
+  * We also need to handle these cases that OpenLaszlo allows
   * which aren't real URLs:
   * 
   * http:foo.html
@@ -57,59 +55,47 @@
   * http:/foo/bar.ksp?q=12
   * 
   */
-public class  LzURL {
+public class LzURL {
 
-    var protocol = null;
-    var host = null;
-    var port = null;
-    var path = null;
-    var file = null;
-    var query = null;
-    var fragment = null;
-    var _parsed = null;
+    var protocol :String = null;
+    var host :String = null;
+    var port :String = null;
+    var path :String = null;
+    var file :String = null;
+    var query :String = null;
+    var fragment :String = null;
+    var _parsed :String = null;
 
-    // TODO [hqm 2008-01] this should take an option arg (url=null), but our
-    // parser doesn't accept that at the moment.
-    public function LzURL ( ...rest ){
-        this.protocol = null;
-        this.host = null;
-        this.port = null;
-        this.path = null;
-        this.file = null;
-        this.query = null;
-        this.fragment = null;
-        if (rest.length > 0) {
-            var url = rest[0];
-            if ( url != null ) {
-                this.parseURL( url );
-            }
+    /** 
+      * @param String url: URL to parse
+      * @access public 
+      */
+    public function LzURL (url:String? = null) {
+        if (url != null) {
+            this.parseURL( url );
         }
     }
 
-
-
     /**
      * Parses the protocol, host, port, path, file ,query and fragment properties for 
      * the specified URL.  
      * 
      * @param String url: URL to parse
      */
-    public function parseURL (url)
-    {
+    public function parseURL (url:String) :void {
         if (this._parsed == url) return;
         this._parsed = url;
 
         // Look for protocol marker "protocol:[//host]"
-        var i0 = 0;
-        var i1 = url.indexOf(":");
+        var i0:int = 0;
+        var i1:int = url.indexOf(":");
 
         // Look for query or fragment char, which delimits end of host/path
-
         // "blah/barf/searchme?btnI=1&q=laszlosystems.com#foobar;bax"
 
-        var iquery = url.indexOf("?", i0);
-        var ifrag = url.indexOf("#", i0);
-        var iopt = url.length;
+        var iquery:int = url.indexOf("?", i0);
+        var ifrag:int = url.indexOf("#", i0);
+        var iopt:int = url.length;
 
         if (ifrag != -1) {
             iopt = ifrag;
@@ -132,8 +118,8 @@
                     // There is only a host field, no path e.g.:  http://www.foo.com[?query][#fragment]
                     i1 = iopt;
                 }
-                var hostPort = url.substring(i0, i1);
-                var i = hostPort.indexOf(":");
+                var hostPort:String = url.substring(i0, i1);
+                var i:int = hostPort.indexOf(":");
                 if (i == -1 ) {
                     this.host = hostPort;
                     this.port = null;
@@ -164,7 +150,6 @@
         if (iquery != -1) {
             this.query = url.substring(iquery+1, ifrag);
         }
-
     }
 
     /** split out the path and file portion of a url path
@@ -179,13 +164,12 @@
         foo.html                := null, "foo.html"
         @access private
     */
-    function _splitPath(pathfile)
-    {
+    private function _splitPath (pathfile:String) :void {
         if (pathfile == "") {
             return;
         }
     
-        var ls = pathfile.lastIndexOf("/");
+        var ls:int = pathfile.lastIndexOf("/");
         if (ls != -1) {
             // case "/", "/foo", "/foo/bar", "/foo/bar/";
             this.path = pathfile.substring(0,ls+1);
@@ -200,12 +184,11 @@
         this.file = pathfile;
     }
 
-
     /** @access private */ 
-    function dupe (){
+    function dupe () :LzURL {
         //make this function fast, because it is called by lz.Browser.toAbsoluteURL
         //which is called frequently by the loader
-        var o = new LzURL();
+        var o:LzURL = new LzURL();
         o.protocol = this.protocol;
         o.host = this.host;
         o.port = this.port;
@@ -219,9 +202,8 @@
     /**
      * Returns this URL as a string
      */
-    function toString()
-    {
-        var out = "";
+    function toString () :String {
+        var out:String = "";
 
         if (this.protocol != null) {
             out += this.protocol + ":";
@@ -246,43 +228,26 @@
         if (null != this.fragment) {
             out += "#" + this.fragment;
         }
-
     
         //Debug.write("orig: "+ this._parsed + ", Parsed: " + out );
         return out;
     }
-
     
 
     /**
      * Returns URL merged with DEFAULTS as an LzURL
+     * @param LzURL url: base URL
+     * @param LzURL defaults: default URL
+     * @return LzURL: the merged URL
      */
-    static function merge( url, defaults) 
-    {
-
-        var m = url.dupe();
-    
-        if (url.protocol == null) {
-            m.protocol = defaults.protocol;
+    static function merge (url:LzURL, defaults:LzURL) :LzURL {
+        var m:LzURL = new LzURL();
+        var tocopy:Object = {protocol:true, host:true, port:true,
+                                path:true, file:true, query:true, fragment: true};
+        for (var key:String in tocopy) {
+            m[key] = url[key] != null ? url[key] : defaults[key];
         }
-        if (url.host == null) {
-            m.host = defaults.host;
-        }
-        if (url.port == null) {
-            m.port = defaults.port;
-        }
-        if (url.path == null) {
-            m.path = defaults.path;
-        }
-        if (url.file == null) {
-            m.file = defaults.file;
-        }
-        if (url.query == null) {
-            m.query = defaults.query;
-        }
-        if (url.fragment == null) {
-            m.fragment = defaults.fragment;
-        }
+        
         return m;
     }
 }



More information about the Laszlo-checkins mailing list