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/glue/plugins/plugin_list.h" | 5 #include "webkit/glue/plugins/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" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // to handle mimeTypes on its own. | 300 // to handle mimeTypes on its own. |
301 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 301 const std::string &mime_type = plugin_info.mime_types[i].mime_type; |
302 if (mime_type == "*" ) | 302 if (mime_type == "*" ) |
303 return; | 303 return; |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 plugins->push_back(plugin_info); | 307 plugins->push_back(plugin_info); |
308 } | 308 } |
309 | 309 |
310 bool PluginList::FindPlugin(const std::string& mime_type, | |
311 bool allow_wildcard, | |
312 WebPluginInfo* info) { | |
313 DCHECK(mime_type == StringToLowerASCII(mime_type)); | |
314 | |
315 LoadPlugins(false); | |
316 AutoLock lock(lock_); | |
317 for (size_t i = 0; i < plugins_.size(); ++i) { | |
318 if (plugins_[i].enabled && | |
319 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | |
320 *info = plugins_[i]; | |
321 return true; | |
322 } | |
323 } | |
324 | |
325 return false; | |
326 } | |
327 | |
328 bool PluginList::FindDisabledPlugin(const std::string& mime_type, | |
329 bool allow_wildcard, | |
330 WebPluginInfo* info) { | |
331 DCHECK(mime_type == StringToLowerASCII(mime_type)); | |
332 | |
333 LoadPlugins(false); | |
334 AutoLock lock(lock_); | |
335 for (size_t i = 0; i < plugins_.size(); ++i) { | |
336 if (!plugins_[i].enabled && | |
337 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | |
338 *info = plugins_[i]; | |
339 return true; | |
340 } | |
341 } | |
342 | |
343 return false; | |
344 } | |
345 | |
346 bool PluginList::FindPlugin(const GURL &url, | |
347 std::string* actual_mime_type, | |
348 WebPluginInfo* info) { | |
349 LoadPlugins(false); | |
350 AutoLock lock(lock_); | |
351 std::string path = url.path(); | |
352 std::string::size_type last_dot = path.rfind('.'); | |
353 if (last_dot == std::string::npos) | |
354 return false; | |
355 | |
356 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); | |
357 | |
358 for (size_t i = 0; i < plugins_.size(); ++i) { | |
359 if (plugins_[i].enabled && | |
360 SupportsExtension(plugins_[i], extension, actual_mime_type)) { | |
361 *info = plugins_[i]; | |
362 return true; | |
363 } | |
364 } | |
365 | |
366 return false; | |
367 } | |
368 | |
369 bool PluginList::SupportsType(const WebPluginInfo& info, | 310 bool PluginList::SupportsType(const WebPluginInfo& info, |
370 const std::string &mime_type, | 311 const std::string &mime_type, |
371 bool allow_wildcard) { | 312 bool allow_wildcard) { |
372 // Webkit will ask for a plugin to handle empty mime types. | 313 // Webkit will ask for a plugin to handle empty mime types. |
373 if (mime_type.empty()) | 314 if (mime_type.empty()) |
374 return false; | 315 return false; |
375 | 316 |
376 for (size_t i = 0; i < info.mime_types.size(); ++i) { | 317 for (size_t i = 0; i < info.mime_types.size(); ++i) { |
377 const WebPluginMimeType& mime_info = info.mime_types[i]; | 318 const WebPluginMimeType& mime_info = info.mime_types[i]; |
378 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { | 319 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 plugins->clear(); | 358 plugins->clear(); |
418 AutoLock lock(lock_); | 359 AutoLock lock(lock_); |
419 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); | 360 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); |
420 it != plugins_.end(); | 361 it != plugins_.end(); |
421 ++it) { | 362 ++it) { |
422 if (it->enabled) | 363 if (it->enabled) |
423 plugins->push_back(*it); | 364 plugins->push_back(*it); |
424 } | 365 } |
425 } | 366 } |
426 | 367 |
| 368 void PluginList::GetPluginInfoArray(const GURL& url, |
| 369 const std::string& mime_type, |
| 370 bool allow_wildcard, |
| 371 std::vector<WebPluginInfo>* info, |
| 372 std::vector<std::string>* actual_mime_types)
{ |
| 373 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
| 374 DCHECK(info); |
| 375 |
| 376 LoadPlugins(false); |
| 377 AutoLock lock(lock_); |
| 378 info->clear(); |
| 379 if (actual_mime_types) |
| 380 actual_mime_types->clear(); |
| 381 |
| 382 std::set<FilePath> visited_plugins; |
| 383 |
| 384 // Add in enabled plugins by mime type. |
| 385 WebPluginInfo default_plugin; |
| 386 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 387 if (plugins_[i].enabled && |
| 388 SupportsType(plugins_[i], mime_type, allow_wildcard)) { |
| 389 FilePath path = plugins_[i].path; |
| 390 if (path.value() != kDefaultPluginLibraryName && |
| 391 visited_plugins.insert(path).second) { |
| 392 info->push_back(plugins_[i]); |
| 393 if (actual_mime_types) |
| 394 actual_mime_types->push_back(mime_type); |
| 395 } |
| 396 } |
| 397 } |
| 398 |
| 399 // Add in enabled plugins by url. |
| 400 std::string path = url.path(); |
| 401 std::string::size_type last_dot = path.rfind('.'); |
| 402 if (last_dot != std::string::npos) { |
| 403 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); |
| 404 std::string actual_mime_type; |
| 405 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 406 if (plugins_[i].enabled && |
| 407 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { |
| 408 FilePath path = plugins_[i].path; |
| 409 if (path.value() != kDefaultPluginLibraryName && |
| 410 visited_plugins.insert(path).second) { |
| 411 info->push_back(plugins_[i]); |
| 412 if (actual_mime_types) |
| 413 actual_mime_types->push_back(actual_mime_type); |
| 414 } |
| 415 } |
| 416 } |
| 417 } |
| 418 |
| 419 // Add in disabled plugins by mime type. |
| 420 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 421 if (!plugins_[i].enabled && |
| 422 SupportsType(plugins_[i], mime_type, allow_wildcard)) { |
| 423 FilePath path = plugins_[i].path; |
| 424 if (path.value() != kDefaultPluginLibraryName && |
| 425 visited_plugins.insert(path).second) { |
| 426 info->push_back(plugins_[i]); |
| 427 if (actual_mime_types) |
| 428 actual_mime_types->push_back(mime_type); |
| 429 } |
| 430 } |
| 431 } |
| 432 |
| 433 // Add the default plugin at the end if it supports the mime type given. |
| 434 if (!plugins_.empty()) { |
| 435 const WebPluginInfo& default_info = plugins_.back(); |
| 436 DCHECK(default_info.path.value() == kDefaultPluginLibraryName); |
| 437 if (SupportsType(default_info, mime_type, allow_wildcard)) { |
| 438 info->push_back(default_info); |
| 439 if (actual_mime_types) |
| 440 actual_mime_types->push_back(mime_type); |
| 441 } |
| 442 } |
| 443 } |
| 444 |
427 bool PluginList::GetPluginInfo(const GURL& url, | 445 bool PluginList::GetPluginInfo(const GURL& url, |
428 const std::string& mime_type, | 446 const std::string& mime_type, |
429 bool allow_wildcard, | 447 bool allow_wildcard, |
430 WebPluginInfo* info, | 448 WebPluginInfo* info, |
431 std::string* actual_mime_type) { | 449 std::string* actual_mime_type) { |
432 bool found = FindPlugin(mime_type, allow_wildcard, info); | 450 DCHECK(info); |
433 if (!found || (info->path.value() == kDefaultPluginLibraryName)) { | 451 std::vector<WebPluginInfo> info_list; |
434 if (FindPlugin(url, actual_mime_type, info) || | 452 |
435 FindDisabledPlugin(mime_type, allow_wildcard, info)) { | 453 // GetPluginInfoArray has slightly less work to do if we can pass |
436 found = true; | 454 // NULL for the mime type list... |
| 455 if (actual_mime_type) { |
| 456 std::vector<std::string> mime_type_list; |
| 457 GetPluginInfoArray(url, mime_type, allow_wildcard, &info_list, &mime_type_li
st); |
| 458 if (!info_list.empty()) { |
| 459 *info = info_list[0]; |
| 460 *actual_mime_type = mime_type_list[0]; |
| 461 return true; |
| 462 } |
| 463 } else { |
| 464 GetPluginInfoArray(url, mime_type, allow_wildcard, &info_list, NULL); |
| 465 if (!info_list.empty()) { |
| 466 *info = info_list[0]; |
| 467 return true; |
437 } | 468 } |
438 } | 469 } |
439 | 470 return false; |
440 return found; | |
441 } | 471 } |
442 | 472 |
443 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 473 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, |
444 WebPluginInfo* info) { | 474 WebPluginInfo* info) { |
445 LoadPlugins(false); | 475 LoadPlugins(false); |
446 AutoLock lock(lock_); | 476 AutoLock lock(lock_); |
447 for (size_t i = 0; i < plugins_.size(); ++i) { | 477 for (size_t i = 0; i < plugins_.size(); ++i) { |
448 if (plugins_[i].path == plugin_path) { | 478 if (plugins_[i].path == plugin_path) { |
449 *info = plugins_[i]; | 479 *info = plugins_[i]; |
450 return true; | 480 return true; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 612 } |
583 | 613 |
584 PluginList::~PluginList() { | 614 PluginList::~PluginList() { |
585 } | 615 } |
586 | 616 |
587 void PluginList::Shutdown() { | 617 void PluginList::Shutdown() { |
588 // TODO | 618 // TODO |
589 } | 619 } |
590 | 620 |
591 } // namespace NPAPI | 621 } // namespace NPAPI |
OLD | NEW |