Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4506852

Regression: Opening a browser window under Windows OS fails under 1.3.1_01

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0_01
    • deploy
    • beta3
    • x86
    • windows_2000
    • Verified



      Name: bsT130419 Date: 09/25/2001


      java version "1.3.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
      Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)


      Somewhere between versions 1.3.0 and 1.3.1_01, an AccessControlException was
      introduced while trying to use Java to open a browser window. Below is a
      static method that can be used to open such a window from either an application
      or an applet in a browser on a Windows platform. When I uninstall the most
      recent version, and regress to the older version, a new browser window is
      opened as expected. After I upgrade to the recent version of the Java Plugin,
      the area indicated by "NOTICE" is executed, signifying an exception thrown, and
      no window is opened.

        This method is typically called by the command:
      WindowsHelp.launchBrowser("http://www.integretechpub.com/", (Applet) this);


      import java.applet.Applet;
      import java.io.IOException;
      import java.security.AccessControlException;
      import javax.swing.JOptionPane;
      import netscape.javascript.JSObject;

      public class WindowsHelp
        {
      /** Wrapper for {@link Runtime#exec(String)}.
        * You will not see the console output of the spawned command.
        * @param command fully qualified *.exe or *.com command
        * @author Roedy Green http://www.mindprod.com/
        */
        public static Process exec(String command, boolean wait)
          {
          Process p;
          try
            { p = Runtime.getRuntime().exec(command); }

          catch (IOException ioe)
            { return null; }

          if (wait)
            {
            try
              { p.waitFor(); }
            catch (InterruptedException ie)
              {}

            } // ends if

          return p;
          } // ends exec(String, boolean)

      /** This method tries to launch a browser window to the requested
        * internet address. It has two possible ways of doing this,
        * depending on the value in <I>app</I>. The first attempted
        * algorithm is cross-platform, whereas the second is Windows-specific.
        * @param url A fully-qualified <CODE>String</CODE> representation of
        * the desired URL, or an actual <CODE>URL</CODE> object.
        * Either way, the <CODE>toString()</CODE> method is used
        * to acquire the address.
        * @param app If the calling method is initiated by a browser-based
        * <CODE>Applet</CODE> subclass, this argument should be
        * that <CODE>Applet</CODE> instance. This is so that we may
        * attempt to use JavaScript to launch the new browser window.
        * This has the ability to be a cross-platform solution. If
        * the requests derives from an application-based subclass,
        * this argument should be <CODE>null</CODE> (though it does
        * not really matter as all <CODE>Error</CODE> or
        * <CODE>Exception</CODE> objects thrown are caught in that
        * case) and the Windows-specific solution of launching a
        * <CODE>DLL</CODE> is attempted.
        */
        public static void launchBrowser(Object url, Applet app)
          {
          boolean notInBrowser = true;

          try
            {
            if (app == null)
              throw new NullPointerException();

            JSObject javascript = JSObject.getWindow(app);
            if (javascript != null)
              {
              notInBrowser = false;
              String command = "window.open('" + url + "', '_blank');";
              javascript.eval(command);
              } // ends if

            } // ends try

          catch(Throwable t)
            {}

          if (notInBrowser)
            {
            try
              {
              String windowsCommand = "rundll32.exe url.dll,FileProtocolHandler " +url;
              Process p = WindowsHelp.exec(windowsCommand, false);
              if (p == null)
                {
                String msg = "Process was null for some reason.\n" + " Assuming permission issues...";
                throw new AccessControlException(msg);
                } // ends if

              } // ends try

            catch(AccessControlException ace)
              {
      // BEGIN NOTICE
      // An exception is caught here under version 1.3.1_01,
      // but not under version 1.3.0. What happened?
      // END NOTICE
              JOptionPane.showMessageDialog(null, "A browser window could not be successfully opened.\n" + "Please visit http://www.integretechpub.com/ at your convenience.",
               "Error", JOptionPane.WARNING_MESSAGE);
              } // ends catch(AccessControlException)

            } // ends if

          } // ends launchBrowser(Object, Applet)

        } // ends class WindowsHelp
      (Review ID: 132066)
      ======================================================================

            dgu Dennis Gu (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: