[evolution/gnome-3-22] Use unique D-Bus service name for WebKit editor and cancel pending calls on dispose
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-22] Use unique D-Bus service name for WebKit editor and cancel pending calls on dispose
- Date: Wed, 19 Oct 2016 21:44:09 +0000 (UTC)
commit 4114b3967aa72b408ebc6c1df9135c75c00f97ee
Author: Milan Crha <mcrha redhat com>
Date: Wed Oct 19 23:03:24 2016 +0200
Use unique D-Bus service name for WebKit editor and cancel pending calls on dispose
The former part is good to not reuse D-Bus service name between different processes.
The later part fixes a crash of `test-html-editor-units -p /font/size` where
the test could crashed right after the first finished. The reason was that
the dispose call on the window caused style change signal, which called
ElementSetAttributeBySelector D-Bus method, which may not always finish before
the the WebKitWebProcess stopped, which resulted in a D-Bus error and following
test abort due to a critical warning with that particular error message.
modules/webkit-editor/e-webkit-editor.c | 122 ++++++++++++--------
.../web-extension/e-editor-web-extension-main.c | 13 ++-
.../web-extension/e-editor-web-extension-names.h | 2 +-
3 files changed, 86 insertions(+), 51 deletions(-)
---
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index 633b4b6..f715aeb 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -68,6 +68,7 @@ struct _EWebKitEditorPrivate {
EContentEditorInitializedCallback initialized_callback;
gpointer initialized_user_data;
+ GCancellable *cancellable;
GDBusProxy *web_extension;
guint web_extension_watch_name_id;
guint web_extension_selection_changed_cb_id;
@@ -444,6 +445,14 @@ web_extension_user_changed_default_colors_cb (GDBusConnection *connection,
g_variant_get (parameters, "(b)", &wk_editor->priv->suppress_color_changes);
}
+static gchar *
+webkit_editor_create_service_name_for_web_context (WebKitWebContext *web_context)
+{
+ g_warn_if_fail (WEBKIT_IS_WEB_CONTEXT (web_context));
+
+ return g_strdup_printf ("%s.WC%p", E_WEBKIT_EDITOR_WEB_EXTENSION_SERVICE_NAME_PREFIX, web_context);
+}
+
static void
dispatch_pending_operations (EWebKitEditor *wk_editor)
{
@@ -606,15 +615,21 @@ web_extension_vanished_cb (GDBusConnection *connection,
static void
webkit_editor_watch_web_extension (EWebKitEditor *wk_editor)
{
+ gchar *service_name;
+
+ service_name = webkit_editor_create_service_name_for_web_context (webkit_web_view_get_context
(WEBKIT_WEB_VIEW (wk_editor)));
+
wk_editor->priv->web_extension_watch_name_id =
g_bus_watch_name (
G_BUS_TYPE_SESSION,
- E_WEBKIT_EDITOR_WEB_EXTENSION_SERVICE_NAME,
+ service_name,
G_BUS_NAME_WATCHER_FLAGS_NONE,
(GBusNameAppearedCallback) web_extension_appeared_cb,
(GBusNameVanishedCallback) web_extension_vanished_cb,
wk_editor,
NULL);
+
+ g_free (service_name);
}
static guint64
@@ -656,7 +671,7 @@ webkit_editor_call_simple_extension_function (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
function,
g_variant_new ("(t)", current_page_id (wk_editor)),
- NULL);
+ wk_editor->priv->cancellable);
}
static GVariant *
@@ -696,7 +711,7 @@ webkit_editor_set_element_attribute (EWebKitEditor *wk_editor,
"ElementSetAttributeBySelector",
g_variant_new (
"(tsss)", current_page_id (wk_editor), selector, attribute, value),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -713,7 +728,7 @@ webkit_editor_remove_element_attribute (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
"ElementRemoveAttributeBySelector",
g_variant_new ("(tss)", current_page_id (wk_editor), selector, attribute),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -730,7 +745,7 @@ webkit_editor_set_format_boolean (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
format_dom_function,
g_variant_new ("(tb)", current_page_id (wk_editor), format_value),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -747,7 +762,7 @@ webkit_editor_set_format_int (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
format_dom_function,
g_variant_new ("(ti)", current_page_id (wk_editor), format_value),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -770,7 +785,7 @@ webkit_editor_set_format_string (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
format_dom_function,
g_variant_new ("(ts)", current_page_id (wk_editor), format_value),
- NULL);
+ wk_editor->priv->cancellable);
g_object_notify (G_OBJECT (wk_editor), format_name);
}
@@ -1661,7 +1676,7 @@ webkit_editor_set_html_mode (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
"SetEditorHTMLMode",
g_variant_new ("(tbb)", current_page_id (wk_editor), html_mode, convert),
- NULL);
+ wk_editor->priv->cancellable);
/* Update fonts - in plain text we only want monospaced */
webkit_editor_update_styles (E_CONTENT_EDITOR (wk_editor));
@@ -1678,8 +1693,7 @@ set_convert_in_situ (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
"SetConvertInSitu",
g_variant_new ("(tb)", current_page_id (wk_editor), value),
- NULL);
-
+ wk_editor->priv->cancellable);
}
static void
@@ -1737,7 +1751,7 @@ webkit_editor_insert_content (EContentEditor *editor,
current_page_id (wk_editor),
content,
(flags & E_CONTENT_EDITOR_INSERT_TEXT_HTML)),
- NULL);
+ wk_editor->priv->cancellable);
} else if ((flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL) &&
(flags & E_CONTENT_EDITOR_INSERT_TEXT_HTML)) {
if ((strstr (content, "data-evo-draft") ||
@@ -1778,7 +1792,7 @@ webkit_editor_insert_content (EContentEditor *editor,
wk_editor->priv->web_extension,
"DOMConvertContent",
g_variant_new ("(ts)", current_page_id (wk_editor), content),
- NULL);
+ wk_editor->priv->cancellable);
} else if ((flags & E_CONTENT_EDITOR_INSERT_CONVERT) &&
!(flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL) &&
!(flags & E_CONTENT_EDITOR_INSERT_QUOTE_CONTENT)) {
@@ -1788,7 +1802,7 @@ webkit_editor_insert_content (EContentEditor *editor,
"DOMConvertAndInsertHTMLIntoSelection",
g_variant_new (
"(tsb)", current_page_id (wk_editor), content, TRUE),
- NULL);
+ wk_editor->priv->cancellable);
} else if ((flags & E_CONTENT_EDITOR_INSERT_QUOTE_CONTENT) &&
!(flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL)) {
/* e_html_editor_view_paste_clipboard_quoted */
@@ -1797,7 +1811,7 @@ webkit_editor_insert_content (EContentEditor *editor,
"DOMQuoteAndInsertTextIntoSelection",
g_variant_new (
"(tsb)", current_page_id (wk_editor), content, (flags &
E_CONTENT_EDITOR_INSERT_TEXT_HTML) != 0),
- NULL);
+ wk_editor->priv->cancellable);
} else if (!(flags & E_CONTENT_EDITOR_INSERT_CONVERT) &&
!(flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL)) {
/* e_html_editor_view_insert_html */
@@ -1806,7 +1820,7 @@ webkit_editor_insert_content (EContentEditor *editor,
"DOMInsertHTML",
g_variant_new (
"(ts)", current_page_id (wk_editor), content),
- NULL);
+ wk_editor->priv->cancellable);
} else
g_warning ("Unsupported flags combination (%d) in (%s)", flags, G_STRFUNC);
}
@@ -1912,7 +1926,7 @@ webkit_editor_get_content (EContentEditor *editor,
"(ts)",
current_page_id (wk_editor),
wk_editor->priv->current_user_stylesheet),
- NULL);
+ wk_editor->priv->cancellable);
result = e_util_invoke_g_dbus_proxy_call_sync_wrapper_with_error_check (
wk_editor->priv->web_extension,
@@ -2030,7 +2044,7 @@ webkit_editor_insert_emoticon (EContentEditor *editor,
"DOMInsertSmiley",
g_variant_new (
"(ts)", current_page_id (wk_editor), e_emoticon_get_name (emoticon)),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -2080,7 +2094,7 @@ webkit_editor_insert_image_from_mime_part (EContentEditor *editor,
wk_editor->priv->web_extension,
"DOMAddNewInlineImageIntoList",
g_variant_new ("(tsss)", current_page_id (wk_editor), name ? name : "", cid_uri, src),
- NULL);
+ wk_editor->priv->cancellable);
g_free (base64_encoded);
g_free (mime_type);
@@ -2420,7 +2434,7 @@ webkit_editor_clear_undo_redo_history (EContentEditor *editor)
wk_editor->priv->web_extension,
"DOMClearUndoRedoHistory",
g_variant_new ("(t)", current_page_id (wk_editor)),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -2439,7 +2453,7 @@ webkit_editor_replace_caret_word (EContentEditor *editor,
wk_editor->priv->web_extension,
"DOMReplaceCaretWord",
g_variant_new ("(ts)", current_page_id (wk_editor), replacement),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -2595,7 +2609,7 @@ webkit_editor_replace (EContentEditor *editor,
wk_editor->priv->web_extension,
"DOMSelectionReplace",
g_variant_new ("(ts)", current_page_id (wk_editor), replacement),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -2985,7 +2999,7 @@ webkit_editor_insert_image (EContentEditor *editor,
wk_editor->priv->web_extension,
"DOMSelectionInsertImage",
g_variant_new ("(ts)", current_page_id (wk_editor), image_uri),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -3003,7 +3017,7 @@ webkit_editor_replace_image_src (EWebKitEditor *wk_editor,
wk_editor->priv->web_extension,
"DOMReplaceImageSrc",
g_variant_new ("(tss)", current_page_id (wk_editor), selector, image_uri),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -3087,7 +3101,7 @@ webkit_editor_image_set_url (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorImageDialogSetElementUrl",
g_variant_new ("(ts)", current_page_id (wk_editor), value),
- NULL);
+ wk_editor->priv->cancellable);
}
static gchar *
@@ -3136,7 +3150,7 @@ webkit_editor_image_set_vspace (EContentEditor *editor,
"ImageElementSetVSpace",
g_variant_new (
"(tsi)", current_page_id (wk_editor), "-x-evo-current-img", value),
- NULL);
+ wk_editor->priv->cancellable);
}
static gint
@@ -3185,7 +3199,7 @@ webkit_editor_image_set_hspace (EContentEditor *editor,
"ImageElementSetHSpace",
g_variant_new (
"(tsi)", current_page_id (wk_editor), "-x-evo-current-img", value),
- NULL);
+ wk_editor->priv->cancellable);
}
static gint
@@ -3362,7 +3376,7 @@ webkit_editor_image_set_height (EContentEditor *editor,
"ImageElementSetHeight",
g_variant_new (
"(tsi)", current_page_id (wk_editor), "-x-evo-current-img", value),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -3383,7 +3397,7 @@ webkit_editor_image_set_width (EContentEditor *editor,
"ImageElementSetWidth",
g_variant_new (
"(tsi)", current_page_id (wk_editor), "-x-evo-current-img", value),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -3525,7 +3539,7 @@ webkit_editor_link_set_values (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorLinkDialogOk",
g_variant_new ("(tss)", current_page_id (wk_editor), href, text),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -3810,7 +3824,7 @@ webkit_editor_page_set_background_image_uri (EContentEditor *editor,
wk_editor->priv->web_extension,
"RemoveImageAttributesFromElementBySelector",
g_variant_new ("(ts)", current_page_id (wk_editor), "body"),
- NULL);
+ wk_editor->priv->cancellable);
}
}
@@ -3830,7 +3844,7 @@ webkit_editor_on_cell_dialog_open (EContentEditor *editor)
wk_editor->priv->web_extension,
"EEditorCellDialogMarkCurrentCellElement",
g_variant_new ("(ts)", current_page_id (wk_editor), "-x-evo-current-cell"),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -3865,7 +3879,7 @@ webkit_editor_cell_set_v_align (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementVAlign",
g_variant_new ("(tsi)", current_page_id (wk_editor), value, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
}
static gchar *
@@ -3911,7 +3925,7 @@ webkit_editor_cell_set_align (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementAlign",
g_variant_new ("(tsi)", current_page_id (wk_editor), value, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
}
static gchar *
@@ -3957,7 +3971,7 @@ webkit_editor_cell_set_wrap (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementNoWrap",
g_variant_new ("(tbi)", current_page_id (wk_editor), !value, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
}
static gboolean
@@ -4013,7 +4027,7 @@ webkit_editor_cell_set_header_style (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementHeaderStyle",
g_variant_new ("(tbi)", current_page_id (wk_editor), value, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
}
static gboolean
@@ -4221,7 +4235,7 @@ webkit_editor_cell_set_row_span (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementRowSpan",
g_variant_new ("(tii)", current_page_id (wk_editor), value, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -4245,7 +4259,7 @@ webkit_editor_cell_set_col_span (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementColSpan",
g_variant_new ("(tii)", current_page_id (wk_editor), value, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
}
static void
@@ -4279,7 +4293,7 @@ webkit_editor_cell_set_width (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementWidth",
g_variant_new ("(tsi)", current_page_id (wk_editor), width, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
g_free (width);
}
@@ -4308,7 +4322,7 @@ webkit_editor_cell_set_background_color (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorCellDialogSetElementBgColor",
g_variant_new ("(tsi)", current_page_id (wk_editor), color, (gint32) scope),
- NULL);
+ wk_editor->priv->cancellable);
g_free (color);
}
@@ -4336,7 +4350,7 @@ webkit_editor_cell_set_background_image_uri (EContentEditor *editor,
wk_editor->priv->web_extension,
"RemoveImageAttributesFromElementBySelector",
g_variant_new ("(ts)", current_page_id (wk_editor), "#-x-evo-current-cell"),
- NULL);
+ wk_editor->priv->cancellable);
}
}
@@ -4360,7 +4374,7 @@ webkit_editor_table_set_row_count (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorTableDialogSetRowCount",
g_variant_new ("(tu)", current_page_id (wk_editor), value),
- NULL);
+ wk_editor->priv->cancellable);
}
static guint
@@ -4414,7 +4428,7 @@ webkit_editor_table_set_column_count (EContentEditor *editor,
wk_editor->priv->web_extension,
"EEditorTableDialogSetColumnCount",
g_variant_new ("(tu)", current_page_id (wk_editor), value),
- NULL);
+ wk_editor->priv->cancellable);
}
static guint
@@ -4775,7 +4789,7 @@ webkit_editor_table_set_background_image_uri (EContentEditor *editor,
wk_editor->priv->web_extension,
"RemoveImageAttributesFromElementBySelector",
g_variant_new ("(ts)", current_page_id (wk_editor), "#-x-evo-current-table"),
- NULL);
+ wk_editor->priv->cancellable);
}
}
@@ -4928,6 +4942,8 @@ webkit_editor_constructed (GObject *object)
wk_editor = E_WEBKIT_EDITOR (object);
web_view = WEBKIT_WEB_VIEW (wk_editor);
+ webkit_editor_watch_web_extension (wk_editor);
+
/* Give spell check languages to WebKit */
languages = e_spell_checker_list_active_languages (wk_editor->priv->spell_checker, NULL);
@@ -4987,12 +5003,20 @@ webkit_editor_constructor (GType type,
static gpointer web_context = NULL;
if (!web_context) {
+ gchar *service_name;
+
web_context = webkit_web_context_new ();
+ service_name = webkit_editor_create_service_name_for_web_context
(web_context);
+
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_web_extensions_initialization_user_data (web_context,
+ g_variant_new_string (service_name));
g_object_add_weak_pointer (G_OBJECT (web_context), &web_context);
+
+ g_free (service_name);
} else {
g_object_ref (web_context);
}
@@ -5013,6 +5037,9 @@ webkit_editor_dispose (GObject *object)
priv = E_WEBKIT_EDITOR_GET_PRIVATE (object);
+ if (priv->cancellable)
+ g_cancellable_cancel (priv->cancellable);
+
if (priv->aliasing_settings != NULL) {
g_signal_handlers_disconnect_by_data (priv->aliasing_settings, object);
g_object_unref (priv->aliasing_settings);
@@ -5124,6 +5151,7 @@ webkit_editor_finalize (GObject *object)
priv->last_hover_uri = NULL;
g_clear_object (&priv->spell_checker);
+ g_clear_object (&priv->cancellable);
g_free (priv->font_name);
@@ -5525,7 +5553,7 @@ webkit_editor_clipboard_owner_change_cb (GtkClipboard *clipboard,
"(tb)",
current_page_id (wk_editor),
wk_editor->priv->copy_paste_clipboard_in_view),
- NULL);
+ wk_editor->priv->cancellable);
wk_editor->priv->copy_cut_actions_triggered = FALSE;
@@ -5554,7 +5582,7 @@ webkit_editor_primary_clipboard_owner_change_cb (GtkClipboard *clipboard,
"(tb)",
current_page_id (wk_editor),
wk_editor->priv->copy_paste_clipboard_in_view),
- NULL);
+ wk_editor->priv->cancellable);
wk_editor->priv->pasting_from_itself_extension_value = wk_editor->priv->copy_paste_clipboard_in_view;
}
@@ -5929,12 +5957,12 @@ e_webkit_editor_init (EWebKitEditor *wk_editor)
wk_editor->priv = E_WEBKIT_EDITOR_GET_PRIVATE (wk_editor);
+ /* To be able to cancel any pending calls when 'dispose' is called. */
+ wk_editor->priv->cancellable = g_cancellable_new ();
wk_editor->priv->spell_check_enabled = TRUE;
wk_editor->priv->spell_checker = e_spell_checker_new ();
wk_editor->priv->old_settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) g_variant_unref);
- webkit_editor_watch_web_extension (wk_editor);
-
g_signal_connect (
wk_editor, "load-changed",
G_CALLBACK (webkit_editor_load_changed_cb), NULL);
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension-main.c
b/modules/webkit-editor/web-extension/e-editor-web-extension-main.c
index 244bc4c..be7f358 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension-main.c
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension-main.c
@@ -33,12 +33,19 @@ bus_acquired_cb (GDBusConnection *connection,
}
/* Forward declaration */
-G_MODULE_EXPORT void webkit_web_extension_initialize (WebKitWebExtension *wk_extension);
+G_MODULE_EXPORT void webkit_web_extension_initialize_with_user_data (WebKitWebExtension *wk_extension,
+ GVariant *user_data);
G_MODULE_EXPORT void
-webkit_web_extension_initialize (WebKitWebExtension *wk_extension)
+webkit_web_extension_initialize_with_user_data (WebKitWebExtension *wk_extension,
+ GVariant *user_data)
{
EEditorWebExtension *extension;
+ const gchar *service_name;
+
+ g_return_if_fail (user_data != NULL);
+
+ service_name = g_variant_get_string (user_data, NULL);
camel_debug_init ();
@@ -47,7 +54,7 @@ webkit_web_extension_initialize (WebKitWebExtension *wk_extension)
g_bus_own_name (
G_BUS_TYPE_SESSION,
- E_WEBKIT_EDITOR_WEB_EXTENSION_SERVICE_NAME,
+ service_name,
G_BUS_NAME_OWNER_FLAGS_NONE,
(GBusAcquiredCallback) bus_acquired_cb,
NULL, /* GBusNameAcquiredCallback */
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension-names.h
b/modules/webkit-editor/web-extension/e-editor-web-extension-names.h
index d1b5f02..9aee4ab 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension-names.h
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension-names.h
@@ -19,7 +19,7 @@
#ifndef E_EDITOR_WEB_EXTENSION_NAMES_H
#define E_EDITOR_WEB_EXTENSION_NAMES_H
-#define E_WEBKIT_EDITOR_WEB_EXTENSION_SERVICE_NAME "org.gnome.Evolution.WebExtension.EWebKitEditor"
+#define E_WEBKIT_EDITOR_WEB_EXTENSION_SERVICE_NAME_PREFIX "org.gnome.Evolution.WebExtension.EWebKitEditor"
#define E_WEBKIT_EDITOR_WEB_EXTENSION_OBJECT_PATH "/org/gnome/Evolution/WebExtension/EWebKitEditor"
#define E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE "org.gnome.Evolution.WebExtension.EWebKitEditor"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]