Removed Scholar.HTTP, now that its functionality has been incorporated back into Scholar.Utilities.HTTP
This commit is contained in:
parent
312f32f505
commit
cb8f961639
2 changed files with 1 additions and 109 deletions
|
@ -80,7 +80,7 @@ Scholar.Schema = new function(){
|
|||
+ 'version=' + Scholar.version;
|
||||
|
||||
Scholar.debug('Checking repository for updates (' + url + ')');
|
||||
var get = Scholar.HTTP.doGet(url, _updateScrapersRemoteCallback);
|
||||
var get = Scholar.Utilities.HTTP.doGet(url, _updateScrapersRemoteCallback);
|
||||
|
||||
// TODO: instead, add an observer to start and stop timer on online state change
|
||||
if (!get){
|
||||
|
|
|
@ -461,114 +461,6 @@ Scholar.Hash.prototype.has = function(in_key){
|
|||
|
||||
|
||||
|
||||
Scholar.HTTP = new function(){
|
||||
|
||||
this.doGet = doGet;
|
||||
this.doPost = doPost;
|
||||
this.browserIsOffline = browserIsOffline;
|
||||
|
||||
/**
|
||||
* Send an HTTP GET request via XMLHTTPRequest
|
||||
*
|
||||
* Returns false if browser is offline
|
||||
**/
|
||||
function doGet(url, onDone){
|
||||
if (this.browserIsOffline()){
|
||||
return false;
|
||||
}
|
||||
|
||||
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||
.createInstance();
|
||||
|
||||
var test = xmlhttp.open('GET', url, true);
|
||||
|
||||
xmlhttp.onreadystatechange = function(){
|
||||
_stateChange(xmlhttp, onDone);
|
||||
};
|
||||
|
||||
xmlhttp.send(null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send an HTTP POST request via XMLHTTPRequest
|
||||
*
|
||||
* Returns false if browser is offline
|
||||
**/
|
||||
function doPost(url, body, onDone){
|
||||
if (this.browserIsOffline()){
|
||||
return false;
|
||||
}
|
||||
|
||||
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||
.createInstance();
|
||||
|
||||
xmlhttp.open('POST', url, true);
|
||||
|
||||
xmlhttp.onreadystatechange = function(){
|
||||
_stateChange(xmlhttp, onDone);
|
||||
};
|
||||
|
||||
xmlhttp.send(body);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function browserIsOffline(){
|
||||
return Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService).offline;
|
||||
}
|
||||
|
||||
|
||||
function _stateChange(xmlhttp, onDone){
|
||||
switch (xmlhttp.readyState){
|
||||
// Request not yet made
|
||||
case 1:
|
||||
break;
|
||||
|
||||
// Contact established with server but nothing downloaded yet
|
||||
case 2:
|
||||
// Accessing status will throw an exception if no network connection
|
||||
try {
|
||||
xmlhttp.status;
|
||||
}
|
||||
catch (e){
|
||||
Scholar.debug('No network connection');
|
||||
xmlhttp.noNetwork = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for HTTP status 200
|
||||
if (xmlhttp.status != 200){
|
||||
Scholar.debug('XMLHTTPRequest received HTTP response code '
|
||||
+ xmlhttp.status);
|
||||
}
|
||||
break;
|
||||
|
||||
// Called multiple while downloading in progress
|
||||
case 3:
|
||||
break;
|
||||
|
||||
// Download complete
|
||||
case 4:
|
||||
try {
|
||||
if (onDone){
|
||||
onDone(xmlhttp);
|
||||
}
|
||||
}
|
||||
catch (e){
|
||||
Scholar.debug(e, 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Scholar.Date = new function(){
|
||||
this.sqlToDate = sqlToDate;
|
||||
|
||||
|
|
Loading…
Reference in a new issue