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

Unified Diff: lib/client.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Created Sept. 21, 2012, 1:16 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/client.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/client.js
@@ -0,0 +1,47 @@
+function get(url, callback)
+{
+ let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
+ .createInstance(Ci.nsIXMLHttpRequest);
+ request.mozBackgroundRequest = true;
+ request.open("GET", url);
+ if (callback)
+ request.addEventListener("load", function()
+ {
Wladimir Palant 2012/09/21 15:36:18 How about request.addEventListener("load", callbac
+ callback(request);
+ });
+ request.send();
+}
+
+function postFile(url, window, filePath, callback)
+{
+ let formData = Cc["@mozilla.org/files/formdata;1"]
+ .createInstance(Ci.nsIDOMFormData);
+ 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
+
+ let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
+ .createInstance(Ci.nsIXMLHttpRequest);
+ request.mozBackgroundRequest = true;
+ request.open("POST", url);
+ if (callback)
+ request.addEventListener("load", function()
Wladimir Palant 2012/09/21 15:36:18 Same as above, better use Function.bind().
+ {
+ callback(request);
+ });
+ request.send(formData);
+}
+
+let Client = exports.Client = {};
+
+Client.fetchCrawlableSites = function(backendUrl, callback)
+{
+ get(backendUrl + "/crawlableSites", function(request)
+ {
+ let sites = request.responseText.trim().split("\n");
+ callback(sites);
+ });
+};
+
+Client.sendCrawlerDataFile = function(backendUrl, window, dataFilePath, callback)
+{
+ postFile(backendUrl + "/crawlerData", window, dataFilePath, callback);
+};

Powered by Google App Engine
This is Rietveld