changeset 36:5537145cde35

integrate desktop shortcut creation with configuration 2010-11-05 Omair Majid <omajid@redhat.com> * netx/net/sourceforge/jnlp/ShortcutDesc.java: Change prefixes from SHORTCUT_ to CREATE_. * netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java (addMenuAndDesktopEntries): Call shouldCreateShortcut to find out if shortcut should be created. Remove call to checkAccess which does nothing as the entire stack contains trusted classes. (shouldCreateShortcut): New method. Use the configuration to find out if a shorcut should be created, and possibly prompt the user. * netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java: Add KEY_CREATE_DESKTOP_SHORTCUT. (loadDefaultProperties): Use KEY_CREATE_DESKTOP_SHORTCUT.
author Omair Majid <omajid@redhat.com>
date Wed, 10 Nov 2010 16:07:06 -0500
parents f089abbcf019
children 3cac6a3232e6
files ChangeLog netx/net/sourceforge/jnlp/ShortcutDesc.java netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java
diffstat 4 files changed, 64 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Nov 08 16:48:38 2010 -0500
+++ b/ChangeLog	Wed Nov 10 16:07:06 2010 -0500
@@ -1,3 +1,17 @@
+2010-11-05  Omair Majid  <omajid@redhat.com>
+
+	* netx/net/sourceforge/jnlp/ShortcutDesc.java: Change prefixes from
+	SHORTCUT_ to CREATE_.
+	* netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java
+	(addMenuAndDesktopEntries): Call shouldCreateShortcut to find out
+	if shortcut should be created. Remove call to checkAccess which
+	does nothing as the entire stack contains trusted classes.
+	(shouldCreateShortcut): New method. Use the configuration to find
+	out if a shorcut should be created, and possibly prompt the user.
+	* netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java:
+	Add KEY_CREATE_DESKTOP_SHORTCUT.
+	(loadDefaultProperties): Use KEY_CREATE_DESKTOP_SHORTCUT.
+
 2010-11-08  Omair Majid  <omajid@redhat.com>
 
 	* Makefile.am (JDK_UPDATE_VERSION): Define variable.
