[icedtea-web] RFC: allow alternate means of finding browsers

Dr Andrew John Hughes ahughes at redhat.com
Wed Mar 23 14:58:46 PDT 2011


On 12:14 Thu 17 Mar     , Omair Majid wrote:

snip...

> 
> Done. Please see the attached patch.
> 
> Okay to commit?
> 
> Cheers,
> Omair

Looks good.  Please commit.

> diff -r 2d359e723fef netx/net/sourceforge/jnlp/resources/Messages.properties
> --- a/netx/net/sourceforge/jnlp/resources/Messages.properties	Wed Mar 16 12:01:58 2011 +0100
> +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties	Thu Mar 17 12:05:00 2011 -0400
> @@ -154,6 +154,9 @@
>  RPRoxyPacNotSupported=Using Proxy Auto Config (PAC) files is not supported.
>  RProxyFirefoxNotFound=Unable to use Firefox's proxy settings. Using "DIRECT" as proxy type.
>  RProxyFirefoxOptionNotImplemented=Browser proxy option "{0}" ({1}) not supported yet.
> +RBrowserLocationPromptTitle=Browser Location
> +RBrowserLocationPromptMessage=Specify Browser Location
> +RBrowserLocationPromptMessageWithReason=Specify Browser Location (the browser command "{0}" is invalid).
>  
>  # Boot options, message should be shorter than this ---------------->
>  BOUsage=javaws [-run-options] <jnlp file>
> diff -r 2d359e723fef netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
> --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java	Wed Mar 16 12:01:58 2011 +0100
> +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java	Thu Mar 17 12:05:00 2011 -0400
> @@ -615,6 +615,23 @@
>          }
>      }
>  
> +    /**
> +     * @return true if running on Windows
> +     */
> +    public static boolean isWindows() {
> +        String os = System.getProperty("os.name");
> +        return (os != null && os.startsWith("Windows"));
> +    }
> +
> +    /**
> +     * @return true if running on a Unix or Unix-like system (including Linux
> +     * and *BSD)
> +     */
> +    public static boolean isUnix() {
> +        String sep = System.getProperty("file.separator");
> +        return (sep != null && sep.equals("/"));
> +    }
> +
>      public static void setInitialArgments(List<String> args) {
>          checkInitialized();
>          SecurityManager securityManager = System.getSecurityManager();
> diff -r 2d359e723fef netx/net/sourceforge/jnlp/services/XBasicService.java
> --- a/netx/net/sourceforge/jnlp/services/XBasicService.java	Wed Mar 16 12:01:58 2011 +0100
> +++ b/netx/net/sourceforge/jnlp/services/XBasicService.java	Thu Mar 17 12:05:00 2011 -0400
> @@ -16,6 +16,8 @@
>  
>  package net.sourceforge.jnlp.services;
>  
> +import static net.sourceforge.jnlp.runtime.Translator.R;
> +
>  import java.io.IOException;
>  import java.net.MalformedURLException;
>  import java.net.URL;
> @@ -190,9 +192,47 @@
>          if (initialized)
>              return;
>          initialized = true;
> +        initializeBrowserCommand();
> +        if (JNLPRuntime.isDebug()) {
> +            System.out.println("browser is " + command);
> +        }
> +    }
>  
> -        if (isWindows()) {
> +    /**
> +     * Initializes {@link #command} to launch a browser
> +     */
> +    private void initializeBrowserCommand() {
> +        if (JNLPRuntime.isWindows()) {
>              command = "rundll32 url.dll,FileProtocolHandler ";
> +        } else if (JNLPRuntime.isUnix()) {
> +            DeploymentConfiguration config = JNLPRuntime.getConfiguration();
> +            command = config.getProperty(DeploymentConfiguration.KEY_BROWSER_PATH);
> +            if (command != null) {
> +                return;
> +            }
> +
> +            if (posixCommandExists("xdg-open")) {
> +                command = "xdg-open";
> +                return;
> +            }
> +
> +            if (posixCommandExists(System.getenv("BROWSER"))) {
> +                command = System.getenv("BROWSER");
> +                return;
> +            }
> +
> +            while (true) {
> +                command = promptForCommand(command);
> +                if (command != null && posixCommandExists(command)) {
> +                    config.setProperty(DeploymentConfiguration.KEY_BROWSER_PATH, command);
> +                    try {
> +                        config.save();
> +                    } catch (IOException e) {
> +                        e.printStackTrace();
> +                    }
> +                    break;
> +                }
> +            }
>          } else {
>              DeploymentConfiguration config = JNLPRuntime.getConfiguration();
>              command = config.getProperty(DeploymentConfiguration.KEY_BROWSER_PATH);
> @@ -212,18 +252,44 @@
>          }
>      }
>  
> -    private boolean isWindows() {
> -        String os = System.getProperty("os.name");
> -        if (os != null && os.startsWith("Windows"))
> -            return true;
> -        else
> +    /**
> +     * Check that a command exists on a posix-like system
> +     * @param command the command to check
> +     * @return true if the command exists
> +     */
> +    private boolean posixCommandExists(String command) {
> +        if (command == null || command.trim().length() == 0) {
>              return false;
> +        }
> +
> +        command = command.trim();
> +        if (command.contains("\n") || command.contains("\r")) {
> +            return false;
> +        }
> +
> +        try {
> +            Process p = Runtime.getRuntime().exec(new String[] { "bash", "-c", "type " + command });
> +            p.waitFor();
> +            return (p.exitValue() == 0);
> +        } catch (IOException e) {
> +            e.printStackTrace();
> +            return false;
> +        } catch (InterruptedException e) {
> +            e.printStackTrace();
> +            return false;
> +        }
>      }
>  
> -    private String promptForCommand(String cmd) {
> +    private String promptForCommand(String previousCommand) {
> +        String message = null;
> +        if (previousCommand == null) {
> +            message = R("RBrowserLocationPromptMessage");
> +        } else {
> +            message = R("RBrowserLocationPromptMessageWithReason", previousCommand);
> +        }
>          return JOptionPane.showInputDialog(new JPanel(),
> -                                           "Browser Location:",
> -                                           "Specify Browser Location",
> +                                           R("RBrowserLocationPromptTitle"),
> +                                           message,
>                                             JOptionPane.PLAIN_MESSAGE
>                                            );
>      }


-- 
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and IcedTea
http://www.gnu.org/software/classpath
http://icedtea.classpath.org
PGP Key: F5862A37 (https://keys.indymedia.org/)
Fingerprint = EA30 D855 D50F 90CD F54D  0698 0713 C3ED F586 2A37



More information about the distro-pkg-dev mailing list