netsurf: branch chris/amiga-corewindow updated. release/3.6-146-ga9cc079

NetSurf Browser Project (Commit Mailer) no-reply at netsurf-browser.org
Mon Jan 2 12:58:27 GMT 2017


Gitweb links:

...log http://git.netsurf-browser.org/netsurf.git/shortlog/a9cc0792a43d108e5ff61055354422a6c7218a74
...commit http://git.netsurf-browser.org/netsurf.git/commit/a9cc0792a43d108e5ff61055354422a6c7218a74
...tree http://git.netsurf-browser.org/netsurf.git/tree/a9cc0792a43d108e5ff61055354422a6c7218a74

The branch, chris/amiga-corewindow has been updated
       via  a9cc0792a43d108e5ff61055354422a6c7218a74 (commit)
      from  dab118b6f7e9a22ed01413a2ce2fd60e4c4df97b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=a9cc0792a43d108e5ff61055354422a6c7218a74
commit a9cc0792a43d108e5ff61055354422a6c7218a74
Author: Chris Young <chris at unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris at unsatisfactorysoftware.co.uk>

    migrate sslcert to use corewindow
    predictably blank

diff --git a/frontends/amiga/corewindow.c b/frontends/amiga/corewindow.c
index f05d47b..5aff074 100644
--- a/frontends/amiga/corewindow.c
+++ b/frontends/amiga/corewindow.c
@@ -451,14 +451,18 @@ ami_cw_event(void *w)
 					default:
 						/* pass the event to the window owner */
 						if(ami_cw->event != NULL)
-							ami_cw->event(ami_cw, result);
+							if(ami_cw->event(ami_cw, result) == TRUE) {
+								return TRUE;
+							}
 					break;
 				}
 
 			default:
 				/* pass the event to the window owner */
 				if(ami_cw->event != NULL)
-					ami_cw->event(ami_cw, result);
+					if(ami_cw->event(ami_cw, result) == TRUE) {
+						return TRUE;
+					}
 			break;
 		}
 	};
@@ -603,10 +607,9 @@ nserror ami_corewindow_init(struct ami_corewindow *ami_cw)
 	/* set up the IDCMP hook for event processing (extended mouse, scrollbars) */
 	ami_cw->idcmp_hook.h_Entry = (void *)ami_cw_idcmp_hook;
 	ami_cw->idcmp_hook.h_Data = ami_cw;
