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/plugins/npapi/webplugininfo.h" | 5 #include "webkit/plugins/npapi/webplugininfo.h" |
6 | 6 |
| 7 #include "base/logging.h" |
| 8 #include "net/base/mime_util.h" |
| 9 |
7 namespace webkit { | 10 namespace webkit { |
8 namespace npapi { | 11 namespace npapi { |
9 | 12 |
10 WebPluginMimeType::WebPluginMimeType() {} | 13 WebPluginMimeType::WebPluginMimeType() {} |
11 | 14 |
12 WebPluginMimeType::~WebPluginMimeType() {} | 15 WebPluginMimeType::~WebPluginMimeType() {} |
13 | 16 |
14 WebPluginInfo::WebPluginInfo() : enabled(false) {} | 17 WebPluginInfo::WebPluginInfo() |
| 18 : enabled(false), |
| 19 reason(USER) { |
| 20 } |
15 | 21 |
16 WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs) | 22 WebPluginInfo::WebPluginInfo(const WebPluginInfo& rhs) |
17 : name(rhs.name), | 23 : name(rhs.name), |
18 path(rhs.path), | 24 path(rhs.path), |
19 version(rhs.version), | 25 version(rhs.version), |
20 desc(rhs.desc), | 26 desc(rhs.desc), |
21 mime_types(rhs.mime_types), | 27 mime_types(rhs.mime_types), |
22 enabled(rhs.enabled) { | 28 enabled(rhs.enabled), |
| 29 reason(rhs.reason) { |
23 } | 30 } |
24 | 31 |
25 WebPluginInfo::~WebPluginInfo() {} | 32 WebPluginInfo::~WebPluginInfo() {} |
26 | 33 |
27 WebPluginInfo& WebPluginInfo::operator=(const WebPluginInfo& rhs) { | 34 WebPluginInfo& WebPluginInfo::operator=(const WebPluginInfo& rhs) { |
28 name = rhs.name; | 35 name = rhs.name; |
29 path = rhs.path; | 36 path = rhs.path; |
30 version = rhs.version; | 37 version = rhs.version; |
31 desc = rhs.desc; | 38 desc = rhs.desc; |
32 mime_types = rhs.mime_types; | 39 mime_types = rhs.mime_types; |
33 enabled = rhs.enabled; | 40 enabled = rhs.enabled; |
| 41 reason = rhs.reason; |
34 return *this; | 42 return *this; |
35 } | 43 } |
36 | 44 |
37 WebPluginInfo::WebPluginInfo(const string16& fake_name, | 45 WebPluginInfo::WebPluginInfo(const string16& fake_name, |
38 const FilePath& fake_path, | 46 const FilePath& fake_path, |
39 const string16& fake_version, | 47 const string16& fake_version, |
40 const string16& fake_desc) | 48 const string16& fake_desc) |
41 : name(fake_name), | 49 : name(fake_name), |
42 path(fake_path), | 50 path(fake_path), |
43 version(fake_version), | 51 version(fake_version), |
44 desc(fake_desc), | 52 desc(fake_desc), |
45 mime_types(), | 53 mime_types(), |
46 enabled(true) { | 54 enabled(true), |
| 55 reason(USER) { |
| 56 } |
| 57 |
| 58 /* static */ |
| 59 bool WebPluginInfoUtils::Enable(WebPluginInfo* plugin, |
| 60 WebPluginInfo::Reason new_reason) { |
| 61 // If already enabled just upgrade the reason. |
| 62 if (plugin->enabled) { |
| 63 plugin->reason |= new_reason; |
| 64 return true; |
| 65 } else { |
| 66 // Only changeable if not managed. |
| 67 if (IsManaged(*plugin)) |
| 68 return false; |
| 69 plugin->enabled = true; |
| 70 plugin->reason = new_reason; |
| 71 } |
| 72 return true; |
| 73 } |
| 74 |
| 75 /* static */ |
| 76 bool WebPluginInfoUtils::Disable(WebPluginInfo* plugin, |
| 77 WebPluginInfo::Reason new_reason) { |
| 78 // If already disabled just upgrade the reason. |
| 79 if (!plugin->enabled) { |
| 80 plugin->reason |= new_reason; |
| 81 return true; |
| 82 } else { |
| 83 // Only changeable if not managed. |
| 84 if (IsManaged(*plugin)) |
| 85 return false; |
| 86 plugin->enabled = false; |
| 87 plugin->reason = new_reason; |
| 88 } |
| 89 return true; |
| 90 } |
| 91 |
| 92 /* static */ |
| 93 bool WebPluginInfoUtils::IsEnabled(const WebPluginInfo& plugin) { |
| 94 return plugin.enabled; |
| 95 } |
| 96 |
| 97 /* static */ |
| 98 bool WebPluginInfoUtils::IsManaged(const WebPluginInfo& plugin) { |
| 99 return (plugin.reason & WebPluginInfo::MANAGED) != 0; |
| 100 } |
| 101 |
| 102 /* static */ |
| 103 bool WebPluginInfoUtils::SupportsType(const WebPluginInfo& plugin, |
| 104 const std::string& mime_type, |
| 105 bool allow_wildcard) { |
| 106 // Webkit will ask for a plugin to handle empty mime types. |
| 107 if (mime_type.empty()) |
| 108 return false; |
| 109 |
| 110 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
| 111 const WebPluginMimeType& mime_info = plugin.mime_types[i]; |
| 112 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { |
| 113 if (!allow_wildcard && mime_info.mime_type == "*") |
| 114 continue; |
| 115 return true; |
| 116 } |
| 117 } |
| 118 return false; |
| 119 } |
| 120 |
| 121 /* static */ |
| 122 bool WebPluginInfoUtils::SupportsExtension(const WebPluginInfo& plugin, |
| 123 const std::string& extension, |
| 124 std::string* actual_mime_type) { |
| 125 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
| 126 const WebPluginMimeType& mime_type = plugin.mime_types[i]; |
| 127 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) { |
| 128 if (mime_type.file_extensions[j] == extension) { |
| 129 if (actual_mime_type) |
| 130 *actual_mime_type = mime_type.mime_type; |
| 131 return true; |
| 132 } |
| 133 } |
| 134 } |
| 135 |
| 136 return false; |
47 } | 137 } |
48 | 138 |
49 } // namespace npapi | 139 } // namespace npapi |
50 } // namespace webkit | 140 } // namespace webkit |
51 | |
OLD | NEW |