< prev index next >

modules/javafx.graphics/src/main/java/javafx/application/HostServices.java

Print this page
rev 10669 : 8187149: Remove HostServices::getWebContext
Reviewed-by:


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.application;
  27 
  28 import java.net.URI;
  29 
  30 import netscape.javascript.JSObject;
  31 
  32 import com.sun.javafx.application.HostServicesDelegate;
  33 
  34 /**
  35  * This class provides HostServices for an Application. This includes
  36  * methods to get the code base and document base for an Application,
  37  * show a web page in a browser, and communicate with the enclosing web page
  38  * using JavaScript if the Application is running in
  39  * a browser.
  40  * @since JavaFX 2.0
  41  */
  42 public final class HostServices {
  43 
  44     private final HostServicesDelegate delegate;
  45 
  46     /**
  47      * Package scope constructor to create the HostServices object.
  48      *
  49      * @param app the application class
  50      */
  51     HostServices(Application app) {
  52         delegate = HostServicesDelegate.getInstance(app);
  53     }
  54 
  55     /**
  56      * Gets the code base URI for this application.
  57      * If the application was launched via a JNLP file, this method returns
  58      * the codebase parameter specified in the JNLP file.
  59      * If the application was launched in standalone mode, this method returns


 106      * any other error in resolving the URI.
 107      *
 108      * @return the fully resolved URI.
 109      */
 110     public final String resolveURI(String base, String rel) {
 111         URI uri = URI.create(base).resolve(rel);
 112         return uri.toString();
 113     }
 114 
 115     /**
 116      * Opens the specified URI in a new browser window or tab.
 117      * The determination of whether it is a new browser window or a tab in
 118      * an existing browser window will be made by the browser preferences.
 119      * Note that this will respect the pop-up blocker settings of the default
 120      * browser; it will not try to circumvent them.
 121      *
 122      * @param uri the URI of the web page that will be opened in a browser.
 123      */
 124     public final void showDocument(String uri) {
 125         delegate.showDocument(uri);
 126     }
 127 
 128     /**
 129      * Returns the JavaScript handle of the enclosing DOM window of the web
 130      * page containing this application.
 131      * This handle is used to access the web page by calling from Java into
 132      * JavaScript.
 133      * If the application is not embedded into a web page, this method
 134      * return null.
 135      *
 136      * <p>Example:</p>
 137      * <pre>{@code
 138      *     JSObject jsWin = getHostServices().getWebContext();
 139      *     if (jsWin != null) {
 140      *         jsWin.eval("var b = document.body;" +
 141      *                    "var newdiv = document.createElement('div');" +
 142      *                    "newdiv.innerHTML = '<br>Hello from JavaScript!';" +
 143      *                    "b.appendChild(newdiv);");
 144      *     }
 145      * }</pre>
 146      *
 147      * @return handle of the enclosing DOM window of the web page containing
 148      * this application
 149      *
 150      * @deprecated This method is deprecated as of JDK 9 because the
 151      * {@link java.applet.Applet Applet} API is deprecated.
 152      */
 153     @Deprecated(since="9", forRemoval=true)
 154     public final JSObject getWebContext() {
 155         return delegate.getWebContext();
 156     }
 157 
 158 }


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.application;
  27 
  28 import java.net.URI;
  29 


  30 import com.sun.javafx.application.HostServicesDelegate;
  31 
  32 /**
  33  * This class provides HostServices for an Application. This includes
  34  * methods to get the code base and document base for an Application,
  35  * and to show a web page in a browser.
  36  *

  37  * @since JavaFX 2.0
  38  */
  39 public final class HostServices {
  40 
  41     private final HostServicesDelegate delegate;
  42 
  43     /**
  44      * Package scope constructor to create the HostServices object.
  45      *
  46      * @param app the application class
  47      */
  48     HostServices(Application app) {
  49         delegate = HostServicesDelegate.getInstance(app);
  50     }
  51 
  52     /**
  53      * Gets the code base URI for this application.
  54      * If the application was launched via a JNLP file, this method returns
  55      * the codebase parameter specified in the JNLP file.
  56      * If the application was launched in standalone mode, this method returns


 103      * any other error in resolving the URI.
 104      *
 105      * @return the fully resolved URI.
 106      */
 107     public final String resolveURI(String base, String rel) {
 108         URI uri = URI.create(base).resolve(rel);
 109         return uri.toString();
 110     }
 111 
 112     /**
 113      * Opens the specified URI in a new browser window or tab.
 114      * The determination of whether it is a new browser window or a tab in
 115      * an existing browser window will be made by the browser preferences.
 116      * Note that this will respect the pop-up blocker settings of the default
 117      * browser; it will not try to circumvent them.
 118      *
 119      * @param uri the URI of the web page that will be opened in a browser.
 120      */
 121     public final void showDocument(String uri) {
 122         delegate.showDocument(uri);






























 123     }
 124 
 125 }
< prev index next >