2015-04-12 19:55:46 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Vincent Sanders <vince@netsurf-browser.org>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
#include "utils/log.h"
|
2015-04-12 19:55:46 +03:00
|
|
|
#include "utils/nsurl.h"
|
|
|
|
#include "desktop/tree.h"
|
|
|
|
#include "desktop/sslcert_viewer.h"
|
|
|
|
|
|
|
|
#include "gtk/treeview.h"
|
|
|
|
#include "gtk/scaffolding.h"
|
2015-06-13 13:31:23 +03:00
|
|
|
#include "gtk/resources.h"
|
2015-04-12 19:55:46 +03:00
|
|
|
#include "gtk/ssl_cert.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void nsgtk_ssl_accept(GtkButton *w, gpointer data)
|
|
|
|
{
|
|
|
|
void **session = data;
|
|
|
|
GtkBuilder *x = session[0];
|
|
|
|
struct nsgtk_treeview *wnd = session[1];
|
|
|
|
struct sslcert_session_data *ssl_data = session[2];
|
|
|
|
|
|
|
|
sslcert_viewer_accept(ssl_data);
|
|
|
|
|
|
|
|
nsgtk_treeview_destroy(wnd);
|
|
|
|
g_object_unref(G_OBJECT(x));
|
|
|
|
free(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nsgtk_ssl_reject(GtkWidget *w, gpointer data)
|
|
|
|
{
|
|
|
|
void **session = data;
|
|
|
|
GtkBuilder *x = session[0];
|
|
|
|
struct nsgtk_treeview *wnd = session[1];
|
|
|
|
struct sslcert_session_data *ssl_data = session[2];
|
|
|
|
|
|
|
|
sslcert_viewer_reject(ssl_data);
|
|
|
|
|
|
|
|
nsgtk_treeview_destroy(wnd);
|
|
|
|
g_object_unref(G_OBJECT(x));
|
|
|
|
free(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean nsgtk_ssl_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
|
|
|
|
{
|
|
|
|
nsgtk_ssl_reject(w, data);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-31 03:24:57 +03:00
|
|
|
nserror gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
|
2015-04-12 19:55:46 +03:00
|
|
|
unsigned long num, nserror (*cb)(bool proceed, void *pw),
|
|
|
|
void *cbpw)
|
|
|
|
{
|
|
|
|
static struct nsgtk_treeview *ssl_window;
|
|
|
|
struct sslcert_session_data *data;
|
|
|
|
GtkButton *accept, *reject;
|
|
|
|
void **session;
|
|
|
|
GtkDialog *dlg;
|
|
|
|
GtkScrolledWindow *scrolled;
|
|
|
|
GtkDrawingArea *drawing_area;
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWindow *gtk_parent;
|
2015-06-13 13:31:23 +03:00
|
|
|
nserror res;
|
2015-04-12 19:55:46 +03:00
|
|
|
|
|
|
|
/* state while dlg is open */
|
|
|
|
session = calloc(sizeof(void *), 3);
|
|
|
|
if (session == NULL) {
|
2016-07-31 03:24:57 +03:00
|
|
|
return NSERROR_NOMEM;
|
2015-04-12 19:55:46 +03:00
|
|
|
}
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
res = nsgtk_builder_new_from_resname("ssl", &builder);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
LOG("SSL UI builder init failed");
|
2015-04-12 19:55:46 +03:00
|
|
|
free(session);
|
2016-07-31 03:24:57 +03:00
|
|
|
return NSERROR_INIT_FAILED;
|
2015-04-12 19:55:46 +03:00
|
|
|
}
|
|
|
|
|
2015-06-13 13:31:23 +03:00
|
|
|
gtk_builder_connect_signals(builder, NULL);
|
|
|
|
|
2015-04-12 19:55:46 +03:00
|
|
|
sslcert_viewer_create_session_data(num, url, cb, cbpw, certs, &data);
|
|
|
|
|
|
|
|
dlg = GTK_DIALOG(gtk_builder_get_object(builder, "wndSSLProblem"));
|
|
|
|
|
|
|
|
/* set parent for transient dialog */
|
|
|
|
gtk_parent = nsgtk_scaffolding_window(nsgtk_current_scaffolding());
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(dlg), gtk_parent);
|
|
|
|
|
|
|
|
scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(builder, "SSLScrolled"));
|
|
|
|
drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(builder, "SSLDrawingArea"));
|
|
|
|
|
2016-07-12 02:29:58 +03:00
|
|
|
ssl_window = nsgtk_treeview_create(TREE_SSLCERT,
|
|
|
|
GTK_WINDOW(dlg),
|
|
|
|
scrolled,
|
|
|
|
drawing_area,
|
|
|
|
data);
|
2015-04-12 19:55:46 +03:00
|
|
|
if (ssl_window == NULL) {
|
|
|
|
free(session);
|
|
|
|
g_object_unref(G_OBJECT(dlg));
|
2016-07-31 03:24:57 +03:00
|
|
|
return NSERROR_INIT_FAILED;
|
2015-04-12 19:55:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
accept = GTK_BUTTON(gtk_builder_get_object(builder, "sslaccept"));
|
|
|
|
reject = GTK_BUTTON(gtk_builder_get_object(builder, "sslreject"));
|
|
|
|
|
|
|
|
session[0] = builder;
|
|
|
|
session[1] = ssl_window;
|
|
|
|
session[2] = data;
|
|
|
|
|
|
|
|
#define CONNECT(obj, sig, callback, ptr) \
|
|
|
|
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
|
|
|
|
|
|
|
|
CONNECT(accept, "clicked", nsgtk_ssl_accept, session);
|
|
|
|
CONNECT(reject, "clicked", nsgtk_ssl_reject, session);
|
|
|
|
CONNECT(dlg, "delete_event", G_CALLBACK(nsgtk_ssl_delete_event),
|
|
|
|
(gpointer)session);
|
|
|
|
|
|
|
|
gtk_widget_show(GTK_WIDGET(dlg));
|
2016-07-31 03:24:57 +03:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2015-04-12 19:55:46 +03:00
|
|
|
}
|