[Bbs2ch-cvs 200] [182] GP_BRANCH の統合

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2007年 7月 28日 (土) 03:27:33 JST


Revision: 182
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=182
Author:   flyson
Date:     2007-07-28 03:27:33 +0900 (Sat, 28 Jul 2007)

Log Message:
-----------
GP_BRANCH の統合

Modified Paths:
--------------
    trunk/bbs2chreader/components/b2rServer.js
    trunk/bbs2chreader/install.rdf

Modified: trunk/bbs2chreader/components/b2rServer.js
===================================================================
--- trunk/bbs2chreader/components/b2rServer.js	2007-07-27 18:00:45 UTC (rev 181)
+++ trunk/bbs2chreader/components/b2rServer.js	2007-07-27 18:27:33 UTC (rev 182)
@@ -163,11 +163,127 @@
 		throw Components.results.NS_ERROR_NO_INTERFACE;
 	}
 
+};
+
+
+// ********** ********* b2rServer for Gecko1.9 ********** **********
+
+
+function b2rServer_GECKO_1_9(){
+	this._listening = false;
 }
 
+b2rServer_GECKO_1_9.prototype = {
 
+	get currentThread(){
+		return this._thread;
+	},
 
+	start: function(){
+		if(this._listening){
+			dump("b2rServer running\n");
+			return;
+		}
 
+		if(!this._thread){
+			this._thread = Components.classes["@mozilla.org/thread-manager;1"]
+				.getService().newThread(0);
+		}
+		this._thread.dispatch(this, this._thread.DISPATCH_NORMAL);
+		dump("b2rServer.start\n");
+	},
+
+	stop: function(){
+		if(this._listening){
+			this._listening = false;
+       		dump("b2rServer.stop\n");
+		}
+	},
+
+
+  	// ********** ********* implements nsIRunnable ********** **********
+
+	run: function (){
+		var pref = Components.classes["@mozilla.org/preferences-service;1"]
+						.getService(Components.interfaces.nsIPrefBranch);
+		var port = pref.getIntPref("extensions.bbs2chreader.server_port");
+
+		var serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
+					.createInstance(Components.interfaces.nsIServerSocket);
+		serverSocket.init(port, true, 10);
+		serverSocket.asyncListen(this);
+
+		dump("b2rServer.run : Listening Port " +  port + "\n");
+		this._listening = true;
+		while(this._listening){
+			this._thread.processNextEvent(true);
+		}
+		serverSocket.close();
+		dump("b2rServer.run : Stop Listening\n");
+    },
+
+
+  	// ********** ********* implements nsIServerSocketListener ********** **********
+
+	onSocketAccepted: function(aServerSocket, aTransport){
+		new b2rServerHandler(this, aServerSocket, aTransport);
+		// dump("b2rServer.onSocketAccepted\n");
+	},
+
+	onStopListening: function(aServerSocket, aStatus) {
+		// dump("b2rServer.onStopListening\n");
+	},
+
+
+	// ********** ********* implements nsIObserver ********** **********
+
+	observe: function(aSubject, aTopic, aData){
+		var os = Components.classes["@mozilla.org/observer-service;1"]
+					.getService(Components.interfaces.nsIObserverService);
+
+		switch(aTopic){
+			case "app-startup":
+				os.addObserver(this, "network:offline-status-changed", false);
+				os.addObserver(this, "final-ui-startup", false);
+				os.addObserver(this, "xpcom-shutdown", false);
+				break;
+		    case "final-ui-startup":
+				os.removeObserver(this, "final-ui-startup");
+				this.start();
+				break;
+			case "network:offline-status-changed":
+				if(aData == "online"){
+					this.start();
+				}else{
+					this.stop();
+				}
+				break;
+			case "xpcom-shutdown":
+				this.stop();
+				this.close();
+				os.removeObserver(this, "xpcom-shutdown");
+				os.removeObserver(this, "network:offline-status-changed");
+				break;
+		}
+	},
+
+
+	// ********** ********* implements nsISupports ********** **********
+
+	QueryInterface: function(aIID){
+		if(aIID.equals(Components.interfaces.nsIServerSocketListener)) return this;
+		if(aIID.equals(Components.interfaces.nsIServerSocket)) return this;
+		if(aIID.equals(Components.interfaces.nsIRunnable)) return this;
+		if(aIID.equals(Components.interfaces.nsIObserver)) return this;
+		if(aIID.equals(Components.interfaces.nsISupportsWeakReference)) return this;
+		if(aIID.equals(Components.interfaces.nsISupports)) return this;
+
+		throw Components.results.NS_ERROR_NO_INTERFACE;
+	}
+
+};
+
+
 // ********** ********* b2rServerHandler ********** **********
 
 function b2rServerHandler(aServer, aServerSocket, aTransport){
@@ -431,7 +547,7 @@
 // ********** ********* b2rServer Factory ********** **********
 
 
-var b2rServerFactory = {
+var Factory = {
 
 	createInstance: function (aOuter, aIID) {
 		if(aOuter != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
@@ -455,12 +571,16 @@
 
 	getInstance: function(aIID){
 		if(!this._instance){
-			this._instance = new b2rServer().QueryInterface(aIID);
+			if("@mozilla.org/thread-manager;1" in Components.classes){
+				this._instance = new b2rServer_GECKO_1_9();
+			}else{
+				this._instance = new b2rServer();
+			}
 		}
-		return this._instance;
+		return this._instance.QueryInterface(aIID);
 	}
 
-}
+};
 
 
 // ********** ********* Component Registration ********** **********
@@ -498,7 +618,7 @@
 
 	getClassObject: function(aCompMgr, aCID, aIID){
 		if(aCID.equals(this.CID))
-				return b2rServerFactory;
+				return Factory;
 
 		if(!aIID.equals(Components.interfaces.nsIFactory))
 				throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
@@ -511,7 +631,7 @@
 		return true;
 	}
 
-}
+};
 
 
 function NSGetModule(aCompMgr, aFileSpec){

Modified: trunk/bbs2chreader/install.rdf
===================================================================
--- trunk/bbs2chreader/install.rdf	2007-07-27 18:00:45 UTC (rev 181)
+++ trunk/bbs2chreader/install.rdf	2007-07-27 18:27:33 UTC (rev 182)
@@ -5,7 +5,7 @@
 	<Description about="urn:mozilla:install-manifest">
 		<em:name>bbs2chreader</em:name>
 		<em:id>{0B9D558E-6983-486b-9AAD-B6CBCD2FC807}</em:id>
-		<em:version>0.4.2</em:version>
+		<em:version>0.4.3</em:version>
 		<em:description>2ch.net(Japanese Web Forums) Browser</em:description>
 		<em:optionsURL>chrome://bbs2chreader/content/settings/settings.xul</em:optionsURL>
 		<em:homepageURL>http://bbs2ch.sourceforge.jp/</em:homepageURL>
@@ -17,7 +17,7 @@
 			<Description>
 				<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
 				<em:minVersion>2.0</em:minVersion>
-				<em:maxVersion>2.0.0.*</em:maxVersion>
+				<em:maxVersion>3.0a7</em:maxVersion>
 			</Description>
 		</em:targetApplication>
 	</Description>




bbs2ch-cvs メーリングリストの案内
アーカイブの一覧に戻る