LEFT | RIGHT |
1 function get(url, callback) | 1 function get(url, callback) |
2 { | 2 { |
3 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] | 3 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
4 .createInstance(Ci.nsIXMLHttpRequest); | 4 .createInstance(Ci.nsIXMLHttpRequest); |
5 request.mozBackgroundRequest = true; | 5 request.mozBackgroundRequest = true; |
6 request.open("GET", url); | 6 request.open("GET", url); |
7 if (callback) | 7 if (callback) |
8 request.addEventListener("load", callback.bind(undefined, request)); | 8 request.addEventListener("load", callback.bind(undefined, request)); |
9 request.send(); | 9 request.send(); |
10 } | 10 } |
11 | 11 |
12 function postFile(url, window, filePath, callback) | 12 function postFile(url, filePath, callback) |
13 { | 13 { |
14 let formData = new window.FormData; | 14 let formData = Cc["@mozilla.org/files/formdata;1"] |
15 formData.append("file", new window.File(filePath)); | 15 .createInstance(Ci.nsIDOMFormData); |
| 16 formData.append("file", new File(filePath)); |
16 | 17 |
17 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] | 18 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
18 .createInstance(Ci.nsIXMLHttpRequest); | 19 .createInstance(Ci.nsIXMLHttpRequest); |
19 request.mozBackgroundRequest = true; | 20 request.mozBackgroundRequest = true; |
20 request.open("POST", url); | 21 request.open("POST", url); |
21 if (callback) | 22 if (callback) |
22 request.addEventListener("load", callback.bind(undefined, request)); | 23 request.addEventListener("load", callback.bind(undefined, request)); |
23 request.send(formData); | 24 request.send(formData); |
24 } | 25 } |
25 | 26 |
26 let Client = exports.Client = {}; | 27 let Client = exports.Client = {}; |
27 | 28 |
28 Client.fetchCrawlableSites = function(backendUrl, callback) | 29 Client.fetchCrawlableSites = function(backendUrl, callback) |
29 { | 30 { |
30 get(backendUrl + "/crawlableSites", function(request) | 31 get(backendUrl + "/crawlableSites", function(request) |
31 { | 32 { |
32 let sites = request.responseText.trim().split("\n"); | 33 let sites = request.responseText.trim().split("\n"); |
33 callback(sites); | 34 callback(sites); |
34 }); | 35 }); |
35 }; | 36 }; |
36 | 37 |
37 Client.sendCrawlerDataFile = function(backendUrl, window, dataFilePath, callback
) | 38 Client.sendCrawlerDataFile = function(backendUrl, dataFilePath, callback) |
38 { | 39 { |
39 postFile(backendUrl + "/crawlerData", window, dataFilePath, callback); | 40 postFile(backendUrl + "/crawlerData", dataFilePath, callback); |
40 }; | 41 }; |
LEFT | RIGHT |