1/*
2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26WebInspector.fileExtensionForURL = function(url)
27{
28    var lastPathComponent = parseURL(url).lastPathComponent;
29    if (!lastPathComponent)
30        return "";
31
32    var index = lastPathComponent.indexOf(".");
33    if (index === -1)
34        return "";
35
36    return lastPathComponent.substr(index + 1);
37};
38
39WebInspector.mimeTypeForFileExtension = function(extension)
40{
41    const extensionToMIMEType = {
42        // Document types.
43        "html": "text/html",
44        "xhtml": "application/xhtml+xml",
45        "xml": "text/xml",
46
47        // Script types.
48        "js": "text/javascript",
49        "json": "application/json",
50        "clj": "text/x-clojure",
51        "coffee": "text/x-coffeescript",
52        "ls": "text/x-livescript",
53        "ts": "text/typescript",
54
55        // Stylesheet types.
56        "css": "text/css",
57        "less": "text/x-less",
58        "sass": "text/x-sass",
59        "scss": "text/x-scss",
60
61        // Image types.
62        "bmp": "image/bmp",
63        "gif": "image/gif",
64        "jpeg": "image/jpeg",
65        "jpg": "image/jpeg",
66        "pdf": "application/pdf",
67        "png": "image/png",
68        "tif": "image/tiff",
69        "tiff": "image/tiff",
70
71        // Font types and Media types are ignored for now.
72
73        // Miscellaneous types.
74        "svg": "image/svg+xml",
75        "txt": "text/plain",
76        "xsl": "text/xsl"
77    };
78
79    return extensionToMIMEType[extension] || null;
80};
81