-	/* probably set this when defining the window
-	SetAttrs(ami_cw->objects[GID_CW_WIN],
-		WINDOW_IDCMPHook, &ami_cw->idcmp_hook,
-		TAG_DONE); */
+
+	/* open the window */
+	ami_cw->win = (struct Window *)RA_OpenWindow(ami_cw->objects[GID_CW_WIN]);
 
 	/* attach the scrollbars for event processing _if they are in the window border_ */
 	if(ami_cw->objects[GID_CW_HSCROLL] == NULL) {
diff --git a/frontends/amiga/corewindow.h b/frontends/amiga/corewindow.h
index d8f80d3..f62987f 100644
--- a/frontends/amiga/corewindow.h
+++ b/frontends/amiga/corewindow.h
@@ -108,16 +108,16 @@ struct ami_corewindow {
 		 *
 		 * \param ami_cw The Amiga core window structure.
 		 * \param result event as returned by RA_HandleInput()
-		 * \return NSERROR_OK on sucess otherwise apropriate error code.
+ 		 * \return TRUE if window closed during event processing
 		 */
-		nserror (*event)(struct ami_corewindow *ami_cw, ULONG id);
+		BOOL (*event)(struct ami_corewindow *ami_cw, ULONG result);
 
 		/**
 		 * callback to close an Amiga core window
 		 *
 		 * \param ami_cw The Amiga core window structure.
 		 */
-		nserror (*close)(struct ami_corewindow *ami_cw);
+		void (*close)(struct ami_corewindow *ami_cw);
 
 };
 
diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c
index 9499ff8..1508135 100644
--- a/frontends/amiga/gui.c
+++ b/frontends/amiga/gui.c
@@ -5610,7 +5610,7 @@ static struct gui_misc_table amiga_misc_table = {
 
 	.quit = gui_quit,
 	.launch_url = gui_launch_url,
-	.cert_verify = gui_cert_verify,
+	.cert_verify = ami_cert_verify,
 	.login = gui_401login_open,
 };
 
diff --git a/frontends/amiga/sslcert.c b/frontends/amiga/sslcert.c
index 83798f2..df0005e 100644
--- a/frontends/amiga/sslcert.c
+++ b/frontends/amiga/sslcert.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Chris Young <chris at unsatisfactorysoftware.co.uk>
+ * Copyright 2017 Chris Young <chris at unsatisfactorysoftware.co.uk>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -16,39 +16,340 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <proto/exec.h>
+/**
+ * \file
+ * Implementation of Amiga certificate viewing using core windows.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <proto/intuition.h>
+#include <intuition/icclass.h>
+
+#include <classes/window.h>
+#include <gadgets/button.h>
+#include <gadgets/layout.h>
+#include <gadgets/space.h>
+#include <images/label.h>
+
+#include <reaction/reaction_macros.h>
 
-#include "utils/nsurl.h"
-#include "content/llcache.h"
-#include "netsurf/mouse.h"
-#include "netsurf/window.h"
+#include "utils/log.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
 #include "desktop/sslcert_viewer.h"
+#include "utils/messages.h"
 
-#include "amiga/tree.h"
+#include "amiga/corewindow.h"
+#include "amiga/libs.h"
 #include "amiga/sslcert.h"
+#include "amiga/utf8.h"
+
+
+/**
+ * Amiga certificate viewing window context
+ */
+enum {
+	GID_SSLCERT_ACCEPT = GID_CW_LAST,
+	GID_SSLCERT_REJECT,
+	GID_SSLCERT_LAST
+};
+
+#define GID_SSLCERT_SIZE GID_SSLCERT_LAST - GID_CW_LAST
+
+struct ami_crtvrfy_window {
+	/** Amiga core window context */
+	struct ami_corewindow core;
+
+	/** Amiga GUI stuff */
+	Object *sslcert_objects[GID_SSLCERT_LAST]; // technically wasting a few bytes here
+
+	char *wintitle;
+	char *sslerr;
+	char *sslaccept;
+	char *sslreject;
+
+	/** SSL certificate viewer context data */
+	struct sslcert_session_data *ssl_data;
+};
+
+/**
+ * destroy a previously created certificate view
+ */
+static nserror
+ami_crtvrfy_destroy(struct ami_crtvrfy_window *crtvrfy_win)
+{
+	nserror res;
+
+	res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+	if (res == NSERROR_OK) {
+		res = ami_corewindow_fini(&crtvrfy_win->core); /* closes the window for us */
+		ami_utf8_free(crtvrfy_win->wintitle);
+		ami_utf8_free(crtvrfy_win->sslerr);
+		ami_utf8_free(crtvrfy_win->sslaccept);
+		ami_utf8_free(crtvrfy_win->sslreject);
+		free(crtvrfy_win);
+	}
+	return res;
+}
 
-nserror gui_cert_verify(nsurl *url, 
-		const struct ssl_cert_info *certs, unsigned long num,
-		nserror (*cb)(bool proceed, void *pw), void *cbpw)
+static void
+ami_crtvrfy_accept(struct ami_corewindow *ami_cw)
 {
-	struct sslcert_session_data *data;
-	struct treeview_window *ssl_window;
+	struct ami_crtvrfy_window *crtvrfy_win;
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
 
-	sslcert_viewer_create_session_data(num, url, cb, cbpw,
-			certs, &data);
-	ssl_current_session = data;
+	sslcert_viewer_accept(crtvrfy_win->ssl_data);
 
-	ssl_window = ami_tree_create(TREE_SSLCERT, data);
-	if (!ssl_window) {
-		return NSERROR_INIT_FAILED;
+	ami_crtvrfy_destroy(crtvrfy_win);
+}
+
+static void
+ami_crtvrfy_reject(struct ami_corewindow *ami_cw)
+{
+	struct ami_crtvrfy_window *crtvrfy_win;
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	sslcert_viewer_reject(crtvrfy_win->ssl_data);
+
+	ami_crtvrfy_destroy(crtvrfy_win);
+}
+
+/**
+ * callback for unknown events on Amiga core window
+ * eg. buttons in the ssl cert window
+ * (result & WMHI_CLASSMASK) gives the class of event (eg. WMHI_GADGETUP)
+ * (result & WMHI_GADGETMASK) gives the gadget ID (eg. GID_SSLCERT_ACCEPT)
+ *
+ * \param ami_cw The Amiga core window structure.
+ * \param result event as returned by RA_HandleInput()
+ * \return TRUE if window closed during event processing
+ */
+static BOOL
+ami_crtvrfy_event(struct ami_corewindow *ami_cw, ULONG result)
+{
+	if((result & WMHI_CLASSMASK) == WMHI_GADGETUP) {
+		switch(result & WMHI_GADGETMASK) {
+			case GID_SSLCERT_ACCEPT:
+				ami_crtvrfy_accept(ami_cw);
+				return TRUE;
+			break;
+
+			case GID_SSLCERT_REJECT:
+				ami_crtvrfy_reject(ami_cw);
+				return TRUE;
+			break;
+		}
 	}
+	return FALSE;
+}
 
-	ami_tree_open(ssl_window, AMI_TREE_SSLCERT);
+/**
+ * callback for mouse action for certificate verify on core window
+ *
+ * \param ami_cw The Amiga core window structure.
+ * \param mouse_state netsurf mouse state on event
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+ami_crtvrfy_mouse(struct ami_corewindow *ami_cw,
+					browser_mouse_state mouse_state,
+					int x, int y)
+{
+	struct ami_crtvrfy_window *crtvrfy_win;
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
 
 	return NSERROR_OK;
 }
 
-void ami_ssl_free(struct treeview_window *twin)
+/**
+ * callback for keypress for certificate verify on core window
+ *
+ * \param example_cw The Amiga core window structure.
+ * \param nskey The netsurf key code
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+ami_crtvrfy_key(struct ami_corewindow *ami_cw, uint32_t nskey)
 {
-	ami_tree_destroy(twin);
+	struct ami_crtvrfy_window *crtvrfy_win;
+
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+			return NSERROR_OK;
+	}
+	return NSERROR_NOT_IMPLEMENTED;
+}
+
+/**
+ * callback on draw event for certificate verify on core window
+ *
+ * \param ami_cw The Amiga core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \param ctx The drawing context
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+ami_crtvrfy_draw(struct ami_corewindow *ami_cw, struct rect *r, struct redraw_context *ctx)
+{
+	struct ami_crtvrfy_window *crtvrfy_win;
+
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, ctx);
+
+	return NSERROR_OK;
+}
+
+static nserror
+ami_crtvrfy_create_window(struct ami_crtvrfy_window *crtvrfy_win)
+{
+	struct ami_corewindow *ami_cw = (struct ami_corewindow *)&crtvrfy_win->core;
+
+	ami_cw->objects[GID_CW_WIN] = WindowObj,
+  	    WA_ScreenTitle, ami_gui_get_screen_title(),
+       	WA_Title, crtvrfy_win->wintitle,
+       	WA_Activate, TRUE,
+       	WA_DepthGadget, TRUE,
+       	WA_DragBar, TRUE,
+       	WA_CloseGadget, TRUE,
+       	WA_SizeGadget, TRUE,
+		WA_SizeBRight, TRUE,
+		WA_Height, scrn->Height / 2,
+		WA_PubScreen, scrn,
+		WA_ReportMouse, TRUE,
+       	WA_IDCMP, IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE |
+				IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE |
+				IDCMP_EXTENDEDMOUSE | IDCMP_SIZEVERIFY,
+		WINDOW_HorizProp, 1,
+		WINDOW_VertProp, 1,
+		WINDOW_IDCMPHook, &ami_cw->idcmp_hook,
+		WINDOW_IDCMPHookBits, IDCMP_IDCMPUPDATE | IDCMP_EXTENDEDMOUSE,
+		WINDOW_SharedPort, sport,
+		WINDOW_UserData, crtvrfy_win,
+		/* WINDOW_NewMenu, twin->menu,   -> No menu for SSL Cert */
+		WINDOW_IconifyGadget, FALSE,
+		WINDOW_Position, WPOS_CENTERSCREEN,
+		WINDOW_ParentGroup, ami_cw->objects[GID_CW_MAIN] = LayoutVObj,
+			LAYOUT_AddImage, LabelObj,
+				LABEL_Text, crtvrfy_win->sslerr,
+			LabelEnd,
+			LAYOUT_AddChild, ami_cw->objects[GID_CW_DRAW] = SpaceObj,
+				GA_ID, GID_CW_DRAW,
+				SPACE_Transparent, TRUE,
+				SPACE_BevelStyle, BVS_DISPLAY,
+				GA_RelVerify, TRUE,
+				ICA_TARGET, ICTARGET_IDCMP,
+   			SpaceEnd,
+			LAYOUT_AddChild, LayoutHObj,
+				LAYOUT_AddChild, crtvrfy_win->sslcert_objects[GID_SSLCERT_ACCEPT] = ButtonObj,
+					GA_ID, GID_SSLCERT_ACCEPT,
+					GA_Text, crtvrfy_win->sslaccept,
+					GA_RelVerify, TRUE,
+				ButtonEnd,
+				LAYOUT_AddChild, crtvrfy_win->sslcert_objects[GID_SSLCERT_REJECT] = ButtonObj,
+					GA_ID, GID_SSLCERT_REJECT,
+					GA_Text, crtvrfy_win->sslreject,
+					GA_RelVerify, TRUE,
+				ButtonEnd,
+			EndGroup,
+			CHILD_WeightedHeight, 0,
+		EndGroup,
+	EndWindow;
+
+	if(ami_cw->objects[GID_CW_WIN] == NULL) {
+		return NSERROR_NOMEM;
+	}
+
+	return NSERROR_OK;
 }
+
+/* exported interface documented in amiga/ssl_cert.h */
+nserror ami_cert_verify(struct nsurl *url,
+						const struct ssl_cert_info *certs,
+						unsigned long num,
+						nserror (*cb)(bool proceed, void *pw),
+						void *cbpw)
+{
+	struct ami_crtvrfy_window *ncwin;
+	nserror res;
+
+	ncwin = malloc(sizeof(struct ami_crtvrfy_window));
+	if (ncwin == NULL) {
+		return NSERROR_NOMEM;
+	}
+
+	ncwin->wintitle = ami_utf8_easy((char *)messages_get("SSLCerts"));
+	ncwin->sslerr = ami_utf8_easy((char *)messages_get("SSLError"));
+	ncwin->sslaccept = ami_utf8_easy((char *)messages_get("SSL_Certificate_Accept"));
+	ncwin->sslreject = ami_utf8_easy((char *)messages_get("SSL_Certificate_Reject"));
+
+	res = ami_crtvrfy_create_window(ncwin);
+	if (res != NSERROR_OK) {
+		LOG("SSL UI builder init failed");
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		free(ncwin);
+		return res;
+	}
+
+	/* initialise example core window */
+	ncwin->core.draw = ami_crtvrfy_draw;
+	ncwin->core.key = ami_crtvrfy_key;
+	ncwin->core.mouse = ami_crtvrfy_mouse;
+	ncwin->core.close = ami_crtvrfy_reject;
+	ncwin->core.event = ami_crtvrfy_event;
+
+	res = ami_corewindow_init(&ncwin->core);
+	if (res != NSERROR_OK) {
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		DisposeObject(ncwin->core.objects[GID_CW_WIN]);
+		free(ncwin);
+		return res;
+	}
+
+	/* initialise certificate viewing interface */
+	res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
+									   &ncwin->ssl_data);
+	if (res != NSERROR_OK) {
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		DisposeObject(ncwin->core.objects[GID_CW_WIN]);
+		free(ncwin);
+		return res;
+	}
+
+	res = sslcert_viewer_init(ncwin->core.cb_table,
+							  (struct core_window *)ncwin,
+							  ncwin->ssl_data);
+	if (res != NSERROR_OK) {
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		DisposeObject(ncwin->core.objects[GID_CW_WIN]);
+		free(ncwin);
+		return res;
+	}
+
+	return NSERROR_OK;
+}
+
diff --git a/frontends/amiga/sslcert.h b/frontends/amiga/sslcert.h
index 86ce9c4..4718e75 100644
--- a/frontends/amiga/sslcert.h
+++ b/frontends/amiga/sslcert.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Chris Young <chris at unsatisfactorysoftware.co.uk>
+ * Copyright 2017 Chris Young <chris at unsatisfactorysoftware.co.uk>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -18,11 +18,21 @@
 
 #ifndef AMIGA_SSLCERT_H
 #define AMIGA_SSLCERT_H
