changeset 5405:915737d79cc6 8.0-b112

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/8.0/MASTER/jfx/rt
author kcr
date Tue, 15 Oct 2013 16:22:03 -0700
parents 30fceec780f7 a19b6f85332b
children 18e21b07b801 aee256fde552 eb08481a0c71
files modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java
diffstat 5 files changed, 188 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/LocalClipboard.java	Tue Oct 15 16:22:03 2013 -0700
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.tk;
+
+import java.security.AccessControlContext;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javafx.scene.image.Image;
+import javafx.scene.input.DataFormat;
+import javafx.scene.input.TransferMode;
+import javafx.util.Pair;
+
+final class LocalClipboard implements TKClipboard {
+    private final Map<DataFormat, Object> values;
+
+    public LocalClipboard() {
+        values = new HashMap<DataFormat, Object>();
+    }
+
+    @Override
+    public void setSecurityContext(final AccessControlContext ctx) {
+        // ctx not needed
+    }
+
+    @Override
+    public Set<DataFormat> getContentTypes() {
+        return Collections.unmodifiableSet(
+                   new HashSet<DataFormat>(values.keySet()));
+    }
+
+    @Override
+    public boolean putContent(final Pair<DataFormat, Object>... content) {
+        for (final Pair<DataFormat, Object> pair: content) {
+            if (pair.getKey() == null) {
+                throw new NullPointerException(
+                        "Clipboard.putContent: null data format");
+            }
+            if (pair.getValue() == null) {
+                throw new NullPointerException(
+                        "Clipboard.putContent: null data");
+            }
+        }
+
+        // all OK, replace clipboard content
+        values.clear();
+        for (final Pair<DataFormat, Object> pair: content) {
+            values.put(pair.getKey(), pair.getValue());
+        }
+
+        return true;
+    }
+
+    @Override
+    public Object getContent(final DataFormat dataFormat) {
+        return values.get(dataFormat);
+    }
+
+    @Override
+    public boolean hasContent(final DataFormat dataFormat) {
+        return values.containsKey(dataFormat);
+    }
+
+    @Override
+    public Set<TransferMode> getTransferModes() {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public void setDragView(final Image image) {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public void setDragViewOffsetX(final double offsetX) {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public void setDragViewOffsetY(final double offsetY) {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public Image getDragView() {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public double getDragViewOffsetX() {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public double getDragViewOffsetY() {
+        throw new IllegalStateException();
+    }
+}
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java	Tue Oct 15 14:55:53 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java	Tue Oct 15 16:22:03 2013 -0700
@@ -602,6 +602,10 @@
 
     public abstract TKClipboard getSystemClipboard();
 
+    public TKClipboard createLocalClipboard() {
+        return new LocalClipboard();
+    }
+
     public abstract TKSystemMenu getSystemMenu();
 
     public abstract TKClipboard getNamedClipboard(String name);
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/GlassScene.java	Tue Oct 15 14:55:53 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/GlassScene.java	Tue Oct 15 16:22:03 2013 -0700
@@ -48,9 +48,14 @@
 import com.sun.prism.impl.PrismSettings;
 import com.sun.prism.paint.Color;
 import com.sun.prism.paint.Paint;
+import sun.misc.JavaSecurityAccess;
+import sun.misc.SharedSecrets;
 
 abstract class GlassScene implements TKScene {
 
+    private static final JavaSecurityAccess javaSecurityAccess =
+            SharedSecrets.getJavaSecurityAccess();
+
     private GlassStage stage;
 
     protected TKSceneListener sceneListener;
@@ -100,7 +105,16 @@
         if (accessCtrlCtx != null) {
             throw new RuntimeException("Scene security context has been already set!");
         }
-        accessCtrlCtx = ctx;
+        AccessControlContext acc = AccessController.getContext();
+        // JDK doesn't provide public APIs to get ACC intersection,
+        // so using this ugly workaround
+        accessCtrlCtx = javaSecurityAccess.doIntersectionPrivilege(
+                new PrivilegedAction<AccessControlContext>() {
+                    @Override
+                    public AccessControlContext run() {
+                        return AccessController.getContext();
+                    }
+                }, acc, ctx);
     }
 
     public void waitForRenderingToComplete() {
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/GlassStage.java	Tue Oct 15 14:55:53 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/GlassStage.java	Tue Oct 15 16:22:03 2013 -0700
@@ -40,8 +40,14 @@
 import com.sun.javafx.tk.TKStageListener;
 import com.sun.javafx.tk.Toolkit;
 
+import sun.misc.JavaSecurityAccess;
+import sun.misc.SharedSecrets;
+
 abstract class GlassStage implements TKStage {
 
+    private static final JavaSecurityAccess javaSecurityAccess =
+            SharedSecrets.getJavaSecurityAccess();
+
     // A list of all GlassStage objects regardless of visibility.
     private static final List<GlassStage> windows = new ArrayList<>();
 
@@ -107,7 +113,16 @@
         if (accessCtrlCtx != null) {
             throw new RuntimeException("Stage security context has been already set!");
         }
-        accessCtrlCtx = ctx;
+        AccessControlContext acc = AccessController.getContext();
+        // JDK doesn't provide public APIs to get ACC intersection,
+        // so using this ugly workaround
+        accessCtrlCtx = javaSecurityAccess.doIntersectionPrivilege(
+            new PrivilegedAction<AccessControlContext>() {
+                @Override
+                public AccessControlContext run() {
+                    return AccessController.getContext();
+                }
+            }, acc, ctx);
     }
 
     @Override public void requestFocus() {
--- a/modules/graphics/src/main/java/javafx/scene/input/Clipboard.java	Tue Oct 15 14:55:53 2013 -0700
+++ b/modules/graphics/src/main/java/javafx/scene/input/Clipboard.java	Tue Oct 15 16:22:03 2013 -0700
@@ -37,6 +37,7 @@
 
 import com.sun.javafx.tk.TKClipboard;
 import com.sun.javafx.tk.Toolkit;
+import java.security.AllPermission;
 
 /**
  * Represents an operating system clipboard, on which data may be placed during, for
@@ -158,20 +159,23 @@
      * the system will invoke the provided callback to stream the image data over to the client.
      */
 
-    private static Clipboard systemClipboard = null;
+    private final AccessControlContext acc = AccessController.getContext();
 
-    private final AccessControlContext acc = AccessController.getContext();
-    
     /**
      * Gets the current system clipboard, through which data can be stored and
      * retrieved. There is ever only one system clipboard for a JavaFX application.
      * @return The single system clipboard, used for cut / copy / paste operations
      */
     public static Clipboard getSystemClipboard() {
-        if (systemClipboard == null) {
-            systemClipboard = new Clipboard(Toolkit.getToolkit().getSystemClipboard());
+        try {
+            final SecurityManager securityManager = System.getSecurityManager();
+            if (securityManager != null) {
+                securityManager.checkPermission(new AllPermission());
+            }
+            return getSystemClipboardImpl();
+        } catch (final SecurityException e) {
+            return getLocalClipboardImpl();
         }
-        return systemClipboard;
     }
 
     TKClipboard peer;
@@ -390,4 +394,24 @@
     public boolean impl_contentPut() {
         return contentPut;
     }
+
+    private static Clipboard systemClipboard;
+
+    private static synchronized Clipboard getSystemClipboardImpl() {
+        if (systemClipboard == null) {
+            systemClipboard =
+                    new Clipboard(Toolkit.getToolkit().getSystemClipboard());
+        }
+        return systemClipboard;
+    }
+
+    private static Clipboard localClipboard;
+
+    private static synchronized Clipboard getLocalClipboardImpl() {
+        if (localClipboard == null) {
+            localClipboard =
+                    new Clipboard(Toolkit.getToolkit().createLocalClipboard());
+        }
+        return localClipboard;
+    }
 }