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 sun.lwawt.macosx; 27 28 import java.awt.datatransfer.*; 29 import java.io.IOException; 30 import java.util.*; 31 32 import sun.awt.datatransfer.*; 33 34 35 /** 36 * A class which interfaces with Cocoa's pasteboard in order to support 37 * data transfer via Clipboard operations. Most of the work is provided by 38 * sun.awt.datatransfer.DataTransferer. 39 */ 40 41 public class CClipboard extends SunClipboard { 42 43 public CClipboard(String name) { 44 super(name); 45 } 46 47 public long getID() { 48 return 0; 49 } 50 51 protected void clearNativeContext() { 52 // Leaving Empty, as WClipboard.clearNativeContext is empty as well. 53 } 54 55 protected void setContentsNative(Transferable contents) { 56 57 // Don't use delayed Clipboard rendering for the Transferable's data. 58 // If we did that, we would call Transferable.getTransferData on 59 // the Toolkit thread, which is a security hole. 60 // 61 // Get all of the target formats into which the Transferable can be 62 // translated. Then, for each format, translate the data and post 63 // it to the Clipboard. 64 DataTransferer dataTransferer = DataTransferer.getInstance(); 65 long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap); 66 declareTypes(formatArray, this); 67 68 Map<Long, DataFlavor> formatMap = DataTransferer.getInstance().getFormatsForTransferable(contents, flavorMap); 69 70 for (Iterator<Long> iter = formatMap.keySet().iterator(); iter.hasNext(); ) { 71 Long lFormat = iter.next(); 72 long format = lFormat.longValue(); 73 DataFlavor flavor = formatMap.get(lFormat); 74 75 try { 76 byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format); 77 setData(bytes, format); 78 } catch (IOException e) { 79 // Fix 4696186: don't print exception if data with 80 // javaJVMLocalObjectMimeType failed to serialize. 81 // May remove this if-check when 5078787 is fixed. 82 if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) && 83 e instanceof java.io.NotSerializableException)) { 84 e.printStackTrace(); 85 } 86 } 87 } 88 } 89 90 private void lostSelectionOwnershipImpl() { 91 lostOwnershipImpl(); 92 } 93 94 protected native long[] getClipboardFormats(); 95 protected native byte[] getClipboardData(long format) throws IOException; 96 97 // 1.5 peer method 98 protected void unregisterClipboardViewerChecked() { 99 // no-op because we lack OS support. This requires 4048791, which requires 4048792 100 } 101 102 // 1.5 peer method 103 protected void registerClipboardViewerChecked() { 104 // no-op because we lack OS support. This requires 4048791, which requires 4048792 105 } 106 107 // 1.5 peer method 108 // no-op. This appears to be win32 specific. Filed 4048790 for investigation 109 //protected Transferable createLocaleTransferable(long[] formats) throws IOException; 110 111 public native void declareTypes(long[] formats, SunClipboard newOwner); 112 public native void setData(byte[] data, long format); 113 | 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 sun.lwawt.macosx; 27 28 import java.awt.*; 29 import java.awt.datatransfer.*; 30 import java.io.IOException; 31 import java.io.NotSerializableException; 32 import java.util.*; 33 34 import sun.awt.datatransfer.*; 35 36 37 /** 38 * A class which interfaces with Cocoa's pasteboard in order to support 39 * data transfer via Clipboard operations. Most of the work is provided by 40 * sun.awt.datatransfer.DataTransferer. 41 */ 42 43 public class CClipboard extends SunClipboard { 44 45 public CClipboard(String name) { 46 super(name); 47 } 48 49 public long getID() { 50 return 0; 51 } 52 53 protected void clearNativeContext() { 54 // Leaving Empty, as WClipboard.clearNativeContext is empty as well. 55 } 56 57 protected void setContentsNative(Transferable contents) { 58 59 // Don't use delayed Clipboard rendering for the Transferable's data. 60 // If we did that, we would call Transferable.getTransferData on 61 // the Toolkit thread, which is a security hole. 62 // 63 // Get all of the target formats into which the Transferable can be 64 // translated. Then, for each format, translate the data and post 65 // it to the Clipboard. 66 DataTransferer dataTransferer = DataTransferer.getInstance(); 67 long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap); 68 declareTypes(formatArray, this); 69 70 Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap); 71 for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) { 72 long format = entry.getKey(); 73 DataFlavor flavor = entry.getValue(); 74 75 try { 76 byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format); 77 setData(bytes, format); 78 } catch (IOException e) { 79 // Fix 4696186: don't print exception if data with 80 // javaJVMLocalObjectMimeType failed to serialize. 81 // May remove this if-check when 5078787 is fixed. 82 if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) && 83 e instanceof NotSerializableException)) { 84 e.printStackTrace(); 85 } 86 } 87 } 88 89 notifyChanged(); 90 } 91 92 private void notifyLostOwnership() { 93 lostOwnershipImpl(); 94 } 95 96 private static void notifyChanged() { 97 CClipboard clipboard = (CClipboard) Toolkit.getDefaultToolkit().getSystemClipboard(); 98 if (!clipboard.areFlavorListenersRegistered()) { 99 return; 100 } 101 clipboard.checkChange(clipboard.getClipboardFormats()); 102 } 103 104 protected native long[] getClipboardFormats(); 105 protected native byte[] getClipboardData(long format) throws IOException; 106 107 // 1.5 peer method 108 protected void unregisterClipboardViewerChecked() { 109 // no-op because we lack OS support. This requires 4048791, which requires 4048792 110 } 111 112 // 1.5 peer method 113 protected void registerClipboardViewerChecked() { 114 // no-op because we lack OS support. This requires 4048791, which requires 4048792 115 } 116 117 // 1.5 peer method 118 // no-op. This appears to be win32 specific. Filed 4048790 for investigation 119 //protected Transferable createLocaleTransferable(long[] formats) throws IOException; 120 121 public native void declareTypes(long[] formats, SunClipboard newOwner); 122 public native void setData(byte[] data, long format); 123 |