Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
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 | |
Lei Zhang | d8c5318 | 2019-02-06 22:24:39 | [diff] [blame] | 5 | #include "content/browser/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 | |
Peter Kasting | 1557e5f | 2025-01-28 01:14:08 | [diff] [blame] | 9 | #include <algorithm> |
Md Hasibul Hasan | a963a934 | 2024-04-03 10:15:14 | [diff] [blame] | 10 | #include <string_view> |
| 11 | |
Hans Wennborg | 0917de89 | 2020-04-28 20:21:15 | [diff] [blame] | 12 | #include "base/check.h" |
[email protected] | 3c0c0bf5 | 2010-06-25 06:05:09 | [diff] [blame] | 13 | #include "base/command_line.h" |
Lei Zhang | de19767 | 2021-04-29 08:11:24 | [diff] [blame] | 14 | #include "base/containers/contains.h" |
[email protected] | 1953711 | 2009-01-21 19:38:14 | [diff] [blame] | 15 | #include "base/lazy_instance.h" |
[email protected] | d778e042 | 2013-03-06 18:10:22 | [diff] [blame] | 16 | #include "base/strings/string_split.h" |
[email protected] | f63582d | 2013-06-11 22:52:54 | [diff] [blame] | 17 | #include "base/strings/string_util.h" |
[email protected] | 13ac5353 | 2013-03-30 00:27:00 | [diff] [blame] | 18 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 19 | #include "base/strings/utf_string_conversions.h" |
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 20 | #include "build/build_config.h" |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 21 | #include "content/public/browser/browser_thread.h" |
[email protected] | 1bbbc49 | 2013-08-09 00:36:15 | [diff] [blame] | 22 | #include "content/public/common/content_switches.h" |
[email protected] | b734450 | 2009-01-12 19:43:44 | [diff] [blame] | 23 | #include "net/base/mime_util.h" |
[email protected] | ad67777 | 2013-06-29 14:18:38 | [diff] [blame] | 24 | #include "url/gurl.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 25 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 26 | namespace content { |
| 27 | |
| 28 | namespace { |
[email protected] | 0b30017 | 2012-09-27 16:11:52 | [diff] [blame] | 29 | |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 30 | base::LazyInstance<PluginList>::DestructorAtExit g_singleton = |
| 31 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 123a0496 | 2011-11-03 15:43:01 | [diff] [blame] | 32 | |
Lei Zhang | a2eb1878 | 2018-08-15 18:09:21 | [diff] [blame] | 33 | // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
| 34 | // lower case. |
| 35 | bool SupportsType(const WebPluginInfo& plugin, |
| 36 | const std::string& mime_type, |
| 37 | bool allow_wildcard) { |
| 38 | // Webkit will ask for a plugin to handle empty mime types. |
| 39 | if (mime_type.empty()) |
| 40 | return false; |
| 41 | |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 42 | for (const WebPluginMimeType& mime_info : plugin.mime_types) { |
Lei Zhang | a2eb1878 | 2018-08-15 18:09:21 | [diff] [blame] | 43 | if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 44 | if (allow_wildcard || mime_info.mime_type != "*") |
| 45 | return true; |
Lei Zhang | a2eb1878 | 2018-08-15 18:09:21 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | // Returns true if the given plugin supports a given file extension. |
| 52 | // |extension| should be all lower case. |actual_mime_type| will be set to the |
| 53 | // MIME type if found. The MIME type which corresponds to the extension is |
| 54 | // optionally returned back. |
| 55 | bool SupportsExtension(const WebPluginInfo& plugin, |
| 56 | const std::string& extension, |
| 57 | std::string* actual_mime_type) { |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 58 | for (const WebPluginMimeType& mime_type : plugin.mime_types) { |
| 59 | for (const std::string& file_extension : mime_type.file_extensions) { |
| 60 | if (file_extension == extension) { |
Lei Zhang | a2eb1878 | 2018-08-15 18:09:21 | [diff] [blame] | 61 | *actual_mime_type = mime_type.mime_type; |
| 62 | return true; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
[email protected] | 3b91edbe | 2012-09-27 22:49:23 | [diff] [blame] | 69 | } // namespace |
[email protected] | 123a0496 | 2011-11-03 15:43:01 | [diff] [blame] | 70 | |
[email protected] | 1953711 | 2009-01-21 19:38:14 | [diff] [blame] | 71 | // static |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 72 | PluginList* PluginList::Singleton() { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 73 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 74 | return g_singleton.Pointer(); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 77 | void PluginList::RefreshPlugins() { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 78 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 79 | loading_state_ = LOADING_STATE_NEEDS_REFRESH; |
[email protected] | 367230c5 | 2009-02-21 01:44:30 | [diff] [blame] | 80 | } |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 81 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 82 | void PluginList::RegisterInternalPlugin(const WebPluginInfo& info, |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 83 | bool add_at_beginning) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 84 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 85 | |
[email protected] | fee3a98b | 2013-07-18 18:12:48 | [diff] [blame] | 86 | internal_plugins_.push_back(info); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 87 | if (add_at_beginning) { |
| 88 | // Newer registrations go earlier in the list so they can override the MIME |
| 89 | // types of older registrations. |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 90 | extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 91 | } else { |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 92 | extra_plugin_paths_.push_back(info.path); |
[email protected] | 8ca37f4 | 2011-11-02 16:03:41 | [diff] [blame] | 93 | } |
[email protected] | f99c73ad | 2011-01-11 00:43:44 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 96 | void PluginList::UnregisterInternalPlugin(const base::FilePath& path) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 97 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 98 | |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 99 | bool found = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 100 | for (size_t i = 0; i < internal_plugins_.size(); i++) { |
[email protected] | fee3a98b | 2013-07-18 18:12:48 | [diff] [blame] | 101 | if (internal_plugins_[i].path == path) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 102 | internal_plugins_.erase(internal_plugins_.begin() + i); |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 103 | found = true; |
| 104 | break; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 105 | } |
| 106 | } |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 107 | DCHECK(found); |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 108 | RemoveExtraPluginPath(path); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 111 | void PluginList::GetInternalPlugins( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 112 | std::vector<WebPluginInfo>* internal_plugins) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 113 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 114 | |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 115 | for (const auto& plugin : internal_plugins_) |
| 116 | internal_plugins->push_back(plugin); |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 119 | bool PluginList::ReadPluginInfo(const base::FilePath& filename, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 120 | WebPluginInfo* info) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 121 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 122 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 123 | for (const auto& plugin : internal_plugins_) { |
| 124 | if (filename == plugin.path) { |
| 125 | *info = plugin; |
| 126 | return true; |
[email protected] | 8ff2609 | 2009-01-29 01:53:24 | [diff] [blame] | 127 | } |
| 128 | } |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 129 | return false; |
[email protected] | 8ff2609 | 2009-01-29 01:53:24 | [diff] [blame] | 130 | } |
| 131 | |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 132 | PluginList::PluginList() { |
| 133 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 134 | } |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 135 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 136 | bool PluginList::PrepareForPluginLoading() { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 137 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 138 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 139 | if (loading_state_ == LOADING_STATE_UP_TO_DATE) |
| 140 | return false; |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 141 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 142 | loading_state_ = LOADING_STATE_REFRESHING; |
| 143 | return true; |
| 144 | } |
| 145 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 146 | void PluginList::LoadPlugins() { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 147 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 148 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 149 | if (!PrepareForPluginLoading()) |
| 150 | return; |
[email protected] | a466a0c | 2010-10-02 00:42:39 | [diff] [blame] | 151 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 152 | std::vector<WebPluginInfo> new_plugins; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 153 | std::vector<base::FilePath> plugin_paths; |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 154 | GetPluginPathsToLoad(&plugin_paths); |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 155 | |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 156 | for (const base::FilePath& path : plugin_paths) { |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 157 | WebPluginInfo plugin_info; |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 158 | LoadPluginIntoPluginList(path, &new_plugins, &plugin_info); |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 159 | } |
[email protected] | 1134a00 | 2010-10-08 08:03:14 | [diff] [blame] | 160 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 161 | SetPlugins(new_plugins); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 162 | } |
| 163 | |
Lei Zhang | d8c5318 | 2019-02-06 22:24:39 | [diff] [blame] | 164 | bool PluginList::LoadPluginIntoPluginList(const base::FilePath& path, |
| 165 | std::vector<WebPluginInfo>* plugins, |
| 166 | WebPluginInfo* plugin_info) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 167 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 168 | |
[email protected] | fee3a98b | 2013-07-18 18:12:48 | [diff] [blame] | 169 | if (!ReadPluginInfo(path, plugin_info)) |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 170 | return false; |
| 171 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 172 | // TODO(piman): Do we still need this after NPAPI removal? |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 173 | for (const content::WebPluginMimeType& mime_type : plugin_info->mime_types) { |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 174 | // TODO: don't load global handlers for now. |
| 175 | // WebKit hands to the Plugin before it tries |
| 176 | // to handle mimeTypes on its own. |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 177 | if (mime_type.mime_type == "*") |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 178 | return false; |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 179 | } |
| 180 | plugins->push_back(*plugin_info); |
| 181 | return true; |
| 182 | } |
| 183 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 184 | void PluginList::GetPluginPathsToLoad( |
| 185 | std::vector<base::FilePath>* plugin_paths) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 186 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 187 | |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 188 | for (const base::FilePath& path : extra_plugin_paths_) { |
Jan Wilken Dörrie | 531be7ca | 2019-06-07 10:05:57 | [diff] [blame] | 189 | if (base::Contains(*plugin_paths, path)) |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 190 | continue; |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 191 | plugin_paths->push_back(path); |
| 192 | } |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 193 | } |
| 194 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 195 | void PluginList::SetPlugins(const std::vector<WebPluginInfo>& plugins) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 196 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 197 | |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 198 | // 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] | 199 | // up to date. |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 200 | if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) |
| 201 | loading_state_ = LOADING_STATE_UP_TO_DATE; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 202 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 203 | plugins_list_ = plugins; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 204 | } |
| 205 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 206 | void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 207 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 208 | LoadPlugins(); |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 209 | plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 210 | } |
| 211 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 212 | bool PluginList::GetPluginsNoRefresh(std::vector<WebPluginInfo>* plugins) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 213 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 214 | plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
| 215 | |
[email protected] | 480c7cc | 2012-06-29 17:38:44 | [diff] [blame] | 216 | return loading_state_ == LOADING_STATE_UP_TO_DATE; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 217 | } |
| 218 | |
Lei Zhang | c923379e | 2019-02-07 18:13:08 | [diff] [blame] | 219 | bool PluginList::GetPluginInfoArray( |
[email protected] | 9bcdced7 | 2010-12-07 20:51:36 | [diff] [blame] | 220 | const GURL& url, |
| 221 | const std::string& mime_type, |
| 222 | bool allow_wildcard, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 223 | std::vector<WebPluginInfo>* info, |
[email protected] | 9bcdced7 | 2010-12-07 20:51:36 | [diff] [blame] | 224 | std::vector<std::string>* actual_mime_types) { |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 225 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
brettw | 8e2106d | 2015-08-11 19:30:22 | [diff] [blame] | 226 | DCHECK(mime_type == base::ToLowerASCII(mime_type)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 227 | DCHECK(info); |
| 228 | |
Lei Zhang | c923379e | 2019-02-07 18:13:08 | [diff] [blame] | 229 | bool is_stale = loading_state_ != LOADING_STATE_UP_TO_DATE; |
[email protected] | f4d43cb | 2013-10-28 20:53:07 | [diff] [blame] | 230 | info->clear(); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 231 | if (actual_mime_types) |
| 232 | actual_mime_types->clear(); |
| 233 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 234 | std::set<base::FilePath> visited_plugins; |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 235 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 236 | // Add in plugins by mime type. |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 237 | for (const WebPluginInfo& plugin : plugins_list_) { |
| 238 | if (SupportsType(plugin, mime_type, allow_wildcard)) { |
| 239 | const base::FilePath& path = plugin.path; |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 240 | if (visited_plugins.insert(path).second) { |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 241 | info->push_back(plugin); |
[email protected] | 68b63bc | 2012-08-20 22:14:03 | [diff] [blame] | 242 | if (actual_mime_types) |
| 243 | actual_mime_types->push_back(mime_type); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 248 | // Add in plugins by url. |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 249 | // We do not permit URL-sniff based plugin MIME type overrides aside from |
[email protected] | cafe0d0 | 2013-07-23 15:16:20 | [diff] [blame] | 250 | // the case where the "type" was initially missing. |
| 251 | // We collected stats to determine this approach isn't a major compat issue, |
| 252 | // and we defend against content confusion attacks in various cases, such |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 253 | // as when the user doesn't have the Flash plugin enabled. |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 254 | std::string path = url.path(); |
| 255 | std::string::size_type last_dot = path.rfind('.'); |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 256 | if (last_dot == std::string::npos || !mime_type.empty()) |
Lei Zhang | c923379e | 2019-02-07 18:13:08 | [diff] [blame] | 257 | return is_stale; |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 258 | |
| 259 | std::string extension = |
Md Hasibul Hasan | a963a934 | 2024-04-03 10:15:14 | [diff] [blame] | 260 | base::ToLowerASCII(std::string_view(path).substr(last_dot + 1)); |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 261 | std::string actual_mime_type; |
| 262 | for (const WebPluginInfo& plugin : plugins_list_) { |
| 263 | if (SupportsExtension(plugin, extension, &actual_mime_type)) { |
| 264 | base::FilePath plugin_path = plugin.path; |
| 265 | if (visited_plugins.insert(plugin_path).second) { |
| 266 | info->push_back(plugin); |
| 267 | if (actual_mime_types) |
| 268 | actual_mime_types->push_back(actual_mime_type); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | } |
Lei Zhang | c923379e | 2019-02-07 18:13:08 | [diff] [blame] | 272 | return is_stale; |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 273 | } |
| 274 | |
Lei Zhang | 8403fa6 | 2022-10-12 20:15:26 | [diff] [blame] | 275 | void PluginList::RemoveExtraPluginPath(const base::FilePath& plugin_path) { |
| 276 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Peter Kasting | ff5db669 | 2022-10-06 18:57:24 | [diff] [blame] | 277 | std::vector<base::FilePath>::iterator it = |
Peter Kasting | 1557e5f | 2025-01-28 01:14:08 | [diff] [blame] | 278 | std::ranges::find(extra_plugin_paths_, plugin_path); |
[email protected] | 797d9a6 | 2013-09-13 23:36:07 | [diff] [blame] | 279 | if (it != extra_plugin_paths_.end()) |
| 280 | extra_plugin_paths_.erase(it); |
| 281 | } |
| 282 | |
Lei Zhang | 41da8785 | 2019-02-07 00:45:30 | [diff] [blame] | 283 | PluginList::~PluginList() = default; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 284 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 285 | } // namespace content |