From 259bdf7c86fe9b4f58d73f7a63e197a0f9d59ef8 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Thu, 18 Aug 2016 22:52:30 +0900 Subject: [PATCH] Collect and store all content URLs in the tab --- content/treestyletab/content-utils.js | 57 +++++++++++++++++++++++++++ modules/constants.js | 3 +- modules/contentBridge.js | 6 ++- modules/utils.js | 12 ++++++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/content/treestyletab/content-utils.js b/content/treestyletab/content-utils.js index 511af1d4..1ac35952 100644 --- a/content/treestyletab/content-utils.js +++ b/content/treestyletab/content-utils.js @@ -12,13 +12,16 @@ var Cr = Components.results; var { TreeStyleTabConstants } = Cu.import('resource://treestyletab-modules/constants.js', {}); + var { XPCOMUtils } = Cu.import('resource://gre/modules/XPCOMUtils.jsm', {}); function free() { cleanup = Cc = Ci = Cu = Cr = TreeStyleTabConstants = + XPCOMUtils = messageListener = handleEvent = + progressListener = mydump = undefined; } @@ -31,6 +34,11 @@ case TreeStyleTabConstants.COMMAND_SHUTDOWN: global.removeMessageListener(TreeStyleTabConstants.MESSAGE_TYPE, messageListener); global.removeEventListener('selectionchange', handleEvent, true); + global.removeEventListener('DOMContentLoaded', handleEvent, true); + global.docShell + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebProgress) + .removeProgressListener(progressListener); free(); return; } @@ -49,7 +57,56 @@ text : aEvent.target.getSelection().toString() }); return; + + case 'DOMContentLoaded': + progressListener.onLocationChange(); + return; } } 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); diff --git a/modules/constants.js b/modules/constants.js index ca13ac1d..a5e565a0 100644 --- a/modules/constants.js +++ b/modules/constants.js @@ -14,7 +14,7 @@ * The Original Code is the Tree Style Tab. * * 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. * * Contributor(s): YUKI "Piro" Hiroshi @@ -243,6 +243,7 @@ var TreeStyleTabConstants = Object.freeze({ COMMAND_SHUTDOWN : 'shutdown', COMMAND_REPORT_SELECTION_CHANGE : 'report-selection-change', + COMMAND_REPORT_LOCATION_CHANGE : 'report-location-change', COMMAND_REPORT_MOUSEDOWN : 'report-mousedown', COMMAND_REPORT_MOUSEUP : 'report-mouseup', COMMAND_REPORT_MOUSEMOVE : 'report-mousemove', diff --git a/modules/contentBridge.js b/modules/contentBridge.js index d40246b1..51e589bf 100644 --- a/modules/contentBridge.js +++ b/modules/contentBridge.js @@ -14,7 +14,7 @@ * The Original Code is the Tree Style Tab. * * 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. * * Contributor(s): YUKI "Piro" Hiroshi @@ -127,6 +127,10 @@ ContentBridge.prototype = inherit(TreeStyleTabConstants, { this.mTab.__treestyletab__lastContentSelectionText = aMessage.json.text; return; + case this.COMMAND_REPORT_LOCATION_CHANGE: + this.mTab.__treestyletab__contentLocations = aMessage.json.locations; + return; + case this.COMMAND_REPORT_MOUSEDOWN: { let fakeEvent = this.fixupEventCoordinates(aMessage.json.event); diff --git a/modules/utils.js b/modules/utils.js index af093c60..fb9dfab3 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -730,6 +730,18 @@ var TreeStyleTabUtils = { 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']