[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 4 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 5 | #include "content/common/plugin_list.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 6 | |
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | |
[email protected] | 3c0c0bf5 | 2010-06-25 06:05:09 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 1953711 | 2009-01-21 19:38:14 | [diff] [blame] | 12 | #include "base/lazy_instance.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 13 | #include "base/logging.h" |
[email protected] | d778e042 | 2013-03-06 18:10:22 | [diff] [blame] | 14 | #include "base/strings/string_split.h" |
[email protected] | f63582d | 2013-06-11 22:52:54 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
[email protected] | 13ac5353 | 2013-03-30 00:27:00 | [diff] [blame] | 16 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 18 | #include "build/build_config.h" |
[email protected] | 1bbbc49 | 2013-08-09 00:36:15 | [diff] [blame] | 19 | #include "content/public/common/content_switches.h" |
[email protected] | b734450 | 2009-01-12 19:43:44 | [diff] [blame] | 20 | #include "net/base/mime_util.h" |
[email protected] | ad67777 | 2013-06-29 14:18:38 | [diff] [blame] | 21 | #include "url/gurl.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 22 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 23 | namespace content { |
| 24 | |
| 25 | namespace { |
[email protected] | 0b30017 | 2012-09-27 16:11:52 | [diff] [blame] | 26 | |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 27 | base::LazyInstance<PluginList>::DestructorAtExit g_singleton = |
| 28 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 123a0496 | 2011-11-03 15:43:01 | [diff] [blame] | 29 | |
[email protected] | 3b91edbe | 2012-09-27 22:49:23 | [diff] [blame] | 30 | } // namespace |
[email protected] | 123a0496 | 2011-11-03 15:43:01 | [diff] [blame] | 31 | |
[email protected] | 1953711 | 2009-01-21 19:38:14 | [diff] [blame] | 32 | // static |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 33 | PluginList* PluginList::Singleton() { |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 34 | return g_singleton.Pointer(); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 37 | void PluginList::RefreshPlugins() { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 38 | base::AutoLock lock(lock_); |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 39 | loading_state_ = LOADING_STATE_NEEDS_REFRESH; |
[email protected] | 367230c5 | 2009-02-21 01:44:30 | [diff] [blame] | 40 | } |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 41 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 42 | void PluginList::RegisterInternalPlugin(const WebPluginInfo& info, |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 43 | bool add_at_beginning) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 44 | base::AutoLock lock(lock_); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 45 | |
[email protected] | fee3a98 | 2013-07-18 18:12:48 | [diff] [blame] | 46 | internal_plugins_.push_back(info); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 47 | if (add_at_beginning) { |
| 48 | // Newer registrations go earlier in the list so they can override the MIME |
| 49 | // types of older registrations. |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 50 | extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 51 | } else { |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 52 | extra_plugin_paths_.push_back(info.path); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 53 | } |
[email protected] | f99c73ad | 2011-01-11 00:43:44 | [diff] [blame] | 54 | } |
| 55 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 56 | void PluginList::UnregisterInternalPlugin(const base::FilePath& path) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 57 | base::AutoLock lock(lock_); |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 58 | bool found = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 59 | for (size_t i = 0; i < internal_plugins_.size(); i++) { |
[email protected] | fee3a98 | 2013-07-18 18:12:48 | [diff] [blame] | 60 | if (internal_plugins_[i].path == path) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 61 | internal_plugins_.erase(internal_plugins_.begin() + i); |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 62 | found = true; |
| 63 | break; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 64 | } |
| 65 | } |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 66 | DCHECK(found); |
| 67 | RemoveExtraPluginPathLocked(path); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 70 | void PluginList::GetInternalPlugins( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 71 | std::vector<WebPluginInfo>* internal_plugins) { |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 72 | base::AutoLock lock(lock_); |
| 73 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 74 | for (std::vector<WebPluginInfo>::iterator it = internal_plugins_.begin(); |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 75 | it != internal_plugins_.end(); |
| 76 | ++it) { |
[email protected] | fee3a98 | 2013-07-18 18:12:48 | [diff] [blame] | 77 | internal_plugins->push_back(*it); |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 81 | bool PluginList::ReadPluginInfo(const base::FilePath& filename, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 82 | WebPluginInfo* info) { |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 83 | base::AutoLock lock(lock_); |
| 84 | for (const auto& plugin : internal_plugins_) { |
| 85 | if (filename == plugin.path) { |
| 86 | *info = plugin; |
| 87 | return true; |
[email protected] | 8ff2609 | 2009-01-29 01:53:24 | [diff] [blame] | 88 | } |
| 89 | } |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 90 | return false; |
[email protected] | 8ff2609 | 2009-01-29 01:53:24 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 93 | PluginList::PluginList() |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 94 | : loading_state_(LOADING_STATE_NEEDS_REFRESH) { |
[email protected] | b83ff22 | 2011-01-24 17:37:12 | [diff] [blame] | 95 | } |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 96 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 97 | bool PluginList::PrepareForPluginLoading() { |
| 98 | base::AutoLock lock(lock_); |
| 99 | if (loading_state_ == LOADING_STATE_UP_TO_DATE) |
| 100 | return false; |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 101 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 102 | loading_state_ = LOADING_STATE_REFRESHING; |
| 103 | return true; |
| 104 | } |
| 105 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 106 | void PluginList::LoadPlugins() { |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 107 | if (!PrepareForPluginLoading()) |
| 108 | return; |
[email protected] | a466a0c | 2010-10-02 00:42:39 | [diff] [blame] | 109 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 110 | std::vector<WebPluginInfo> new_plugins; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 111 | base::Closure will_load_callback; |
| 112 | { |
| 113 | base::AutoLock lock(lock_); |
| 114 | will_load_callback = will_load_plugins_callback_; |
| 115 | } |
| 116 | if (!will_load_callback.is_null()) |
| 117 | will_load_callback.Run(); |
| 118 | |
| 119 | std::vector<base::FilePath> plugin_paths; |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 120 | GetPluginPathsToLoad(&plugin_paths); |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 121 | |
| 122 | for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); |
| 123 | it != plugin_paths.end(); |
| 124 | ++it) { |
| 125 | WebPluginInfo plugin_info; |
| 126 | LoadPluginIntoPluginList(*it, &new_plugins, &plugin_info); |
| 127 | } |
[email protected] | 1134a00 | 2010-10-08 08:03:14 | [diff] [blame] | 128 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 129 | SetPlugins(new_plugins); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 132 | bool PluginList::LoadPluginIntoPluginList( |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 133 | const base::FilePath& path, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 134 | std::vector<WebPluginInfo>* plugins, |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 135 | WebPluginInfo* plugin_info) { |
[email protected] | fee3a98 | 2013-07-18 18:12:48 | [diff] [blame] | 136 | if (!ReadPluginInfo(path, plugin_info)) |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 137 | return false; |
| 138 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 139 | // TODO(piman): Do we still need this after NPAPI removal? |
| 140 | for (size_t i = 0; i < plugin_info->mime_types.size(); ++i) { |
| 141 | // TODO: don't load global handlers for now. |
| 142 | // WebKit hands to the Plugin before it tries |
| 143 | // to handle mimeTypes on its own. |
| 144 | const std::string &mime_type = plugin_info->mime_types[i].mime_type; |
| 145 | if (mime_type == "*") |
| 146 | return false; |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 147 | } |
| 148 | plugins->push_back(*plugin_info); |
| 149 | return true; |
| 150 | } |
| 151 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 152 | void PluginList::GetPluginPathsToLoad( |
| 153 | std::vector<base::FilePath>* plugin_paths) { |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 154 | // Don't want to hold the lock while loading new plugins, so we don't block |
| 155 | // other methods if they're called on other threads. |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 156 | std::vector<base::FilePath> extra_plugin_paths; |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 157 | { |
| 158 | base::AutoLock lock(lock_); |
| 159 | extra_plugin_paths = extra_plugin_paths_; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 160 | } |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 161 | |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 162 | for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 163 | const base::FilePath& path = extra_plugin_paths[i]; |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 164 | if (std::find(plugin_paths->begin(), plugin_paths->end(), path) != |
| 165 | plugin_paths->end()) { |
| 166 | continue; |
| 167 | } |
| 168 | plugin_paths->push_back(path); |
| 169 | } |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 172 | void PluginList::SetPlugins(const std::vector<WebPluginInfo>& plugins) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 173 | base::AutoLock lock(lock_); |
| 174 | |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 175 | // If we haven't been invalidated in the mean time, mark the plugin list as |
thakis | 3e861de | 2016-06-14 14:24:01 | [diff] [blame] | 176 | // up to date. |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 177 | if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) |
| 178 | loading_state_ = LOADING_STATE_UP_TO_DATE; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 179 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 180 | plugins_list_ = plugins; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { |
| 184 | base::AutoLock lock(lock_); |
| 185 | will_load_plugins_callback_ = callback; |
| 186 | } |
| 187 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 188 | void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) { |
| 189 | LoadPlugins(); |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 190 | base::AutoLock lock(lock_); |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 191 | plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 194 | bool PluginList::GetPluginsNoRefresh(std::vector<WebPluginInfo>* plugins) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 195 | base::AutoLock lock(lock_); |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 196 | plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
| 197 | |
[email protected] | 480c7cc | 2012-06-29 17:38:44 | [diff] [blame] | 198 | return loading_state_ == LOADING_STATE_UP_TO_DATE; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | 9bcdced7 | 2010-12-07 20:51:36 | [diff] [blame] | 201 | void PluginList::GetPluginInfoArray( |
| 202 | const GURL& url, |
| 203 | const std::string& mime_type, |
| 204 | bool allow_wildcard, |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 205 | bool* use_stale, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 206 | std::vector<WebPluginInfo>* info, |
[email protected] | 9bcdced7 | 2010-12-07 20:51:36 | [diff] [blame] | 207 | std::vector<std::string>* actual_mime_types) { |
brettw | 8e2106d | 2015-08-11 19:30:22 | [diff] [blame] | 208 | DCHECK(mime_type == base::ToLowerASCII(mime_type)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 209 | DCHECK(info); |
| 210 | |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 211 | if (!use_stale) |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 212 | LoadPlugins(); |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 213 | base::AutoLock lock(lock_); |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 214 | if (use_stale) |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 215 | *use_stale = (loading_state_ != LOADING_STATE_UP_TO_DATE); |
[email protected] | f4d43cb | 2013-10-28 20:53:07 | [diff] [blame] | 216 | info->clear(); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 217 | if (actual_mime_types) |
| 218 | actual_mime_types->clear(); |
| 219 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 220 | std::set<base::FilePath> visited_plugins; |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 221 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 222 | // Add in plugins by mime type. |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 223 | for (size_t i = 0; i < plugins_list_.size(); ++i) { |
| 224 | if (SupportsType(plugins_list_[i], mime_type, allow_wildcard)) { |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 225 | base::FilePath path = plugins_list_[i].path; |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 226 | if (visited_plugins.insert(path).second) { |
[email protected] | f4d43cb | 2013-10-28 20:53:07 | [diff] [blame] | 227 | info->push_back(plugins_list_[i]); |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 228 | if (actual_mime_types) |
| 229 | actual_mime_types->push_back(mime_type); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 234 | // Add in plugins by url. |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 235 | // We do not permit URL-sniff based plugin MIME type overrides aside from |
[email protected] | cafe0d0 | 2013-07-23 15:16:20 | [diff] [blame] | 236 | // the case where the "type" was initially missing. |
| 237 | // We collected stats to determine this approach isn't a major compat issue, |
| 238 | // and we defend against content confusion attacks in various cases, such |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 239 | // as when the user doesn't have the Flash plugin enabled. |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 240 | std::string path = url.path(); |
| 241 | std::string::size_type last_dot = path.rfind('.'); |
[email protected] | cafe0d0 | 2013-07-23 15:16:20 | [diff] [blame] | 242 | if (last_dot != std::string::npos && mime_type.empty()) { |
[email protected] | cb1f4ac | 2014-08-07 16:55:42 | [diff] [blame] | 243 | std::string extension = |
brettw | 8e2106d | 2015-08-11 19:30:22 | [diff] [blame] | 244 | base::ToLowerASCII(base::StringPiece(path).substr(last_dot + 1)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 245 | std::string actual_mime_type; |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 246 | for (size_t i = 0; i < plugins_list_.size(); ++i) { |
| 247 | if (SupportsExtension(plugins_list_[i], extension, &actual_mime_type)) { |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 248 | base::FilePath path = plugins_list_[i].path; |
[email protected] | cafe0d0 | 2013-07-23 15:16:20 | [diff] [blame] | 249 | if (visited_plugins.insert(path).second) { |
[email protected] | f4d43cb | 2013-10-28 20:53:07 | [diff] [blame] | 250 | info->push_back(plugins_list_[i]); |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 251 | if (actual_mime_types) |
| 252 | actual_mime_types->push_back(actual_mime_type); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 259 | bool PluginList::SupportsType(const WebPluginInfo& plugin, |
[email protected] | b83ff22 | 2011-01-24 17:37:12 | [diff] [blame] | 260 | const std::string& mime_type, |
| 261 | bool allow_wildcard) { |
| 262 | // Webkit will ask for a plugin to handle empty mime types. |
| 263 | if (mime_type.empty()) |
| 264 | return false; |
| 265 | |
| 266 | for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 267 | const WebPluginMimeType& mime_info = plugin.mime_types[i]; |
[email protected] | b83ff22 | 2011-01-24 17:37:12 | [diff] [blame] | 268 | if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { |
| 269 | if (!allow_wildcard && mime_info.mime_type == "*") |
| 270 | continue; |
| 271 | return true; |
| 272 | } |
| 273 | } |
| 274 | return false; |
| 275 | } |
| 276 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 277 | bool PluginList::SupportsExtension(const WebPluginInfo& plugin, |
[email protected] | b83ff22 | 2011-01-24 17:37:12 | [diff] [blame] | 278 | const std::string& extension, |
| 279 | std::string* actual_mime_type) { |
| 280 | for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 281 | const WebPluginMimeType& mime_type = plugin.mime_types[i]; |
[email protected] | b83ff22 | 2011-01-24 17:37:12 | [diff] [blame] | 282 | for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) { |
| 283 | if (mime_type.file_extensions[j] == extension) { |
| 284 | if (actual_mime_type) |
| 285 | *actual_mime_type = mime_type.mime_type; |
| 286 | return true; |
[email protected] | a466a0c | 2010-10-02 00:42:39 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | } |
[email protected] | b83ff22 | 2011-01-24 17:37:12 | [diff] [blame] | 290 | return false; |
[email protected] | a466a0c | 2010-10-02 00:42:39 | [diff] [blame] | 291 | } |
| 292 | |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 293 | void PluginList::RemoveExtraPluginPathLocked( |
| 294 | const base::FilePath& plugin_path) { |
| 295 | lock_.AssertAcquired(); |
| 296 | std::vector<base::FilePath>::iterator it = |
| 297 | std::find(extra_plugin_paths_.begin(), extra_plugin_paths_.end(), |
| 298 | plugin_path); |
| 299 | if (it != extra_plugin_paths_.end()) |
| 300 | extra_plugin_paths_.erase(it); |
| 301 | } |
| 302 | |
[email protected] | a466a0c | 2010-10-02 00:42:39 | [diff] [blame] | 303 | PluginList::~PluginList() { |
| 304 | } |
| 305 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 306 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 307 | } // namespace content |