Bug 1548177 support incognito flag in request filtering r=kmag,robwu

Differential Revision: https://phabricator.services.mozilla.com/D29446

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Shane Caraveo 2019-05-02 16:23:03 +00:00
Родитель 973f7ba7af
Коммит 5f24a04aa2
8 изменённых файлов: 48 добавлений и 21 удалений

Просмотреть файл

@ -462,6 +462,12 @@ dictionary MozRequestFilter {
* match pattern set.
*/
MatchPatternSet? urls = null;
/**
* If present, the request only matches if the loadInfo privateBrowsingId matches
* against the given incognito value.
*/
boolean? incognito = null;
};
dictionary MozRequestMatchOptions {

Просмотреть файл

@ -242,7 +242,8 @@ function normalizeFilter(filter) {
filter = {};
}
return {urls: filter.urls || null, types: filter.types || null};
return {urls: filter.urls || null, types: filter.types || null,
incognito: filter.incognito !== undefined ? filter.incognito : null};
}
class ProxyChannelFilter {

Просмотреть файл

@ -64,6 +64,9 @@ function registerEvent(extension, eventName, fire, filter, info, remoteTab = nul
if (filter.windowId) {
filter2.windowId = filter.windowId;
}
if (filter.incognito !== undefined) {
filter2.incognito = filter.incognito;
}
let blockingAllowed = extension.hasPermission("webRequestBlocking");

Просмотреть файл

@ -119,7 +119,8 @@
"minItems": 1
},
"tabId": { "type": "integer", "optional": true },
"windowId": { "type": "integer", "optional": true }
"windowId": { "type": "integer", "optional": true },
"incognito": { "type": "boolean", "optional": true, "description": "If provided, requests that do not match the incognito state will be filtered out."}
}
},
{

Просмотреть файл

@ -19,8 +19,12 @@ add_task(async function test_incognito_webrequest_access() {
background() {
browser.webRequest.onBeforeRequest.addListener(async (details) => {
browser.test.assertTrue(details.incognito, "incognito flag is set");
browser.test.notifyPass("webRequest.private");
}, {urls: ["<all_urls>"]}, ["blocking"]);
}, {urls: ["<all_urls>"], incognito: true}, ["blocking"]);
browser.webRequest.onBeforeRequest.addListener(async (details) => {
browser.test.assertFalse(details.incognito, "incognito flag is not set");
browser.test.notifyPass("webRequest.spanning");
}, {urls: ["<all_urls>"], incognito: false}, ["blocking"]);
},
});
await pb_extension.startup();
@ -40,14 +44,15 @@ add_task(async function test_incognito_webrequest_access() {
await extension.startup();
let contentPage = await ExtensionTestUtils.loadContentPage("http://example.com/dummy", {privateBrowsing: true});
await pb_extension.awaitFinish("webRequest.private");
await pb_extension.unload();
await contentPage.close();
contentPage = await ExtensionTestUtils.loadContentPage("http://example.com/dummy");
await extension.awaitFinish("webRequest");
await extension.unload();
await pb_extension.awaitFinish("webRequest.spanning");
await contentPage.close();
await pb_extension.unload();
await extension.unload();
Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
});

Просмотреть файл

@ -27,7 +27,7 @@ add_task(async function test_incognito_proxy_onRequest_access() {
browser.proxy.onRequest.addListener(async (details) => {
browser.test.assertFalse(details.incognito, "incognito flag is not set");
browser.test.notifyPass("proxy.onRequest");
}, {urls: ["<all_urls>"]});
}, {urls: ["<all_urls>"], types: ["main_frame"]});
// Actual call arguments do not matter here.
await browser.test.assertRejects(
@ -50,24 +50,30 @@ add_task(async function test_incognito_proxy_onRequest_access() {
},
background() {
browser.proxy.onRequest.addListener(async (details) => {
browser.test.assertTrue(details.incognito, "incognito flag is set");
browser.test.notifyPass("proxy.onRequest.private");
}, {urls: ["<all_urls>"]});
browser.test.assertTrue(details.incognito, "incognito flag is set with filter");
browser.test.sendMessage("proxy.onRequest.private");
}, {urls: ["<all_urls>"], types: ["main_frame"], incognito: true});
browser.proxy.onRequest.addListener(async (details) => {
browser.test.assertFalse(details.incognito, "incognito flag is not set with filter");
browser.test.notifyPass("proxy.onRequest.spanning");
}, {urls: ["<all_urls>"], types: ["main_frame"], incognito: false});
},
});
await pextension.startup();
let contentPage = await ExtensionTestUtils.loadContentPage("http://example.com/dummy", {privateBrowsing: true});
await pextension.awaitFinish("proxy.onRequest.private");
await pextension.unload();
await pextension.awaitMessage("proxy.onRequest.private");
await contentPage.close();
contentPage = await ExtensionTestUtils.loadContentPage("http://example.com/dummy");
await extension.awaitFinish("proxy.onRequest");
await extension.unload();
await pextension.awaitFinish("proxy.onRequest.spanning");
await contentPage.close();
await pextension.unload();
await extension.unload();
Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
});

Просмотреть файл

@ -521,13 +521,17 @@ bool ChannelWrapper::Matches(
return false;
}
nsCOMPtr<nsILoadInfo> loadInfo = GetLoadInfo();
bool isPrivate =
loadInfo && loadInfo->GetOriginAttributes().mPrivateBrowsingId > 0;
if (!aFilter.mIncognito.IsNull() && aFilter.mIncognito.Value() != isPrivate) {
return false;
}
if (aExtension) {
// Verify extension access to private requests
if (!aExtension->PrivateBrowsingAllowed()) {
nsCOMPtr<nsILoadInfo> loadInfo = GetLoadInfo();
if (loadInfo && loadInfo->GetOriginAttributes().mPrivateBrowsingId > 0) {
return false;
}
if (isPrivate && !aExtension->PrivateBrowsingAllowed()) {
return false;
}
bool isProxy =

Просмотреть файл

@ -31,7 +31,8 @@ function parseFilter(filter) {
}
// FIXME: Support windowId filtering.
return {urls: filter.urls || null, types: filter.types || null};
return {urls: filter.urls || null, types: filter.types || null,
incognito: filter.incognito !== undefined ? filter.incognito : null};
}
function parseExtra(extra, allowed = [], optionsObj = {}) {