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( |
| 369 const GURL& url, |
| 370 const std::string& mime_type, |
| 371 bool allow_wildcard, |
| 372 std::vector<WebPluginInfo>* info, |
| 373 std::vector<std::string>* actual_mime_types) { |
| 374 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
| 375 DCHECK(info); |
| 376 |
| 377 LoadPlugins(false); |
| 378 AutoLock lock(lock_); |
| 379 info->clear(); |
| 380 if (actual_mime_types) |
| 381 actual_mime_types->clear(); |
| 382 |
| 383 std::set<FilePath> visited_plugins; |
| 384 |
| 385 // Add in enabled plugins by mime type. |
| 386 WebPluginInfo default_plugin; |
| 387 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 388 if (plugins_[i].enabled && |
| 389 SupportsType(plugins_[i], mime_type, allow_wildcard)) { |
| 390 FilePath path = plugins_[i].path; |
| 391 if (path.value() != kDefaultPluginLibraryName && |
| 392 visited_plugins.insert(path).second) { |
| 393 info->push_back(plugins_[i]); |
| 394 if (actual_mime_types) |
| 395 actual_mime_types->push_back(mime_type); |
| 396 } |
| 397 } |
| 398 } |
| 399 |
| 400 // Add in enabled plugins by url. |
| 401 std::string path = url.path(); |
| 402 std::string::size_type last_dot = path.rfind('.'); |
| 403 if (last_dot != std::string::npos) { |
| 404 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); |
| 405 std::string actual_mime_type; |
| 406 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 407 if (plugins_[i].enabled && |
| 408 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { |
| 409 FilePath path = plugins_[i].path; |
| 410 if (path.value() != kDefaultPluginLibraryName && |
| 411 visited_plugins.insert(path).second) { |
| 412 info->push_back(plugins_[i]); |
| 413 if (actual_mime_types) |
| 414 actual_mime_types->push_back(actual_mime_type); |
| 415 } |
| 416 } |
| 417 } |
| 418 } |
| 419 |
| 420 // Add in disabled plugins by mime type. |
| 421 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 422 if (!plugins_[i].enabled && |
| 423 SupportsType(plugins_[i], mime_type, allow_wildcard)) { |
| 424 FilePath path = plugins_[i].path; |
| 425 if (path.value() != kDefaultPluginLibraryName && |
| 426 visited_plugins.insert(path).second) { |
| 427 info->push_back(plugins_[i]); |
| 428 if (actual_mime_types) |
| 429 actual_mime_types->push_back(mime_type); |
| 430 } |
| 431 } |
| 432 } |
| 433 |
| 434 // Add the default plugin at the end if it supports the mime type given, |
| 435 // and the default plugin is enabled. |
| 436 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { |
| 437 const WebPluginInfo& default_info = plugins_.back(); |
| 438 if (SupportsType(default_info, mime_type, allow_wildcard)) { |
| 439 info->push_back(default_info); |
| 440 if (actual_mime_types) |
| 441 actual_mime_types->push_back(mime_type); |
| 442 } |
| 443 } |
| 444 } |
| 445 |
427 bool PluginList::GetPluginInfo(const GURL& url, | 446 bool PluginList::GetPluginInfo(const GURL& url, |
428 const std::string& mime_type, | 447 const std::string& mime_type, |
429 bool allow_wildcard, | 448 bool allow_wildcard, |
430 WebPluginInfo* info, | 449 WebPluginInfo* info, |
431 std::string* actual_mime_type) { | 450 std::string* actual_mime_type) { |
432 bool found = FindPlugin(mime_type, allow_wildcard, info); | 451 DCHECK(info); |
433 if (!found || (info->path.value() == kDefaultPluginLibraryName)) { | 452 std::vector<WebPluginInfo> info_list; |
434 if (FindPlugin(url, actual_mime_type, info) || | 453 |
435 FindDisabledPlugin(mime_type, allow_wildcard, info)) { | 454 // GetPluginInfoArray has slightly less work to do if we can pass |
436 found = true; | 455 // NULL for the mime type list... |
| 456 if (actual_mime_type) { |
| 457 std::vector<std::string> mime_type_list; |
| 458 GetPluginInfoArray(url, mime_type, allow_wildcard, &info_list, |
| 459 &mime_type_list); |
| 460 if (!info_list.empty()) { |
| 461 *info = info_list[0]; |
| 462 *actual_mime_type = mime_type_list[0]; |
| 463 return true; |
| 464 } |
| 465 } else { |
| 466 GetPluginInfoArray(url, mime_type, allow_wildcard, &info_list, NULL); |
| 467 if (!info_list.empty()) { |
| 468 *info = info_list[0]; |
| 469 return true; |
437 } | 470 } |
438 } | 471 } |
439 | 472 return false; |
440 return found; | |
441 } | 473 } |
442 | 474 |
443 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 475 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, |
444 WebPluginInfo* info) { | 476 WebPluginInfo* info) { |
445 LoadPlugins(false); | 477 LoadPlugins(false); |
446 AutoLock lock(lock_); | 478 AutoLock lock(lock_); |
447 for (size_t i = 0; i < plugins_.size(); ++i) { | 479 for (size_t i = 0; i < plugins_.size(); ++i) { |
448 if (plugins_[i].path == plugin_path) { | 480 if (plugins_[i].path == plugin_path) { |
449 *info = plugins_[i]; | 481 *info = plugins_[i]; |
450 return true; | 482 return true; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 614 } |
583 | 615 |
584 PluginList::~PluginList() { | 616 PluginList::~PluginList() { |
585 } | 617 } |
586 | 618 |
587 void PluginList::Shutdown() { | 619 void PluginList::Shutdown() { |
588 // TODO | 620 // TODO |
589 } | 621 } |
590 | 622 |
591 } // namespace NPAPI | 623 } // namespace NPAPI |
OLD | NEW |