1 // Copyright (c) 2011 The Chromium Authors. 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.
4 
5 #ifndef CONTENT_PUBLIC_COMMON_WEBPLUGININFO_H_
6 #define CONTENT_PUBLIC_COMMON_WEBPLUGININFO_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 #include <vector>
12 
13 #include "base/files/file_path.h"
14 #include "content/common/content_export.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 
17 namespace base {
18 class Version;
19 }
20 
21 namespace content {
22 
23 struct CONTENT_EXPORT WebPluginMimeType {
24   WebPluginMimeType();
25   // A constructor for the common case of a single file extension and an ASCII
26   // description.
27   WebPluginMimeType(const std::string& m,
28                     const std::string& f,
29                     const std::string& d);
30   WebPluginMimeType(const WebPluginMimeType& other);
31   ~WebPluginMimeType();
32 
33   // The name of the mime type (e.g., "application/x-shockwave-flash").
34   std::string mime_type;
35 
36   // A list of all the file extensions for this mime type.
37   std::vector<std::string> file_extensions;
38 
39   // Description of the mime type.
40   base::string16 description;
41 
42   // Extra parameters to include when instantiating the plugin.
43   struct Param {
44     Param() = default;
ParamWebPluginMimeType::Param45     Param(base::string16 n, base::string16 v)
46         : name(std::move(n)), value(std::move(v)) {}
47     base::string16 name;
48     base::string16 value;
49   };
50   std::vector<Param> additional_params;
51 };
52 
53 // Describes an available Pepper plugin.
54 struct CONTENT_EXPORT WebPluginInfo {
55   enum PluginType {
56     PLUGIN_TYPE_PEPPER_IN_PROCESS,
57     PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS,
58     PLUGIN_TYPE_BROWSER_PLUGIN
59   };
60 
61   static constexpr SkColor kDefaultBackgroundColor = SkColorSetRGB(38, 38, 38);
62 
63   WebPluginInfo();
64   WebPluginInfo(const WebPluginInfo& rhs);
65   ~WebPluginInfo();
66   WebPluginInfo& operator=(const WebPluginInfo& rhs);
67 
68   // Special constructor only used during unit testing:
69   WebPluginInfo(const base::string16& fake_name,
70                 const base::FilePath& fake_path,
71                 const base::string16& fake_version,
72                 const base::string16& fake_desc);
73 
is_pepper_pluginWebPluginInfo74   bool is_pepper_plugin() const {
75     return ((type == PLUGIN_TYPE_PEPPER_IN_PROCESS ) ||
76           (type == PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS));
77   }
78 
79   // Parse a version string as used by a plugin. This method is more lenient
80   // in accepting weird version strings than base::Version::GetFromString()
81   static void CreateVersionFromString(const base::string16& version_string,
82                                       base::Version* parsed_version);
83 
84   // The name of the plugin (i.e. Flash).
85   base::string16 name;
86 
87   // The path to the plugin file (DLL/bundle/library).
88   base::FilePath path;
89 
90   // The version number of the plugin file (may be OS-specific)
91   base::string16 version;
92 
93   // A description of the plugin that we get from its version info.
94   base::string16 desc;
95 
96   // A list of all the mime types that this plugin supports.
97   std::vector<WebPluginMimeType> mime_types;
98 
99   // Plugin type. See the PluginType enum.
100   int type;
101 
102   // When type is PLUGIN_TYPE_PEPPER_* this indicates the permission bits.
103   int32_t pepper_permissions;
104 
105   // The color to use as the background before the plugin loads.
106   SkColor background_color = kDefaultBackgroundColor;
107 };
108 
109 }  // namespace content
110 
111 #endif  // CONTENT_PUBLIC_COMMON_WEBPLUGININFO_H_
112