Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: webkit/glue/plugins/plugin_group.h

Issue 5516004: Clean up PluginGroup and related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_GLUE_PLUGINS_PLUGIN_GROUP_H_ 5 #ifndef WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_
6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ 6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
15 #include "base/string16.h" 16 #include "base/string16.h"
16 17
17 class DictionaryValue; 18 class DictionaryValue;
18 class FilePath; 19 class FilePath;
19 class Version; 20 class Version;
20 struct WebPluginInfo; 21 struct WebPluginInfo;
21 22
22 namespace NPAPI { 23 namespace NPAPI {
23 class PluginList; 24 class PluginList;
24 }; 25 };
25 26
26 template <typename T>
27 class linked_ptr;
28
29 // Hard-coded definitions of plugin groups. 27 // Hard-coded definitions of plugin groups.
30 struct PluginGroupDefinition { 28 struct PluginGroupDefinition {
31 const char* identifier; // Unique identifier for this group. 29 const char* identifier; // Unique identifier for this group.
32 const char* name; // Name of this group. 30 const char* name; // Name of this group.
33 const char* name_matcher; // Substring matcher for the plugin name. 31 const char* name_matcher; // Substring matcher for the plugin name.
34 const char* version_matcher_low; // Matchers for the plugin version. 32 const char* version_matcher_low; // Matchers for the plugin version.
35 const char* version_matcher_high; 33 const char* version_matcher_high;
36 const char* min_version; // Minimum secure version. 34 const char* min_version; // Minimum secure version.
37 const char* update_url; // Location of latest secure version. 35 const char* update_url; // Location of latest secure version.
38 }; 36 };
39 37
40 // 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
41 // by matching a substring of its name). 39 // by matching a substring of its name).
42 // It contains all WebPluginInfo structs (at least one) matching its definition. 40 // It contains all WebPluginInfo structs (at least one) matching its definition.
43 // In addition, it knows about a security "baseline", i.e. the minimum version 41 // In addition, it knows about a security "baseline", i.e. the minimum version
44 // of a plugin that is needed in order not to exhibit known security 42 // of a plugin that is needed in order not to exhibit known security
45 // vulnerabilities. 43 // vulnerabilities.
46 44
47 class PluginGroup { 45 class PluginGroup {
48 public: 46 public:
49 // Used by about:plugins to disable Reader plugin when internal PDF viewer is 47 // Used by about:plugins to disable Reader plugin when internal PDF viewer is
50 // enabled. 48 // enabled.
51 static const char* kAdobeReader8GroupName; 49 static const char* kAdobeReader8GroupName;
52 static const char* kAdobeReader9GroupName; 50 static const char* kAdobeReader9GroupName;
53 51
54 typedef std::map<std::string, linked_ptr<PluginGroup> > PluginMap; 52 typedef std::map<std::string, PluginGroup*> PluginMap;
Bernhard Bauer 2010/12/03 16:13:28 Do we need this typedef outside of PluginGroup or
Jakob Kummerow 2010/12/06 18:21:12 Done. (Made private.)
55 53
56 // Creates a PluginGroup from a PluginGroupDefinition. 54 // Creates a PluginGroup from a PluginGroupDefinition.
57 static PluginGroup* FromPluginGroupDefinition( 55 static PluginGroup* FromPluginGroupDefinition(
58 const PluginGroupDefinition& definition); 56 const PluginGroupDefinition& definition);
59 57
58 PluginGroup(const PluginGroup& other);
Bernhard Bauer 2010/12/03 16:13:28 Nit: make the single-argument constructor explicit
Jakob Kummerow 2010/12/06 18:21:12 Nope. Let me quote the style guide: "We require al
59
60 ~PluginGroup(); 60 ~PluginGroup();
61 61
62 // Creates a PluginGroup from a WebPluginInfo -- when no hard-coded 62 PluginGroup& operator=(const PluginGroup& other);
63 // definition is found. 63
64 // Creates a PluginGroup from a WebPluginInfo. Should not be called externally
65 // except by PluginList and unit tests.
Bernhard Bauer 2010/12/03 16:13:28 PluginList is already a friend, so just declare th
Jakob Kummerow 2010/12/06 18:21:12 Done. This required adding several more friend cla
64 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi); 66 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi);
65 67
66 // Find a plugin group matching |info| in the list of hardcoded plugins and
67 // returns a copy of it if found, or a new group matching exactly this plugin
68 // otherwise.
69 // The caller should take ownership of the return PluginGroup.
70 static PluginGroup* CopyOrCreatePluginGroup(const WebPluginInfo& info);
71
72 // Configures the set of plugin name patterns for disabling plugins via 68 // Configures the set of plugin name patterns for disabling plugins via
73 // enterprise configuration management. 69 // enterprise configuration management.
74 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set); 70 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set);
75 71
76 // Tests to see if a plugin is on the blacklist using its name as 72 // Tests to see if a plugin is on the blacklist using its name as
77 // the lookup key. 73 // the lookup key.
78 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); 74 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name);
79 75
80 // Tests to see if a plugin is on the blacklist using its path as 76 // Tests to see if a plugin is on the blacklist using its path as
81 // the lookup key. 77 // the lookup key.
82 static bool IsPluginPathDisabledByPolicy(const FilePath& plugin_path); 78 static bool IsPluginPathDisabledByPolicy(const FilePath& plugin_path);
83 79
84 // Find the PluginGroup matching a Plugin in a list of plugin groups. Returns
85 // NULL if no matching PluginGroup is found.
86 static PluginGroup* FindGroupMatchingPlugin(
87 const std::map<std::string, linked_ptr<PluginGroup> >& plugin_groups,
88 const WebPluginInfo& plugin);
89
90 // Creates a copy of this plugin group.
91 PluginGroup* Copy() {
92 return new PluginGroup(group_name_, name_matcher_, version_range_low_str_,
93 version_range_high_str_, min_version_str_,
94 update_url_, identifier_);
95 }
96
97 // Returns true if the given plugin matches this group. 80 // Returns true if the given plugin matches this group.
98 bool Match(const WebPluginInfo& plugin) const; 81 bool Match(const WebPluginInfo& plugin) const;
99 82
100 // Adds the given plugin to this group. Provide the position of the 83 // Adds the given plugin to this group. Provide the position of the
101 // plugin as given by PluginList so we can display its priority. 84 // plugin as given by PluginList so we can display its priority.
102 void AddPlugin(const WebPluginInfo& plugin, int position); 85 void AddPlugin(const WebPluginInfo& plugin, int position);
103 86
104 // Enables/disables this group. This enables/disables all plugins in the 87 // Enables/disables this group. This enables/disables all plugins in the
105 // group. 88 // group.
106 void Enable(bool enable); 89 void Enable(bool enable);
(...skipping 23 matching lines...) Expand all
130 113
131 // Returns true if the highest-priority plugin in this group has known 114 // Returns true if the highest-priority plugin in this group has known
132 // security problems. 115 // security problems.
133 bool IsVulnerable() const; 116 bool IsVulnerable() const;
134 117
135 // Disables all plugins in this group that are older than the 118 // Disables all plugins in this group that are older than the
136 // minimum version. 119 // minimum version.
137 void DisableOutdatedPlugins(); 120 void DisableOutdatedPlugins();
138 121
139 private: 122 private:
123 friend class NPAPI::PluginList;
140 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); 124 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition);
141 125
142 static const PluginGroupDefinition* GetPluginGroupDefinitions(); 126 static const PluginGroupDefinition* GetPluginGroupDefinitions();
143 static size_t GetPluginGroupDefinitionsSize(); 127 static size_t GetPluginGroupDefinitionsSize();
144 128
129 // Generates the (short) identifier string for the given plugin.
130 static std::string GetIdentifier(const WebPluginInfo& wpi);
131
132 // Generates the long identifier (based on the full file path) for the given
133 // plugin, to be called when the short identifier is not unique.
134 static std::string GetLongIdentifier(const WebPluginInfo& wpi);
135
136 // Find the PluginGroup matching a Plugin in a list of plugin groups. Returns
137 // NULL if no matching PluginGroup is found.
138 static PluginGroup* FindGroupMatchingPlugin(
139 const PluginMap* plugin_groups,
140 const WebPluginInfo& plugin);
141
145 PluginGroup(const string16& group_name, 142 PluginGroup(const string16& group_name,
146 const string16& name_matcher, 143 const string16& name_matcher,
147 const std::string& version_range_low, 144 const std::string& version_range_low,
148 const std::string& version_range_high, 145 const std::string& version_range_high,
149 const std::string& min_version, 146 const std::string& min_version,
150 const std::string& update_url, 147 const std::string& update_url,
151 const std::string& identifier); 148 const std::string& identifier);
152 149
153 Version* CreateVersionFromString(const string16& version_string); 150 Version* CreateVersionFromString(const string16& version_string);
154 151
(...skipping 15 matching lines...) Expand all
170 scoped_ptr<Version> version_range_low_; 167 scoped_ptr<Version> version_range_low_;
171 scoped_ptr<Version> version_range_high_; 168 scoped_ptr<Version> version_range_high_;
172 string16 description_; 169 string16 description_;
173 std::string update_url_; 170 std::string update_url_;
174 bool enabled_; 171 bool enabled_;
175 std::string min_version_str_; 172 std::string min_version_str_;
176 scoped_ptr<Version> min_version_; 173 scoped_ptr<Version> min_version_;
177 scoped_ptr<Version> version_; 174 scoped_ptr<Version> version_;
178 std::vector<WebPluginInfo> web_plugin_infos_; 175 std::vector<WebPluginInfo> web_plugin_infos_;
179 std::vector<int> web_plugin_positions_; 176 std::vector<int> web_plugin_positions_;
180
181 DISALLOW_COPY_AND_ASSIGN(PluginGroup);
182 }; 177 };
183 178
184 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ 179 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698