flyson
flyso****@users*****
2005年 11月 6日 (日) 21:18:29 JST
Index: bbs2chreader/content/bbs2chreader/board-rss.js diff -u bbs2chreader/content/bbs2chreader/board-rss.js:1.9 bbs2chreader/content/bbs2chreader/board-rss.js:1.10 --- bbs2chreader/content/bbs2chreader/board-rss.js:1.9 Sat Sep 17 04:36:51 2005 +++ bbs2chreader/content/bbs2chreader/board-rss.js Sun Nov 6 21:18:29 2005 @@ -100,7 +100,6 @@ return; } - // _E[hÔu̧À if(this.boardItems.subjectFile.exists()){ var interval = new Date().getTime() @@ -116,20 +115,67 @@ } } + var httpChannel = this._ioService.newChannelFromURI(this.boardItems.subjectURL) + .QueryInterface(Components.interfaces.nsIHttpChannel); + httpChannel.requestMethod = "GET"; + httpChannel.redirectionLimit = 0; // 302 Ì_CNgðsíÈ¢ + httpChannel.loadFlags = httpChannel.LOAD_BYPASS_CACHE; + httpChannel.setRequestHeader("User-Agent", this._bbs2chService.userAgent, false); + + this.wrappedJSObject = this; + httpChannel.asyncOpen(this, null); + + }, + + onStartRequest: function(aRequest, aContext){ + aRequest.QueryInterface(Components.interfaces.nsIHttpChannel); + + this._bInputStream = Components.classes["@mozilla.org/binaryinputstream;1"] + .createInstance(Components.interfaces.nsIBinaryInputStream); + this._data = new Array(); + }, + + onDataAvailable: function (aRequest, aContext, aInputStream, aOffset, aCount){ + aRequest.QueryInterface(Components.interfaces.nsIHttpChannel); + var httpStatus = aRequest.responseStatus; + + // KvÈîñªÈ¢ÈçI¹ + if(!(httpStatus==200 || httpStatus==206)) return; - this._subjectDownloader = new Bbs2chDownloader(this.boardItems.subjectURL.spec, - this.boardItems.subjectFile.path); - this._subjectDownloader._context = this; - - this._subjectDownloader.onStart = function(aDownloader){}; - this._subjectDownloader.onStop = function(aDownloader, aStatus){ - this._context.RespondRSS(); - }; - this._subjectDownloader.onProgressChange = function(aDownloader, aPercentage){}; - this._subjectDownloader.onError = function(aDownloader, aErrorCode){ - this._context.requestErrorEnd(); - }; - this._subjectDownloader.download(); + this._bInputStream.setInputStream(aInputStream); + var availableData = this._bInputStream.readBytes(aCount); + this._data.push(availableData); + }, + + onStopRequest: function(aRequest, aContext, aStatus){ + aRequest.QueryInterface(Components.interfaces.nsIHttpChannel); + var httpStatus = aRequest.responseStatus; + this._bInputStream.close(); + + switch(httpStatus){ + case 200: // ÊíGET OK + case 206: // ·ªGET OK + break; + case 302: // DAT¿ + this.requestRespond("DAT DOWNED"); + this.requestEnd(); + return; + case 304: // ¢XV + this.requestRespond("NOT MODIFIED"); + this.requestEnd(); + return; + default: // HTTP G[ + this.requestRespond("ERROR HTTP STATUS : " + httpStatus); + this.requestEnd(); + return; + } + + var availableData = this._data.join(); + this._data = null; + if(availableData){ + this._bbs2chService.writeFile(this.boardItems.subjectFile.path, availableData, false); + } + this.RespondRSS(); }, @@ -170,7 +216,8 @@ } if(this._bbs2chService.pref.getBoolPref("fls.bbs2chreader.livebookmarks_append_board_link")){ - var boardTemplate = "<item>\n\t<title>%BOARDTITLE%</title>\n\t<link>bbs2ch:board:%BOARDURL%</link>\n</item>\n\n"; + var boardTemplate = "<item>\n\t<title>%BOARDTITLE%</title>\n\t" + + "<link>bbs2ch:board:%BOARDURL%</link>\n</item>\n\n"; var boardSource = boardTemplate .replace("%BOARDTITLE%", this.boardItems.title) .replace("%BOARDURL%", this.boardItems.url.spec);