[Pkg-mozext-commits] [requestpolicy] 150/257: [ref] settings: wrap js code in IIFEs
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:20:07 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 3fc873f413e03111253e9bf8f09dbd21842bfb27
Author: Martin Kimmerle <dev at 256k.de>
Date: Mon Nov 30 22:37:11 2015 +0100
[ref] settings: wrap js code in IIFEs
Wrap the settings *.js files in IIFEs, all of them with a common
header.
<body onload="onload()"> is replaced by setting `window.onload`
---
src/content/settings/advancedprefs.html | 2 +-
src/content/settings/advancedprefs.js | 266 ++++++++++----------
src/content/settings/basicprefs.html | 2 +-
src/content/settings/basicprefs.js | 168 +++++++------
src/content/settings/common.js | 282 +++++++++++-----------
src/content/settings/defaultpolicy.html | 2 +-
src/content/settings/defaultpolicy.js | 168 +++++++------
src/content/settings/oldrules.html | 2 +-
src/content/settings/oldrules.js | 202 ++++++++--------
src/content/settings/setup.html | 2 +-
src/content/settings/setup.js | 331 +++++++++++++------------
src/content/settings/subscriptions.html | 2 +-
src/content/settings/subscriptions.js | 281 +++++++++++----------
src/content/settings/yourpolicy.html | 2 +-
src/content/settings/yourpolicy.js | 416 +++++++++++++++++---------------
15 files changed, 1124 insertions(+), 1004 deletions(-)
diff --git a/src/content/settings/advancedprefs.html b/src/content/settings/advancedprefs.html
index 8285c08..b386055 100644
--- a/src/content/settings/advancedprefs.html
+++ b/src/content/settings/advancedprefs.html
@@ -8,7 +8,7 @@
<link href="chrome://rpcontinued/content/settings/settings.css"
rel="stylesheet" type="text/css"/>
</head>
-<body onload="onload()">
+<body>
<table>
<tr>
<td id="sidepad"></td>
diff --git a/src/content/settings/advancedprefs.js b/src/content/settings/advancedprefs.js
index e8ac116..4ee6b93 100644
--- a/src/content/settings/advancedprefs.js
+++ b/src/content/settings/advancedprefs.js
@@ -1,133 +1,147 @@
-var PAGE_STRINGS = [
- 'basic',
- 'advanced',
- 'advancedPreferences',
- 'linkPrefetching',
- 'dnsPrefetching',
- 'enabled',
- 'disableOnStartup',
- 'restoreDefaultOnUninstall',
- 'menuPreferences',
- 'menuSorting',
- 'sortByNumRequests',
- 'sortByDestName',
- 'noSorting',
- 'hint',
- 'menuSortingHint',
- 'menuIndicatedInformation',
- 'menuIndicateNumRequests'
-];
-
-$(function () {
- common.localize(PAGE_STRINGS);
-});
-
-Cu.import("resource://gre/modules/Services.jsm");
-
-
-function updateDisplay() {
- // Link prefetch.
- $id('pref-linkPrefetch').checked =
- rootPrefBranch.getBoolPref('network.prefetch-next');
-
- $id('pref-prefetch.link.disableOnStartup').checked =
- rpPrefBranch.getBoolPref('prefetch.link.disableOnStartup');
-
- $id('pref-prefetch.link.restoreDefaultOnUninstall').checked =
- rpPrefBranch.getBoolPref('prefetch.link.restoreDefaultOnUninstall');
-
- // DNS prefetch.
- $id('pref-dnsPrefetch').checked =
- !rootPrefBranch.getBoolPref('network.dns.disablePrefetch');
-
- $id('pref-prefetch.dns.disableOnStartup').checked =
- rpPrefBranch.getBoolPref('prefetch.dns.disableOnStartup');
-
- $id('pref-prefetch.dns.restoreDefaultOnUninstall').checked =
- rpPrefBranch.getBoolPref('prefetch.dns.restoreDefaultOnUninstall');
-
- // TODO: Create a class which acts as an API for preferences and which ensures
- // that the returned value is always a valid value for "string" preferences.
- var sorting = rpPrefBranch.getCharPref('menu.sorting');
-
- if (sorting == $id('sortByNumRequests').value) {
- $id('sortByNumRequests').checked = true;
- $id('sortByDestName').checked = false;
- $id('noSorting').checked = false;
- } else if (sorting == $id('noSorting').value) {
- $id('sortByNumRequests').checked = false;
- $id('sortByDestName').checked = false;
- $id('noSorting').checked = true;
- } else {
- $id('sortByNumRequests').checked = false;
- $id('sortByDestName').checked = true;
- $id('noSorting').checked = false;
- }
+/* global window, $, common, WinEnv, elManager, $id */
+
+(function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {rpPrefBranch, rootPrefBranch} = importModule("lib/prefs");
+
+ //============================================================================
+
+ var PAGE_STRINGS = [
+ 'basic',
+ 'advanced',
+ 'advancedPreferences',
+ 'linkPrefetching',
+ 'dnsPrefetching',
+ 'enabled',
+ 'disableOnStartup',
+ 'restoreDefaultOnUninstall',
+ 'menuPreferences',
+ 'menuSorting',
+ 'sortByNumRequests',
+ 'sortByDestName',
+ 'noSorting',
+ 'hint',
+ 'menuSortingHint',
+ 'menuIndicatedInformation',
+ 'menuIndicateNumRequests'
+ ];
+
+ $(function () {
+ common.localize(PAGE_STRINGS);
+ });
- $id('menu.info.showNumRequests').checked =
- rpPrefBranch.getBoolPref('menu.info.showNumRequests');
-}
+ function updateDisplay() {
+ // Link prefetch.
+ $id('pref-linkPrefetch').checked =
+ rootPrefBranch.getBoolPref('network.prefetch-next');
-function onload() {
- updateDisplay();
+ $id('pref-prefetch.link.disableOnStartup').checked =
+ rpPrefBranch.getBoolPref('prefetch.link.disableOnStartup');
- // Link prefetch.
- elManager.addListener($id('pref-linkPrefetch'), 'change', function (event) {
- rootPrefBranch.setBoolPref('network.prefetch-next', event.target.checked);
- Services.prefs.savePrefFile(null);
- });
+ $id('pref-prefetch.link.restoreDefaultOnUninstall').checked =
+ rpPrefBranch.getBoolPref('prefetch.link.restoreDefaultOnUninstall');
- elManager.addListener(
- $id('pref-prefetch.link.disableOnStartup'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('prefetch.link.disableOnStartup',
- event.target.checked);
- Services.prefs.savePrefFile(null);
- });
-
- elManager.addListener(
- $id('pref-prefetch.link.restoreDefaultOnUninstall'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('prefetch.link.restoreDefaultOnUninstall', event.target.checked);
- Services.prefs.savePrefFile(null);
- });
-
- // DNS prefetch.
- elManager.addListener($id('pref-dnsPrefetch'), 'change', function (event) {
- rootPrefBranch.setBoolPref('network.dns.disablePrefetch', !event.target.checked);
- Services.prefs.savePrefFile(null);
- });
+ // DNS prefetch.
+ $id('pref-dnsPrefetch').checked =
+ !rootPrefBranch.getBoolPref('network.dns.disablePrefetch');
+
+ $id('pref-prefetch.dns.disableOnStartup').checked =
+ rpPrefBranch.getBoolPref('prefetch.dns.disableOnStartup');
+
+ $id('pref-prefetch.dns.restoreDefaultOnUninstall').checked =
+ rpPrefBranch.getBoolPref('prefetch.dns.restoreDefaultOnUninstall');
- elManager.addListener(
- $id('pref-prefetch.dns.disableOnStartup'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('prefetch.dns.disableOnStartup', event.target.checked);
- Services.prefs.savePrefFile(null);
- });
-
- elManager.addListener(
- $id('pref-prefetch.dns.restoreDefaultOnUninstall'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('prefetch.dns.restoreDefaultOnUninstall', event.target.checked);
- Services.prefs.savePrefFile(null);
- });
-
- var sortingListener = function (event) {
- rpPrefBranch.setCharPref('menu.sorting', event.target.value);
- Services.prefs.savePrefFile(null);
+ // TODO: Create a class which acts as an API for preferences and which ensures
+ // that the returned value is always a valid value for "string" preferences.
+ var sorting = rpPrefBranch.getCharPref('menu.sorting');
+
+ if (sorting === $id('sortByNumRequests').value) {
+ $id('sortByNumRequests').checked = true;
+ $id('sortByDestName').checked = false;
+ $id('noSorting').checked = false;
+ } else if (sorting === $id('noSorting').value) {
+ $id('sortByNumRequests').checked = false;
+ $id('sortByDestName').checked = false;
+ $id('noSorting').checked = true;
+ } else {
+ $id('sortByNumRequests').checked = false;
+ $id('sortByDestName').checked = true;
+ $id('noSorting').checked = false;
+ }
+
+ $id('menu.info.showNumRequests').checked =
+ rpPrefBranch.getBoolPref('menu.info.showNumRequests');
+ }
+
+
+ window.onload = function () {
+ updateDisplay();
+
+ // Link prefetch.
+ elManager.addListener($id('pref-linkPrefetch'), 'change', function (event) {
+ rootPrefBranch.setBoolPref('network.prefetch-next', event.target.checked);
+ Services.prefs.savePrefFile(null);
+ });
+
+ elManager.addListener(
+ $id('pref-prefetch.link.disableOnStartup'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('prefetch.link.disableOnStartup',
+ event.target.checked);
+ Services.prefs.savePrefFile(null);
+ });
+
+ elManager.addListener(
+ $id('pref-prefetch.link.restoreDefaultOnUninstall'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('prefetch.link.restoreDefaultOnUninstall', event.target.checked);
+ Services.prefs.savePrefFile(null);
+ });
+
+ // DNS prefetch.
+ elManager.addListener($id('pref-dnsPrefetch'), 'change', function (event) {
+ rootPrefBranch.setBoolPref('network.dns.disablePrefetch', !event.target.checked);
+ Services.prefs.savePrefFile(null);
+ });
+
+ elManager.addListener(
+ $id('pref-prefetch.dns.disableOnStartup'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('prefetch.dns.disableOnStartup', event.target.checked);
+ Services.prefs.savePrefFile(null);
+ });
+
+ elManager.addListener(
+ $id('pref-prefetch.dns.restoreDefaultOnUninstall'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('prefetch.dns.restoreDefaultOnUninstall', event.target.checked);
+ Services.prefs.savePrefFile(null);
+ });
+
+ var sortingListener = function (event) {
+ rpPrefBranch.setCharPref('menu.sorting', event.target.value);
+ Services.prefs.savePrefFile(null);
+ };
+ elManager.addListener($id('sortByNumRequests'), 'change', sortingListener);
+ elManager.addListener($id('sortByDestName'), 'change', sortingListener);
+ elManager.addListener($id('noSorting'), 'change', sortingListener);
+
+ elManager.addListener(
+ $id('menu.info.showNumRequests'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('menu.info.showNumRequests', event.target.checked);
+ Services.prefs.savePrefFile(null);
+ });
+
+ // call updateDisplay() every time a preference gets changed
+ WinEnv.obMan.observePrefChanges(updateDisplay);
};
- elManager.addListener($id('sortByNumRequests'), 'change', sortingListener);
- elManager.addListener($id('sortByDestName'), 'change', sortingListener);
- elManager.addListener($id('noSorting'), 'change', sortingListener);
-
- elManager.addListener(
- $id('menu.info.showNumRequests'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('menu.info.showNumRequests', event.target.checked);
- Services.prefs.savePrefFile(null);
- });
-
- // call updateDisplay() every time a preference gets changed
- WinEnv.obMan.observePrefChanges(updateDisplay);
-}
+
+}());
diff --git a/src/content/settings/basicprefs.html b/src/content/settings/basicprefs.html
index 697f949..6b58042 100644
--- a/src/content/settings/basicprefs.html
+++ b/src/content/settings/basicprefs.html
@@ -8,7 +8,7 @@
<link href="chrome://rpcontinued/content/settings/settings.css"
rel="stylesheet" type="text/css"/>
</head>
-<body onload="onload()">
+<body>
<table>
<tr>
<td id="sidepad"></td>
diff --git a/src/content/settings/basicprefs.js b/src/content/settings/basicprefs.js
index 34011d9..4da7899 100644
--- a/src/content/settings/basicprefs.js
+++ b/src/content/settings/basicprefs.js
@@ -1,79 +1,93 @@
-var PAGE_STRINGS = [
- 'basic',
- 'advanced',
- 'webPages',
- 'indicateBlockedImages',
- 'dontIndicateBlacklisted',
- 'autoReload',
- 'menu',
- 'allowAddingNonTemporaryRulesInPBM'
-];
-
-$(function () {
- common.localize(PAGE_STRINGS);
-});
-
-Cu.import("resource://gre/modules/Services.jsm");
-
-
-function updateDisplay() {
- var indicate = rpPrefBranch.getBoolPref('indicateBlockedObjects');
- $id('pref-indicateBlockedObjects').checked = indicate;
- $id('indicateBlockedImages-details').hidden = !indicate;
-
- $id('pref-dontIndicateBlacklistedObjects').checked =
- !rpPrefBranch.getBoolPref('indicateBlacklistedObjects');
-
- $id('pref-autoReload').checked =
- rpPrefBranch.getBoolPref('autoReload');
-
- $id('pref-privateBrowsingPermanentWhitelisting').checked =
- rpPrefBranch.getBoolPref('privateBrowsingPermanentWhitelisting');
-
-// if (rpPrefBranch.getBoolPref('defaultPolicy.allow')) {
-// var word = 'allow';
-// } else {
-// var word = 'block';
-// }
-// $id('defaultpolicyword').innerHTML = word;
-}
-
-
-function onload() {
- updateDisplay();
-
- elManager.addListener(
- $id('pref-indicateBlockedObjects'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('indicateBlockedObjects', event.target.checked);
- Services.prefs.savePrefFile(null);
- updateDisplay();
- });
-
- elManager.addListener(
- $id('pref-dontIndicateBlacklistedObjects'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('indicateBlacklistedObjects',
- !event.target.checked);
- Services.prefs.savePrefFile(null);
- updateDisplay();
- });
-
- elManager.addListener($id('pref-autoReload'), 'change', function(event) {
- rpPrefBranch.setBoolPref('autoReload', event.target.checked);
- Services.prefs.savePrefFile(null);
- updateDisplay();
+/* global window, $, common, WinEnv, elManager, $id */
+
+(function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {rpPrefBranch} = importModule("lib/prefs");
+
+ //============================================================================
+
+ var PAGE_STRINGS = [
+ 'basic',
+ 'advanced',
+ 'webPages',
+ 'indicateBlockedImages',
+ 'dontIndicateBlacklisted',
+ 'autoReload',
+ 'menu',
+ 'allowAddingNonTemporaryRulesInPBM'
+ ];
+
+ $(function () {
+ common.localize(PAGE_STRINGS);
});
- elManager.addListener(
- $id('pref-privateBrowsingPermanentWhitelisting'), 'change',
- function (event) {
- rpPrefBranch.setBoolPref('privateBrowsingPermanentWhitelisting',
- event.target.checked);
- Services.prefs.savePrefFile(null);
- updateDisplay();
- });
-
- // call updateDisplay() every time a preference gets changed
- WinEnv.obMan.observePrefChanges(updateDisplay);
-}
+
+ function updateDisplay() {
+ var indicate = rpPrefBranch.getBoolPref('indicateBlockedObjects');
+ $id('pref-indicateBlockedObjects').checked = indicate;
+ $id('indicateBlockedImages-details').hidden = !indicate;
+
+ $id('pref-dontIndicateBlacklistedObjects').checked =
+ !rpPrefBranch.getBoolPref('indicateBlacklistedObjects');
+
+ $id('pref-autoReload').checked =
+ rpPrefBranch.getBoolPref('autoReload');
+
+ $id('pref-privateBrowsingPermanentWhitelisting').checked =
+ rpPrefBranch.getBoolPref('privateBrowsingPermanentWhitelisting');
+
+ // if (rpPrefBranch.getBoolPref('defaultPolicy.allow')) {
+ // var word = 'allow';
+ // } else {
+ // var word = 'block';
+ // }
+ // $id('defaultpolicyword').innerHTML = word;
+ }
+
+
+ window.onload = function () {
+ updateDisplay();
+
+ elManager.addListener(
+ $id('pref-indicateBlockedObjects'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('indicateBlockedObjects', event.target.checked);
+ Services.prefs.savePrefFile(null);
+ updateDisplay();
+ });
+
+ elManager.addListener(
+ $id('pref-dontIndicateBlacklistedObjects'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('indicateBlacklistedObjects',
+ !event.target.checked);
+ Services.prefs.savePrefFile(null);
+ updateDisplay();
+ });
+
+ elManager.addListener($id('pref-autoReload'), 'change', function(event) {
+ rpPrefBranch.setBoolPref('autoReload', event.target.checked);
+ Services.prefs.savePrefFile(null);
+ updateDisplay();
+ });
+
+ elManager.addListener(
+ $id('pref-privateBrowsingPermanentWhitelisting'), 'change',
+ function (event) {
+ rpPrefBranch.setBoolPref('privateBrowsingPermanentWhitelisting',
+ event.target.checked);
+ Services.prefs.savePrefFile(null);
+ updateDisplay();
+ });
+
+ // call updateDisplay() every time a preference gets changed
+ WinEnv.obMan.observePrefChanges(updateDisplay);
+ };
+
+}());
diff --git a/src/content/settings/common.js b/src/content/settings/common.js
index d44ecbe..43aecec 100644
--- a/src/content/settings/common.js
+++ b/src/content/settings/common.js
@@ -1,149 +1,151 @@
-
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-const Cu = Components.utils;
-
-Cu.import("resource://gre/modules/Services.jsm");
-
-Cu.import("chrome://rpcontinued/content/lib/script-loader.jsm");
-ScriptLoader.importModules([
- "lib/utils/constants",
- "lib/utils/strings",
- "lib/utils/info",
- "lib/utils",
- "lib/prefs",
- "lib/utils/domains",
- "lib/logger",
- "lib/subscription",
- "lib/policy-manager",
- "main/requestpolicy-service",
- "lib/environment"
-], this);
-
-// create a new Environment for this window
-var WinEnv = new Environment(ProcessEnvironment, "WinEnv");
-// The Environment has to be shut down when the content window gets unloaded.
-WinEnv.shutdownOnUnload(window);
-// start up right now, as there won't be any startup functions
-WinEnv.startup();
-var elManager = WinEnv.elManager;
-
-
-var $id = window.document.getElementById.bind(window.document);
-
-
-var COMMON_STRINGS = [
- 'preferences',
- 'managePolicies',
- 'about',
- 'help',
- 'basic',
- 'advanced'
-];
-
-
-var $str = StringUtils.$str;
-
-var common = {};
-
-/*
- Based on the user's current default policy (allow or deny), swaps out which
- subscriptions are enabled. That is, each subscription are either intended to be
- used with a default allow or a default policy policy. So, if this has changed
- then calling this function will disable/enable the correct subscriptions.
- */
-// TODO: rename this function.
-common.switchSubscriptionPolicies = function () {
- var subscriptions = new UserSubscriptions();
-
- var newDefaultPolicy = Prefs.isDefaultAllow() ? 'allow' : 'deny';
- var oldDefaultPolicy = Prefs.isDefaultAllow() ? 'deny' : 'allow';
-
- var oldSubInfo = subscriptions.getSubscriptionInfo(oldDefaultPolicy);
- for (var listName in oldSubInfo) {
- for (var subName in oldSubInfo[listName]) {
- if (subName.indexOf('allow_') != 0 && subName.indexOf('deny_') != 0) {
- continue;
+/* global $, window */
+/* exported common, WinEnv, elManager, $id, $str */
+
+var {common, WinEnv, elManager, $id, $str} = (function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {StringUtils} = importModule("lib/utils/strings");
+ let {Prefs} = importModule("lib/prefs");
+ let {UserSubscriptions, SUBSCRIPTION_ADDED_TOPIC,
+ SUBSCRIPTION_REMOVED_TOPIC} = importModule("lib/subscription");
+ let {Environment, ProcessEnvironment} = importModule("lib/environment");
+
+ //============================================================================
+
+ // create a new Environment for this window
+ var WinEnv = new Environment(ProcessEnvironment, "WinEnv");
+ // The Environment has to be shut down when the content window gets unloaded.
+ WinEnv.shutdownOnUnload(window);
+ // start up right now, as there won't be any startup functions
+ WinEnv.startup();
+ var elManager = WinEnv.elManager;
+
+
+ var $id = window.document.getElementById.bind(window.document);
+
+
+ var COMMON_STRINGS = [
+ 'preferences',
+ 'managePolicies',
+ 'about',
+ 'help',
+ 'basic',
+ 'advanced'
+ ];
+
+
+ var $str = StringUtils.$str;
+
+ var common = {};
+
+ /*
+ Based on the user's current default policy (allow or deny), swaps out which
+ subscriptions are enabled. That is, each subscription are either intended to be
+ used with a default allow or a default policy policy. So, if this has changed
+ then calling this function will disable/enable the correct subscriptions.
+ */
+ // TODO: rename this function.
+ common.switchSubscriptionPolicies = function () {
+ var subscriptions = new UserSubscriptions();
+
+ var newDefaultPolicy = Prefs.isDefaultAllow() ? 'allow' : 'deny';
+ var oldDefaultPolicy = Prefs.isDefaultAllow() ? 'deny' : 'allow';
+
+ var listName, subName, subInfo;
+
+ var oldSubInfo = subscriptions.getSubscriptionInfo(oldDefaultPolicy);
+ for (listName in oldSubInfo) {
+ for (subName in oldSubInfo[listName]) {
+ if (!subName.startsWith("allow_") && subName.startsWith("deny_")) {
+ continue;
+ }
+ subInfo = {};
+ subInfo[listName] = {};
+ subInfo[listName][subName] = true;
+ Services.obs.notifyObservers(null, SUBSCRIPTION_REMOVED_TOPIC,
+ JSON.stringify(subInfo));
}
- var subInfo = {};
- subInfo[listName] = {};
- subInfo[listName][subName] = true;
- Services.obs.notifyObservers(null, SUBSCRIPTION_REMOVED_TOPIC,
- JSON.stringify(subInfo));
}
- }
- var newSubInfo = subscriptions.getSubscriptionInfo(newDefaultPolicy);
- for (var listName in newSubInfo) {
- for (var subName in newSubInfo[listName]) {
- if (subName.indexOf('allow_') != 0 && subName.indexOf('deny_') != 0) {
- continue;
+ var newSubInfo = subscriptions.getSubscriptionInfo(newDefaultPolicy);
+ for (listName in newSubInfo) {
+ for (subName in newSubInfo[listName]) {
+ if (!subName.startsWith("allow_") && !subName.startsWith("deny_")) {
+ continue;
+ }
+ subInfo = {};
+ subInfo[listName] = {};
+ subInfo[listName][subName] = true;
+ Services.obs.notifyObservers(null, SUBSCRIPTION_ADDED_TOPIC,
+ JSON.stringify(subInfo));
}
- var subInfo = {};
- subInfo[listName] = {};
- subInfo[listName][subName] = true;
- Services.obs.notifyObservers(null, SUBSCRIPTION_ADDED_TOPIC,
- JSON.stringify(subInfo));
}
- }
-};
-
-/**
- * Get a string representation of an endpoint (origin or dest) specification.
- *
- * The following list shows a mapping of the possible endpoint specs
- * to the corresponding string representation. Each endpoint spec contains at
- * least one of the parts "scheme", "host" and "port". The list shows the
- * strings by example: scheme "http"; host "www.example.com"; port "80".
- *
- * - s__: `scheme "http"`
- * - _h_: `www.example.com`
- * - __p: `*://*:80`
- * - sh_: `http://www.example.com`
- * - s_p: `http://*:80`
- * - _hp: `*://www.example.com:80`
- * - shp: `http://www.example.com:80`
- *
- * TODO: remove code duplication with menu.js
- */
-common.ruleDataPartToDisplayString = function (ruleDataPart) {
- if (ruleDataPart["s"] && !ruleDataPart["h"] && !ruleDataPart["port"]) {
- // Special case: Only a scheme is specified.
- // The result string will be `scheme "..."`.
- // Background info: The string could be `http:*`, but this could however
- // be confused with `*://http:*`. The string `http://*`
- // wouldn't be correct for all cases, since there are
- // URIs _without_ a host.
- return "scheme \"" + ruleDataPart["s"] + "\"";
- }
- var str = "";
- if (ruleDataPart["s"] || ruleDataPart["port"]) {
- str += ruleDataPart["s"] || "*";
- str += "://";
- }
- str += ruleDataPart["h"] || "*";
- if (ruleDataPart["port"]) {
- str += ":" + ruleDataPart["port"];
- }
- // TODO: path
- return str;
-};
-
-
-
-
-
-
-common.localize = function(stringNames) {
- stringNames.forEach(function(name) {
- $('[data-string="' + name + '"]').each(function () {
- $(this).text($str(name));
+ };
+
+ /**
+ * Get a string representation of an endpoint (origin or dest) specification.
+ *
+ * The following list shows a mapping of the possible endpoint specs
+ * to the corresponding string representation. Each endpoint spec contains at
+ * least one of the parts "scheme", "host" and "port". The list shows the
+ * strings by example: scheme "http"; host "www.example.com"; port "80".
+ *
+ * - s__: `scheme "http"`
+ * - _h_: `www.example.com`
+ * - __p: `*://*:80`
+ * - sh_: `http://www.example.com`
+ * - s_p: `http://*:80`
+ * - _hp: `*://www.example.com:80`
+ * - shp: `http://www.example.com:80`
+ *
+ * TODO: remove code duplication with menu.js
+ */
+ common.ruleDataPartToDisplayString = function (ruleDataPart) {
+ if (ruleDataPart.s && !ruleDataPart.h && !ruleDataPart.port) {
+ // Special case: Only a scheme is specified.
+ // The result string will be `scheme "..."`.
+ // Background info: The string could be `http:*`, but this could however
+ // be confused with `*://http:*`. The string `http://*`
+ // wouldn't be correct for all cases, since there are
+ // URIs _without_ a host.
+ return "scheme \"" + ruleDataPart.s + "\"";
+ }
+ var str = "";
+ if (ruleDataPart.s || ruleDataPart.port) {
+ str += ruleDataPart.s || "*";
+ str += "://";
+ }
+ str += ruleDataPart.h || "*";
+ if (ruleDataPart.port) {
+ str += ":" + ruleDataPart.port;
+ }
+ // TODO: path
+ return str;
+ };
+
+
+
+
+
+
+ common.localize = function(stringNames) {
+ stringNames.forEach(function(name) {
+ $('[data-string="' + name + '"]').each(function () {
+ $(this).text($str(name));
+ });
});
- });
-};
+ };
+
+ $(function() {
+ common.localize(COMMON_STRINGS);
+ });
-$(function() {
- common.localize(COMMON_STRINGS);
-});
+ return {common, WinEnv, elManager, $id, $str};
+}());
diff --git a/src/content/settings/defaultpolicy.html b/src/content/settings/defaultpolicy.html
index a56b541..8c7b74a 100644
--- a/src/content/settings/defaultpolicy.html
+++ b/src/content/settings/defaultpolicy.html
@@ -8,7 +8,7 @@
<link href="chrome://rpcontinued/content/settings/settings.css"
rel="stylesheet" type="text/css"/>
</head>
-<body onload="onload()">
+<body>
<table>
<tr>
<td id="sidepad"></td>
diff --git a/src/content/settings/defaultpolicy.js b/src/content/settings/defaultpolicy.js
index b8c7fdd..423e5d1 100644
--- a/src/content/settings/defaultpolicy.js
+++ b/src/content/settings/defaultpolicy.js
@@ -1,79 +1,93 @@
-var PAGE_STRINGS = [
- 'yourPolicy',
- 'defaultPolicy',
- 'subscriptions',
- 'allowRequestsByDefault',
- 'blockRequestsByDefault',
- 'defaultPolicyDefinition',
- 'learnMore',
- 'allowRequestsToTheSameDomain',
- 'differentSubscriptionsAreAvailable',
- 'manageSubscriptions'
-];
-
-$(function () {
- common.localize(PAGE_STRINGS);
-});
-
-Cu.import("resource://gre/modules/Services.jsm");
-
-
-function updateDisplay() {
- var defaultallow = rpPrefBranch.getBoolPref('defaultPolicy.allow');
- if (defaultallow) {
- $id('defaultallow').checked = true;
- $id('defaultdenysetting').hidden = true;
- } else {
- $id('defaultdeny').checked = true;
- $id('defaultdenysetting').hidden = false;
+/* global window, $, common, WinEnv, elManager, $id */
+
+(function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {rpPrefBranch} = importModule("lib/prefs");
+
+ //============================================================================
+
+ var PAGE_STRINGS = [
+ 'yourPolicy',
+ 'defaultPolicy',
+ 'subscriptions',
+ 'allowRequestsByDefault',
+ 'blockRequestsByDefault',
+ 'defaultPolicyDefinition',
+ 'learnMore',
+ 'allowRequestsToTheSameDomain',
+ 'differentSubscriptionsAreAvailable',
+ 'manageSubscriptions'
+ ];
+
+ $(function () {
+ common.localize(PAGE_STRINGS);
+ });
+
+
+ function updateDisplay() {
+ var defaultallow = rpPrefBranch.getBoolPref('defaultPolicy.allow');
+ if (defaultallow) {
+ $id('defaultallow').checked = true;
+ $id('defaultdenysetting').hidden = true;
+ } else {
+ $id('defaultdeny').checked = true;
+ $id('defaultdenysetting').hidden = false;
+ }
+
+ var allowsamedomain = rpPrefBranch.getBoolPref('defaultPolicy.allowSameDomain');
+ $id('allowsamedomain').checked = allowsamedomain;
+ }
+
+ function showManageSubscriptionsLink() {
+ $id('subscriptionschanged').style.display = 'block';
}
- var allowsamedomain = rpPrefBranch.getBoolPref('defaultPolicy.allowSameDomain');
- $id('allowsamedomain').checked = allowsamedomain;
-}
-
-function showManageSubscriptionsLink() {
- $id('subscriptionschanged').style.display = 'block';
-}
-
-function onload() {
- updateDisplay();
-
- elManager.addListener(
- $id('defaultallow'), 'change',
- function (event) {
- var allow = event.target.checked;
- rpPrefBranch.setBoolPref('defaultPolicy.allow', allow);
- Services.prefs.savePrefFile(null);
- // Reload all subscriptions because it's likely that different
- // subscriptions will now be active.
- common.switchSubscriptionPolicies();
- updateDisplay();
- showManageSubscriptionsLink();
- });
-
- elManager.addListener(
- $id('defaultdeny'), 'change',
- function (event) {
- var deny = event.target.checked;
- rpPrefBranch.setBoolPref('defaultPolicy.allow', !deny);
- Services.prefs.savePrefFile(null);
- // Reload all subscriptions because it's likely that different
- // subscriptions will now be active.
- common.switchSubscriptionPolicies();
- updateDisplay();
- showManageSubscriptionsLink();
- });
-
- elManager.addListener(
- $id('allowsamedomain'), 'change',
- function (event) {
- var allowSameDomain = event.target.checked;
- rpPrefBranch.setBoolPref('defaultPolicy.allowSameDomain',
- allowSameDomain);
- Services.prefs.savePrefFile(null);
- });
-
- // call updateDisplay() every time a preference gets changed
- WinEnv.obMan.observePrefChanges(updateDisplay);
-}
+ window.onload = function () {
+ updateDisplay();
+
+ elManager.addListener(
+ $id('defaultallow'), 'change',
+ function (event) {
+ var allow = event.target.checked;
+ rpPrefBranch.setBoolPref('defaultPolicy.allow', allow);
+ Services.prefs.savePrefFile(null);
+ // Reload all subscriptions because it's likely that different
+ // subscriptions will now be active.
+ common.switchSubscriptionPolicies();
+ updateDisplay();
+ showManageSubscriptionsLink();
+ });
+
+ elManager.addListener(
+ $id('defaultdeny'), 'change',
+ function (event) {
+ var deny = event.target.checked;
+ rpPrefBranch.setBoolPref('defaultPolicy.allow', !deny);
+ Services.prefs.savePrefFile(null);
+ // Reload all subscriptions because it's likely that different
+ // subscriptions will now be active.
+ common.switchSubscriptionPolicies();
+ updateDisplay();
+ showManageSubscriptionsLink();
+ });
+
+ elManager.addListener(
+ $id('allowsamedomain'), 'change',
+ function (event) {
+ var allowSameDomain = event.target.checked;
+ rpPrefBranch.setBoolPref('defaultPolicy.allowSameDomain',
+ allowSameDomain);
+ Services.prefs.savePrefFile(null);
+ });
+
+ // call updateDisplay() every time a preference gets changed
+ WinEnv.obMan.observePrefChanges(updateDisplay);
+ };
+
+}());
diff --git a/src/content/settings/oldrules.html b/src/content/settings/oldrules.html
index 6820106..60e0d77 100644
--- a/src/content/settings/oldrules.html
+++ b/src/content/settings/oldrules.html
@@ -8,7 +8,7 @@
<link href="chrome://rpcontinued/content/settings/settings.css"
rel="stylesheet" type="text/css"/>
</head>
-<body onload="onload()">
+<body>
<table>
<tr>
<td id="sidepad"></td>
diff --git a/src/content/settings/oldrules.js b/src/content/settings/oldrules.js
index 31640d8..de8f319 100644
--- a/src/content/settings/oldrules.js
+++ b/src/content/settings/oldrules.js
@@ -1,102 +1,114 @@
-var PAGE_STRINGS = [
- 'importOldRules',
- 'deleteOldRules',
- 'showOldRuleReimportOptions',
- 'yourOldRulesHaveBeenDeleted',
- 'type',
- 'origin',
- 'destination'
-];
-
-$(function () {
- common.localize(PAGE_STRINGS);
-});
-
-ScriptLoader.importModules([
- "lib/old-rules"
-], this);
-
-var rules = null;
-var addHostWildcard = true;
-
-
-function clearRulesTable() {
- var table = $id('rules');
- var children = table.getElementsByTagName('tr');
- while (children.length) {
- var child = children.item(0);
- child.parentNode.removeChild(child);
+/* global window, $, common, $id, $str */
+
+(function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {Prefs} = importModule("lib/prefs");
+ let {PolicyManager} = importModule("lib/policy-manager");
+ let {OldRules} = importModule("lib/old-rules");
+
+ //============================================================================
+
+ var PAGE_STRINGS = [
+ 'importOldRules',
+ 'deleteOldRules',
+ 'showOldRuleReimportOptions',
+ 'yourOldRulesHaveBeenDeleted',
+ 'type',
+ 'origin',
+ 'destination'
+ ];
+
+ $(function () {
+ common.localize(PAGE_STRINGS);
+ });
+
+ var rules = null;
+ var addHostWildcard = true;
+
+
+ function clearRulesTable() {
+ var table = $id('rules');
+ var children = table.getElementsByTagName('tr');
+ while (children.length) {
+ var child = children.item(0);
+ child.parentNode.removeChild(child);
+ }
}
-}
-function populateRuleTable() {
- var table = $id('rules');
+ function populateRuleTable() {
+ var table = $id('rules');
- let oldRules = new OldRules();
- // Setting the global rules var here.
- rules = oldRules.getAsNewRules(addHostWildcard);
+ let oldRules = new OldRules();
+ // Setting the global rules var here.
+ rules = oldRules.getAsNewRules(addHostWildcard);
- for (var i = 0; i < rules.length; i++) {
- var entry = rules[i];
- var origin = entry['o'] ? common.ruleDataPartToDisplayString(entry['o']) : '';
- var dest = entry['d'] ? common.ruleDataPartToDisplayString(entry['d']) : '';
- addRulesTableRow(table, 'allow', origin, dest, entry);
+ for (var i = 0; i < rules.length; i++) {
+ var entry = rules[i];
+ var origin = entry.o ? common.ruleDataPartToDisplayString(entry.o) : '';
+ var dest = entry.d ? common.ruleDataPartToDisplayString(entry.d) : '';
+ addRulesTableRow(table, 'allow', origin, dest, entry);
+ }
}
-}
-
-function addRulesTableRow(table, ruleAction, origin, dest, ruleData) {
- var actionClass = ruleAction == 'allow' ? 'allow' : 'block';
- var action = ruleAction == 'allow' ? $str('allow') : $str('block');
-
- var row = $('<tr>').addClass(actionClass).appendTo(table);
-
- row.append(
- $('<td>').text(action),
- $('<td>').text(origin),
- $('<td>').text(dest)
- );
-}
-
-function deleteOldRules() {
- Prefs.clearPref('allowedOrigins');
- Prefs.clearPref('allowedDestinations');
- Prefs.clearPref('allowedOriginsToDestinations');
- $("#doimport").hide();
- $("#deletedone").show();
- $("#showReimportOptions").hide();
- $("#reimportOldRules").hide();
- $("#deleteOldRules").hide();
-}
-
-function showReimportOptions() {
- $("#showReimportOptions").hide();
- $("#reimportOldRules").show();
-}
-
-function importOldRules() {
- if (!rules || rules.length == 0) {
- throw 'rules is undefined or empty';
+
+ function addRulesTableRow(table, ruleAction, origin, dest, ruleData) {
+ var actionClass = ruleAction === 'allow' ? 'allow' : 'block';
+ var action = ruleAction === 'allow' ? $str('allow') : $str('block');
+
+ var row = $('<tr>').addClass(actionClass).appendTo(table);
+
+ row.append(
+ $('<td>').text(action),
+ $('<td>').text(origin),
+ $('<td>').text(dest)
+ );
}
- PolicyManager.addAllowRules(rules);
- $("#doimport").hide();
- $("#policy").hide();
- $("#importoptions").hide();
- $("#importdone").show();
-}
-
-function handleAddHostWildcardsChange(event) {
- addHostWildcard = event.target.checked;
- clearRulesTable();
- populateRuleTable();
-}
-
-function onload() {
- var oldRulesExist = Prefs.oldRulesExist();
- if (!oldRulesExist) {
- $("#hasrules").hide();
- $("#norules").show();
- return;
+
+ window.deleteOldRules = function () {
+ Prefs.clearPref('allowedOrigins');
+ Prefs.clearPref('allowedDestinations');
+ Prefs.clearPref('allowedOriginsToDestinations');
+ $("#doimport").hide();
+ $("#deletedone").show();
+ $("#showReimportOptions").hide();
+ $("#reimportOldRules").hide();
+ $("#deleteOldRules").hide();
+ };
+
+ window.showReimportOptions = function () {
+ $("#showReimportOptions").hide();
+ $("#reimportOldRules").show();
+ };
+
+ window.importOldRules = function () {
+ if (!rules || rules.length === 0) {
+ throw 'rules is undefined or empty';
+ }
+ PolicyManager.addAllowRules(rules);
+ $("#doimport").hide();
+ $("#policy").hide();
+ $("#importoptions").hide();
+ $("#importdone").show();
+ };
+
+ function handleAddHostWildcardsChange(event) {
+ addHostWildcard = event.target.checked;
+ clearRulesTable();
+ populateRuleTable();
}
- populateRuleTable();
- $('#addhostwildcards').change(handleAddHostWildcardsChange);
-}
+
+ window.onload = function () {
+ var oldRulesExist = Prefs.oldRulesExist();
+ if (!oldRulesExist) {
+ $("#hasrules").hide();
+ $("#norules").show();
+ return;
+ }
+ populateRuleTable();
+ $('#addhostwildcards').change(handleAddHostWildcardsChange);
+ };
+
+}());
diff --git a/src/content/settings/setup.html b/src/content/settings/setup.html
index 10caac9..9d49fee 100644
--- a/src/content/settings/setup.html
+++ b/src/content/settings/setup.html
@@ -119,7 +119,7 @@
}
</style>
</head>
-<body onload="onload()">
+<body>
<div id="container">
diff --git a/src/content/settings/setup.js b/src/content/settings/setup.js
index 6832b68..7e431cb 100644
--- a/src/content/settings/setup.js
+++ b/src/content/settings/setup.js
@@ -1,170 +1,189 @@
-var PAGE_STRINGS = [
- 'welcomeToRequestPolicy',
- 'forMostUsersDefaultsAreIdeal',
- 'youCanConfigureRequestPolicyToBeMoreStrict',
- 'teachMeHowToUseRequestPolicy',
- 'returnToBrowsing',
- 'configureRequestPolicy',
- 'defaultPolicy',
- 'defaultPolicyDefinition',
- 'allowRequestsByDefault',
- 'blockRequestsByDefault',
- 'allowRequestsToTheSameDomain',
- 'subscriptionPolicies',
- 'subscriptionPoliciesDefinition',
- 'yesUseSubscriptions',
- 'noDoNotUseSubscriptions'
-];
-
-$(function () {
- common.localize(PAGE_STRINGS);
-});
-
-Cu.import("resource://gre/modules/Services.jsm");
-
-ScriptLoader.importModules([
- "lib/old-rules"
-], this);
-
-function showConfigure() {
- $('#welcome').css('display', 'none');
- $('#configure').css('display', 'block');
-}
-
-function handleDefaultPolicyChange() {
- rpPrefBranch.setBoolPref('defaultPolicy.allow',
- $id("defaultallow").checked);
- Services.prefs.savePrefFile(null);
- setAllowSameDomainBlockDisplay();
- handleSubscriptionsChange();
-}
-
-function handleAllowSameDomainChange() {
- rpPrefBranch.setBoolPref('defaultPolicy.allowSameDomain',
- $id("allowsamedomain").checked);
- Services.prefs.savePrefFile(null);
-}
-
-function setAllowSameDomainBlockDisplay() {
- if ($id("defaultallow").checked) {
- $('#allowsamedomainblock').css('display', 'none');
- } else {
- $('#allowsamedomainblock').css('display', 'block');
+/* global window, $, common, $id */
+
+(function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {Info} = importModule("lib/utils/info");
+ let {rpPrefBranch} = importModule("lib/prefs");
+ let {Logger} = importModule("lib/logger");
+ let {PolicyManager} = importModule("lib/policy-manager");
+ let {SUBSCRIPTION_ADDED_TOPIC, SUBSCRIPTION_REMOVED_TOPIC} =
+ importModule("lib/subscription");
+ let {rpService} = importModule("main/requestpolicy-service");
+ let {OldRules} = importModule("lib/old-rules");
+
+ //============================================================================
+
+ var PAGE_STRINGS = [
+ 'welcomeToRequestPolicy',
+ 'forMostUsersDefaultsAreIdeal',
+ 'youCanConfigureRequestPolicyToBeMoreStrict',
+ 'teachMeHowToUseRequestPolicy',
+ 'returnToBrowsing',
+ 'configureRequestPolicy',
+ 'defaultPolicy',
+ 'defaultPolicyDefinition',
+ 'allowRequestsByDefault',
+ 'blockRequestsByDefault',
+ 'allowRequestsToTheSameDomain',
+ 'subscriptionPolicies',
+ 'subscriptionPoliciesDefinition',
+ 'yesUseSubscriptions',
+ 'noDoNotUseSubscriptions'
+ ];
+
+ $(function () {
+ common.localize(PAGE_STRINGS);
+ });
+
+ function showConfigure() {
+ $('#welcome').css('display', 'none');
+ $('#configure').css('display', 'block');
}
-}
-
-function handleSubscriptionsChange() {
- var enableSubs = $id("enablesubs").checked;
- var enableAllowSubs = enableSubs && $id("defaultdeny").checked;
- var enableDenySubs = enableSubs && $id("defaultallow").checked;
- var subs = {
- 'allow_embedded':{},
- 'allow_extensions':{},
- 'allow_functionality':{},
- 'allow_mozilla':{},
- 'allow_sameorg':{},
- 'deny_trackers':{}
- };
- var userSubs = rpService.getSubscriptions();
- for (var subName in subs) {
- var subInfo = {};
- subInfo['official'] = {};
- subInfo['official'][subName] = true;
- if (enableAllowSubs && subName.indexOf('allow_') == 0 ||
- enableDenySubs && subName.indexOf('deny_') == 0) {
- userSubs.addSubscription('official', subName);
- Services.obs.notifyObservers(null, SUBSCRIPTION_ADDED_TOPIC,
- JSON.stringify(subInfo));
- } else {
- userSubs.removeSubscription('official', subName);
- Services.obs.notifyObservers(null, SUBSCRIPTION_REMOVED_TOPIC,
- JSON.stringify(subInfo));
- }
- }
-}
-/*
-function getArguments(args) {
- let urlQuery = document.location.search || "";
- if (urlQuery.length > 1) {
- urlQuery = decodeURIComponent(urlQuery.substr(1));
+ function handleDefaultPolicyChange() {
+ rpPrefBranch.setBoolPref('defaultPolicy.allow',
+ $id("defaultallow").checked);
+ Services.prefs.savePrefFile(null);
+ setAllowSameDomainBlockDisplay();
+ handleSubscriptionsChange();
}
- let queryArgs = split("&");
- for (let i in queryArgs) {
- let tmp = queryArgs.split("=");
- if (args.hasOwnProperty(tmp)) {
- args[tmp[0]] = tmp[1];
- }
+
+ function handleAllowSameDomainChange() {
+ rpPrefBranch.setBoolPref('defaultPolicy.allowSameDomain',
+ $id("allowsamedomain").checked);
+ Services.prefs.savePrefFile(null);
}
- return args;
-}*/
-
-function onload() {
- // To retrieve the last RP version, `Info` needs to be used,
- // because the pref "extensions.requestpolicy.lastVersion" has
- // already been updated.
- var lastRPVersion = Info.lastRPVersion;
-
- // Populate the form values based on the user's current settings.
- // If the use has just upgrade from an 0.x version, populate based on the old
- // preferences and also do a rule import based on the old strictness settings.
- // Note: using version 1.0.0a8 instead of 1.0 as that was the last version
- // before this setup window was added.
- if (lastRPVersion &&
- Services.vc.compare(lastRPVersion, '0.0') > 0 &&
- Services.vc.compare(lastRPVersion, '1.0.0a8') <= 0) {
- if (rpPrefBranch.prefHasUserValue('uriIdentificationLevel')) {
- var identLevel = rpPrefBranch.getIntPref('uriIdentificationLevel');
+
+ function setAllowSameDomainBlockDisplay() {
+ if ($id("defaultallow").checked) {
+ $('#allowsamedomainblock').css('display', 'none');
} else {
- var identLevel = 1;
+ $('#allowsamedomainblock').css('display', 'block');
}
+ }
- $id("defaultdeny").checked = true;
- handleDefaultPolicyChange();
-
- $id("allowsamedomain").checked = identLevel == 1;
- handleAllowSameDomainChange();
+ function handleSubscriptionsChange() {
+ var enableSubs = $id("enablesubs").checked;
+ var enableAllowSubs = enableSubs && $id("defaultdeny").checked;
+ var enableDenySubs = enableSubs && $id("defaultallow").checked;
+ var subs = {
+ 'allow_embedded':{},
+ 'allow_extensions':{},
+ 'allow_functionality':{},
+ 'allow_mozilla':{},
+ 'allow_sameorg':{},
+ 'deny_trackers':{}
+ };
+ var userSubs = rpService.getSubscriptions();
+ for (var subName in subs) {
+ var subInfo = {};
+ subInfo.official = {};
+ subInfo.official[subName] = true;
+ if (enableAllowSubs && subName.startsWith('allow_') ||
+ enableDenySubs && subName.startsWith('deny_')) {
+ userSubs.addSubscription('official', subName);
+ Services.obs.notifyObservers(null, SUBSCRIPTION_ADDED_TOPIC,
+ JSON.stringify(subInfo));
+ } else {
+ userSubs.removeSubscription('official', subName);
+ Services.obs.notifyObservers(null, SUBSCRIPTION_REMOVED_TOPIC,
+ JSON.stringify(subInfo));
+ }
+ }
+ }
- // If the user doesn't have any new-style rules, automatically do an import
- // of the old rules. We check for new-style rules just in case the user has
- // opened the setup window again after initial upgrade.
- try {
- var ruleCount = PolicyManager.getUserRuleCount();
- } catch (e) {
- Logger.warning(Logger.TYPE_INTERNAL, 'Unable to get new rule count: ' + e);
- ruleCount = -1;
+ /*
+ function getArguments(args) {
+ let urlQuery = document.location.search || "";
+ if (urlQuery.length > 1) {
+ urlQuery = decodeURIComponent(urlQuery.substr(1));
}
- Logger.dump('Rule count: ' + ruleCount);
- if (ruleCount <= 0) {
- Logger.dump('Performing rule import.');
- let addHostWildcard = identLevel == 1;
- let oldRules = new OldRules();
- let rules = oldRules.getAsNewRules(addHostWildcard);
- PolicyManager.addAllowRules(rules);
+ let queryArgs = split("&");
+ for (let i in queryArgs) {
+ let tmp = queryArgs.split("=");
+ if (args.hasOwnProperty(tmp)) {
+ args[tmp[0]] = tmp[1];
+ }
}
+ return args;
+ }*/
+
+ window.onload = function () {
+ // To retrieve the last RP version, `Info` needs to be used,
+ // because the pref "extensions.requestpolicy.lastVersion" has
+ // already been updated.
+ var lastRPVersion = Info.lastRPVersion;
+
+ // Populate the form values based on the user's current settings.
+ // If the use has just upgrade from an 0.x version, populate based on the old
+ // preferences and also do a rule import based on the old strictness settings.
+ // Note: using version 1.0.0a8 instead of 1.0 as that was the last version
+ // before this setup window was added.
+ if (lastRPVersion &&
+ Services.vc.compare(lastRPVersion, '0.0') > 0 &&
+ Services.vc.compare(lastRPVersion, '1.0.0a8') <= 0) {
+ var identLevel;
+ if (rpPrefBranch.prefHasUserValue('uriIdentificationLevel')) {
+ identLevel = rpPrefBranch.getIntPref('uriIdentificationLevel');
+ } else {
+ identLevel = 1;
+ }
+
+ $id("defaultdeny").checked = true;
+ handleDefaultPolicyChange();
+
+ $id("allowsamedomain").checked = identLevel === 1;
+ handleAllowSameDomainChange();
+
+ // If the user doesn't have any new-style rules, automatically do an import
+ // of the old rules. We check for new-style rules just in case the user has
+ // opened the setup window again after initial upgrade.
+ var ruleCount;
+ try {
+ ruleCount = PolicyManager.getUserRuleCount();
+ } catch (e) {
+ Logger.warning(Logger.TYPE_INTERNAL, 'Unable to get new rule count: ' + e);
+ ruleCount = -1;
+ }
+ Logger.dump('Rule count: ' + ruleCount);
+ if (ruleCount <= 0) {
+ Logger.dump('Performing rule import.');
+ let addHostWildcard = identLevel === 1;
+ let oldRules = new OldRules();
+ let rules = oldRules.getAsNewRules(addHostWildcard);
+ PolicyManager.addAllowRules(rules);
+ }
+
+ // Skip the welcome screen.
+ showConfigure();
- // Skip the welcome screen.
- showConfigure();
-
- } else {
- var defaultAllow = rpPrefBranch.getBoolPref('defaultPolicy.allow');
- $id("defaultallow").checked = !!defaultAllow;
- $id("defaultdeny").checked = !defaultAllow;
- if (!defaultAllow) {
- $('#allowsamedomainblock').css('display', 'block');
+ } else {
+ var defaultAllow = rpPrefBranch.getBoolPref('defaultPolicy.allow');
+ $id("defaultallow").checked = !!defaultAllow;
+ $id("defaultdeny").checked = !defaultAllow;
+ if (!defaultAllow) {
+ $('#allowsamedomainblock').css('display', 'block');
+ }
+
+ $id("allowsamedomain").checked =
+ rpPrefBranch.getBoolPref('defaultPolicy.allowSameDomain');
+ // Subscriptions are only simple here if we assume the user won't open the
+ // setup window again after changing their individual subscriptions through
+ // the preferences. So, let's assume that as the worst case is that the setup
+ // page shows such a setup-page-revisiting user the subscriptions as being
+ // enabled when they really aren't.
}
- $id("allowsamedomain").checked =
- rpPrefBranch.getBoolPref('defaultPolicy.allowSameDomain');
- // Subscriptions are only simple here if we assume the user won't open the
- // setup window again after changing their individual subscriptions through
- // the preferences. So, let's assume that as the worst case is that the setup
- // page shows such a setup-page-revisiting user the subscriptions as being
- // enabled when they really aren't.
- }
+ $('#showconfigure').click(showConfigure);
+ $('input[name=defaultpolicy]').change(handleDefaultPolicyChange);
+ $('input[name=subscriptions]').change(handleSubscriptionsChange);
+ $('#allowsamedomain').change(handleAllowSameDomainChange);
+ };
- $('#showconfigure').click(showConfigure);
- $('input[name=defaultpolicy]').change(handleDefaultPolicyChange);
- $('input[name=subscriptions]').change(handleSubscriptionsChange);
- $('#allowsamedomain').change(handleAllowSameDomainChange);
-}
+}());
diff --git a/src/content/settings/subscriptions.html b/src/content/settings/subscriptions.html
index a18ad8a..9d3a75a 100644
--- a/src/content/settings/subscriptions.html
+++ b/src/content/settings/subscriptions.html
@@ -10,7 +10,7 @@
<style>
</style>
</head>
-<body onload="onload()">
+<body>
<table>
<tr>
<td id="sidepad"></td>
diff --git a/src/content/settings/subscriptions.js b/src/content/settings/subscriptions.js
index d6d873c..c509bd2 100644
--- a/src/content/settings/subscriptions.js
+++ b/src/content/settings/subscriptions.js
@@ -1,140 +1,163 @@
-var PAGE_STRINGS = [
- 'yourPolicy',
- 'defaultPolicy',
- 'subscriptions',
- 'subscriptionPolicies',
- 'subscriptionPoliciesDefinition',
- 'learnMoreAboutSubscriptions',
- 'usability',
- 'privacy',
- 'browser',
- 'subscriptionDenyTrackersDescription',
- 'subscriptionAllowSameOrgDescription',
- 'subscriptionAllowFunctionalityDescription',
- 'subscriptionAllowEmbeddedDescription',
- 'subscriptionAllowMozillaDescription',
- 'subscriptionAllowExtensionsDescription'
-];
-
-$(function () {
- common.localize(PAGE_STRINGS);
-});
-
-/**
- * @param {String} policy
- * "allow" or "deny"
- */
-function getDefaultPolicyElements(policy) {
- var selector = '[data-defaultpolicy=' + policy + ']';
- var matches = document.body.querySelectorAll(selector);
- var elements = Array.prototype.slice.call(matches);
- return elements;
-}
-
-function displayDefaultPolicyElements(policy, display) {
- // note: display could be undefined.
- display = display === false ? false : true;
- var elements = getDefaultPolicyElements(policy);
- for (var i = 0, len = elements.length; i < len; i++) {
- if (display) {
- elements[i].removeAttribute("style");
- } else {
- elements[i].style.display = 'none';
- }
- }
-}
+/* global window, document, $, common, WinEnv, elManager */
-function getInputElement(subName) {
- var elements = document.body.querySelectorAll('input[name=' + subName + ']');
- if (elements.length <= 0) {
- return null;
- }
- return elements[0];
-}
-
-function getAllSubscriptionElements() {
- var divs = document.getElementsByClassName("subscription");
- var elements = [];
- for (var i = 0, len = divs.length; i < len; ++i) {
- var div = divs[i];
- elements.push({
- id: div.id,
- div: div,
- input: getInputElement(div.id)});
+(function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {Prefs} = importModule("lib/prefs");
+ let {Logger} = importModule("lib/logger");
+ let {SUBSCRIPTION_ADDED_TOPIC, SUBSCRIPTION_REMOVED_TOPIC} =
+ importModule("lib/subscription");
+ let {rpService} = importModule("main/requestpolicy-service");
+
+ //============================================================================
+
+ var PAGE_STRINGS = [
+ 'yourPolicy',
+ 'defaultPolicy',
+ 'subscriptions',
+ 'subscriptionPolicies',
+ 'subscriptionPoliciesDefinition',
+ 'learnMoreAboutSubscriptions',
+ 'usability',
+ 'privacy',
+ 'browser',
+ 'subscriptionDenyTrackersDescription',
+ 'subscriptionAllowSameOrgDescription',
+ 'subscriptionAllowFunctionalityDescription',
+ 'subscriptionAllowEmbeddedDescription',
+ 'subscriptionAllowMozillaDescription',
+ 'subscriptionAllowExtensionsDescription'
+ ];
+
+ $(function () {
+ common.localize(PAGE_STRINGS);
+ });
+
+ /**
+ * @param {String} policy
+ * "allow" or "deny"
+ */
+ function getDefaultPolicyElements(policy) {
+ var selector = '[data-defaultpolicy=' + policy + ']';
+ var matches = document.body.querySelectorAll(selector);
+ var elements = Array.prototype.slice.call(matches);
+ return elements;
}
- return elements;
-}
-
-function updateDisplay() {
- var userSubs = rpService.getSubscriptions();
- var subsInfo = userSubs.getSubscriptionInfo();
- var allSubElements = getAllSubscriptionElements();
- for (var i = 0, len = allSubElements.length; i < len; ++i) {
- var element = allSubElements[i];
- element.input.checked = (element.id in subsInfo['official']);
+
+ function displayDefaultPolicyElements(policy, display) {
+ // note: display could be undefined.
+ display = display === false ? false : true;
+ var elements = getDefaultPolicyElements(policy);
+ for (var i = 0, len = elements.length; i < len; i++) {
+ if (display) {
+ elements[i].removeAttribute("style");
+ } else {
+ elements[i].style.display = 'none';
+ }
+ }
}
- if (Prefs.isDefaultAllow()) {
- var currentPolicy = 'allow', otherPolicy = 'deny';
- } else {
- var currentPolicy = 'deny', otherPolicy = 'allow';
+ function getInputElement(subName) {
+ var elements = document.body.querySelectorAll('input[name=' + subName + ']');
+ if (elements.length <= 0) {
+ return null;
+ }
+ return elements[0];
}
- displayDefaultPolicyElements(currentPolicy, true);
- displayDefaultPolicyElements(otherPolicy, false);
-}
-
-
-
-function handleSubscriptionCheckboxChange(event) {
- var userSubs = rpService.getSubscriptions();
-
- var subName = event.target.name;
- var enabled = event.target.checked;
- var subInfo = {};
- subInfo['official'] = {};
- subInfo['official'][subName] = true;
- if (enabled) {
- userSubs.addSubscription('official', subName);
- Services.obs.notifyObservers(null, SUBSCRIPTION_ADDED_TOPIC,
- JSON.stringify(subInfo));
- } else {
- userSubs.removeSubscription('official', subName);
- Services.obs.notifyObservers(null, SUBSCRIPTION_REMOVED_TOPIC,
- JSON.stringify(subInfo));
+
+ function getAllSubscriptionElements() {
+ var divs = document.getElementsByClassName("subscription");
+ var elements = [];
+ for (var i = 0, len = divs.length; i < len; ++i) {
+ var div = divs[i];
+ elements.push({
+ id: div.id,
+ div: div,
+ input: getInputElement(div.id)});
+ }
+ return elements;
}
-}
-
-function onload() {
- updateDisplay();
-
- var available = {
- 'allow_embedded' : {},
- 'allow_extensions' : {},
- 'allow_functionality' : {},
- 'allow_mozilla' : {},
- 'allow_sameorg' : {},
- 'deny_trackers' : {}
- };
- for (var subName in available) {
- var el = getInputElement(subName);
- if (!el) {
- Logger.dump('Skipping unexpected official subName: ' + subName);
- continue;
+
+ function updateDisplay() {
+ var userSubs = rpService.getSubscriptions();
+ var subsInfo = userSubs.getSubscriptionInfo();
+ var allSubElements = getAllSubscriptionElements();
+ for (var i = 0, len = allSubElements.length; i < len; ++i) {
+ var element = allSubElements[i];
+ element.input.checked = element.id in subsInfo.official;
+ }
+
+ var currentPolicy, otherPolicy;
+ if (Prefs.isDefaultAllow()) {
+ currentPolicy = 'allow';
+ otherPolicy = 'deny';
+ } else {
+ currentPolicy = 'deny';
+ otherPolicy = 'allow';
}
- elManager.addListener(el, 'change', handleSubscriptionCheckboxChange);
+ displayDefaultPolicyElements(currentPolicy, true);
+ displayDefaultPolicyElements(otherPolicy, false);
}
- var selector = '[data-defaultpolicy=' +
- (Prefs.isDefaultAllow() ? 'deny' : 'allow') + ']';
- var matches = document.body.querySelectorAll(selector);
- var hideElements = Array.prototype.slice.call(matches);
- for (var i = 0; i < hideElements.length; i++) {
- hideElements[i].style.display = 'none';
+
+
+ function handleSubscriptionCheckboxChange(event) {
+ var userSubs = rpService.getSubscriptions();
+
+ var subName = event.target.name;
+ var enabled = event.target.checked;
+ var subInfo = {};
+ subInfo.official = {};
+ subInfo.official[subName] = true;
+ if (enabled) {
+ userSubs.addSubscription('official', subName);
+ Services.obs.notifyObservers(null, SUBSCRIPTION_ADDED_TOPIC,
+ JSON.stringify(subInfo));
+ } else {
+ userSubs.removeSubscription('official', subName);
+ Services.obs.notifyObservers(null, SUBSCRIPTION_REMOVED_TOPIC,
+ JSON.stringify(subInfo));
+ }
}
- // call updateDisplay() every time a subscription is added or removed
- WinEnv.obMan.observe([
- SUBSCRIPTION_ADDED_TOPIC,
- SUBSCRIPTION_REMOVED_TOPIC
- ], updateDisplay);
-}
+ window.onload = function () {
+ updateDisplay();
+
+ var available = {
+ 'allow_embedded' : {},
+ 'allow_extensions' : {},
+ 'allow_functionality' : {},
+ 'allow_mozilla' : {},
+ 'allow_sameorg' : {},
+ 'deny_trackers' : {}
+ };
+ for (var subName in available) {
+ var el = getInputElement(subName);
+ if (!el) {
+ Logger.dump('Skipping unexpected official subName: ' + subName);
+ continue;
+ }
+ elManager.addListener(el, 'change', handleSubscriptionCheckboxChange);
+ }
+
+ var selector = '[data-defaultpolicy=' +
+ (Prefs.isDefaultAllow() ? 'deny' : 'allow') + ']';
+ var matches = document.body.querySelectorAll(selector);
+ var hideElements = Array.prototype.slice.call(matches);
+ for (var i = 0; i < hideElements.length; i++) {
+ hideElements[i].style.display = 'none';
+ }
+
+ // call updateDisplay() every time a subscription is added or removed
+ WinEnv.obMan.observe([
+ SUBSCRIPTION_ADDED_TOPIC,
+ SUBSCRIPTION_REMOVED_TOPIC
+ ], updateDisplay);
+ };
+
+}());
diff --git a/src/content/settings/yourpolicy.html b/src/content/settings/yourpolicy.html
index b9a6fdc..e03f1c0 100644
--- a/src/content/settings/yourpolicy.html
+++ b/src/content/settings/yourpolicy.html
@@ -8,7 +8,7 @@
<link href="chrome://rpcontinued/content/settings/settings.css"
rel="stylesheet" type="text/css"/>
</head>
-<body onload="onload()">
+<body>
<table>
<tr>
<td id="sidepad"></td>
diff --git a/src/content/settings/yourpolicy.js b/src/content/settings/yourpolicy.js
index 810e3a8..ca18dd0 100644
--- a/src/content/settings/yourpolicy.js
+++ b/src/content/settings/yourpolicy.js
@@ -1,223 +1,245 @@
-var PAGE_STRINGS = [
- 'yourPolicy',
- 'defaultPolicy',
- 'subscriptions',
- 'type',
- 'origin',
- 'destination',
- 'allow',
- 'block',
- 'temporary',
- 'addRule',
- 'learnMoreAboutRules',
- 'removeOldRules',
- 'ruleSet',
- 'filterRules',
- 'policy'
-];
-
-$(function () {
- common.localize(PAGE_STRINGS);
- // l10n for input placeholders.
- $id("rulesearch").placeholder = $str('search');
- $('[name=originscheme]').prop('placeholder', $str('scheme'));
- $('[name=destscheme]').prop('placeholder', $str('scheme'));
- $('[name=originhost]').prop('placeholder', $str('host'));
- $('[name=desthost]').prop('placeholder', $str('host'));
- $('[name=originport]').prop('placeholder', $str('port'));
- $('[name=destport]').prop('placeholder', $str('port'));
-});
-
-const SEARCH_DELAY = 100;
-
-var searchTimeoutId = null;
-
-function populateRuleTable(filter) {
- searchTimeoutId = null;
-
- var table = $id('rules');
-
- clearRulesTable(table);
-
- // Get and display user rules
- var user = PolicyManager.getUserRulesets()['user'];
- var entries = user.rawRuleset.toJSON()['entries'];
- addRules(entries, 'User', filter, false);
-
- // Get and display temorary rules
- var temp = PolicyManager.getUserRulesets()['temp'];
- var entries = temp.rawRuleset.toJSON()['entries'];
- addRules(entries, 'Temporary', filter, false);
-
- // Get and display subscription rules
- var subscriptionLists = PolicyManager.getSubscriptionRulesets();
- for (subscriptionList in subscriptionLists) {
- for (subscription in subscriptionLists[subscriptionList]) {
- entries = subscriptionLists[subscriptionList][subscription].rawRuleset.toJSON()['entries'];
- addRules(entries, subscription, filter, true);
+/* global window, document, $, common, WinEnv, elManager, $id, $str */
+
+(function () {
+ /* global Components */
+ const {utils: Cu} = Components;
+
+ let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+ let {Prefs} = importModule("lib/prefs");
+ let {PolicyManager} = importModule("lib/policy-manager");
+
+ //============================================================================
+
+ var PAGE_STRINGS = [
+ 'yourPolicy',
+ 'defaultPolicy',
+ 'subscriptions',
+ 'type',
+ 'origin',
+ 'destination',
+ 'allow',
+ 'block',
+ 'temporary',
+ 'addRule',
+ 'learnMoreAboutRules',
+ 'removeOldRules',
+ 'ruleSet',
+ 'filterRules',
+ 'policy'
+ ];
+
+ $(function () {
+ common.localize(PAGE_STRINGS);
+ // l10n for input placeholders.
+ $id("rulesearch").placeholder = $str('search');
+ $('[name=originscheme]').prop('placeholder', $str('scheme'));
+ $('[name=destscheme]').prop('placeholder', $str('scheme'));
+ $('[name=originhost]').prop('placeholder', $str('host'));
+ $('[name=desthost]').prop('placeholder', $str('host'));
+ $('[name=originport]').prop('placeholder', $str('port'));
+ $('[name=destport]').prop('placeholder', $str('port'));
+ });
+
+ const SEARCH_DELAY = 100;
+
+ var searchTimeoutId = null;
+
+ function populateRuleTable(filter) {
+ searchTimeoutId = null;
+
+ var table = $id('rules');
+
+ clearRulesTable(table);
+
+ var entries;
+
+ // Get and display user rules
+ var user = PolicyManager.getUserRulesets().user;
+ entries = user.rawRuleset.toJSON().entries;
+ addRules(entries, 'User', filter, false);
+
+ // Get and display temorary rules
+ var temp = PolicyManager.getUserRulesets().temp;
+ entries = temp.rawRuleset.toJSON().entries;
+ addRules(entries, 'Temporary', filter, false);
+
+ // Get and display subscription rules
+ var subscriptionLists = PolicyManager.getSubscriptionRulesets();
+ for (var subscriptionList in subscriptionLists) {
+ for (var subscription in subscriptionLists[subscriptionList]) {
+ entries = subscriptionLists[subscriptionList][subscription].rawRuleset.
+ toJSON().entries;
+ addRules(entries, subscription, filter, true);
+ }
}
}
-}
-
-function addRules(entries, source, filter, readOnly) {
- var table = $('#rules');
- for (var entryType in entries) {
- for (var i = 0; i < entries[entryType].length; i++) {
- var entry = entries[entryType][i];
- var origin = entry['o'] ? common.ruleDataPartToDisplayString(entry['o']) : '';
- var dest = entry['d'] ? common.ruleDataPartToDisplayString(entry['d']) : '';
- if (filter) {
- if (origin.indexOf(filter) == -1 && dest.indexOf(filter) == -1) {
- continue;
+ function addRules(entries, source, filter, readOnly) {
+ var table = $('#rules');
+ for (var entryType in entries) {
+ for (var i = 0; i < entries[entryType].length; i++) {
+ var entry = entries[entryType][i];
+ var origin = entry.o ? common.ruleDataPartToDisplayString(entry.o) : '';
+ var dest = entry.d ? common.ruleDataPartToDisplayString(entry.d) : '';
+ if (filter) {
+ if (origin.indexOf(filter) === -1 && dest.indexOf(filter) === -1) {
+ continue;
+ }
}
+ addRulesTableRow(table, entryType, origin, dest, entry, source,
+ readOnly);
}
- addRulesTableRow(table, entryType, origin, dest, entry, source, readOnly);
}
}
-}
-
-function deleteRule(event) {
- // TODO: the rule should not be referenced by the rule data but by some
- // unique identifier. Currently, if there's exactly the same rule twice,
- // (one of them might be a temporary rule), both will get removed.
- var anchor = $(event.target);
- var ruleAction = anchor.data('requestpolicyRuleAction');
- var ruleData = anchor.data('requestpolicyRuleData');
- if (ruleAction == 'allow') {
- PolicyManager.removeAllowRule(ruleData);
- } else {
- PolicyManager.removeDenyRule(ruleData);
+
+ function deleteRule(event) {
+ // TODO: the rule should not be referenced by the rule data but
+ // by some unique identifier. Currently, if there's exactly
+ // the same rule twice, (one of them might be a temporary
+ // rule), both will get removed.
+ var anchor = $(event.target);
+ var ruleAction = anchor.data('requestpolicyRuleAction');
+ var ruleData = anchor.data('requestpolicyRuleData');
+ if (ruleAction === 'allow') {
+ PolicyManager.removeAllowRule(ruleData);
+ } else {
+ PolicyManager.removeDenyRule(ruleData);
+ }
+ anchor.closest('tr').remove();
}
- anchor.closest('tr').remove();
-}
-
-function clearRulesTable(table) {
- var children = table.getElementsByTagName('tr');
- while (children.length) {
- var child = children.item(0);
- child.parentNode.removeChild(child);
+
+ function clearRulesTable(table) {
+ var children = table.getElementsByTagName('tr');
+ while (children.length) {
+ var child = children.item(0);
+ child.parentNode.removeChild(child);
+ }
}
-}
-function addRulesTableRow(table, ruleAction, origin, dest, ruleData, source, readOnly) {
+ function addRulesTableRow(table, ruleAction, origin, dest, ruleData, source,
+ readOnly) {
- if (ruleAction != 'allow') {
- ruleAction = 'block';
- }
- ruleAction = ruleAction == 'allow' ? 'allow' : 'block';
- var ruleActionString = ruleAction == 'allow' ? $str('allow') : $str('block');
-
- var row = $('<tr>').addClass(ruleAction).appendTo(table);
-
- row.append(
- $('<td>').text(ruleActionString),
- $('<td>').text(origin),
- $('<td>').text(dest),
- $('<td>').text(source)
- );
-
- if (!readOnly) {
- var anchor = $('<a>');
- anchor.text('x').addClass('deleterule');
- anchor.data('requestpolicyRuleAction', ruleAction);
- anchor.data('requestpolicyRuleData', ruleData);
- anchor.click(deleteRule);
- row.append($('<td>').append(anchor));
- } else {
- row.append($('<td>'));
- }
-}
-
-function addRule() {
- try {
- addRuleHelper();
- } catch (e) {
- alert('Unable to add rule: ' + e.toString());
- return;
+ if (ruleAction !== 'allow') {
+ ruleAction = 'block';
+ }
+ ruleAction = ruleAction === 'allow' ? 'allow' : 'block';
+ var ruleActionString = ruleAction === 'allow' ? $str('allow') :
+ $str('block');
+
+ var row = $('<tr>').addClass(ruleAction).appendTo(table);
+
+ row.append(
+ $('<td>').text(ruleActionString),
+ $('<td>').text(origin),
+ $('<td>').text(dest),
+ $('<td>').text(source)
+ );
+
+ if (!readOnly) {
+ var anchor = $('<a>');
+ anchor.text('x').addClass('deleterule');
+ anchor.data('requestpolicyRuleAction', ruleAction);
+ anchor.data('requestpolicyRuleData', ruleData);
+ anchor.click(deleteRule);
+ row.append($('<td>').append(anchor));
+ } else {
+ row.append($('<td>'));
+ }
}
- var search = $id('rulesearch');
-
- // the table is repopulated through the RulesChangedObserver
-}
-
-function addRuleHelper() {
- var form = document.forms['addruleform'];
- var allow = form.elements['allowrule'].checked ? true : false;
- var temporary = form.elements['temporary'].checked ? true : false;
- var originScheme = form.elements['originscheme'].value;
- var originHost = form.elements['originhost'].value;
- var originPort = form.elements['originport'].value;
- var destScheme = form.elements['destscheme'].value;
- var destHost = form.elements['desthost'].value;
- var destPort = form.elements['destport'].value;
- // TODO: we either need to sanity check the ruleData here or the policy needs
- // to do this when it is added. Probably better to do it in the policy code.
- function ruleInfoToRuleDataPart(scheme, host, port) {
- if (!scheme && !host && !port) {
- return null;
+
+ window.addRule = function () {
+ try {
+ addRuleHelper();
+ } catch (e) {
+ window.alert('Unable to add rule: ' + e.toString());
+ return;
}
- var part = {};
- if (scheme) {
- part['s'] = scheme;
+
+ // the table is repopulated through the RulesChangedObserver
+ };
+
+ function addRuleHelper() {
+ var form = document.forms.addruleform;
+ var allow = form.elements.allowrule.checked ? true : false;
+ var temporary = form.elements.temporary.checked ? true : false;
+ var originScheme = form.elements.originscheme.value;
+ var originHost = form.elements.originhost.value;
+ var originPort = form.elements.originport.value;
+ var destScheme = form.elements.destscheme.value;
+ var destHost = form.elements.desthost.value;
+ var destPort = form.elements.destport.value;
+ // TODO: we either need to sanity check the ruleData here
+ // or the policy needs to do this when it is added.
+ // Probably better to do it in the policy code.
+ function ruleInfoToRuleDataPart(scheme, host, port) {
+ if (!scheme && !host && !port) {
+ return null;
+ }
+ var part = {};
+ if (scheme) {
+ part.s = scheme;
+ }
+ if (host) {
+ part.h = host;
+ }
+ if (port) {
+ part.port = port;
+ }
+ return part;
}
- if (host) {
- part['h'] = host;
+ var originPart = ruleInfoToRuleDataPart(originScheme, originHost,
+ originPort);
+ var destPart = ruleInfoToRuleDataPart(destScheme, destHost, destPort);
+ if (!originPart && !destPart) {
+ // TODO: don't throw, instead show message in form.
+ throw 'You must specify some rule information';
}
- if (port) {
- part['port'] = port;
+ var ruleData = {};
+ if (originPart) {
+ ruleData.o = originPart;
}
- return part;
- }
- var originPart = ruleInfoToRuleDataPart(originScheme, originHost, originPort);
- var destPart = ruleInfoToRuleDataPart(destScheme, destHost, destPort);
- if (!originPart && !destPart) {
- // TODO: don't throw, instead show message in form.
- throw 'You must specify some rule information';
- }
- var ruleData = {};
- if (originPart) {
- ruleData['o'] = originPart;
- }
- if (destPart) {
- ruleData['d'] = destPart;
- }
- if (allow) {
- if (temporary) {
- PolicyManager.addTemporaryAllowRule(ruleData);
- } else {
- PolicyManager.addAllowRule(ruleData);
+ if (destPart) {
+ ruleData.d = destPart;
}
- } else {
- if (temporary) {
- PolicyManager.addTemporaryDenyRule(ruleData);
+ if (allow) {
+ if (temporary) {
+ PolicyManager.addTemporaryAllowRule(ruleData);
+ } else {
+ PolicyManager.addAllowRule(ruleData);
+ }
} else {
- PolicyManager.addDenyRule(ruleData);
+ if (temporary) {
+ PolicyManager.addTemporaryDenyRule(ruleData);
+ } else {
+ PolicyManager.addDenyRule(ruleData);
+ }
}
}
-}
-
-function onload() {
- var search = $id('rulesearch');
- elManager.addListener(search, 'keyup', function (event) {
- if (searchTimeoutId != null) {
- clearTimeout(searchTimeoutId);
- }
- searchTimeoutId = setTimeout(function () {
- populateRuleTable(event.target.value)
- }, SEARCH_DELAY);
- }, false);
- populateRuleTable(search.value);
- if (Prefs.oldRulesExist()) {
- $("#oldrulesexist").show();
- }
- // observe rule changes and update the table then
- WinEnv.obMan.observe(["rpcontinued-rules-changed"], function() {
+ window.onload = function () {
var search = $id('rulesearch');
+ elManager.addListener(search, 'keyup', function (event) {
+ if (searchTimeoutId !== null) {
+ window.clearTimeout(searchTimeoutId);
+ }
+ searchTimeoutId = window.setTimeout(function () {
+ populateRuleTable(event.target.value);
+ }, SEARCH_DELAY);
+ }, false);
populateRuleTable(search.value);
- });
-}
+ if (Prefs.oldRulesExist()) {
+ $("#oldrulesexist").show();
+ }
+
+ // observe rule changes and update the table then
+ WinEnv.obMan.observe(["rpcontinued-rules-changed"], function() {
+ var search = $id('rulesearch');
+ populateRuleTable(search.value);
+ });
+ };
+
+}());
--
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