Index: lib/scriptInjection.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/scriptInjection.js
@@ -0,0 +1,72 @@
+/*
+ * This file is part of Adblock Plus ,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus 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 Adblock Plus. If not, see .
+ */
+
+/** @module scriptInjection */
+
+"use strict";
+
+const {defaultMatcher} = require("matcher");
+const {RegExpFilter} = require("filterClasses");
+const {extractHostFromFrame, isThirdParty, stringifyURL} = require("url");
+
+let {typeMap} = RegExpFilter;
+
+function injectScript(tabId, frameId)
+{
+ try
+ {
+ browser.tabs.executeScript(tabId, {
+ file: "/inject.preload.js",
+ frameId,
+ matchAboutBlank: true,
+ runAt: "document_start"
+ });
+ }
+ catch (error)
+ {
+ }
+}
+
+browser.webNavigation.onCommitted.addListener(({tabId, frameId, url}) =>
+{
+ // There's a bug in Chrome that causes webNavigation.onCommitted to get
+ // dispatched twice if there's a URL filter present, therefore we must listen
+ // for all URLs and do an explicit check here.
+ // https://crbug.com/827855
+ if (!/^(https?:\/\/|about:blank\b|about:srcdoc\b)/.test(url))
+ return;
+
+ let urlObject = new URL(url);
+ let urlString = stringifyURL(urlObject);
+
+ let frame = ext.getFrame(tabId, frameId);
+ if (!frame)
+ return;
+
+ let hostname = extractHostFromFrame(frame);
+ let thirdParty = isThirdParty(urlObject, hostname);
+
+ let filter = defaultMatcher.matchesAny(urlString, typeMap.WEBRTC, hostname,
+ thirdParty, null, false);
+ if (!filter)
+ return;
+
+ // As long as there's a matching filter, inject the API wrappers. We could
+ // check if the URL is whitelisted or if the filter is a whitelisting filter,
+ // but it's not worth it (i.e. false positives are OK).
+ injectScript(tabId, frameId);
+});
Index: metadata.chrome
===================================================================
--- a/metadata.chrome
+++ b/metadata.chrome
@@ -117,27 +117,29 @@
updates.html = adblockplusui/updates.html
updates.js = adblockplusui/updates.js
skin/updates.css = adblockplusui/skin/updates.css
[bundles]
lib/adblockplus.js =
adblockpluscore/lib/filterListener.js
adblockpluscore/lib/synchronizer.js
+ lib/scriptInjection.js
lib/requestBlocker.js
lib/popupBlocker.js
lib/subscriptionInit.js
lib/filterComposer.js
lib/stats.js
lib/uninstall.js
lib/csp.js
lib/cssInjection.js
adblockplusui/messageResponder.js
background.js
-include.preload.js = include.preload.js inject.preload.js
+include.preload.js = include.preload.js
+inject.preload.js = inject.preload.js
include.postload.js = subscriptionLink.postload.js composer.postload.js
qunit/tests.js =
qunit/common.js
qunit/tests/prefs.js
qunit/tests/url.js
qunit/tests/cssEscaping.js
[import_locales]
Index: polyfill.js
===================================================================
--- a/polyfill.js
+++ b/polyfill.js
@@ -27,16 +27,17 @@
"runtime.openOptionsPage",
"runtime.sendMessage",
"runtime.setUninstallURL",
"storage.local.get",
"storage.local.remove",
"storage.local.set",
"storage.managed.get",
"tabs.create",
+ "tabs.executeScript",
"tabs.get",
"tabs.getCurrent",
"tabs.insertCSS",
"tabs.query",
"tabs.reload",
"tabs.removeCSS",
"tabs.sendMessage",
"tabs.update",