Skip to content

Commit

Permalink
Merge remote branch 'upstream/master' into late-injection. closes gre…
Browse files Browse the repository at this point in the history
…asemonkey#1165

Conflicts:
	content/script.js
	content/scriptdownloader.js
  • Loading branch information
sizzlemctwizzle committed Jul 17, 2010
2 parents 02a9fdc + 5f64905 commit 974f2e8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 115 deletions.
129 changes: 41 additions & 88 deletions components/greasemonkey.js
@@ -1,22 +1,25 @@
const CLASSNAME = "GM_GreasemonkeyService";

// XPCOM info
const DESCRIPTION = "GM_GreasemonkeyService";
const CONTRACTID = "@greasemonkey.mozdev.org/greasemonkey-service;1";
const CID = Components.ID("{77bf3650-1cd6-11da-8cd6-0800200c9a66}");
const CLASSID = Components.ID("{77bf3650-1cd6-11da-8cd6-0800200c9a66}");

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

const appSvc = Cc["@mozilla.org/appshell/appShellService;1"]
.getService(Ci.nsIAppShellService);

const gmSvcFilename = Components.stack.filename;

const maxJSVersion = (function getMaxJSVersion() {
var appInfo = Components
.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo);
var versionChecker = Components
.classes["@mozilla.org/xpcom/version-comparator;1"]
.getService(Components.interfaces.nsIVersionComparator);
var appInfo = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULAppInfo);
var versionChecker = Cc["@mozilla.org/xpcom/version-comparator;1"]
.getService(Ci.nsIVersionComparator);

