[Pkg-mozext-commits] [greasemonkey] 03/20: Rewrite script install manager.
David Prévot
taffit at moszumanska.debian.org
Fri Mar 25 21:37:19 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository greasemonkey.
commit fe737c78f61a83273eb2031a143c541b409d02eb
Author: Anthony Lieuallen <arantius at gmail.com>
Date: Fri Feb 19 12:47:05 2016 -0500
Rewrite script install manager.
Switch from nsIContentPolicy to http-on-modify-request observer. This lets us properly detect a POST, for a proper fix to #1875, so we can remove the suboptimal workaround solution to that.
Fixes #2280
---
components/greasemonkey.js | 37 +++++++------
content/addons4-overlay.js | 2 +-
content/framescript.js | 26 ++--------
modules/installPolicy.js | 86 ++++++++-----------------------
modules/processScript.js | 4 ++
modules/remoteScript.js | 27 ++++++----
modules/requestObserver.js | 103 ++++++++++++++++++++++++++++++++++---
modules/util.js | 1 -
modules/util/findMessageManager.js | 28 ----------
modules/util/showInstallDialog.js | 44 ++++++++++------
10 files changed, 188 insertions(+), 170 deletions(-)
diff --git a/components/greasemonkey.js b/components/greasemonkey.js
index df7f64f..a01c5d3 100644
--- a/components/greasemonkey.js
+++ b/components/greasemonkey.js
@@ -3,34 +3,34 @@
var DESCRIPTION = "GM_GreasemonkeyService";
var CONTRACTID = "@greasemonkey.mozdev.org/greasemonkey-service;1";
var CLASSID = Components.ID("{77bf3650-1cd6-11da-8cd6-0800200c9a66}");
+var GM_GUID = "{e4a8a97b-f2ed-450b-b12d-ee082ba24781}";
+
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/AddonManager.jsm");
+
Cu.import("chrome://greasemonkey-modules/content/ipcscript.js");
Cu.import("chrome://greasemonkey-modules/content/menucommand.js");
Cu.import("chrome://greasemonkey-modules/content/prefmanager.js");
Cu.import("chrome://greasemonkey-modules/content/storageBack.js");
Cu.import("chrome://greasemonkey-modules/content/sync.js");
Cu.import("chrome://greasemonkey-modules/content/util.js");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
-var gStartupHasRun = false;
var gFileProtocolHandler = Components
.classes["@mozilla.org/network/protocol;1?name=file"]
.getService(Ci.nsIFileProtocolHandler);
+var gGreasemonkeyVersion = 'unknown';
+var gStartupHasRun = false;
var gTmpDir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
-var GM_GUID = "{e4a8a97b-f2ed-450b-b12d-ee082ba24781}";
-var gGreasemonkeyVersion = 'unknown';
-Cu.import("resource://gre/modules/AddonManager.jsm");
-
/////////////////////// Component-global Helper Functions //////////////////////
function shutdown(aService) {
@@ -50,8 +50,6 @@ function startup(aService) {
// Most incoming messages go to the "global" message manager.
var globalMessageManager = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
- globalMessageManager.addMessageListener(
- 'greasemonkey:script-install', aService.scriptInstall.bind(aService));
var scriptValHandler = aService.handleScriptValMsg.bind(aService);
globalMessageManager.addMessageListener(
@@ -63,20 +61,22 @@ function startup(aService) {
globalMessageManager.addMessageListener(
'greasemonkey:scriptVal-set', scriptValHandler);
+ // Others go to the "parent" message manager.
var parentMessageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
parentMessageManager.addMessageListener(
'greasemonkey:scripts-for-uuid',
aService.getScriptsForUuid.bind(aService));
- parentMessageManager.addMessageListener("greasemonkey:scripts-update", function(message) {
- return aService.scriptUpdateData();
- });
- var mm = Services.ppmm ? Services.ppmm : globalMessageManager;
- mm.addMessageListener(
+ parentMessageManager.addMessageListener(
+ 'greasemonkey:scripts-update', function(message) {
+ return aService.scriptUpdateData();
+ });
+ parentMessageManager.addMessageListener(
+ 'greasemonkey:script-install', aService.scriptInstall.bind(aService));
+ parentMessageManager.addMessageListener(
'greasemonkey:url-is-temp-file', aService.urlIsTempFile.bind(aService));
- // Yes, we have to load the frame script once here in the parent scope.
- // Why? Who knows!?
+ // Yes, we have to load the frame script once here in the parent scope. Why!?
globalMessageManager.loadFrameScript(
'chrome://greasemonkey/content/framescript.js', true);
@@ -231,8 +231,7 @@ service.prototype.handleScriptValMsg = function(aMessage) {
};
service.prototype.scriptInstall = function(aMessage) {
- GM_util.showInstallDialog(
- aMessage.data.url, aMessage.target, aMessage.data.referer);
+ GM_util.showInstallDialog(aMessage.data.url);
};
service.prototype.urlIsTempFile = function(aMessage) {
diff --git a/content/addons4-overlay.js b/content/addons4-overlay.js
index ed5032e..e3a595a 100644
--- a/content/addons4-overlay.js
+++ b/content/addons4-overlay.js
@@ -45,7 +45,7 @@ gDragDrop.onDrop = function GM_onDrop(aEvent) {
var droppedNonUserScript = false;
for (var i = urls.length - 1, url = null; url = urls[i]; i--) {
if (url.match(/\.user\.js$/)) {
- GM_util.showInstallDialog(url, GM_util.getBrowserWindow().gBrowser);
+ GM_util.showInstallDialog(url);
} else {
droppedNonUserScript = true;
}
diff --git a/content/framescript.js b/content/framescript.js
index 9ee36e0..3d459e6 100644
--- a/content/framescript.js
+++ b/content/framescript.js
@@ -7,19 +7,17 @@ var Cu = Components.utils;
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
+Cu.import('chrome://greasemonkey-modules/content/documentObserver.js');
Cu.import('chrome://greasemonkey-modules/content/GM_setClipboard.js');
-Cu.import('chrome://greasemonkey-modules/content/installPolicy.js');
Cu.import('chrome://greasemonkey-modules/content/ipcscript.js');
Cu.import('chrome://greasemonkey-modules/content/menucommand.js');
Cu.import('chrome://greasemonkey-modules/content/miscapis.js');
Cu.import('chrome://greasemonkey-modules/content/sandbox.js');
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. Don't import all the vars into the local scope.
-Cu.import('chrome://greasemonkey-modules/content/processScript.js', {}
- ).addFrame(this);
+Cu.import('chrome://greasemonkey-modules/content/processScript.js', {})
+ .addFrame(this);
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
@@ -120,21 +118,6 @@ function injectScripts(aScripts, aContentWin) {
}
-function loadFailedScript(aMessage) {
- var url = aMessage.data.url;
- var loadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
- var referer = aMessage.data.referer
- && GM_util.uriFromUrl(aMessage.data.referer);
- var postData = null;
- var headers = null;
-
- var webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
-
- passNextScript();
- webNav.loadURI(url, loadFlags, referer, postData, headers);
-}
-
-
function contextMenuStart(aMessage) {
var culprit = aMessage.objects.culprit;
@@ -204,7 +187,6 @@ addEventListener('DOMWindowCreated', windowCreated);
if (content) windowCreated();
addMessageListener('greasemonkey:inject-delayed-script', injectDelayedScript);
-addMessageListener('greasemonkey:load-failed-script', loadFailedScript);
addMessageListener('greasemonkey:menu-command-list', function(aMessage) {
MenuCommandListRequest(content, aMessage);
});
@@ -214,6 +196,4 @@ addMessageListener('greasemonkey:menu-command-run', function(aMessage) {
addMessageListener("greasemonkey:context-menu-start", contextMenuStart);
addMessageListener("greasemonkey:newscript-load-start", newScriptLoadStart);
-
-initInstallPolicy();
initScriptProtocol();
diff --git a/modules/installPolicy.js b/modules/installPolicy.js
index 9110fea..c8b7952 100644
--- a/modules/installPolicy.js
+++ b/modules/installPolicy.js
@@ -1,7 +1,8 @@
-// This module is responsible for observing HTTP traffic, detecting when a user
-// script is loaded (e.g. a link to one is clicked), and launching the install
-// dialog instead.
-var EXPORTED_SYMBOLS = ['passNextScript', 'initInstallPolicy'];
+// This module is responsible for detecting user scripts that are loaded by
+// some means OTHER than HTTP (which the http-on-modify-request observer
+// handles), i.e. local files.
+
+var EXPORTED_SYMBOLS = [];
var Cc = Components.classes;
var Ci = Components.interfaces;
@@ -14,21 +15,11 @@ Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('chrome://greasemonkey-modules/content/util.js');
var gHaveDoneInit = false;
-var gBlockNextScript = false;
-var gPassNextScript = false;
var gScriptEndingRegexp = new RegExp('\\.user\\.js$');
-////////////////////////////////////////////////////////////////////////////////
-
-function passNextScript() {
- gPassNextScript = true;
-}
-
-function initInstallPolicy() {
- if (gHaveDoneInit) return;
- gHaveDoneInit = true;
- InstallPolicy.init();
-}
+XPCOMUtils.defineLazyServiceGetter(
+ this, 'cpmm',
+ '@mozilla.org/childprocessmessagemanager;1', 'nsIMessageSender');
////////////////////////////////////////////////////////////////////////////////
@@ -69,70 +60,31 @@ var InstallPolicy = {
var ACCEPT = Ci.nsIContentPolicy.ACCEPT;
var REJECT = Ci.nsIContentPolicy.REJECT_REQUEST;
- // Don't interrupt the "view-source:" scheme (which is triggered if the link
- // in the error console is clicked), nor the "greasemonkey-script:" scheme.
- // Never break chrome.
- if ("view-source" == aContentURI.scheme
- || "chrome" == aContentURI.scheme
- || "greasemonkey-script" == aContentURI.scheme) {
+ // Ignore everything that isn't a file:// .
+ if ('file' != aContentURI.scheme) {
return ACCEPT;
}
// Ignore everything that isn't a top-level document navigation.
if (aContentType != Ci.nsIContentPolicy.TYPE_DOCUMENT) {
return ACCEPT;
}
- // Don't intercept anything when GM is not enabled.
+ // Ignore everything when GM is not enabled.
if (!GM_util.getEnabled()) {
return ACCEPT;
}
-
- // Do not install scripts when the origin URL "is a script". See #1875
- if (aOriginURI && aOriginURI.spec.match(gScriptEndingRegexp)) {
- return ACCEPT;
- }
-
+ // Ignore everything that isn't a user script.
if (!aContentURI.spec.match(gScriptEndingRegexp)) {
return ACCEPT;
}
-
- if (gPassNextScript) {
- // E.g. Detected HTML content so forced re-navigation.
- gPassNextScript = false;
- return ACCEPT;
- }
-
- // TODO: Remove this when e10s is always enabled.
- // See #2292
- // Recent Firefoxen with e10s on, when opening a file:/// .user.js will
- // trigger the install policy twice. Block the second one.
- if (gBlockNextScript) {
- gBlockNextScript = false;
- return REJECT;
- }
- if (!Services.appinfo.browserTabsRemoteAutostart
- && aContentURI.scheme == 'file') {
- gBlockNextScript = true;
- }
-
// Ignore temporary files, e.g. "Show script source".
- var messageManager = GM_util.findMessageManager(aContext);
- var cpmm = Services.cpmm ? Services.cpmm : messageManager;
- var tmpResult = cpmm && cpmm.sendSyncMessage(
+ var tmpResult = cpmm.sendSyncMessage(
'greasemonkey:url-is-temp-file', {'url': aContentURI.spec});
if (tmpResult.length && tmpResult[0]) {
return ACCEPT;
}
- if (!messageManager) {
- dump('ERROR ignoring script ' + aContentURI.spec + ' because no content'
- + ' message manager could be located from ' + aContext + '\n');
- return ACCEPT;
- }
-
- messageManager.sendAsyncMessage('greasemonkey:script-install', {
- 'referer': aOriginURI ? aOriginURI.spec : null,
- 'url': aContentURI.spec,
- });
+ cpmm.sendAsyncMessage(
+ 'greasemonkey:script-install', {'url': aContentURI.spec});
return REJECT;
},
@@ -149,5 +101,11 @@ var InstallPolicy = {
}
return this.QueryInterface(iid);
},
-
};
+
+////////////////////////////////////////////////////////////////////////////////
+
+if (!gHaveDoneInit) {
+ gHaveDoneInit = true;
+ InstallPolicy.init();
+}
diff --git a/modules/processScript.js b/modules/processScript.js
index 7b73950..168bbbd 100644
--- a/modules/processScript.js
+++ b/modules/processScript.js
@@ -7,6 +7,10 @@
var EXPORTED_SYMBOLS = ['addFrame'];
+// Each (child) process needs to handle navigation to `.user.js` via file://.
+Components.utils.import("chrome://greasemonkey-modules/content/installPolicy.js");
+
+// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
function addFrame(frameMM) {
frameMM.addMessageListener("greasemonkey:frame-urls", urlTree);
diff --git a/modules/remoteScript.js b/modules/remoteScript.js
index 27f5844..0d97297 100644
--- a/modules/remoteScript.js
+++ b/modules/remoteScript.js
@@ -2,15 +2,17 @@ var EXPORTED_SYMBOLS = ['cleanFilename', 'RemoteScript'];
var Cc = Components.classes;
var Ci = Components.interfaces;
+var Cu = Components.utils;
-Components.utils.import("chrome://greasemonkey-modules/content/GM_notification.js");
-Components.utils.import('chrome://greasemonkey-modules/content/addons4.js');
-Components.utils.import('chrome://greasemonkey-modules/content/script.js');
-Components.utils.import('chrome://greasemonkey-modules/content/scriptIcon.js');
-Components.utils.import('chrome://greasemonkey-modules/content/util.js');
+Cu.import("chrome://greasemonkey-modules/content/GM_notification.js");
+Cu.import('chrome://greasemonkey-modules/content/addons4.js');
+Cu.import('chrome://greasemonkey-modules/content/script.js');
+Cu.import('chrome://greasemonkey-modules/content/scriptIcon.js');
+Cu.import('chrome://greasemonkey-modules/content/util.js');
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-Components.utils.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
var GM_config = GM_util.getService().config;
var ioService = Cc['@mozilla.org/network/io-service;1']
@@ -412,7 +414,7 @@ RemoteScript.prototype.parseScript = function(aSource, aFatal) {
if (this.script) return true;
var scope = {};
- Components.utils.import('chrome://greasemonkey-modules/content/parseScript.js', scope);
+ Cu.import('chrome://greasemonkey-modules/content/parseScript.js', scope);
var script = scope.parse(aSource, this._uri, aFatal);
if (!script || script.parseErrors.length) {
if (aFatal) {
@@ -590,8 +592,13 @@ RemoteScript.prototype._downloadFile = function(
}
}
- var channel = GM_util.channelFromUri(aUri);
- channel.loadFlags |= channel.LOAD_BYPASS_CACHE;
+ // Construct a channel with a policy type that the HTTP observer is
+ // designed to ignore, so it won't intercept this network call.
+ var channel = NetUtil.newChannel({
+ 'uri': aUri,
+ 'contentPolicyType': Ci.nsIContentPolicy.TYPE_OBJECT_SUBREQUEST,
+ 'loadUsingSystemPrincipal': true,
+ });
this._channels.push(channel);
var dsl = new DownloadListener(
0 == this._progressIndex, // aTryToParse
diff --git a/modules/requestObserver.js b/modules/requestObserver.js
index 2616cf0..2a127b0 100644
--- a/modules/requestObserver.js
+++ b/modules/requestObserver.js
@@ -2,12 +2,23 @@
var EXPORTED_SYMBOLS = [];
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("chrome://greasemonkey-modules/content/util.js");
-Components.utils.import("chrome://greasemonkey-modules/content/prefmanager.js");
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+var Cr = Components.results;
-var types = Components.interfaces.nsIContentPolicy;
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("chrome://greasemonkey-modules/content/util.js");
+Cu.import("chrome://greasemonkey-modules/content/prefmanager.js");
+
+var gDisallowedSchemes = {
+ 'chrome': 1, 'greasemonkey-script': 1, 'view-source': 1};
+var gScriptEndingRegexp = new RegExp('\\.user\\.js$');
+var gContentTypes = Ci.nsIContentPolicy;
+
+// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
function checkScriptRefresh(channel) {
// .loadInfo is part of nsiChannel -> implicit QI needed
@@ -19,8 +30,12 @@ function checkScriptRefresh(channel) {
? channel.loadInfo.externalContentPolicyType
: channel.loadInfo.contentPolicyType;
- // only check for updated scripts when tabs/iframes are loaded
- if (type != types.TYPE_DOCUMENT && type != types.TYPE_SUBDOCUMENT) return;
+ // only check for updated scripts when tabs/iframes are loaded
+ if (type != gContentTypes.TYPE_DOCUMENT
+ && type != gContentTypes.TYPE_SUBDOCUMENT
+ ) {
+ return;
+ }
// forward compatibility: https://bugzilla.mozilla.org/show_bug.cgi?id=1124477
var browser = channel.loadInfo.topFrameElement;
@@ -38,8 +53,80 @@ function checkScriptRefresh(channel) {
GM_util.getService().scriptRefresh(channel.URI.spec, windowId, browser);
}
+// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
+
+function installObserver(aSubject, aTopic, aData) {
+ // When observing a new request, inspect it to determine if it should be
+ // a user script install. If so, abort and restart as an install rather
+ // than a navigation.
+ if (!GM_util.getEnabled()) {
+ return;
+ }
+
+ var channel = aSubject.QueryInterface(Ci.nsIChannel);
+ if (!channel || !channel.loadInfo) {
+ return;
+ }
+
+ // See http://bugzil.la/1182571
+ var type = channel.loadInfo.externalContentPolicyType
+ || channel.loadInfo.contentPolicyType;
+ if (type != gContentTypes.TYPE_DOCUMENT) {
+ return;
+ }
+
+ if (channel.URI.scheme in gDisallowedSchemes) {
+ return;
+ }
+
+ try {
+ var httpChannel = channel.QueryInterface(Ci.nsIHttpChannel);
+ if ('POST' == httpChannel.requestMethod) {
+ return;
+ }
+ } catch (e) {
+ // Ignore completely, e.g. file:/// URIs.
+ }
+
+ if (!channel.URI.spec.match(gScriptEndingRegexp)) {
+ return;
+ }
+
+ // We've done an early return above for all non-user-script navigations. If
+ // execution has proceeded to this point, we want to cancel the existing
+ // request (i.e. navigation) and instead start a script installation for
+ // this same URI.
+ try {
+ var request = channel.QueryInterface(Ci.nsIRequest);
+ request.suspend();
+
+ var browser = channel
+ .QueryInterface(Ci.nsIHttpChannel)
+ .notificationCallbacks
+ .getInterface(Ci.nsILoadContext)
+ .topFrameElement;
+
+ GM_util.showInstallDialog(channel.URI.spec, browser, request);
+ } catch (e) {
+ dump('Greasemonkey could not do script install!\n'+e+'\n');
+ // Ignore.
+ return;
+ }
+}
+
+// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
+
Services.obs.addObserver({
- observe: function(subject, topic, data) {
- checkScriptRefresh(subject);
+ observe: function(aSubject, aTopic, aData) {
+ try {
+ installObserver(aSubject, aTopic, aData);
+ } catch (e) {
+ dump('Greasemonkey install observer failed:\n' + e + '\n');
+ }
+ try {
+ checkScriptRefresh(aSubject);
+ } catch (e) {
+ dump('Greasemonkey refresh observer failed:\n' + e + '\n');
+ }
}
}, "http-on-modify-request", false);
diff --git a/modules/util.js b/modules/util.js
index 6299951..b36d365 100644
--- a/modules/util.js
+++ b/modules/util.js
@@ -29,7 +29,6 @@ XPCOMUtils.defineLazyModuleGetter(GM_util, 'compareFirefoxVersion', 'chrome://gr
XPCOMUtils.defineLazyModuleGetter(GM_util, 'emptyEl', 'chrome://greasemonkey-modules/content/util/emptyEl.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'enqueueRemoveFile', 'chrome://greasemonkey-modules/content/util/enqueueRemoveFile.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'fileXhr', 'chrome://greasemonkey-modules/content/util/fileXhr.js');
-XPCOMUtils.defineLazyModuleGetter(GM_util, 'findMessageManager', 'chrome://greasemonkey-modules/content/util/findMessageManager.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'getBestLocaleMatch', 'chrome://greasemonkey-modules/content/util/getBestLocaleMatch.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'getBinaryContents', 'chrome://greasemonkey-modules/content/util/getBinaryContents.js');
XPCOMUtils.defineLazyModuleGetter(GM_util, 'getBrowserWindow', 'chrome://greasemonkey-modules/content/util/getBrowserWindow.js');
diff --git a/modules/util/findMessageManager.js b/modules/util/findMessageManager.js
deleted file mode 100644
index b6dfba5..0000000
--- a/modules/util/findMessageManager.js
+++ /dev/null
@@ -1,28 +0,0 @@
-var EXPORTED_SYMBOLS = ['findMessageManager'];
-
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cu = Components.utils;
-
-function findMessageManager(aContext) {
- // With e10s off, context is a <browser> with a direct reference to
- // the docshell loaded therein.
- var docShell = aContext && aContext.docShell;
-
- if (!docShell) {
- // But with e10s on, context is a content window and we have to work hard
- // to find the docshell, from which we can find the message manager.
- docShell = aContext
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem;
- }
-
- try {
- return docShell
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIContentFrameMessageManager);
- } catch (e) {
- return null;
- }
-};
diff --git a/modules/util/showInstallDialog.js b/modules/util/showInstallDialog.js
index bc19549..d62c06e 100644
--- a/modules/util/showInstallDialog.js
+++ b/modules/util/showInstallDialog.js
@@ -1,13 +1,17 @@
var EXPORTED_SYMBOLS = ['showInstallDialog'];
-Components.utils.import('chrome://greasemonkey-modules/content/util.js');
-Components.utils.import('chrome://greasemonkey-modules/content/remoteScript.js');
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
-var gWindowWatcher = Components
- .classes["@mozilla.org/embedcomp/window-watcher;1"]
- .getService(Components.interfaces.nsIWindowWatcher);
+Cu.import('chrome://greasemonkey-modules/content/util.js');
+Cu.import('chrome://greasemonkey-modules/content/remoteScript.js');
-function showInstallDialog(aUrlOrRemoteScript, aBrowser, aRefererUrl) {
+var gWindowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"]
+ .getService(Ci.nsIWindowWatcher);
+
+
+function showInstallDialog(aUrlOrRemoteScript, aBrowser, aRequest) {
var rs = null;
if ('string' == typeof aUrlOrRemoteScript) {
rs = new RemoteScript(aUrlOrRemoteScript);
@@ -15,18 +19,19 @@ function showInstallDialog(aUrlOrRemoteScript, aBrowser, aRefererUrl) {
rs = aUrlOrRemoteScript;
}
+ var browser = aBrowser || GM_util.getBrowserWindow().gBrowser;
var params = null;
function openDialog(aScript) {
- params = [rs, aBrowser, aScript];
+ params = [rs, browser, aScript];
params.wrappedJSObject = params;
// Don't set "modal" param, or this blocks. Even though we'd prefer the
// sort of behavior that gives us.
gWindowWatcher.openWindow(
- /* aParent */ null,
- 'chrome://greasemonkey/content/install.xul',
- /* aName */ null,
- 'chrome,centerscreen,dialog,titlebar,resizable',
- params);
+ /* aParent */ null,
+ 'chrome://greasemonkey/content/install.xul',
+ /* aName */ null,
+ 'chrome,centerscreen,dialog,titlebar,resizable',
+ params);
}
if (rs.script) {
@@ -38,10 +43,17 @@ function showInstallDialog(aUrlOrRemoteScript, aBrowser, aRefererUrl) {
}
rs.download(function(aSuccess, aType) {
- if (!aSuccess && 'script' == aType) {
- aBrowser.messageManager.sendAsyncMessage(
- 'greasemonkey:load-failed-script',
- {'referer': aRefererUrl, 'url': rs.url});
+ if (aRequest && 'script' == aType) {
+ if (aSuccess) {
+ aRequest.cancel(Components.results.NS_BINDING_ABORTED);
+ var browser = aRequest
+ .QueryInterface(Ci.nsIHttpChannel)
+ .notificationCallbacks.getInterface(Ci.nsILoadContext)
+ .topFrameElement;
+ browser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
+ } else {
+ aRequest.resume();
+ }
}
});
}
--
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