summaryrefslogtreecommitdiff
path: root/amiga
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-05-06 20:40:09 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-05-06 20:40:09 +0000
commite71691bae890040b83cfd54a2d9a1097d5026866 (patch)
tree96b2680dc6559ca0ab88fa0b6a533c13b7c9487e /amiga
parente77b1a29550e4753f771848705975295a6ebe99e (diff)
downloadnetsurf-e71691bae890040b83cfd54a2d9a1097d5026866.tar.gz
netsurf-e71691bae890040b83cfd54a2d9a1097d5026866.tar.bz2
Merge branches/jmb/content-factory to trunk
svn path=/trunk/netsurf/; revision=12283
Diffstat (limited to 'amiga')
-rw-r--r--amiga/Makefile.target4
-rwxr-xr-xamiga/clipboard.c2
-rwxr-xr-xamiga/context_menu.c4
-rw-r--r--amiga/drag.c4
-rw-r--r--amiga/filetype.c64
-rw-r--r--amiga/filetype.h4
-rwxr-xr-xamiga/gui.c21
-rw-r--r--amiga/icon.c149
-rw-r--r--amiga/icon.h20
-rwxr-xr-xamiga/menu.c15
-rw-r--r--amiga/plugin.c191
-rw-r--r--amiga/plugin.h18
-rwxr-xr-xamiga/save_complete.c4
13 files changed, 339 insertions, 161 deletions
diff --git a/amiga/Makefile.target b/amiga/Makefile.target
index 551d12cf9..00b700551 100644
--- a/amiga/Makefile.target
+++ b/amiga/Makefile.target
@@ -23,7 +23,7 @@ ifeq ($(HOST),amiga)
$(eval $(call feature_enabled,NSSVG,-DWITH_NS_SVG,-lsvgtiny,SVG (libsvgtiny)))
$(eval $(call feature_enabled,MNG,,-llcms -ljpeg,PNG/JNG/MNG (libmng)))
$(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp,WebP (libwebp)))
- $(eval $(call feature_enabled,AMIGA_ICON,-DWITH_AMIGA_ICON,,Amiga icon ))
+ $(eval $(call feature_enabled,AMIGA_ICON,-DWITH_AMIGA_ICON,,Amiga icon))
$(eval $(call feature_enabled,PLUGINS,-DWITH_PLUGIN,,DataTypes images))
CFLAGS += -I /SDK/local/common/include/libpng12
@@ -42,6 +42,8 @@ else
$(eval $(call pkg_config_find_and_add,GIF,libnsgif,GIF))
$(eval $(call pkg_config_find_and_add,PNG,libpng,PNG))
$(eval $(call pkg_config_find_and_add,NSSVG,libsvgtiny,NSSVG))
+ $(eval $(call feature_enabled,AMIGA_ICON,-DWITH_AMIGA_ICON,,Amiga icon))
+ $(eval $(call feature_enabled,PLUGINS,-DWITH_PLUGIN,,DataTypes images))
CFLAGS += -I$(GCCSDK_INSTALL_ENV)/include
CFLAGS += $(shell $(PKG_CONFIG) --cflags libxml-2.0 libcurl libcares openssl)
diff --git a/amiga/clipboard.c b/amiga/clipboard.c
index ee9e692f5..0d1ba74ad 100755
--- a/amiga/clipboard.c
+++ b/amiga/clipboard.c
@@ -421,7 +421,7 @@ bool ami_easy_clipboard_svg(struct hlcache_handle *c)
char *source_data;
ULONG source_size;
- if(content_get_type(c) != CONTENT_SVG) return false;
+ if(ami_mime_compare(c, "svg") == false) return false;
if((source_data = content_get_source_data(c, &source_size)) == NULL) return false;
if(!(OpenIFF(iffh,IFFF_WRITE)))
diff --git a/amiga/context_menu.c b/amiga/context_menu.c
index 81f81361e..12fed3160 100755
--- a/amiga/context_menu.c
+++ b/amiga/context_menu.c
@@ -469,7 +469,7 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved
ami_easy_clipboard_bitmap(bm);
}
#ifdef WITH_NS_SVG
- else if(content_get_type(object) == CONTENT_SVG)
+ else if(ami_mime_compare(object, "svg") == true)
{
ami_easy_clipboard_svg(object);
}
@@ -529,7 +529,7 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved
SetComment(fname, content_get_url(object));
}
#ifdef WITH_NS_SVG
- else if(content_get_type(object) == CONTENT_SVG)
+ else if(ami_mime_compare(object, "svg") == true)
{
if(ami_save_svg(object,fname))
SetComment(fname, content_get_url(object));
diff --git a/amiga/drag.c b/amiga/drag.c
index 37e0acd24..8f5625bcf 100644
--- a/amiga/drag.c
+++ b/amiga/drag.c
@@ -73,7 +73,7 @@ void gui_drag_save_object(gui_save_type type, hlcache_handle *c,
break;
case GUI_SAVE_OBJECT_NATIVE:
#ifdef WITH_NS_SVG
- if(content_get_type(c) == CONTENT_SVG)
+ if(ami_mime_compare(c, "svg") == true)
{
filetype = "dr2d";
}
@@ -211,7 +211,7 @@ void ami_drag_save(struct Window *win)
SetComment(path, content_get_url(c));
}
#ifdef WITH_NS_SVG
- else if(content_get_type(c) == CONTENT_SVG)
+ else if(ami_mime_compare(c, "svg") == true)
{
if(ami_save_svg(c, path))
SetComment(path, content_get_url(c));
diff --git a/amiga/filetype.c b/amiga/filetype.c
index 61fe4a5c9..9d4414a13 100644
--- a/amiga/filetype.c
+++ b/amiga/filetype.c
@@ -20,7 +20,7 @@
#include <string.h>
#include "amiga/filetype.h"
#include "content/fetch.h"
-#include "content/content_type.h"
+#include "content/content.h"
#include "utils/log.h"
#include "utils/utils.h"
#include <proto/icon.h>
@@ -140,54 +140,6 @@ const char *ami_content_type_to_file_type(content_type type)
return "css";
break;
-#ifdef WITH_JPEG
- case CONTENT_JPEG:
- return "jpeg";
- break;
-#endif
-#ifdef WITH_GIF
- case CONTENT_GIF:
- return "gif";
- break;
-#endif
-#ifdef WITH_BMP
- case CONTENT_BMP:
- return "bmp";
- break;
-
- case CONTENT_ICO:
- return "ico";
- break;
-#endif
-#if defined(WITH_MNG) || defined(WITH_PNG)
- case CONTENT_PNG:
- return "png";
- break;
-#endif
-#ifdef WITH_MNG
- case CONTENT_JNG:
- return "jng";
- break;
-
- case CONTENT_MNG:
- return "mng";
- break;
-#endif
-#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
- case CONTENT_SPRITE:
- return "rosprite";
- break;
-#endif
-#if defined(WITH_NS_SVG) || defined(WITH_RSVG)
- case CONTENT_SVG:
- return "svg";
- break;
-#endif
-#ifdef WITH_WEBP
- case CONTENT_WEBP:
- return "webp";
- break;
-#endif
default:
return "project";
break;
@@ -245,3 +197,17 @@ void ami_datatype_to_mimetype(struct DataType *dtn, char *mimetype)
break;
}
}
+
+bool ami_mime_compare(struct hlcache_handle *c, const char *type)
+{
+ lwc_string *mime = content_get_mime_type(c);
+ const char *mime_string = lwc_string_data(mime);
+ size_t mime_length = lwc_string_length(mime);
+
+ if(!strncmp("svg", type, 3))
+ {
+ if(!strncmp(mime_string, "image/svg", mime_length)) return true;
+ if(!strncmp(mime_string, "image/svg+xml", mime_length)) return true;
+ }
+ else return false;
+}
diff --git a/amiga/filetype.h b/amiga/filetype.h
index b7a1a54a9..a09a79a52 100644
--- a/amiga/filetype.h
+++ b/amiga/filetype.h
@@ -18,9 +18,13 @@
#ifndef AMIGA_FILETYPE_H
#define AMIGA_FILETYPE_H
+#include <stdbool.h>
#include "content/content_type.h"
#include <datatypes/datatypes.h>
+struct hlcache_handle;
+
const char *ami_content_type_to_file_type(content_type type);
void ami_datatype_to_mimetype(struct DataType *dtn, char *mimetype);
+bool ami_mime_compare(struct hlcache_handle *c, const char *type);
#endif
diff --git a/amiga/gui.c b/amiga/gui.c
index 880901b9d..d3f05e576 100755
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -50,12 +50,14 @@
#include "amiga/history.h"
#include "amiga/history_local.h"
#include "amiga/hotlist.h"
+#include "amiga/icon.h"
#include "amiga/launch.h"
#include "amiga/login.h"
#include "amiga/menu.h"
#include "amiga/misc.h"
#include "amiga/options.h"
#include "amiga/plotters.h"
+#include "amiga/plugin.h"
#include "amiga/print.h"
#include "amiga/schedule.h"
#include "amiga/search.h"
@@ -748,8 +750,12 @@ int main(int argc, char** argv)
ami_schedule_open_timer();
ami_schedule_create();
+ plugin_init();
+
netsurf_init(&argc, &argv, "PROGDIR:Resources/Options", messages);
+ amiga_icon_init();
+
gui_init(argc, argv);
gui_init2(argc, argv);
@@ -765,6 +771,9 @@ int main(int argc, char** argv)
netsurf_exit();
+ plugin_fini();
+ amiga_icon_fini();
+
return 0;
}
@@ -3634,12 +3643,6 @@ void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
if ((icon != NULL) &&
(content_get_status(icon) != CONTENT_STATUS_READY) &&
(content_get_status(icon) != CONTENT_STATUS_DONE)) return;
-#ifdef WITH_BMP
- if ((icon != NULL) && (content_get_type(icon) == CONTENT_ICO))
- {
- nsico_set_bitmap_from_size(icon, 16, 16);
- }
-#endif
if ((icon != NULL) && (content_get_bitmap(icon) != NULL))
{
bm = ami_getcachenativebm(content_get_bitmap(icon), 16, 16,
@@ -3691,12 +3694,6 @@ void gui_window_set_search_ico(hlcache_handle *ico)
if(IsMinListEmpty(window_list)) return;
if(option_kiosk_mode == true) return;
if (ico == NULL) ico = search_web_ico();
-#ifdef WITH_BMP
- if ((ico != NULL) && (content_get_type(ico) == CONTENT_ICO))
- {
- nsico_set_bitmap_from_size(ico, 16, 16);
- }
-#endif
if ((ico != NULL) && (content_get_bitmap(ico) != NULL))
{
bm = ami_getcachenativebm(content_get_bitmap(ico), 16, 16, NULL);
diff --git a/amiga/icon.c b/amiga/icon.c
index 86d01bcd7..07dac8c0e 100644
--- a/amiga/icon.c
+++ b/amiga/icon.c
@@ -44,6 +44,7 @@
#include "content/content_protected.h"
#include "utils/log.h"
#include "utils/messages.h"
+#include "utils/talloc.h"
#include "utils/utils.h"
#include "utils/url.h"
@@ -52,6 +53,112 @@ ULONG *amiga_icon_convertcolouricon32(UBYTE *icondata, ULONG width, ULONG height
#ifdef WITH_AMIGA_ICON
+typedef struct amiga_icon_content {
+ struct content base;
+} amiga_icon_content;
+
+static nserror amiga_icon_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c);
+static bool amiga_icon_convert(struct content *c);
+static void amiga_icon_destroy(struct content *c);
+static bool amiga_icon_redraw(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour);
+static nserror amiga_icon_clone(const struct content *old,
+ struct content **newc);
+static content_type amiga_icon_content_type(lwc_string *mime_type);
+
+static const content_handler amiga_icon_content_handler = {
+ amiga_icon_create,
+ NULL,
+ amiga_icon_convert,
+ NULL,
+ amiga_icon_destroy,
+ NULL,
+ NULL,
+ NULL,
+ amiga_icon_redraw,
+ NULL,
+ NULL,
+ NULL,
+ amiga_icon_clone,
+ NULL,
+ amiga_icon_content_type,
+ false
+};
+
+static const char *amiga_icon_types[] = {
+ "image/x-amiga-icon"
+};
+
+static lwc_string *amiga_icon_mime_types[NOF_ELEMENTS(amiga_icon_types)];
+
+nserror amiga_icon_init(void)
+{
+ uint32_t i;
+ lwc_error lerror;
+ nserror error;
+
+ for (i = 0; i < NOF_ELEMENTS(amiga_icon_mime_types); i++) {
+ lerror = lwc_intern_string(amiga_icon_types[i],
+ strlen(amiga_icon_types[i]),
+ &amiga_icon_mime_types[i]);
+ if (lerror != lwc_error_ok) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
+ error = content_factory_register_handler(
+ amiga_icon_mime_types[i],
+ &amiga_icon_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
+ }
+
+ return NSERROR_OK;
+
+error:
+ amiga_icon_fini();
+
+ return error;
+}
+
+void amiga_icon_fini(void)
+{
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(amiga_icon_mime_types); i++) {
+ if (amiga_icon_mime_types[i] != NULL)
+ lwc_string_unref(amiga_icon_mime_types[i]);
+ }
+}
+
+nserror amiga_icon_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
+{
+ amiga_icon_content *ai;
+ nserror error;
+
+ ai = talloc_zero(0, amiga_icon_content);
+ if (ai == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&ai->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(ai);
+ return error;
+ }
+
+ *c = (struct content *) ai;
+
+ return NSERROR_OK;
+}
+
/**
* Convert a CONTENT_AMIGA_ICON for display.
*
@@ -70,7 +177,7 @@ bool amiga_icon_convert(struct content *c)
int err = 0;
uint8 r, g, b, a;
ULONG offset;
- char *url;
+ const char *url;
char *filename;
char *p;
ULONG trans, pals1;
@@ -119,7 +226,7 @@ bool amiga_icon_convert(struct content *c)
if(dobj) FreeDiskObject(dobj);
return false;
}
- imagebuf = bitmap_get_buffer(c->bitmap);
+ imagebuf = (ULONG *) bitmap_get_buffer(c->bitmap);
if (!imagebuf) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
@@ -138,7 +245,7 @@ bool amiga_icon_convert(struct content *c)
ICONCTRLA_GetPaletteSize1, &pals1,
TAG_DONE);
- imagebufptr = amiga_icon_convertcolouricon32((UBYTE *)imagebufptr,
+ imagebufptr = (unsigned char *) amiga_icon_convertcolouricon32((UBYTE *)imagebufptr,
width, height, trans, pals1, pal1, 0xff);
}
@@ -197,16 +304,38 @@ bool amiga_icon_redraw(struct content *c, int x, int y,
}
-bool amiga_icon_clone(const struct content *old, struct content *new_content)
+nserror amiga_icon_clone(const struct content *old, struct content **newc)
{
+ amiga_icon_content *ai;
+ nserror error;
+
+ ai = talloc_zero(0, amiga_icon_content);
+ if (ai == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &ai->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&ai->base);
+ return error;
+ }
+
/* Simply replay convert */
if (old->status == CONTENT_STATUS_READY ||
old->status == CONTENT_STATUS_DONE) {
- if (amiga_icon_convert(new_content) == false)
- return false;
+ if (amiga_icon_convert(&ai->base) == false) {
+ content_destroy(&ai->base);
+ return NSERROR_CLONE_FAILED;
+ }
}
- return true;
+ *newc = (struct content *) ai;
+
+ return NSERROR_OK;
+}
+
+content_type amiga_icon_content_type(lwc_string *mime_type)
+{
+ return CONTENT_IMAGE;
}
#endif /* WITH_AMIGA_ICON */
@@ -317,12 +446,6 @@ void ami_superimpose_favicon(char *path, struct hlcache_handle *icon, char *type
if((format == IDFMT_DIRECTMAPPED) || (format == IDFMT_PALETTEMAPPED))
{
-#ifdef WITH_BMP
- if ((icon != NULL) && (content_get_type(icon) == CONTENT_ICO))
- {
- nsico_set_bitmap_from_size(icon, 16, 16);
- }
-#endif
if ((icon != NULL) && (content_get_bitmap(icon) != NULL))
{
bm = ami_getcachenativebm(content_get_bitmap(icon), 16, 16, NULL);
diff --git a/amiga/icon.h b/amiga/icon.h
index bd9fb501d..646c50653 100644
--- a/amiga/icon.h
+++ b/amiga/icon.h
@@ -24,23 +24,17 @@
#define AMIGA_ICON_H
#include "utils/config.h"
-#ifdef WITH_AMIGA_ICON
+#include "utils/errors.h"
-#include <stdbool.h>
-#include "content/hlcache.h"
+#ifdef WITH_AMIGA_ICON
-struct rect;
+nserror amiga_icon_init(void);
+void amiga_icon_fini(void);
-struct content_amiga_icon_data {
-/* empty */
-};
+#else
-bool amiga_icon_convert(struct content *c);
-void amiga_icon_destroy(struct content *c);
-bool amiga_icon_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour);
-bool amiga_icon_clone(const struct content *old, struct content *new_content);
+#define amiga_icon_init() NSERROR_OK
+#define amiga_icon_fini() ((void) 0)
#endif /* WITH_AMIGA_ICON */
diff --git a/amiga/menu.c b/amiga/menu.c
index c39eb94bc..06820479b 100755
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -68,7 +68,6 @@
#include "desktop/save_complete.h"
#include "desktop/selection.h"
#include "desktop/textinput.h"
-#include "desktop/plugin.h"
#include "utils/messages.h"
#include "utils/url.h"
@@ -635,7 +634,7 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
SetComment(fname, content_get_url(gwin->bw->current_content));
}
#ifdef WITH_NS_SVG
- else if(content_get_type(gwin->bw->current_content) == CONTENT_SVG)
+ else if(ami_mime_compare(gwin->bw->current_content, "svg") == true)
{
if(ami_save_svg(gwin->bw->current_content,fname))
SetComment(fname, content_get_url(gwin->bw->current_content));
@@ -727,7 +726,7 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
ami_easy_clipboard_bitmap(bm);
}
#ifdef WITH_NS_SVG
- else if(content_get_type(gwin->bw->current_content) == CONTENT_SVG)
+ else if(ami_mime_compare(gwin->bw->current_content, "svg") == true)
{
ami_easy_clipboard_svg(gwin->bw->current_content);
}
@@ -895,13 +894,9 @@ static const ULONG ami_asl_mime_hook(struct Hook *mh,struct FileRequester *fr,st
AddPart(fname,ap->ap_Info.fib_FileName,1024);
mt = fetch_mimetype(fname);
- ct = content_lookup(mt);
+ ct = content_factory_type_from_mime_type(mt);
- if(ct != CONTENT_OTHER) ret = TRUE;
-
-#ifdef WITH_PLUGIN
- if(ct == CONTENT_PLUGIN) ret = plugin_handleable(mt);
-#endif
+ if(ct != CONTENT_NONE) ret = TRUE;
free(mt);
return ret;
@@ -952,7 +947,7 @@ void ami_menu_update_disabled(struct gui_window *g, hlcache_handle *c)
OffMenu(win,AMI_MENU_FIND);
#ifdef WITH_NS_SVG
- if(content_get_bitmap(c) || content_get_type(c) == CONTENT_SVG)
+ if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == true))
#else
if(content_get_bitmap(c))
#endif
diff --git a/amiga/plugin.c b/amiga/plugin.c
index e21a7c2fc..e68930283 100644
--- a/amiga/plugin.c
+++ b/amiga/plugin.c
@@ -26,25 +26,135 @@
#include "amiga/plugin.h"
#include "content/content_protected.h"
#include "desktop/plotters.h"
+#include "image/bitmap.h"
#include "render/box.h"
#include "utils/log.h"
#include "utils/messages.h"
+#include "utils/talloc.h"
#include <proto/datatypes.h>
#include <proto/intuition.h>
#include <datatypes/pictureclass.h>
+#include <intuition/classusr.h>
-bool plugin_create(struct content *c, const struct http_parameter *params)
+typedef struct plugin_content {
+ struct content base;
+
+ Object *dto;
+ int x;
+ int y;
+ int w;
+ int h;
+} plugin_content;
+
+static nserror plugin_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c);
+static bool plugin_convert(struct content *c);
+static void plugin_reformat(struct content *c, int width, int height);
+static void plugin_destroy(struct content *c);
+static bool plugin_redraw(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour);
+static void plugin_open(struct content *c, struct browser_window *bw,
+ struct content *page, struct box *box,
+ struct object_params *params);
+static void plugin_close(struct content *c);
+static nserror plugin_clone(const struct content *old, struct content **newc);
+static content_type plugin_content_type(lwc_string *mime_type);
+
+static const content_handler plugin_content_handler = {
+ plugin_create,
+ NULL,
+ plugin_convert,
+ plugin_reformat,
+ plugin_destroy,
+ NULL,
+ NULL,
+ NULL,
+ plugin_redraw,
+ NULL,
+ plugin_open,
+ plugin_close,
+ plugin_clone,
+ NULL,
+ plugin_content_type,
+ false
+};
+
+nserror plugin_init(void)
{
- LOG(("plugin_create"));
+ char dt_mime[50];
+ struct DataType *dt, *prevdt = NULL;
+ lwc_string *type;
+ lwc_error lerror;
+ nserror error;
- return true;
+ while((dt = ObtainDataType(DTST_RAM, NULL,
+ DTA_DataType, prevdt,
+ DTA_GroupID, GID_PICTURE, // we only support images for now
+ TAG_DONE)) != NULL)
+ {
+ ReleaseDataType(prevdt);
+ prevdt = dt;
+ ami_datatype_to_mimetype(dt, dt_mime);
+
+ LOG(("Guessed MIME from DT: %s", dt_mime));
+
+ lerror = lwc_intern_string(dt_mime, strlen(dt_mime), &type);
+ if (lerror != lwc_error_ok)
+ return NSERROR_NOMEM;
+
+ error = content_factory_register_handler(type,
+ &plugin_content_handler);
+
+ lwc_string_unref(type);
+
+ if (error != NSERROR_OK)
+ return error;
+
+ }
+
+ ReleaseDataType(prevdt);
+
+ return NSERROR_OK;
+}
+
+void plugin_fini(void)
+{
+ /* Nothing to do */
+}
+
+nserror plugin_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
+{
+ plugin_content *plugin;
+ nserror error;
+
+ plugin = talloc_zero(0, plugin_content);
+ if (plugin == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&plugin->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(plugin);
+ return error;
+ }
+
+ *c = (struct content *) plugin;
+
+ return NSERROR_OK;
}
bool plugin_convert(struct content *c)
{
LOG(("plugin_convert"));
+ plugin_content *plugin = (plugin_content *) c;
union content_msg_data msg_data;
int width, height;
char title[100];
@@ -60,7 +170,7 @@ bool plugin_convert(struct content *c)
data = (uint8 *)content__get_source_data(c, &size);
- if(c->data.plugin.dto = NewDTObject(NULL,
+ if(plugin->dto = NewDTObject(NULL,
DTA_SourceType, DTST_MEMORY,
DTA_SourceAddress, data,
DTA_SourceSize, size,
@@ -68,7 +178,7 @@ bool plugin_convert(struct content *c)
PDTA_DestMode, PMODE_V43,
TAG_DONE))
{
- if(GetDTAttrs(c->data.plugin.dto, PDTA_BitMapHeader, &bmh, TAG_DONE))
+ if(GetDTAttrs(plugin->dto, PDTA_BitMapHeader, &bmh, TAG_DONE))
{
width = (int)bmh->bmh_Width;
height = (int)bmh->bmh_Height;
@@ -82,7 +192,7 @@ bool plugin_convert(struct content *c)
bm_buffer = bitmap_get_buffer(c->bitmap);
- IDoMethod(c->data.plugin.dto, PDTM_READPIXELARRAY,
+ IDoMethod(plugin->dto, PDTM_READPIXELARRAY,
bm_buffer, bm_format, bitmap_get_rowstride(c->bitmap),
0, 0, width, height);
}
@@ -110,12 +220,14 @@ bool plugin_convert(struct content *c)
void plugin_destroy(struct content *c)
{
+ plugin_content *plugin = (plugin_content *) c;
+
LOG(("plugin_destroy"));
if (c->bitmap != NULL)
bitmap_destroy(c->bitmap);
- DisposeDTObject(c->data.plugin.dto);
+ DisposeDTObject(plugin->dto);
return;
}
@@ -161,57 +273,40 @@ void plugin_reformat(struct content *c, int width, int height)
return;
}
-bool plugin_clone(const struct content *old, struct content *new_content)
+nserror plugin_clone(const struct content *old, struct content **newc)
{
+ plugin_content *plugin;
+ nserror error;
+
LOG(("plugin_clone"));
- /* We "clone" the old content by replaying creation and conversion */
- if (plugin_create(new_content, NULL) == false)
- return false;
+ plugin = talloc_zero(0, plugin_content);
+ if (plugin == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &plugin->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&plugin->base);
+ return error;
+ }
+
+ /* We "clone" the old content by replaying conversion */
if (old->status == CONTENT_STATUS_READY ||
old->status == CONTENT_STATUS_DONE) {
- if (plugin_convert(new_content) == false)
- return false;
+ if (plugin_convert(&plugin->base) == false) {
+ content_destroy(&plugin->base);
+ return NSERROR_CLONE_FAILED;
+ }
}
- return true;
+ *newc = (struct content *) plugin;
+
+ return NSERROR_OK;
}
-/**
- * Determines whether a content is handleable by a plugin
- *
- * \param mime_type The mime type of the content
- * \return true if the content is handleable, false otherwise
- */
-bool plugin_handleable(const char *mime_type)
+content_type plugin_content_type(lwc_string *mime_type)
{
- LOG(("plugin_handleable %s", mime_type));
-
- char dt_mime[50];
- struct DataType *dt, *prevdt = NULL;
- bool found = false;
-
- while((dt = ObtainDataType(DTST_RAM, NULL,
- DTA_DataType, prevdt,
- DTA_GroupID, GID_PICTURE, // we only support images for now
- TAG_DONE)) != NULL)
- {
- ReleaseDataType(prevdt);
- prevdt = dt;
- ami_datatype_to_mimetype(dt, &dt_mime);
-
- LOG(("Guessed MIME from DT: %s", dt_mime));
-
- if(strcmp(dt_mime, mime_type) == 0)
- {
- found = true;
- break;
- }
- }
-
- ReleaseDataType(prevdt);
-
- return found;
+ return CONTENT_IMAGE;
}
#endif
diff --git a/amiga/plugin.h b/amiga/plugin.h
index 669c5af5a..605d989d4 100644
--- a/amiga/plugin.h
+++ b/amiga/plugin.h
@@ -19,19 +19,19 @@
#ifndef NETSURF_AMIGA_PLUGIN_H_
#define NETSURF_AMIGA_PLUGIN_H_
+#include "utils/config.h"
+#include "utils/errors.h"
+
#ifdef WITH_PLUGIN
-#include <intuition/classusr.h>
+nserror plugin_init(void);
+void plugin_fini(void);
-#include "desktop/plugin.h"
+#else
-struct content_plugin_data {
- Object *dto;
- int x;
- int y;
- int w;
- int h;
-};
+#define plugin_init() NSERROR_OK
+#define plugin_fini() ((void) 0)
#endif /* WITH_PLUGIN */
+
#endif
diff --git a/amiga/save_complete.c b/amiga/save_complete.c
index a1059b29a..592781ef8 100755
--- a/amiga/save_complete.c
+++ b/amiga/save_complete.c
@@ -40,8 +40,10 @@
*/
bool save_complete_gui_save(const char *path, const char *filename, size_t len,
- const char *sourcedata, content_type type)
+ const char *sourcedata, lwc_string *mime_type)
{
+ content_type type = content_factory_type_from_mime_type(
+ lwc_string_data(mime_type));
int res;
int namelen;
char deftype[5];