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 #include "chrome/browser/plugins/plugin_metadata.h" | 5 #include "chrome/browser/plugins/plugin_metadata.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "webkit/plugins/npapi/plugin_list.h" |
8 #include "webkit/plugins/npapi/plugin_utils.h" | 11 #include "webkit/plugins/npapi/plugin_utils.h" |
9 #include "webkit/plugins/webplugininfo.h" | 12 #include "webkit/plugins/webplugininfo.h" |
10 | 13 |
11 // static | 14 // static |
12 const char PluginMetadata::kAdobeReaderGroupName[] = "Adobe Reader"; | 15 const char PluginMetadata::kAdobeReaderGroupName[] = "Adobe Reader"; |
13 const char PluginMetadata::kJavaGroupName[] = "Java(TM)"; | 16 const char PluginMetadata::kJavaGroupName[] = "Java(TM)"; |
14 const char PluginMetadata::kQuickTimeGroupName[] = "QuickTime Player"; | 17 const char PluginMetadata::kQuickTimeGroupName[] = "QuickTime Player"; |
15 const char PluginMetadata::kShockwaveGroupName[] = "Adobe Shockwave Player"; | 18 const char PluginMetadata::kShockwaveGroupName[] = "Adobe Shockwave Player"; |
16 const char PluginMetadata::kRealPlayerGroupName[] = "RealPlayer"; | 19 const char PluginMetadata::kRealPlayerGroupName[] = "RealPlayer"; |
17 const char PluginMetadata::kSilverlightGroupName[] = "Silverlight"; | 20 const char PluginMetadata::kSilverlightGroupName[] = "Silverlight"; |
18 const char PluginMetadata::kWindowsMediaPlayerGroupName[] = | 21 const char PluginMetadata::kWindowsMediaPlayerGroupName[] = |
19 "Windows Media Player"; | 22 "Windows Media Player"; |
20 | 23 |
21 PluginMetadata::PluginMetadata(const std::string& identifier, | 24 PluginMetadata::PluginMetadata(const std::string& identifier, |
22 const string16& name, | 25 const string16& name, |
23 bool url_for_display, | 26 bool url_for_display, |
24 const GURL& plugin_url, | 27 const GURL& plugin_url, |
25 const GURL& help_url, | 28 const GURL& help_url, |
26 const string16& group_name_matcher) | 29 const string16& group_name_matcher, |
| 30 const std::string& language) |
27 : identifier_(identifier), | 31 : identifier_(identifier), |
28 name_(name), | 32 name_(name), |
29 group_name_matcher_(group_name_matcher), | 33 group_name_matcher_(group_name_matcher), |
30 url_for_display_(url_for_display), | 34 url_for_display_(url_for_display), |
31 plugin_url_(plugin_url), | 35 plugin_url_(plugin_url), |
32 help_url_(help_url) { | 36 help_url_(help_url), |
| 37 language_(language) { |
33 } | 38 } |
34 | 39 |
35 PluginMetadata::~PluginMetadata() { | 40 PluginMetadata::~PluginMetadata() { |
36 } | 41 } |
37 | 42 |
38 void PluginMetadata::AddVersion(const Version& version, | 43 void PluginMetadata::AddVersion(const Version& version, |
39 SecurityStatus status) { | 44 SecurityStatus status) { |
40 DCHECK(versions_.find(version) == versions_.end()); | 45 DCHECK(versions_.find(version) == versions_.end()); |
41 versions_[version] = status; | 46 versions_[version] = status; |
42 } | 47 } |
43 | 48 |
| 49 void PluginMetadata::AddMimeType(const std::string& mime_type) { |
| 50 all_mime_types_.push_back(mime_type); |
| 51 } |
| 52 |
| 53 void PluginMetadata::AddMatchingMimeType(const std::string& mime_type) { |
| 54 matching_mime_types_.push_back(mime_type); |
| 55 } |
| 56 |
| 57 bool PluginMetadata::HasMimeType(const std::string& mime_type) const { |
| 58 return std::find(all_mime_types_.begin(), all_mime_types_.end(), mime_type) != |
| 59 all_mime_types_.end(); |
| 60 } |
| 61 |
44 bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin) { | 62 bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin) { |
| 63 using webkit::npapi::PluginList; |
| 64 |
| 65 for (size_t i = 0; i < matching_mime_types_.size(); ++i) { |
| 66 // To have a match, every one of the |matching_mime_types_| |
| 67 // must be handled by the plug-in. |
| 68 if (!PluginList::SupportsType(plugin, matching_mime_types_[i], false)) |
| 69 return false; |
| 70 } |
| 71 |
45 return plugin.name.find(group_name_matcher_) != string16::npos; | 72 return plugin.name.find(group_name_matcher_) != string16::npos; |
46 } | 73 } |
47 | 74 |
48 // static | 75 // static |
49 bool PluginMetadata::ParseSecurityStatus( | 76 bool PluginMetadata::ParseSecurityStatus( |
50 const std::string& status_str, | 77 const std::string& status_str, |
51 PluginMetadata::SecurityStatus* status) { | 78 PluginMetadata::SecurityStatus* status) { |
52 if (status_str == "up_to_date") | 79 if (status_str == "up_to_date") |
53 *status = SECURITY_STATUS_UP_TO_DATE; | 80 *status = SECURITY_STATUS_UP_TO_DATE; |
54 else if (status_str == "out_of_date") | 81 else if (status_str == "out_of_date") |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Keep versions ordered by newest (biggest) first. | 120 // Keep versions ordered by newest (biggest) first. |
94 return lhs.CompareTo(rhs) > 0; | 121 return lhs.CompareTo(rhs) > 0; |
95 } | 122 } |
96 | 123 |
97 scoped_ptr<PluginMetadata> PluginMetadata::Clone() const { | 124 scoped_ptr<PluginMetadata> PluginMetadata::Clone() const { |
98 PluginMetadata* copy = new PluginMetadata(identifier_, | 125 PluginMetadata* copy = new PluginMetadata(identifier_, |
99 name_, | 126 name_, |
100 url_for_display_, | 127 url_for_display_, |
101 plugin_url_, | 128 plugin_url_, |
102 help_url_, | 129 help_url_, |
103 group_name_matcher_); | 130 group_name_matcher_, |
| 131 language_); |
104 copy->versions_ = versions_; | 132 copy->versions_ = versions_; |
105 return make_scoped_ptr(copy); | 133 return make_scoped_ptr(copy); |
106 } | 134 } |
OLD | NEW |