Skip to content

Commit

Permalink
Merge remote branch 'sizzlemctwizzle/issue-1103' into issue-1103
Browse files Browse the repository at this point in the history
Conflicts:
	components/greasemonkey.js
	content/browser.js
	content/config.js
	content/script.js
	content/scriptdownloader.js
	content/utils.js
  • Loading branch information
arantius committed Jul 18, 2011
2 parents ba21bff + ce66e3a commit 797d424
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 31 deletions.
Binary file modified components/gmIGreasemonkeyService.xpt
Binary file not shown.
29 changes: 13 additions & 16 deletions components/greasemonkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down Expand Up @@ -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);
}
};

Expand Down
24 changes: 16 additions & 8 deletions content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions content/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Config.prototype.parse = function(source, uri, updateScript) {
}
}
break;
case "run-at":
script._runAt = value;
break;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions content/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Script(configNode) {
this._resources = [];
this._unwrap = false;
this._dependFail = false;
this._runAt = null;
this._rawMeta = null;
this.pendingExec = [];

Expand Down Expand Up @@ -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; });

Expand Down Expand Up @@ -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();
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion content/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 2 additions & 5 deletions idl/gmIGreasemonkeyService.idl
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 797d424

Please sign in to comment.