Chromium Code Reviews| Index: chrome/browser/file_select_helper.cc |
| diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc |
| index 4b328fc7c062b7cb832e2f8bb963e976fb9dad24..95eebaf59923360b60a46df55ce74a5a007b95cd 100644 |
| --- a/chrome/browser/file_select_helper.cc |
| +++ b/chrome/browser/file_select_helper.cc |
| @@ -249,30 +249,38 @@ SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType( |
| file_type->extensions.resize(1); |
| std::vector<FilePath::StringType>* extensions = &file_type->extensions.back(); |
| - // Find the correspondinge extensions. |
| + // Find the corresponding extensions. |
| int valid_type_count = 0; |
| int description_id = 0; |
| for (size_t i = 0; i < accept_types.size(); ++i) { |
| - std::string ascii_mime_type = UTF16ToASCII(accept_types[i]); |
| - // WebKit normalizes MIME types. See HTMLInputElement::acceptMIMETypes(). |
| - DCHECK(StringToLowerASCII(ascii_mime_type) == ascii_mime_type) |
| - << "A MIME type contains uppercase letter: " << ascii_mime_type; |
| - DCHECK(TrimWhitespaceASCII(ascii_mime_type, TRIM_ALL, &ascii_mime_type) |
| + std::string ascii_type = UTF16ToASCII(accept_types[i]); |
| + // WebKit normalizes accept types. |
| + DCHECK(ascii_type.length() > 0) << "An accept type is an empty string."; |
| + DCHECK(ascii_type[0] == '.' ? ascii_type.length() > 1 : true) |
|
Evan Stade
2012/05/25 20:19:57
DCHECK(ascii_type != ".")
raymes
2012/05/25 21:00:23
Umm yes :P. Done.
|
| + << "An accept type is a period."; |
| + DCHECK(StringToLowerASCII(ascii_type) == ascii_type) |
| + << "An accept type contains uppercase letter: " << ascii_type; |
| + DCHECK(TrimWhitespaceASCII(ascii_type, TRIM_ALL, &ascii_type) |
|
Evan Stade
2012/05/25 20:19:57
unit tests > DCHECKs?
raymes
2012/05/25 21:00:23
I agree, I was just extending the current behavior
Evan Stade
2012/05/25 21:10:15
the function should be robust to failures of these
|
| == TRIM_NONE) |
| - << "A MIME type contains whitespace: '" << ascii_mime_type << "'"; |
| + << "An accept type contains whitespace: '" << ascii_type << "'"; |
| size_t old_extension_size = extensions->size(); |
| - if (ascii_mime_type == "image/*") { |
| + if (ascii_type[0] == '.') { |
| + // If the type starts with a period it is assumed to be a file extension |
| + // so we just have to add it to the list. |
| + FilePath::StringType ext(ascii_type.begin(), ascii_type.end()); |
| + extensions->push_back(ext.substr(1)); |
| + } else if (ascii_type == "image/*") { |
| description_id = IDS_IMAGE_FILES; |
| net::GetImageExtensions(extensions); |
| - } else if (ascii_mime_type == "audio/*") { |
| + } else if (ascii_type == "audio/*") { |
| description_id = IDS_AUDIO_FILES; |
| net::GetAudioExtensions(extensions); |
| - } else if (ascii_mime_type == "video/*") { |
| + } else if (ascii_type == "video/*") { |
| description_id = IDS_VIDEO_FILES; |
| net::GetVideoExtensions(extensions); |
| } else { |
| - net::GetExtensionsForMimeType(ascii_mime_type, extensions); |
| + net::GetExtensionsForMimeType(ascii_type, extensions); |
| } |
| if (extensions->size() > old_extension_size) |