summaryrefslogtreecommitdiff
path: root/riscos/plugin.c
blob: 526c347d61c8e7201d0f941ef600e83bc2a9a0e3 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * $Id: plugin.c,v 1.3 2003/06/05 13:17:55 philpem Exp $
 */

#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "netsurf/content/content.h"
#include "netsurf/render/html.h"
#include "netsurf/riscos/plugin.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"

#include "oslib/mimemap.h"

char* create_mime_from_ext(char* data);

void plugin_fetch(struct content* content, char* url, struct box* box,
                  struct plugin_object* po) {


        content_type mime_type;

        if (po->data != NULL) {

                if (po->type != NULL) {

                        mime_type = content_lookup((const char*)po->type);
                }
                else {

                        po->type = create_mime_from_ext(po->data);

                        if (po->type != NULL)
                          mime_type = content_lookup((const char*)po->type);

                }

                /* OK, we have an image. Let's make the image handler
                   deal with it */
                if (mime_type == CONTENT_JPEG || mime_type == CONTENT_PNG ||
                    mime_type == CONTENT_GIF) {

                        xfree(po);
                        LOG(("sending data to image handler"));
                        /* TODO - stop segfault when redrawing window */
                        /*html_fetch_image(content, url, box);*/
                }
        }
        else {


        }
        /* TODO - this function.*/

}

/**
 * create_mime_from_ext
 * attempts to create a mime type from the filename extension.
 * returns NULL if it fails.
 */

char* create_mime_from_ext(char* data){

        char* ret;
        os_error *e;

        ret = strrchr(data, '.');
        LOG(("Extension = %s", ret));

        /* Let's make the mime map module do the work for us */
        e = xmimemaptranslate_extension_to_mime_type((const char*)ret,
                                                      ret);
        LOG(("Mime Type = %s", ret));

        if(e != NULL) ret = NULL;

        return ret;
}