[Pkg-mozext-commits] [itsalltext] 109/459: Fixed problem with the back and forwards buttons, I no longer delete tracker info for pages still in cache.

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:12 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 ee7477d4cb21f1061eb10904065473a793bceb3d
Author: Christian Höltje <docwhat at gerf.org>
Date:   Sun Feb 4 12:39:25 2007 -0500

    Fixed problem with the back and forwards buttons, I no longer delete tracker info for pages still in cache.
---
 chrome/content/cacheobj.js   | 48 ++++++++++++++++++++++++++------
 chrome/content/itsalltext.js | 65 ++++++++++++++------------------------------
 2 files changed, 59 insertions(+), 54 deletions(-)

diff --git a/chrome/content/cacheobj.js b/chrome/content/cacheobj.js
index 50f2ce3..58d421a 100644
--- a/chrome/content/cacheobj.js
+++ b/chrome/content/cacheobj.js
@@ -19,27 +19,34 @@ function CacheObj(node) {
     that.button = null;
     that.initial_color = 'transparent';
      
-    that.node_id = ItsAllText.getNodeIdentifier(node);
-    that.doc_id  = ItsAllText.getDocumentIdentifier(node.ownerDocument);
-    that.uid = that.hashString([ that.doc_id,
+    that.node_id = that.getNodeIdentifier(node);
+    var doc = node.ownerDocument;
+
+    /* This is a unique identifier for use on the web page to prevent the
+     * web page from knowing what it's connected to.
+     * @type String
+     */
+    that.uid = that.hashString([ doc.location.toString(),
                                  Math.random(),
                                  that.node_id ].join(':'));
 
-    that.filename = that.hashString([ that.doc_id,
-                                      that.node_id ].join(':'));
-
     node.setAttribute(ItsAllText.MYSTRING+'_UID', that.uid);
     ItsAllText.tracker[that.uid] = that;
     
+    /* Figure out where we will store the file.  While the filename can
+     * change, the directory that the file is stored in should not!
+     */
+    ItsAllText.debug('narf',doc, doc.location);
+
+    var hostname = doc.location.toString;
     /* Since the hash is supposed to be equally distributed, it shouldn't
      * matter how we slice it.  However, this does make it less unique.
      */
-
-    // @todo [security] Detect collisions using the raw key.
+    that.filename = that.hashString([ doc.location.toString(),
+                                      that.node_id ].join(':'));
     that.filename = that.filename.slice(0,15);
      
     var editdir = ItsAllText.getEditDir();
-    ItsAllText.debug('editdir',editdir.path);
 
     /* Get a file */
     that.file = Components.classes["@mozilla.org/file/local;1"].
@@ -71,6 +78,29 @@ function CacheObj(node) {
         var style = that.button.style;
         style.opacity = '0.1';
     };
+}
+
+
+/**
+ * Returns a unique identifier for the node, within the document.
+ * @returns {String} the unique identifier.
+ */
+CacheObj.prototype.getNodeIdentifier = function(node) {
+    var id   = node.getAttribute('id');
+    if (!id) {
+        var name = node.getAttribute('name');
+        var doc = node.ownerDocument.getElementsByTagName('html')[0];
+        var attr = ItsAllText.MYSTRING+'_id_serial';
+        
+        /* Get a serial that's unique to this document */
+        var serial = doc.getAttribute(attr);
+        if (serial) { serial = parseInt(serial, 10)+1;
+        } else { serial = 1; }
+        id = [ItsAllText.MYSTRING,'generated_id',name,serial].join('_');
+        doc.setAttribute(attr,serial);
+        node.setAttribute('id',id);
+    }
+    return id;
 };
 
 /**
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index 3c2e817..e2989c0 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -242,39 +242,6 @@ var ItsAllText = function() {
         return that.preferences.debug;
     };
 
-    /**
-     * Returns a unique identifier for the node, within the document.
-     * @returns {String} the unique identifier.
-     */
-    that.getNodeIdentifier = function(node) {
-        var id   = node.getAttribute('id');
-        if (!id) {
-            var name = node.getAttribute('name');
-            var doc = node.ownerDocument.getElementsByTagName('html')[0];
-            var attr = that.MYSTRING+'_id_serial';
-        
-            /* Get a serial that's unique to this document */
-            var serial = doc.getAttribute(attr);
-            if (serial) { serial = parseInt(serial, 10)+1;
-            } else { serial = 1; }
-            id = [that.MYSTRING,'generated_id',name,serial].join('_');
-            doc.setAttribute(attr,serial);
-      
-            node.setAttribute('id',id);
-        }
-        return id;
-    };
-
-    /**
-     * Returns a unique identifier for the document.
-     * @returns {String} the unique identifier.
-     */
-    that.getDocumentIdentifier = function(doc) {
-        // @todo [low] getDocumentIdentifier should sort arguments and append the post data.
-        return doc.URL;
-    };
-
-
     // @todo [med] Profiling and optimization.
     
     /**
@@ -300,7 +267,7 @@ var ItsAllText = function() {
     that.cleanCacheObjs = function() {
         var count = 0;
         for(var id in that.tracker) {
-            var cobj = tracker[id];
+            var cobj = that.tracker[id];
             if (cobj.node.ownerDocument.location === null) {
                 that.debug('cleaning %s', id);
                 delete cobj.node;
@@ -335,6 +302,7 @@ var ItsAllText = function() {
      */
     that.refreshDocument = function(doc) {
         // @todo [high] Confirm that we find textareas inside iframes and frames.
+        if(!doc.location) { return; } // it's being cached, but not shown.
         var is_chrome = (doc.location.protocol == 'chrome:');
         var nodes = doc.getElementsByTagName('textarea');
         var i;
@@ -427,23 +395,28 @@ var ItsAllText = function() {
             var did_delete = false;
             for(i in documents) {
                 var doc = documents[i];
-                that.refreshDocument(doc);
                 if (doc.location) {
                     that.debuglog('refreshing', doc.location);
                     that.refreshDocument(doc);
-                } else {
+                }
+            }
+        },
+        /**
+         * Stops watching doc.
+         * @param {Object} doc The document to watch.
+         */
+        unwatch: function(doc) {
+            var documents = that.monitor.documents;
+            for(i in documents) {
+                if (documents[i] === doc) {
+                    that.debug('unwatching', doc);
                     delete documents[i];
-                    did_delete = true;
                 }
             }
-
-            if(did_delete) {
-                /* Remove deleted elements */
-                that.cleanCacheObjs();
-                for(i=documents.length - 1; i >= 0; i--) {
-                    if(typeof(documents[i]) == 'undefined') {
-                        documents.splice(i,1);
-                    }
+            that.cleanCacheObjs();
+            for(i=documents.length - 1; i >= 0; i--) {
+                if(typeof(documents[i]) == 'undefined') {
+                    documents.splice(i,1);
                 }
             }
         }
@@ -513,6 +486,8 @@ var ItsAllText = function() {
   
     // Do the startup when things are loaded.
     window.addEventListener("load", startup, true);
+    // Do the startup when things are unloaded.
+    window.addEventListener("unload", function(event){that.monitor.unwatch(event.originalTarget||document);}, true);
 
     // Start the monitor
     that.monitor.restart();

-- 
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