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