< prev index next >

modules/javafx.graphics/src/main/java/com/sun/javafx/application/HostServicesDelegate.java

Print this page
rev 10669 : 8187149: Remove HostServices::getWebContext
Reviewed-by:
   1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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 com.sun.javafx.application;
  27 
  28 import java.awt.Desktop;
  29 import java.io.File;
  30 import java.lang.reflect.Method;
  31 import java.net.URI;
  32 import java.security.AccessController;
  33 import java.security.PrivilegedActionException;
  34 import java.security.PrivilegedExceptionAction;
  35 import javafx.application.Application;
  36 import netscape.javascript.JSObject;
  37 
  38 
  39 public abstract class HostServicesDelegate {
  40 
  41     private static Method getInstanceMeth = null;
  42 
  43     public static HostServicesDelegate getInstance(final Application app) {
  44         // Call into the deploy code to get the delegate class
  45         HostServicesDelegate instance = null;
  46         try {
  47             instance = AccessController.doPrivileged(
  48                     (PrivilegedExceptionAction<HostServicesDelegate>) () -> {
  49                         if (getInstanceMeth == null) {
  50                             try {
  51                                 final String factoryClassName =
  52                                         "com.sun.deploy.uitoolkit.impl.fx.HostServicesFactory";
  53 
  54                                 Class factoryClass = Class.forName(factoryClassName,
  55                                         true,
  56                                         HostServicesDelegate.class.getClassLoader());
  57                                 getInstanceMeth = factoryClass.getMethod(


  67         } catch (PrivilegedActionException pae) {
  68             System.err.println(pae.getException().toString());
  69             return null;
  70         }
  71         if (instance == null) {
  72             // in this case we are in standalone mode
  73             instance = StandaloneHostService.getInstance(app);
  74         }
  75         return instance;
  76     }
  77 
  78     protected HostServicesDelegate() {
  79     }
  80 
  81     public abstract String getCodeBase();
  82 
  83     public abstract String getDocumentBase();
  84 
  85     public abstract void showDocument(String uri);
  86 
  87     public abstract JSObject getWebContext();
  88 
  89     // StandaloneHostService implementation
  90     private static class StandaloneHostService extends HostServicesDelegate {
  91 
  92         private static HostServicesDelegate instance = null;
  93 
  94         private Class appClass = null;
  95 
  96         public static HostServicesDelegate getInstance(Application app) {
  97             synchronized (StandaloneHostService.class) {
  98                 if (instance == null) {
  99                     instance = new StandaloneHostService(app);
 100                 }
 101                 return instance;
 102             }
 103         }
 104 
 105         private StandaloneHostService(Application app) {
 106              appClass = app.getClass();
 107         }
 108 


 175                 } else if (osName.startsWith("Windows")) {
 176                     Runtime.getRuntime().exec(
 177                             "rundll32 url.dll,FileProtocolHandler " + uri);
 178                 } else { //assume Unix or Linux
 179                     String browser = null;
 180                     for (String b : browsers) {
 181                         if (browser == null && Runtime.getRuntime().exec(
 182                                 new String[]{"which", b}).getInputStream().read() != -1) {
 183                             Runtime.getRuntime().exec(new String[]{browser = b, uri});
 184                         }
 185                     }
 186                     if (browser == null) {
 187                         throw new Exception("No web browser found");
 188                     }
 189                 }
 190             } catch (Exception e) {
 191                 // should not happen
 192                 // dump stack for debug purpose
 193                 e.printStackTrace();
 194             }
 195         }
 196 
 197         @Override public JSObject getWebContext() {
 198             return null;
 199         }
 200     }
 201 }
   1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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 com.sun.javafx.application;
  27 
  28 import java.awt.Desktop;
  29 import java.io.File;
  30 import java.lang.reflect.Method;
  31 import java.net.URI;
  32 import java.security.AccessController;
  33 import java.security.PrivilegedActionException;
  34 import java.security.PrivilegedExceptionAction;
  35 import javafx.application.Application;


  36 
  37 public abstract class HostServicesDelegate {
  38 
  39     private static Method getInstanceMeth = null;
  40 
  41     public static HostServicesDelegate getInstance(final Application app) {
  42         // Call into the deploy code to get the delegate class
  43         HostServicesDelegate instance = null;
  44         try {
  45             instance = AccessController.doPrivileged(
  46                     (PrivilegedExceptionAction<HostServicesDelegate>) () -> {
  47                         if (getInstanceMeth == null) {
  48                             try {
  49                                 final String factoryClassName =
  50                                         "com.sun.deploy.uitoolkit.impl.fx.HostServicesFactory";
  51 
  52                                 Class factoryClass = Class.forName(factoryClassName,
  53                                         true,
  54                                         HostServicesDelegate.class.getClassLoader());
  55                                 getInstanceMeth = factoryClass.getMethod(


  65         } catch (PrivilegedActionException pae) {
  66             System.err.println(pae.getException().toString());
  67             return null;
  68         }
  69         if (instance == null) {
  70             // in this case we are in standalone mode
  71             instance = StandaloneHostService.getInstance(app);
  72         }
  73         return instance;
  74     }
  75 
  76     protected HostServicesDelegate() {
  77     }
  78 
  79     public abstract String getCodeBase();
  80 
  81     public abstract String getDocumentBase();
  82 
  83     public abstract void showDocument(String uri);
  84 


  85     // StandaloneHostService implementation
  86     private static class StandaloneHostService extends HostServicesDelegate {
  87 
  88         private static HostServicesDelegate instance = null;
  89 
  90         private Class appClass = null;
  91 
  92         public static HostServicesDelegate getInstance(Application app) {
  93             synchronized (StandaloneHostService.class) {
  94                 if (instance == null) {
  95                     instance = new StandaloneHostService(app);
  96                 }
  97                 return instance;
  98             }
  99         }
 100 
 101         private StandaloneHostService(Application app) {
 102              appClass = app.getClass();
 103         }
 104 


 171                 } else if (osName.startsWith("Windows")) {
 172                     Runtime.getRuntime().exec(
 173                             "rundll32 url.dll,FileProtocolHandler " + uri);
 174                 } else { //assume Unix or Linux
 175                     String browser = null;
 176                     for (String b : browsers) {
 177                         if (browser == null && Runtime.getRuntime().exec(
 178                                 new String[]{"which", b}).getInputStream().read() != -1) {
 179                             Runtime.getRuntime().exec(new String[]{browser = b, uri});
 180                         }
 181                     }
 182                     if (browser == null) {
 183                         throw new Exception("No web browser found");
 184                     }
 185                 }
 186             } catch (Exception e) {
 187                 // should not happen
 188                 // dump stack for debug purpose
 189                 e.printStackTrace();
 190             }




 191         }
 192     }
 193 }
< prev index next >