| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <map> |
| 10 #include <set> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string16.h" | 16 #include "base/string16.h" |
| 15 #include "webkit/plugins/webplugininfo.h" | 17 #include "webkit/plugins/webplugininfo.h" |
| 16 | 18 |
| 17 class FilePath; | 19 class FilePath; |
| 18 class PluginExceptionsTableModelTest; | 20 class PluginExceptionsTableModelTest; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 static const char* kRealPlayerGroupName; | 90 static const char* kRealPlayerGroupName; |
| 89 static const char* kSilverlightGroupName; | 91 static const char* kSilverlightGroupName; |
| 90 static const char* kWindowsMediaPlayerGroupName; | 92 static const char* kWindowsMediaPlayerGroupName; |
| 91 | 93 |
| 92 PluginGroup(const PluginGroup& other); | 94 PluginGroup(const PluginGroup& other); |
| 93 | 95 |
| 94 ~PluginGroup(); | 96 ~PluginGroup(); |
| 95 | 97 |
| 96 PluginGroup& operator=(const PluginGroup& other); | 98 PluginGroup& operator=(const PluginGroup& other); |
| 97 | 99 |
| 100 // Configures the set of plugin name patterns for enabling and disabling |
| 101 // plugins via enterprise configuration management. |
| 102 static void SetPolicyEnforcedPluginPatterns( |
| 103 const std::set<string16>& plugins_disabled, |
| 104 const std::set<string16>& plugins_disabled_exceptions, |
| 105 const std::set<string16>& plugins_enabled); |
| 106 |
| 107 // Tests whether |plugin_name| is disabled by policy. |
| 108 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); |
| 109 |
| 110 // Tests whether |plugin_name| within the plugin group |group_name| is |
| 111 // disabled by policy. |
| 112 static bool IsPluginFileNameDisabledByPolicy(const string16& plugin_name, |
| 113 const string16& group_name); |
| 114 |
| 115 // Tests whether |plugin_name| is enabled by policy. |
| 116 static bool IsPluginNameEnabledByPolicy(const string16& plugin_name); |
| 117 |
| 98 // Returns true if the given plugin matches this group. | 118 // Returns true if the given plugin matches this group. |
| 99 bool Match(const webkit::WebPluginInfo& plugin) const; | 119 bool Match(const webkit::WebPluginInfo& plugin) const; |
| 100 | 120 |
| 101 // Adds the given plugin to this group. | 121 // Adds the given plugin to this group. |
| 102 void AddPlugin(const webkit::WebPluginInfo& plugin); | 122 void AddPlugin(const webkit::WebPluginInfo& plugin); |
| 103 | 123 |
| 104 // Removes a plugin from the group by its path. | 124 // Removes a plugin from the group by its path. |
| 105 bool RemovePlugin(const FilePath& filename); | 125 bool RemovePlugin(const FilePath& filename); |
| 106 | 126 |
| 127 // The two following functions enable/disable a plugin given its filename. The |
| 128 // function returns true if the plugin could be enabled/disabled. Plugins |
| 129 // might not get enabled/disabled if they are controlled by policy or are |
| 130 // already in the wanted state. |
| 131 bool EnablePlugin(const FilePath& filename); |
| 132 bool DisablePlugin(const FilePath& filename); |
| 133 |
| 134 // Enables/disables this group. This enables/disables all plugins in the |
| 135 // group. |
| 136 bool EnableGroup(bool enable); |
| 137 |
| 138 // Checks whether the group should be disabled/enabled by a policy and puts |
| 139 // it in the needed state. Updates all contained plugins too. |
| 140 void EnforceGroupPolicy(); |
| 141 |
| 142 // Returns whether the plugin group is enabled or not. |
| 143 bool Enabled() const { return enabled_; } |
| 144 |
| 107 // Returns a unique identifier for this group, if one is defined, or the empty | 145 // Returns a unique identifier for this group, if one is defined, or the empty |
| 108 // string otherwise. | 146 // string otherwise. |
| 109 const std::string& identifier() const { return identifier_; } | 147 const std::string& identifier() const { return identifier_; } |
| 110 | 148 |
| 111 // Sets a unique identifier for this group or if none is set an empty string. | 149 // Sets a unique identifier for this group or if none is set an empty string. |
| 112 void set_identifier(const std::string& identifier) { | 150 void set_identifier(const std::string& identifier) { |
| 113 identifier_ = identifier; | 151 identifier_ = identifier; |
| 114 } | 152 } |
| 115 | 153 |
| 116 // Returns this group's name, or the filename without extension if the name | 154 // Returns this group's name, or the filename without extension if the name |
| 117 // is empty. | 155 // is empty. |
| 118 string16 GetGroupName() const; | 156 string16 GetGroupName() const; |
| 119 | 157 |
| 158 // Returns all plugins added to the group. |
| 159 const std::vector<webkit::WebPluginInfo>& web_plugins_info() const { |
| 160 return web_plugin_infos_; |
| 161 } |
| 162 |
| 120 // Checks whether a plugin exists in the group with the given path. | 163 // Checks whether a plugin exists in the group with the given path. |
| 121 bool ContainsPlugin(const FilePath& path) const; | 164 bool ContainsPlugin(const FilePath& path) const; |
| 122 | 165 |
| 166 // Returns the description of the highest-priority plug-in in the group. |
| 167 const string16& description() const { return description_; } |
| 168 |
| 169 // Returns a DictionaryValue with data to display in the UI. |
| 170 base::DictionaryValue* GetDataForUI() const; |
| 171 |
| 172 // Returns a DictionaryValue with data to save in the preferences. |
| 173 base::DictionaryValue* GetSummary() const; |
| 174 |
| 123 // Returns the update URL. | 175 // Returns the update URL. |
| 124 std::string GetUpdateURL() const { return update_url_; } | 176 std::string GetUpdateURL() const { return update_url_; } |
| 125 | 177 |
| 126 // Returns true if this plugin group is whitelisted. | 178 // Returns true if this plugin group is whitelisted. |
| 127 bool IsWhitelisted() const; | 179 bool IsWhitelisted() const; |
| 128 | 180 |
| 129 // Returns true if |plugin| in this group has known security problems. | 181 // Returns true if the highest-priority plugin in this group has known |
| 130 bool IsVulnerable(const WebPluginInfo& plugin) const; | 182 // security problems. |
| 183 bool IsVulnerable() const; |
| 131 | 184 |
| 132 // Returns true if |plugin| in this plug-in group always requires user | 185 // Returns true if this plug-in group always requires user authorization |
| 133 // authorization to run. | 186 // to run. |
| 134 bool RequiresAuthorization(const WebPluginInfo& plugin) const; | 187 bool RequiresAuthorization() const; |
| 135 | 188 |
| 136 // Check if the group has no plugins. Could happen after a reload if the plug- | 189 // Check if the group has no plugins. Could happen after a reload if the plug- |
| 137 // in has disappeared from the pc (or in the process of updating). | 190 // in has disappeared from the pc (or in the process of updating). |
| 138 bool IsEmpty() const; | 191 bool IsEmpty() const; |
| 139 | 192 |
| 140 // Parse a version string as used by a plug-in. This method is more lenient | 193 // Parse a version string as used by a plug-in. This method is more lenient |
| 141 // in accepting weird version strings than Version::GetFromString(). | 194 // in accepting weird version strings than Version::GetFromString(). |
| 142 static Version* CreateVersionFromString(const string16& version_string); | 195 static Version* CreateVersionFromString(const string16& version_string); |
| 143 | 196 |
| 144 const std::vector<webkit::WebPluginInfo>& web_plugin_infos() const { | 197 std::vector<webkit::WebPluginInfo> web_plugin_infos() { |
| 145 return web_plugin_infos_; | 198 return web_plugin_infos_; |
| 146 } | 199 } |
| 147 | 200 |
| 148 private: | 201 private: |
| 149 friend class PluginList; | 202 friend class PluginList; |
| 150 friend class MockPluginList; | 203 friend class MockPluginList; |
| 151 friend class PluginGroupTest; | 204 friend class PluginGroupTest; |
| 152 friend class ::PluginExceptionsTableModelTest; | 205 friend class ::PluginExceptionsTableModelTest; |
| 153 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); | 206 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); |
| 154 | 207 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 177 static bool IsPluginOutdated(const Version& plugin_version, | 230 static bool IsPluginOutdated(const Version& plugin_version, |
| 178 const VersionRange& version_range); | 231 const VersionRange& version_range); |
| 179 | 232 |
| 180 PluginGroup(const string16& group_name, | 233 PluginGroup(const string16& group_name, |
| 181 const string16& name_matcher, | 234 const string16& name_matcher, |
| 182 const std::string& update_url, | 235 const std::string& update_url, |
| 183 const std::string& identifier); | 236 const std::string& identifier); |
| 184 | 237 |
| 185 void InitFrom(const PluginGroup& other); | 238 void InitFrom(const PluginGroup& other); |
| 186 | 239 |
| 240 // Set the description and version for this plugin group from the |
| 241 // given plug-in. |
| 242 void UpdateDescriptionAndVersion(const webkit::WebPluginInfo& plugin); |
| 243 |
| 244 // Updates the active plugin in the group. The active plugin is the first |
| 245 // enabled one, or if all plugins are disabled, simply the first one. |
| 246 void UpdateActivePlugin(const webkit::WebPluginInfo& plugin); |
| 247 |
| 248 // Resets the group state to its default value (as if the group was empty). |
| 249 // After calling this method, calling |UpdateActivePlugin| with all plugins |
| 250 // in a row will correctly set the group state. |
| 251 void ResetGroupState(); |
| 252 |
| 253 // Enables the plugin if not already enabled and if policy allows it to. |
| 254 // Returns true on success. Does not update the group state. |
| 255 static bool Enable(webkit::WebPluginInfo* plugin, int reason); |
| 256 |
| 257 // Disables the plugin if not already disabled and if policy allows it to. |
| 258 // Returns true on success. Does not update the group state. |
| 259 static bool Disable(webkit::WebPluginInfo* plugin, int reason); |
| 260 |
| 261 // Helper function to implement the functions above. |
| 262 static bool SetPluginState(webkit::WebPluginInfo* plugin, |
| 263 int new_reason, |
| 264 bool state_changes); |
| 265 |
| 187 // Returns a non-const vector of all plugins in the group. This is only used | 266 // Returns a non-const vector of all plugins in the group. This is only used |
| 188 // by PluginList. | 267 // by PluginList. |
| 189 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { | 268 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { |
| 190 return web_plugin_infos_; | 269 return web_plugin_infos_; |
| 191 } | 270 } |
| 192 | 271 |
| 272 // Checks if |name| matches any of the patterns in |pattern_set|. |
| 273 static bool IsStringMatchedInSet(const string16& name, |
| 274 const std::set<string16>* pattern_set); |
| 275 |
| 276 static std::set<string16>* policy_disabled_plugin_patterns_; |
| 277 static std::set<string16>* policy_disabled_plugin_exception_patterns_; |
| 278 static std::set<string16>* policy_enabled_plugin_patterns_; |
| 279 |
| 193 std::string identifier_; | 280 std::string identifier_; |
| 194 string16 group_name_; | 281 string16 group_name_; |
| 195 string16 name_matcher_; | 282 string16 name_matcher_; |
| 283 string16 description_; |
| 196 std::string update_url_; | 284 std::string update_url_; |
| 285 bool enabled_; |
| 197 std::vector<VersionRange> version_ranges_; | 286 std::vector<VersionRange> version_ranges_; |
| 287 scoped_ptr<Version> version_; |
| 198 std::vector<webkit::WebPluginInfo> web_plugin_infos_; | 288 std::vector<webkit::WebPluginInfo> web_plugin_infos_; |
| 199 }; | 289 }; |
| 200 | 290 |
| 201 } // namespace npapi | 291 } // namespace npapi |
| 202 } // namespace webkit | 292 } // namespace webkit |
| 203 | 293 |
| 204 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 294 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
| OLD | NEW |