summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2021-05-17 15:21:29 +0300
committerCem Keylan <cem@ckyln.com>2021-05-17 15:34:23 +0300
commite0dff764218ae146b0a21585a6a53ec4ca7e649f (patch)
tree299b73ac90aa7ffbe50c29a07fdb811725bad7ac
parent0c8d6d0d28aa0cb1ad19d1c37688aaf485b3a51b (diff)
downloadlariza-e0dff764218ae146b0a21585a6a53ec4ca7e649f.tar.gz
lariza: handle permission requests
-rw-r--r--browser.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/browser.c b/browser.c
index 29c694a..2facd88 100644
--- a/browser.c
+++ b/browser.c
@@ -48,6 +48,7 @@ gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
void mainwindow_setup(void);
void mainwindow_title(gint);
void notebook_switch_page(GtkNotebook *, GtkWidget *, guint, gpointer);
+gboolean permission_request(WebKitWebView *, WebKitPermissionRequest *, gpointer);
gboolean quit_if_nothing_active(void);
gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
void run_user_scripts(WebKitWebView *);
@@ -175,6 +176,8 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
G_CALLBACK(hover_web_view), c);
+ g_signal_connect(G_OBJECT(c->web_view), "permission-request",
+ G_CALLBACK(permission_request), c);
g_signal_connect(G_OBJECT(c->web_view), "web-process-crashed",
G_CALLBACK(crashed_web_view), c);
@@ -1143,6 +1146,51 @@ notebook_switch_page(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data)
}
gboolean
+permission_request(WebKitWebView *v, WebKitPermissionRequest *r, gpointer data)
+{
+ char *permission_str;
+ if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r))
+ {
+ permission_str = "Allow this site to see your location?";
+ }
+ else if (WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST(r))
+ {
+ permission_str = "Allow notifications from this website?";
+ }
+ else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(r)) {
+ if (webkit_user_media_permission_is_for_audio_device(
+ WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
+ permission_str = "Allow this site to access your microphone?";
+ else if (webkit_user_media_permission_is_for_video_device(
+ WEBKIT_USER_MEDIA_PERMISSION_REQUEST(r)))
+ permission_str = "Allow this site to access your webcam?";
+ else
+ return FALSE;
+ }
+ else {
+ /* Deny anything that are not listed above */
+ return FALSE;
+ }
+ GtkWidget *dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ permission_str);
+ gtk_widget_show(dialog);
+ gint result = gtk_dialog_run(GTK_DIALOG(dialog));
+ switch(result) {
+ case GTK_RESPONSE_YES:
+ webkit_permission_request_allow(r);
+ break;
+ default:
+ webkit_permission_request_deny(r);
+ break;
+ }
+ gtk_widget_destroy(dialog);
+ return TRUE;
+}
+
+gboolean
quit_if_nothing_active(void)
{
if (clients == 0)