/*
* 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 .
*/
#include
#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;
}
}
}