Permalink
Browse files

Merge remote branch 'sizzlemctwizzle/issue-1103' into issue-1103

Conflicts:
	components/greasemonkey.js
	content/browser.js
	content/config.js
	content/script.js
	content/scriptdownloader.js
	content/utils.js
2 parents ba21bff + ce66e3a commit 797d4247473d25f8b39135be3b5a2db87da74371 @arantius arantius committed Jul 18, 2011
Binary file not shown.
View
@@ -254,18 +254,6 @@ service.prototype.QueryInterface = XPCOMUtils.generateQI([
/////////////////////////////////// Privates ///////////////////////////////////
-service.prototype._getScriptsForUrl = function(
- url, wrappedContentWin, chromeWin
-) {
- if (GM_prefRoot.getValue('enableScriptRefreshing')) {
- this.config.updateModifiedScripts(wrappedContentWin, chromeWin);
- }
-
- return this.config.getMatchingScripts(function(script) {
- return GM_scriptMatchesUrlAndRuns(script, url);
- });
-};
-
service.prototype._openInTab = function(
safeContentWin, chromeWin, url, aLoadInBackground
) {
@@ -414,12 +402,21 @@ service.prototype.contentThawed = function(contentWindowId) {
function(index, command) { command.frozen = false; });
};
-service.prototype.domContentLoaded = function(wrappedContentWin, chromeWin) {
- var url = wrappedContentWin.document.location.href;
- var scripts = this._getScriptsForUrl(url, wrappedContentWin, chromeWin);
+service.prototype.runScripts = function(
+ aRunWhen, aWrappedContentWin, aChromeWin
+) {
+ var url = aWrappedContentWin.document.location.href;
+ if (!GM_getEnabled() || !GM_isGreasemonkeyable(url)) return;
+ if (GM_prefRoot.getValue('enableScriptRefreshing')) {
+ this._config.updateModifiedScripts(aWrappedContentWin, aChromeWin);
+ }
+
+ var scripts = this.config.getMatchingScripts(function(script) {
+ return GM_scriptMatchesUrlAndRuns(script, url, aRunWhen);
+ });
if (scripts.length > 0) {
- this.injectScripts(scripts, url, wrappedContentWin, chromeWin);
+ this.injectScripts(scripts, url, aWrappedContentWin, aChromeWin);
}
};
View
@@ -18,18 +18,25 @@ GM_BrowserUI.QueryInterface = function(aIID) {
};
-/**
- * Called when this file is parsed, by the last line. Set up initial objects,
- * do version checking, and set up listeners for browser xul load and location
- * changes.
- */
GM_BrowserUI.init = function() {
window.addEventListener("load", GM_BrowserUI.chromeLoad, false);
window.addEventListener("unload", GM_BrowserUI.chromeUnload, false);
window.addEventListener('DOMNodeInserted', GM_BrowserUI.nodeInserted, false);
};
+GM_BrowserUI.progressListener = {
+ onLocationChange:function(aProgress, aRequest, aURI) {
+ GM_BrowserUI.gmSvc.runScripts(
+ 'document-start', aProgress.DOMWindow, window);
+ },
+ onStateChange:function() { },
+ onProgressChange:function() { },
+ onStatusChange:function() { },
+ onSecurityChange:function() { },
+ onLinkIconAvailable:function() { }
+};
+
/**
* The browser XUL has loaded. Find the elements we need and set up our
* listeners and wrapper objects.
@@ -86,6 +93,9 @@ GM_BrowserUI.chromeLoad = function(e) {
GM_BrowserUI.gmSvc.config;
GM_BrowserUI.showToolbarButton();
+
+ gBrowser.addProgressListener(GM_BrowserUI.progressListener,
+ Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
};
GM_BrowserUI.contentLoad = function(event) {
@@ -94,9 +104,7 @@ GM_BrowserUI.contentLoad = function(event) {
var safeWin = event.target.defaultView;
var href = safeWin.location.href;
- if (GM_isGreasemonkeyable(href)) {
- GM_BrowserUI.gmSvc.domContentLoaded(safeWin, window);
- }
+ GM_BrowserUI.gmSvc.runScripts('document-end', safeWin, window);
// Show the greasemonkey install banner if we are navigating to a .user.js
// file in a top-level tab. If the file was previously cached it might have
View
@@ -237,6 +237,9 @@ Config.prototype.parse = function(source, uri, updateScript) {
}
}
break;
+ case "run-at":
+ script._runAt = value;
+ break;
}
}
}
View
@@ -23,6 +23,7 @@ function Script(configNode) {
this._resources = [];
this._unwrap = false;
this._dependFail = false;
+ this._runAt = null;
this._rawMeta = null;
this.pendingExec = [];
@@ -118,6 +119,9 @@ function Script_getRequires() { return this._requires.concat(); });
Script.prototype.__defineGetter__('resources',
function Script_getResources() { return this._resources.concat(); });
+Script.prototype.__defineGetter__('runAt',
+function Script_getRunAt() { return this._runAt; });
+
Script.prototype.__defineGetter__('unwrap',
function Script_getUnwrap() { return this._unwrap; });
@@ -238,6 +242,7 @@ Script.prototype._loadFromConfigNode = function(node) {
this._name = node.getAttribute("name");
this._namespace = node.getAttribute("namespace");
this._description = node.getAttribute("description");
+ this._runAt = node.getAttribute("runAt") || "document-end"; // legacy default
this.icon.fileURL = node.getAttribute("icon");
this._enabled = node.getAttribute("enabled") == true.toString();
};
@@ -297,6 +302,7 @@ Script.prototype.toConfigNode = function(doc) {
scriptNode.setAttribute("description", this._description);
scriptNode.setAttribute("version", this._version);
scriptNode.setAttribute("enabled", this._enabled);
+ scriptNode.setAttribute("runAt", this._runAt);
scriptNode.setAttribute("basedir", this._basedir);
scriptNode.setAttribute("modified", this._modified);
scriptNode.setAttribute("dependhash", this._dependhash);
@@ -389,6 +395,7 @@ Script.prototype.updateFromNewScript = function(newScript, safeWin, chromeWin) {
this._includes = newScript._includes;
this._excludes = newScript._excludes;
this._description = newScript._description;
+ this._runAt = newScript._runAt;
this._unwrap = newScript._unwrap;
this._version = newScript._version;
View
@@ -393,10 +393,11 @@ function GM_installUri(uri, contentWin) {
return false;
}
-function GM_scriptMatchesUrlAndRuns(script, url) {
+function GM_scriptMatchesUrlAndRuns(script, url, when) {
return !script.pendingExec.length
&& script.enabled
&& !script.needsUninstall
+ && (script.runAt == when || 'any' == when)
&& script.matchesURL(url);
}
@@ -1,11 +1,8 @@
#include "nsISupports.idl"
-#include "gmIMenuCommand.idl"
-#include "gmIBrowserWindow.idl"
[scriptable, uuid(c5826e20-1cc7-11da-8cd6-0800200c9a66)]
interface gmIGreasemonkeyService : nsISupports
{
- void registerBrowser(in gmIBrowserWindow window);
- void unregisterBrowser(in gmIBrowserWindow window);
- void domContentLoaded(in nsISupports contentWin, in nsISupports chromeWin);
+ void runScripts(in string aRunWhen,
+ in nsISupports aWrappedContentWin, in nsISupports aChromeWin);
};
View
@@ -42,7 +42,7 @@
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
- <em:minVersion>3.0</em:minVersion>
+ <em:minVersion>3.5</em:minVersion>
<em:maxVersion>7.*</em:maxVersion>
</Description>
</em:targetApplication>

0 comments on commit 797d424

Please sign in to comment.