aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--background.html1
-rw-r--r--js/vapi-background.js41
-rw-r--r--js/vapi-net.js78
4 files changed, 80 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index 419afcd..8aaab0a 100644
--- a/Makefile
+++ b/Makefile
@@ -125,7 +125,7 @@ JS3 := js/tab.js js/traffic.js js/udom.js js/uritools.js js/user-rules.js \
JS4 := js/vapi-client.js js/vapi-common.js js/vapi-background.js \
js/vapi-popup.js js/vapi-tabs.js js/vapi-window.js \
js/vapi-core.js js/vapi-browser.js js/vapi-storage.js \
- js/vapi-messaging.js
+ js/vapi-messaging.js js/vapi-net.js
JS := $(JS1) $(JS2) $(JS3) $(JS4)
diff --git a/background.html b/background.html
index bab0678..6e1f4ff 100644
--- a/background.html
+++ b/background.html
@@ -39,6 +39,7 @@
<script src="js/vapi-tabs.js"></script>
<script src="js/vapi-browser.js"></script>
<script src="js/vapi-storage.js"></script>
+<script src="js/vapi-net.js"></script>
<script src="js/background.js"></script>
<script src="js/xal.js"></script>
<script src="js/usersettings.js"></script>
diff --git a/js/vapi-background.js b/js/vapi-background.js
index a7cc5f3..3035556 100644
--- a/js/vapi-background.js
+++ b/js/vapi-background.js
@@ -534,47 +534,6 @@
}
};
- vAPI.net = {};
-
- vAPI.net.registerListeners = function () {
- this.onBeforeRequest.types = this.onBeforeRequest.types
- ? new Set(this.onBeforeRequest.types)
- : null;
-
- this.onBeforeSendHeaders.types = this.onBeforeSendHeaders.types
- ? new Set(this.onBeforeSendHeaders.types)
- : null;
-
- let shouldLoadListenerMessageName = location.host + ':shouldLoad';
- let shouldLoadListener = function (e) {
- let details = e.data;
- let pendingReq = httpObserver.createPendingRequest(details.url);
- pendingReq.rawType = details.rawType;
- pendingReq.tabId = vAPI.tabs.manager.tabIdFromTarget(e.target);
- };
-
- // https://github.com/gorhill/uMatrix/issues/200
- // We need this only for Firefox 34 and less: the tab id is derived from
- // the origin of the message.
- if (!vAPI.modernFirefox) {
- vAPI.messaging.globalMessageManager
- .addMessageListener(shouldLoadListenerMessageName,
- shouldLoadListener);
- }
-
- httpObserver.register();
-
- vAPI.addCleanUpTask(function () {
- if (!vAPI.modernFirefox) {
- vAPI.messaging.globalMessageManager
- .removeMessageListener(shouldLoadListenerMessageName,
- shouldLoadListener);
- }
-
- httpObserver.unregister();
- });
- };
-
vAPI.toolbarButton = {
id: location.host + '-button',
type: 'view',
diff --git a/js/vapi-net.js b/js/vapi-net.js
new file mode 100644
index 0000000..5c6ccaf
--- /dev/null
+++ b/js/vapi-net.js
@@ -0,0 +1,78 @@
+/*******************************************************************************
+
+ ηMatrix - a browser extension to black/white list requests.
+ Copyright (C) 2014-2019 The uMatrix/uBlock Origin authors
+ Copyright (C) 2019 Alessio Vanni
+
+ 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/}.
+
+ Home: https://gitlab.com/vannilla/ematrix
+ uMatrix Home: https://github.com/gorhill/uMatrix
+*/
+
+/* global self, Components */
+
+// For background page (tabs management)
+
+'use strict';
+
+/******************************************************************************/
+
+(function () {
+ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
+
+ let vAPI = self.vAPI; // Guaranteed to be initialized by vapi-background.js
+
+ vAPI.net = {};
+
+ vAPI.net.registerListeners = function () {
+ this.onBeforeRequest.types = this.onBeforeRequest.types
+ ? new Set(this.onBeforeRequest.types)
+ : null;
+
+ this.onBeforeSendHeaders.types = this.onBeforeSendHeaders.types
+ ? new Set(this.onBeforeSendHeaders.types)
+ : null;
+
+ let shouldLoadListenerMessageName = location.host + ':shouldLoad';
+ let shouldLoadListener = function (e) {
+ let details = e.data;
+ let pendingReq = httpObserver.createPendingRequest(details.url);
+ pendingReq.rawType = details.rawType;
+ pendingReq.tabId = vAPI.tabs.manager.tabIdFromTarget(e.target);
+ };
+
+ // https://github.com/gorhill/uMatrix/issues/200
+ // We need this only for Firefox 34 and less: the tab id is derived from
+ // the origin of the message.
+ if (!vAPI.modernFirefox) {
+ vAPI.messaging.globalMessageManager
+ .addMessageListener(shouldLoadListenerMessageName,
+ shouldLoadListener);
+ }
+
+ httpObserver.register();
+
+ vAPI.addCleanUpTask(function () {
+ if (!vAPI.modernFirefox) {
+ vAPI.messaging.globalMessageManager
+ .removeMessageListener(shouldLoadListenerMessageName,
+ shouldLoadListener);
+ }
+
+ httpObserver.unregister();
+ });
+ };
+})();