From 08e2cc32bab262979126837b82de6db2922b9afb Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 1 Dec 2019 16:20:42 +0000 Subject: repurpose ssl certificate core window for nitial page infor window on gtk --- frontends/gtk/Makefile | 2 +- frontends/gtk/gui.c | 1 - frontends/gtk/page_info.c | 268 ++++++++++++++++++++++++++++++++++++++++++++++ frontends/gtk/page_info.h | 30 ++++++ frontends/gtk/ssl_cert.c | 259 -------------------------------------------- frontends/gtk/ssl_cert.h | 37 ------- frontends/gtk/toolbar.c | 36 +++++++ 7 files changed, 335 insertions(+), 298 deletions(-) create mode 100644 frontends/gtk/page_info.c create mode 100644 frontends/gtk/page_info.h delete mode 100644 frontends/gtk/ssl_cert.c delete mode 100644 frontends/gtk/ssl_cert.h diff --git a/frontends/gtk/Makefile b/frontends/gtk/Makefile index 2f151e7b7..ae2e856ab 100644 --- a/frontends/gtk/Makefile +++ b/frontends/gtk/Makefile @@ -169,7 +169,7 @@ S_FRONTEND := gui.c schedule.c layout_pango.c bitmap.c plotters.c \ selection.c window.c fetch.c download.c menu.c print.c \ search.c tabs.c toolbar.c gettext.c compat.c viewdata.c \ viewsource.c preferences.c about.c resources.c corewindow.c \ - local_history.c global_history.c cookies.c hotlist.c ssl_cert.c + local_history.c global_history.c cookies.c hotlist.c page_info.c # This is the final source build list # Note this is deliberately *not* expanded here as common and image diff --git a/frontends/gtk/gui.c b/frontends/gtk/gui.c index 351b00281..609662e05 100644 --- a/frontends/gtk/gui.c +++ b/frontends/gtk/gui.c @@ -69,7 +69,6 @@ #include "gtk/schedule.h" #include "gtk/selection.h" #include "gtk/search.h" -#include "gtk/ssl_cert.h" #include "gtk/bitmap.h" #include "gtk/resources.h" #include "gtk/layout_pango.h" diff --git a/frontends/gtk/page_info.c b/frontends/gtk/page_info.c new file mode 100644 index 000000000..adc2dfa66 --- /dev/null +++ b/frontends/gtk/page_info.c @@ -0,0 +1,268 @@ +/* + * Copyright 2015 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file + * Implementation of gtk certificate viewing using gtk core windows. + */ + +#include +#include +#include + +#include "utils/log.h" +#include "netsurf/keypress.h" +#include "netsurf/plotters.h" +#include "netsurf/browser_window.h" +#include "desktop/sslcert_viewer.h" + +#include "gtk/plotters.h" +#include "gtk/scaffolding.h" +#include "gtk/resources.h" +#include "gtk/page_info.h" +#include "gtk/corewindow.h" + + +/** + * GTK certificate viewing window context + */ +struct nsgtk_crtvrfy_window { + /** GTK core window context */ + struct nsgtk_corewindow core; + /** GTK builder for window */ + GtkBuilder *builder; + /** GTK dialog window being shown */ + GtkDialog *dlg; + /** SSL certificate viewer context data */ + struct sslcert_session_data *ssl_data; +}; + +/** + * destroy a previously created certificate view + */ +static nserror nsgtk_crtvrfy_destroy(struct nsgtk_crtvrfy_window *crtvrfy_win) +{ + nserror res; + + res = sslcert_viewer_fini(crtvrfy_win->ssl_data); + if (res == NSERROR_OK) { + res = nsgtk_corewindow_fini(&crtvrfy_win->core); + gtk_widget_destroy(GTK_WIDGET(crtvrfy_win->dlg)); + g_object_unref(G_OBJECT(crtvrfy_win->builder)); + free(crtvrfy_win); + } + return res; +} + +static void +nsgtk_crtvrfy_accept(GtkButton *w, gpointer data) +{ + struct nsgtk_crtvrfy_window *crtvrfy_win; + crtvrfy_win = (struct nsgtk_crtvrfy_window *)data; + + sslcert_viewer_accept(crtvrfy_win->ssl_data); + + nsgtk_crtvrfy_destroy(crtvrfy_win); +} + +static void +nsgtk_crtvrfy_reject(GtkWidget *w, gpointer data) +{ + struct nsgtk_crtvrfy_window *crtvrfy_win; + crtvrfy_win = (struct nsgtk_crtvrfy_window *)data; + + sslcert_viewer_reject(crtvrfy_win->ssl_data); + + nsgtk_crtvrfy_destroy(crtvrfy_win); +} + +static gboolean +nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event, gpointer data) +{ + nsgtk_crtvrfy_reject(w, data); + return FALSE; +} + +/** + * callback for mouse action for certificate verify on core window + * + * \param nsgtk_cw The nsgtk 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 appropriate error code + */ +static nserror +nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw, + browser_mouse_state mouse_state, + int x, int y) +{ + struct nsgtk_crtvrfy_window *crtvrfy_win; + /* technically degenerate container of */ + crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw; + + sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y); + + return NSERROR_OK; +} + +/** + * callback for keypress for certificate verify on core window + * + * \param nsgtk_cw The nsgtk core window structure. + * \param nskey The netsurf key code + * \return NSERROR_OK on success otherwise appropriate error code + */ +static nserror +nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey) +{ + struct nsgtk_crtvrfy_window *crtvrfy_win; + + /* technically degenerate container of */ + crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_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 nsgtk_cw The nsgtk core window structure. + * \param r The rectangle of the window that needs updating. + * \return NSERROR_OK on success otherwise appropriate error code + */ +static nserror +nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r) +{ + struct redraw_context ctx = { + .interactive = true, + .background_images = true, + .plot = &nsgtk_plotters + }; + struct nsgtk_crtvrfy_window *crtvrfy_win; + + /* technically degenerate container of */ + crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw; + + sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx); + + return NSERROR_OK; +} + +static nserror dummy_cb(bool proceed, void *pw) +{ + return NSERROR_OK; +} + +/* exported interface documented in gtk/page_info.h */ +nserror nsgtk_page_info(struct browser_window *bw) +{ + struct nsgtk_crtvrfy_window *ncwin; + nserror res; + + size_t num; + struct ssl_cert_info *chain; + struct nsurl *url; + + browser_window_get_ssl_chain(bw, &num, &chain); + url = browser_window_access_url(bw); + + ncwin = malloc(sizeof(struct nsgtk_crtvrfy_window)); + if (ncwin == NULL) { + return NSERROR_NOMEM; + } + + res = nsgtk_builder_new_from_resname("ssl", &ncwin->builder); + if (res != NSERROR_OK) { + NSLOG(netsurf, INFO, "SSL UI builder init failed"); + free(ncwin); + return res; + } + + gtk_builder_connect_signals(ncwin->builder, NULL); + + ncwin->dlg = GTK_DIALOG(gtk_builder_get_object(ncwin->builder, + "wndSSLProblem")); + + /* set parent for transient dialog */ + gtk_window_set_transient_for(GTK_WINDOW(ncwin->dlg), + nsgtk_scaffolding_window(nsgtk_current_scaffolding())); + + ncwin->core.scrolled = GTK_SCROLLED_WINDOW( + gtk_builder_get_object(ncwin->builder, "SSLScrolled")); + + ncwin->core.drawing_area = GTK_DRAWING_AREA( + gtk_builder_get_object(ncwin->builder, "SSLDrawingArea")); + + /* make the delete event call our destructor */ + g_signal_connect(G_OBJECT(ncwin->dlg), + "delete_event", + G_CALLBACK(nsgtk_crtvrfy_delete_event), + ncwin); + + /* accept button */ + g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder, + "sslaccept")), + "clicked", + G_CALLBACK(nsgtk_crtvrfy_accept), + ncwin); + + /* reject button */ + g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder, + "sslreject")), + "clicked", + G_CALLBACK(nsgtk_crtvrfy_reject), + ncwin); + + /* initialise GTK core window */ + ncwin->core.draw = nsgtk_crtvrfy_draw; + ncwin->core.key = nsgtk_crtvrfy_key; + ncwin->core.mouse = nsgtk_crtvrfy_mouse; + + res = nsgtk_corewindow_init(&ncwin->core); + if (res != NSERROR_OK) { + g_object_unref(G_OBJECT(ncwin->dlg)); + free(ncwin); + return res; + } + + /* initialise certificate viewing interface */ + res = sslcert_viewer_create_session_data(num, url, dummy_cb, NULL, chain, + &ncwin->ssl_data); + if (res != NSERROR_OK) { + g_object_unref(G_OBJECT(ncwin->dlg)); + free(ncwin); + return res; + } + + res = sslcert_viewer_init(ncwin->core.cb_table, + (struct core_window *)ncwin, + ncwin->ssl_data); + if (res != NSERROR_OK) { + g_object_unref(G_OBJECT(ncwin->dlg)); + free(ncwin); + return res; + } + + gtk_widget_show(GTK_WIDGET(ncwin->dlg)); + + return NSERROR_OK; +} diff --git a/frontends/gtk/page_info.h b/frontends/gtk/page_info.h new file mode 100644 index 000000000..ad443fcfd --- /dev/null +++ b/frontends/gtk/page_info.h @@ -0,0 +1,30 @@ +/* + * Copyright 2019 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NETSURF_GTK_PAGE_INFO_H +#define NETSURF_GTK_PAGE_INFO_H 1 + +/** + * Page information window + * + * \param bw the browser window to get page information for + * \return NSERROR_OK or error code if prompt creation failed. + */ +nserror nsgtk_page_info(struct browser_window *bw); + +#endif diff --git a/frontends/gtk/ssl_cert.c b/frontends/gtk/ssl_cert.c deleted file mode 100644 index 9d98db1f6..000000000 --- a/frontends/gtk/ssl_cert.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright 2015 Vincent Sanders - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file - * Implementation of gtk certificate viewing using gtk core windows. - */ - -#include -#include -#include - -#include "utils/log.h" -#include "netsurf/keypress.h" -#include "netsurf/plotters.h" -#include "desktop/sslcert_viewer.h" - -#include "gtk/plotters.h" -#include "gtk/scaffolding.h" -#include "gtk/resources.h" -#include "gtk/ssl_cert.h" -#include "gtk/corewindow.h" - - -/** - * GTK certificate viewing window context - */ -struct nsgtk_crtvrfy_window { - /** GTK core window context */ - struct nsgtk_corewindow core; - /** GTK builder for window */ - GtkBuilder *builder; - /** GTK dialog window being shown */ - GtkDialog *dlg; - /** SSL certificate viewer context data */ - struct sslcert_session_data *ssl_data; -}; - -/** - * destroy a previously created certificate view - */ -static nserror nsgtk_crtvrfy_destroy(struct nsgtk_crtvrfy_window *crtvrfy_win) -{ - nserror res; - - res = sslcert_viewer_fini(crtvrfy_win->ssl_data); - if (res == NSERROR_OK) { - res = nsgtk_corewindow_fini(&crtvrfy_win->core); - gtk_widget_destroy(GTK_WIDGET(crtvrfy_win->dlg)); - g_object_unref(G_OBJECT(crtvrfy_win->builder)); - free(crtvrfy_win); - } - return res; -} - -static void -nsgtk_crtvrfy_accept(GtkButton *w, gpointer data) -{ - struct nsgtk_crtvrfy_window *crtvrfy_win; - crtvrfy_win = (struct nsgtk_crtvrfy_window *)data; - - sslcert_viewer_accept(crtvrfy_win->ssl_data); - - nsgtk_crtvrfy_destroy(crtvrfy_win); -} - -static void -nsgtk_crtvrfy_reject(GtkWidget *w, gpointer data) -{ - struct nsgtk_crtvrfy_window *crtvrfy_win; - crtvrfy_win = (struct nsgtk_crtvrfy_window *)data; - - sslcert_viewer_reject(crtvrfy_win->ssl_data); - - nsgtk_crtvrfy_destroy(crtvrfy_win); -} - -static gboolean -nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event, gpointer data) -{ - nsgtk_crtvrfy_reject(w, data); - return FALSE; -} - -/** - * callback for mouse action for certificate verify on core window - * - * \param nsgtk_cw The nsgtk 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 appropriate error code - */ -static nserror -nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw, - browser_mouse_state mouse_state, - int x, int y) -{ - struct nsgtk_crtvrfy_window *crtvrfy_win; - /* technically degenerate container of */ - crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw; - - sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y); - - return NSERROR_OK; -} - -/** - * callback for keypress for certificate verify on core window - * - * \param nsgtk_cw The nsgtk core window structure. - * \param nskey The netsurf key code - * \return NSERROR_OK on success otherwise appropriate error code - */ -static nserror -nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey) -{ - struct nsgtk_crtvrfy_window *crtvrfy_win; - - /* technically degenerate container of */ - crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_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 nsgtk_cw The nsgtk core window structure. - * \param r The rectangle of the window that needs updating. - * \return NSERROR_OK on success otherwise appropriate error code - */ -static nserror -nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r) -{ - struct redraw_context ctx = { - .interactive = true, - .background_images = true, - .plot = &nsgtk_plotters - }; - struct nsgtk_crtvrfy_window *crtvrfy_win; - - /* technically degenerate container of */ - crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw; - - sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx); - - return NSERROR_OK; -} - -/* exported interface documented in gtk/ssl_cert.h */ -nserror gtk_cert_verify(struct nsurl *url, - const struct ssl_cert_info *certs, - unsigned long num, - nserror (*cb)(bool proceed, void *pw), - void *cbpw) -{ - struct nsgtk_crtvrfy_window *ncwin; - nserror res; - - ncwin = malloc(sizeof(struct nsgtk_crtvrfy_window)); - if (ncwin == NULL) { - return NSERROR_NOMEM; - } - - res = nsgtk_builder_new_from_resname("ssl", &ncwin->builder); - if (res != NSERROR_OK) { - NSLOG(netsurf, INFO, "SSL UI builder init failed"); - free(ncwin); - return res; - } - - gtk_builder_connect_signals(ncwin->builder, NULL); - - ncwin->dlg = GTK_DIALOG(gtk_builder_get_object(ncwin->builder, - "wndSSLProblem")); - - /* set parent for transient dialog */ - gtk_window_set_transient_for(GTK_WINDOW(ncwin->dlg), - nsgtk_scaffolding_window(nsgtk_current_scaffolding())); - - ncwin->core.scrolled = GTK_SCROLLED_WINDOW( - gtk_builder_get_object(ncwin->builder, "SSLScrolled")); - - ncwin->core.drawing_area = GTK_DRAWING_AREA( - gtk_builder_get_object(ncwin->builder, "SSLDrawingArea")); - - /* make the delete event call our destructor */ - g_signal_connect(G_OBJECT(ncwin->dlg), - "delete_event", - G_CALLBACK(nsgtk_crtvrfy_delete_event), - ncwin); - - /* accept button */ - g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder, - "sslaccept")), - "clicked", - G_CALLBACK(nsgtk_crtvrfy_accept), - ncwin); - - /* reject button */ - g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder, - "sslreject")), - "clicked", - G_CALLBACK(nsgtk_crtvrfy_reject), - ncwin); - - /* initialise GTK core window */ - ncwin->core.draw = nsgtk_crtvrfy_draw; - ncwin->core.key = nsgtk_crtvrfy_key; - ncwin->core.mouse = nsgtk_crtvrfy_mouse; - - res = nsgtk_corewindow_init(&ncwin->core); - if (res != NSERROR_OK) { - g_object_unref(G_OBJECT(ncwin->dlg)); - 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) { - g_object_unref(G_OBJECT(ncwin->dlg)); - free(ncwin); - return res; - } - - res = sslcert_viewer_init(ncwin->core.cb_table, - (struct core_window *)ncwin, - ncwin->ssl_data); - if (res != NSERROR_OK) { - g_object_unref(G_OBJECT(ncwin->dlg)); - free(ncwin); - return res; - } - - gtk_widget_show(GTK_WIDGET(ncwin->dlg)); - - return NSERROR_OK; -} diff --git a/frontends/gtk/ssl_cert.h b/frontends/gtk/ssl_cert.h deleted file mode 100644 index 1712756e9..000000000 --- a/frontends/gtk/ssl_cert.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2005 James Bursa - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef NETSURF_GTK_SSL_CERT_H -#define NETSURF_GTK_SSL_CERT_H 1 - -struct nsurl; -struct ssl_cert_info; - -/** - * Prompt the user to verify a certificate with issuse. - * - * \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 gtk_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); - -#endif diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c index 8eba86718..5d7d3f461 100644 --- a/frontends/gtk/toolbar.c +++ b/frontends/gtk/toolbar.c @@ -69,6 +69,7 @@ #include "gtk/about.h" #include "gtk/gdk.h" #include "gtk/bitmap.h" +#include "gtk/page_info.h" #include "gtk/toolbar.h" /** @@ -301,6 +302,9 @@ make_toolbar_item_throbber(bool sensitivity, bool edit) * create url bar toolbar item widget * * create a gtk entry widget with a completion attached + * + * \param sensitivity if the entry should be created sensitive to input + * \param edit if the entry should be editable */ static GtkToolItem * make_toolbar_item_url_bar(bool sensitivity, bool edit) @@ -314,6 +318,9 @@ make_toolbar_item_url_bar(bool sensitivity, bool edit) if (entry == NULL) { return NULL; } + nsgtk_entry_set_icon_from_icon_name(entry, + GTK_ENTRY_ICON_PRIMARY, + NSGTK_STOCK_INFO); if (edit) { gtk_entry_set_width_chars(GTK_ENTRY(entry), 9); @@ -1940,6 +1947,31 @@ url_entry_changed_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) } +/** + * callback for url entry widget icon button release + * + * handler connected to url entry widget for the icon release signal + * + * \param widget The widget the signal is being delivered to. + * \param event The key change event that changed the entry. + * \param data The toolbar context passed when the signal was connected + * \return TRUE to allow activation. + */ +static void +url_entry_icon_release_cb(GtkEntry *entry, + GtkEntryIconPosition icon_pos, + GdkEvent *event, + gpointer data) +{ + struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data; + struct browser_window *bw; + + bw = tb->get_bw(tb->get_ctx); + + nsgtk_page_info(bw); +} + + /** * handler for web search tool bar entry item activate signal * @@ -3276,6 +3308,10 @@ toolbar_connect_signal(struct nsgtk_toolbar *tb, nsgtk_toolbar_button itemid) "changed", G_CALLBACK(url_entry_changed_cb), tb); + g_signal_connect(GTK_WIDGET(entry), + "icon-release", + G_CALLBACK(url_entry_icon_release_cb), + tb); nsgtk_completion_connect_signals(entry, tb->get_bw, -- cgit v1.2.3