1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.io.XhrIframeProxy");
|
|
|
14 |
dojo.require("dojo.experimental");
|
|
|
15 |
dojo.experimental("dojo.io.XhrIframeProxy");
|
|
|
16 |
dojo.require("dojo.io.IframeIO");
|
|
|
17 |
dojo.require("dojo.dom");
|
|
|
18 |
dojo.require("dojo.uri.Uri");
|
|
|
19 |
dojo.io.XhrIframeProxy = {xipClientUrl:djConfig["xipClientUrl"] || dojo.uri.moduleUri("dojo.io", "xip_client.html"), _state:{}, _stateIdCounter:0, needFrameRecursion:function () {
|
|
|
20 |
return (true == dojo.render.html.ie70);
|
|
|
21 |
}, send:function (facade) {
|
|
|
22 |
var stateId = "XhrIframeProxy" + (this._stateIdCounter++);
|
|
|
23 |
facade._stateId = stateId;
|
|
|
24 |
var frameUrl = this.xipClientUrl + "#0:init:id=" + stateId + "&server=" + encodeURIComponent(facade._ifpServerUrl) + "&fr=false";
|
|
|
25 |
if (this.needFrameRecursion()) {
|
|
|
26 |
var fullClientUrl = window.location.href;
|
|
|
27 |
if ((this.xipClientUrl + "").charAt(0) == "/") {
|
|
|
28 |
var endIndex = fullClientUrl.indexOf("://");
|
|
|
29 |
endIndex = fullClientUrl.indexOf("/", endIndex + 1);
|
|
|
30 |
fullClientUrl = fullClientUrl.substring(0, endIndex);
|
|
|
31 |
} else {
|
|
|
32 |
fullClientUrl = fullClientUrl.substring(0, fullClientUrl.lastIndexOf("/") + 1);
|
|
|
33 |
}
|
|
|
34 |
fullClientUrl += this.xipClientUrl;
|
|
|
35 |
var serverUrl = facade._ifpServerUrl + (facade._ifpServerUrl.indexOf("?") == -1 ? "?" : "&") + "dojo.fr=1";
|
|
|
36 |
frameUrl = serverUrl + "#0:init:id=" + stateId + "&client=" + encodeURIComponent(fullClientUrl) + "&fr=" + this.needFrameRecursion();
|
|
|
37 |
}
|
|
|
38 |
this._state[stateId] = {facade:facade, stateId:stateId, clientFrame:dojo.io.createIFrame(stateId, "", frameUrl)};
|
|
|
39 |
return stateId;
|
|
|
40 |
}, receive:function (stateId, urlEncodedData) {
|
|
|
41 |
var response = {};
|
|
|
42 |
var nvPairs = urlEncodedData.split("&");
|
|
|
43 |
for (var i = 0; i < nvPairs.length; i++) {
|
|
|
44 |
if (nvPairs[i]) {
|
|
|
45 |
var nameValue = nvPairs[i].split("=");
|
|
|
46 |
response[decodeURIComponent(nameValue[0])] = decodeURIComponent(nameValue[1]);
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
var state = this._state[stateId];
|
|
|
50 |
var facade = state.facade;
|
|
|
51 |
facade._setResponseHeaders(response.responseHeaders);
|
|
|
52 |
if (response.status == 0 || response.status) {
|
|
|
53 |
facade.status = parseInt(response.status, 10);
|
|
|
54 |
}
|
|
|
55 |
if (response.statusText) {
|
|
|
56 |
facade.statusText = response.statusText;
|
|
|
57 |
}
|
|
|
58 |
if (response.responseText) {
|
|
|
59 |
facade.responseText = response.responseText;
|
|
|
60 |
var contentType = facade.getResponseHeader("Content-Type");
|
|
|
61 |
if (contentType && (contentType == "application/xml" || contentType == "text/xml")) {
|
|
|
62 |
facade.responseXML = dojo.dom.createDocumentFromText(response.responseText, contentType);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
facade.readyState = 4;
|
|
|
66 |
this.destroyState(stateId);
|
|
|
67 |
}, clientFrameLoaded:function (stateId) {
|
|
|
68 |
var state = this._state[stateId];
|
|
|
69 |
var facade = state.facade;
|
|
|
70 |
if (this.needFrameRecursion()) {
|
|
|
71 |
var clientWindow = window.open("", state.stateId + "_clientEndPoint");
|
|
|
72 |
} else {
|
|
|
73 |
var clientWindow = state.clientFrame.contentWindow;
|
|
|
74 |
}
|
|
|
75 |
var reqHeaders = [];
|
|
|
76 |
for (var param in facade._requestHeaders) {
|
|
|
77 |
reqHeaders.push(param + ": " + facade._requestHeaders[param]);
|
|
|
78 |
}
|
|
|
79 |
var requestData = {uri:facade._uri};
|
|
|
80 |
if (reqHeaders.length > 0) {
|
|
|
81 |
requestData.requestHeaders = reqHeaders.join("\r\n");
|
|
|
82 |
}
|
|
|
83 |
if (facade._method) {
|
|
|
84 |
requestData.method = facade._method;
|
|
|
85 |
}
|
|
|
86 |
if (facade._bodyData) {
|
|
|
87 |
requestData.data = facade._bodyData;
|
|
|
88 |
}
|
|
|
89 |
clientWindow.send(dojo.io.argsFromMap(requestData, "utf8"));
|
|
|
90 |
}, destroyState:function (stateId) {
|
|
|
91 |
var state = this._state[stateId];
|
|
|
92 |
if (state) {
|
|
|
93 |
delete this._state[stateId];
|
|
|
94 |
var parentNode = state.clientFrame.parentNode;
|
|
|
95 |
parentNode.removeChild(state.clientFrame);
|
|
|
96 |
state.clientFrame = null;
|
|
|
97 |
state = null;
|
|
|
98 |
}
|
|
|
99 |
}, createFacade:function () {
|
|
|
100 |
if (arguments && arguments[0] && arguments[0]["iframeProxyUrl"]) {
|
|
|
101 |
return new dojo.io.XhrIframeFacade(arguments[0]["iframeProxyUrl"]);
|
|
|
102 |
} else {
|
|
|
103 |
return dojo.io.XhrIframeProxy.oldGetXmlhttpObject.apply(dojo.hostenv, arguments);
|
|
|
104 |
}
|
|
|
105 |
}};
|
|
|
106 |
dojo.io.XhrIframeProxy.oldGetXmlhttpObject = dojo.hostenv.getXmlhttpObject;
|
|
|
107 |
dojo.hostenv.getXmlhttpObject = dojo.io.XhrIframeProxy.createFacade;
|
|
|
108 |
dojo.io.XhrIframeFacade = function (ifpServerUrl) {
|
|
|
109 |
this._requestHeaders = {};
|
|
|
110 |
this._allResponseHeaders = null;
|
|
|
111 |
this._responseHeaders = {};
|
|
|
112 |
this._method = null;
|
|
|
113 |
this._uri = null;
|
|
|
114 |
this._bodyData = null;
|
|
|
115 |
this.responseText = null;
|
|
|
116 |
this.responseXML = null;
|
|
|
117 |
this.status = null;
|
|
|
118 |
this.statusText = null;
|
|
|
119 |
this.readyState = 0;
|
|
|
120 |
this._ifpServerUrl = ifpServerUrl;
|
|
|
121 |
this._stateId = null;
|
|
|
122 |
};
|
|
|
123 |
dojo.lang.extend(dojo.io.XhrIframeFacade, {open:function (method, uri) {
|
|
|
124 |
this._method = method;
|
|
|
125 |
this._uri = uri;
|
|
|
126 |
this.readyState = 1;
|
|
|
127 |
}, setRequestHeader:function (header, value) {
|
|
|
128 |
this._requestHeaders[header] = value;
|
|
|
129 |
}, send:function (stringData) {
|
|
|
130 |
this._bodyData = stringData;
|
|
|
131 |
this._stateId = dojo.io.XhrIframeProxy.send(this);
|
|
|
132 |
this.readyState = 2;
|
|
|
133 |
}, abort:function () {
|
|
|
134 |
dojo.io.XhrIframeProxy.destroyState(this._stateId);
|
|
|
135 |
}, getAllResponseHeaders:function () {
|
|
|
136 |
return this._allResponseHeaders;
|
|
|
137 |
}, getResponseHeader:function (header) {
|
|
|
138 |
return this._responseHeaders[header];
|
|
|
139 |
}, _setResponseHeaders:function (allHeaders) {
|
|
|
140 |
if (allHeaders) {
|
|
|
141 |
this._allResponseHeaders = allHeaders;
|
|
|
142 |
allHeaders = allHeaders.replace(/\r/g, "");
|
|
|
143 |
var nvPairs = allHeaders.split("\n");
|
|
|
144 |
for (var i = 0; i < nvPairs.length; i++) {
|
|
|
145 |
if (nvPairs[i]) {
|
|
|
146 |
var nameValue = nvPairs[i].split(": ");
|
|
|
147 |
this._responseHeaders[nameValue[0]] = nameValue[1];
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
}});
|
|
|
152 |
|