OLD | NEW |
---|---|
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 #include "webkit/glue/plugins/plugin_group.h" | 5 #include "webkit/glue/plugins/plugin_group.h" |
6 | 6 |
7 #include "base/linked_ptr.h" | 7 #include "base/linked_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 if (!version_range_low.empty()) | 150 if (!version_range_low.empty()) |
151 version_range_low_.reset(Version::GetVersionFromString(version_range_low)); | 151 version_range_low_.reset(Version::GetVersionFromString(version_range_low)); |
152 if (!version_range_high.empty()) { | 152 if (!version_range_high.empty()) { |
153 version_range_high_.reset( | 153 version_range_high_.reset( |
154 Version::GetVersionFromString(version_range_high)); | 154 Version::GetVersionFromString(version_range_high)); |
155 } | 155 } |
156 if (!min_version.empty()) | 156 if (!min_version.empty()) |
157 min_version_.reset(Version::GetVersionFromString(min_version)); | 157 min_version_.reset(Version::GetVersionFromString(min_version)); |
158 } | 158 } |
159 | 159 |
160 PluginGroup::PluginGroup(const PluginGroup& other) | |
161 : identifier_(other.identifier_), | |
162 group_name_(other.group_name_), | |
163 name_matcher_(other.name_matcher_), | |
164 version_range_low_str_(other.version_range_low_str_), | |
165 version_range_high_str_(other.version_range_high_str_), | |
166 version_range_low_(Version::GetVersionFromString(version_range_low_str_)), | |
167 version_range_high_( | |
168 Version::GetVersionFromString(version_range_high_str_)), | |
169 description_(other.description_), | |
170 update_url_(other.update_url_), | |
171 enabled_(other.enabled_), | |
172 min_version_str_(other.min_version_str_), | |
173 min_version_(Version::GetVersionFromString(min_version_str_)) { | |
174 DCHECK(other.web_plugin_infos_.size() == other.web_plugin_positions_.size()); | |
Bernhard Bauer
2010/12/03 16:13:28
You could pull this and the version_ constructor c
Jakob Kummerow
2010/12/06 18:21:12
Done. Good idea.
| |
175 for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) | |
176 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); | |
177 if (!version_.get()) | |
178 version_.reset(Version::GetVersionFromString("0")); | |
179 DCHECK(enabled_ == other.enabled_); | |
180 } | |
181 | |
182 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | |
183 identifier_ = other.identifier_; | |
184 group_name_ = other.group_name_; | |
185 name_matcher_ = other.name_matcher_; | |
186 version_range_low_str_ = other.version_range_low_str_; | |
187 version_range_high_str_ = other.version_range_high_str_; | |
188 version_range_low_.reset( | |
189 Version::GetVersionFromString(version_range_low_str_)); | |
190 version_range_high_.reset( | |
191 Version::GetVersionFromString(version_range_high_str_)); | |
192 description_ = other.description_; | |
193 update_url_ = other.update_url_; | |
194 enabled_ = other.enabled_; | |
195 min_version_str_ = other.min_version_str_; | |
196 min_version_.reset(Version::GetVersionFromString(min_version_str_)); | |
197 DCHECK(other.web_plugin_infos_.size() == other.web_plugin_positions_.size()); | |
198 for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) | |
199 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); | |
200 DCHECK(web_plugin_infos_.size() == other.web_plugin_infos_.size()); | |
201 if (!version_.get()) | |
202 version_.reset(Version::GetVersionFromString("0")); | |
203 return *this; | |
204 } | |
205 | |
206 /*static*/ | |
160 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 207 PluginGroup* PluginGroup::FromPluginGroupDefinition( |
161 const PluginGroupDefinition& definition) { | 208 const PluginGroupDefinition& definition) { |
162 return new PluginGroup(ASCIIToUTF16(definition.name), | 209 return new PluginGroup(ASCIIToUTF16(definition.name), |
163 ASCIIToUTF16(definition.name_matcher), | 210 ASCIIToUTF16(definition.name_matcher), |
164 definition.version_matcher_low, | 211 definition.version_matcher_low, |
165 definition.version_matcher_high, | 212 definition.version_matcher_high, |
166 definition.min_version, | 213 definition.min_version, |
167 definition.update_url, | 214 definition.update_url, |
168 definition.identifier); | 215 definition.identifier); |
169 } | 216 } |
170 | 217 |
171 PluginGroup::~PluginGroup() { } | 218 PluginGroup::~PluginGroup() { } |
172 | 219 |
220 /*static*/ | |
221 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { | |
222 #if defined(OS_POSIX) | |
223 return wpi.path.BaseName().value(); | |
224 #elif defined(OS_WIN) | |
225 return base::SysWideToUTF8(wpi.path.BaseName().value()); | |
226 #endif | |
227 } | |
228 | |
229 /*static*/ | |
230 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { | |
231 #if defined(OS_POSIX) | |
232 return wpi.path.value(); | |
233 #elif defined(OS_WIN) | |
234 return base::SysWideToUTF8(wpi.path.value()); | |
235 #endif | |
236 } | |
237 | |
238 /*static*/ | |
173 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { | 239 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { |
174 // Create a matcher from the name of this plugin. | 240 // Create a matcher from the name of this plugin. |
175 #if defined(OS_POSIX) | |
176 std::string identifier = wpi.path.BaseName().value(); | |
177 #elif defined(OS_WIN) | |
178 std::string identifier = base::SysWideToUTF8(wpi.path.BaseName().value()); | |
179 #endif | |
180 return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), | 241 return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), |
181 std::string(), std::string(), identifier); | 242 std::string(), std::string(), |
243 GetIdentifier(wpi)); | |
182 } | 244 } |
183 | 245 |
184 PluginGroup* PluginGroup::CopyOrCreatePluginGroup( | 246 /*static*/ |
185 const WebPluginInfo& info) { | |
186 static PluginMap* hardcoded_plugin_groups = NULL; | |
187 if (!hardcoded_plugin_groups) { | |
188 PluginMap* groups = new PluginMap(); | |
189 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); | |
190 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { | |
191 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( | |
192 definitions[i]); | |
193 std::string identifier = definition_group->identifier(); | |
194 DCHECK(groups->find(identifier) == groups->end()); | |
195 (*groups)[identifier] = linked_ptr<PluginGroup>(definition_group); | |
196 } | |
197 hardcoded_plugin_groups = groups; | |
198 } | |
199 | |
200 // See if this plugin matches any of the hardcoded groups. | |
201 PluginGroup* hardcoded_group = FindGroupMatchingPlugin( | |
202 *hardcoded_plugin_groups, info); | |
203 if (hardcoded_group) { | |
204 // Make a copy. | |
205 return hardcoded_group->Copy(); | |
206 } else { | |
207 // Not found in our hardcoded list, create a new one. | |
208 return PluginGroup::FromWebPluginInfo(info); | |
209 } | |
210 } | |
211 | |
212 PluginGroup* PluginGroup::FindGroupMatchingPlugin( | 247 PluginGroup* PluginGroup::FindGroupMatchingPlugin( |
213 const PluginMap& plugin_groups, | 248 const PluginMap* plugin_groups, |
Bernhard Bauer
2010/12/03 16:13:28
If you remove the const here, you can get rid of t
Jakob Kummerow
2010/12/06 18:21:12
Done.
| |
214 const WebPluginInfo& plugin) { | 249 const WebPluginInfo& plugin) { |
215 for (std::map<std::string, linked_ptr<PluginGroup> >::const_iterator it = | 250 for (PluginMap::const_iterator it = plugin_groups->begin(); |
216 plugin_groups.begin(); | 251 it != plugin_groups->end(); |
217 it != plugin_groups.end(); | |
218 ++it) { | 252 ++it) { |
219 if (it->second->Match(plugin)) | 253 if (it->second->Match(plugin)) |
220 return it->second.get(); | 254 return const_cast<PluginGroup*>(it->second); |
221 } | 255 } |
222 return NULL; | 256 return NULL; |
223 } | 257 } |
224 | 258 |
225 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 259 bool PluginGroup::Match(const WebPluginInfo& plugin) const { |
226 if (name_matcher_.empty()) { | 260 if (name_matcher_.empty()) { |
227 return false; | 261 return false; |
228 } | 262 } |
229 | 263 |
230 // Look for the name matcher anywhere in the plugin name. | 264 // Look for the name matcher anywhere in the plugin name. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 | 314 |
281 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 315 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
282 description_ = plugin.desc; | 316 description_ = plugin.desc; |
283 if (Version* new_version = CreateVersionFromString(plugin.version)) | 317 if (Version* new_version = CreateVersionFromString(plugin.version)) |
284 version_.reset(new_version); | 318 version_.reset(new_version); |
285 else | 319 else |
286 version_.reset(Version::GetVersionFromString("0")); | 320 version_.reset(Version::GetVersionFromString("0")); |
287 } | 321 } |
288 | 322 |
289 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 323 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { |
324 // Check if this group already contains this plugin. | |
325 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | |
326 if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), | |
327 plugin.path.value())) { | |
328 return; | |
329 } | |
330 } | |
290 web_plugin_infos_.push_back(plugin); | 331 web_plugin_infos_.push_back(plugin); |
291 // The position of this plugin relative to the global list of plugins. | 332 // The position of this plugin relative to the global list of plugins. |
292 web_plugin_positions_.push_back(position); | 333 web_plugin_positions_.push_back(position); |
293 UpdateActivePlugin(plugin); | 334 UpdateActivePlugin(plugin); |
294 } | 335 } |
295 | 336 |
296 string16 PluginGroup::GetGroupName() const { | 337 string16 PluginGroup::GetGroupName() const { |
297 if (!group_name_.empty()) | 338 if (!group_name_.empty()) |
298 return group_name_; | 339 return group_name_; |
299 DCHECK_EQ(1u, web_plugin_infos_.size()); | 340 DCHECK_EQ(1u, web_plugin_infos_.size()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 441 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
401 if (version.get() && version->CompareTo(*min_version_) < 0) { | 442 if (version.get() && version->CompareTo(*min_version_) < 0) { |
402 it->enabled = false; | 443 it->enabled = false; |
403 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 444 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
404 } | 445 } |
405 UpdateActivePlugin(*it); | 446 UpdateActivePlugin(*it); |
406 } | 447 } |
407 } | 448 } |
408 | 449 |
409 void PluginGroup::Enable(bool enable) { | 450 void PluginGroup::Enable(bool enable) { |
410 for (std::vector<WebPluginInfo>::const_iterator it = | 451 bool enabled_plugin_exists = false; |
452 for (std::vector<WebPluginInfo>::iterator it = | |
411 web_plugin_infos_.begin(); | 453 web_plugin_infos_.begin(); |
412 it != web_plugin_infos_.end(); ++it) { | 454 it != web_plugin_infos_.end(); ++it) { |
413 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 455 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { |
414 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 456 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
457 it->enabled = true; | |
458 enabled_plugin_exists = true; | |
415 } else { | 459 } else { |
460 it->enabled = false; | |
416 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 461 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
417 } | 462 } |
418 } | 463 } |
464 enabled_ = enable && enabled_plugin_exists; | |
Bernhard Bauer
2010/12/03 16:13:28
Nit: I think you can leave out the |enable &&| her
Jakob Kummerow
2010/12/06 18:21:12
Done.
I agree that |enable &&| is superfluous; I l
| |
465 LOG(WARNING) << "Group " << GetGroupName() << " is now enabled: " << enabled_; | |
Bernhard Bauer
2010/12/03 16:13:28
Nit: Remove logging plz :-)
Jakob Kummerow
2010/12/06 18:21:12
Done.
(Of course -- that was just a leftover I for
| |
419 } | 466 } |
OLD | NEW |