+struct nsurl;
+struct ssl_cert_info;
 
-nserror gui_cert_verify(nsurl *url, 
+/**
+ * Prompt the user to verify a certificate with issues.
+ *
+ * \param url The URL being verified.
+ * \param certs The certificate to be verified
+ * \param num The number of certificates to be verified.
+ * \param cb Callback upon user decision.
+ * \param cbpw Context pointer passed to cb
+ * \return NSERROR_OK or error code if prompt creation failed.
+ */
+nserror ami_cert_verify(struct nsurl *url, 
 		const struct ssl_cert_info *certs, unsigned long num,
 		     nserror (*cb)(bool proceed, void *pw), void *cbpw);
-
-void ami_ssl_free(struct treeview_window *twin);
-
 #endif
+
diff --git a/frontends/amiga/tree.c b/frontends/amiga/tree.c
index f1c5327..b9747c0 100644
--- a/frontends/amiga/tree.c
+++ b/frontends/amiga/tree.c
@@ -916,7 +916,7 @@ void ami_tree_close(void *w)
 		ami_utf8_free(twin->sslerr);
 		ami_utf8_free(twin->sslaccept);
 		ami_utf8_free(twin->sslreject);
-		ami_ssl_free(twin);
+		//ami_ssl_free(twin);
 	}
 
 	if(twin->type == AMI_TREE_HOTLIST)


