1/*
2 * Copyright (C) 2010, 2012 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#if ENABLE(NETSCAPE_PLUGIN_API)
30
31#include "PluginModuleInfo.h"
32
33#include <WebCore/PluginData.h>
34
35namespace WebCore {
36    class URL;
37}
38
39namespace WebKit {
40
41class PluginInfoStore;
42
43class PluginInfoStoreClient {
44    WTF_MAKE_NONCOPYABLE(PluginInfoStoreClient);
45public:
46    virtual ~PluginInfoStoreClient() { }
47    virtual void pluginInfoStoreDidLoadPlugins(PluginInfoStore*) = 0;
48protected:
49    PluginInfoStoreClient() { }
50};
51
52class PluginInfoStore {
53    WTF_MAKE_NONCOPYABLE(PluginInfoStore);
54
55public:
56    PluginInfoStore();
57
58    void setAdditionalPluginsDirectories(const Vector<String>&);
59
60    void refresh();
61    Vector<PluginModuleInfo> plugins();
62
63    // Returns the info for a plug-in that can handle the given MIME type.
64    // If the MIME type is null, the file extension of the given url will be used to infer the
65    // plug-in type. In that case, mimeType will be filled in with the right MIME type.
66    PluginModuleInfo findPlugin(String& mimeType, const WebCore::URL&, WebCore::PluginData::AllowedPluginTypes = WebCore::PluginData::AllPlugins);
67
68    // Returns the info for the plug-in with the given bundle identifier.
69    PluginModuleInfo findPluginWithBundleIdentifier(const String& bundleIdentifier);
70
71    // Returns the info for the plug-in with the given path.
72    PluginModuleInfo infoForPluginWithPath(const String& pluginPath) const;
73
74    static PluginModuleLoadPolicy defaultLoadPolicyForPlugin(const PluginModuleInfo&);
75
76    void setClient(PluginInfoStoreClient* client) { m_client = client; }
77    PluginInfoStoreClient* client() const { return m_client; }
78
79private:
80    PluginModuleInfo findPluginForMIMEType(const String& mimeType, WebCore::PluginData::AllowedPluginTypes) const;
81    PluginModuleInfo findPluginForExtension(const String& extension, String& mimeType, WebCore::PluginData::AllowedPluginTypes) const;
82
83    void loadPluginsIfNecessary();
84    static void loadPlugin(Vector<PluginModuleInfo>& plugins, const String& pluginPath);
85
86    // Platform-specific member functions:
87
88    // Returns paths to directories that should be searched for plug-ins (via pluginPathsInDirectory).
89    static Vector<String> pluginsDirectories();
90
91    // Returns paths to all plug-ins in the specified directory.
92    static Vector<String> pluginPathsInDirectory(const String& directory);
93
94    // Returns paths to individual plug-ins that won't be found via pluginsDirectories/pluginPathsInDirectory.
95    static Vector<String> individualPluginPaths();
96
97    // Load plug-in info for the plug-in with the specified path.
98    static bool getPluginInfo(const String& pluginPath, PluginModuleInfo&);
99
100    // Return whether this plug-in should be used (added to the list of plug-ins) or not.
101    static bool shouldUsePlugin(Vector<PluginModuleInfo>& alreadyLoadedPlugins, const PluginModuleInfo&);
102
103    Vector<String> m_additionalPluginsDirectories;
104    Vector<PluginModuleInfo> m_plugins;
105    bool m_pluginListIsUpToDate;
106    PluginInfoStoreClient* m_client;
107};
108
109} // namespace WebKit
110
111#endif // ENABLE(NETSCAPE_PLUGIN_API)
112
113#endif // PluginInfoStore_h
114