1 | /* |
2 | * Copyright (C) 2010, 2012, 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(NETSCAPE_PLUGIN_API) |
29 | |
30 | #include "PluginModuleInfo.h" |
31 | |
32 | #include <WebCore/PluginData.h> |
33 | |
34 | namespace WebKit { |
35 | |
36 | class PluginInfoStore; |
37 | |
38 | class PluginInfoStore { |
39 | WTF_MAKE_NONCOPYABLE(PluginInfoStore); |
40 | |
41 | public: |
42 | PluginInfoStore(); |
43 | |
44 | void setAdditionalPluginsDirectories(const Vector<String>&); |
45 | |
46 | void refresh(); |
47 | Vector<PluginModuleInfo> plugins(); |
48 | |
49 | // Returns the info for a plug-in that can handle the given MIME type. |
50 | // If the MIME type is null, the file extension of the given url will be used to infer the |
51 | // plug-in type. In that case, mimeType will be filled in with the right MIME type. |
52 | PluginModuleInfo findPlugin(String& mimeType, const URL&, WebCore::PluginData::AllowedPluginTypes = WebCore::PluginData::AllPlugins); |
53 | |
54 | // Returns the info for the plug-in with the given bundle identifier. |
55 | PluginModuleInfo findPluginWithBundleIdentifier(const String& bundleIdentifier); |
56 | |
57 | // Returns the info for the plug-in with the given path. |
58 | PluginModuleInfo infoForPluginWithPath(const String& pluginPath) const; |
59 | |
60 | static PluginModuleLoadPolicy defaultLoadPolicyForPlugin(const PluginModuleInfo&); |
61 | |
62 | bool isSupportedPlugin(const String& mimeType, const URL& pluginURL, const String& frameURLString, const URL& pageURL); |
63 | Optional<Vector<WebCore::SupportedPluginIdentifier>> supportedPluginIdentifiers(); |
64 | void addSupportedPlugin(String&& matchingDomain, String&& identifier, HashSet<String>&& mimeTypes, HashSet<String> extensions); |
65 | void clearSupportedPlugins() { m_supportedPlugins = WTF::nullopt; } |
66 | |
67 | private: |
68 | PluginModuleInfo findPluginForMIMEType(const String& mimeType, WebCore::PluginData::AllowedPluginTypes) const; |
69 | PluginModuleInfo findPluginForExtension(const String& extension, String& mimeType, WebCore::PluginData::AllowedPluginTypes) const; |
70 | |
71 | void loadPluginsIfNecessary(); |
72 | static void loadPlugin(Vector<PluginModuleInfo>& plugins, const String& pluginPath); |
73 | |
74 | // Platform-specific member functions: |
75 | |
76 | // Returns paths to directories that should be searched for plug-ins (via pluginPathsInDirectory). |
77 | static Vector<String> pluginsDirectories(); |
78 | |
79 | // Returns paths to all plug-ins in the specified directory. |
80 | static Vector<String> pluginPathsInDirectory(const String& directory); |
81 | |
82 | // Returns paths to individual plug-ins that won't be found via pluginsDirectories/pluginPathsInDirectory. |
83 | static Vector<String> individualPluginPaths(); |
84 | |
85 | // Load plug-in info for the plug-in with the specified path. |
86 | static bool getPluginInfo(const String& pluginPath, PluginModuleInfo&); |
87 | |
88 | // Return whether this plug-in should be used (added to the list of plug-ins) or not. |
89 | static bool shouldUsePlugin(Vector<PluginModuleInfo>& alreadyLoadedPlugins, const PluginModuleInfo&); |
90 | |
91 | Vector<String> m_additionalPluginsDirectories; |
92 | Vector<PluginModuleInfo> m_plugins; |
93 | bool m_pluginListIsUpToDate; |
94 | |
95 | struct SupportedPlugin { |
96 | String matchingDomain; |
97 | String identifier; |
98 | HashSet<String> mimeTypes; |
99 | HashSet<String> extensions; |
100 | }; |
101 | static bool isSupportedPlugin(const SupportedPlugin&, const String& mimeType, const URL& pluginURL); |
102 | |
103 | Optional<Vector<SupportedPlugin>> m_supportedPlugins; |
104 | }; |
105 | |
106 | } // namespace WebKit |
107 | |
108 | #endif // ENABLE(NETSCAPE_PLUGIN_API) |
109 | |