Index: third_party/WebKit/Source/platform/network/mime/MIMETypeFromURL.cpp |
diff --git a/third_party/WebKit/Source/platform/network/mime/MIMETypeFromURL.cpp b/third_party/WebKit/Source/platform/network/mime/MIMETypeFromURL.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80937e5448ad6860bfa86ccadffd8187d9d838e8 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/network/mime/MIMETypeFromURL.cpp |
@@ -0,0 +1,36 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "platform/network/mime/MIMETypeFromURL.h" |
+ |
+#include "platform/network/mime/MIMETypeRegistry.h" |
+#include "platform/weborigin/KURL.h" |
+#include "wtf/text/WTFString.h" |
+ |
+namespace blink { |
+ |
+String mimeTypeFromDataURL(const String& url) { |
+ DCHECK(protocolIs(url, "data")); |
+ size_t index = url.find(';'); |
+ if (index == kNotFound) |
+ index = url.find(','); |
+ if (index != kNotFound) { |
+ if (index > 5) |
+ return url.substring(5, index - 5).lower(); |
+ // Data URLs with no MIME type are considered text/plain. |
+ return "text/plain"; |
+ } |
+ return ""; |
+} |
+ |
+String mimeTypeFromURL(const KURL& url) { |
+ String decodedPath = decodeURLEscapeSequences(url.path()); |
+ String extension = decodedPath.substring(decodedPath.reverseFind('.') + 1); |
+ |
+ // We don't use MIMETypeRegistry::getMIMETypeForPath() because it returns |
+ // "application/octet-stream" upon failure |
+ return MIMETypeRegistry::getMIMETypeForExtension(extension); |
+} |
+ |
+} // namespace blink |