File: mime.js

package info (click to toggle)
conkeror 0.9~git080629-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,132 kB
  • ctags: 906
  • sloc: sh: 340; ansic: 246; xml: 105; makefile: 77
file content (43 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
 *
 * Use, modification, and distribution are subject to the terms specified in the
 * COPYING file.
**/

const mime_service = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);

var mime_type_external_handlers = [

    [ /^text\/.*$/, getenv("EDITOR")],
    [/^image\/.*$/, "feh"],
    [/^video\/.*$/, "mplayer"],
    [/^audio\/.*$/, "mplayer"],
    [/^application\/pdf$/, "evince"],
    [/^application\/postscript$/, "evince"],
    [/^application\/x-dvi$/, "evince"],
    [/^.*$/, getenv("EDITOR")]
    ];

function get_external_handler_for_mime_type(mime_type) {
    return predicate_alist_match(mime_type_external_handlers, mime_type);
}

function mime_type_from_uri(uri) {
    var type = "application/octet-stream";
    try {
        uri = make_uri(uri);
        type = mime_service.getTypeFromURI(uri);
    } catch (e) {}
    return type;
}

function mime_info_from_mime_type(type) {
    if (type == null)
        type = "application/octet-stream";
    try {
        return mime_service.getFromTypeAndExtension(type, null);
    } catch (e) {
        return null;
    }
}