-----------------------------------------------------------------------

Summary of changes:
 frontends/amiga/corewindow.c |   15 +-
 frontends/amiga/corewindow.h |    6 +-
 frontends/amiga/gui.c        |    2 +-
 frontends/amiga/sslcert.c    |  343 +++++++++++++++++++++++++++++++++++++++---
 frontends/amiga/sslcert.h    |   20 ++-
 frontends/amiga/tree.c       |    2 +-
 6 files changed, 351 insertions(+), 37 deletions(-)

diff --git a/frontends/amiga/corewindow.c b/frontends/amiga/corewindow.c
index f05d47b..5aff074 100644
--- a/frontends/amiga/corewindow.c
+++ b/frontends/amiga/corewindow.c
@@ -451,14 +451,18 @@ ami_cw_event(void *w)
 					default:
 						/* pass the event to the window owner */
 						if(ami_cw->event != NULL)
-							ami_cw->event(ami_cw, result);
+							if(ami_cw->event(ami_cw, result) == TRUE) {
+								return TRUE;
+							}
 					break;
 				}
 
 			default:
 				/* pass the event to the window owner */
 				if(ami_cw->event != NULL)
-					ami_cw->event(ami_cw, result);
+					if(ami_cw->event(ami_cw, result) == TRUE) {
+						return TRUE;
+					}
 			break;
 		}
 	};
