Changeset 7416

Show
Ignore:
Timestamp:
02/22/07 23:10:01 (21 months ago)
Author:
BradNeuberg
Message:

Wired JavaScript? layer and Moxie into offline cache proxy API -- tested and works

Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/demos/storage/editor.html

    r7385 r7416  
    1010                var djConfig =  
    1111                                                {  
    12                                                         isDebug: false,  
     12                                                        isDebug: true,  
    1313                                                        parseWidgets: false,  
    1414                                                        searchIds: ["storageValue"]  
  • trunk/demos/storage/editor.js

    r7385 r7416  
    1313// set our application name 
    1414dojo.off.ui.appName = "Moxie"; 
    15  
    16 // we aren't going to need a real offline cache for now; 
    17 // we will just have our server return good HTTP/1.1 
    18 // caching headers and rely on the browser's native cache 
    19 dojo.off.requireOfflineCache = false; 
    2015 
    2116// add our list resources we need offline 
     
    368363                var self = this; 
    369364                dojo.sync.log.onCommand = function(command){ 
    370                         dojo.debug("Moxie.onCommand="+command); 
    371                         dojo.debug("command.name="+command.name); 
    372365                        if(command.name == "save"){ 
    373366                                self._save(command.key, command.value); 
     
    377370                // setup how we download our data from the server 
    378371                dojo.sync.doDownload = function(){ 
    379                         dojo.debug("Moxie.doDownload"); 
    380372                        // actually download our data 
    381373                        self._downloadData(); 
  • trunk/dot/proxy/client.c

    r7413 r7416  
    729729    HTTPConditionPtr condition; 
    730730    HTTPRangeRec range; 
    731  
    732         printf("httpClientRequest\n"); 
    733731         
    734732        referer = NULL; 
  • trunk/dot/proxy/local.c

    r7413 r7416  
    229229           isRunning, getVersion 
    230230    */ 
    231         printf("results=%s\n", host_ptr); 
    232231        if(matchUrl("/polipo/offline?addOfflineHost", object)){ 
    233232      status = addOfflineHost(host_ptr); 
  • trunk/dot/proxy/off.h

    r7413 r7416  
    2525    Example: 
    2626 
    27       durableCacheCallback("isRunning", true); 
     27      window.offlineCacheCallback("isRunning", true); 
    2828*/ 
    29 #define OFF_JAVASCRIPT_CALLBACK "durableCacheCallback" 
     29#define OFF_JAVASCRIPT_CALLBACK "window.offlineCacheCallback" 
    3030 
    3131/* 
  • trunk/src/off.js

    r7385 r7416  
    7171        doNetworkChecking: true, 
    7272         
     73        // hasOfflineCache: boolean 
     74        //  Determines if an offline cache is available or installed; 
     75        //      an offline cache is a facility that can truely cache offline 
     76        //      resources, such as JavaScript, HTML, etc. in such a way that 
     77        //      they won't be removed from the cache inappropriately like 
     78        //      a browser cache would. If this is false, and  
     79        //      dojo.off.requireOfflineCache is true, then an offline cache 
     80        //      will be installed 
     81        hasOfflineCache: null, 
     82         
     83        _OFFLINE_CACHE_URL: "http://localhost:8123/polipo/offline?", 
     84         
    7385        _onLoadListeners: new Array(), 
    7486        _storageLoaded: false, 
    7587        _pageLoaded: false, 
    76          
    77         hasOfflineCache: function(){ /* boolean */ 
    78                 // summary:  
    79                 //      Returns whether we have an offline cache available 
    80                 // description: 
    81                 //      Determines if an offline cache is available or installed; 
    82                 //      an offline cache is a facility that can truely cache offline 
    83                 //      resources, such as JavaScript, HTML, etc. in such a way that 
    84                 //      they won't be removed from the cache inappropriately like 
    85                 //      a browser cache would. If this is false, and  
    86                 //      dojo.off.requireOfflineCache is true, then an offline cache 
    87                 //      will be installed 
    88          
    89                 // FIXME: Implement 
    90                 return false; 
    91         }, 
    9288         
    9389        onOnline: function(){ /* void */ 
     
    238234        }, 
    239235         
     236        addOfflineHost: function(resultsCallback /* Function(successful) */){ 
     237                // summary: 
     238                //      Makes the this web application's host name, such as  
     239                //  "sitepen.com", offline-enabled with a true offline cache. 
     240                // description: 
     241                //  If a true offline cache is available on this platform, this 
     242                //  means this hosts resources are made truly available 
     243                //  offline and will not disappear from the offline cache 
     244                //  as it might from a browser cache. The host name this 
     245                //  page was served from is the host that is used, such 
     246                //  as "sitepen.com". 
     247                // resultsCallback: 
     248                //  A Function that will be called with the results of this 
     249                //  add attempt; if it was successful, you will get true; if 
     250                //  not, you will receive false 
     251                if(this.requireOfflineCache == false){ 
     252                        resultsCallback(true); 
     253                } 
     254                 
     255                if(this.hasOfflineCache != true){ 
     256                        resultsCallback(false); 
     257                } 
     258                 
     259                this._talkToOfflineCache("addOfflineHost", resultsCallback); 
     260        }, 
     261         
     262        removeOfflineHost: function(resultsCallback /* Function(successful) */){ 
     263                // summary: 
     264                //      Removes this web application's host name, such as "sitepen.com", 
     265                //  from being offline enabled. 
     266                // description: 
     267                //  If a true offline cache is available on this platform, this 
     268                //  means this hosts resources are made truly available 
     269                //  offline and will not disappear from the offline cache 
     270                //  as it might from a browser cache. The host name this 
     271                //  page was served from is the host that is used, such 
     272                //  as "sitepen.com". 
     273                // resultsCallback: 
     274                //  A Function that will be called with the results of this 
     275                //  remove attempt; if it was successful, you will get true; if 
     276                //  not, you will receive false 
     277                if(this.requireOfflineCache == false){ 
     278                        resultsCallback(true); 
     279                } 
     280                 
     281                if(this.hasOfflineCache != true){ 
     282                        resultsCallback(false); 
     283                } 
     284                 
     285                this._talkToOfflineCache("removeOfflineHost", resultsCallback); 
     286        }, 
     287         
     288        standardSaveHandler: function(status, isCoreSave, dataStore, item){ 
     289                // summary: 
     290                //      Called by portions of the Dojo Offline framework 
     291                //      as a standard way to handle local save's; this method 
     292                //      is 'package private' and should not be used outside 
     293                //      of the Dojo Offline package. 
     294                if(status == dojo.storage.FAILED 
     295                        && isCoreSave == true){ 
     296                        this.coreSaveFailed = true; 
     297                        this.enabled = false;    
     298                } 
     299                 
     300                if(this.onSave){ 
     301                        onSave(status, isCoreSave, dataStore, item); 
     302                } 
     303        }, 
     304         
     305        _checkOfflineCacheAvailable: function(finishedCallback){ 
     306                var self = this; 
     307                 
     308                // is an true, offline cache running on this machine as a 
     309                // local web proxy distributed with DOT? 
     310                if(this.requireOfflineCache == false){ 
     311                        self.hasOfflineCache = false; 
     312                        resultsCallback(); 
     313                        return; 
     314                } 
     315                 
     316                // give the local proxy 200 milliseconds to respond 
     317                var timer = setTimeout(function(){ 
     318                        self.hasOfflineCache = false; 
     319                        finishedCallback(); 
     320                }, 200); 
     321                 
     322                this._talkToOfflineCache("isRunning", function(results){ 
     323                        self.hasOfflineCache = true; 
     324                        window.clearTimeout(timer); 
     325                        finishedCallback(); 
     326                }); 
     327        }, 
     328         
    240329        _onLoad: function(){ 
    241330                //dojo.debug("dojo.off._onLoad"); 
     
    249338                // load framework data; when we are finished, continue 
    250339                // initializing ourselves 
     340                this.load(dojo.lang.hitch(this, this._onFrameworkDataLoaded)); 
     341        }, 
     342         
     343        _onFrameworkDataLoaded: function(){ 
     344                // this method is part of our _onLoad series of startup tasks 
     345                 
     346                // see if we have an offline cache; when done, move 
     347                // on to the rest of our startup tasks 
     348                this._checkOfflineCacheAvailable(dojo.lang.hitch(this, this._onOfflineCacheChecked)); 
     349        }, 
     350         
     351        _onOfflineCacheChecked: function(){ 
     352                // this method is part of our _onLoad series of startup tasks 
     353                 
     354                // if we have an offline cache, try to add ourselves to this list of available 
     355                // offline web apps 
     356                if(this.hasOfflineCache == true){ 
     357                        this.addOfflineHost(dojo.lang.hitch(this, this._finishStartingUp)); 
     358                }else{ 
     359                        this._finishStartingUp(); 
     360                } 
     361        }, 
     362         
     363        _finishStartingUp: function(){ 
     364                // this method is part of our _onLoad series of startup tasks 
     365                 
     366                // kick off a thread to check network status on 
     367                // a regular basis 
     368                this._startNetworkThread(); 
     369 
     370                // try to go online 
    251371                var self = this; 
    252                 this.load(function(){ 
    253                         // kick off a thread to check network status on 
    254                         // a regular basis 
    255                         self._startNetworkThread(); 
    256                  
    257                         // try to go online 
    258                         self.goOnline(function(){ 
    259                                 // indicate we are ready to be used 
    260                                 for(var i = 0; i < self._onLoadListeners.length; i++){ 
    261                                         self._onLoadListeners[i](); 
    262                                 } 
    263                         }); 
     372                this.goOnline(function(){ 
     373                        // indicate we are ready to be used 
     374                        for(var i = 0; i < self._onLoadListeners.length; i++){ 
     375                                self._onLoadListeners[i](); 
     376                        } 
    264377                }); 
    265378        }, 
     
    328441        }, 
    329442         
    330         standardSaveHandler: function(status, isCoreSave, dataStore, item){ 
    331                 // summary: 
    332                 //      Called by portions of the Dojo Offline framework 
    333                 //      as a standard way to handle local save's; this method 
    334                 //      is 'package private' and should not be used outside 
    335                 //      of the Dojo Offline package. 
    336                 if(status == dojo.storage.FAILED 
    337                         && isCoreSave == true){ 
    338                         this.coreSaveFailed = true; 
    339                         this.enabled = false;    
    340                 } 
    341                  
    342                 if(this.onSave){ 
    343                         onSave(status, isCoreSave, dataStore, item); 
    344                 } 
    345         }, 
    346          
    347443        _startNetworkThread: function(){ 
    348444                // kick off a thread that does periodic 
     
    390486                 
    391487                return url; 
     488        }, 
     489         
     490        _talkToOfflineCache: function(methodName, resultsCallback){ 
     491                var head = document.getElementsByTagName("head")[0]; 
     492                var script = document.createElement("script"); 
     493                var url = this._OFFLINE_CACHE_URL + methodName; 
     494                script.setAttribute("src", url); 
     495                window.offlineCacheCallback = function(name, results){ 
     496                        if(name == "UnknownMethod"){ 
     497                                dojo.raise("Programming error in dojo.off._talkToOfflineCache: " + name); 
     498                                return; 
     499                        } 
     500                         
     501                        // avoid memory leaks on IE 
     502                        head = null; 
     503                        script = null; 
     504                         
     505                        resultsCallback(results); 
     506                } 
     507                 
     508                head.appendChild(script); 
    392509        } 
    393510}); 
  • trunk/src/off/ui.js

    r7298 r7416  
    321321                // check offline cache settings 
    322322                if(dojo.off.requireOfflineCache == true 
    323                         && dojo.off.hasOfflineCache() == false){ 
     323                        && dojo.off.hasOfflineCache == false){ 
    324324                        this._needsOfflineCache(); 
    325325                        return; 
     
    397397                        this.learnHowPath += "?appName=" + encodeURIComponent(this.appName) 
    398398                                                                        + "&requireOfflineCache=" + dojo.off.requireOfflineCache 
    399                                                                         + "&hasOfflineCache=" + dojo.off.hasOfflineCache() 
     399                                                                        + "&hasOfflineCache=" + dojo.off.hasOfflineCache 
    400400                                                                        + "&runLink=" + encodeURIComponent(this.runLink) 
    401401                                                                        + "&runLinkText=" + encodeURIComponent(this.runLinkText); 
  • trunk/src/storage/browser.js

    r7327 r7416  
    8282                var self = this; 
    8383                var storageListener = function(evt){ 
    84                         dojo.debug("storage event, evt="+evt); 
    85                          
    8684                        // remove any old storage event listener we might have added 
    8785                        // to the window on old put() requests; Firefox has a bug