4848a247ba036624bdac677cff9dabfe7fabc302
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / Plugins / PluginInfoStore.h
1 /*
2  * Copyright (C) 2010 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 #ifndef PluginInfoStore_h
27 #define PluginInfoStore_h
28
29 #include "PluginModuleInfo.h"
30 #include <wtf/ThreadingPrimitives.h>
31
32 namespace WebCore {
33     class KURL;
34 }
35
36 namespace WebKit {
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 WebCore::KURL&);
53     
54     // Returns the info for the plug-in with the given path.
55     PluginModuleInfo infoForPluginWithPath(const String& pluginPath) const;
56
57     // Return whether this plug-in should be blocked from being instantiated.
58     // Note that the plug-in will still be seen by e.g. navigator.plugins
59     bool shouldBlockPlugin(const PluginModuleInfo&) const;
60
61 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
62     void setExecutablePath(const String& path) { m_executablePath = path; };
63     const String& executablePath() const { return m_executablePath; };
64 #endif
65
66 private:
67     PluginModuleInfo findPluginForMIMEType(const String& mimeType) const;
68     PluginModuleInfo findPluginForExtension(const String& extension, String& mimeType) const;
69
70     void loadPluginsIfNecessary();
71     static void loadPlugin(Vector<PluginModuleInfo>& plugins, const String& pluginPath);
72     
73     // Platform-specific member functions:
74
75     // Returns paths to directories that should be searched for plug-ins (via pluginPathsInDirectory).
76     static Vector<String> pluginsDirectories();
77
78     // Returns paths to all plug-ins in the specified directory.
79     static Vector<String> pluginPathsInDirectory(const String& directory);
80
81     // Returns paths to individual plug-ins that won't be found via pluginsDirectories/pluginPathsInDirectory.
82     static Vector<String> individualPluginPaths();
83
84     // Load plug-in info for the plug-in with the specified path.
85     static bool getPluginInfo(const String& pluginPath, PluginModuleInfo&);
86
87     // Return whether this plug-in should be used (added to the list of plug-ins) or not.
88     static bool shouldUsePlugin(Vector<PluginModuleInfo>& alreadyLoadedPlugins, const PluginModuleInfo&);
89
90     // Get the MIME type for the given extension.
91     static String getMIMETypeForExtension(const String& extension);
92
93     Vector<String> m_additionalPluginsDirectories;
94     Vector<PluginModuleInfo> m_plugins;
95     bool m_pluginListIsUpToDate;
96 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
97     String m_executablePath;
98 #endif
99     mutable Mutex m_pluginsLock;
100 };
101     
102 } // namespace WebKit
103
104 #endif // PluginInfoStore_h