[Pkg-mozext-commits] [requestpolicy] 47/100: [refactoring] move RequestResult to separate file
David Prévot
taffit at moszumanska.debian.org
Fri Dec 12 22:56:56 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 33e957c686e187101af18370b80249c6a7eb3a12
Author: myrdd <myrdd at users.noreply.github.com>
Date: Fri Oct 3 22:03:26 2014 +0200
[refactoring] move RequestResult to separate file
---
src/modules/PolicyManager.jsm | 78 +++------------------------------
src/modules/RequestProcessor.jsm | 2 +-
src/modules/RequestResult.jsm | 94 ++++++++++++++++++++++++++++++++++++++++
src/modules/RequestUtil.jsm | 2 +-
4 files changed, 101 insertions(+), 75 deletions(-)
diff --git a/src/modules/PolicyManager.jsm b/src/modules/PolicyManager.jsm
index d51de40..76399cd 100644
--- a/src/modules/PolicyManager.jsm
+++ b/src/modules/PolicyManager.jsm
@@ -23,22 +23,7 @@
var EXPORTED_SYMBOLS = [
"PolicyManager",
"RULES_CHANGED_TOPIC",
- "RequestResult",
- "Destination",
- "REQUEST_REASON_USER_POLICY",
- "REQUEST_REASON_SUBSCRIPTION_POLICY",
- "REQUEST_REASON_DEFAULT_POLICY",
- "REQUEST_REASON_DEFAULT_POLICY_INCONSISTENT_RULES",
- "REQUEST_REASON_DEFAULT_SAME_DOMAIN",
- "REQUEST_REASON_COMPATIBILITY",
- "REQUEST_REASON_LINK_CLICK",
- "REQUEST_REASON_FORM_SUBMISSION",
- "REQUEST_REASON_HISTORY_REQUEST",
- "REQUEST_REASON_USER_ALLOWED_REDIRECT",
- "REQUEST_REASON_USER_ACTION",
- "REQUEST_REASON_NEW_WINDOW",
- "REQUEST_REASON_IDENTICAL_IDENTIFIER",
- "REQUEST_REASON_RELATIVE_URL"
+ "Destination"
];
const CI = Components.interfaces;
@@ -58,6 +43,8 @@ Components.utils.import("resource://requestpolicy/Policy.jsm",
requestpolicy.mod);
Components.utils.import("resource://requestpolicy/PolicyStorage.jsm",
requestpolicy.mod);
+Components.utils.import("resource://requestpolicy/RequestResult.jsm",
+ requestpolicy.mod);
function dprint(msg) {
@@ -94,61 +81,6 @@ function notifyRulesChanged() {
-const REQUEST_REASON_USER_POLICY = 1;
-const REQUEST_REASON_SUBSCRIPTION_POLICY = 2;
-const REQUEST_REASON_DEFAULT_POLICY = 3;
-const REQUEST_REASON_DEFAULT_POLICY_INCONSISTENT_RULES = 4; // if there are allow _and_ deny rules for the same request
-const REQUEST_REASON_DEFAULT_SAME_DOMAIN = 5;
-const REQUEST_REASON_COMPATIBILITY = 6;
-
-const REQUEST_REASON_LINK_CLICK = 7;
-const REQUEST_REASON_FORM_SUBMISSION = 8;
-const REQUEST_REASON_HISTORY_REQUEST = 9;
-const REQUEST_REASON_USER_ALLOWED_REDIRECT = 10;
-const REQUEST_REASON_USER_ACTION = 11;
-const REQUEST_REASON_NEW_WINDOW = 12;
-const REQUEST_REASON_IDENTICAL_IDENTIFIER = 13;
-
-const REQUEST_REASON_RELATIVE_URL = 14; // TODO: give user control about relative urls on the page
-
-
-// TODO: merge this Class with the "Request" class and/or some kind of
-// "RememberedRequest" or "RequestInfo" class.
-/**
- * RequestResult objects are used to hand over the result of a check
- * whether a request is allowed or not. Sometimes only the boolean value of
- * isAllowed is needed; in that case the other arguments may be unused.
- */
-function RequestResult(isAllowed, resultReason) {
- this.matchedAllowRules = [];
- this.matchedDenyRules = [];
-
- this.isAllowed = isAllowed;
- this.resultReason = resultReason;
-}
-RequestResult.prototype = {
- matchedAllowRules : null,
- matchedDenyRules : null,
-
- isAllowed : undefined, // whether the request will be or has been allowed
- resultReason : undefined,
-
- allowRulesExist : function() {
- return this.matchedAllowRules.length > 0;
- },
- denyRulesExist : function () {
- return this.matchedDenyRules.length > 0;
- },
-
- isDefaultPolicyUsed : function () {
- // returns whether the default policy has been or will be used for this request.
- return (this.resultReason == REQUEST_REASON_DEFAULT_POLICY ||
- this.resultReason == REQUEST_REASON_DEFAULT_POLICY_INCONSISTENT_RULES ||
- this.resultReason == REQUEST_REASON_DEFAULT_SAME_DOMAIN);
- }
-};
-
-
/**
* Destination objects are used to hand over not only "destination" strings, like
@@ -495,7 +427,7 @@ PolicyManager.prototype = {
},
checkRequestAgainstSubscriptionPolicies : function(origin, dest) {
- var result = new RequestResult();
+ var result = new requestpolicy.mod.RequestResult();
for (var listName in this._subscriptionPolicies) {
var policies = this._subscriptionPolicies[listName];
this._checkRequest(origin, dest, policies, result);
@@ -511,7 +443,7 @@ PolicyManager.prototype = {
throw "Destination must be an nsIURI.";
}
if (!result) {
- result = new RequestResult();
+ result = new requestpolicy.mod.RequestResult();
}
for (var i in policies) {
var policy = policies[i].policy;
diff --git a/src/modules/RequestProcessor.jsm b/src/modules/RequestProcessor.jsm
index 8ecfac0..0028efd 100644
--- a/src/modules/RequestProcessor.jsm
+++ b/src/modules/RequestProcessor.jsm
@@ -42,7 +42,7 @@ Components.utils.import("resource://requestpolicy/DomainUtil.jsm",
requestpolicy.mod);
Components.utils.import("resource://requestpolicy/Logger.jsm",
requestpolicy.mod);
-Components.utils.import("resource://requestpolicy/PolicyManager.jsm",
+Components.utils.import("resource://requestpolicy/RequestResult.jsm",
requestpolicy.mod);
Components.utils.import("resource://requestpolicy/RequestUtil.jsm",
requestpolicy.mod);
diff --git a/src/modules/RequestResult.jsm b/src/modules/RequestResult.jsm
new file mode 100644
index 0000000..09196f2
--- /dev/null
+++ b/src/modules/RequestResult.jsm
@@ -0,0 +1,94 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ *
+ * RequestPolicy - A Firefox extension for control over cross-site requests.
+ * Copyright (c) 2011 Justin Samuel
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+var EXPORTED_SYMBOLS = [
+ "RequestResult",
+ "REQUEST_REASON_USER_POLICY",
+ "REQUEST_REASON_SUBSCRIPTION_POLICY",
+ "REQUEST_REASON_DEFAULT_POLICY",
+ "REQUEST_REASON_DEFAULT_POLICY_INCONSISTENT_RULES",
+ "REQUEST_REASON_DEFAULT_SAME_DOMAIN",
+ "REQUEST_REASON_COMPATIBILITY",
+ "REQUEST_REASON_LINK_CLICK",
+ "REQUEST_REASON_FORM_SUBMISSION",
+ "REQUEST_REASON_HISTORY_REQUEST",
+ "REQUEST_REASON_USER_ALLOWED_REDIRECT",
+ "REQUEST_REASON_USER_ACTION",
+ "REQUEST_REASON_NEW_WINDOW",
+ "REQUEST_REASON_IDENTICAL_IDENTIFIER",
+ "REQUEST_REASON_RELATIVE_URL"
+];
+
+
+const REQUEST_REASON_USER_POLICY = 1;
+const REQUEST_REASON_SUBSCRIPTION_POLICY = 2;
+const REQUEST_REASON_DEFAULT_POLICY = 3;
+const REQUEST_REASON_DEFAULT_POLICY_INCONSISTENT_RULES = 4; // if there are allow _and_ deny rules for the same request
+const REQUEST_REASON_DEFAULT_SAME_DOMAIN = 5;
+const REQUEST_REASON_COMPATIBILITY = 6;
+
+const REQUEST_REASON_LINK_CLICK = 7;
+const REQUEST_REASON_FORM_SUBMISSION = 8;
+const REQUEST_REASON_HISTORY_REQUEST = 9;
+const REQUEST_REASON_USER_ALLOWED_REDIRECT = 10;
+const REQUEST_REASON_USER_ACTION = 11;
+const REQUEST_REASON_NEW_WINDOW = 12;
+const REQUEST_REASON_IDENTICAL_IDENTIFIER = 13;
+
+const REQUEST_REASON_RELATIVE_URL = 14; // TODO: give user control about relative urls on the page
+
+
+// TODO: merge this Class with the "Request" class and/or some kind of
+// "RememberedRequest" or "RequestInfo" class.
+/**
+ * RequestResult objects are used to hand over the result of a check
+ * whether a request is allowed or not. Sometimes only the boolean value of
+ * isAllowed is needed; in that case the other arguments may be unused.
+ */
+function RequestResult(isAllowed, resultReason) {
+ this.matchedAllowRules = [];
+ this.matchedDenyRules = [];
+
+ this.isAllowed = isAllowed;
+ this.resultReason = resultReason;
+}
+RequestResult.prototype = {
+ matchedAllowRules : null,
+ matchedDenyRules : null,
+
+ isAllowed : undefined, // whether the request will be or has been allowed
+ resultReason : undefined,
+
+ allowRulesExist : function() {
+ return this.matchedAllowRules.length > 0;
+ },
+ denyRulesExist : function () {
+ return this.matchedDenyRules.length > 0;
+ },
+
+ isDefaultPolicyUsed : function () {
+ // returns whether the default policy has been or will be used for this request.
+ return (this.resultReason == REQUEST_REASON_DEFAULT_POLICY ||
+ this.resultReason == REQUEST_REASON_DEFAULT_POLICY_INCONSISTENT_RULES ||
+ this.resultReason == REQUEST_REASON_DEFAULT_SAME_DOMAIN);
+ }
+};
diff --git a/src/modules/RequestUtil.jsm b/src/modules/RequestUtil.jsm
index af6be43..d4bc56e 100644
--- a/src/modules/RequestUtil.jsm
+++ b/src/modules/RequestUtil.jsm
@@ -24,7 +24,7 @@ var EXPORTED_SYMBOLS = ["RequestUtil", "RequestSet"];
Components.utils.import("resource://requestpolicy/DomainUtil.jsm");
Components.utils.import("resource://requestpolicy/Logger.jsm");
-Components.utils.import("resource://requestpolicy/PolicyManager.jsm");
+Components.utils.import("resource://requestpolicy/RequestResult.jsm");
function getUriObject(uri) {
return DomainUtil.getUriObject(uri);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list