2002/05/05 08:37:32
[org.ibex.core.git] / src / org / xwt / Platform.java
index 710df27..e3ee510 100644 (file)
@@ -21,14 +21,20 @@ public class Platform {
 
     // Static Data /////////////////////////////////////////////////////////////////////////////////////
 
-    /** set to true during the delivery of a KeyPressed:C-v/A-v or Press3; it is safe to use a 'global' here,
-     *  since message delivery is single-threaded and non-preemptable
+    /**
+     *  set to true during the delivery of a KeyPressed:C-v/A-v or Press3; it is safe to use a
+     *  'global' here, since message delivery is single-threaded and non-preemptable
      */
     static boolean clipboardReadEnabled = false;
 
     /** The appropriate Platform object for this JVM */
     static Platform platform = null;
 
+    /** true if proxy autodetection has already been run */
+    static boolean alreadyDetectedProxy = false;
+
+    /** the result of proxy autodetection */
+    static HTTP.ProxyInfo cachedProxyInfo = null;
 
     // VM Detection Logic /////////////////////////////////////////////////////////////////////
 
@@ -47,16 +53,18 @@ public class Platform {
             String os_name = System.getProperty("os.name", "");
             String platform_class = null;
             
-            if (os_name.startsWith("Mac OS X")) platform_class = "MacOSX";
-            else if (vendor.startsWith("Free Software Foundation")) platform_class = "Win32";
+            //if (os_name.startsWith("Mac OS X")) platform_class = "MacOSX";
+            if (vendor.startsWith("Free Software Foundation")) platform_class = "Win32";
             else if (version.startsWith("1.1") && vendor.startsWith("Netscape")) platform_class = "Netscape";
             else if (version.startsWith("1.1") && vendor.startsWith("Microsoft")) platform_class = "Microsoft";
-            else if (!version.startsWith("1.0") && !version.startsWith("1.1")) platform_class = "Java2";
+            else if (version.startsWith("1.4")) platform_class = "Java14";
+            else if (!version.startsWith("1.0") && !version.startsWith("1.1")) platform_class = "Java12";
 
             if (platform_class != null) {
                 platform = (Platform)Class.forName("org.xwt.plat." + platform_class).newInstance();
                 platform.init();
             }
+
             if (Log.on) Log.log(Platform.class, "XWT VM detection:   vendor = " + vendor);
             if (Log.on) Log.log(Platform.class, "                   version = " + version);
             if (Log.on) Log.log(Platform.class, "                        os = " + os_name);
@@ -95,8 +103,8 @@ public class Platform {
     protected Surface _createSurface(Box b, boolean framed) { return null; }
 
     /** creates a socket object */
-    protected Socket _getSocket(String host, int port, boolean ssl) throws IOException {
-        return ssl ? new TinySSL(host, port) : new Socket(java.net.InetAddress.getByName(host), port);
+    protected Socket _getSocket(String host, int port, boolean ssl, boolean negotiate) throws IOException {
+        return ssl ? new TinySSL(host, port, negotiate) : new Socket(java.net.InetAddress.getByName(host), port);
     }
 
     /** creates and returns a picture */
@@ -161,6 +169,9 @@ public class Platform {
         return;
     }
 
+    /** Returns null if XWT should always use direct connection; otherwise returns a ProxyInfo object with proxy settings */
+    protected synchronized HTTP.ProxyInfo _detectProxy() { return null; }
+
     // Static methods -- thunk to the instance /////////////////////////////////////////////////////////////////////////
 
     /** if true, org.xwt.Surface should generate Click messages automatically when a Release happens after a Press and the mouse has not moved much */
@@ -178,8 +189,8 @@ public class Platform {
     /** returns the maximum ascent of all glyphs in a given platform-specific font */
     public static int getMaxAscent(String font) { return platform._getMaxAscent(font); }
 
-    /** returns the maximum descent of all glyphs in a given platform-specific font */
-    public static int getMaxDescent(String font) { return platform._getMaxDescent(font); }
+    /** returns the maximum descent of all glyphs in a given platform-specific font. Three pixel minimum ensures space for underline. */
+    public static int getMaxDescent(String font) { return Math.max(3, platform._getMaxDescent(font)); }
 
     /** returns the maximum number of threads that the XWT engine can create without adversely affecting the host OS */
     public static int maxThreads() { return platform._maxThreads(); }
@@ -200,7 +211,9 @@ public class Platform {
     public static void setClipBoard(String s) { platform._setClipBoard(s); }
 
     /** creates a socket object, with or without ssl encryption */
-    public static Socket getSocket(String host, int port, boolean ssl) throws IOException { return platform._getSocket(host, port, ssl); }
+    public static Socket getSocket(String host, int port, boolean ssl, boolean negotiate) throws IOException {
+        return platform._getSocket(host, port, ssl, negotiate);
+    }
 
     /** returns the width of the screen, in pixels */
     public static int getScreenWidth() { return platform._getScreenWidth(); }
@@ -217,12 +230,13 @@ public class Platform {
     /** creates and returns a picture */
     public static Picture createPicture(ImageDecoder i) { return platform._createPicture(i.getData(), i.getWidth(), i.getHeight()); }
 
-    /** creates and returns a picture */
+    /** opens a new browser window */
     public static void newBrowserWindow(String url) {
         if (!(url.startsWith("https://") || url.startsWith("http://") || url.startsWith("ftp://") || url.startsWith("mailto:"))) {
             if (Log.on) Log.log(Platform.class, "xwt.newBrowserWindow() only supports http and https urls");
             return;
         }
+        if (Log.on) Log.log(Platform.class, "newBrowserWindow, url = " + url);
         platform._newBrowserWindow(url);
     }
 
@@ -268,6 +282,28 @@ public class Platform {
         return ret;
     }
 
+    /** detects proxy settings */
+    public static synchronized HTTP.ProxyInfo detectProxy() {
+
+        if (cachedProxyInfo != null) return cachedProxyInfo;
+        if (alreadyDetectedProxy) return null;
+        alreadyDetectedProxy = true;
+
+        if (Log.on) Log.log(Platform.class, "attempting xwt-proxy DNS proxy detection");
+        cachedProxyInfo = HTTP.ProxyInfo.detectProxyViaManual();
+        if (cachedProxyInfo != null) return cachedProxyInfo;
+
+        if (Log.on) Log.log(Platform.class, "attempting " + platform.getClass().getName() + " proxy detection");
+        cachedProxyInfo = platform._detectProxy();
+        if (cachedProxyInfo != null) return cachedProxyInfo;
+
+        if (Log.on) Log.log(Platform.class, "attempting WPAD proxy detection");
+        cachedProxyInfo = HTTP.ProxyInfo.detectProxyViaWPAD();
+        if (cachedProxyInfo != null) return cachedProxyInfo;
+
+        return cachedProxyInfo;
+    }
+
     // Helpful font parsing stuff //////////////////////////////////////////////////////
 
     public static class ParsedFont {
@@ -306,10 +342,10 @@ public class Platform {
                 i = j;
                 while(i < font.length()) {
                     switch (font.charAt(i)) {
-                    case 'b': bold = true;
-                    case 'i': italic = true;
-                    case 'd': dotted_underline = true;
-                    case 'u': underline = true;
+                    case 'b': bold = true; break;
+                    case 'i': italic = true; break;
+                    case 'd': dotted_underline = true; break;
+                    case 'u': underline = true; break;
                     }
                     i++;
                 }
@@ -320,3 +356,4 @@ public class Platform {
 
 }
 
+