[Pkg-mozext-commits] [itsalltext] 326/459: Ticket #1 iframe/frames don't work

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:34 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit 5c9c0a6783927f8b2e5786cd7153f29ee5d8186e
Author: Christian Höltje <docwhat at gmail.com>
Date:   Wed Oct 22 21:06:34 2008 -0400

    Ticket #1 iframe/frames don't work
    
    Thanks to Nick Borko for much help. :-)
---
 src/chrome/content/API.js        |   2 +-
 src/chrome/content/cacheobj.js   |   5 +-
 src/chrome/content/itsalltext.js |  49 +++---------------
 src/chrome/content/monitor.js    | 106 +++++++++++++++++++++++++--------------
 4 files changed, 80 insertions(+), 82 deletions(-)

diff --git a/src/chrome/content/API.js b/src/chrome/content/API.js
index 807fd7b..9f68f45 100644
--- a/src/chrome/content/API.js
+++ b/src/chrome/content/API.js
@@ -97,7 +97,7 @@
         i,
         nodesIter;
         /* Start watching the document, but force it. */
-        ItsAllText.new_monitor.startPage({originalTarget: document}, true);
+        ItsAllText.monitor.startPage({originalTarget: document}, true);
 
         /* Turn on all the hidden CSS */
         nodesIter = document.evaluate("//node()[@itsalltext-control]",
diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index 34cf515..1fbbaf7 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -111,7 +111,10 @@ function CacheObj(node) {
             style.setProperty('opacity', '0.7',   'important');
             style.setProperty('display', 'block', 'important');
         }
-        ItsAllText.refreshTextarea(that.node);
+
+        // Refresh the Textarea.
+        that.update();
+        that.addGumDrop();
     };
 
     /**
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index 1ba9c8a..c7141bb 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -196,7 +196,7 @@ var ItsAllText = function () {
         loader.loadSubScript('chrome://itsalltext/content/Color.js', that);
         loader.loadSubScript('chrome://itsalltext/content/monitor.js', that);
         loader.loadSubScript('chrome://itsalltext/content/cacheobj.js', that);
-        that.new_monitor = new that.new_monitor(that);
+        that.monitor = new that.monitor(that);
     };
     loadthings();
 
@@ -301,7 +301,7 @@ var ItsAllText = function () {
             if (that.preferences) {
                 that.preferences[aData] = that.preferences.private_get(aData);
                 if (aData == 'refresh') {
-                    that.new_monitor.restart();
+                    that.monitor.restart();
                 }
             }
         }
@@ -480,49 +480,12 @@ var ItsAllText = function () {
         that.debug('textarea count (tracker):', count);
     };
 
-    /**
-     * Refresh Textarea.
-     * @param {Object} node A specific textarea dom object to update.
-     */
-    that.refreshTextarea = function (node, is_chrome) {
-        var cobj = ItsAllText.CacheObj.get(node);
-        if (!cobj) {
-            return;
-        }
-
-        cobj.update();
-        if (!is_chrome) {
-            cobj.addGumDrop();
-        }
-    };
-
     // @todo [wish] Refresh textarea on editor quit.
     // @todo [9] IDEA: support for input elements as well?
     // @todo [5] Minimum size for textareas.
     // @todo [5] Mark textareas somehow as 'in editor'.
 
     /**
-     * Refresh Document.
-     * @param {Object} doc The document to refresh.
-     */
-    that.refreshDocument = function (doc) {
-        if (!doc.location) {
-            return; // it's being cached, but not shown.
-        }
-        var is_chrome = (doc.location.protocol == 'chrome:' &&
-                         doc.location.href != that.README),
-            nodes = doc.getElementsByTagName('textarea'),
-            i;
-        for (i = 0; i < nodes.length; i++) {
-            that.refreshTextarea(nodes[i], is_chrome);
-        }
-        nodes = doc.getElementsByTagName('textbox');
-        for (i = 0; i < nodes.length; i++) {
-            that.refreshTextarea(nodes[i], is_chrome);
-        }
-    };
-
-    /**
      * Returns the offset from the containing block.
      * @param {Object} node A DOM element.
      * @param {Object} container If unset, then this will use the offsetParent of node. Pass in null to go all the way to the root.
@@ -683,12 +646,12 @@ var ItsAllText = function () {
     that.listen(window, 'load', function (event) {
         that.debug('!!load', event);
         if (typeof(gBrowser) === 'undefined') {
-            that.new_monitor.registerPage(event);
+            that.monitor.registerPage(event);
         } else {
             // Add a callback to be run every time a document loads.
             // note that this includes frames/iframes within the document
             that.listen(gBrowser, "load",
-                        that.new_monitor.registerPage, true);
+                        that.monitor.registerPage, true);
         }
 
         // Start watching the preferences.
@@ -704,13 +667,13 @@ var ItsAllText = function () {
     // TODONOW: move to separate function
     that.listen(window, 'unload', function (event) {
         if (typeof(gBrowser) === 'undefined') {
-            that.new_monitor.stopPage(event);
+            that.monitor.stopPage(event);
         }
         var doc = event.originalTarget;
         that.debug("pageunload(): A page has been unloaded", doc && doc.location);
         that.cleanCacheObjs();
         that.preference_observer.unregister();
-        that.new_monitor.destroy();
+        that.monitor.destroy();
     }, false);
 
 };
diff --git a/src/chrome/content/monitor.js b/src/chrome/content/monitor.js
index feacf69..4c4a5de 100644
--- a/src/chrome/content/monitor.js
+++ b/src/chrome/content/monitor.js
@@ -18,11 +18,11 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-function new_monitor(iat) {
+function monitor(iat) {
     var hitch_re = /^hitched_/,
         method;
     this.iat = iat;
-    this.iat.debug('new_monitor');
+    this.iat.debug('monitor');
 
     for (method in this) {
         if (hitch_re.test(method)) {
@@ -34,11 +34,11 @@ function new_monitor(iat) {
 
 }
 
-new_monitor.destroy = function () {
+monitor.destroy = function () {
     delete this.iat;
 };
 
-new_monitor.prototype.hitched_restart = function () {
+monitor.prototype.hitched_restart = function () {
     var rate = this.iat.getRefresh(),
         id   = this.id;
     if (id) {
@@ -47,21 +47,14 @@ new_monitor.prototype.hitched_restart = function () {
     this.id = setInterval(this.watcher, rate);
 };
 
-new_monitor.prototype.hitched_registerPage = function (event) {
+/**
+ * Gets a page ready to be used by IAT.
+ * This is called as an event handler.
+ */
+monitor.prototype.hitched_registerPage = function (event) {
     var doc, appContent;
     if (event.originalTarget instanceof HTMLDocument) {
         doc = event.originalTarget;
-        if (doc.defaultView.frameElement) {
-            // Frame within a tab was loaded. doc should be the root document of
-            // the frameset. If you don't want do anything when frames/iframes
-            // are loaded in this web page, uncomment the following line:
-            // return;
-            // Find the root document:
-            while (doc.defaultView.frameElement) {
-                doc = doc.defaultView.frameElement.ownerDocument;
-            }
-        }
-
         this.iat.debug('registerPage: ', doc && doc.location);
 
         /* appContent is the browser chrome. */
@@ -74,20 +67,68 @@ new_monitor.prototype.hitched_registerPage = function (event) {
     }
 };
 
-new_monitor.prototype.hitched_watcher = function (offset, init) {
+/**
+ * This is called repeatedly and regularly to trigger updates for the
+ * cache objects in the page.
+ */
+monitor.prototype.hitched_watcher = function (offset, init) {
     if (typeof(offset) === 'number' &&
         offset.type === 'TabSelect') {
         init = true;
     }
     var rate = this.iat.getRefresh(),
         now = Date.now(),
+        that = this,
+        findnodes,
         doc,
         nodes = [],
         i,
         cobj,
-        node,
-        is_html,
-        is_xul;
+        node;
+
+    /* Finds all nodes under a doc; includes iframes and frames. */
+    findnodes = function (doc) {
+        if (!doc) {
+            return [];
+        }
+        var is_html = that.isHTML(doc),
+            is_xul  = that.isXUL(doc),
+            i,
+            tmp,
+            nodes = [],
+            iframes,
+            frames;
+        if (is_html) {
+            /* HTML */
+            tmp = doc.getElementsByTagName('textarea');
+            for (i = 0; i < tmp.length; i++) {
+                nodes.push(tmp[i]);
+            }
+
+            /* Now that we got the nodes in this document,
+             * look for other documents. */
+            iframes = doc.getElementsByTagName('iframe');
+            for (i = 0; i < iframes.length; i++) {
+                nodes.push.apply(nodes, (findnodes(iframes[i].contentDocument)));
+            }
+
+            frames = doc.getElementsByTagName('frame');
+            for (i = 0; i < frames.length; i++) {
+                nodes.push.apply(nodes, (findnodes(frames[i].contentDocument)));
+            }
+        } else if (is_xul) {
+            /* XUL */
+            tmp = doc.getElementsByTagName('textbox');
+            for (i = 0; i < tmp.length; i++) {
+                nodes.push(tmp[i]);
+            }
+        } else {
+            that.stopPage({originalTarget: doc});
+            return [];
+        }
+        return nodes;
+    };
+
     if (!init && now - this.last_watcher_call < Math.round(rate * 0.9)) {
         this.iat.debug('watcher(', offset, '/', (now - this.last_watcher_call), ') -- skipping catchup refresh');
         return;
@@ -102,22 +143,13 @@ new_monitor.prototype.hitched_watcher = function (offset, init) {
         doc = gBrowser.selectedBrowser.contentDocument;
     }
     this.iat.debug('watcher: ', offset, init, doc && doc.location);
-    is_html = this.isHTML(doc);
-    is_xul  = this.isXUL(doc);
-    if (is_html) {
-        /* HTML */
-        nodes = doc.getElementsByTagName('textarea');
-    } else if (is_xul) {
-        /* XUL */
-        nodes = doc.getElementsByTagName('textbox');
-    } else {
-        this.stopPage({originalTarget: doc});
-        return;
-    }
+    nodes = findnodes(doc);
+    /* Now that we have the nodes, walk through and either make or
+     * get the cache objects and update them. */
     for (i = 0; i < nodes.length; i++) {
         node = nodes[i];
         if (init) {
-            cobj = ItsAllText.CacheObj.make(node, is_html);
+            cobj = ItsAllText.CacheObj.make(node, this.isHTML(doc));
         } else {
             cobj = ItsAllText.CacheObj.get(node);
         }
@@ -127,7 +159,7 @@ new_monitor.prototype.hitched_watcher = function (offset, init) {
     }
 };
 
-new_monitor.prototype.hitched_startPage = function (event, force) {
+monitor.prototype.hitched_startPage = function (event, force) {
     var doc = event.originalTarget,
         unsafeWin;
     this.iat.debug('startPage', doc && doc.location, force);
@@ -147,7 +179,7 @@ new_monitor.prototype.hitched_startPage = function (event, force) {
     this.restart();
 };
 
-new_monitor.prototype.hitched_stopPage = function (event) {
+monitor.prototype.hitched_stopPage = function (event) {
     var doc = event.originalTarget,
         unsafeWin;
     this.iat.debug('stopPage', doc && doc.location);
@@ -158,7 +190,7 @@ new_monitor.prototype.hitched_stopPage = function (event) {
     }
 };
 
-new_monitor.prototype.isXUL = function (doc) {
+monitor.prototype.isXUL = function (doc) {
     var contentType = doc && doc.contentType,
         is_xul = (contentType == 'application/vnd.mozilla.xul+xml'),
         is_my_readme;
@@ -170,7 +202,7 @@ new_monitor.prototype.isXUL = function (doc) {
     return is_xul && !is_my_readme;
 };
 
-new_monitor.prototype.isHTML = function (doc) {
+monitor.prototype.isHTML = function (doc) {
     var contentType,
         location,
         is_html,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list