Add geolocation setting
authorAlva <a@u8.is>
Mon, 11 Nov 2019 15:07:51 +0000 (16:07 +0100)
committerAlva <a@u8.is>
Mon, 18 Nov 2019 21:25:57 +0000 (22:25 +0100)
This setting lets users automatically reject/allow geolocation access.
The default is to ask every time, like before.

src/main.c
src/setting.c

index 3d7b8ca..b5423ce 100644 (file)
@@ -2008,7 +2008,14 @@ static gboolean on_permission_request(WebKitWebView *webview,
     char *msg = NULL;
 
     if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(request)) {
-        msg = "request your location";
+        char* geolocation_setting = GET_CHAR(c, "geolocation");
+        if (strcmp(geolocation_setting, "ask") == 0) {
+            msg = "access your location";
+        } else if (strcmp(geolocation_setting, "always") == 0) {
+            return TRUE;
+        } else if (strcmp(geolocation_setting, "never") == 0) {
+            return FALSE;
+        }
     } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(request)) {
         if (webkit_user_media_permission_is_for_audio_device(WEBKIT_USER_MEDIA_PERMISSION_REQUEST(request))) {
             msg = "access the microphone";
index c16509b..6b334b6 100644 (file)
@@ -53,6 +53,7 @@ static void setting_free(Setting *s);
 static int cookie_accept(Client *c, const char *name, DataType type, void *value, void *data);
 static int default_zoom(Client *c, const char *name, DataType type, void *value, void *data);
 static int fullscreen(Client *c, const char *name, DataType type, void *value, void *data);
+static int geolocation(Client *c, const char *name, DataType type, void *value, void *data);
 static int gui_style(Client *c, const char *name, DataType type, void *value, void *data);
 static int hardware_acceleration_policy(Client *c, const char *name, DataType type, void *value, void *data);
 static int input_autohide(Client *c, const char *name, DataType type, void *value, void *data);
@@ -90,6 +91,7 @@ void setting_init(Client *c)
     i = SETTING_DEFAULT_FONT_SIZE;
     setting_add(c, "font-size", TYPE_INTEGER, &i, webkit, 0, "default-font-size");
     setting_add(c, "frame-flattening", TYPE_BOOLEAN, &off, webkit, 0, "enable-frame-flattening");
+    setting_add(c, "geolocation", TYPE_CHAR, &"ask", geolocation, FLAG_NODUP, NULL);
     setting_add(c, "hardware-acceleration-policy", TYPE_CHAR, &"ondemand", hardware_acceleration_policy, FLAG_NODUP, NULL);
     setting_add(c, "header", TYPE_CHAR, &"", headers, FLAG_LIST|FLAG_NODUP, "header");
     i = 1000;
@@ -539,6 +541,16 @@ static int fullscreen(Client *c, const char *name, DataType type, void *value, v
     return CMD_SUCCESS;
 }
 
+static int geolocation(Client *c, const char *name, DataType type, void *value, void *data)
+{
+    char *policy = (char *)value;
+    if (strcmp("always", policy) != 0 && strcmp("ask", policy) != 0 && strcmp("never", policy) != 0) {
+        vb_echo(c, MSG_ERROR, FALSE, "%s must be in [always, ask, never]", name);
+        return CMD_ERROR | CMD_KEEPINPUT;
+    }
+    return CMD_SUCCESS;
+}
+
 /* This needs to be called before the window is shown for the best chance of
  * success, but it may be called at any time.
  * Currently the setting file is read after the window has been shown, which