OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "webkit/plugins/webkit_plugins_export.h" | 15 #include "webkit/plugins/webkit_plugins_export.h" |
16 #include "webkit/plugins/webplugininfo.h" | 16 #include "webkit/plugins/webplugininfo.h" |
17 | 17 |
18 class FilePath; | 18 class FilePath; |
19 class PluginExceptionsTableModelTest; | 19 class PluginExceptionsTableModelTest; |
20 class Version; | 20 class Version; |
21 | 21 |
22 namespace webkit { | 22 namespace webkit { |
23 namespace npapi { | 23 namespace npapi { |
24 | 24 |
25 class PluginList; | 25 class PluginList; |
26 class MockPluginList; | 26 class MockPluginList; |
27 | 27 |
| 28 // Hard-coded version ranges for plugin groups. |
| 29 struct VersionRangeDefinition { |
| 30 // Matcher for lowest version matched by this range (inclusive). May be empty |
| 31 // to match everything iff |version_matcher_high| is also empty. |
| 32 const char* version_matcher_low; |
| 33 // Matcher for highest version matched by this range (exclusive). May be empty |
| 34 // to match anything higher than |version_matcher_low|. |
| 35 const char* version_matcher_high; |
| 36 const char* min_version; // Minimum secure version. |
| 37 }; |
| 38 |
28 // Hard-coded definitions of plugin groups. | 39 // Hard-coded definitions of plugin groups. |
29 struct PluginGroupDefinition { | 40 struct PluginGroupDefinition { |
30 // Unique identifier for this group. | 41 // Unique identifier for this group. |
31 const char* identifier; | 42 const char* identifier; |
32 // Name of this group. | 43 // Name of this group. |
33 const char* name; | 44 const char* name; |
34 // Substring matcher for the plugin name. | 45 // Substring matcher for the plugin name. |
35 const char* name_matcher; | 46 const char* name_matcher; |
| 47 // List of version ranges. |
| 48 const VersionRangeDefinition* versions; |
| 49 // Size of the array |versions| points to. |
| 50 size_t num_versions; |
| 51 }; |
| 52 |
| 53 // Run-time structure to hold version range information. |
| 54 struct VersionRange { |
| 55 public: |
| 56 explicit VersionRange(const VersionRangeDefinition& definition); |
| 57 VersionRange(const VersionRange& other); |
| 58 VersionRange& operator=(const VersionRange& other); |
| 59 ~VersionRange(); |
| 60 |
| 61 std::string low_str; |
| 62 std::string high_str; |
| 63 std::string min_str; |
| 64 scoped_ptr<Version> low; |
| 65 scoped_ptr<Version> high; |
| 66 scoped_ptr<Version> min; |
| 67 private: |
| 68 void InitFrom(const VersionRange& other); |
36 }; | 69 }; |
37 | 70 |
38 // A PluginGroup can match a range of versions of a specific plugin (as defined | 71 // A PluginGroup can match a range of versions of a specific plugin (as defined |
39 // by matching a substring of its name). | 72 // by matching a substring of its name). |
40 // It contains all WebPluginInfo structs (at least one) matching its definition. | 73 // It contains all WebPluginInfo structs (at least one) matching its definition. |
| 74 // In addition, it knows about a security "baseline", i.e. the minimum version |
| 75 // of a plugin that is needed in order not to exhibit known security |
| 76 // vulnerabilities. |
41 | 77 |
42 class WEBKIT_PLUGINS_EXPORT PluginGroup { | 78 class WEBKIT_PLUGINS_EXPORT PluginGroup { |
43 public: | 79 public: |
44 // Used by about:plugins to disable Reader plugin when internal PDF viewer is | 80 // Used by about:plugins to disable Reader plugin when internal PDF viewer is |
45 // enabled. | 81 // enabled. |
46 static const char kAdobeReaderGroupName[]; | 82 static const char kAdobeReaderGroupName[]; |
47 static const char kJavaGroupName[]; | 83 static const char kJavaGroupName[]; |
48 static const char kQuickTimeGroupName[]; | 84 static const char kQuickTimeGroupName[]; |
49 static const char kShockwaveGroupName[]; | 85 static const char kShockwaveGroupName[]; |
50 static const char kRealPlayerGroupName[]; | 86 static const char kRealPlayerGroupName[]; |
(...skipping 24 matching lines...) Expand all Loading... |
75 identifier_ = identifier; | 111 identifier_ = identifier; |
76 } | 112 } |
77 | 113 |
78 // Returns this group's name, or the filename without extension if the name | 114 // Returns this group's name, or the filename without extension if the name |
79 // is empty. | 115 // is empty. |
80 string16 GetGroupName() const; | 116 string16 GetGroupName() const; |
81 | 117 |
82 // Checks whether a plugin exists in the group with the given path. | 118 // Checks whether a plugin exists in the group with the given path. |
83 bool ContainsPlugin(const FilePath& path) const; | 119 bool ContainsPlugin(const FilePath& path) const; |
84 | 120 |
| 121 // Returns true if |plugin| in this group has known security problems. |
| 122 bool IsVulnerable(const WebPluginInfo& plugin) const; |
| 123 |
85 // Check if the group has no plugins. Could happen after a reload if the plug- | 124 // Check if the group has no plugins. Could happen after a reload if the plug- |
86 // in has disappeared from the pc (or in the process of updating). | 125 // in has disappeared from the pc (or in the process of updating). |
87 bool IsEmpty() const; | 126 bool IsEmpty() const; |
88 | 127 |
89 // Parse a version string as used by a plug-in. This method is more lenient | 128 // Parse a version string as used by a plug-in. This method is more lenient |
90 // in accepting weird version strings than Version::GetFromString(). | 129 // in accepting weird version strings than Version::GetFromString(). |
91 static Version* CreateVersionFromString(const string16& version_string); | 130 static Version* CreateVersionFromString(const string16& version_string); |
92 | 131 |
93 const std::vector<webkit::WebPluginInfo>& web_plugin_infos() const { | 132 const std::vector<webkit::WebPluginInfo>& web_plugin_infos() const { |
94 return web_plugin_infos_; | 133 return web_plugin_infos_; |
95 } | 134 } |
96 | 135 |
| 136 const std::vector<VersionRange>& version_ranges() const { |
| 137 return version_ranges_; |
| 138 } |
| 139 |
97 private: | 140 private: |
98 friend class MockPluginList; | 141 friend class MockPluginList; |
99 friend class PluginGroupTest; | 142 friend class PluginGroupTest; |
100 friend class PluginList; | 143 friend class PluginList; |
101 friend class ::PluginExceptionsTableModelTest; | 144 friend class ::PluginExceptionsTableModelTest; |
102 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); | 145 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); |
103 | 146 |
104 // Generates the (short) identifier string for the given plugin. | 147 // Generates the (short) identifier string for the given plugin. |
105 static std::string GetIdentifier(const webkit::WebPluginInfo& wpi); | 148 static std::string GetIdentifier(const webkit::WebPluginInfo& wpi); |
106 | 149 |
107 // Generates the long identifier (based on the full file path) for the given | 150 // Generates the long identifier (based on the full file path) for the given |
108 // plugin, to be called when the short identifier is not unique. | 151 // plugin, to be called when the short identifier is not unique. |
109 static std::string GetLongIdentifier(const webkit::WebPluginInfo& wpi); | 152 static std::string GetLongIdentifier(const webkit::WebPluginInfo& wpi); |
110 | 153 |
111 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes | 154 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes |
112 // ownership of the created PluginGroup. | 155 // ownership of the created PluginGroup. |
113 static PluginGroup* FromPluginGroupDefinition( | 156 static PluginGroup* FromPluginGroupDefinition( |
114 const PluginGroupDefinition& definition); | 157 const PluginGroupDefinition& definition); |
115 | 158 |
116 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of | 159 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of |
117 // the created PluginGroup. | 160 // the created PluginGroup. |
118 static PluginGroup* FromWebPluginInfo(const webkit::WebPluginInfo& wpi); | 161 static PluginGroup* FromWebPluginInfo(const webkit::WebPluginInfo& wpi); |
119 | 162 |
| 163 // Returns |true| if |version| is contained in [low, high) of |range|. |
| 164 static bool IsVersionInRange(const Version& version, |
| 165 const VersionRange& range); |
| 166 |
| 167 // Returns |true| iff |plugin_version| is both contained in |version_range| |
| 168 // and declared outdated (== vulnerable) by it. |
| 169 static bool IsPluginOutdated(const Version& plugin_version, |
| 170 const VersionRange& version_range); |
| 171 |
120 PluginGroup(const string16& group_name, | 172 PluginGroup(const string16& group_name, |
121 const string16& name_matcher, | 173 const string16& name_matcher, |
122 const std::string& identifier); | 174 const std::string& identifier); |
123 | 175 |
124 void InitFrom(const PluginGroup& other); | 176 void InitFrom(const PluginGroup& other); |
125 | 177 |
126 // Returns a non-const vector of all plugins in the group. This is only used | 178 // Returns a non-const vector of all plugins in the group. This is only used |
127 // by PluginList. | 179 // by PluginList. |
128 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { | 180 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { |
129 return web_plugin_infos_; | 181 return web_plugin_infos_; |
130 } | 182 } |
131 | 183 |
132 std::string identifier_; | 184 std::string identifier_; |
133 string16 group_name_; | 185 string16 group_name_; |
134 string16 name_matcher_; | 186 string16 name_matcher_; |
| 187 std::vector<VersionRange> version_ranges_; |
135 std::vector<webkit::WebPluginInfo> web_plugin_infos_; | 188 std::vector<webkit::WebPluginInfo> web_plugin_infos_; |
136 }; | 189 }; |
137 | 190 |
138 } // namespace npapi | 191 } // namespace npapi |
139 } // namespace webkit | 192 } // namespace webkit |
140 | 193 |
141 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 194 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
OLD | NEW |