[evolution/wip/mcrha/webkit-jsc-api] Few initial changes, like to load .js files into the editor



commit 4adea36eb61528e5635396a1eb8887ab807a4332
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 22 21:37:06 2019 +0200

    Few initial changes, like to load .js files into the editor
    
    ...and attach/replace some functions

 data/webkit/e-editor.js                            |  55 +++++++
 data/webkit/e-undo-redo.js                         |  12 +-
 src/e-util/e-util-enums.h                          |  18 ++-
 src/modules/webkit-editor/e-webkit-editor.c        | 108 ++++++-------
 .../webkit-editor/web-extension/e-editor-page.c    |  41 -----
 .../webkit-editor/web-extension/e-editor-page.h    |   2 -
 .../web-extension/e-editor-web-extension.c         | 180 +++++----------------
 7 files changed, 164 insertions(+), 252 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index dee4c83979..6e9e9785e9 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -21,4 +21,59 @@
    public functions start with upper-case letter. */
 
 var EvoEditor = {
+       E_CONTENT_EDITOR_ALIGNMENT_LEFT : 0,
+       E_CONTENT_EDITOR_ALIGNMENT_CENTER : 1,
+       E_CONTENT_EDITOR_ALIGNMENT_RIGHT : 2,
+
+       E_CONTENT_EDITOR_BLOCK_FORMAT_NONE : 0,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_PARAGRAPH : 1,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_PRE : 2,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_ADDRESS : 3,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_H1 : 4,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_H2 : 5,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_H3 : 6,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_H4 : 7,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_H5 : 8,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_H6 : 9,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_UNORDERED_LIST : 10,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_ORDERED_LIST : 11,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_ORDERED_LIST_ROMAN : 12,
+       E_CONTENT_EDITOR_BLOCK_FORMAT_ORDERED_LIST_ALPHA : 13,
+
+       htmlFormat : false,
+       storedSelection : null
 };
+
+EvoEditor.StoreSelection = function()
+{
+       EvoEditor.storedSelection = EvoSelection.Store(document);
+}
+
+EvoEditor.RestoreSelection = function()
+{
+       if (EvoEditor.storedSelection) {
+               EvoSelection.Restore(document, EvoEditor.storedSelection);
+               EvoEditor.storedSelection = null;
+       }
+}
+
+EvoEditor.SetAlignment = function(alignment)
+{
+       EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setAlignment");
+
+       try {
+       } finally {
+               EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setAlignment");
+       }
+}
+
+EvoEditor.SetBlockFormat = function(format)
+{
+}
+
+document.onload = function() {
+       /* Make sure there is a selection */
+       if (!document.getSelection().baseNode) {
+               document.getSelection.setPosition(document.body.firstChild ? document.body.firstChild : 
document.body, 0);
+       }
+}
diff --git a/data/webkit/e-undo-redo.js b/data/webkit/e-undo-redo.js
index 9ecc3b9ad5..086701790c 100644
--- a/data/webkit/e-undo-redo.js
+++ b/data/webkit/e-undo-redo.js
@@ -227,14 +227,18 @@ var EvoUndoRedo = {
 
 EvoUndoRedo.Attach = function()
 {
-       document.documentElement.onbeforeinput = EvoUndoRedo.before_input_cb;
-       document.documentElement.oninput = EvoUndoRedo.input_cb;
+       if (document.documentElement) {
+               document.documentElement.onbeforeinput = EvoUndoRedo.before_input_cb;
+               document.documentElement.oninput = EvoUndoRedo.input_cb;
+       }
 }
 
 EvoUndoRedo.Detach = function()
 {
-       document.documentElement.onbeforeinput = null;
-       document.documentElement.oninput = null;
+       if (document.documentElement) {
+               document.documentElement.onbeforeinput = null;
+               document.documentElement.oninput = null;
+       }
 }
 
 EvoUndoRedo.Enable = function()
diff --git a/src/e-util/e-util-enums.h b/src/e-util/e-util-enums.h
index a951f6b223..9bdb26d3af 100644
--- a/src/e-util/e-util-enums.h
+++ b/src/e-util/e-util-enums.h
@@ -535,18 +535,20 @@ typedef enum {
 } EContentEditorFindFlags;
 
 /**
- * EClipboardFlags:
- * @E_CLIPBOARD_CAN_COPY: It's possible to copy the currently selected content.
+ * EUndoRedoState:
+ * @E_UNDO_REDO_STATE_NONE: Cannot undo, neither redo.
+ * @E_UNDO_REDO_STATE_CAN_UNDO: Undo is available.
+ * @E_UNDO_REDO_STATE_CAN_REDO: Redo is available.
  *
- * Specifies clipboard's current state.
+ * Flags in what state Undo/Redo stack is.
  *
- * Since: 3.24
+ * Since: 3.36
  **/
 typedef enum {
-       E_CLIPBOARD_CAN_COPY    = 1 << 0
-       /* E_CLIPBOARD_CAN_CUT  = 1 << 1,
-       E_CLIPBOARD_CAN_PASTE   = 1 << 2 */
-} EClipboardFlags;
+       E_UNDO_REDO_STATE_NONE          = 0,
+       E_UNDO_REDO_STATE_CAN_UNDO      = 1 << 0,
+       E_UNDO_REDO_STATE_CAN_REDO      = 1 << 1
+} EUndoRedoState;
 
 /**
  * EDnDTargetType:
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 5cb78d692d..f810810333 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -80,7 +80,6 @@ struct _EWebKitEditorPrivate {
        gint stamp; /* Changed only in the main thread, doesn't need locking */
        guint web_extension_selection_changed_cb_id;
        guint web_extension_content_changed_cb_id;
-       guint web_extension_undo_redo_state_changed_cb_id;
        guint web_extension_user_changed_default_colors_cb_id;
 
        gboolean html_mode;
@@ -472,27 +471,30 @@ web_extension_selection_changed_cb (GDBusConnection *connection,
        g_object_thaw_notify (G_OBJECT (wk_editor));
 }
 
+
 static void
-web_extension_undo_redo_state_changed_cb (GDBusConnection *connection,
-                                          const gchar *sender_name,
-                                          const gchar *object_path,
-                                          const gchar *interface_name,
-                                          const gchar *signal_name,
-                                          GVariant *parameters,
-                                          EWebKitEditor *wk_editor)
+undu_redo_state_changed_cb (WebKitUserContentManager *manager,
+                           WebKitJavascriptResult *js_result,
+                           gpointer user_data)
 {
-       guint64 page_id = 0;
-       gboolean can_undo = FALSE, can_redo = FALSE;
+       EWebKitEditor *wk_editor = user_data;
+       JSCValue *jsc_value;
+       JSCValue *jsc_params;
+       gint32 state;
 
-       if (g_strcmp0 (signal_name, "UndoRedoStateChanged") != 0)
-               return;
+       g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
+       g_return_if_fail (js_result != NULL);
 
-       g_variant_get (parameters, "(tbb)", &page_id, &can_undo, &can_redo);
+       jsc_params = webkit_javascript_result_get_js_value (js_result);
+       g_return_if_fail (jsc_value_is_object (jsc_params));
 
-       if (page_id == webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (wk_editor))) {
-               webkit_editor_set_can_undo (wk_editor, can_undo);
-               webkit_editor_set_can_redo (wk_editor, can_redo);
-       }
+       jsc_value = jsc_value_object_get_property (jsc_params, "state");
+       g_return_if_fail (jsc_value_is_number (jsc_value));
+       state = jsc_value_to_int32 (jsc_value);
+       g_clear_object (&jsc_value);
+
+       webkit_editor_set_can_undo (wk_editor, (state & E_UNDO_REDO_STATE_CAN_UNDO) != 0);
+       webkit_editor_set_can_redo (wk_editor, (state & E_UNDO_REDO_STATE_CAN_REDO) != 0);
 }
 
 static void
@@ -611,12 +613,6 @@ e_webkit_editor_set_web_extension_proxy (EWebKitEditor *wk_editor,
                        wk_editor->priv->web_extension_selection_changed_cb_id = 0;
                }
 
-               if (wk_editor->priv->web_extension_undo_redo_state_changed_cb_id) {
-                       if (connection)
-                               g_dbus_connection_signal_unsubscribe (connection, 
wk_editor->priv->web_extension_undo_redo_state_changed_cb_id);
-                       wk_editor->priv->web_extension_undo_redo_state_changed_cb_id = 0;
-               }
-
                if (wk_editor->priv->web_extension_user_changed_default_colors_cb_id) {
                        if (connection)
                                g_dbus_connection_signal_unsubscribe (connection, 
wk_editor->priv->web_extension_user_changed_default_colors_cb_id);
@@ -655,19 +651,6 @@ e_webkit_editor_set_web_extension_proxy (EWebKitEditor *wk_editor,
                                wk_editor,
                                NULL);
 
-               wk_editor->priv->web_extension_undo_redo_state_changed_cb_id =
-                       g_dbus_connection_signal_subscribe (
-                               g_dbus_proxy_get_connection (wk_editor->priv->web_extension_proxy),
-                               g_dbus_proxy_get_name (wk_editor->priv->web_extension_proxy),
-                               E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE,
-                               "UndoRedoStateChanged",
-                               E_WEBKIT_EDITOR_WEB_EXTENSION_OBJECT_PATH,
-                               NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE,
-                               (GDBusSignalCallback) web_extension_undo_redo_state_changed_cb,
-                               wk_editor,
-                               NULL);
-
                wk_editor->priv->web_extension_user_changed_default_colors_cb_id =
                        g_dbus_connection_signal_subscribe (
                                g_dbus_proxy_get_connection (wk_editor->priv->web_extension_proxy),
@@ -2070,9 +2053,12 @@ webkit_editor_undo (EContentEditor *editor)
 {
        EWebKitEditor *wk_editor;
 
+       g_return_if_fail (E_IS_WEBKIT_EDITOR (editor));
+
        wk_editor = E_WEBKIT_EDITOR (editor);
 
-       webkit_editor_call_simple_extension_function (wk_editor, "DOMUndo");
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+               "EvoUndoRedo.Undo();");
 }
 
 static gboolean
@@ -2092,7 +2078,8 @@ webkit_editor_redo (EContentEditor *editor)
 
        wk_editor = E_WEBKIT_EDITOR (editor);
 
-       webkit_editor_call_simple_extension_function (wk_editor, "DOMRedo");
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+               "EvoUndoRedo.Redo();");
 }
 
 static void
@@ -2596,18 +2583,12 @@ webkit_editor_clear_undo_redo_history (EContentEditor *editor)
 {
        EWebKitEditor *wk_editor;
 
-       wk_editor = E_WEBKIT_EDITOR (editor);
+       g_return_if_fail (E_IS_WEBKIT_EDITOR (editor));
 
-       if (!wk_editor->priv->web_extension_proxy) {
-               g_warning ("EHTMLEditorWebExtension not ready at %s!", G_STRFUNC);
-               return;
-       }
+       wk_editor = E_WEBKIT_EDITOR (editor);
 
-       e_util_invoke_g_dbus_proxy_call_with_error_check (
-               wk_editor->priv->web_extension_proxy,
-               "DOMClearUndoRedoHistory",
-               g_variant_new ("(t)", current_page_id (wk_editor)),
-               wk_editor->priv->cancellable);
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+               "EvoUndoRedo.Clear();");
 }
 
 static void
@@ -2862,10 +2843,12 @@ webkit_editor_selection_save (EContentEditor *editor)
 {
        EWebKitEditor *wk_editor;
 
+       g_return_if_fail (E_IS_WEBKIT_EDITOR (editor));
+
        wk_editor = E_WEBKIT_EDITOR (editor);
 
-       webkit_editor_call_simple_extension_function (
-               wk_editor, "DOMSaveSelection");
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+               "EvoEditor.StoreSelection();");
 }
 
 static void
@@ -2873,10 +2856,12 @@ webkit_editor_selection_restore (EContentEditor *editor)
 {
        EWebKitEditor *wk_editor;
 
+       g_return_if_fail (E_IS_WEBKIT_EDITOR (editor));
+
        wk_editor = E_WEBKIT_EDITOR (editor);
 
-       webkit_editor_call_simple_extension_function (
-               wk_editor, "DOMRestoreSelection");
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+               "EvoEditor.RestoreSelection();");
 }
 
 static void
@@ -3795,8 +3780,9 @@ webkit_editor_set_alignment (EWebKitEditor *wk_editor,
 {
        g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
 
-       webkit_editor_set_format_int (
-               wk_editor, "DOMSelectionSetAlignment", (gint32) value);
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+               "EvoEditor.SetAlignment(%d);",
+               value);
 }
 
 static EContentEditorAlignment
@@ -3813,8 +3799,9 @@ webkit_editor_set_block_format (EWebKitEditor *wk_editor,
 {
        g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
 
-       webkit_editor_set_format_int (
-               wk_editor, "DOMSelectionSetBlockFormat", (gint32) value);
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+               "EvoEditor.SetBlockFormat(%d);",
+               value);
 }
 
 static EContentEditorBlockFormat
@@ -5231,6 +5218,7 @@ webkit_editor_constructed (GObject *object)
        WebKitWebContext *web_context;
        WebKitSettings *web_settings;
        WebKitWebView *web_view;
+       WebKitUserContentManager *manager;
 
        wk_editor = E_WEBKIT_EDITOR (object);
        web_view = WEBKIT_WEB_VIEW (wk_editor);
@@ -5244,6 +5232,13 @@ webkit_editor_constructed (GObject *object)
 
        G_OBJECT_CLASS (e_webkit_editor_parent_class)->constructed (object);
 
+       manager = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (wk_editor));
+
+       g_signal_connect_object (manager, "script-message-received::undoRedoStateChanged",
+               G_CALLBACK (undu_redo_state_changed_cb), wk_editor, 0);
+
+       webkit_user_content_manager_register_script_message_handler (manager, "undoRedoStateChanged");
+
        /* Give spell check languages to WebKit */
        languages = e_spell_checker_list_active_languages (wk_editor->priv->spell_checker, NULL);
 
@@ -6647,7 +6642,6 @@ e_webkit_editor_init (EWebKitEditor *wk_editor)
 
        wk_editor->priv->web_extension_selection_changed_cb_id = 0;
        wk_editor->priv->web_extension_content_changed_cb_id = 0;
-       wk_editor->priv->web_extension_undo_redo_state_changed_cb_id = 0;
        wk_editor->priv->web_extension_user_changed_default_colors_cb_id = 0;
 }
 
diff --git a/src/modules/webkit-editor/web-extension/e-editor-page.c 
b/src/modules/webkit-editor/web-extension/e-editor-page.c
index 8164900575..9a21a76a78 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-page.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-page.c
@@ -147,14 +147,6 @@ e_editor_page_setup (EEditorPage *editor_page,
        editor_page->priv->web_extension = web_extension;
        editor_page->priv->undo_redo_manager = e_editor_undo_redo_manager_new (editor_page);
 
-       g_signal_connect_swapped (
-               editor_page->priv->undo_redo_manager, "notify::can-undo",
-               G_CALLBACK (e_editor_page_emit_undo_redo_state_changed), editor_page);
-
-       g_signal_connect_swapped (
-               editor_page->priv->undo_redo_manager, "notify::can-redo",
-               G_CALLBACK (e_editor_page_emit_undo_redo_state_changed), editor_page);
-
        web_editor = webkit_web_page_get_editor (web_page);
 
        g_signal_connect_swapped (
@@ -982,39 +974,6 @@ e_editor_page_emit_content_changed (EEditorPage *editor_page)
        }
 }
 
-void
-e_editor_page_emit_undo_redo_state_changed (EEditorPage *editor_page)
-{
-       GDBusConnection *connection;
-       GError *error = NULL;
-
-       g_return_if_fail (E_IS_EDITOR_PAGE (editor_page));
-
-       if (!editor_page->priv->web_extension)
-               return;
-
-       connection = e_editor_web_extension_get_connection (editor_page->priv->web_extension);
-       if (!connection)
-               return;
-
-       g_dbus_connection_emit_signal (
-               connection,
-               NULL,
-               E_WEBKIT_EDITOR_WEB_EXTENSION_OBJECT_PATH,
-               E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE,
-               "UndoRedoStateChanged",
-               g_variant_new ("(tbb)",
-                       e_editor_page_get_page_id (editor_page),
-                       e_editor_undo_redo_manager_can_undo (editor_page->priv->undo_redo_manager),
-                       e_editor_undo_redo_manager_can_redo (editor_page->priv->undo_redo_manager)),
-               &error);
-
-       if (error) {
-               g_warning ("%s: Failed to emit signal: %s", G_STRFUNC, error->message);
-               g_error_free (error);
-       }
-}
-
 void
 e_editor_page_emit_user_changed_default_colors (EEditorPage *editor_page,
                                                 gboolean suppress_color_changes)
diff --git a/src/modules/webkit-editor/web-extension/e-editor-page.h 
b/src/modules/webkit-editor/web-extension/e-editor-page.h
index 8365149ee8..8fffb4860a 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-page.h
+++ b/src/modules/webkit-editor/web-extension/e-editor-page.h
@@ -212,8 +212,6 @@ void                e_editor_page_emit_selection_changed
                                                (EEditorPage *editor_page);
 void           e_editor_page_emit_content_changed
                                                (EEditorPage *editor_page);
-void           e_editor_page_emit_undo_redo_state_changed
-                                               (EEditorPage *editor_page);
 void           e_editor_page_emit_user_changed_default_colors
                                                (EEditorPage *editor_page,
                                                 gboolean suppress_color_changes);
diff --git a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c 
b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
index 73d3f4a23e..de431baffd 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -83,11 +83,6 @@ static const gchar *introspection_xml =
 "    <signal name='ContentChanged'>"
 "      <arg type='t' name='page_id' direction='out'/>"
 "    </signal>"
-"    <signal name='UndoRedoStateChanged'>"
-"      <arg type='t' name='page_id' direction='out'/>"
-"      <arg type='b' name='can_undo' direction='out'/>"
-"      <arg type='b' name='can_redo' direction='out'/>"
-"    </signal>"
 "    <signal name='UserChangedDefaultColors'>"
 "      <arg type='b' name='suppress_color_changes' direction='out'/>"
 "    </signal>"
@@ -436,18 +431,6 @@ static const gchar *introspection_xml =
 "    <method name='DOMRemoveEmbeddedStyleSheet'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "    </method>"
-"    <method name='DOMSaveSelection'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"    </method>"
-"    <method name='DOMRestoreSelection'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"    </method>"
-"    <method name='DOMUndo'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"    </method>"
-"    <method name='DOMRedo'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"    </method>"
 "    <method name='DOMQuoteAndInsertTextIntoSelection'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='text' direction='in'/>"
@@ -613,9 +596,6 @@ static const gchar *introspection_xml =
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='u' name='offset' direction='out'/>"
 "    </method>"
-"    <method name='DOMClearUndoRedoHistory'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"    </method>"
 "  </interface>"
 "</node>";
 
@@ -1637,52 +1617,6 @@ handle_method_call (GDBusConnection *connection,
 
                g_dbus_method_invocation_return_value (
                        invocation, g_variant_new ("(i)", value));
-       } else if (g_strcmp0 (method_name, "DOMSaveSelection") == 0) {
-               g_variant_get (parameters, "(t)", &page_id);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               e_editor_dom_selection_save (editor_page);
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "DOMRestoreSelection") == 0) {
-               g_variant_get (parameters, "(t)", &page_id);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               e_editor_dom_selection_restore (editor_page);
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "DOMUndo") == 0) {
-               EEditorUndoRedoManager *manager;
-
-               g_variant_get (parameters, "(t)", &page_id);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               manager = e_editor_page_get_undo_redo_manager (editor_page);
-
-               e_editor_undo_redo_manager_undo (manager);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "DOMRedo") == 0) {
-               EEditorUndoRedoManager *manager;
-
-               g_variant_get (parameters, "(t)", &page_id);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               manager = e_editor_page_get_undo_redo_manager (editor_page);
-
-               e_editor_undo_redo_manager_redo (manager);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "DOMTurnSpellCheckOff") == 0) {
                g_variant_get (parameters, "(t)", &page_id);
 
@@ -2262,20 +2196,6 @@ handle_method_call (GDBusConnection *connection,
                g_dbus_method_invocation_return_value (
                        invocation,
                        g_variant_new ("(u)", value));
-       } else if (g_strcmp0 (method_name, "DOMClearUndoRedoHistory") == 0) {
-               EEditorUndoRedoManager *manager;
-
-               g_variant_get (parameters, "(t)", &page_id);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               manager = e_editor_page_get_undo_redo_manager (editor_page);
-               if (manager)
-                       e_editor_undo_redo_manager_clean_history (manager);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
        } else {
                g_warning ("UNKNOWN METHOD '%s'", method_name);
        }
@@ -2468,37 +2388,6 @@ web_page_send_request_cb (WebKitWebPage *web_page,
        return FALSE;
 }
 
-static void
-web_page_document_loaded_cb (WebKitWebPage *web_page,
-                             gpointer user_data)
-{
-       WebKitDOMDocument *document;
-       WebKitDOMRange *range = NULL;
-       WebKitDOMDOMWindow *dom_window;
-       WebKitDOMDOMSelection *dom_selection;
-
-       g_return_if_fail (WEBKIT_IS_WEB_PAGE (web_page));
-
-       document = webkit_web_page_get_dom_document (web_page);
-       if (!document)
-               return;
-
-       dom_window = webkit_dom_document_get_default_view (document);
-       dom_selection = webkit_dom_dom_window_get_selection (dom_window);
-
-       /* Make sure there is a cursor located in the body after the document loads. */
-       if (!webkit_dom_dom_selection_get_anchor_node (dom_selection) &&
-           !webkit_dom_dom_selection_get_focus_node (dom_selection)) {
-               range = webkit_dom_document_caret_range_from_point (document, 0, 0);
-               webkit_dom_dom_selection_remove_all_ranges (dom_selection);
-               webkit_dom_dom_selection_add_range (dom_selection, range);
-       }
-
-       g_clear_object (&range);
-       g_clear_object (&dom_selection);
-       g_clear_object (&dom_window);
-}
-
 static void
 web_page_notify_uri_cb (GObject *object,
                        GParamSpec *param,
@@ -2571,35 +2460,6 @@ web_page_notify_uri_cb (GObject *object,
        g_warning ("%s: Cannot find web_page %p\n", G_STRFUNC, web_page);
 }
 
-static void
-web_page_created_cb (WebKitWebExtension *wk_extension,
-                     WebKitWebPage *web_page,
-                     EEditorWebExtension *extension)
-{
-       EEditorPage *editor_page;
-
-       g_return_if_fail (WEBKIT_IS_WEB_PAGE (web_page));
-       g_return_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension));
-
-       editor_page = e_editor_page_new (web_page, extension);
-       extension->priv->pages = g_slist_prepend (extension->priv->pages, editor_page);
-
-       g_object_weak_ref (G_OBJECT (web_page), web_page_gone_cb, extension);
-
-       g_signal_connect (
-               web_page, "send-request",
-               G_CALLBACK (web_page_send_request_cb), extension);
-
-       g_signal_connect (
-               web_page, "document-loaded",
-               G_CALLBACK (web_page_document_loaded_cb), NULL);
-
-       g_signal_connect_object (
-               web_page, "notify::uri",
-               G_CALLBACK (web_page_notify_uri_cb),
-               extension, 0);
-}
-
 static void
 load_javascript_file (JSCContext *jsc_context,
                      const gchar *js_filename)
@@ -2667,6 +2527,46 @@ window_object_cleared_cb (WebKitScriptWorld *world,
        g_clear_object (&jsc_context);
 }
 
+static void
+web_page_document_loaded_cb (WebKitWebPage *web_page,
+                            gpointer user_data)
+{
+       g_return_if_fail (WEBKIT_IS_WEB_PAGE (web_page));
+
+       window_object_cleared_cb (NULL, web_page, webkit_web_page_get_main_frame (web_page), NULL);
+}
+
+static void
+web_page_created_cb (WebKitWebExtension *wk_extension,
+                     WebKitWebPage *web_page,
+                     EEditorWebExtension *extension)
+{
+       EEditorPage *editor_page;
+
+       g_return_if_fail (WEBKIT_IS_WEB_PAGE (web_page));
+       g_return_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension));
+
+       window_object_cleared_cb (NULL, web_page, webkit_web_page_get_main_frame (web_page), NULL);
+
+       editor_page = e_editor_page_new (web_page, extension);
+       extension->priv->pages = g_slist_prepend (extension->priv->pages, editor_page);
+
+       g_object_weak_ref (G_OBJECT (web_page), web_page_gone_cb, extension);
+
+       g_signal_connect (
+               web_page, "send-request",
+               G_CALLBACK (web_page_send_request_cb), extension);
+
+       g_signal_connect_object (
+               web_page, "notify::uri",
+               G_CALLBACK (web_page_notify_uri_cb),
+               extension, 0);
+
+       g_signal_connect (
+               web_page, "document-loaded",
+               G_CALLBACK (web_page_document_loaded_cb), NULL);
+}
+
 void
 e_editor_web_extension_initialize (EEditorWebExtension *extension,
                                    WebKitWebExtension *wk_extension)


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