@@ -603,10 +607,9 @@ nserror ami_corewindow_init(struct ami_corewindow *ami_cw)
 	/* set up the IDCMP hook for event processing (extended mouse, scrollbars) */
 	ami_cw->idcmp_hook.h_Entry = (void *)ami_cw_idcmp_hook;
 	ami_cw->idcmp_hook.h_Data = ami_cw;
-	/* probably set this when defining the window
-	SetAttrs(ami_cw->objects[GID_CW_WIN],
-		WINDOW_IDCMPHook, &ami_cw->idcmp_hook,
-		TAG_DONE); */
+
+	/* open the window */
+	ami_cw->win = (struct Window *)RA_OpenWindow(ami_cw->objects[GID_CW_WIN]);
 
 	/* attach the scrollbars for event processing _if they are in the window border_ */
 	if(ami_cw->objects[GID_CW_HSCROLL] == NULL) {
diff --git a/frontends/amiga/corewindow.h b/frontends/amiga/corewindow.h
index d8f80d3..f62987f 100644
--- a/frontends/amiga/corewindow.h
+++ b/frontends/amiga/corewindow.h
@@ -108,16 +108,16 @@ struct ami_corewindow {
 		 *
 		 * \param ami_cw The Amiga core window structure.
 		 * \param result event as returned by RA_HandleInput()
-		 * \return NSERROR_OK on sucess otherwise apropriate error code.
+ 		 * \return TRUE if window closed during event processing
 		 */
-		nserror (*event)(struct ami_corewindow *ami_cw, ULONG id);
+		BOOL (*event)(struct ami_corewindow *ami_cw, ULONG result);
 
 		/**
 		 * callback to close an Amiga core window
 		 *
 		 * \param ami_cw The Amiga core window structure.
 		 */
-		nserror (*close)(struct ami_corewindow *ami_cw);
+		void (*close)(struct ami_corewindow *ami_cw);
 
 };
 
diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c
index 9499ff8..1508135 100644
--- a/frontends/amiga/gui.c
+++ b/frontends/amiga/gui.c
@@ -5610,7 +5610,7 @@ static struct gui_misc_table amiga_misc_table = {
 
 	.quit = gui_quit,
 	.launch_url = gui_launch_url,
-	.cert_verify = gui_cert_verify,
+	.cert_verify = ami_cert_verify,
 	.login = gui_401login_open,
 };
 
diff --git a/frontends/amiga/sslcert.c b/frontends/amiga/sslcert.c
index 83798f2..df0005e 100644
--- a/frontends/amiga/sslcert.c
+++ b/frontends/amiga/sslcert.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Chris Young <chris at unsatisfactorysoftware.co.uk>
+ * Copyright 2017 Chris Young <chris at unsatisfactorysoftware.co.uk>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -16,39 +16,340 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <proto/exec.h>
+/**
+ * \file
+ * Implementation of Amiga certificate viewing using core windows.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <proto/intuition.h>
+#include <intuition/icclass.h>
+
+#include <classes/window.h>
+#include <gadgets/button.h>
+#include <gadgets/layout.h>
+#include <gadgets/space.h>
+#include <images/label.h>
+
+#include <reaction/reaction_macros.h>
 
-#include "utils/nsurl.h"
-#include "content/llcache.h"
-#include "netsurf/mouse.h"
-#include "netsurf/window.h"
+#include "utils/log.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
 #include "desktop/sslcert_viewer.h"
+#include "utils/messages.h"
 
-#include "amiga/tree.h"
+#include "amiga/corewindow.h"
+#include "amiga/libs.h"
 #include "amiga/sslcert.h"
+#include "amiga/utf8.h"
+
+
+/**
+ * Amiga certificate viewing window context
+ */
+enum {
+	GID_SSLCERT_ACCEPT = GID_CW_LAST,
+	GID_SSLCERT_REJECT,
+	GID_SSLCERT_LAST
+};
+
+#define GID_SSLCERT_SIZE GID_SSLCERT_LAST - GID_CW_LAST
+
+struct ami_crtvrfy_window {
+	/** Amiga core window context */
+	struct ami_corewindow core;
+
+	/** Amiga GUI stuff */
+	Object *sslcert_objects[GID_SSLCERT_LAST]; // technically wasting a few bytes here
+
+	char *wintitle;
+	char *sslerr;
+	char *sslaccept;
+	char *sslreject;
+
+	/** SSL certificate viewer context data */
+	struct sslcert_session_data *ssl_data;
+};
+
+/**
+ * destroy a previously created certificate view
+ */
+static nserror
+ami_crtvrfy_destroy(struct ami_crtvrfy_window *crtvrfy_win)
+{
+	nserror res;
+
+	res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+	if (res == NSERROR_OK) {
+		res = ami_corewindow_fini(&crtvrfy_win->core); /* closes the window for us */
+		ami_utf8_free(crtvrfy_win->wintitle);
+		ami_utf8_free(crtvrfy_win->sslerr);
+		ami_utf8_free(crtvrfy_win->sslaccept);
+		ami_utf8_free(crtvrfy_win->sslreject);
+		free(crtvrfy_win);
+	}
+	return res;
+}
 
-nserror gui_cert_verify(nsurl *url, 
-		const struct ssl_cert_info *certs, unsigned long num,
-		nserror (*cb)(bool proceed, void *pw), void *cbpw)
+static void
+ami_crtvrfy_accept(struct ami_corewindow *ami_cw)
 {
-	struct sslcert_session_data *data;
-	struct treeview_window *ssl_window;
+	struct ami_crtvrfy_window *crtvrfy_win;
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
 
-	sslcert_viewer_create_session_data(num, url, cb, cbpw,
-			certs, &data);
-	ssl_current_session = data;
+	sslcert_viewer_accept(crtvrfy_win->ssl_data);
 
-	ssl_window = ami_tree_create(TREE_SSLCERT, data);
-	if (!ssl_window) {
-		return NSERROR_INIT_FAILED;
+	ami_crtvrfy_destroy(crtvrfy_win);
+}
+
+static void
+ami_crtvrfy_reject(struct ami_corewindow *ami_cw)
+{
+	struct ami_crtvrfy_window *crtvrfy_win;
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	sslcert_viewer_reject(crtvrfy_win->ssl_data);
+
+	ami_crtvrfy_destroy(crtvrfy_win);
+}
+
+/**
+ * callback for unknown events on Amiga core window
+ * eg. buttons in the ssl cert window
+ * (result & WMHI_CLASSMASK) gives the class of event (eg. WMHI_GADGETUP)
+ * (result & WMHI_GADGETMASK) gives the gadget ID (eg. GID_SSLCERT_ACCEPT)
+ *
+ * \param ami_cw The Amiga core window structure.
+ * \param result event as returned by RA_HandleInput()
+ * \return TRUE if window closed during event processing
+ */
+static BOOL
+ami_crtvrfy_event(struct ami_corewindow *ami_cw, ULONG result)
+{
+	if((result & WMHI_CLASSMASK) == WMHI_GADGETUP) {
+		switch(result & WMHI_GADGETMASK) {
+			case GID_SSLCERT_ACCEPT:
+				ami_crtvrfy_accept(ami_cw);
+				return TRUE;
+			break;
+
+			case GID_SSLCERT_REJECT:
+				ami_crtvrfy_reject(ami_cw);
+				return TRUE;
+			break;
+		}
 	}
+	return FALSE;
+}
 
-	ami_tree_open(ssl_window, AMI_TREE_SSLCERT);
+/**
+ * callback for mouse action for certificate verify on core window
+ *
+ * \param ami_cw The Amiga core window structure.
+ * \param mouse_state netsurf mouse state on event
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+ami_crtvrfy_mouse(struct ami_corewindow *ami_cw,
+					browser_mouse_state mouse_state,
+					int x, int y)
+{
+	struct ami_crtvrfy_window *crtvrfy_win;
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
 
 	return NSERROR_OK;
 }
 
-void ami_ssl_free(struct treeview_window *twin)
+/**
+ * callback for keypress for certificate verify on core window
+ *
+ * \param example_cw The Amiga core window structure.
+ * \param nskey The netsurf key code
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+ami_crtvrfy_key(struct ami_corewindow *ami_cw, uint32_t nskey)
 {
-	ami_tree_destroy(twin);
+	struct ami_crtvrfy_window *crtvrfy_win;
+
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+			return NSERROR_OK;
+	}
+	return NSERROR_NOT_IMPLEMENTED;
+}
+
+/**
+ * callback on draw event for certificate verify on core window
+ *
+ * \param ami_cw The Amiga core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \param ctx The drawing context
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+ami_crtvrfy_draw(struct ami_corewindow *ami_cw, struct rect *r, struct redraw_context *ctx)
+{
+	struct ami_crtvrfy_window *crtvrfy_win;
+
+	/* technically degenerate container of */
+	crtvrfy_win = (struct ami_crtvrfy_window *)ami_cw;
+
+	sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, ctx);
+
+	return NSERROR_OK;
+}
+
+static nserror
+ami_crtvrfy_create_window(struct ami_crtvrfy_window *crtvrfy_win)
+{
+	struct ami_corewindow *ami_cw = (struct ami_corewindow *)&crtvrfy_win->core;
+
+	ami_cw->objects[GID_CW_WIN] = WindowObj,
+  	    WA_ScreenTitle, ami_gui_get_screen_title(),
+       	WA_Title, crtvrfy_win->wintitle,
+       	WA_Activate, TRUE,
+       	WA_DepthGadget, TRUE,
+       	WA_DragBar, TRUE,
+       	WA_CloseGadget, TRUE,
+       	WA_SizeGadget, TRUE,
+		WA_SizeBRight, TRUE,
+		WA_Height, scrn->Height / 2,
+		WA_PubScreen, scrn,
+		WA_ReportMouse, TRUE,
+       	WA_IDCMP, IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE |
+				IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE |
+				IDCMP_EXTENDEDMOUSE | IDCMP_SIZEVERIFY,
+		WINDOW_HorizProp, 1,
+		WINDOW_VertProp, 1,
+		WINDOW_IDCMPHook, &ami_cw->idcmp_hook,
+		WINDOW_IDCMPHookBits, IDCMP_IDCMPUPDATE | IDCMP_EXTENDEDMOUSE,
+		WINDOW_SharedPort, sport,
+		WINDOW_UserData, crtvrfy_win,
+		/* WINDOW_NewMenu, twin->menu,   -> No menu for SSL Cert */
+		WINDOW_IconifyGadget, FALSE,
+		WINDOW_Position, WPOS_CENTERSCREEN,
+		WINDOW_ParentGroup, ami_cw->objects[GID_CW_MAIN] = LayoutVObj,
+			LAYOUT_AddImage, LabelObj,
+				LABEL_Text, crtvrfy_win->sslerr,
+			LabelEnd,
+			LAYOUT_AddChild, ami_cw->objects[GID_CW_DRAW] = SpaceObj,
+				GA_ID, GID_CW_DRAW,
+				SPACE_Transparent, TRUE,
+				SPACE_BevelStyle, BVS_DISPLAY,
+				GA_RelVerify, TRUE,
+				ICA_TARGET, ICTARGET_IDCMP,
+   			SpaceEnd,
+			LAYOUT_AddChild, LayoutHObj,
+				LAYOUT_AddChild, crtvrfy_win->sslcert_objects[GID_SSLCERT_ACCEPT] = ButtonObj,
+					GA_ID, GID_SSLCERT_ACCEPT,
+					GA_Text, crtvrfy_win->sslaccept,
+					GA_RelVerify, TRUE,
+				ButtonEnd,
+				LAYOUT_AddChild, crtvrfy_win->sslcert_objects[GID_SSLCERT_REJECT] = ButtonObj,
+					GA_ID, GID_SSLCERT_REJECT,
+					GA_Text, crtvrfy_win->sslreject,
+					GA_RelVerify, TRUE,
+				ButtonEnd,
+			EndGroup,
+			CHILD_WeightedHeight, 0,
+		EndGroup,
+	EndWindow;
+
+	if(ami_cw->objects[GID_CW_WIN] == NULL) {
+		return NSERROR_NOMEM;
+	}
+
+	return NSERROR_OK;
 }
