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.plugin;
27
28 import java.net.URL;
29 import java.util.Collection;
30 import java.util.HashSet;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.ServiceLoader;
34 import java.util.TreeMap;
35 import java.util.Vector;
36 import java.util.logging.Level;
37 import java.util.logging.Logger;
38
39 public final class PluginManager {
40 private final static Logger log =
41 Logger.getLogger("com.sun.browser.plugin.PluginManager");
42
43 private static final ServiceLoader<PluginHandler> pHandlers =
44 ServiceLoader.load(PluginHandler.class);
45
46 private static final TreeMap<String,PluginHandler> hndMap =
47 new TreeMap<String,PluginHandler>();
48
49 private static PluginHandler[] hndArray;
50
51 private static final HashSet<String> disabledPluginHandlers =
52 new HashSet<String>();
53
54
55 private static void updatePluginHandlers() {
56 log.fine("Update plugin handlers");
57
58 hndMap.clear();
59
60 Iterator<PluginHandler> iter = pHandlers.iterator();
61 while(iter.hasNext()) {
84
85 updatePluginHandlers();
86 }
87
88 public static Plugin createPlugin(URL url, String type, String[] pNames,
89 String[] pValues)
90 {
91 try {
92 PluginHandler hnd = hndMap.get(type);
93 if (hnd == null) {
94 return new DefaultPlugin(url, type, pNames, pValues);
95 } else {
96 Plugin p = hnd.createPlugin(url, type, pNames, pValues);
97 if (p == null) {
98 return new DefaultPlugin(url, type, pNames, pValues);
99 } else {
100 return p;
101 }
102 }
103 } catch (Throwable ex) {
104 log.log(Level.FINE, "Cannot create plugin" , ex);
105 return new DefaultPlugin(url, type, pNames, pValues);
106 }
107 }
108
109
110 private static List<PluginHandler> getAvailablePlugins() {
111 Vector<PluginHandler> res = new Vector<PluginHandler>();
112 Iterator<PluginHandler> iter = pHandlers.iterator();
113 while(iter.hasNext()) {
114 PluginHandler hnd = iter.next();
115 if (hnd.isSupportedPlatform()) {
116 res.add(hnd);
117 }
118 }
119 return res;
120 }
121
122 private static PluginHandler getEnabledPlugin(int i) {
123 if (i < 0 || i >= hndArray.length) return null;
124 return hndArray[i];
|
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.plugin;
27
28 import com.sun.javafx.logging.PlatformLogger;
29 import java.net.URL;
30 import java.util.Collection;
31 import java.util.HashSet;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.ServiceLoader;
35 import java.util.TreeMap;
36 import java.util.Vector;
37
38 public final class PluginManager {
39 private final static PlatformLogger log =
40 PlatformLogger.getLogger("com.sun.browser.plugin.PluginManager");
41
42 private static final ServiceLoader<PluginHandler> pHandlers =
43 ServiceLoader.load(PluginHandler.class);
44
45 private static final TreeMap<String,PluginHandler> hndMap =
46 new TreeMap<String,PluginHandler>();
47
48 private static PluginHandler[] hndArray;
49
50 private static final HashSet<String> disabledPluginHandlers =
51 new HashSet<String>();
52
53
54 private static void updatePluginHandlers() {
55 log.fine("Update plugin handlers");
56
57 hndMap.clear();
58
59 Iterator<PluginHandler> iter = pHandlers.iterator();
60 while(iter.hasNext()) {
83
84 updatePluginHandlers();
85 }
86
87 public static Plugin createPlugin(URL url, String type, String[] pNames,
88 String[] pValues)
89 {
90 try {
91 PluginHandler hnd = hndMap.get(type);
92 if (hnd == null) {
93 return new DefaultPlugin(url, type, pNames, pValues);
94 } else {
95 Plugin p = hnd.createPlugin(url, type, pNames, pValues);
96 if (p == null) {
97 return new DefaultPlugin(url, type, pNames, pValues);
98 } else {
99 return p;
100 }
101 }
102 } catch (Throwable ex) {
103 log.fine("Cannot create plugin" , ex);
104 return new DefaultPlugin(url, type, pNames, pValues);
105 }
106 }
107
108
109 private static List<PluginHandler> getAvailablePlugins() {
110 Vector<PluginHandler> res = new Vector<PluginHandler>();
111 Iterator<PluginHandler> iter = pHandlers.iterator();
112 while(iter.hasNext()) {
113 PluginHandler hnd = iter.next();
114 if (hnd.isSupportedPlatform()) {
115 res.add(hnd);
116 }
117 }
118 return res;
119 }
120
121 private static PluginHandler getEnabledPlugin(int i) {
122 if (i < 0 || i >= hndArray.length) return null;
123 return hndArray[i];
|