45 import sun.awt.EventQueueItem; |
45 import sun.awt.EventQueueItem; |
46 import sun.awt.AWTAccessor; |
46 import sun.awt.AWTAccessor; |
47 |
47 |
48 import java.util.concurrent.locks.Condition; |
48 import java.util.concurrent.locks.Condition; |
49 import java.util.concurrent.locks.Lock; |
49 import java.util.concurrent.locks.Lock; |
|
50 |
|
51 import java.security.AccessControlContext; |
|
52 import java.security.ProtectionDomain; |
|
53 |
|
54 import sun.misc.SharedSecrets; |
|
55 import sun.misc.JavaSecurityAccess; |
50 |
56 |
51 /** |
57 /** |
52 * <code>EventQueue</code> is a platform-independent class |
58 * <code>EventQueue</code> is a platform-independent class |
53 * that queues events, both from the underlying peer classes |
59 * that queues events, both from the underlying peer classes |
54 * and from trusted application classes. |
60 * and from trusted application classes. |
648 * @param event an instance of <code>java.awt.AWTEvent</code>, |
657 * @param event an instance of <code>java.awt.AWTEvent</code>, |
649 * or a subclass of it |
658 * or a subclass of it |
650 * @throws NullPointerException if <code>event</code> is <code>null</code> |
659 * @throws NullPointerException if <code>event</code> is <code>null</code> |
651 * @since 1.2 |
660 * @since 1.2 |
652 */ |
661 */ |
653 protected void dispatchEvent(AWTEvent event) { |
662 protected void dispatchEvent(final AWTEvent event) { |
|
663 final Object src = event.getSource(); |
|
664 final PrivilegedAction<Void> action = new PrivilegedAction<Void>() { |
|
665 public Void run() { |
|
666 dispatchEventImpl(event, src); |
|
667 return null; |
|
668 } |
|
669 }; |
|
670 |
|
671 final AccessControlContext stack = AccessController.getContext(); |
|
672 final AccessControlContext srcAcc = getAccessControlContextFrom(src); |
|
673 final AccessControlContext eventAcc = event.getAccessControlContext(); |
|
674 if (srcAcc == null) { |
|
675 javaSecurityAccess.doIntersectionPrivilege(action, stack, eventAcc); |
|
676 } else { |
|
677 javaSecurityAccess.doIntersectionPrivilege( |
|
678 new PrivilegedAction<Void>() { |
|
679 public Void run() { |
|
680 javaSecurityAccess.doIntersectionPrivilege(action, eventAcc); |
|
681 return null; |
|
682 } |
|
683 }, stack, srcAcc); |
|
684 } |
|
685 } |
|
686 |
|
687 private static AccessControlContext getAccessControlContextFrom(Object src) { |
|
688 return src instanceof Component ? |
|
689 ((Component)src).getAccessControlContext() : |
|
690 src instanceof MenuComponent ? |
|
691 ((MenuComponent)src).getAccessControlContext() : |
|
692 src instanceof TrayIcon ? |
|
693 ((TrayIcon)src).getAccessControlContext() : |
|
694 null; |
|
695 } |
|
696 |
|
697 /** |
|
698 * Called from dispatchEvent() under a correct AccessControlContext |
|
699 */ |
|
700 private void dispatchEventImpl(final AWTEvent event, final Object src) { |
654 event.isPosted = true; |
701 event.isPosted = true; |
655 Object src = event.getSource(); |
|
656 if (event instanceof ActiveEvent) { |
702 if (event instanceof ActiveEvent) { |
657 // This could become the sole method of dispatching in time. |
703 // This could become the sole method of dispatching in time. |
658 setCurrentEventAndMostRecentTimeImpl(event); |
704 setCurrentEventAndMostRecentTimeImpl(event); |
659 |
|
660 ((ActiveEvent)event).dispatch(); |
705 ((ActiveEvent)event).dispatch(); |
661 } else if (src instanceof Component) { |
706 } else if (src instanceof Component) { |
662 ((Component)src).dispatchEvent(event); |
707 ((Component)src).dispatchEvent(event); |
663 event.dispatched(); |
708 event.dispatched(); |
664 } else if (src instanceof MenuComponent) { |
709 } else if (src instanceof MenuComponent) { |