[Pkg-mozext-commits] [greasemonkey] 15/55: Address "unsafe CPOW usage" warnings - the new script, the context menu
David Prévot
taffit at moszumanska.debian.org
Thu Oct 29 15:38:03 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 d6b0089cc072ea85f320a8d1634d061bc9c32c90
Author: janekptacijarabaci <janekptacijarabaci at seznam.cz>
Date: Sat Sep 19 18:53:29 2015 +0200
Address "unsafe CPOW usage" warnings - the new script, the context menu
---
content/browser.js | 86 ++++++++++++++++++++++++++++----------------------
content/framescript.js | 24 ++++++++++++++
content/newscript.js | 16 ++++++++--
3 files changed, 86 insertions(+), 40 deletions(-)
diff --git a/content/browser.js b/content/browser.js
index 13f5385..d0a1c21 100644
--- a/content/browser.js
+++ b/content/browser.js
@@ -111,38 +111,62 @@ GM_BrowserUI.chromeUnload = function() {
* to show our context items.
*/
GM_BrowserUI.contextMenuShowing = function() {
- var contextItem = document.getElementById("greasemonkey-view-userscript");
- var contextSep = document.getElementById("greasemonkey-install-sep");
-
- var culprit = gContextMenu.target || document.popupNode;
-
- while (culprit && culprit.tagName && culprit.tagName.toLowerCase() != "a") {
- culprit = culprit.parentNode;
- }
-
- contextItem.hidden =
- contextSep.hidden =
- !GM_BrowserUI.getUserScriptLinkUnderPointer();
+ GM_BrowserUI.getUserScriptLinkUnderPointer(1)
};
-GM_BrowserUI.getUserScriptLinkUnderPointer = function() {
+GM_BrowserUI.getUserScriptLinkUnderPointer = function(what) {
var culprit = gContextMenu.target || document.popupNode;
- while (culprit && culprit.tagName && culprit.tagName.toLowerCase() != "a") {
- culprit = culprit.parentNode;
- }
+ var mm = gBrowser.selectedBrowser.messageManager;
- if (!culprit || !culprit.href ||
- !culprit.href.match(/\.user\.js(\?|$)/i)) {
- return null;
- }
+ var callback = null;
+ callback = function (aMessage) {
+ mm.removeMessageListener("greasemonkey:context-menu-end", callback);
+
+ var href = aMessage.data.href;
+
+ var result = null;
+ if (culprit && href &&
+ href.match(/\.user\.js(\?|$)/i)) {
+ var ioSvc = Components.classes["@mozilla.org/network/io-service;1"]
+ .getService(Components.interfaces.nsIIOService);
+ var uri = ioSvc.newURI(href, null, null);
+ result = uri;
+ }
+
+ switch (what) {
+ case 1:
+ var contextItem = document
+ .getElementById("greasemonkey-view-userscript");
+ var contextSep = document.getElementById("greasemonkey-install-sep");
+
+ contextItem.hidden = contextSep.hidden = !result;
+ break;
+ case 2:
+ if (result) {
+ var scope = {};
+ Components.utils.import(
+ "chrome://greasemonkey-modules/content/remoteScript.js", scope);
+ var rs = new scope.RemoteScript(result.spec);
+ rs.downloadScript(function (aSuccess) {
+ if (aSuccess) {
+ rs.showSource(gBrowser);
+ } else {
+ alert(rs.errorMessage);
+ }
+ });
+ }
+ break;
+ }
+ };
- var ioSvc = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var uri = ioSvc.newURI(culprit.href, null, null);
+ mm.addMessageListener("greasemonkey:context-menu-end", callback);
- return uri;
+ gBrowser.selectedBrowser.messageManager
+ .sendAsyncMessage("greasemonkey:context-menu-start", {}, {
+ "culprit": culprit
+ });
};
GM_BrowserUI.refreshStatus = function() {
@@ -164,19 +188,7 @@ GM_BrowserUI.startInstallScript = function(aUri) {
};
GM_BrowserUI.viewContextItemClicked = function() {
- var uri = GM_BrowserUI.getUserScriptLinkUnderPointer();
- if (!uri) return;
-
- var scope = {};
- Components.utils.import('chrome://greasemonkey-modules/content/remoteScript.js', scope);
- var rs = new scope.RemoteScript(uri.spec);
- rs.downloadScript(function(aSuccess) {
- if (aSuccess) {
- rs.showSource(gBrowser);
- } else {
- alert(rs.errorMessage);
- }
- });
+ GM_BrowserUI.getUserScriptLinkUnderPointer(2);
};
GM_BrowserUI.showToolbarButton = function() {
diff --git a/content/framescript.js b/content/framescript.js
index c3b7e00..a05ac0a 100644
--- a/content/framescript.js
+++ b/content/framescript.js
@@ -125,6 +125,28 @@ function loadFailedScript(aMessage) {
}
+function contextMenuStart(aMessage) {
+ var culprit = aMessage.objects.culprit;
+
+ while (culprit && culprit.tagName && culprit.tagName.toLowerCase() != "a") {
+ culprit = culprit.parentNode;
+ }
+
+ var href = culprit.href;
+
+ aMessage.target.sendAsyncMessage("greasemonkey:context-menu-end", {
+ "href": href
+ });
+}
+
+
+function newScriptLoadStart(aMessage) {
+ aMessage.target.sendAsyncMessage("greasemonkey:newscript-load-end", {
+ "href": content.location.href
+ });
+}
+
+
function runScripts(aRunWhen, aContentWin) {
var url = urlForWin(aContentWin);
if (!GM_util.isGreasemonkeyable(url)) return;
@@ -190,6 +212,8 @@ addMessageListener('greasemonkey:menu-command-list', function(aMessage) {
addMessageListener('greasemonkey:menu-command-run', function(aMessage) {
MenuCommandRun(content, aMessage);
});
+addMessageListener("greasemonkey:context-menu-start", contextMenuStart);
+addMessageListener("greasemonkey:newscript-load-start", newScriptLoadStart);
initInstallPolicy();
diff --git a/content/newscript.js b/content/newscript.js
index d396ad6..7f56d6e 100644
--- a/content/newscript.js
+++ b/content/newscript.js
@@ -21,10 +21,20 @@ window.addEventListener("load", function window_load() {
GM_prefRoot.getValue("newscript_namespace", "");
// default the includes with the current page's url
- var content = window.opener.document.getElementById("content");
+ var content = window.opener.gBrowser;
if (content) {
- document.getElementById("include").value =
- content.selectedBrowser.contentWindow.location.href;
+ var callback = null;
+ callback = function (aMessage) {
+ window.opener.messageManager
+ .removeMessageListener("greasemonkey:newscript-load-end", callback);
+ document.getElementById("include").value = aMessage.data.href;
+ };
+
+ window.opener.messageManager
+ .addMessageListener("greasemonkey:newscript-load-end", callback);
+
+ content.selectedBrowser.messageManager
+ .sendAsyncMessage("greasemonkey:newscript-load-start", {});
}
gClipText = getClipText();
--
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