Changeset 12227

Show
Ignore:
Timestamp:
01/31/08 13:08:57 (11 months ago)
Author:
jburke
Message:

Fixes #5699. Opera now working. Support now is IE6/7, FF2/3b2, Safari 3 and Opera 9.25. \!strict

Location:
dojox/trunk/io/proxy
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • dojox/trunk/io/proxy/xip.js

    r12181 r12227  
    5454        _isWebKit: navigator.userAgent.indexOf("WebKit") != -1, 
    5555 
    56         send: function(facade){ 
     56 
     57        send: function(/*Object*/facade){ 
     58                //summary: starts the xdomain request using the provided facade. 
     59                //This method first does some init work, then delegates to _realSend. 
     60 
     61                var url = this.xipClientUrl; 
     62                //Make sure we are not dealing with javascript urls, just to be safe. 
     63                if(url.split(":")[0].match(/javascript/i) || facade._ifpServerUrl.split(":")[0].match(/javascript/i)){ 
     64                        return; 
     65                } 
     66                 
     67                //Make xip_client a full URL. 
     68                var colonIndex = url.indexOf(":"); 
     69                var slashIndex = url.indexOf("/"); 
     70                if(colonIndex == -1 || slashIndex < colonIndex){ 
     71                        //No colon or we are starting with a / before a colon, so we need to make a full URL. 
     72                        var loc = window.location.href; 
     73                        if(slashIndex == 0){ 
     74                                //Have a full path, just need the domain. 
     75                                url = loc.substring(0, loc.indexOf("/", 9)) + url; //Using 9 to get past http(s):// 
     76                        }else{ 
     77                                url = loc.substring(0, (loc.lastIndexOf("/") + 1)) + url; 
     78                        } 
     79                } 
     80                this.fullXipClientUrl = url; 
     81 
     82                //Set up an HTML5 messaging listener if postMessage exists. 
     83                //As of this writing, this is only useful to get Opera 9.25+ to work. 
     84                if(typeof document.postMessage != "undefined"){ 
     85                        document.addEventListener("message", dojo.hitch(this, this.fragmentReceivedEvent), false); 
     86                } 
     87 
     88                //Now that we did first time init, always use the realSend method. 
     89                this.send = this._realSend; 
     90                return this._realSend(facade); //Object 
     91        }, 
     92 
     93        _realSend: function(facade){ 
     94                //summary: starts the actual xdomain request using the provided facade. 
    5795                var stateId = "XhrIframeProxy" + (this._stateIdCounter++); 
    5896                facade._stateId = stateId; 
    59                 var url = this.xipClientUrl; 
    60  
    61                 //Make sure we are not dealing with javascript urls, just to be safe. 
    62                 if(!url.split(":")[0].match(/javascript/i) && !facade._ifpServerUrl.split(":")[0].match(/javascript/i)){ 
    63                         //Make xip_client a full URL. 
    64                         var colonIndex = url.indexOf(":"); 
    65                         var slashIndex = url.indexOf("/"); 
    66                         if(colonIndex == -1 || slashIndex < colonIndex){ 
    67                                 //No colon or we are starting with a / before a colon, so we need to make a full URL. 
    68                                 var loc = window.location.href; 
    69                                 if(slashIndex == 0){ 
    70                                         //Have a full path, just need the domain. 
    71                                         url = loc.substring(0, loc.indexOf("/", 9)) + url; //Using 9 to get past http(s):// 
    72                                 }else{ 
    73                                         url = loc.substring(0, (loc.lastIndexOf("/") + 1)) + url; 
    74                                 } 
    75                         } 
    76          
    77                         var frameUrl = facade._ifpServerUrl + "#0:init:id=" + stateId + "&client="  
    78                                 + encodeURIComponent(url) + "&callback=" + encodeURIComponent(this._callbackName); 
    79          
    80                         this._state[stateId] = { 
    81                                 facade: facade, 
    82                                 stateId: stateId, 
    83                                 clientFrame: dojo.io.iframe.create(stateId, "", frameUrl), 
    84                                 isSending: false, 
    85                                 serverUrl: facade._ifpServerUrl, 
    86                                 requestData: null, 
    87                                 responseMessage: "", 
    88                                 requestParts: [], 
    89                                 idCounter: 1, 
    90                                 partIndex: 0, 
    91                                 serverWindow: null 
    92                         }; 
    93          
    94                         return stateId; 
    95                 } 
     97 
     98                var frameUrl = facade._ifpServerUrl + "#0:init:id=" + stateId + "&client="  
     99                        + encodeURIComponent(this.fullXipClientUrl) + "&callback=" + encodeURIComponent(this._callbackName); 
     100 
     101                this._state[stateId] = { 
     102                        facade: facade, 
     103                        stateId: stateId, 
     104                        clientFrame: dojo.io.iframe.create(stateId, "", frameUrl), 
     105                        isSending: false, 
     106                        serverUrl: facade._ifpServerUrl, 
     107                        requestData: null, 
     108                        responseMessage: "", 
     109                        requestParts: [], 
     110                        idCounter: 1, 
     111                        partIndex: 0, 
     112                        serverWindow: null 
     113                }; 
     114 
     115                return stateId; //Object 
    96116        }, 
    97117 
     
    145165                var facade = state.facade; 
    146166 
    147                 var clientWindow = state.clientFrame.contentWindow; 
    148  
    149167                var reqHeaders = []; 
    150168                for(var param in facade._requestHeaders){ 
    151169                        reqHeaders.push(param + ": " + facade._requestHeaders[param]); 
    152170                } 
    153                  
     171 
    154172                var requestData = { 
    155173                        uri: facade._uri 
     
    200218                                state.serverWindow = document.getElementById(state.stateId).contentWindow; 
    201219                        } 
    202                          
    203                         if(state.serverWindow.contentWindow){ 
    204                                 state.serverWindow = state.serverWindow.contentWindow; 
     220 
     221                        //Make sure we have contentWindow, but only do this for non-postMessage 
     222                        //browsers (right now just opera is postMessage). 
     223                        if(typeof document.postMessage == "undefined"){ 
     224                                if(state.serverWindow.contentWindow){ 
     225                                        state.serverWindow = state.serverWindow.contentWindow; 
     226                                } 
    205227                        } 
    206228 
     
    275297                } 
    276298                return serverUrl; 
     299        }, 
     300 
     301        fragmentReceivedEvent: function(evt){ 
     302                //summary: HTML5 document messaging endpoint. Unpack the event to see 
     303                //if we want to use it. 
     304                if(evt.uri.split("#")[0] == this.fullXipClientUrl){ 
     305                        this.fragmentReceived(evt.data); 
     306                } 
    277307        }, 
    278308 
  • dojox/trunk/io/proxy/xip_client.html

    r12181 r12227  
    6666        xipMasterFrame = parent.parent; 
    6767 
    68         var parts = config.callback.split("."); 
    69         xipCallbackObject = xipMasterFrame; 
    70         for(var i = 0; i < parts.length - 1; i++){ 
    71                 xipCallbackObject = xipCallbackObject[parts[i]]; 
    72         } 
    73         xipCallback = parts[parts.length - 1]; 
    74          
    75         callMaster = function(stateId, message){ 
    76                 xipCallbackObject[xipCallback](stateId + "#" + message); 
     68        //Set up an HTML5 messaging publisher if postMessage exists. 
     69        //As of this writing, this is only useful to get Opera 9.25+ to work. 
     70        if(typeof document.postMessage != "undefined"){ 
     71                callMaster = function(stateId, message){ 
     72                        xipMasterFrame.document.postMessage(stateId + "#" + message); 
     73                } 
     74        }else{ 
     75                var parts = config.callback.split("."); 
     76                xipCallbackObject = xipMasterFrame; 
     77                for(var i = 0; i < parts.length - 1; i++){ 
     78                        xipCallbackObject = xipCallbackObject[parts[i]]; 
     79                } 
     80                xipCallback = parts[parts.length - 1]; 
     81 
     82                callMaster = function(stateId, message){ 
     83                        xipCallbackObject[xipCallback](stateId + "#" + message); 
     84                } 
    7785        } 
    7886