Changeset 437
- Timestamp:
- 08/03/08 11:24:45 (5 months ago)
- Location:
- branches/0.5/daemon/orbited/static
- Files:
-
- 2 modified
-
XSubdomainBridge.html (modified) (7 diffs)
-
XSubdomainRequest.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.5/daemon/orbited/static/XSubdomainBridge.html
r349 r437 1 1 <html> 2 2 <head> 3 <script> 3 <script src="JSON.js"></script> 4 5 <script> 6 4 7 var origDomain = document.domain 5 8 var topDomain = null; 6 9 var id = parseInt(location.hash.slice(1)); 7 8 10 //var id = location.hash 9 11 var parts = document.domain.split('.') 12 var req = null; 13 14 // Posts a message in JSON string format to the parent document, issuing the request 15 function postMessageToParent(msg) 16 { 17 var target = parent.postMessage ? parent : (parent.document.postMessage ? parent.document : undefined); 18 if (typeof target != "undefined") { 19 target.postMessage(msg, "*"); 20 } 21 }; 22 23 24 function push(data) { 25 document.domain = topDomain 26 27 if (typeof(opera) != "undefined") 28 postMessageToParent("event " + id + " " + JSON.stringify(data)); 29 else 30 parent.XSubdomainRequest.prototype._event(id, data); 31 32 try { 33 document.domain = origDomain; 34 } 35 catch(e) { 36 } 37 } 38 10 39 if (parts.length == 1) { 11 40 try { 12 41 document.domain = document.domain 13 parent.XSubdomainRequest.prototype 42 if (typeof(opera) == "undefined") 43 parent.XSubdomainRequest.prototype 14 44 topDomain = document.domain 15 45 } … … 21 51 document.domain = parts.slice(i).join(".") 22 52 try { 23 parent.XSubdomainRequest.prototype 53 if (typeof(opera) == "undefined") 54 parent.XSubdomainRequest.prototype 24 55 topDomain = document.domain 25 56 break; … … 30 61 } 31 62 } 63 32 64 if (topDomain == null) 33 65 throw new Error("Invalid document.domain for cross-frame communication") … … 40 72 catch(e) { 41 73 } 74 75 42 76 function getNext() { 43 77 document.domain = topDomain … … 54 88 return data 55 89 } 56 function push(data) { 57 document.domain = topDomain 58 parent.XSubdomainRequest.prototype._event(id, data); 59 try { 60 document.domain = origDomain; 61 } 62 catch(e) { 63 } 90 91 // Sends a message to the parent, requesting it to send the next request on 92 // the queue. The result is handled in the message receiver handler 93 function sendGetNext() { 94 document.domain = topDomain; 95 postMessageToParent("queues " + id); 64 96 } 65 97 66 98 function doNextRequest() { 67 var req = getNext(); 99 if (typeof(opera) != "undefined") 100 sendGetNext() 101 else 102 req = getNext(); 103 68 104 if (req == null) { 69 105 return setTimeout(doNextRequest, 10); 70 106 } 107 71 108 var smethod = req[0] 72 109 var surl = req[1] … … 117 154 payload['headers'] = headers 118 155 push(["readystatechange", payload]) 156 req = null; 119 157 return doNextRequest(); 120 158 } … … 140 178 }; 141 179 180 181 // Message receiver handler (req. for Opera compatibility) 182 document.addEventListener('message', function(e) { 183 var msg = e.data; 184 var response = JSON.parse(msg); 185 req = response; 186 } 187 , false 188 ); 189 190 142 191 </script> 143 192 </head> -
branches/0.5/daemon/orbited/static/XSubdomainRequest.js
r350 r437 103 103 } 104 104 } 105 105 106 self.abort = function() { 106 107 // TODO implement. this is needed by TCPSocket.disconnect … … 117 118 ifr.style.visibility = 'hidden'; 118 119 } 119 120 120 } 121 122 121 123 122 … … 142 141 receive(payload); 143 142 } 143 144 145 // Message handler - parses messages posted by the 146 // XSubdomainBridge 147 document.addEventListener('message', function(e) { 148 var msg = e.data.split(" "); 149 var cmd = msg.shift(); 150 if (cmd == "event") 151 { 152 var id = msg.shift(); 153 var dataString = msg.join(" "); 154 var data = JSON.parse(dataString); 155 156 XSubdomainRequest.prototype._event(id, data); 157 } 158 if (cmd == "queues") 159 { 160 var id = msg.shift(); 161 var queue = XSubdomainRequest.prototype._state.queues[id]; 162 if (queue.length > 0) { 163 var data = queue.shift(); 164 e.source.postMessage(JSON.stringify(data), e.origin); 165 } 166 } 167 }, false 168 );