Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: assets/js/XMLHttpRequest.jsm

Issue 8482109: ABP/Android JavaScript code (Closed)
Patch Set: ABP/Android JavaScript code Created Nov. 13, 2012, 9:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « assets/js/Synchronizer.jsm ('k') | assets/js/basedomain.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 XMLHttpRequest = function()
3 {
4 this.headers = {};
5 this.responseHeaders = {};
6 };
7
8 XMLHttpRequest.UNSENT = 0;
9 XMLHttpRequest.OPEN = 1;
10 XMLHttpRequest.HEADERS_RECEIVED = 2;
11 XMLHttpRequest.LOADING = 3;
12 XMLHttpRequest.DONE = 4;
13
14 XMLHttpRequest.prototype =
15 {
16 open: function(method, url, async, user, password)
17 {
18 this.async = (typeof async == "undefined" || async) ? true : false;
19 this.method = method || "GET";
20 this.url = url;
21 this.readyState = XMLHttpRequest.OPEN;
22 this.onreadystatechange();
23 },
24 setRequestHeader: function(header, value)
25 {
26 this.headers[header] = value;
27 },
28 send: function(data)
29 {
30 var self = this;
31
32 Android.httpSend(self.method, self.url, self.headers, self.async, handleResp onse);
33
34 function handleResponse(code, message, headers, text)
35 {
36 if (self.aborted)
37 return;
38 if (headers != null)
39 {
40 for (var i = 0; i < headers.length; i++)
41 {
42 var headerName = headers[i][0];
43 var headerValue = headers[i][1];
44 if (headerName)
45 self.responseHeaders[headerName] = headerValue;
46 }
47 }
48 self.readyState = XMLHttpRequest.HEADERS_RECEIVED;
49 self.onreadystatechange();
50
51 self.readyState = XMLHttpRequest.LOADING;
52 self.onreadystatechange();
53 self.status = parseInt(code) || undefined;
54 self.statusText = message || "";
55
56 self.responseText = text;
57
58 self.readyState = XMLHttpRequest.DONE;
59 self.onreadystatechange();
60 self.triggerListeners("load");
61 self.triggerListeners("loadend");
62 }
63 },
64 abort: function()
65 {
66 this.aborted = true;
67 this.triggerListeners("abort");
68 this.readyState = XMLHttpRequest.DONE;
69 this.onreadystatechange();
70 },
71 onreadystatechange: function(){},
72 getResponseHeader: function(header)
73 {
74 if (this.readyState < XMLHttpRequest.LOADING)
75 throw new Error("INVALID_STATE_ERR");
76 else
77 {
78 var lcHeader = header.toLowerCase();
79 var returnedHeaders = [];
80 for (var rHeader in this.responseHeaders)
81 {
82 if (this.responseHeaders.hasOwnProperty(rHeader) && rHeader.toLowerCase( ) == lcHeader)
83 returnedHeaders.push(this.responseHeaders[rHeader]);
84 }
85
86 if (returnedHeaders.length)
87 return returnedHeaders.join(", ");
88 }
89
90 return null;
91 },
92 getAllResponseHeaders: function(header)
93 {
94 if (this.readyState < 3)
95 throw new Error("INVALID_STATE_ERR");
96 else
97 {
98 var returnedHeaders = [];
99
100 for (var header in this.responseHeaders)
101 returnedHeaders.push(header + ": " + this.responseHeaders[header]);
102
103 return returnedHeaders.join("\r\n");
104 }
105 },
106 overrideMimeType: function(mime) {},
107 addEventListener: function(type, listener, useCapture)
108 {
109 var listeners = null;
110
111 if (type == "progress")
112 listeners = this.progressEventListeners;
113 else if (type == "loadend")
114 listeners = this.loadendEventListeners;
115 else if (type == "load")
116 listeners = this.loadEventListeners;
117 else if (type == "error")
118 listeners = this.errorEventListeners;
119 else if (type == "abort")
120 listeners = this.abortEventListeners;
121
122 if (listeners == null || listeners.indexOf(listener) >= 0)
123 return;
124 listeners.push(listener);
125 },
126 triggerListeners: function(type)
127 {
128 var listeners = null;
129
130 if (type == "progress")
131 listeners = this.progressEventListeners;
132 else if (type == "loadend")
133 listeners = this.loadendEventListeners;
134 else if (type == "load")
135 listeners = this.loadEventListeners;
136 else if (type == "error")
137 listeners = this.errorEventListeners;
138 else if (type == "abort")
139 listeners = this.abortEventListeners;
140
141 for (var i = 0; i < listeners.length; i++)
142 {
143 var listener = listeners[i];
144 listener();
145 }
146 },
147 progressEventListeners: [],
148 loadendEventListeners: [],
149 loadEventListeners: [],
150 errorEventListeners: [],
151 abortEventListeners: [],
152 aborted: false,
153 async: true,
154 readyState: XMLHttpRequest.UNSENT,
155 responseText: "",
156 status: 0
157 };
158
159 XMLHttpRequest.prototype.channel =
160 {
161 status: -1,
162 notificationCallbacks: {},
163 loadFlags: 0,
164 INHIBIT_CACHING: 0,
165 VALIDATE_ALWAYS: 0,
166 QueryInterface: function()
167 {
168 return this;
169 }
170 };
OLDNEW
« no previous file with comments | « assets/js/Synchronizer.jsm ('k') | assets/js/basedomain.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld