From 2d20fe717d5013ce6c54bdcaaa1594b3c65752e8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 15 Jun 2006 16:52:46 +0000 Subject: [PATCH] Added Scholar.HTTP.browserIsOffline() and changed doGet() and doPost() to return false if so --- .../content/scholar/xpcom/scholar.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js index 71a1ba128..cc95e97b1 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/scholar.js +++ b/chrome/chromeFiles/content/scholar/xpcom/scholar.js @@ -327,8 +327,18 @@ 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, onStatus, onDone){ + if (this.browserIsOffline()){ + return false; + } + var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] .createInstance(); @@ -338,10 +348,21 @@ Scholar.HTTP = new function(){ _stateChange(xmlhttp, onStatus, onDone); }; xmlhttp.send(null); + + return true; } + /** + * Send an HTTP POST request via XMLHTTPRequest + * + * Returns false if browser is offline + **/ function doPost(url, body, onStatus, onDone){ + if (this.browserIsOffline()){ + return false; + } + var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] .createInstance(); @@ -351,6 +372,14 @@ Scholar.HTTP = new function(){ _stateChange(xmlhttp, onStatus, onDone); }; xmlhttp.send(body); + + return true; + } + + + function browserIsOffline(){ + return Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService).offline; }