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

Side by Side 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 unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698