NetSurf
plugin_hack.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Chris Young <chris@unsatisfactorysoftware.co.uk>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/** \file
20 * Plugin=>external program handler (implementation)
21*/
22
23#include "amiga/os3support.h"
24
25#include <stdlib.h>
26#include <proto/dos.h>
27#include <proto/exec.h>
28#include <proto/intuition.h>
29#include <proto/utility.h>
30
31#include "utils/log.h"
32#include "utils/messages.h"
33#include "netsurf/plotters.h"
34#include "netsurf/content.h"
35#include "amiga/filetype.h"
36#include "amiga/plugin_hack.h"
39#include "content/llcache.h"
40
41
43 struct content base;
45
47 lwc_string *imime_type, const struct http_parameter *params,
49 bool quirks, struct content **c);
50static bool amiga_plugin_hack_convert(struct content *c);
51static void amiga_plugin_hack_reformat(struct content *c, int width, int height);
52static void amiga_plugin_hack_destroy(struct content *c);
53static bool amiga_plugin_hack_redraw(struct content *c,
54 struct content_redraw_data *data, const struct rect *clip,
55 const struct redraw_context *ctx);
56static nserror amiga_plugin_hack_open(struct content *c, struct browser_window *bw,
57 struct content *page, struct object_params *params);
59static nserror amiga_plugin_hack_clone(const struct content *old, struct content **newc);
61
64 .data_complete = amiga_plugin_hack_convert,
72 .no_share = false,
73};
74
76{
77 struct Node *node = NULL;
78 lwc_string *type;
79 nserror error;
80
81 do {
82 node = ami_mime_has_cmd(&type, node);
83
84 if(node)
85 {
86 NSLOG(netsurf, INFO, "plugin_hack registered %s",
87 lwc_string_data(type));
88
90 lwc_string_data(type),
92
93 if (error != NSERROR_OK)
94 return error;
95 }
96
97 }while (node != NULL);
98
99 return NSERROR_OK;
100}
101
103 lwc_string *imime_type, const struct http_parameter *params,
104 llcache_handle *llcache, const char *fallback_charset,
105 bool quirks, struct content **c)
106{
108 nserror error;
109
110 plugin = calloc(1, sizeof(amiga_plugin_hack_content));
111 if (plugin == NULL)
112 return NSERROR_NOMEM;
113
114 error = content__init(&plugin->base, handler, imime_type, params,
115 llcache, fallback_charset, quirks);
116 if (error != NSERROR_OK) {
117 free(plugin);
118 return error;
119 }
120
121 *c = (struct content *) plugin;
122
123 return NSERROR_OK;
124}
125
127{
128 NSLOG(netsurf, INFO, "amiga_plugin_hack_convert");
129
132
133 content_set_status(c, "");
134
135 return true;
136}
137
139{
141
142 NSLOG(netsurf, INFO, "amiga_plugin_hack_destroy %p", plugin);
143
144 return;
145}
146
148 struct content_redraw_data *data, const struct rect *clip,
149 const struct redraw_context *ctx)
150{
151 plot_style_t pstyle = {
153 .fill_colour = 0xffffff,
154 .stroke_colour = 0x000000,
155 .stroke_width = plot_style_int_to_fixed(1),
156 };
157 struct rect rect;
158 nserror res;
159
160 NSLOG(netsurf, INFO, "amiga_plugin_hack_redraw");
161
162 rect.x0 = data->x;
163 rect.y0 = data->y;
164 rect.x1 = data->x + data->width;
165 rect.y1 = data->y + data->height;
166
167 ctx->plot->rectangle(ctx, &pstyle, &rect);
168
169 res = ctx->plot->text(ctx,
171 data->x, data->y+20,
172 lwc_string_data(content__get_mime_type(c)),
173 lwc_string_length(content__get_mime_type(c)));
174 if (res != NSERROR_OK) {
175 return false;
176 }
177 return true;
178}
179
180/**
181 * Handle a window containing a CONTENT_PLUGIN being opened.
182 *
183 * \param c content that has been opened
184 * \param bw browser window containing the content
185 * \param page content of type CONTENT_HTML containing c, or 0 if not an
186 * object within a page
187 * \param params object parameters, or 0 if not an object
188 */
190 struct content *page, struct object_params *params)
191{
192 NSLOG(netsurf, INFO, "amiga_plugin_hack_open %s",
194
195 if(c)
196 {
197 /* TODO: Do we need valid dimensions at this point? */
198 c->width = 0;
199 c->height = 0;
200 }
201
202 return NSERROR_OK;
203}
204
206{
207 NSLOG(netsurf, INFO, "amiga_plugin_hack_close");
208 return NSERROR_OK;
209}
210
212{
213 NSLOG(netsurf, INFO, "amiga_plugin_hack_reformat");
214
215 c->width = width;
216 c->height = height;
217
218 return;
219}
220
221nserror amiga_plugin_hack_clone(const struct content *old, struct content **newc)
222{
224 nserror error;
225
226 NSLOG(netsurf, INFO, "amiga_plugin_hack_clone");
227
228 plugin = calloc(1, sizeof(amiga_plugin_hack_content));
229 if (plugin == NULL)
230 return NSERROR_NOMEM;
231
232 error = content__clone(old, &plugin->base);
233 if (error != NSERROR_OK) {
234 content_destroy(&plugin->base);
235 return error;
236 }
237
238 /* We "clone" the old content by replaying conversion */
239 if (old->status == CONTENT_STATUS_READY ||
240 old->status == CONTENT_STATUS_DONE) {
241 if (amiga_plugin_hack_convert(&plugin->base) == false) {
242 content_destroy(&plugin->base);
244 }
245 }
246
247 *newc = (struct content *) plugin;
248
249 return NSERROR_OK;
250}
251
253{
254 return CONTENT_PLUGIN;
255}
256
258{
259 lwc_string *plugincmd;
260 char *full_cmd;
261 BPTR in, out;
262
263 if(c == NULL) return;
264
265 plugincmd = ami_mime_content_to_cmd(c);
266 if(plugincmd == NULL) return;
267
268 full_cmd = ASPrintf("%s %s", lwc_string_data(plugincmd), nsurl_access(hlcache_handle_get_url(c)));
269
270 if(full_cmd)
271 {
272#ifdef __amigaos4__
273 NSLOG(netsurf, INFO, "Attempting to execute %s", full_cmd);
274
275 in = Open("NIL:", MODE_OLDFILE);
276 out = Open("NIL:", MODE_NEWFILE);
277
278 SystemTags(full_cmd,
279 SYS_Input, in,
280 SYS_Output, out,
281 SYS_Error, out,
282 SYS_Asynch, TRUE,
283 NP_Name, "NetSurf External Process",
284 TAG_DONE);
285
286 FreeVec(full_cmd);
287#endif
288 }
289}
lwc_string * ami_mime_content_to_cmd(struct hlcache_handle *c)
Definition: filetype.c:595
struct Node * ami_mime_has_cmd(lwc_string **mimetype, struct Node *start_node)
Return all MIME types containing a plugincmd.
Definition: filetype.c:547
void content_destroy(struct content *c)
Destroy and free a content.
Definition: content.c:354
lwc_string * content__get_mime_type(struct content *c)
Retrieve mime-type of content.
Definition: content.c:1080
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
Definition: content.c:299
nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks)
Definition: content.c:190
nsurl * content_get_url(struct content *c)
Retrieve URL associated with content.
Definition: content.c:1051
nserror content__clone(const struct content *c, struct content *nc)
Clone a content's data members.
Definition: content.c:1382
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
Definition: content.c:285
void content_set_status(struct content *c, const char *status_message)
Updates content with new status.
Definition: content.c:270
nserror content_factory_register_handler(const char *mime_type, const content_handler *handler)
Register a handler with the content factory.
Protected interface to Content handling.
@ CONTENT_STATUS_READY
Some parts of content still being loaded, but can be displayed.
Definition: content_type.h:92
@ CONTENT_STATUS_DONE
Content has completed all processing.
Definition: content_type.h:95
content_type
The type of a content.
Definition: content_type.h:53
@ CONTENT_PLUGIN
Navigator API Plugins.
Definition: content_type.h:70
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_CLONE_FAILED
Failed to clone handle.
Definition: errors.h:37
@ NSERROR_OK
No error.
Definition: errors.h:30
const char * type
Definition: filetype.cpp:44
Public content interface.
struct nsurl * hlcache_handle_get_url(const struct hlcache_handle *handle)
Retrieve the URL associated with a high level cache handle.
Target independent plotting interface.
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:267
Low-level resource cache (interface)
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
Localised message support (interface).
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
char * ASPrintf(const char *fmt,...)
Definition: os3support.c:139
Minimal compatibility header for AmigaOS 3.
plot_font_style_t const *const plot_style_font
Definition: plot_style.c:165
#define plot_style_int_to_fixed(v)
Definition: plot_style.h:51
@ PLOT_OP_TYPE_SOLID
Solid colour.
Definition: plot_style.h:67
static void amiga_plugin_hack_destroy(struct content *c)
Definition: plugin_hack.c:138
void amiga_plugin_hack_execute(struct hlcache_handle *c)
Definition: plugin_hack.c:257
static content_type amiga_plugin_hack_content_type(void)
Definition: plugin_hack.c:252
static const content_handler amiga_plugin_hack_content_handler
Definition: plugin_hack.c:62
nserror amiga_plugin_hack_init(void)
Definition: plugin_hack.c:75
static nserror amiga_plugin_hack_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Definition: plugin_hack.c:102
static nserror amiga_plugin_hack_clone(const struct content *old, struct content **newc)
Definition: plugin_hack.c:221
struct amiga_plugin_hack_content amiga_plugin_hack_content
static nserror amiga_plugin_hack_open(struct content *c, struct browser_window *bw, struct content *page, struct object_params *params)
Handle a window containing a CONTENT_PLUGIN being opened.
Definition: plugin_hack.c:189
static void amiga_plugin_hack_reformat(struct content *c, int width, int height)
Definition: plugin_hack.c:211
static bool amiga_plugin_hack_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Definition: plugin_hack.c:147
static bool amiga_plugin_hack_convert(struct content *c)
Definition: plugin_hack.c:126
static nserror amiga_plugin_hack_close(struct content *c)
Definition: plugin_hack.c:205
int width
Definition: gui.c:159
int height
Definition: gui.c:160
Browser window data.
Content operation function table.
nserror(* create)(const struct content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, struct llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
parameters to content redraw
Definition: content.h:40
int height
vertical dimension
Definition: content.h:48
int y
coordinate for top-left of redraw
Definition: content.h:42
int x
coordinate for top-left of redraw
Definition: content.h:41
int width
dimensions to render content at (for scaling contents with intrinsic dimensions)
Definition: content.h:47
Content which corresponds to a single URL.
bool quirks
Content is in quirks mode.
int height
Height dimension, if applicable.
char * fallback_charset
Fallback charset, or NULL.
int width
Width dimension, if applicable.
const struct content_handler * handler
Handler for content.
content_status status
Current status.
High-level cache handle.
Definition: hlcache.c:66
Representation of an HTTP parameter.
Definition: parameter.c:31
Handle to low-level cache object.
Definition: llcache.c:76
Parameters for object element and similar elements.
Definition: box.h:164
Plot style for stroke/fill plotters.
Definition: plot_style.h:76
plot_operation_type_t fill_type
Fill plot type.
Definition: plot_style.h:80
nserror(* text)(const struct redraw_context *ctx, const plot_font_style_t *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plotters.h:278
nserror(* rectangle)(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *rectangle)
Plots a rectangle.
Definition: plotters.h:188
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Redraw context.
Definition: plotters.h:51
const struct plotter_table * plot
Current plot operation table.
Definition: plotters.h:73
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357