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

Side by Side Diff: lib/client.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Created Sept. 21, 2012, 1:16 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 function get(url, callback)
2 {
3 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
4 .createInstance(Ci.nsIXMLHttpRequest);
5 request.mozBackgroundRequest = true;
6 request.open("GET", url);
7 if (callback)
8 request.addEventListener("load", function()
9 {
Wladimir Palant 2012/09/21 15:36:18 How about request.addEventListener("load", callbac
10 callback(request);
11 });
12 request.send();
13 }
14
15 function postFile(url, window, filePath, callback)
16 {
17 let formData = Cc["@mozilla.org/files/formdata;1"]
18 .createInstance(Ci.nsIDOMFormData);
19 formData.append("file", new window.File(filePath));
Wladimir Palant 2012/09/21 15:36:18 If you use window.File then you can also use windo
20
21 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
22 .createInstance(Ci.nsIXMLHttpRequest);
23 request.mozBackgroundRequest = true;
24 request.open("POST", url);
25 if (callback)
26 request.addEventListener("load", function()
Wladimir Palant 2012/09/21 15:36:18 Same as above, better use Function.bind().
27 {
28 callback(request);
29 });
30 request.send(formData);
31 }
32
33 let Client = exports.Client = {};
34
35 Client.fetchCrawlableSites = function(backendUrl, callback)
36 {
37 get(backendUrl + "/crawlableSites", function(request)
38 {
39 let sites = request.responseText.trim().split("\n");
40 callback(sites);
41 });
42 };
43
44 Client.sendCrawlerDataFile = function(backendUrl, window, dataFilePath, callback )
45 {
46 postFile(backendUrl + "/crawlerData", window, dataFilePath, callback);
47 };
OLDNEW

Powered by Google App Engine
This is Rietveld