summaryrefslogtreecommitdiff
path: root/riscos/plugin.c
blob: 42619ae962098faff7f801411483fb76a10197cc (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
 * This file is part of NetSurf, http://netsurf.sourceforge.net/
 * Licensed under the GNU General Public License,
 *                http://www.opensource.org/licenses/gpl-license
 * Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
 */

#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"

bool plugin_handleable(struct content* c);

/**
 * plugin_decode
 * This function checks that the contents of the plugin_object struct
 * are valid. If they are, it initiates the fetch process. If they are
 * not, it exits, leaving the box structure as it was on entry. This is
 * necessary as there are multiple ways of declaring an object's attributes.
 *
 * TODO: alt html
 *       params - create parameters file and put the filename string
 *                somewhere such that it is accessible from plugin_create.
 */
void plugin_decode(struct content* content, char* url, struct box* box,
                  struct plugin_object* po)
{
  os_error *e;
  unsigned int *fv;

  /* Check if the codebase attribute is defined.
   * If it is not, set it to the codebase of the current document.
   */
   if(po->codebase == 0)
           po->codebase = strdup(content->url);
   else
           po->codebase = url_join(po->codebase, content->url);

  /* Check that we have some data specified.
   * First, check the data attribute.
   * Second, check the classid attribute.
   * The data attribute takes precedence.
   * If neither are specified or if classid begins "clsid:",
   * we can't handle this object.
   */
   if(po->data == 0 && po->classid == 0) {
           xfree(po);
           return;
   }
   if(po->data == 0 && po->classid != 0) {
           if(strnicmp(po->classid, "clsid:", 6) == 0) {
                   LOG(("ActiveX object - n0"));
                   xfree(po);
                   return;
           }
           else {
                   url = url_join(po->classid, po->codebase);
           }
   }
   else {
           url = url_join(po->data, po->codebase);
   }

   /* Check if the declared mime type is understandable.
    * ie. is it referenced in the mimemap file?
    * Checks type and codetype attributes.
    */
    if(po->type != 0) {
          e = xmimemaptranslate_mime_type_to_filetype((const char*)po->type,
                                                      (unsigned int*)&fv);
          LOG(("fv: &%x", (int) fv));
          if(e != NULL) {
                  xfree(po);
                  return;
          }
          /* If a filetype of &ffd (Data) is returned,
           * one of the following mime types is possible :
           * application/octet-stream
           * multipart/x-mixed-replace
           * unknown mime type (* / *)
           * we assume it to be the last one as the other two
           * are unlikely to occur in an <object> definition.
           */
          if((int)fv == 0xffd) {
                  xfree(po);
                  return;
          }
          /* TODO: implement GUI for iframes/frames
           * For now, we just discard the data and
           * render the alternative html
           */
          if((int)fv == 0xfaf) {
                  xfree(po);
                  return;
          }
    }
    if(po->codetype != 0) {
      e = xmimemaptranslate_mime_type_to_filetype((const char*)po->codetype,
                                                  (unsigned int*)&fv);
          if(e != NULL) {
                  xfree(po);
                  return;
          }
          /* If a filetype of &ffd (Data) is returned,
           * one of the following mime types is possible :
           * application/octet-stream
           * multipart/x-mixed-replace
           * unknown mime type (* / *)
           * we assume it to be the last one as the other two
           * are unlikely to occur in an <object> definition.
           */
          if((int)fv == 0xffd) {
                  xfree(po);
                  return;
          }
          /* TODO: implement GUI for iframes/frames
           * For now, we just discard the data and
           * render the alternative html
           */
          if((int)fv == 0xfaf) {
                  xfree(po);
                  return;
          }
    }

  /* If we've got to here, the object declaration has provided us with
   * enough data to enable us to have a go at downloading and displaying it.
   */
   xfree(po);
   html_fetch_object(content, url, box);
}

/**
 * plugin_create
 * initialises plugin system in readiness for recieving object data
 *
 * TODO: implement aborting the fetch
 *       get parameter filename from wherever it was put by plugin_decode
 *       launch plugin system
 */
void plugin_create(struct content *c)
{
  bool can_handle = TRUE; /* we assume we can handle all types */

  LOG(("mime type: %s", c->mime_type));

  /* check if we can handle this type */
  can_handle = plugin_handleable(c);
  LOG(("can_handle = %s", can_handle ? "TRUE" : "FALSE"));
  LOG(("sysvar: %s", can_handle ? c->data.plugin.sysvar : "not set"));

  if(!can_handle) {
          /* TODO: need to find a way of stopping the fetch
           * if we can't handle this type
           */
  }

  /* ok, it looks like we can handle this object.
   * Broadcast Message_PlugIn_Open (&4D540) and listen for response
   * Message_PlugIn_Opening (&4D541). If no response, try to launch
   * plugin by Wimp_StartTask(sysvar). Then re-broadcast Message_PlugIn_Open
   * and listen for response. If there is still no response, give up and set
   * can_handle to FALSE.
   * NB: For the bounding box in Message_PlugIn_Open, we choose arbitrary
   *     values outside the area displayed. This is corrected when
   *     plugin_redraw is called.
   */



  /* Recheck if can_handle is false. If it is, stop fetch and exit .*/
  if(!can_handle) {
          /* TODO: need to find a way of stopping the fetch
           * if we can't handle this type
           */
  }

}

static const char * const ALIAS_PREFIX = "Alias$@PlugInType_";

/**
 * plugin_handleable
 * Tests whether we can handle an object using a browser plugin
 * returns TRUE if we can handle it, FALSE if we can't.
 */
bool plugin_handleable(struct content* c)
{
  bool ret = TRUE;
  char *sysvar;
  unsigned int *fv;
  int used;
  os_error *e;

  /* prefix + 3 for file type + 1 for terminating \0 */
  sysvar = xcalloc(strlen(ALIAS_PREFIX)+4, sizeof(char));

  e = xmimemaptranslate_mime_type_to_filetype((const char*)c->mime_type,
                                               (unsigned int*)&fv);

  sprintf(sysvar, "%s%x", ALIAS_PREFIX, e == NULL ? (int)fv : 0 );

  xos_read_var_val_size((const char*)sysvar,0, os_VARTYPE_STRING,
                                            &used, 0, os_VARTYPE_STRING);

  if(used == 0)
          /* No system variable set => no plugin available */
          ret = FALSE;

  if(ret)
          c->data.plugin.sysvar = strdup(sysvar);

  xfree(sysvar);

  return ret;
}

/**
 * plugin_process_data
 * processes data retrieved by the fetch process
 *
 * TODO: plugin stream protocol
 *
 */
void plugin_process_data(struct content *c, char *data, unsigned long size)
{

  /* If the plugin requests, we send the data to it via the
   * plugin stream protocol.
   * Also, we should listen for Message_PlugIn_URL_Access (&4D54D)
   * as the plugin may need us to retrieve URLs for it.
   * We should also listen for Message_PlugIn_Closed (&4D543).
   * If this occurs, the plugin has exited with an error.
   * Therefore, we need to stop the fetch and exit.
   */

}

/**
 * plugin_convert
 * This isn't needed by the plugin system as all the data processing is done
 * externally. Therefore, just tell NetSurf that everything's OK.
 */
int plugin_convert(struct content *c, unsigned int width, unsigned int height)
{
  c->status=CONTENT_STATUS_DONE;
  return 0;
}

void plugin_revive(struct content *c, unsigned int width, unsigned int height)
{
}

void plugin_reformat(struct content *c, unsigned int width, unsigned int height)
{
}

/**
 * plugin_destroy
 * we've finished with this data, destroy it. Also, shutdown plugin.
 *
 * TODO: clean up
 */
void plugin_destroy(struct content *c)
{
}

/**
 * plugin_redraw
 * redraw plugin on page.
 *
 * TODO: Message_PlugIn_Reshape
 */
void plugin_redraw(struct content *c, long x, long y,
		unsigned long width, unsigned long height)
{

  /* By now, we've got the plugin up and running in a nested window
   * off the viewable page area. Now we want to display it in its place.
   * Therefore, broadcast a Message_PlugIn_Reshape (&4D544) with the values
   * given to us.
   */
}