< prev index next >

modules/javafx.web/src/main/java/com/sun/webkit/Utilities.java

Print this page
rev 10441 : imported patch fix-8177566-trampoline
   1 /*
   2  * Copyright (c) 2011, 2014, 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
  23  * questions.
  24  */
  25 
  26 package com.sun.webkit;
  27 
  28 import java.lang.reflect.InvocationTargetException;
  29 import java.lang.reflect.Method;
  30 import java.security.AccessControlContext;
  31 import java.security.AccessController;
  32 import java.security.PrivilegedActionException;
  33 import java.security.PrivilegedExceptionAction;
  34 import java.util.HashMap;
  35 import java.util.Map;
  36 import sun.reflect.misc.MethodUtil;
  37 
  38 public abstract class Utilities {
  39 
  40     private static Utilities instance;
  41 
  42     public static synchronized void setUtilities(Utilities util) {
  43         instance = util;
  44     }
  45 
  46     public static synchronized Utilities getUtilities() {
  47         return instance;
  48     }
  49 
  50     protected abstract Pasteboard createPasteboard();
  51     protected abstract PopupMenu createPopupMenu();
  52     protected abstract ContextMenu createContextMenu();
  53 
  54     private static String fwkGetMIMETypeForExtension(String ext) {
  55         return MimeTypeMapHolder.MIME_TYPE_MAP.get(ext);
  56     }


  74             mimeTypeMap.put("gif", "image/gif");
  75             mimeTypeMap.put("jpg", "image/jpeg");
  76             mimeTypeMap.put("jpeg", "image/jpeg");
  77             mimeTypeMap.put("png", "image/png");
  78             mimeTypeMap.put("tif", "image/tiff");
  79             mimeTypeMap.put("tiff", "image/tiff");
  80             mimeTypeMap.put("ico", "image/ico");
  81             mimeTypeMap.put("cur", "image/ico");
  82             mimeTypeMap.put("bmp", "image/bmp");
  83             mimeTypeMap.put("mp3", "audio/mpeg");
  84             return mimeTypeMap;
  85         }
  86     }
  87 
  88     private static Object fwkInvokeWithContext(final Method method,
  89                                                final Object instance,
  90                                                final Object[] args,
  91                                                AccessControlContext acc)
  92     throws Throwable {
  93         try {
  94             return AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> MethodUtil.invoke(method, instance, args), acc);

  95         } catch (PrivilegedActionException ex) {
  96             Throwable cause = ex.getCause();
  97             if (cause == null)
  98                 cause = ex;
  99             else if (cause instanceof InvocationTargetException
 100                 && cause.getCause() != null)
 101                 cause = cause.getCause();
 102             throw cause;
 103         }
 104     }
 105 }
 106 
   1 /*
   2  * Copyright (c) 2011, 2017, 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
  23  * questions.
  24  */
  25 
  26 package com.sun.webkit;
  27 
  28 import java.lang.reflect.InvocationTargetException;
  29 import java.lang.reflect.Method;
  30 import java.security.AccessControlContext;
  31 import java.security.AccessController;
  32 import java.security.PrivilegedActionException;
  33 import java.security.PrivilegedExceptionAction;
  34 import java.util.HashMap;
  35 import java.util.Map;

  36 
  37 public abstract class Utilities {
  38 
  39     private static Utilities instance;
  40 
  41     public static synchronized void setUtilities(Utilities util) {
  42         instance = util;
  43     }
  44 
  45     public static synchronized Utilities getUtilities() {
  46         return instance;
  47     }
  48 
  49     protected abstract Pasteboard createPasteboard();
  50     protected abstract PopupMenu createPopupMenu();
  51     protected abstract ContextMenu createContextMenu();
  52 
  53     private static String fwkGetMIMETypeForExtension(String ext) {
  54         return MimeTypeMapHolder.MIME_TYPE_MAP.get(ext);
  55     }


  73             mimeTypeMap.put("gif", "image/gif");
  74             mimeTypeMap.put("jpg", "image/jpeg");
  75             mimeTypeMap.put("jpeg", "image/jpeg");
  76             mimeTypeMap.put("png", "image/png");
  77             mimeTypeMap.put("tif", "image/tiff");
  78             mimeTypeMap.put("tiff", "image/tiff");
  79             mimeTypeMap.put("ico", "image/ico");
  80             mimeTypeMap.put("cur", "image/ico");
  81             mimeTypeMap.put("bmp", "image/bmp");
  82             mimeTypeMap.put("mp3", "audio/mpeg");
  83             return mimeTypeMap;
  84         }
  85     }
  86 
  87     private static Object fwkInvokeWithContext(final Method method,
  88                                                final Object instance,
  89                                                final Object[] args,
  90                                                AccessControlContext acc)
  91     throws Throwable {
  92         try {
  93             return AccessController.doPrivileged((PrivilegedExceptionAction<Object>)
  94                     () -> MethodHelper.invoke(method, instance, args), acc);
  95         } catch (PrivilegedActionException ex) {
  96             Throwable cause = ex.getCause();
  97             if (cause == null)
  98                 cause = ex;
  99             else if (cause instanceof InvocationTargetException
 100                 && cause.getCause() != null)
 101                 cause = cause.getCause();
 102             throw cause;
 103         }
 104     }
 105 }

< prev index next >