• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <WebCore/PluginData.h>
30 
31 namespace WebCore {
32     class KURL;
33 }
34 
35 namespace WebKit {
36 
37 class PluginInfoStore {
38     WTF_MAKE_NONCOPYABLE(PluginInfoStore);
39 
40 public:
41     PluginInfoStore();
42 
43     void setAdditionalPluginsDirectories(const Vector<String>&);
44 
45     void refresh();
46     void getPlugins(Vector<WebCore::PluginInfo>&);
47     void getPluginPaths(Vector<String>&);
48 
49     // Represents a single plug-in.
50     struct Plugin {
51         String path;
52         WebCore::PluginInfo info;
53 #if PLATFORM(MAC)
54         cpu_type_t pluginArchitecture;
55         String bundleIdentifier;
56         unsigned versionNumber;
57 #elif PLATFORM(WIN)
58         uint64_t fileVersion;
59 #endif
60     };
61 
62     const Vector<Plugin>& plugins();
63 
64     // Returns the info for a plug-in that can handle the given MIME type.
65     // If the MIME type is null, the file extension of the given url will be used to infer the
66     // plug-in type. In that case, mimeType will be filled in with the right MIME type.
67     Plugin findPlugin(String& mimeType, const WebCore::KURL& url);
68 
69     // Returns the info for the plug-in with the given path.
70     Plugin infoForPluginWithPath(const String& pluginPath);
71 
72 private:
73 
74     Plugin findPluginForMIMEType(const String& mimeType);
75     Plugin findPluginForExtension(const String& extension, String& mimeType);
76 
77     void loadPluginsIfNecessary();
78     void loadPlugin(const String& pluginPath);
79 
80     // Platform-specific member functions
81 
82     // Returns paths to directories that should be searched for plug-ins (via pluginPathsInDirectory).
83     static Vector<String> pluginsDirectories();
84     // Returns paths to all plug-ins in the specified directory.
85     static Vector<String> pluginPathsInDirectory(const String& directory);
86     // Returns paths to individual plug-ins that won't be found via pluginsDirectories/pluginPathsInDirectory.
87     static Vector<String> individualPluginPaths();
88     static bool getPluginInfo(const String& pluginPath, Plugin& plugin);
89     bool shouldUsePlugin(const Plugin& plugin);
90     static String getMIMETypeForExtension(const String& extension);
91 
92     Vector<String> m_additionalPluginsDirectories;
93     Vector<Plugin> m_plugins;
94     bool m_pluginListIsUpToDate;
95 };
96 
97 } // namespace WebKit
98 
99 #endif // PluginInfoStore_h
100