1 // Copyright 2016 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EWK_EFL_INTEGRATION_COMMON_TRUSTED_PEPPER_PLUGIN_INFO_CACHE_H_
6 #define EWK_EFL_INTEGRATION_COMMON_TRUSTED_PEPPER_PLUGIN_INFO_CACHE_H_
10 #include <unordered_map>
14 #include "base/macros.h"
15 #include "base/files/file_path.h"
16 #include "content/public/common/pepper_plugin_info.h"
19 template <typename T> struct DefaultSingletonTraits;
24 // Class holding (caching) discovered plugins in given directories.
25 // Plugin needs to have manifest file pmf which descibes it.
27 // See |ParsePepperPluginManifest| for Plugin Manifest File (pmf) specification.
28 class TrustedPepperPluginInfoCache {
30 // Gets singleton of representing cache built for predefined directories.
31 static TrustedPepperPluginInfoCache* GetInstance();
33 // Special constructor only used during unit testing:
34 explicit TrustedPepperPluginInfoCache(
35 const std::vector<base::FilePath>& paths);
37 ~TrustedPepperPluginInfoCache();
39 // Adds all the plugins present in the cache to the |plugins| vector.
41 // If the plugins vector is empty then adds all plugins present currently
42 // in the cache to the vector.
44 // If the plugins vector is not empty then adds only those plugins that
45 // are present in the cache, but are not present in the vector.
47 // |plugins| is *non-null* pointer to vector which will be filled
48 void GetPlugins(std::vector<content::PepperPluginInfo>* plugins) const;
50 // Searches cached pepper plugins whether there is plugin which supports
53 // If plugin was found function returns true and sets |found_plugin|
54 // information for plugin found. Otherwise function returns false and
55 // doesn't touch |found_plugin| agrument
57 // |found_plugin| must be *non-null* pointer
58 bool FindPlugin(const std::string& mime_type,
59 content::PepperPluginInfo* found_plugin) const;
62 friend struct base::DefaultSingletonTraits<TrustedPepperPluginInfoCache>;
64 // Builds plugin cache based on predefined directories.
65 TrustedPepperPluginInfoCache();
67 // Discover plugins in given directory by scanning it recursively
68 // and adds their descriptions to the cache.
69 void AddPluginsFromDirectory(const base::FilePath& dir);
72 std::pair<base::FilePath, std::unique_ptr<content::PepperPluginInfo>>;
74 // cached plugin infos
75 std::vector<PluginEntry> plugins_;
77 // PepperPluginInfo is non owning pointer to plugins element
78 std::unordered_map<std::string, content::PepperPluginInfo*> mime_map_;
80 DISALLOW_COPY_AND_ASSIGN(TrustedPepperPluginInfoCache);
83 // Exposed in header for UnitTesting:
85 // Parses Plugin Manifest File (PMF) provided as string |contents|
86 // and fills properly |out_info|.
88 // |pmf| is path from which PMF was loaded from and its used to fill
89 // |PepperPluginInfo::path| field if such information is not present in the PMF.
91 // This function does not performs any operation on filesystem.
95 // libsample_plugin.pmf:
98 // "name" : "Sample Trusted Plugin",
100 // "description" : "Example Pepper Trusted Plugin",
103 // "type" : "application/x-ppapi-example",
104 // "description" : "Example Ppapi",
105 // "extensions" : [ ".ext1", ".ext2" ]
108 // "type" : "application/x-ppapi-example2"
115 // "type" : "pepper",
116 // "name" : "Test Trusted Plugin",
117 // "version" : "1.2",
118 // "description" : "Test Trusted Pepper Plugin",
119 // "mimes": [ { type: "application/x-ppapi-test" } ],
120 // "program": { "url": "libtest_plugin.so" }
123 // PMF is a JSON wich have following fields:
124 // - type (mandatory)
125 // type of the plugin, must be set to "pepper'
127 // plugin name, value for |PepperPluginInfo::name|
128 // - description (optional)
129 // plugin description, value for |PepperPluginInfo::description|
130 // - version (optional)
131 // plugin version, value for |PepperPluginInfo::version|
132 // - mimes (mandatory)
133 // provides list of mime types, value for |PepperPluginInfo::mime_types|
134 // - mimes/type (mandatory)
135 // defines mime_type itself, value for |WebPluginMimeType::mime_type|
136 // - mimes/description (optional)
137 // defines mime_type description, value for |WebPluginMimeType::description|
138 // - mimes/extensions (optional)
139 // defines list of the file extensions for this mime type,
140 // value for |WebPluginMimeType::file_extensions|
141 // - program (optional)
142 // provides path for pepper plugin shared library, value for
143 // |PepperPluginInfo::path|. If value is not present in the manifest,
144 // then path is deduced from |pmf|, by replacing .pmf extension form the
145 // manifest to platform dependent library extension (.so on POSIX systems).
146 // - program/url (mandatory if program argument is present)
147 // provides relative or absolute path to pepper plugin shared library.
149 // Following fields are not present in PMF and are set to given values:
150 // - PepperPluginInfo::is_internal is set to |false|
151 // - PepperPluginInfo::is_out_of_process is set to |true|
153 // Function returns true if manifest is parsed and follows specification
155 bool ParsePepperPluginManifest(
156 const base::FilePath& pmf,
157 const std::string& contents,
158 content::PepperPluginInfo* out_info);
160 // Exposed in header for UnitTesting:
162 // Reads plugin manifest from |pmf| path, parses it and validates
163 // whether plugin path (|PepperPluginInfo::path|) is valid (exsists).
165 // See |ParsePepperPluginManifest| for Plugin Manifest File (pmf) specification.
166 bool FillPepperPluginInfoFromManifest(
167 const base::FilePath& pmf,
168 content::PepperPluginInfo* out_info);
170 } // namespace pepper
172 #endif // EWK_EFL_INTEGRATION_COMMON_TRUSTED_PEPPER_PLUGIN_INFO_CACHE_H_