| 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 "content/common/plugin_list.h" | 5 #include "content/common/plugin_list.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "net/base/mime_util.h" | 16 #include "net/base/mime_util.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 #include "webkit/plugins/plugin_switches.h" | 18 #include "webkit/plugins/plugin_switches.h" |
| 19 | 19 |
| 20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 21 #include "content/common/plugin_constants_win.h" | 21 #include "content/common/plugin_constants_win.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 using webkit::WebPluginInfo; | |
| 25 using webkit::WebPluginMimeType; | |
| 26 | |
| 27 namespace content { | 24 namespace content { |
| 28 | 25 |
| 29 namespace { | 26 namespace { |
| 30 | 27 |
| 31 const char kApplicationOctetStream[] = "application/octet-stream"; | 28 const char kApplicationOctetStream[] = "application/octet-stream"; |
| 32 | 29 |
| 33 base::LazyInstance<PluginList> g_singleton = LAZY_INSTANCE_INITIALIZER; | 30 base::LazyInstance<PluginList> g_singleton = LAZY_INSTANCE_INITIALIZER; |
| 34 | 31 |
| 35 bool AllowMimeTypeMismatch(const std::string& orig_mime_type, | 32 bool AllowMimeTypeMismatch(const std::string& orig_mime_type, |
| 36 const std::string& actual_mime_type) { | 33 const std::string& actual_mime_type) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 90 } |
| 94 | 91 |
| 95 void PluginList::AddExtraPluginDir(const base::FilePath& plugin_dir) { | 92 void PluginList::AddExtraPluginDir(const base::FilePath& plugin_dir) { |
| 96 // Chrome OS only loads plugins from /opt/google/chrome/plugins. | 93 // Chrome OS only loads plugins from /opt/google/chrome/plugins. |
| 97 #if !defined(OS_CHROMEOS) | 94 #if !defined(OS_CHROMEOS) |
| 98 base::AutoLock lock(lock_); | 95 base::AutoLock lock(lock_); |
| 99 extra_plugin_dirs_.push_back(plugin_dir); | 96 extra_plugin_dirs_.push_back(plugin_dir); |
| 100 #endif | 97 #endif |
| 101 } | 98 } |
| 102 | 99 |
| 103 void PluginList::RegisterInternalPlugin(const webkit::WebPluginInfo& info, | 100 void PluginList::RegisterInternalPlugin(const WebPluginInfo& info, |
| 104 bool add_at_beginning) { | 101 bool add_at_beginning) { |
| 105 base::AutoLock lock(lock_); | 102 base::AutoLock lock(lock_); |
| 106 | 103 |
| 107 internal_plugins_.push_back(info); | 104 internal_plugins_.push_back(info); |
| 108 if (add_at_beginning) { | 105 if (add_at_beginning) { |
| 109 // Newer registrations go earlier in the list so they can override the MIME | 106 // Newer registrations go earlier in the list so they can override the MIME |
| 110 // types of older registrations. | 107 // types of older registrations. |
| 111 extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path); | 108 extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path); |
| 112 } else { | 109 } else { |
| 113 extra_plugin_paths_.push_back(info.path); | 110 extra_plugin_paths_.push_back(info.path); |
| 114 } | 111 } |
| 115 } | 112 } |
| 116 | 113 |
| 117 void PluginList::UnregisterInternalPlugin(const base::FilePath& path) { | 114 void PluginList::UnregisterInternalPlugin(const base::FilePath& path) { |
| 118 base::AutoLock lock(lock_); | 115 base::AutoLock lock(lock_); |
| 119 for (size_t i = 0; i < internal_plugins_.size(); i++) { | 116 for (size_t i = 0; i < internal_plugins_.size(); i++) { |
| 120 if (internal_plugins_[i].path == path) { | 117 if (internal_plugins_[i].path == path) { |
| 121 internal_plugins_.erase(internal_plugins_.begin() + i); | 118 internal_plugins_.erase(internal_plugins_.begin() + i); |
| 122 return; | 119 return; |
| 123 } | 120 } |
| 124 } | 121 } |
| 125 NOTREACHED(); | 122 NOTREACHED(); |
| 126 } | 123 } |
| 127 | 124 |
| 128 void PluginList::GetInternalPlugins( | 125 void PluginList::GetInternalPlugins( |
| 129 std::vector<webkit::WebPluginInfo>* internal_plugins) { | 126 std::vector<WebPluginInfo>* internal_plugins) { |
| 130 base::AutoLock lock(lock_); | 127 base::AutoLock lock(lock_); |
| 131 | 128 |
| 132 for (std::vector<webkit::WebPluginInfo>::iterator it = | 129 for (std::vector<WebPluginInfo>::iterator it = internal_plugins_.begin(); |
| 133 internal_plugins_.begin(); | |
| 134 it != internal_plugins_.end(); | 130 it != internal_plugins_.end(); |
| 135 ++it) { | 131 ++it) { |
| 136 internal_plugins->push_back(*it); | 132 internal_plugins->push_back(*it); |
| 137 } | 133 } |
| 138 } | 134 } |
| 139 | 135 |
| 140 bool PluginList::ReadPluginInfo(const base::FilePath& filename, | 136 bool PluginList::ReadPluginInfo(const base::FilePath& filename, |
| 141 webkit::WebPluginInfo* info) { | 137 WebPluginInfo* info) { |
| 142 { | 138 { |
| 143 base::AutoLock lock(lock_); | 139 base::AutoLock lock(lock_); |
| 144 for (size_t i = 0; i < internal_plugins_.size(); ++i) { | 140 for (size_t i = 0; i < internal_plugins_.size(); ++i) { |
| 145 if (filename == internal_plugins_[i].path) { | 141 if (filename == internal_plugins_[i].path) { |
| 146 *info = internal_plugins_[i]; | 142 *info = internal_plugins_[i]; |
| 147 return true; | 143 return true; |
| 148 } | 144 } |
| 149 } | 145 } |
| 150 } | 146 } |
| 151 | 147 |
| 152 return PluginList::ReadWebPluginInfo(filename, info); | 148 return PluginList::ReadWebPluginInfo(filename, info); |
| 153 } | 149 } |
| 154 | 150 |
| 155 // static | 151 // static |
| 156 bool PluginList::ParseMimeTypes( | 152 bool PluginList::ParseMimeTypes( |
| 157 const std::string& mime_types_str, | 153 const std::string& mime_types_str, |
| 158 const std::string& file_extensions_str, | 154 const std::string& file_extensions_str, |
| 159 const base::string16& mime_type_descriptions_str, | 155 const base::string16& mime_type_descriptions_str, |
| 160 std::vector<webkit::WebPluginMimeType>* parsed_mime_types) { | 156 std::vector<WebPluginMimeType>* parsed_mime_types) { |
| 161 std::vector<std::string> mime_types, file_extensions; | 157 std::vector<std::string> mime_types, file_extensions; |
| 162 std::vector<base::string16> descriptions; | 158 std::vector<base::string16> descriptions; |
| 163 base::SplitString(mime_types_str, '|', &mime_types); | 159 base::SplitString(mime_types_str, '|', &mime_types); |
| 164 base::SplitString(file_extensions_str, '|', &file_extensions); | 160 base::SplitString(file_extensions_str, '|', &file_extensions); |
| 165 base::SplitString(mime_type_descriptions_str, '|', &descriptions); | 161 base::SplitString(mime_type_descriptions_str, '|', &descriptions); |
| 166 | 162 |
| 167 parsed_mime_types->clear(); | 163 parsed_mime_types->clear(); |
| 168 | 164 |
| 169 if (mime_types.empty()) | 165 if (mime_types.empty()) |
| 170 return false; | 166 return false; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 199 |
| 204 void PluginList::LoadPlugins(bool include_npapi) { | 200 void PluginList::LoadPlugins(bool include_npapi) { |
| 205 { | 201 { |
| 206 base::AutoLock lock(lock_); | 202 base::AutoLock lock(lock_); |
| 207 if (loading_state_ == LOADING_STATE_UP_TO_DATE) | 203 if (loading_state_ == LOADING_STATE_UP_TO_DATE) |
| 208 return; | 204 return; |
| 209 | 205 |
| 210 loading_state_ = LOADING_STATE_REFRESHING; | 206 loading_state_ = LOADING_STATE_REFRESHING; |
| 211 } | 207 } |
| 212 | 208 |
| 213 std::vector<webkit::WebPluginInfo> new_plugins; | 209 std::vector<WebPluginInfo> new_plugins; |
| 214 base::Closure will_load_callback; | 210 base::Closure will_load_callback; |
| 215 { | 211 { |
| 216 base::AutoLock lock(lock_); | 212 base::AutoLock lock(lock_); |
| 217 will_load_callback = will_load_plugins_callback_; | 213 will_load_callback = will_load_plugins_callback_; |
| 218 } | 214 } |
| 219 if (!will_load_callback.is_null()) | 215 if (!will_load_callback.is_null()) |
| 220 will_load_callback.Run(); | 216 will_load_callback.Run(); |
| 221 | 217 |
| 222 std::vector<base::FilePath> plugin_paths; | 218 std::vector<base::FilePath> plugin_paths; |
| 223 GetPluginPathsToLoad(&plugin_paths, include_npapi); | 219 GetPluginPathsToLoad(&plugin_paths, include_npapi); |
| 224 | 220 |
| 225 for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); | 221 for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); |
| 226 it != plugin_paths.end(); | 222 it != plugin_paths.end(); |
| 227 ++it) { | 223 ++it) { |
| 228 WebPluginInfo plugin_info; | 224 WebPluginInfo plugin_info; |
| 229 LoadPluginIntoPluginList(*it, &new_plugins, &plugin_info); | 225 LoadPluginIntoPluginList(*it, &new_plugins, &plugin_info); |
| 230 } | 226 } |
| 231 | 227 |
| 232 base::AutoLock lock(lock_); | 228 base::AutoLock lock(lock_); |
| 233 plugins_list_.swap(new_plugins); | 229 plugins_list_.swap(new_plugins); |
| 234 | 230 |
| 235 // If we haven't been invalidated in the mean time, mark the plug-in list as | 231 // If we haven't been invalidated in the mean time, mark the plug-in list as |
| 236 // up-to-date. | 232 // up-to-date. |
| 237 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) | 233 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) |
| 238 loading_state_ = LOADING_STATE_UP_TO_DATE; | 234 loading_state_ = LOADING_STATE_UP_TO_DATE; |
| 239 } | 235 } |
| 240 | 236 |
| 241 bool PluginList::LoadPluginIntoPluginList( | 237 bool PluginList::LoadPluginIntoPluginList( |
| 242 const base::FilePath& path, | 238 const base::FilePath& path, |
| 243 std::vector<webkit::WebPluginInfo>* plugins, | 239 std::vector<WebPluginInfo>* plugins, |
| 244 WebPluginInfo* plugin_info) { | 240 WebPluginInfo* plugin_info) { |
| 245 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 241 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
| 246 << "Loading plugin " << path.value(); | 242 << "Loading plugin " << path.value(); |
| 247 if (!ReadPluginInfo(path, plugin_info)) | 243 if (!ReadPluginInfo(path, plugin_info)) |
| 248 return false; | 244 return false; |
| 249 | 245 |
| 250 if (!ShouldLoadPluginUsingPluginList(*plugin_info, plugins)) | 246 if (!ShouldLoadPluginUsingPluginList(*plugin_info, plugins)) |
| 251 return false; | 247 return false; |
| 252 | 248 |
| 253 #if defined(OS_WIN) && !defined(NDEBUG) | 249 #if defined(OS_WIN) && !defined(NDEBUG) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 GetPluginDirectories(&directories_to_scan); | 294 GetPluginDirectories(&directories_to_scan); |
| 299 for (size_t i = 0; i < directories_to_scan.size(); ++i) | 295 for (size_t i = 0; i < directories_to_scan.size(); ++i) |
| 300 GetPluginsInDir(directories_to_scan[i], plugin_paths); | 296 GetPluginsInDir(directories_to_scan[i], plugin_paths); |
| 301 | 297 |
| 302 #if defined(OS_WIN) | 298 #if defined(OS_WIN) |
| 303 GetPluginPathsFromRegistry(plugin_paths); | 299 GetPluginPathsFromRegistry(plugin_paths); |
| 304 #endif | 300 #endif |
| 305 } | 301 } |
| 306 } | 302 } |
| 307 | 303 |
| 308 void PluginList::SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins) { | 304 void PluginList::SetPlugins(const std::vector<WebPluginInfo>& plugins) { |
| 309 base::AutoLock lock(lock_); | 305 base::AutoLock lock(lock_); |
| 310 | 306 |
| 311 DCHECK_NE(LOADING_STATE_REFRESHING, loading_state_); | 307 DCHECK_NE(LOADING_STATE_REFRESHING, loading_state_); |
| 312 loading_state_ = LOADING_STATE_UP_TO_DATE; | 308 loading_state_ = LOADING_STATE_UP_TO_DATE; |
| 313 | 309 |
| 314 plugins_list_.clear(); | 310 plugins_list_.clear(); |
| 315 plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end()); | 311 plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end()); |
| 316 } | 312 } |
| 317 | 313 |
| 318 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { | 314 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { |
| 319 base::AutoLock lock(lock_); | 315 base::AutoLock lock(lock_); |
| 320 will_load_plugins_callback_ = callback; | 316 will_load_plugins_callback_ = callback; |
| 321 } | 317 } |
| 322 | 318 |
| 323 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins, | 319 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins, |
| 324 bool include_npapi) { | 320 bool include_npapi) { |
| 325 LoadPlugins(include_npapi); | 321 LoadPlugins(include_npapi); |
| 326 base::AutoLock lock(lock_); | 322 base::AutoLock lock(lock_); |
| 327 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); | 323 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
| 328 } | 324 } |
| 329 | 325 |
| 330 bool PluginList::GetPluginsNoRefresh( | 326 bool PluginList::GetPluginsNoRefresh(std::vector<WebPluginInfo>* plugins) { |
| 331 std::vector<webkit::WebPluginInfo>* plugins) { | |
| 332 base::AutoLock lock(lock_); | 327 base::AutoLock lock(lock_); |
| 333 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); | 328 plugins->insert(plugins->end(), plugins_list_.begin(), plugins_list_.end()); |
| 334 | 329 |
| 335 return loading_state_ == LOADING_STATE_UP_TO_DATE; | 330 return loading_state_ == LOADING_STATE_UP_TO_DATE; |
| 336 } | 331 } |
| 337 | 332 |
| 338 void PluginList::GetPluginInfoArray( | 333 void PluginList::GetPluginInfoArray( |
| 339 const GURL& url, | 334 const GURL& url, |
| 340 const std::string& mime_type, | 335 const std::string& mime_type, |
| 341 bool allow_wildcard, | 336 bool allow_wildcard, |
| 342 bool* use_stale, | 337 bool* use_stale, |
| 343 bool include_npapi, | 338 bool include_npapi, |
| 344 std::vector<webkit::WebPluginInfo>* info, | 339 std::vector<WebPluginInfo>* info, |
| 345 std::vector<std::string>* actual_mime_types) { | 340 std::vector<std::string>* actual_mime_types) { |
| 346 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 341 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
| 347 DCHECK(info); | 342 DCHECK(info); |
| 348 | 343 |
| 349 if (!use_stale) | 344 if (!use_stale) |
| 350 LoadPlugins(include_npapi); | 345 LoadPlugins(include_npapi); |
| 351 base::AutoLock lock(lock_); | 346 base::AutoLock lock(lock_); |
| 352 if (use_stale) | 347 if (use_stale) |
| 353 *use_stale = (loading_state_ != LOADING_STATE_UP_TO_DATE); | 348 *use_stale = (loading_state_ != LOADING_STATE_UP_TO_DATE); |
| 354 info->clear(); | 349 info->clear(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 382 AllowMimeTypeMismatch(mime_type, actual_mime_type)) { | 377 AllowMimeTypeMismatch(mime_type, actual_mime_type)) { |
| 383 info->push_back(plugins_list_[i]); | 378 info->push_back(plugins_list_[i]); |
| 384 if (actual_mime_types) | 379 if (actual_mime_types) |
| 385 actual_mime_types->push_back(actual_mime_type); | 380 actual_mime_types->push_back(actual_mime_type); |
| 386 } | 381 } |
| 387 } | 382 } |
| 388 } | 383 } |
| 389 } | 384 } |
| 390 } | 385 } |
| 391 | 386 |
| 392 bool PluginList::SupportsType(const webkit::WebPluginInfo& plugin, | 387 bool PluginList::SupportsType(const WebPluginInfo& plugin, |
| 393 const std::string& mime_type, | 388 const std::string& mime_type, |
| 394 bool allow_wildcard) { | 389 bool allow_wildcard) { |
| 395 // Webkit will ask for a plugin to handle empty mime types. | 390 // Webkit will ask for a plugin to handle empty mime types. |
| 396 if (mime_type.empty()) | 391 if (mime_type.empty()) |
| 397 return false; | 392 return false; |
| 398 | 393 |
| 399 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { | 394 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
| 400 const webkit::WebPluginMimeType& mime_info = plugin.mime_types[i]; | 395 const WebPluginMimeType& mime_info = plugin.mime_types[i]; |
| 401 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { | 396 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { |
| 402 if (!allow_wildcard && mime_info.mime_type == "*") | 397 if (!allow_wildcard && mime_info.mime_type == "*") |
| 403 continue; | 398 continue; |
| 404 return true; | 399 return true; |
| 405 } | 400 } |
| 406 } | 401 } |
| 407 return false; | 402 return false; |
| 408 } | 403 } |
| 409 | 404 |
| 410 bool PluginList::SupportsExtension(const webkit::WebPluginInfo& plugin, | 405 bool PluginList::SupportsExtension(const WebPluginInfo& plugin, |
| 411 const std::string& extension, | 406 const std::string& extension, |
| 412 std::string* actual_mime_type) { | 407 std::string* actual_mime_type) { |
| 413 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { | 408 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { |
| 414 const webkit::WebPluginMimeType& mime_type = plugin.mime_types[i]; | 409 const WebPluginMimeType& mime_type = plugin.mime_types[i]; |
| 415 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) { | 410 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) { |
| 416 if (mime_type.file_extensions[j] == extension) { | 411 if (mime_type.file_extensions[j] == extension) { |
| 417 if (actual_mime_type) | 412 if (actual_mime_type) |
| 418 *actual_mime_type = mime_type.mime_type; | 413 *actual_mime_type = mime_type.mime_type; |
| 419 return true; | 414 return true; |
| 420 } | 415 } |
| 421 } | 416 } |
| 422 } | 417 } |
| 423 return false; | 418 return false; |
| 424 } | 419 } |
| 425 | 420 |
| 426 PluginList::~PluginList() { | 421 PluginList::~PluginList() { |
| 427 } | 422 } |
| 428 | 423 |
| 429 | 424 |
| 430 } // namespace content | 425 } // namespace content |
| OLD | NEW |