[rfc] netx: display file name in warning dialog

Deepak Bhole dbhole at redhat.com
Wed Sep 29 12:11:08 PDT 2010


* Deepak Bhole <dbhole at redhat.com> [2010-09-29 15:07]:
> * Omair Majid <omajid at redhat.com> [2010-09-29 14:47]:
> > Hi,
> > 
> > The attached patch adds the filename to the file access warning
> > dialogs used by netx.
> > 
> > Any comments?
> > 
> 
> Looks good to me. Okay for HEAD and backport to 1.7/1.8/1.9 as showing
> filename is a good enough feature, worth a backport.
> 

Just saw Andrew's note. +1 on the storing the "(visibleChars - 3) / 2"
result and using that. As for changes to XExtendedService, I assume 
they are needed to store the filepath in the extras array. Can you 
please confirm?

Cheers,
Deepak

> Cheers,
> Deepak
> 
> > Cheers,
> > Omair
> 
> > diff -r e470c7b5f2dc netx/net/sourceforge/jnlp/resources/Messages.properties
> > --- a/netx/net/sourceforge/jnlp/resources/Messages.properties	Mon Sep 20 00:18:57 2010 +0100
> > +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties	Wed Sep 29 14:45:26 2010 -0400
> > @@ -6,6 +6,7 @@
> >  ButOk=OK
> >  ButCancel=\ Cancel\ 
> >  ButBrowse=Browse...
> > +AFileOnTheMachine=a file on the machine
> >  
> >  # LS - Severity
> >  LSMinor=Minor
> > @@ -150,8 +151,8 @@
> >  CChooseCacheDir=Cache directory
> >  
> >  # Security
> > -SFileReadAccess=The application has requested read access to a file on the machine. Do you want to allow this action?
> > -SFileWriteAccess=The application has requested write access to a file on the machine. Do you want to allow this action?
> > +SFileReadAccess=The application has requested read access to {0}. Do you want to allow this action?
> > +SFileWriteAccess=The application has requested write access to {0}. Do you want to allow this action?
> >  SDesktopShortcut=The application has requested permission to create a desktop launcher. Do you want to allow this action?
> >  SSigUnverified=The application's digital signature cannot be verified. Do you want to run the application?
> >  SSigVerified=The application's digital signature has been verified. Do you want to run the application?
> > diff -r e470c7b5f2dc netx/net/sourceforge/jnlp/security/AccessWarningPane.java
> > --- a/netx/net/sourceforge/jnlp/security/AccessWarningPane.java	Mon Sep 20 00:18:57 2010 +0100
> > +++ b/netx/net/sourceforge/jnlp/security/AccessWarningPane.java	Wed Sep 29 14:45:26 2010 -0400
> > @@ -56,6 +56,7 @@
> >  import javax.swing.SwingConstants;
> >  
> >  import net.sourceforge.jnlp.JNLPFile;
> > +import net.sourceforge.jnlp.util.FileUtils;
> >  
> >  /**
> >   * Provides a panel to show inside a SecurityWarningDialog. These dialogs are
> > @@ -114,10 +115,18 @@
> >                  String topLabelText = "";
> >                  switch (type) {
> >                          case READ_FILE:
> > -                                topLabelText = R("SFileReadAccess");
> > +                                if (extras != null && extras.length > 0 && extras[0] instanceof String) {
> > +                                    topLabelText = R("SFileReadAccess", FileUtils.displayablePath((String)extras[0]));
> > +                                } else {
> > +                                    topLabelText = R("SFileReadAccess", R("AFileOnTheMachine"));
> > +                                }
> >                                  break;
> >                          case WRITE_FILE:
> > -                                topLabelText = R("SFileWriteAccess");
> > +                                if (extras != null && extras.length > 0 && extras[0] instanceof String) {
> > +                                    topLabelText = R("SFileWriteAccess", FileUtils.displayablePath((String)extras[0]));
> > +                                } else {
> > +                                    topLabelText = R("SFileWriteAccess", R("AFileOnTheMachine"));
> > +                                }
> >                                  break;
> >                          case CREATE_DESTKOP_SHORTCUT:
> >                              topLabelText = R("SDesktopShortcut");
> > @@ -145,7 +154,7 @@
> >                  JPanel topPanel = new JPanel(new BorderLayout());
> >                  topPanel.setBackground(Color.WHITE);
> >                  topPanel.add(topLabel, BorderLayout.CENTER);
> > -                topPanel.setPreferredSize(new Dimension(400,60));
> > +                topPanel.setPreferredSize(new Dimension(450,100));
> >                  topPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
> >  
> >                  //application info
> > diff -r e470c7b5f2dc netx/net/sourceforge/jnlp/services/XExtendedService.java
> > --- a/netx/net/sourceforge/jnlp/services/XExtendedService.java	Mon Sep 20 00:18:57 2010 +0100
> > +++ b/netx/net/sourceforge/jnlp/services/XExtendedService.java	Wed Sep 29 14:45:26 2010 -0400
> > @@ -34,7 +34,9 @@
> >  
> >      public FileContents openFile(File file) throws IOException {
> >  
> > -        if (ServiceUtil.checkAccess(SecurityWarningDialog.AccessType.READ_FILE)) {
> > +        /* FIXME: this opens a file with read/write mode, not just read or write */
> > +        if (ServiceUtil.checkAccess(SecurityWarningDialog.AccessType.READ_FILE,
> > +                new Object[]{ file.getAbsolutePath() })) {
> >              return (FileContents) ServiceUtil.createPrivilegedProxy(FileContents.class,
> >                      new XFileContents(file));
> >          } else {
> > diff -r e470c7b5f2dc netx/net/sourceforge/jnlp/util/FileUtils.java
> > --- a/netx/net/sourceforge/jnlp/util/FileUtils.java	Mon Sep 20 00:18:57 2010 +0100
> > +++ b/netx/net/sourceforge/jnlp/util/FileUtils.java	Wed Sep 29 14:45:26 2010 -0400
> > @@ -68,4 +68,49 @@
> >          return filename;
> >      }
> >  
> > +    /**
> > +     * Returns a String that is suitable for using in GUI elements for
> > +     * displaying (long) paths to users.
> > +     *
> > +     * @param path a path that should be shortened
> > +     * @return a shortened path suitable for displaying to the user
> > +     */
> > +    public static String displayablePath(String path) {
> > +        final int DEFAULT_LENGTH = 40;
> > +        return displayablePath(path, DEFAULT_LENGTH);
> > +    }
> > +
> > +    /**
> > +     * Return a String that is suitable for using in GUI elements for displaying
> > +     * paths to users. If the path is longer than visibleChars, it is truncated
> > +     * in a display-friendly way
> > +     *
> > +     * @param path a path that should be shorted
> > +     * @param visibleChars the maximum number of characters that path should fit
> > +     *        into. Also the length of the returned string
> > +     * @return a shortened path that contains limited number of chars
> > +     */
> > +    public static String displayablePath(String path, int visibleChars) {
> > +        /*
> > +         * a very simple method prefix + "..." + suffix where prefix = beginning
> > +         * part of path and suffix = end path of path
> > +         */
> > +
> > +        if (path == null || path.length() <= visibleChars) {
> > +            return path;
> > +        }
> > +
> > +        /*
> > +         * if we have too few chars, then just return as much as we can of the
> > +         * filename
> > +         */
> > +        if (visibleChars < 5) {
> > +            return path.substring(path.length() - visibleChars);
> > +        }
> > +        String prefix = path.substring(0, (visibleChars - 3) / 2);
> > +        String suffix = path.substring(path.length() - (visibleChars - 3) / 2);
> > +
> > +        return prefix + "..." + suffix;
> > +    }
> > +
> >  }
> 



More information about the distro-pkg-dev mailing list