Skip to content

Commit

Permalink
[release] Merge branch 'get-beta10-signed' into dev-1.0-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
myrdd committed Sep 9, 2015
2 parents 48bda95 + 75bcf7d commit 0eb896e
Show file tree
Hide file tree
Showing 25 changed files with 1,363 additions and 745 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Note: ChangeLogs for the source code and unit tests, both not relevant for
users, you can find in the dedicated subdirectories.

#### Version 1.0.beta10.1-signed
* The add-on is now signed by Mozilla. (#701) There's no change in
functionality, and no bugs have been fixed.

#### Version 1.0.beta10
* The extension ID has changed (#609). It has to be taken care that
different versions of RequestPolicy aren't installed at the same time.
Expand Down
196 changes: 98 additions & 98 deletions Makefile

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/LICENSE
148 changes: 98 additions & 50 deletions src/content/lib/utils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,15 @@ const Cu = Components.utils;

let EXPORTED_SYMBOLS = ["Utils"];

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

Cu.import("chrome://rpcontinued/content/lib/script-loader.jsm");
ScriptLoader.importModules([
"lib/prefs",
"lib/utils/constants",
"lib/environment"
"lib/environment",
"lib/logger"
], this);

if (ProcessEnvironment.isMainProcess) {
Cu.import("resource://gre/modules/AddonManager.jsm");
}




Expand Down Expand Up @@ -119,48 +113,6 @@ let Utils = (function() {
};




self.info = {};

// bad smell...
// get/set last/current RP version
if (ProcessEnvironment.isMainProcess) {
self.info.lastRPVersion = rpPrefBranch.getCharPref("lastVersion");

self.info.curRPVersion = "0.0";
// curRPVersion needs to be set asynchronously
AddonManager.getAddonByID(C.EXTENSION_ID, function(addon) {
rpPrefBranch.setCharPref("lastVersion", addon.version);
self.info.curRPVersion = addon.version;
if (self.info.lastRPVersion != self.info.curRPVersion) {
Services.prefs.savePrefFile(null);
}
});
}

// bad smell...
// get/set last/current app (e.g. firefox) version
if (ProcessEnvironment.isMainProcess) {
self.info.lastAppVersion = rpPrefBranch.getCharPref("lastAppVersion");

let curAppVersion = Services.appinfo.version;
self.info.curAppVersion = curAppVersion;
rpPrefBranch.setCharPref("lastAppVersion", curAppVersion);

if (self.info.lastAppVersion != self.info.curAppVersion) {
Services.prefs.savePrefFile(null);
}
}

let appID = Services.appinfo.ID;
self.info.isFirefox = appID === C.FIREFOX_ID;
self.info.isSeamonkey = appID === C.SEAMONKEY_ID;
self.info.isAustralis = self.info.isFirefox &&
Services.vc.compare(Services.appinfo.platformVersion, '29') >= 0;



/**
* This function returns and eventually creates a module's `internal`
* variable. The `internal` can be accessed from all submodules of that
Expand Down Expand Up @@ -188,5 +140,101 @@ let Utils = (function() {
return aModuleScope.internal;
};


/**
* Wrap a function. Allow 'before' and 'after' functions.
* If the function was wrapped already earlier in time, the old
* wrapper function will be re-used.
*
* @param {Object} aOwnerObject The object which contains (a reference to)
* the function which should be wrapped.
* @param {string} aFunctionName The function's name in the object.
* @param {Function=} aBeforeFunction The function to be called before the
* original function.
* @param {Function=} aAfterFunction The function to be called after the
* original function.
*/
self.wrapFunction = function(aOwnerObject, aFunctionName,
aBeforeFunction = null, aAfterFunction = null) {
initWrapperFunction(aOwnerObject, aFunctionName);

var fnMetadata = aOwnerObject.rpcontinuedWrappedFunctions[aFunctionName];
fnMetadata.before = aBeforeFunction;
fnMetadata.after = aAfterFunction;
};

/**
* Unwrap a function which has been wrapped before. The function won't
* be removed though, because another addon could have wrapped the same
* function as well. Instead, the 'before' and 'after' functions are
* set to `null`.
*
* @param {Object} aOwnerObject The object which contains (a reference to)
* the function which should be wrapped.
* @param {string} aFunctionName The function's name in the object.
*/
self.unwrapFunction = function(aOwnerObject, aFunctionName) {
self.wrapFunction(aOwnerObject, aFunctionName, null, null);
};

/**
* @param {Object} aOwnerObject The object which contains (a reference to)
* the function which should be wrapped.
* @param {string} aFunctionName The function's name in the object.
*/
function initWrapperFunction(aOwnerObject, aFunctionName) {
// create metadata object
if (!aOwnerObject.hasOwnProperty("rpcontinuedWrappedFunctions")) {
aOwnerObject.rpcontinuedWrappedFunctions = {};
}

var metadata = aOwnerObject.rpcontinuedWrappedFunctions;

if (metadata.hasOwnProperty(aFunctionName)) {
// the function is already wrapped by RequestPolicy
return;
}

// create metadata
metadata[aFunctionName] = {
main: aOwnerObject[aFunctionName], // the original function
before: null,
after: null
};

// actually wrap the object
aOwnerObject[aFunctionName] = function() {
var {main, before, after} = metadata[aFunctionName];

// Execute some action before the original function call.
try {
if (before) {
before.apply(aOwnerObject, arguments);
}
} catch (e) {
Logger.warning(Logger.TYPE_ERROR, "The 'before' function of the " +
"`" + aFunctionName + "()` wrapper has thrown an " +
"error.", e);
}

// Execute original function.
var rv = main.apply(aOwnerObject, arguments);

// Execute some action afterwards.
try {
if (after) {
after.apply(aOwnerObject, arguments);
}
} catch (e) {
Logger.warning(Logger.TYPE_ERROR, "The 'after' function of the " +
"`" + aFunctionName + "()` wrapper has thrown an " +
"error.", e);
}

// return the original result
return rv;
};
}

return self;
}());
87 changes: 87 additions & 0 deletions src/content/lib/utils/info.jsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* ***** BEGIN LICENSE BLOCK *****
*
* RequestPolicy - A Firefox extension for control over cross-site requests.
* Copyright (c) 2008-2012 Justin Samuel
* Copyright (c) 2014-2015 Martin Kimmerle
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see {tag: "http"://www.gnu.org/licenses}.
*
* ***** END LICENSE BLOCK *****
*/

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

let EXPORTED_SYMBOLS = ["Info"];

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

Cu.import("chrome://rpcontinued/content/lib/script-loader.jsm");
ScriptLoader.importModules([
"lib/prefs",
"lib/utils/constants",
"lib/environment"
], this);

if (ProcessEnvironment.isMainProcess) {
Cu.import("resource://gre/modules/AddonManager.jsm");
}



let Info = (function() {
let self = {};

self = {};

// bad smell...
// get/set last/current RP version
if (ProcessEnvironment.isMainProcess) {
self.lastRPVersion = rpPrefBranch.getCharPref("lastVersion");

self.curRPVersion = "0.0";
// curRPVersion needs to be set asynchronously
AddonManager.getAddonByID(C.EXTENSION_ID, function(addon) {
rpPrefBranch.setCharPref("lastVersion", addon.version);
self.curRPVersion = addon.version;
if (self.lastRPVersion != self.curRPVersion) {
Services.prefs.savePrefFile(null);
}
});
}

// bad smell...
// get/set last/current app (e.g. firefox) version
if (ProcessEnvironment.isMainProcess) {
self.lastAppVersion = rpPrefBranch.getCharPref("lastAppVersion");

let curAppVersion = Services.appinfo.version;
self.curAppVersion = curAppVersion;
rpPrefBranch.setCharPref("lastAppVersion", curAppVersion);

if (self.lastAppVersion != self.curAppVersion) {
Services.prefs.savePrefFile(null);
}
}

let appID = Services.appinfo.ID;
self.isFirefox = appID === C.FIREFOX_ID;
self.isSeamonkey = appID === C.SEAMONKEY_ID;
self.isAustralis = self.isFirefox &&
Services.vc.compare(Services.appinfo.platformVersion, '29') >= 0;

return self;
}());
Loading

0 comments on commit 0eb896e

Please sign in to comment.