[Pkg-mozext-commits] [greasemonkey] 28/62: fixes greasemonkey/greasemonkey#2246
David Prévot
taffit at moszumanska.debian.org
Sun Sep 13 22:10:22 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository greasemonkey.
commit 6b05c4803c96ef4f947a229679e2160be13577af
Author: The8472 <git at infinite-source.de>
Date: Thu Aug 20 22:45:13 2015 +0200
fixes greasemonkey/greasemonkey#2246
build the dropdown menu asynchronously after requesting the frame URLs
through the message manager.
---
content/browser.js | 30 +++++++++++++++++++-----------
content/framescript.js | 3 +++
modules/processScript.js | 29 +++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 11 deletions(-)
diff --git a/content/browser.js b/content/browser.js
index 1b71668..6ddbe11 100644
--- a/content/browser.js
+++ b/content/browser.js
@@ -266,15 +266,26 @@ function GM_popupClicked(aEvent) {
* When a menu pops up, fill its contents with the list of scripts.
*/
function GM_showPopup(aEvent) {
- function urlsOfAllFrames(contentWindow) {
- var urls = [contentWindow.location.href];
- function collect(contentWindow) {
- urls = urls.concat(urlsOfAllFrames(contentWindow));
- }
- Array.prototype.slice.call(contentWindow.frames).forEach(collect);
- return urls;
+ // Make sure this event was triggered by opening the actual monkey menu,
+ // not one of its submenus.
+ if (aEvent.currentTarget != aEvent.target) return;
+
+ var mm = getBrowser().mCurrentBrowser.frameLoader.messageManager;
+
+ var callback = function(message) {
+ mm.removeMessageListener("greasemonkey:frame-urls", callback);
+
+ var urls = message.data.urls;
+ asyncShowPopup(aEvent, urls);
}
+
+ mm.addMessageListener("greasemonkey:frame-urls", callback)
+ mm.sendAsyncMessage("greasemonkey:frame-urls", {});
+
+}
+function asyncShowPopup(aEvent, urls) {
+
function uniq(a) {
var seen = {}, list = [], item;
for (var i = 0; i < a.length; i++) {
@@ -306,9 +317,7 @@ function GM_showPopup(aEvent) {
return mi;
}
- // Make sure this event was triggered by opening the actual monkey menu,
- // not one of its submenus.
- if (aEvent.currentTarget != aEvent.target) return;
+
var popup = aEvent.target;
var scriptsFramedEl = popup.getElementsByClassName("scripts-framed-point")[0];
@@ -327,7 +336,6 @@ function GM_showPopup(aEvent) {
removeMenuitemsAfter(scriptsFramedEl);
removeMenuitemsAfter(scriptsTopEl);
- var urls = uniq( urlsOfAllFrames( getBrowser().contentWindow ));
var runsOnTop = scriptsMatching( [urls.shift()] ); // first url = top window
var runsFramed = scriptsMatching( urls ); // remainder are all its subframes
diff --git a/content/framescript.js b/content/framescript.js
index f5807e6..c3b7e00 100644
--- a/content/framescript.js
+++ b/content/framescript.js
@@ -17,6 +17,9 @@ Cu.import('chrome://greasemonkey-modules/content/scriptProtocol.js');
Cu.import('chrome://greasemonkey-modules/content/documentObserver.js');
Cu.import('chrome://greasemonkey-modules/content/util.js');
+// register with process script. no need to import all the vars into the local scope
+Cu.import('chrome://greasemonkey-modules/content/processScript.js', {}).addFrame(this);
+
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
var gScope = this;
diff --git a/modules/processScript.js b/modules/processScript.js
new file mode 100644
index 0000000..3aa3271
--- /dev/null
+++ b/modules/processScript.js
@@ -0,0 +1,29 @@
+'use strict';
+
+// frame scripts, including all their functions, block scopes etc. are instantiated for each tab
+// having a single per-process script has a lower footprint for stateless things.
+// avoid keeping references to frame scripts or their content, this could leak frames!
+
+const EXPORTED_SYMBOLS = ['addFrame'];
+
+
+function addFrame(frameMM) {
+ frameMM.addMessageListener("greasemonkey:frame-urls", urlTree)
+}
+
+
+function urlsOfAllFrames(contentWindow) {
+ var urls = [contentWindow.location.href];
+ function collect(contentWindow) {
+ urls = urls.concat(urlsOfAllFrames(contentWindow));
+ }
+ Array.from(contentWindow.frames).forEach(collect);
+ return urls;
+}
+
+function urlTree(message) {
+ var frameMM = message.target;
+ var urls = urlsOfAllFrames(frameMM.content);
+ var response = {urls: urls};
+ frameMM.sendAsyncMessage("greasemonkey:frame-urls", response);
+}
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/greasemonkey.git
More information about the Pkg-mozext-commits
mailing list