# HG changeset patch # User malenkov # Date 1390323216 -14400 # Node ID 51af43e32270f375cd44787f090d7ecdd9785748 # Parent 4a8ca39187efa0788d09c140c0b65003fff729c7 8026797: Enhance data transfers Reviewed-by: art, skoivu diff -r 4a8ca39187ef -r 51af43e32270 jdk/src/macosx/classes/sun/lwawt/macosx/CClipboard.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CClipboard.java Tue Jan 21 10:49:19 2014 +0000 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CClipboard.java Tue Jan 21 20:53:36 2014 +0400 @@ -58,7 +58,7 @@ @Override protected void setContentsNative(Transferable contents) { - + FlavorTable flavorMap = getDefaultFlavorTable(); // Don't use delayed Clipboard rendering for the Transferable's data. // If we did that, we would call Transferable.getTransferData on // the Toolkit thread, which is a security hole. diff -r 4a8ca39187ef -r 51af43e32270 jdk/src/share/classes/java/awt/datatransfer/SystemFlavorMap.java --- a/jdk/src/share/classes/java/awt/datatransfer/SystemFlavorMap.java Tue Jan 21 10:49:19 2014 +0000 +++ b/jdk/src/share/classes/java/awt/datatransfer/SystemFlavorMap.java Tue Jan 21 20:53:36 2014 +0400 @@ -46,6 +46,7 @@ import java.util.Set; import java.util.WeakHashMap; +import sun.awt.AppContext; import sun.awt.datatransfer.DataTransferer; /** @@ -65,10 +66,7 @@ */ private static String JavaMIME = "JAVA_DATAFLAVOR:"; - /** - * System singleton which maps a thread's ClassLoader to a SystemFlavorMap. - */ - private static final WeakHashMap flavorMaps = new WeakHashMap<>(); + private static final Object FLAVOR_MAP_KEY = new Object(); /** * Copied from java.util.Properties. @@ -183,22 +181,12 @@ * @return the default FlavorMap for this thread's ClassLoader */ public static FlavorMap getDefaultFlavorMap() { - ClassLoader contextClassLoader = - Thread.currentThread().getContextClassLoader(); - if (contextClassLoader == null) { - contextClassLoader = ClassLoader.getSystemClassLoader(); + AppContext context = AppContext.getAppContext(); + FlavorMap fm = (FlavorMap) context.get(FLAVOR_MAP_KEY); + if (fm == null) { + fm = new SystemFlavorMap(); + context.put(FLAVOR_MAP_KEY, fm); } - - FlavorMap fm; - - synchronized(flavorMaps) { - fm = flavorMaps.get(contextClassLoader); - if (fm == null) { - fm = new SystemFlavorMap(); - flavorMaps.put(contextClassLoader, fm); - } - } - return fm; } @@ -239,26 +227,11 @@ } }); - BufferedReader flavormapURL = + String url = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public BufferedReader run() { - String url = Toolkit.getProperty("AWT.DnD.flavorMapFileURL", null); - - if (url == null) { - return null; - } - - try { - return new BufferedReader - (new InputStreamReader - (new URL(url).openStream(), "ISO-8859-1")); - } catch (MalformedURLException e) { - System.err.println("MalformedURLException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); - } catch (IOException e) { - System.err.println("IOException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); - } - return null; + new java.security.PrivilegedAction() { + public String run() { + return Toolkit.getProperty("AWT.DnD.flavorMapFileURL", null); } }); @@ -270,6 +243,19 @@ } } + BufferedReader flavormapURL = null; + if (url != null) { + try { + flavormapURL = new BufferedReader(new InputStreamReader(new URL(url).openStream(), "ISO-8859-1")); + } catch (MalformedURLException e) { + System.err.println("MalformedURLException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); + } catch (IOException e) { + System.err.println("IOException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); + } catch (SecurityException e) { + // ignored + } + } + if (flavormapURL != null) { try { parseAndStoreReader(flavormapURL); diff -r 4a8ca39187ef -r 51af43e32270 jdk/src/share/classes/sun/awt/datatransfer/ClipboardTransferable.java --- a/jdk/src/share/classes/sun/awt/datatransfer/ClipboardTransferable.java Tue Jan 21 10:49:19 2014 +0000 +++ b/jdk/src/share/classes/sun/awt/datatransfer/ClipboardTransferable.java Tue Jan 21 20:53:36 2014 +0400 @@ -85,7 +85,7 @@ // read it. Map cached_data = new HashMap<>(formats.length, 1.0f); DataTransferer.getInstance() - .getFlavorsForFormats(formats, SunClipboard.flavorMap) + .getFlavorsForFormats(formats, SunClipboard.getDefaultFlavorTable()) .entrySet() .forEach(entry -> fetchOneFlavor(clipboard, entry.getKey(), entry.getValue(), cached_data)); flavors = DataTransferer.setToSortedDataFlavorArray(flavorsToData.keySet()); diff -r 4a8ca39187ef -r 51af43e32270 jdk/src/share/classes/sun/awt/datatransfer/SunClipboard.java --- a/jdk/src/share/classes/sun/awt/datatransfer/SunClipboard.java Tue Jan 21 10:49:19 2014 +0000 +++ b/jdk/src/share/classes/sun/awt/datatransfer/SunClipboard.java Tue Jan 21 20:53:36 2014 +0400 @@ -64,9 +64,6 @@ public abstract class SunClipboard extends Clipboard implements PropertyChangeListener { - public static final FlavorTable flavorMap = - (FlavorTable)SystemFlavorMap.getDefaultFlavorMap(); - private AppContext contentsContext = null; private final Object CLIPBOARD_FLAVOR_LISTENER_KEY; @@ -172,7 +169,7 @@ long[] formats = getClipboardFormatsOpenClose(); return DataTransferer.getInstance(). - getFlavorsForFormatsAsArray(formats, flavorMap); + getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable()); } /** @@ -218,7 +215,7 @@ long[] formats = getClipboardFormats(); Long lFormat = DataTransferer.getInstance(). - getFlavorsForFormats(formats, flavorMap).get(flavor); + getFlavorsForFormats(formats, getDefaultFlavorTable()).get(flavor); if (lFormat == null) { throw new UnsupportedFlavorException(flavor); @@ -349,7 +346,7 @@ private static Set formatArrayAsDataFlavorSet(long[] formats) { return (formats == null) ? null : DataTransferer.getInstance(). - getFlavorsForFormatsAsSet(formats, flavorMap); + getFlavorsForFormatsAsSet(formats, getDefaultFlavorTable()); } @@ -469,4 +466,7 @@ } } + public static FlavorTable getDefaultFlavorTable() { + return (FlavorTable) SystemFlavorMap.getDefaultFlavorMap(); + } } diff -r 4a8ca39187ef -r 51af43e32270 jdk/src/solaris/classes/sun/awt/X11/XClipboard.java --- a/jdk/src/solaris/classes/sun/awt/X11/XClipboard.java Tue Jan 21 10:49:19 2014 +0000 +++ b/jdk/src/solaris/classes/sun/awt/X11/XClipboard.java Tue Jan 21 20:53:36 2014 +0400 @@ -86,7 +86,7 @@ protected synchronized void setContentsNative(Transferable contents) { SortedMap formatMap = DataTransferer.getInstance().getFormatsForTransferable - (contents, DataTransferer.adaptFlavorMap(flavorMap)); + (contents, DataTransferer.adaptFlavorMap(getDefaultFlavorTable())); long[] formats = DataTransferer.keysToLongArray(formatMap); if (!selection.setOwner(contents, formatMap, formats, @@ -125,7 +125,7 @@ private void checkChangeHere(Transferable contents) { if (areFlavorListenersRegistered()) { checkChange(DataTransferer.getInstance(). - getFormatsForTransferableAsArray(contents, flavorMap)); + getFormatsForTransferableAsArray(contents, getDefaultFlavorTable())); } } diff -r 4a8ca39187ef -r 51af43e32270 jdk/src/windows/classes/sun/awt/windows/WClipboard.java --- a/jdk/src/windows/classes/sun/awt/windows/WClipboard.java Tue Jan 21 10:49:19 2014 +0000 +++ b/jdk/src/windows/classes/sun/awt/windows/WClipboard.java Tue Jan 21 20:53:36 2014 +0400 @@ -62,7 +62,6 @@ @Override protected void setContentsNative(Transferable contents) { - // Don't use delayed Clipboard rendering for the Transferable's data. // If we did that, we would call Transferable.getTransferData on // the Toolkit thread, which is a security hole. @@ -71,7 +70,7 @@ // translated. Then, for each format, translate the data and post // it to the Clipboard. Map formatMap = WDataTransferer.getInstance(). - getFormatsForTransferable(contents, flavorMap); + getFormatsForTransferable(contents, getDefaultFlavorTable()); openClipboard(this);