< prev index next >

modules/graphics/src/main/java/com/sun/glass/ui/Robot.java

Print this page
rev 9452 : 8144680: Stage.alwaysOnTop() doesn't work if a security manager is set
Reviewed-by:
   1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  29 import java.security.AccessController;
  30 import java.security.AllPermission;
  31 import java.security.Permission;
  32 
  33 public abstract class Robot {
  34 
  35     private final static Permission allPermission = new AllPermission();
  36 
  37     final static public int MOUSE_LEFT_BTN   = 1;
  38     final static public int MOUSE_RIGHT_BTN  = 2;
  39     final static public int MOUSE_MIDDLE_BTN = 4;
  40 
  41     protected abstract void _create();
  42     protected Robot() {
  43         // Fix for RT-22633
  44         // Ideally, we should restrict user access to Glass packages at all,
  45         // but that's not the case right now. To prevent applications from
  46         // using Robot, we check for AllPermission here as we don't have
  47         // (and will unlikely have in the future) specific permission for
  48         // this functionality
  49         if (System.getSecurityManager() != null) {
  50             AccessController.checkPermission(allPermission);

  51         }
  52         Application.checkEventThread();
  53         _create();
  54     }
  55 
  56     protected abstract void _destroy();
  57     public void destroy() {
  58         Application.checkEventThread();
  59         _destroy();
  60     }
  61 
  62     protected abstract void _keyPress(int code);
  63     /**
  64      * Generate a key pressed event.
  65      * @param code key code for this event
  66      */
  67     public void keyPress(int code) {
  68         Application.checkEventThread();
  69         _keyPress(code);
  70     }


   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  29 import java.security.AccessController;
  30 import java.security.AllPermission;
  31 import java.security.Permission;
  32 
  33 public abstract class Robot {
  34 
  35     private final static Permission allPermission = new AllPermission();
  36 
  37     final static public int MOUSE_LEFT_BTN   = 1;
  38     final static public int MOUSE_RIGHT_BTN  = 2;
  39     final static public int MOUSE_MIDDLE_BTN = 4;
  40 
  41     protected abstract void _create();
  42     protected Robot() {
  43         // Fix for RT-22633
  44         // Ideally, we should restrict user access to Glass packages at all,
  45         // but that's not the case right now. To prevent applications from
  46         // using Robot, we check for AllPermission here as we don't have
  47         // (and will unlikely have in the future) specific permission for
  48         // this functionality
  49         final SecurityManager sm = System.getSecurityManager();
  50         if (sm != null) {
  51             sm.checkPermission(allPermission);
  52         }
  53         Application.checkEventThread();
  54         _create();
  55     }
  56 
  57     protected abstract void _destroy();
  58     public void destroy() {
  59         Application.checkEventThread();
  60         _destroy();
  61     }
  62 
  63     protected abstract void _keyPress(int code);
  64     /**
  65      * Generate a key pressed event.
  66      * @param code key code for this event
  67      */
  68     public void keyPress(int code) {
  69         Application.checkEventThread();
  70         _keyPress(code);
  71     }


< prev index next >