OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/network/mime/MIMETypeFromURL.h" |
| 6 |
| 7 #include "platform/network/mime/MIMETypeRegistry.h" |
| 8 #include "platform/weborigin/KURL.h" |
| 9 #include "wtf/text/WTFString.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 String mimeTypeFromDataURL(const String& url) { |
| 14 DCHECK(protocolIs(url, "data")); |
| 15 size_t index = url.find(';'); |
| 16 if (index == kNotFound) |
| 17 index = url.find(','); |
| 18 if (index != kNotFound) { |
| 19 if (index > 5) |
| 20 return url.substring(5, index - 5).lower(); |
| 21 // Data URLs with no MIME type are considered text/plain. |
| 22 return "text/plain"; |
| 23 } |
| 24 return ""; |
| 25 } |
| 26 |
| 27 String mimeTypeFromURL(const KURL& url) { |
| 28 String decodedPath = decodeURLEscapeSequences(url.path()); |
| 29 String extension = decodedPath.substring(decodedPath.reverseFind('.') + 1); |
| 30 |
| 31 // We don't use MIMETypeRegistry::getMIMETypeForPath() because it returns |
| 32 // "application/octet-stream" upon failure |
| 33 return MIMETypeRegistry::getMIMETypeForExtension(extension); |
| 34 } |
| 35 |
| 36 } // namespace blink |
OLD | NEW |