Permalink
Browse files

General clean up trying to avoid memory leaks.

  • Loading branch information...
cezarsa committed Mar 6, 2012
1 parent 09f44cb commit 3577866b035697ed893a51f5281c39c16d43f072
Showing with 65 additions and 36 deletions.
  1. +1 −1 background.html
  2. +5 −0 lib/image_services.js
  3. +8 −1 lib/send_queue.js
  4. +46 −33 lib/tweets_assembler.js
  5. +1 −0 lib/twitter_lib.js
  6. +4 −1 popup.html
View
@@ -369,7 +369,7 @@
},
setTimelineOrder: function(sortedTimelinesArray) {
- this.timelineOrderCache = sortedTimelinesArray;
+ this.timelineOrderCache = sortedTimelinesArray.slice(0);
this.timelineOrderData.save(JSON.stringify(sortedTimelinesArray));
},
View
@@ -42,6 +42,11 @@ var UploadManager = {
return true;
}
return false;
+ },
+
+ unregisterCallbacks: function() {
+ this.onFinish = null;
+ this.onProgress = null;
}
};
View
@@ -49,13 +49,20 @@ SendQueue.prototype = {
this.onSendFailedCallback = onSendFailedCallback;
},
+ cleanUpCallbacks: function() {
+ this.onQueueEmptyCallback = null;
+ this.onTweetEnqueuedCallback = null;
+ this.onTweetSentCallback = null;
+ this.onSendFailedCallback = null;
+ },
+
_safeCallbackCall: function(callbackFunc) {
if(callbackFunc) {
try {
var args = Array.prototype.slice.call(arguments);
callbackFunc.apply(this, args.slice(1, args.length));
} catch(e) {
- /* ignoring */
+ /* ignoring, popup dead? */
}
}
},
View
@@ -103,9 +103,9 @@ var Renderer = {
gravity: $.fn.tipsy.autoWE
});
return true;
- } else {
- return false;
}
+
+ return false;
},
expandLink: function (aElement, url) {
@@ -241,10 +241,33 @@ var Renderer = {
}
]),
- parseEntities: function(text, entities) {
- var mapFunc = function(type) {
+ entitiesFuncs: {
+ typeMap: function(type) {
return function(e) {e.type = type; return e;};
- };
+ },
+ indexSort: function(e1, e2) {
+ return e1.indices[0] - e2.indices[0];
+ },
+ handleHashTag: function(link, value) {
+ AnyClick.anyClick(link, function(ev) {
+ if(Renderer.isNotification() || !OptionsBackend.get('open_searches_internally')) {
+ openTab(TwitterLib.URLS.SEARCH + "%23" + value);
+ } else {
+ TimelineTab.addNewSearchTab('#' + value, ev.isAlternateClick);
+ }
+ });
+ },
+ handleLink: function(link, baseUrl, expandedUrl, mediaUrl) {
+ var toExpandUrl = mediaUrl || expandedUrl || baseUrl;
+
+ AnyClick.anyClick(link, function() { openTab(baseUrl); });
+ link.addEventListener('mouseover', function() { Renderer.expandLink(this, toExpandUrl); }, false);
+ }
+ },
+
+ parseEntities: function(text, entities) {
+ var mapFunc = this.entitiesFuncs.typeMap,
+ sortFunc = this.entitiesFuncs.indexSort;
entities.media = entities.media || [];
@@ -254,66 +277,56 @@ var Renderer = {
entities.user_mentions.map(mapFunc('mention')),
entities.media.map(mapFunc('media')));
- orderedEntities.sort(function(e1, e2) {
- return e1.indices[0] - e2.indices[0];
- });
+ orderedEntities.sort(sortFunc);
+
+ var totalInc = 0,
+ elements = document.createDocumentFragment(),
+ i, len, entity, indices, link, textContent;
+
+ for (i = 0, len = orderedEntities.length; i < len; ++i) {
+ entity = orderedEntities[i];
+ indices = entity.indices;
+ link = null;
- var totalInc = 0;
- var elements = document.createDocumentFragment();
- orderedEntities.forEach(function(entity) {
- var indices = entity.indices,
- link = null,
- toExpandUrl;
elements.appendChild(Renderer.makeText(text.substring(totalInc, indices[0])));
if (entity.type === 'mention') {
elements.appendChild(Renderer.makeText('@'));
-
link = Renderer.makeElem("a", {href: '#'}, entity.screen_name);
Renderer.createUserActionMenu(link, entity.screen_name);
} else if (entity.type === 'hashtag') {
link = Renderer.makeElem("a", {href: '#'}, '#' + entity.text);
-
- AnyClick.anyClick(link, function(event) {
- if(Renderer.isNotification() || !OptionsBackend.get('open_searches_internally')) {
- openTab(TwitterLib.URLS.SEARCH + "%23" + entity.text);
- } else {
- TimelineTab.addNewSearchTab('#' + entity.text, event.isAlternateClick);
- }
- });
+ this.entitiesFuncs.handleHashTag(link, entity.text);
} else if (entity.type === 'url' || entity.type === "media") {
+
entity.display_url = entity.display_url || entity.url;
link = Renderer.makeElem("a", { href: entity.url }, entity.display_url);
if (entity.display_url[entity.display_url.length - 1].charCodeAt(0) == 8230) { // Ends with ...
link.setAttribute('title', entity.expanded_url);
}
- AnyClick.anyClick(link, function() { openTab(entity.url); });
-
- toExpandUrl = entity.expanded_url || entity.url;
- if (entity.type === "media") {
- toExpandUrl = entity.media_url;
- }
- link.addEventListener('mouseover', function() { Renderer.expandLink(this, toExpandUrl); }, false);
+ this.entitiesFuncs.handleLink(link, entity.url, entity.expanded_url, entity.media_url);
} else {
- var textContent = Transforms.transformEntities(text.substring(indices[0], indices[1]));
+
+ textContent = Transforms.transformEntities(text.substring(indices[0], indices[1]));
elements.appendChild(Renderer.makeText(textContent));
+
}
if (link) {
elements.appendChild(link);
}
totalInc = indices[1];
- });
+ }
- var textContent = Transforms.transformEntities(text.substring(totalInc, text.length));
+ textContent = Transforms.transformEntities(text.substring(totalInc, text.length));
elements.appendChild(Renderer.makeText(textContent));
return elements;
View
@@ -561,6 +561,7 @@ TwitterOAuth.prototype = {
try {
this.responseCallback(success);
} catch(e) { /* ignoring */ }
+ this.responseCallback = null;
}
},
requestTokenCallback: function(data, status, tryAgain) {
View
@@ -1633,6 +1633,10 @@
if(tweetManager) {
tweetManager.registerWarningsCallback(null);
tweetManager.registerNewTweetsCallback(null);
+ tweetManager.sendQueue.cleanUpCallbacks();
+ }
+ if(UploadManager) {
+ UploadManager.unregisterCallbacks();
}
});
@@ -1731,7 +1735,6 @@
</head>
<body>
<div id="error" style="display: none;"></div>
-
<div id="workspace" style="display: none;">
<div id="absolute_container">
<div id="warning">

0 comments on commit 3577866

Please sign in to comment.