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

Delta Between Two Patch Sets: lib/client.js

Issue 8402021: Crawler frontend (Closed)
Left Patch Set: Created Sept. 21, 2012, 1:16 p.m.
Right Patch Set: Created Sept. 26, 2012, 8:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « icon64.png ('k') | lib/crawler.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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", function() 8 request.addEventListener("load", callback.bind(undefined, request));
9 {
Wladimir Palant 2012/09/21 15:36:18 How about request.addEventListener("load", callbac
10 callback(request);
11 });
12 request.send(); 9 request.send();
13 } 10 }
14 11
15 function postFile(url, window, filePath, callback) 12 function postFile(url, filePath, callback)
16 { 13 {
17 let formData = Cc["@mozilla.org/files/formdata;1"] 14 let formData = Cc["@mozilla.org/files/formdata;1"]
18 .createInstance(Ci.nsIDOMFormData); 15 .createInstance(Ci.nsIDOMFormData);
19 formData.append("file", new window.File(filePath)); 16 formData.append("file", new File(filePath));
Wladimir Palant 2012/09/21 15:36:18 If you use window.File then you can also use windo
20 17
21 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] 18 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
22 .createInstance(Ci.nsIXMLHttpRequest); 19 .createInstance(Ci.nsIXMLHttpRequest);
23 request.mozBackgroundRequest = true; 20 request.mozBackgroundRequest = true;
24 request.open("POST", url); 21 request.open("POST", url);
25 if (callback) 22 if (callback)
26 request.addEventListener("load", function() 23 request.addEventListener("load", callback.bind(undefined, request));
Wladimir Palant 2012/09/21 15:36:18 Same as above, better use Function.bind().
27 {
28 callback(request);
29 });
30 request.send(formData); 24 request.send(formData);
31 } 25 }
32 26
33 let Client = exports.Client = {}; 27 let Client = exports.Client = {};
34 28
35 Client.fetchCrawlableSites = function(backendUrl, callback) 29 Client.fetchCrawlableSites = function(backendUrl, callback)
36 { 30 {
37 get(backendUrl + "/crawlableSites", function(request) 31 get(backendUrl + "/crawlableSites", function(request)
38 { 32 {
39 let sites = request.responseText.trim().split("\n"); 33 let sites = request.responseText.trim().split("\n");
40 callback(sites); 34 callback(sites);
41 }); 35 });
42 }; 36 };
43 37
44 Client.sendCrawlerDataFile = function(backendUrl, window, dataFilePath, callback ) 38 Client.sendCrawlerDataFile = function(backendUrl, dataFilePath, callback)
45 { 39 {
46 postFile(backendUrl + "/crawlerData", window, dataFilePath, callback); 40 postFile(backendUrl + "/crawlerData", dataFilePath, callback);
47 }; 41 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld