[evolution/wip/mcrha/webkit-jsc-api] Load the ext-utils.js only to the main frame, not to the subframes



commit 9173a469325109bf1a0a6f2a46b8d1d93de70f25
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 26 09:38:29 2019 +0200

    Load the ext-utils.js only to the main frame, not to the subframes

 src/web-extensions/e-web-extension.c | 18 ++++++++++++++++++
 src/web-extensions/ext-utils.js      | 14 +++++++-------
 2 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/src/web-extensions/e-web-extension.c b/src/web-extensions/e-web-extension.c
index c091bf03b2..9ea45a6537 100644
--- a/src/web-extensions/e-web-extension.c
+++ b/src/web-extensions/e-web-extension.c
@@ -2194,6 +2194,10 @@ window_object_cleared_cb (WebKitScriptWorld *world,
        gsize data_size = 0;
        GError *error = NULL;
 
+       /* Load the ext-utils.js only to the main frame, not to the subframes */
+       if (!webkit_frame_is_main_frame (frame))
+               return;
+
        bytes = g_resources_lookup_data ("/org/gnome/evolution-web-process-extension/js/ext-utils.js", 
G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
        if (!bytes) {
                g_warning ("Failed to load ext-utils.js: %s", error ? error->message : "Unknown error");
@@ -2207,6 +2211,20 @@ window_object_cleared_cb (WebKitScriptWorld *world,
        /* Preload utility functions */
        result = jsc_context_evaluate_with_source_uri (jsc_context, data, data_size, 
"resource:///org/gnome/evolution-web-process-extension/js/ext-utils.js", 1);
 
+       if (result) {
+               JSCException *exception;
+
+               exception = jsc_context_get_exception (jsc_context);
+
+               if (exception) {
+                       g_warning ("Failed to call initial script for %s-frame: %d:%d: %s",
+                               webkit_frame_is_main_frame (frame) ? "main" : "sub",
+                               jsc_exception_get_line_number (exception),
+                               jsc_exception_get_column_number (exception),
+                               jsc_exception_get_message (exception));
+               }
+       }
+
        g_clear_pointer (&bytes, g_bytes_unref);
        g_clear_object (&result);
        g_clear_object (&jsc_context);
diff --git a/src/web-extensions/ext-utils.js b/src/web-extensions/ext-utils.js
index 275b375aed..d9a1572c48 100644
--- a/src/web-extensions/ext-utils.js
+++ b/src/web-extensions/ext-utils.js
@@ -170,8 +170,8 @@ Evo.SetDocumentContent = function(content)
 {
        document.documentElement.innerHTML = content;
 
-       window.webkit.messageHandlers.contentLoaded.postMessage("");
        Evo.Initialize("");
+       window.webkit.messageHandlers.contentLoaded.postMessage("");
 }
 
 Evo.SetIFrameSrc = function(iframe_id, src_uri)
@@ -189,8 +189,8 @@ Evo.SetIFrameContent = function(iframe_id, content)
        if (iframe) {
                iframe.contentDocument.documentElement.innerHTML = content;
 
-               window.webkit.messageHandlers.contentLoaded.postMessage(iframe_id);
                Evo.Initialize(iframe);
+               window.webkit.messageHandlers.contentLoaded.postMessage(iframe_id);
        }
 }
 
@@ -260,7 +260,7 @@ Evo.Initialize = function(elem)
        elems = doc.getElementsByTagName("iframe");
 
        for (ii = 0; ii < elems.length; ii++) {
-               elems[ii].onload = function() { Evo.PostContentLoadedAndInitialize(this) };
+               elems[ii].onload = function() { Evo.InitializeAndPostContentLoaded(this) };
        }
 
        if (!doc.body.hasAttribute("class"))
@@ -273,7 +273,7 @@ Evo.Initialize = function(elem)
        }
 }
 
-Evo.PostContentLoadedAndInitialize = function(elem)
+Evo.InitializeAndPostContentLoaded = function(elem)
 {
        var iframe_id = "";
 
@@ -282,13 +282,13 @@ Evo.PostContentLoadedAndInitialize = function(elem)
        else if (window.frameElement)
                iframe_id = window.frameElement.id;
 
-       window.webkit.messageHandlers.contentLoaded.postMessage(iframe_id);
        Evo.Initialize(elem);
+       window.webkit.messageHandlers.contentLoaded.postMessage(iframe_id);
 }
 
 if (this instanceof Window && this.document) {
-       this.document.onload = function() { Evo.PostContentLoadedAndInitialize(this); };
+       this.document.onload = function() { Evo.InitializeAndPostContentLoaded(this); };
 
        if (this.document.body.firstChild)
-               Evo.PostContentLoadedAndInitialize(this.document);
+               Evo.InitializeAndPostContentLoaded(this.document);
 }


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