+
+/* exported interface documented in amiga/ssl_cert.h */
+nserror ami_cert_verify(struct nsurl *url,
+						const struct ssl_cert_info *certs,
+						unsigned long num,
+						nserror (*cb)(bool proceed, void *pw),
+						void *cbpw)
+{
+	struct ami_crtvrfy_window *ncwin;
+	nserror res;
+
+	ncwin = malloc(sizeof(struct ami_crtvrfy_window));
+	if (ncwin == NULL) {
+		return NSERROR_NOMEM;
+	}
+
+	ncwin->wintitle = ami_utf8_easy((char *)messages_get("SSLCerts"));
+	ncwin->sslerr = ami_utf8_easy((char *)messages_get("SSLError"));
+	ncwin->sslaccept = ami_utf8_easy((char *)messages_get("SSL_Certificate_Accept"));
+	ncwin->sslreject = ami_utf8_easy((char *)messages_get("SSL_Certificate_Reject"));
+
+	res = ami_crtvrfy_create_window(ncwin);
+	if (res != NSERROR_OK) {
+		LOG("SSL UI builder init failed");
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		free(ncwin);
+		return res;
+	}
+
+	/* initialise example core window */
+	ncwin->core.draw = ami_crtvrfy_draw;
+	ncwin->core.key = ami_crtvrfy_key;
+	ncwin->core.mouse = ami_crtvrfy_mouse;
+	ncwin->core.close = ami_crtvrfy_reject;
+	ncwin->core.event = ami_crtvrfy_event;
+
+	res = ami_corewindow_init(&ncwin->core);
+	if (res != NSERROR_OK) {
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		DisposeObject(ncwin->core.objects[GID_CW_WIN]);
+		free(ncwin);
+		return res;
+	}
+
+	/* initialise certificate viewing interface */
+	res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
+									   &ncwin->ssl_data);
+	if (res != NSERROR_OK) {
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		DisposeObject(ncwin->core.objects[GID_CW_WIN]);
+		free(ncwin);
+		return res;
+	}
+
+	res = sslcert_viewer_init(ncwin->core.cb_table,
+							  (struct core_window *)ncwin,
+							  ncwin->ssl_data);
+	if (res != NSERROR_OK) {
+		ami_utf8_free(ncwin->wintitle);
+		ami_utf8_free(ncwin->sslerr);
+		ami_utf8_free(ncwin->sslaccept);
+		ami_utf8_free(ncwin->sslreject);
+		DisposeObject(ncwin->core.objects[GID_CW_WIN]);
+		free(ncwin);
+		return res;
+	}
+
+	return NSERROR_OK;
+}
+
diff --git a/frontends/amiga/sslcert.h b/frontends/amiga/sslcert.h
index 86ce9c4..4718e75 100644
--- a/frontends/amiga/sslcert.h
+++ b/frontends/amiga/sslcert.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Chris Young <chris at unsatisfactorysoftware.co.uk>
+ * Copyright 2017 Chris Young <chris at unsatisfactorysoftware.co.uk>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -18,11 +18,21 @@
 
 #ifndef AMIGA_SSLCERT_H
 #define AMIGA_SSLCERT_H
