[evolution/wip/mcrha/webkit-jsc-api] Introduce additional Evo.runTraversarForIFrameId() helper function



commit 91443dfcd0197db7b20da66356cdafde093ef118
Author: Milan Crha <mcrha redhat com>
Date:   Wed Oct 2 18:37:11 2019 +0200

    Introduce additional Evo.runTraversarForIFrameId() helper function

 src/web-extensions/ext-utils.js | 89 +++++++++++++++++------------------------
 1 file changed, 37 insertions(+), 52 deletions(-)
---
diff --git a/src/web-extensions/ext-utils.js b/src/web-extensions/ext-utils.js
index ce44f9c02a..51116bb779 100644
--- a/src/web-extensions/ext-utils.js
+++ b/src/web-extensions/ext-utils.js
@@ -30,9 +30,9 @@ Evo.foreachIFrameDocument = function(doc, traversar_obj, call_also_for_doc)
        return true;
 }
 
-Evo.findIFrameInDocument = function(doc, iframe_id)
+Evo.findIFrame = function(iframe_id)
 {
-       if (!doc)
+       if (iframe_id == "")
                return null;
 
        var traversar = {
@@ -47,27 +47,34 @@ Evo.findIFrameInDocument = function(doc, iframe_id)
                }
        };
 
-       Evo.foreachIFrameDocument(doc, traversar, true);
+       Evo.foreachIFrameDocument(document, traversar, true);
 
        return traversar.iframe;
 }
 
-Evo.findIFrame = function(iframe_id)
+Evo.findIFrameDocument = function(iframe_id)
 {
        if (iframe_id == "")
-               return null;
-
-       return Evo.findIFrameInDocument(document, iframe_id);
-}
+               return document;
 
-Evo.findIFrameDocument = function(iframe_id)
-{
        var iframe = Evo.findIFrame(iframe_id);
 
        if (iframe)
                return iframe.contentDocument;
 
-       return document;
+       return null;
+}
+
+Evo.runTraversarForIFrameId = function(iframe_id, traversar_obj)
+{
+       if (iframe_id == "*") {
+               Evo.foreachIFrameDocument(document, traversar_obj, true);
+       } else {
+               var doc = Evo.findIFrameDocument(iframe_id);
+
+               if (doc)
+                       traversar_obj.exec(doc, iframe_id);
+       }
 }
 
 Evo.findElementInDocumentById = function(doc, element_id)
@@ -89,34 +96,20 @@ Evo.findElementInDocumentById = function(doc, element_id)
 
 Evo.findElement = function(iframe_id, element_id)
 {
-       var iframe;
-
-       if (iframe_id == "")
-               return Evo.findElementInDocumentById(document, element_id);
-
-       if (iframe_id == "*") {
-               var traversar = {
-                       element_id : element_id,
-                       res : null,
-                       exec : function(doc, iframe_id) {
-                               this.res = Evo.findElementInDocumentById(doc, element_id);
-                               if (this.res)
-                                       return false;
-                               return true;
-                       }
-               };
-
-               Evo.foreachIFrameDocument(document, traversar, true);
-
-               return traversar.res;
-       }
-
-       iframe = Evo.findIFrame(iframe_id);
+       var traversar = {
+               element_id : element_id,
+               res : null,
+               exec : function(doc, iframe_id) {
+                       this.res = Evo.findElementInDocumentById(doc, this.element_id);
+                       if (this.res)
+                               return false;
+                       return true;
+               }
+       };
 
-       if (!iframe)
-               return null;
+       Evo.runTraversarForIFrameId(iframe_id, traversar);
 
-       return Evo.findElementInDocumentById(iframe.contentDocument, element_id);
+       return traversar.res;
 }
 
 Evo.SetElementHidden = function(iframe_id, element_id, value)
@@ -168,6 +161,10 @@ Evo.createStyleSheet = function(doc, style_sheet_id, content)
 Evo.CreateStyleSheet = function(iframe_id, style_sheet_id, content)
 {
        var doc = Evo.findIFrameDocument(iframe_id);
+
+       if (!doc)
+               return;
+
        var styles = doc.head.getElementsByTagName("style"), ii;
 
        for (ii = 0; ii < styles.length; ii++) {
@@ -199,11 +196,7 @@ Evo.RemoveStyleSheet = function(iframe_id, style_sheet_id)
                }
        };
 
-       if (iframe_id == "*") {
-               Evo.foreachIFrameDocument(document, traversar, true);
-       } else {
-               traversar.exec(Evo.findIFrameDocument(iframe_id), iframe_id);
-       }
+       Evo.runTraversarForIFrameId(iframe_id, traversar);
 }
 
 Evo.addRuleIntoStyleSheetDocument = function(doc, style_sheet_id, selector, style)
@@ -247,11 +240,7 @@ Evo.AddRuleIntoStyleSheet = function(iframe_id, style_sheet_id, selector, style)
                }
        };
 
-       if (iframe_id == "*") {
-               Evo.foreachIFrameDocument(document, traversar, true);
-       } else {
-               traversar.exec(Evo.findIFrameDocument(iframe_id), iframe_id);
-       }
+       Evo.runTraversarForIFrameId(iframe_id, traversar);
 }
 
 Evo.SetDocumentContent = function(content)
@@ -361,11 +350,7 @@ Evo.RegisterElementClicked = function(iframe_id, elem_classes_str)
                }
        };
 
-       if (iframe_id == "*") {
-               Evo.foreachIFrameDocument(document, traversar, true);
-       } else {
-               traversar.exec(Evo.findIFrameDocument(iframe_id), iframe_id);
-       }
+       Evo.runTraversarForIFrameId(iframe_id, traversar);
 }
 
 Evo.checkAnyParentIsPre = function(node)


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