OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/renderer_host/pepper/pepper_file_system_browser_host.h
" | 5 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "content/browser/renderer_host/pepper/pepper_file_io_host.h" | 9 #include "content/browser/renderer_host/pepper/pepper_file_io_host.h" |
10 #include "content/browser/renderer_host/pepper/quota_reservation.h" | 10 #include "content/browser/renderer_host/pepper/quota_reservation.h" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // Use the first element in |info->mime_types| even if several elements exist. | 478 // Use the first element in |info->mime_types| even if several elements exist. |
479 return info->mime_types[0].mime_type; | 479 return info->mime_types[0].mime_type; |
480 } | 480 } |
481 | 481 |
482 std::string PepperFileSystemBrowserHost::GeneratePluginId( | 482 std::string PepperFileSystemBrowserHost::GeneratePluginId( |
483 const std::string& mime_type) const { | 483 const std::string& mime_type) const { |
484 // TODO(nhiroki): This function is very specialized for specific plugins (MIME | 484 // TODO(nhiroki): This function is very specialized for specific plugins (MIME |
485 // types). If we bring this API to stable, we might have to make it more | 485 // types). If we bring this API to stable, we might have to make it more |
486 // general. | 486 // general. |
487 | 487 |
488 if (!net::IsMimeType(mime_type)) | 488 std::string top_level_type; |
| 489 std::string subtype; |
| 490 if (!net::ParseMimeTypeWithoutParameter( |
| 491 mime_type, &top_level_type, &subtype) || |
| 492 !net::IsValidTopLevelMimeType(top_level_type)) |
489 return std::string(); | 493 return std::string(); |
490 std::string output = mime_type; | |
491 | 494 |
492 // Replace a slash used for type/subtype separator with an underscore. | 495 // Replace a slash used for type/subtype separator with an underscore. |
493 // NOTE: This assumes there is only one slash in the MIME type. | 496 std::string output = top_level_type + "_" + subtype; |
494 ReplaceFirstSubstringAfterOffset(&output, 0, "/", "_"); | |
495 | 497 |
496 // Verify |output| contains only alphabets, digits, or "._-". | 498 // Verify |output| contains only alphabets, digits, or "._-". |
497 for (std::string::const_iterator it = output.begin(); | 499 for (std::string::const_iterator it = output.begin(); |
498 it != output.end(); ++it) { | 500 it != output.end(); ++it) { |
499 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && | 501 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && |
500 *it != '.' && *it != '_' && *it != '-') { | 502 *it != '.' && *it != '_' && *it != '-') { |
501 LOG(WARNING) << "Failed to generate a plugin id."; | 503 LOG(WARNING) << "Failed to generate a plugin id."; |
502 return std::string(); | 504 return std::string(); |
503 } | 505 } |
504 } | 506 } |
505 return output; | 507 return output; |
506 } | 508 } |
507 | 509 |
508 } // namespace content | 510 } // namespace content |
OLD | NEW |