adium 2748:eedc8ed773b1: Work on a root HTMLElement, which gives...

commits at adium.im commits at adium.im
Mon Oct 19 22:14:22 UTC 2009


details:	http://hg.adium.im/adium/rev/eedc8ed773b1
revision:	2748:eedc8ed773b1
author:		Stephen Holt <sholt at adium.im>
date:		Mon Oct 19 18:04:39 2009 -0400

Work on a root HTMLElement, which gives us querySelector() for the whole unattached DOM tree.
Subject: adium 2749:6c65e4eeb0db: Only hold the buffer for 10ms.  If new content comes in within that 10ms, extend it by another 10ms.

details:	http://hg.adium.im/adium/rev/6c65e4eeb0db
revision:	2749:6c65e4eeb0db
author:		Stephen Holt <sholt at adium.im>
date:		Mon Oct 19 18:12:00 2009 -0400

Only hold the buffer for 10ms.  If new content comes in within that 10ms, extend it by another 10ms.

This has the potential to DOS adium, so forcibly stop after 100 cycles (1s).

diffs (94 lines):

diff -r bd02bf4291ca -r 6c65e4eeb0db Plugins/WebKit Message View/Template.html
--- a/Plugins/WebKit Message View/Template.html	Mon Oct 19 17:19:51 2009 -0400
+++ b/Plugins/WebKit Message View/Template.html	Mon Oct 19 18:12:00 2009 -0400
@@ -21,8 +21,9 @@
 		// (ex. a long twitter timeline)
 		function CoalescedHTML() {
 			var self = this;
-			this.fragment = document.createDocumentFragment();
+			this.fragment = document.createElement("div");
 			this.timeoutID = 0;
+			this.coalesceRounds = 0;
 			this.isCoalescing = false;
 			this.shouldScroll = false;
 			
@@ -30,29 +31,33 @@
 				var insert = document.getElementById("insert");
 				if(insert)
 					insert.parentNode.removeChild(insert);
-
-				document.getElementById("Chat").appendChild(self.fragment);
+				
+				var documentFragment = document.createDocumentFragment();
+				for (var i = 0; i < self.fragment.children.length; i++) {
+					documentFragment.appendChild(self.fragment.children[i]);
+				}
+				
+				document.getElementById("Chat").appendChild(documentFragment);
 				alignChat(self.shouldScroll);
 				
-				self.fragment = document.createDocumentFragment();
+				self.fragment = document.createElement("div");
 				self.shouldScroll = false;
 				self.isCoalescing = false;
+				self.coalesceRounds = 0;
 			}
 			
-			function insertHTMLToNode(html, node) {
+			function createHTMLNode(html) {
 				var newMessage = document.createElement("div");
 				newMessage.innerHTML = html;
-				var children = newMessage.childNodes;
-				for (var i = 0; i < children.length; i++) {
-					node.appendChild(children[i]);
-				}
+				return newMessage.childNodes;
 			}
 			
 			this.coalesce = function() {
-				if(!self.isCoalescing) {
-					self.timeoutID = window.setTimeout(outputHTML, 100);
-					self.isCoalescing = true;
-				}
+				window.clearTimeout(self.timeoutID);
+				self.timeoutID = window.setTimeout(outputHTML, 10);
+				self.isCoalescing = true;
+				if(100 < self.coalesceRounds)
+					self.cancel();
 			}
 			
 			// if we need to append content into an insertion div,
@@ -65,14 +70,14 @@
 			}
 			
 			this.append = function(html, shouldScroll) {
-				var lastAppend = self.fragment.lastChild;
-				if(lastAppend){
-					var insert = lastAppend.querySelector("#insert");
-					if(insert)
-						insert.parentNode.removeChild(insert);
+				var insert = self.fragment.querySelector("#insert");
+				if(insert)
+					insert.parentNode.removeChild(insert);
+				
+				var node = createHTMLNode(html);
+				for (var i = 0; i < node.length; i++) {
+					self.fragment.appendChild(node[i].cloneNode(true));
 				}
-				
-				insertHTMLToNode(html, self.fragment);
 
 				if(shouldScroll) self.shouldScroll = shouldScroll;
 				self.coalesce();
@@ -81,9 +86,8 @@
 			this.appendNext = function(html, shouldScroll) {
 				insert = self.fragment.querySelector("#insert");
 				if(insert) {
-					var insertParent = insert.parentNode;
-					insertParent.removeNode(insert);
-					insertHTMLToNode(html, insertParent);
+					var node = createHTMLNode(html);
+					insert.parentNode.replaceChild(node[0].cloneNode(true),insert);
 				} else {
 					self.append(html, shouldScroll);
 				}




More information about the commits mailing list