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

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

Issue 6590816134889472: Noissue - Removed unused assets (Closed)
Patch Set: Created Oct. 14, 2014, 9:51 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 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 XMLHttpRequest = function()
19 {
20 this.headers = {};
21 this.responseHeaders = {};
22 this.progressEventListeners = [];
23 this.loadendEventListeners = [];
24 this.loadEventListeners = [];
25 this.errorEventListeners = [];
26 this.abortEventListeners = [];
27 this.aborted = false;
28 this.async = true;
29 this.readyState = XMLHttpRequest.UNSENT;
30 this.responseText = "";
31 this.status = 0;
32 };
33
34 XMLHttpRequest.UNSENT = 0;
35 XMLHttpRequest.OPEN = 1;
36 XMLHttpRequest.HEADERS_RECEIVED = 2;
37 XMLHttpRequest.LOADING = 3;
38 XMLHttpRequest.DONE = 4;
39
40 XMLHttpRequest.prototype =
41 {
42 open: function(method, url, async, user, password)
43 {
44 this.async = (typeof async == "undefined" || async) ? true : false;
45 this.method = method || "GET";
46 this.url = url;
47 this.readyState = XMLHttpRequest.OPEN;
48 this.onreadystatechange();
49 },
50 setRequestHeader: function(header, value)
51 {
52 this.headers[header] = value;
53 },
54 send: function(data)
55 {
56 var self = this;
57
58 Android.httpSend(self.method, self.url, self.headers, self.async, handleResp onse);
59
60 function handleResponse(code, message, headers, text)
61 {
62 if (self.aborted)
63 return;
64 if (headers != null)
65 {
66 for (var i = 0; i < headers.length; i++)
67 {
68 var headerName = headers[i][0];
69 var headerValue = headers[i][1];
70 if (headerName)
71 self.responseHeaders[headerName] = headerValue;
72 }
73 }
74 self.readyState = XMLHttpRequest.HEADERS_RECEIVED;
75 self.onreadystatechange();
76
77 self.readyState = XMLHttpRequest.LOADING;
78 self.onreadystatechange();
79 self.status = parseInt(code) || undefined;
80 self.statusText = message || "";
81
82 self.responseText = text;
83
84 self.readyState = XMLHttpRequest.DONE;
85 self.onreadystatechange();
86 self.triggerListeners("load");
87 self.triggerListeners("loadend");
88 }
89 },
90 abort: function()
91 {
92 this.aborted = true;
93 this.triggerListeners("abort");
94 this.readyState = XMLHttpRequest.DONE;
95 this.onreadystatechange();
96 },
97 onreadystatechange: function(){},
98 getResponseHeader: function(header)
99 {
100 if (this.readyState < XMLHttpRequest.LOADING)
101 throw new Error("INVALID_STATE_ERR");
102 else
103 {
104 var lcHeader = header.toLowerCase();
105 var returnedHeaders = [];
106 for (var rHeader in this.responseHeaders)
107 {
108 if (this.responseHeaders.hasOwnProperty(rHeader) && rHeader.toLowerCase( ) == lcHeader)
109 returnedHeaders.push(this.responseHeaders[rHeader]);
110 }
111
112 if (returnedHeaders.length)
113 return returnedHeaders.join(", ");
114 }
115
116 return null;
117 },
118 getAllResponseHeaders: function(header)
119 {
120 if (this.readyState < 3)
121 throw new Error("INVALID_STATE_ERR");
122 else
123 {
124 var returnedHeaders = [];
125
126 for (var header in this.responseHeaders)
127 returnedHeaders.push(header + ": " + this.responseHeaders[header]);
128
129 return returnedHeaders.join("\r\n");
130 }
131 },
132 overrideMimeType: function(mime) {},
133 addEventListener: function(type, listener, useCapture)
134 {
135 var listeners = null;
136
137 if (type == "progress")
138 listeners = this.progressEventListeners;
139 else if (type == "loadend")
140 listeners = this.loadendEventListeners;
141 else if (type == "load")
142 listeners = this.loadEventListeners;
143 else if (type == "error")
144 listeners = this.errorEventListeners;
145 else if (type == "abort")
146 listeners = this.abortEventListeners;
147
148 if (listeners == null || listeners.indexOf(listener) >= 0)
149 return;
150 listeners.push(listener);
151 },
152 triggerListeners: function(type)
153 {
154 var listeners = null;
155
156 if (type == "progress")
157 listeners = this.progressEventListeners;
158 else if (type == "loadend")
159 listeners = this.loadendEventListeners;
160 else if (type == "load")
161 listeners = this.loadEventListeners;
162 else if (type == "error")
163 listeners = this.errorEventListeners;
164 else if (type == "abort")
165 listeners = this.abortEventListeners;
166
167 for (var i = 0; i < listeners.length; i++)
168 {
169 var listener = listeners[i];
170 listener();
171 }
172 }
173 };
174
175 XMLHttpRequest.prototype.channel =
176 {
177 status: -1,
178 notificationCallbacks: {},
179 loadFlags: 0,
180 INHIBIT_CACHING: 0,
181 VALIDATE_ALWAYS: 0,
182 QueryInterface: function()
183 {
184 return this;
185 }
186 };
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