Collect and store all content URLs in the tab

This commit is contained in:
Piro / YUKI Hiroshi 2016-08-18 22:52:30 +09:00
parent 796059daef
commit 259bdf7c86
4 changed files with 76 additions and 2 deletions

View File

@ -12,13 +12,16 @@
var Cr = Components.results; var Cr = Components.results;
var { TreeStyleTabConstants } = Cu.import('resource://treestyletab-modules/constants.js', {}); var { TreeStyleTabConstants } = Cu.import('resource://treestyletab-modules/constants.js', {});
var { XPCOMUtils } = Cu.import('resource://gre/modules/XPCOMUtils.jsm', {});
function free() { function free() {
cleanup = cleanup =
Cc = Ci = Cu = Cr = Cc = Ci = Cu = Cr =
TreeStyleTabConstants = TreeStyleTabConstants =
XPCOMUtils =
messageListener = messageListener =
handleEvent = handleEvent =
progressListener =
mydump = mydump =
undefined; undefined;
} }
@ -31,6 +34,11 @@
case TreeStyleTabConstants.COMMAND_SHUTDOWN: case TreeStyleTabConstants.COMMAND_SHUTDOWN:
global.removeMessageListener(TreeStyleTabConstants.MESSAGE_TYPE, messageListener); global.removeMessageListener(TreeStyleTabConstants.MESSAGE_TYPE, messageListener);
global.removeEventListener('selectionchange', handleEvent, true); global.removeEventListener('selectionchange', handleEvent, true);
global.removeEventListener('DOMContentLoaded', handleEvent, true);
global.docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress)
.removeProgressListener(progressListener);
free(); free();
return; return;
} }
@ -49,7 +57,56 @@
text : aEvent.target.getSelection().toString() text : aEvent.target.getSelection().toString()
}); });
return; return;
case 'DOMContentLoaded':
progressListener.onLocationChange();
return;
} }
} }
global.addEventListener('selectionchange', handleEvent, true); global.addEventListener('selectionchange', handleEvent, true);
global.addEventListener('DOMContentLoaded', handleEvent, true);
var progressListener = {
// nsIPorgressListener
onStateChange : function() {},
onProgressChange : function() {},
onLocationChange : function(aWebProgress, aRequest, aLocation, aFlags) {
global.sendAsyncMessage(TreeStyleTabConstants.MESSAGE_TYPE, {
command : TreeStyleTabConstants.COMMAND_REPORT_LOCATION_CHANGE,
locations : this.collectLocations(global.content)
});
},
onStatusChange : function() {},
onSecurityChange : function() {},
// nsISupports
QueryInterface : XPCOMUtils.generateQI([
Ci.nsIWebPorgressListener,
Ci.nsISupportsWeakReference,
Ci.nsISupports
]),
collectLocations : function(aFrame, aLocations) {
aLocations = aLocations || [];
aLocations.push(this.getHashString(aFrame.location.href));
Array.forEach(aFrame.frames, function(aSubFrame) {
this.collectLocations(aSubFrame, aLocations);
}, this);
return aLocations;
},
getHashString : function(aString) {
let hasher = Cc['@mozilla.org/security/hash;1']
.createInstance(Ci.nsICryptoHash);
hasher.init(Ci.nsICryptoHash.MD5);
let input = Cc['@mozilla.org/io/string-input-stream;1']
.createInstance(Ci.nsIStringInputStream);
input.data = aString;
hasher.updateFromStream(input, -1);
return hasher.finish(true);
}
};
global.docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress)
.addProgressListener(progressListener, Ci.nsIWebProgress.NOTIFY_LOCATION);
})(this); })(this);

View File

@ -14,7 +14,7 @@
* The Original Code is the Tree Style Tab. * The Original Code is the Tree Style Tab.
* *
* The Initial Developer of the Original Code is YUKI "Piro" Hiroshi. * The Initial Developer of the Original Code is YUKI "Piro" Hiroshi.
* Portions created by the Initial Developer are Copyright (C) 2010-2015 * Portions created by the Initial Developer are Copyright (C) 2010-2016
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): YUKI "Piro" Hiroshi <piro.outsider.reflex@gmail.com> * Contributor(s): YUKI "Piro" Hiroshi <piro.outsider.reflex@gmail.com>
@ -243,6 +243,7 @@ var TreeStyleTabConstants = Object.freeze({
COMMAND_SHUTDOWN : 'shutdown', COMMAND_SHUTDOWN : 'shutdown',
COMMAND_REPORT_SELECTION_CHANGE : 'report-selection-change', COMMAND_REPORT_SELECTION_CHANGE : 'report-selection-change',
COMMAND_REPORT_LOCATION_CHANGE : 'report-location-change',
COMMAND_REPORT_MOUSEDOWN : 'report-mousedown', COMMAND_REPORT_MOUSEDOWN : 'report-mousedown',
COMMAND_REPORT_MOUSEUP : 'report-mouseup', COMMAND_REPORT_MOUSEUP : 'report-mouseup',
COMMAND_REPORT_MOUSEMOVE : 'report-mousemove', COMMAND_REPORT_MOUSEMOVE : 'report-mousemove',

View File

@ -14,7 +14,7 @@
* The Original Code is the Tree Style Tab. * The Original Code is the Tree Style Tab.
* *
* The Initial Developer of the Original Code is YUKI "Piro" Hiroshi. * The Initial Developer of the Original Code is YUKI "Piro" Hiroshi.
* Portions created by the Initial Developer are Copyright (C) 2014-2015 * Portions created by the Initial Developer are Copyright (C) 2014-2016
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): YUKI "Piro" Hiroshi <piro.outsider.reflex@gmail.com> * Contributor(s): YUKI "Piro" Hiroshi <piro.outsider.reflex@gmail.com>
@ -127,6 +127,10 @@ ContentBridge.prototype = inherit(TreeStyleTabConstants, {
this.mTab.__treestyletab__lastContentSelectionText = aMessage.json.text; this.mTab.__treestyletab__lastContentSelectionText = aMessage.json.text;
return; return;
case this.COMMAND_REPORT_LOCATION_CHANGE:
this.mTab.__treestyletab__contentLocations = aMessage.json.locations;
return;
case this.COMMAND_REPORT_MOUSEDOWN: case this.COMMAND_REPORT_MOUSEDOWN:
{ {
let fakeEvent = this.fixupEventCoordinates(aMessage.json.event); let fakeEvent = this.fixupEventCoordinates(aMessage.json.event);

View File

@ -730,6 +730,18 @@ var TreeStyleTabUtils = {
return 'about:treestyletab-group?' + parameters.join('&'); return 'about:treestyletab-group?' + parameters.join('&');
}, },
getHashString : function utils_getHashString(aString)
{
let hasher = Cc['@mozilla.org/security/hash;1']
.createInstance(Ci.nsICryptoHash);
hasher.init(Ci.nsICryptoHash.MD5);
let input = Cc['@mozilla.org/io/string-input-stream;1']
.createInstance(Ci.nsIStringInputStream);
input.data = aString;
hasher.updateFromStream(input, -1);
return hasher.finish(true);
},
isMac : Cc['@mozilla.org/xre/app-info;1'] isMac : Cc['@mozilla.org/xre/app-info;1']