+struct nsurl;
+struct ssl_cert_info;
 
-nserror gui_cert_verify(nsurl *url, 
+/**
+ * Prompt the user to verify a certificate with issues.
+ *
+ * \param url The URL being verified.
+ * \param certs The certificate to be verified
+ * \param num The number of certificates to be verified.
+ * \param cb Callback upon user decision.
+ * \param cbpw Context pointer passed to cb
+ * \return NSERROR_OK or error code if prompt creation failed.
+ */
+nserror ami_cert_verify(struct nsurl *url, 
 		const struct ssl_cert_info *certs, unsigned long num,
 		     nserror (*cb)(bool proceed, void *pw), void *cbpw);
-
-void ami_ssl_free(struct treeview_window *twin);
-
 #endif
+
diff --git a/frontends/amiga/tree.c b/frontends/amiga/tree.c
index f1c5327..b9747c0 100644
--- a/frontends/amiga/tree.c
+++ b/frontends/amiga/tree.c
@@ -916,7 +916,7 @@ void ami_tree_close(void *w)
 		ami_utf8_free(twin->sslerr);
 		ami_utf8_free(twin->sslaccept);
 		ami_utf8_free(twin->sslreject);
-		ami_ssl_free(twin);
+		//ami_ssl_free(twin);
 	}
 
 	if(twin->type == AMI_TREE_HOTLIST)


-- 
NetSurf Browser



More information about the netsurf-commits mailing list