[Pkg-mozext-commits] [greasemonkey] 11/45: Move menu command event handling to GM_MenuCommander.
David Prévot
taffit at moszumanska.debian.org
Mon Nov 3 20:59:19 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository greasemonkey.
commit 8692e5d9efb2b3c9368efdcd405de1638c468bd0
Author: Ventero <ventero at ventero.de>
Date: Sun Sep 21 01:54:34 2014 +0200
Move menu command event handling to GM_MenuCommander.
---
components/greasemonkey.js | 21 ---------------------
content/browser.js | 12 ++++++------
content/menucommander.js | 33 ++++++++++++++++++++++++++++-----
3 files changed, 34 insertions(+), 32 deletions(-)
diff --git a/components/greasemonkey.js b/components/greasemonkey.js
index 402a8f8..b3f130c 100644
--- a/components/greasemonkey.js
+++ b/components/greasemonkey.js
@@ -335,27 +335,6 @@ service.prototype.__defineGetter__('config', function() {
return this._config;
});
-service.prototype.contentDestroyed = function(aContentWindowId) {
- removeMatchingMenuCommands(null, function(index, command) {
- // Remove the reference if either the window is closed, ...
- return (GM_util.windowIsClosed(command.contentWindow)
- // ... or the content destroyed message matches the command's window id.
- || (aContentWindowId && (command.contentWindowId == aContentWindowId)));
- }, true); // Don't forget the aForced=true passed here!
-};
-
-service.prototype.contentFrozen = function(contentWindowId) {
- if (!contentWindowId) return;
- withAllMenuCommandsForWindowId(contentWindowId,
- function(index, command) { command.frozen = true; });
-};
-
-service.prototype.contentThawed = function(contentWindowId) {
- if (!contentWindowId) return;
- withAllMenuCommandsForWindowId(contentWindowId,
- function(index, command) { command.frozen = false; });
-};
-
service.prototype.runScripts = function(aRunWhen, aWrappedContentWin) {
// See #1970
// When content does (e.g.) history.replacestate() in an inline script,
diff --git a/content/browser.js b/content/browser.js
index 21a609a..aa42277 100644
--- a/content/browser.js
+++ b/content/browser.js
@@ -88,16 +88,16 @@ GM_BrowserUI.chromeLoad = function(e) {
GM_BrowserUI.pagehide = function(aEvent) {
var windowId = GM_util.windowIdForEvent(aEvent);
- if (aEvent.persisted) {
- GM_BrowserUI.gmSvc.contentFrozen(windowId);
- } else {
- GM_BrowserUI.gmSvc.contentDestroyed(windowId);
- }
+ if (!windowId) return;
+
+ GM_MenuCommander.onPageHide(windowId, aEvent.persisted);
};
GM_BrowserUI.pageshow = function(aEvent) {
var windowId = GM_util.windowIdForEvent(aEvent);
- GM_BrowserUI.gmSvc.contentThawed(windowId);
+ if (!windowId) return;
+
+ GM_MenuCommander.onPageShow(windowId);
};
// nsIObserve
diff --git a/content/menucommander.js b/content/menucommander.js
index b2da3f2..b66fa03 100644
--- a/content/menucommander.js
+++ b/content/menucommander.js
@@ -2,6 +2,10 @@ Components.utils.import('resource://greasemonkey/util.js');
var GM_MenuCommander = {};
+// Mix in menucommand.js so we don't pollute the global scope
+Components.utils.import('resource://greasemonkey/menucommand.js',
+ GM_MenuCommander);
+
GM_MenuCommander.createMenuItem = function(command) {
var menuItem = document.createElement("menuitem");
menuItem.setAttribute("label", command.name);
@@ -16,6 +20,29 @@ GM_MenuCommander.createMenuItem = function(command) {
return menuItem;
};
+GM_MenuCommander.onPageHide = function(aWindowId, aPersisted) {
+ if (aPersisted) {
+ GM_MenuCommander.withAllMenuCommandsForWindowId(aWindowId,
+ function(index, command) { command.frozen = true; });
+ } else {
+ GM_MenuCommander.removeMatchingMenuCommands(
+ null,
+ function(index, command) {
+ return (
+ // Remove the reference if either the window is closed, ...
+ GM_util.windowIsClosed(command.contentWindow)
+ // ... or the window id of the destroyed page matches.
+ || (aWindowId && command.contentWindowId == aWindowId));
+ },
+ true); // Don't forget the aForced=true passed here!
+ }
+}
+
+GM_MenuCommander.onPageShow = function(aWindowId) {
+ GM_MenuCommander.withAllMenuCommandsForWindowId(aWindowId,
+ function(index, command) { command.frozen = false; });
+}
+
GM_MenuCommander.onPopupHiding = function(aMenuPopup) {
// Asynchronously. See #1632.
GM_util.timeout(function() { GM_util.emptyEl(aMenuPopup); }, 0);
@@ -27,11 +54,7 @@ GM_MenuCommander.onPopupShowing = function(aMenuPopup) {
var windowId = GM_util.windowId(gBrowser.contentWindow);
if (windowId) {
- // Avoid polluting the global namespace with the exports of this module.
- var scope = {};
- Components.utils.import('resource://greasemonkey/menucommand.js', scope);
-
- scope.withAllMenuCommandsForWindowId(
+ GM_MenuCommander.withAllMenuCommandsForWindowId(
windowId,
function(index, command) {
if (command.frozen) return;
--
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