[evolution] Enable sandbox usage for WebKitGTK



commit 820aab23429c679071343ec197314957d5c5e1e0
Author: Milan Crha <mcrha redhat com>
Date:   Tue May 5 14:23:13 2020 +0200

    Enable sandbox usage for WebKitGTK

 src/e-util/CMakeLists.txt                   | 1 +
 src/e-util/e-web-view.c                     | 5 +++++
 src/e-util/test-html-editor-units.c         | 4 ++++
 src/e-util/test-html-editor.c               | 4 ++++
 src/e-util/test-web-view-jsc.c              | 4 ++++
 src/modules/webkit-editor/CMakeLists.txt    | 2 ++
 src/modules/webkit-editor/e-webkit-editor.c | 5 +++++
 7 files changed, 25 insertions(+)
---
diff --git a/src/e-util/CMakeLists.txt b/src/e-util/CMakeLists.txt
index 19632d07f2..e138c95ab2 100644
--- a/src/e-util/CMakeLists.txt
+++ b/src/e-util/CMakeLists.txt
@@ -615,6 +615,7 @@ target_compile_definitions(evolution-util PRIVATE
        -DEVOLUTION_RULEDIR=\"${privdatadir}\"
        -DEVOLUTION_WEB_EXTENSIONS_DIR=\"${webextensionsdir}\"
        -DEVOLUTION_WEBKITDATADIR=\"${webkitdatadir}\"
+       -DEVOLUTION_SOURCE_WEBKITDATADIR=\"${CMAKE_SOURCE_DIR}/data/webkit\"
        -DEVOLUTION_TESTGIOMODULESDIR=\"${CMAKE_CURRENT_BINARY_DIR}\"
        -DEVOLUTION_TESTTOPSRCDIR=\"${CMAKE_SOURCE_DIR}\"
        -DLIBEUTIL_COMPILATION
diff --git a/src/e-util/e-web-view.c b/src/e-util/e-web-view.c
index f12602b558..d5bf1488fc 100644
--- a/src/e-util/e-web-view.c
+++ b/src/e-util/e-web-view.c
@@ -906,6 +906,11 @@ web_view_constructor (GType type,
 
                                webkit_web_context_set_cache_model (web_context, 
WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
                                webkit_web_context_set_web_extensions_directory (web_context, 
EVOLUTION_WEB_EXTENSIONS_DIR);
+                               webkit_web_context_set_sandbox_enabled (web_context, TRUE);
+                               webkit_web_context_add_path_to_sandbox (web_context, EVOLUTION_WEBKITDATADIR, 
TRUE);
+                               #if ENABLE_MAINTAINER_MODE
+                               webkit_web_context_add_path_to_sandbox (web_context, 
EVOLUTION_SOURCE_WEBKITDATADIR, TRUE);
+                               #endif
 
                                g_object_add_weak_pointer (G_OBJECT (web_context), &web_context);
                        } else {
diff --git a/src/e-util/test-html-editor-units.c b/src/e-util/test-html-editor-units.c
index 27708fc942..30270ca1b1 100644
--- a/src/e-util/test-html-editor-units.c
+++ b/src/e-util/test-html-editor-units.c
@@ -7365,6 +7365,7 @@ main (gint argc,
                  NULL },
                { NULL }
        };
+       GApplication *application; /* Needed for WebKitGTK sandboxing */
        GOptionContext *context;
        GError *error = NULL;
        GList *modules;
@@ -7413,6 +7414,8 @@ main (gint argc,
        e_util_init_main_thread (NULL);
        e_passwords_init ();
 
+       application = g_application_new ("org.gnome.Evolution.test-html-editor-units", 
G_APPLICATION_FLAGS_NONE);
+
        gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), EVOLUTION_ICONDIR);
 
        modules = e_module_load_all_in_directory (EVOLUTION_MODULEDIR);
@@ -7549,6 +7552,7 @@ main (gint argc,
 
        res = g_test_run ();
 
+       g_clear_object (&application);
        e_misc_util_free_global_memory ();
        test_utils_free_global_memory ();
 
diff --git a/src/e-util/test-html-editor.c b/src/e-util/test-html-editor.c
index 9d684e2a41..995700859e 100644
--- a/src/e-util/test-html-editor.c
+++ b/src/e-util/test-html-editor.c
@@ -692,6 +692,7 @@ gint
 main (gint argc,
       gchar **argv)
 {
+       GApplication *application; /* Needed for WebKitGTK sandboxing */
        GList *modules;
 
        bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
@@ -703,6 +704,8 @@ main (gint argc,
        e_util_init_main_thread (NULL);
        e_passwords_init ();
 
+       application = g_application_new ("org.gnome.Evolution.test-html-editor", G_APPLICATION_FLAGS_NONE);
+
        g_setenv ("E_HTML_EDITOR_TEST_SOURCES", "1", FALSE);
 
        gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), EVOLUTION_ICONDIR);
@@ -717,6 +720,7 @@ main (gint argc,
 
        gtk_main ();
 
+       g_clear_object (&application);
        e_misc_util_free_global_memory ();
 
        return 0;
diff --git a/src/e-util/test-web-view-jsc.c b/src/e-util/test-web-view-jsc.c
index 5b0e785c2d..c58928a645 100644
--- a/src/e-util/test-web-view-jsc.c
+++ b/src/e-util/test-web-view-jsc.c
@@ -2975,6 +2975,7 @@ gint
 main (gint argc,
       gchar *argv[])
 {
+       GApplication *application; /* Needed for WebKitGTK sandboxing */
        gint res;
 
        setlocale (LC_ALL, "");
@@ -2989,6 +2990,8 @@ main (gint argc,
        e_util_init_main_thread (NULL);
        e_passwords_init ();
 
+       application = g_application_new ("org.gnome.Evolution.test-web-view-jsc", G_APPLICATION_FLAGS_NONE);
+
        test_utils_add_test ("/EWebView/JSCObjectProperties", test_jsc_object_properties);
        test_utils_add_test ("/EWebView/SetElementHidden", test_set_element_hidden);
        test_utils_add_test ("/EWebView/SetElementDisabled", test_set_element_disabled);
@@ -3006,6 +3009,7 @@ main (gint argc,
 
        res = g_test_run ();
 
+       g_clear_object (&application);
        e_misc_util_free_global_memory ();
 
        return res;
diff --git a/src/modules/webkit-editor/CMakeLists.txt b/src/modules/webkit-editor/CMakeLists.txt
index 3dadd07bf0..948442e542 100644
--- a/src/modules/webkit-editor/CMakeLists.txt
+++ b/src/modules/webkit-editor/CMakeLists.txt
@@ -11,6 +11,8 @@ set(sources
 )
 set(extra_defines
        -DEVOLUTION_WEB_EXTENSIONS_WEBKIT_EDITOR_DIR=\"${webextensionswebkiteditordir}\"
+       -DEVOLUTION_WEBKITDATADIR=\"${webkitdatadir}\"
+       -DEVOLUTION_SOURCE_WEBKITDATADIR=\"${CMAKE_SOURCE_DIR}/data/webkit\"
 )
 set(extra_cflags)
 set(extra_incdirs)
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index efa8596706..a300f3b980 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -4198,6 +4198,11 @@ webkit_editor_constructor (GType type,
 
                                webkit_web_context_set_cache_model (web_context, 
WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
                                webkit_web_context_set_web_extensions_directory (web_context, 
EVOLUTION_WEB_EXTENSIONS_WEBKIT_EDITOR_DIR);
+                               webkit_web_context_set_sandbox_enabled (web_context, TRUE);
+                               webkit_web_context_add_path_to_sandbox (web_context, EVOLUTION_WEBKITDATADIR, 
TRUE);
+                               #if ENABLE_MAINTAINER_MODE
+                               webkit_web_context_add_path_to_sandbox (web_context, 
EVOLUTION_SOURCE_WEBKITDATADIR, TRUE);
+                               #endif
 
                                g_object_add_weak_pointer (G_OBJECT (web_context), &web_context);
                        } else {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]