Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: third_party/WebKit/Source/platform/network/mime/MIMETypeFromURL.cpp

Issue 2482653002: Move MIME related platform files under network/mime (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698