// Firefox 3.5 and higher supports 1.8.
if (versionChecker.compare(appInfo.version, "3.5") >= 0) {
Expand Down Expand Up @@ -59,7 +62,34 @@ function GM_apiLeakCheck(apiName) {
return true;
}

var greasemonkeyService = {

function GM_GreasemonkeyService() {
this.wrappedJSObject = this;
}

GM_GreasemonkeyService.prototype = {
classDescription: DESCRIPTION,
classID: CLASSID,
contractID: CONTRACTID,
_xpcom_categories: [{category: "app-startup",
entry: DESCRIPTION,
value: CONTRACTID,
service: true},
{category: "content-policy",
entry: CONTRACTID,
value: CONTRACTID,
service: true}],

// nsISupports
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsISupports,
Ci.nsISupportsWeakReference,
Ci.gmIGreasemonkeyService,
Ci.nsIWindowMediatorListener,
Ci.nsIContentPolicy
]),

_config: null,
get config() {
if (!this._config) {
Expand All @@ -74,22 +104,6 @@ var greasemonkeyService = {
},
browserWindows: [],


// nsISupports
QueryInterface: function(aIID) {
if (!aIID.equals(Ci.nsIObserver) &&
!aIID.equals(Ci.nsISupports) &&
!aIID.equals(Ci.nsISupportsWeakReference) &&
!aIID.equals(Ci.gmIGreasemonkeyService) &&
!aIID.equals(Ci.nsIWindowMediatorListener) &&
!aIID.equals(Ci.nsIContentPolicy)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}

return this;
},


// nsIObserver
observe: function(aSubject, aTopic, aData) {
if (aTopic == "app-startup") {
Expand Down Expand Up @@ -474,68 +488,7 @@ var greasemonkeyService = {
}
};

greasemonkeyService.wrappedJSObject = greasemonkeyService;



/**
* XPCOM Registration goop
*/
var Module = new Object();

Module.registerSelf = function(compMgr, fileSpec, location, type) {
compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
compMgr.registerFactoryLocation(CID,
CLASSNAME,
CONTRACTID,
fileSpec,
location,
type);

var catMgr = Cc["@mozilla.org/categorymanager;1"]
.getService(Ci.nsICategoryManager);

catMgr.addCategoryEntry("app-startup",
CLASSNAME,
CONTRACTID,
true,
true);

catMgr.addCategoryEntry("content-policy",
CONTRACTID,
CONTRACTID,
true,
true);
};

Module.getClassObject = function(compMgr, cid, iid) {
if (!cid.equals(CID)) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}

if (!iid.equals(Ci.nsIFactory)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}

return Factory;
};

Module.canUnload = function(compMgr) {
return true;
};


var Factory = new Object();

Factory.createInstance = function(outer, iid) {
if (outer != null) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}

return greasemonkeyService;
};


// XPCOM module registration.
function NSGetModule(compMgr, fileSpec) {
return Module;
return XPCOMUtils.generateModule([GM_GreasemonkeyService]);
}
2 changes: 1 addition & 1 deletion content/addons.js
Expand Up @@ -272,7 +272,7 @@ var greasemonkeyAddons = {
GM_openInEditor(script);
break;
case 'cmd_userscript_show':
GM_openFolder(script._file);
GM_openFolder(script.file);
break;
case 'cmd_userscript_enable':
script.enabled = true;
Expand Down
8 changes: 2 additions & 6 deletions content/config.js
Expand Up @@ -46,12 +46,8 @@ Config.prototype = {
},

_find: function(aScript) {
var namespace = aScript._namespace.toLowerCase();
var name = aScript._name.toLowerCase();

for (var i = 0, script; script = this._scripts[i]; i++) {
if (script._namespace.toLowerCase() == namespace
&& script._name.toLowerCase() == name) {
if (script.id == aScript.id) {
return i;
}
}
Expand Down Expand Up @@ -268,7 +264,7 @@ Config.prototype = {
}

script._modified = script.file.lastModifiedTime;
script._metahash = GM_sha1(script._rawMeta);
script._dependhash = GM_sha1(script._rawMeta);

this._scripts.push(script);
this._changed(script, "install", null);
Expand Down
44 changes: 28 additions & 16 deletions content/script.js
Expand Up @@ -273,28 +273,40 @@ Script.prototype = {
return false;
},

updateFromNewScript: function(newScript, safeWin, chromeWin) {
// Migrate preferences.
if (this.prefroot != newScript.prefroot) {
var storageOld = new GM_ScriptStorage(this);
var storageNew = new GM_ScriptStorage(newScript);

var names = storageOld.listValues();
for (var i = 0, name = null; name = names[i]; i++) {
storageNew.setValue(name, storageOld.getValue(name));
storageOld.deleteValue(name);
updateFromNewScript: function(newScript) {
// if the @name and @namespace have changed
// make sure they don't conflict with another installed script
if (newScript.id != this.id) {
if (!GM_getConfig().installIsUpdate(newScript)) {
// Migrate preferences.
if (this.prefroot != newScript.prefroot) {
var storageOld = new GM_ScriptStorage(this);
var storageNew = new GM_ScriptStorage(newScript);

var names = storageOld.listValues();
for (var i = 0, name = null; name = names[i]; i++) {
storageNew.setValue(name, storageOld.getValue(name));
storageOld.deleteValue(name);
}
}

// Empty cached values.
this._id = null;
this._prefroot = null;

this._name = newScript._name;
this._namespace = newScript._namespace;
} else {
// Notify the user of the conflict
alert('Error: Another script with @name: "' + newScript._name +
'" and @namespace: "' + newScript._namespace +
'" is already installed.\nThese values must be unique.');
}
}

// Empty cached values.
this._id = null;
this._prefroot = null;

// Copy new values.
this._includes = newScript._includes;
this._excludes = newScript._excludes;
this._name = newScript._name;
this._namespace = newScript._namespace;
this._description = newScript._description;
this._unwrap = newScript._unwrap;
this._version = newScript._version;
Expand Down
4 changes: 0 additions & 4 deletions content/utils.js
Expand Up @@ -8,10 +8,6 @@ var GM_stringBundle = Components
.getService(Components.interfaces.nsIStringBundleService)
.createBundle("chrome://greasemonkey/locale/gm-browser.properties");

function GM_isDef(thing) {
return typeof(thing) != "undefined";
}

function GM_getConfig() {
return Components
.classes["@greasemonkey.mozdev.org/greasemonkey-service;1"]
Expand Down

0 comments on commit 974f2e8

Please sign in to comment.