| 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 | |
| 39 // Hard-coded definitions of plugin groups. | 28 // Hard-coded definitions of plugin groups. |
| 40 struct PluginGroupDefinition { | 29 struct PluginGroupDefinition { |
| 41 // Unique identifier for this group. | 30 // Unique identifier for this group. |
| 42 const char* identifier; | 31 const char* identifier; |
| 43 // Name of this group. | 32 // Name of this group. |
| 44 const char* name; | 33 const char* name; |
| 45 // Substring matcher for the plugin name. | 34 // Substring matcher for the plugin name. |
| 46 const char* name_matcher; | 35 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); | |
| 69 }; | 36 }; |
| 70 | 37 |
| 71 // A PluginGroup can match a range of versions of a specific plugin (as defined | 38 // A PluginGroup can match a range of versions of a specific plugin (as defined |
| 72 // by matching a substring of its name). | 39 // by matching a substring of its name). |
| 73 // It contains all WebPluginInfo structs (at least one) matching its definition. | 40 // 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. | |
| 77 | 41 |
| 78 class WEBKIT_PLUGINS_EXPORT PluginGroup { | 42 class WEBKIT_PLUGINS_EXPORT PluginGroup { |
| 79 public: | 43 public: |
| 80 // Used by about:plugins to disable Reader plugin when internal PDF viewer is | 44 // Used by about:plugins to disable Reader plugin when internal PDF viewer is |
| 81 // enabled. | 45 // enabled. |
| 82 static const char kAdobeReaderGroupName[]; | 46 static const char kAdobeReaderGroupName[]; |
| 83 static const char kJavaGroupName[]; | 47 static const char kJavaGroupName[]; |
| 84 static const char kQuickTimeGroupName[]; | 48 static const char kQuickTimeGroupName[]; |
| 85 static const char kShockwaveGroupName[]; | 49 static const char kShockwaveGroupName[]; |
| 86 static const char kRealPlayerGroupName[]; | 50 static const char kRealPlayerGroupName[]; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 111 identifier_ = identifier; | 75 identifier_ = identifier; |
| 112 } | 76 } |
| 113 | 77 |
| 114 // Returns this group's name, or the filename without extension if the name | 78 // Returns this group's name, or the filename without extension if the name |
| 115 // is empty. | 79 // is empty. |
| 116 string16 GetGroupName() const; | 80 string16 GetGroupName() const; |
| 117 | 81 |
| 118 // Checks whether a plugin exists in the group with the given path. | 82 // Checks whether a plugin exists in the group with the given path. |
| 119 bool ContainsPlugin(const FilePath& path) const; | 83 bool ContainsPlugin(const FilePath& path) const; |
| 120 | 84 |
| 121 // Returns true if |plugin| in this group has known security problems. | |
| 122 bool IsVulnerable(const WebPluginInfo& plugin) const; | |
| 123 | |
| 124 // Check if the group has no plugins. Could happen after a reload if the plug- | 85 // Check if the group has no plugins. Could happen after a reload if the plug- |
| 125 // in has disappeared from the pc (or in the process of updating). | 86 // in has disappeared from the pc (or in the process of updating). |
| 126 bool IsEmpty() const; | 87 bool IsEmpty() const; |
| 127 | 88 |
| 128 // Parse a version string as used by a plug-in. This method is more lenient | 89 // Parse a version string as used by a plug-in. This method is more lenient |
| 129 // in accepting weird version strings than Version::GetFromString(). | 90 // in accepting weird version strings than Version::GetFromString(). |
| 130 static Version* CreateVersionFromString(const string16& version_string); | 91 static Version* CreateVersionFromString(const string16& version_string); |
| 131 | 92 |
| 132 const std::vector<webkit::WebPluginInfo>& web_plugin_infos() const { | 93 const std::vector<webkit::WebPluginInfo>& web_plugin_infos() const { |
| 133 return web_plugin_infos_; | 94 return web_plugin_infos_; |
| 134 } | 95 } |
| 135 | 96 |
| 136 const std::vector<VersionRange>& version_ranges() const { | |
| 137 return version_ranges_; | |
| 138 } | |
| 139 | |
| 140 private: | 97 private: |
| 141 friend class MockPluginList; | 98 friend class MockPluginList; |
| 142 friend class PluginGroupTest; | 99 friend class PluginGroupTest; |
| 143 friend class PluginList; | 100 friend class PluginList; |
| 144 friend class ::PluginExceptionsTableModelTest; | 101 friend class ::PluginExceptionsTableModelTest; |
| 145 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); | 102 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); |
| 146 | 103 |
| 147 // Generates the (short) identifier string for the given plugin. | 104 // Generates the (short) identifier string for the given plugin. |
| 148 static std::string GetIdentifier(const webkit::WebPluginInfo& wpi); | 105 static std::string GetIdentifier(const webkit::WebPluginInfo& wpi); |
| 149 | 106 |
| 150 // Generates the long identifier (based on the full file path) for the given | 107 // Generates the long identifier (based on the full file path) for the given |
| 151 // plugin, to be called when the short identifier is not unique. | 108 // plugin, to be called when the short identifier is not unique. |
| 152 static std::string GetLongIdentifier(const webkit::WebPluginInfo& wpi); | 109 static std::string GetLongIdentifier(const webkit::WebPluginInfo& wpi); |
| 153 | 110 |
| 154 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes | 111 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes |
| 155 // ownership of the created PluginGroup. | 112 // ownership of the created PluginGroup. |
| 156 static PluginGroup* FromPluginGroupDefinition( | 113 static PluginGroup* FromPluginGroupDefinition( |
| 157 const PluginGroupDefinition& definition); | 114 const PluginGroupDefinition& definition); |
| 158 | 115 |
| 159 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of | 116 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of |
| 160 // the created PluginGroup. | 117 // the created PluginGroup. |
| 161 static PluginGroup* FromWebPluginInfo(const webkit::WebPluginInfo& wpi); | 118 static PluginGroup* FromWebPluginInfo(const webkit::WebPluginInfo& wpi); |
| 162 | 119 |
| 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 | |
| 172 PluginGroup(const string16& group_name, | 120 PluginGroup(const string16& group_name, |
| 173 const string16& name_matcher, | 121 const string16& name_matcher, |
| 174 const std::string& identifier); | 122 const std::string& identifier); |
| 175 | 123 |
| 176 void InitFrom(const PluginGroup& other); | 124 void InitFrom(const PluginGroup& other); |
| 177 | 125 |
| 178 // Returns a non-const vector of all plugins in the group. This is only used | 126 // Returns a non-const vector of all plugins in the group. This is only used |
| 179 // by PluginList. | 127 // by PluginList. |
| 180 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { | 128 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { |
| 181 return web_plugin_infos_; | 129 return web_plugin_infos_; |
| 182 } | 130 } |
| 183 | 131 |
| 184 std::string identifier_; | 132 std::string identifier_; |
| 185 string16 group_name_; | 133 string16 group_name_; |
| 186 string16 name_matcher_; | 134 string16 name_matcher_; |
| 187 std::vector<VersionRange> version_ranges_; | |
| 188 std::vector<webkit::WebPluginInfo> web_plugin_infos_; | 135 std::vector<webkit::WebPluginInfo> web_plugin_infos_; |
| 189 }; | 136 }; |
| 190 | 137 |
| 191 } // namespace npapi | 138 } // namespace npapi |
| 192 } // namespace webkit | 139 } // namespace webkit |
| 193 | 140 |
| 194 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 141 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
| OLD | NEW |