@@ 5,8 5,11 @@
* Distributed under terms of the MIT license.
*/
+#include "kiln.h"
#include <webkit2/webkit2.h>
+static const char **s_option_kiln_module_paths = NULL;
+static const char **s_option_kiln_open_modules = NULL;
static char *s_option_extensions_path = NULL;
static char *s_option_uri = NULL;
@@ 38,6 41,22 @@ static const GOptionEntry s_cli_options[] = {
"Path to directory containing WebExtensions", "PATH"
},
{
+ .short_name = 'M',
+ .long_name = "module-path",
+ .arg = G_OPTION_ARG_FILENAME_ARRAY,
+ .arg_data = &s_option_kiln_module_paths,
+ .arg_description = "PATH",
+ .description = "Add PATH to the modules search path",
+ },
+ {
+ .short_name = 'm',
+ .long_name = "module",
+ .arg = G_OPTION_ARG_STRING_ARRAY,
+ .arg_data = &s_option_kiln_open_modules,
+ .arg_description = "NAME",
+ .description = "Preload module NAME",
+ },
+ {
G_OPTION_REMAINING, '\0', G_OPTION_FLAG_NONE,
G_OPTION_ARG_CALLBACK, on_remaining_cli_option,
},
@@ 46,6 65,25 @@ static const GOptionEntry s_cli_options[] = {
}
};
+static GVariant*
+build_kiln_ext_options (void)
+{
+ g_autoptr(GVariantDict) options = g_variant_dict_new (NULL);
+
+ /* TODO: Options "loader", "whitelist", and "blacklist". */
+
+ if (s_option_kiln_module_paths) {
+ g_variant_dict_insert_value (options, "paths",
+ g_variant_new_strv (s_option_kiln_module_paths, -1));
+ }
+ if (s_option_kiln_open_modules) {
+ g_variant_dict_insert_value (options, "preload",
+ g_variant_new_strv (s_option_kiln_open_modules, -1));
+ }
+
+ return g_variant_ref_sink (g_variant_dict_end (options));
+}
+
static GtkWidget*
create_web_view (void)
{
@@ 55,6 93,11 @@ create_web_view (void)
if (s_option_extensions_path) {
g_message ("WebExtensions path: %s", s_option_extensions_path);
webkit_web_context_set_web_extensions_directory (context, s_option_extensions_path);
+
+ g_autoptr(GVariant) options = build_kiln_ext_options ();
+ g_autofree char *options_string = g_variant_print (options, TRUE);
+ g_message ("WebExtensions options: %s", options_string);
+ webkit_web_context_set_web_extensions_initialization_user_data (context, options);
} else {
g_warning ("WebExtensions path has not been set - none will be loaded!");
}