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: Fixed issues found in review Created Sept. 24, 2012, 2:10 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", 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);
Wladimir Palant 2012/09/25 09:40:39 As discussed on IRC: we can avoid using the window
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 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld