diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/local.mk | 1 | ||||
-rw-r--r-- | src/web-settings.c | 269 | ||||
-rw-r--r-- | src/web-settings.h | 33 |
3 files changed, 303 insertions, 0 deletions
diff --git a/src/local.mk b/src/local.mk index bee2a35..b838bd8 100644 --- a/src/local.mk +++ b/src/local.mk @@ -2,6 +2,7 @@ marquee_SOURCES += \ %reldir%/main.c \ %reldir%/application.c \ %reldir%/config.c \ + %reldir%/web-settings.c \ %reldir%/window.c \ %reldir%/tab.c \ %reldir%/tab-chrome.c \ diff --git a/src/web-settings.c b/src/web-settings.c new file mode 100644 index 0000000..6985bca --- /dev/null +++ b/src/web-settings.c @@ -0,0 +1,269 @@ +/* + * Mapping from MqConfig to WebKitSettings and WebKitWebContext + * + * Copyright (C) 2017 Patrick McDermott + * + * This file is part of Marquee. + * + * Marquee 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, either version 3 of the License, or + * (at your option) any later version. + * + * Marquee 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 Marquee. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <webkit2/webkit2.h> + +#include "web-settings.h" +#include "config.h" + +enum mapping_type { + MAP_BOOL, + MAP_BOOL_N, + MAP_INT, + /* MAP_DBL, */ + MAP_STR, + /* MAP_STRL, */ +}; + +struct mapping { + enum mapping_type type; + const gchar *mq_name; + const gchar *wk_name; +}; + +static struct mapping mappings[] = { + /* General -> Navigation and Accessibility */ + {MAP_BOOL, "enable-smooth-scrolling", + "navigation.smooth-scrolling"}, + {MAP_BOOL, "navigation.tabbing", + "enable-tabs-to-links"}, + {MAP_BOOL, "navigation.caret", + "enable-caret-browsing"}, + {MAP_BOOL, "navigation.spatial", + "enable-spatial-navigation"}, + + /* General -> Miscellaneous */ + {MAP_BOOL, "display.textarea.resize.enable", + "enable-resizable-text-areas"}, + {MAP_BOOL, "devtools.enable", + "enable-developer-extras"}, + + /* General -> Compatibility */ + // compatibility.user-agent + {MAP_BOOL, "compatibility.quirks", + "enable-site-specific-quirks"}, + + /* Display -> Fonts */ + {MAP_STR, "font.family.default", + "default-font-family"}, + {MAP_STR, "font.family.monospace", + "monospace-font-family"}, + {MAP_STR, "font.family.serif", + "serif-font-family"}, + {MAP_STR, "font.family.sans-serif", + "sans-serif-font-family"}, + {MAP_STR, "font.family.cursive", + "cursive-font-family"}, + {MAP_STR, "font.family.fantasy", + "fantasy-font-family"}, + {MAP_STR, "font.family.pictograph", + "pictograph-font-family"}, + {MAP_INT, "font.size.default", + "default-font-size"}, + {MAP_INT, "font.size.monospace-default", + "default-monospace-font-size"}, + {MAP_INT, "font.size.minimum", + "minimum-font-size"}, + + /* Display -> Languages */ + {MAP_STR, "intl.default-charset", + "default-charset"}, + + /* Display -> Zoom */ + {MAP_BOOL, "zoom.text-only", + "zoom-text-only"}, + + /* Permissions -> General */ + {MAP_BOOL, "permissions.images.auto-load", + "auto-load-images"}, + {MAP_BOOL, "permissions.images.favicons.override", + "load-icons-ignoring-image-load-setting"}, + {MAP_BOOL, "permissions.java.enable", + "enable-java"}, + {MAP_BOOL, "permissions.javascript.enable", + "enable-javascript"}, + {MAP_BOOL, "permissions.plugins.enable", + "enable-plugins"}, + + /* Permissions -> JavaScript */ + {MAP_BOOL, "permissions.javascript.open-windows", + "javascript-can-open-windows-automatically"}, + {MAP_BOOL, "permissions.javascript.fullscreen", + "enable-fullscreen"}, + {MAP_BOOL, "permissions.javascript.modal-dialogs", + "allow-modal-dialogs"}, + {MAP_BOOL, "permissions.javascript.clipboard", + "javascript-can-access-clipboard"}, + + /* Permissions -> Data Storage */ + {MAP_BOOL, "permissions.javascript.database", + "enable-html5-database"}, + {MAP_BOOL, "permissions.javascript.storage", + "enable-html5-local-storage"}, + {MAP_BOOL, "permissions.appcache", + "enable-offline-web-application-cache"}, + + /* Permissions -> Graphics and Multimedia */ + {MAP_BOOL, "canvas.acceleration.enable", + "enable-accelerated-2d-canvas"}, + {MAP_BOOL, "permissions.javascript.webgl", + "enable-webgl"}, + {MAP_BOOL, "permissions.javascript.audio", + "enable-webaudio"}, + {MAP_BOOL_N, "media.autoplay", + "media-playback-requires-user-gesture"}, + {MAP_BOOL_N, "media.force-fullscreen", + "media-playback-allows-inline"}, + {MAP_BOOL, "permissions.javascript.mediastream.enable", + "enable-media-stream"}, + {MAP_BOOL, "permissions.javascript.mediasource.enable", + "enable-mediasource"}, + + /* Security and Privacy -> History */ + {MAP_BOOL, "privacy.private-browsing.enabled", + "enable-private-browsing"}, + + /* Security and Privacy -> Security */ + {MAP_BOOL, "security.xss-auditor.enable", + "enable-xss-auditor"}, + + /* Security and Privacy -> Network */ + {MAP_BOOL, "dns.prefetch.enable", + "enable-dns-prefetching"}, +}; + +static GHashTable *mappings_table = NULL; + +static void +bool_cb(const gchar *name, const gboolean value, WebKitSettings *wk_settings) +{ + GValue g_value; + + g_value_init(&g_value, G_TYPE_BOOLEAN); + g_value_set_boolean(&g_value, value); + g_object_set_property(G_OBJECT(wk_settings), + g_hash_table_lookup(mappings_table, name), &g_value); +} + +static void +bool_n_cb(const gchar *name, const gboolean value, WebKitSettings *wk_settings) +{ + GValue g_value; + + g_value_init(&g_value, G_TYPE_BOOLEAN); + g_value_set_boolean(&g_value, value); + g_object_set_property(G_OBJECT(wk_settings), + g_hash_table_lookup(mappings_table, name), &g_value); +} + +static void +int_cb(const gchar *name, const gint value, WebKitSettings *wk_settings) +{ + GValue g_value; + + g_value_init(&g_value, G_TYPE_INT); + g_value_set_boolean(&g_value, value); + g_object_set_property(G_OBJECT(wk_settings), + g_hash_table_lookup(mappings_table, name), &g_value); +} + +static void +str_cb(const gchar *name, const gchar *value, WebKitSettings *wk_settings) +{ + GValue g_value; + + g_value_init(&g_value, G_TYPE_STRING); + g_value_set_static_string(&g_value, value); + g_object_set_property(G_OBJECT(wk_settings), + g_hash_table_lookup(mappings_table, name), &g_value); +} + +static void +init_mappings_table(void) +{ + gsize i; + + if (mappings_table) { + return; + } + + mappings_table = g_hash_table_new(g_str_hash, g_str_equal); + + for (i = 0; i < sizeof(mappings) / sizeof(mappings[0]); ++i) { + g_hash_table_insert(mappings_table, + g_strdup(mappings[i].mq_name), + g_strdup(mappings[i].wk_name)); + } +} + +void +mq_web_settings_connect(MqConfig *config, WebKitSettings *wk_settings, + WebKitWebContext *wk_web_context) +{ + gsize i; + + init_mappings_table(); + + for (i = 0; i < sizeof(mappings) / sizeof(mappings[0]); ++i) { + switch (mappings[i].type) { + case MAP_BOOL: + mq_config_notify_boolean(config, + mappings[i].mq_name, + (MqConfigBooleanCallback) bool_cb, + wk_settings); + bool_cb(mappings[i].mq_name, + mq_config_get_boolean(config, + mappings[i].mq_name), + wk_settings); + break; + case MAP_BOOL_N: + mq_config_notify_boolean(config, + mappings[i].mq_name, + (MqConfigBooleanCallback) bool_n_cb, + wk_settings); + bool_cb(mappings[i].mq_name, + mq_config_get_boolean(config, + mappings[i].mq_name), + wk_settings); + break; + case MAP_INT: + mq_config_notify_integer(config, + mappings[i].mq_name, + (MqConfigIntegerCallback) int_cb, + wk_settings); + int_cb(mappings[i].mq_name, + mq_config_get_integer(config, + mappings[i].mq_name), + wk_settings); + break; + case MAP_STR: + mq_config_notify_string(config, + mappings[i].mq_name, + (MqConfigStringCallback) str_cb, + wk_settings); + str_cb(mappings[i].mq_name, + mq_config_get_string(config, + mappings[i].mq_name), + wk_settings); + break; + } + } +} diff --git a/src/web-settings.h b/src/web-settings.h new file mode 100644 index 0000000..f669956 --- /dev/null +++ b/src/web-settings.h @@ -0,0 +1,33 @@ +/* + * Mapping from MqConfig to WebKitSettings and WebKitWebContext + * + * Copyright (C) 2017 Patrick McDermott + * + * This file is part of Marquee. + * + * Marquee 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, either version 3 of the License, or + * (at your option) any later version. + * + * Marquee 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 Marquee. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MQ_WEB_SETTINGS_H +#define MQ_WEB_SETTINGS_H + +#include <webkit2/webkit2.h> + +#include "config.h" + +void +mq_web_settings_connect(MqConfig *config, WebKitSettings *wk_settings, + WebKitWebContext *wk_web_context); + +#endif |