--- a/netx/net/sourceforge/jnlp/ShortcutDesc.java	Mon Nov 08 16:48:38 2010 -0500
+++ b/netx/net/sourceforge/jnlp/ShortcutDesc.java	Wed Nov 10 16:07:06 2010 -0500
@@ -19,16 +19,15 @@
 public final class ShortcutDesc {
 
     /** Never create a shortcut */
-    public static final String SHORTCUT_NEVER = "NEVER";
+    public static final String CREATE_NEVER = "NEVER";
     /** Always create a shortcut */
-    public static final String SHORTCUT_ALWAYS = "ALWAYS";
+    public static final String CREATE_ALWAYS = "ALWAYS";
     /** Always ask user whether to create a shortcut */
-    public static final String SHORTCUT_ASK_USER = "ASK_USER";
+    public static final String CREATE_ASK_USER = "ASK_USER";
     /** Ask user whether to create a shortcut but only if jnlp file asks for it */
-    public static final String SHORTCUT_ASK_USER_IF_HINTED = "ASK_IF_HINTED";
+    public static final String CREATE_ASK_USER_IF_HINTED = "ASK_IF_HINTED";
     /** Create a desktop shortcut without prompting if the jnlp asks for it */
-    public static final String SHORTCUT_ALWAYS_IF_HINTED = "ALWAYS_IF_HINTED";
-    public static final String SHORTCUT_DEFAULT = SHORTCUT_ASK_USER_IF_HINTED;
+    public static final String CREATE_ALWAYS_IF_HINTED = "ALWAYS_IF_HINTED";
 
     /** the application wants to be placed on the desktop */
     private boolean onDesktop = false;
--- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java	Mon Nov 08 16:48:38 2010 -0500
+++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java	Wed Nov 10 16:07:06 2010 -0500
@@ -35,6 +35,7 @@
 import net.sourceforge.jnlp.ShortcutDesc;
 import net.sourceforge.jnlp.event.ApplicationEvent;
 import net.sourceforge.jnlp.event.ApplicationListener;
+import net.sourceforge.jnlp.security.SecurityWarning;
 import net.sourceforge.jnlp.security.SecurityWarning.AccessType;
 import net.sourceforge.jnlp.services.ServiceUtil;
 import net.sourceforge.jnlp.util.WeakList;
@@ -148,10 +149,8 @@
         XDesktopEntry entry = new XDesktopEntry(file);
         ShortcutDesc sd = file.getInformation().getShortcut();
 
-        if (sd != null && sd.onDesktop()) {
-            if (ServiceUtil.checkAccess(this, AccessType.CREATE_DESTKOP_SHORTCUT)) {
-                entry.createDesktopShortcut();
-            }
+        if (shouldCreateShortcut(sd)) {
+            entry.createDesktopShortcut();
         }
 
         if (sd != null && sd.getMenu() != null) {
@@ -167,6 +166,45 @@
     }
 
     /**
+     * Indicates whether a desktop launcher/shortcut should be created for this
+     * application instance
+     *
+     * @param sd the ShortcutDesc element from the JNLP file
+     * @return true if a desktop shortcut should be created
+     */
+    private boolean shouldCreateShortcut(ShortcutDesc sd) {
+        String currentSetting = JNLPRuntime.getConfiguration()
+            .getProperty(DeploymentConfiguration.KEY_CREATE_DESKTOP_SHORTCUT);
+        boolean createShortcut = false;
+
+        /*
+         * check configuration and possibly prompt user to find out if a
+         * shortcut should be created or not
+         */
+        if (currentSetting.equals(ShortcutDesc.CREATE_NEVER)) {
+            createShortcut = false;
+        } else if (currentSetting.equals(ShortcutDesc.CREATE_ALWAYS)) {
+            createShortcut = true;
+        } else if (currentSetting.equals(ShortcutDesc.CREATE_ASK_USER)) {
+            if (SecurityWarning.showAccessWarningDialog(AccessType.CREATE_DESTKOP_SHORTCUT, file)) {
+                createShortcut = true;
+            }
+        } else if (currentSetting.equals(ShortcutDesc.CREATE_ASK_USER_IF_HINTED)) {
+            if (sd != null && sd.onDesktop()) {
+                if (SecurityWarning.showAccessWarningDialog(AccessType.CREATE_DESTKOP_SHORTCUT, file)) {
+                    createShortcut = true;
+                }
+            }
+        } else if (currentSetting.equals(ShortcutDesc.CREATE_ALWAYS_IF_HINTED)) {
+            if (sd != null && sd.onDesktop()) {
+                createShortcut = true;
+            }
+        }
+
+        return createShortcut;
+    }
+
+    /**
      * Releases the application's resources before it is collected.
      * Only collectable if classloader and thread group are
      * also collectable so basically is almost never called (an
--- a/netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java	Mon Nov 08 16:48:38 2010 -0500
+++ b/netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java	Wed Nov 10 16:07:06 2010 -0500
@@ -154,6 +154,8 @@
     public static final String KEY_SYSTEM_TRUSTED_JSSE_CERTS = "deployment.system.security.trusted.jssecerts";
     public static final String KEY_SYSTEM_TRUSTED_CLIENT_CERTS = "deployment.system.security.trusted.clientautcerts";
 
+    public static final String KEY_CREATE_DESKTOP_SHORTCUT = "deployment.javaws.shortcut";
+
     public enum ConfigType {
         System, User
     }
@@ -375,7 +377,7 @@
             /* JNLP association */
             { "deployment.javaws.associations", String.valueOf(JNLP_ASSOCIATION_ASK_USER) },
             /* desktop integration */
-            { "deployment.javaws.shortcut", ShortcutDesc.SHORTCUT_ASK_USER_IF_HINTED},
+            { KEY_CREATE_DESKTOP_SHORTCUT, ShortcutDesc.CREATE_ASK_USER_IF_HINTED},
             /* jre selection */
             { "deployment.javaws.installURL", null },
             /* jre management */