зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 434343de944e (bug 1638007) for Mochitest failures in toolkit/components/extensions/test/mochitest/test_ext_activityLog.html. CLOSED TREE
This commit is contained in:
Родитель
e40f8009bc
Коммит
39db8d176f
|
@ -4,6 +4,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
// This file expects tabTracker to be defined in the global scope (e.g.
|
||||
// by ext-utils.js).
|
||||
/* global tabTracker */
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"WebRequest",
|
||||
|
@ -21,7 +25,27 @@ function registerEvent(
|
|||
remoteTab = null
|
||||
) {
|
||||
let listener = async data => {
|
||||
let event = data.serialize(eventName, extension);
|
||||
let browserData = { tabId: -1, windowId: -1 };
|
||||
if (data.browser) {
|
||||
browserData = tabTracker.getBrowserData(data.browser);
|
||||
}
|
||||
if (filter.tabId != null && browserData.tabId != filter.tabId) {
|
||||
return;
|
||||
}
|
||||
if (filter.windowId != null && browserData.windowId != filter.windowId) {
|
||||
return;
|
||||
}
|
||||
|
||||
let event = data.serialize(eventName);
|
||||
event.tabId = browserData.tabId;
|
||||
if (data.originAttributes) {
|
||||
event.incognito = data.originAttributes.privateBrowsingId > 0;
|
||||
if (extension.hasPermission("cookies")) {
|
||||
event.cookieStoreId = getCookieStoreIdForOriginAttributes(
|
||||
data.originAttributes
|
||||
);
|
||||
}
|
||||
}
|
||||
if (data.registerTraceableChannel) {
|
||||
// If this is a primed listener, no tabParent was passed in here,
|
||||
// but the convert() callback later in this function will be called
|
||||
|
@ -54,10 +78,10 @@ function registerEvent(
|
|||
if (filter.types) {
|
||||
filter2.types = filter.types;
|
||||
}
|
||||
if (filter.tabId !== undefined) {
|
||||
if (filter.tabId) {
|
||||
filter2.tabId = filter.tabId;
|
||||
}
|
||||
if (filter.windowId !== undefined) {
|
||||
if (filter.windowId) {
|
||||
filter2.windowId = filter.windowId;
|
||||
}
|
||||
if (filter.incognito !== undefined) {
|
||||
|
|
|
@ -6,19 +6,10 @@ var { WebRequest } = ChromeUtils.import(
|
|||
var { PromiseUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/PromiseUtils.jsm"
|
||||
);
|
||||
var { ExtensionParent } = ChromeUtils.import(
|
||||
"resource://gre/modules/ExtensionParent.jsm"
|
||||
);
|
||||
|
||||
const server = createHttpServer({ hosts: ["example.com"] });
|
||||
server.registerDirectory("/data/", do_get_file("data"));
|
||||
|
||||
add_task(async function setup() {
|
||||
// When WebRequest.jsm is used directly instead of through ext-webRequest.js,
|
||||
// ExtensionParent.apiManager is not automatically initialized. Do it here.
|
||||
await ExtensionParent.apiManager.lazyInit();
|
||||
});
|
||||
|
||||
add_task(async function test_ancestors_exist() {
|
||||
let deferred = PromiseUtils.defer();
|
||||
function onBeforeRequest(details) {
|
||||
|
|
|
@ -4,10 +4,6 @@ var { WebRequest } = ChromeUtils.import(
|
|||
"resource://gre/modules/WebRequest.jsm"
|
||||
);
|
||||
|
||||
var { ExtensionParent } = ChromeUtils.import(
|
||||
"resource://gre/modules/ExtensionParent.jsm"
|
||||
);
|
||||
|
||||
const server = createHttpServer({ hosts: ["example.com"] });
|
||||
server.registerPathHandler("/", (request, response) => {
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
|
@ -74,12 +70,6 @@ function onResponseStarted(details) {
|
|||
equal(countAfter, 1, "onResponseStarted hit once");
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
// When WebRequest.jsm is used directly instead of through ext-webRequest.js,
|
||||
// ExtensionParent.apiManager is not automatically initialized. Do it here.
|
||||
await ExtensionParent.apiManager.lazyInit();
|
||||
});
|
||||
|
||||
add_task(async function filter_urls() {
|
||||
// First load the URL so that we set cookie foopy=1.
|
||||
let contentPage = await ExtensionTestUtils.loadContentPage(URL);
|
||||
|
|
|
@ -4,10 +4,6 @@ var { WebRequest } = ChromeUtils.import(
|
|||
"resource://gre/modules/WebRequest.jsm"
|
||||
);
|
||||
|
||||
var { ExtensionParent } = ChromeUtils.import(
|
||||
"resource://gre/modules/ExtensionParent.jsm"
|
||||
);
|
||||
|
||||
const server = createHttpServer({ hosts: ["example.com"] });
|
||||
server.registerDirectory("/data/", do_get_file("data"));
|
||||
|
||||
|
@ -46,12 +42,6 @@ const expected_urls = [
|
|||
BASE + "/file_style_redirect.css",
|
||||
];
|
||||
|
||||
function resetExpectations() {
|
||||
requested.length = 0;
|
||||
sendHeaders.length = 0;
|
||||
completed.length = 0;
|
||||
}
|
||||
|
||||
function removeDupes(list) {
|
||||
let j = 0;
|
||||
for (let i = 1; i < list.length; i++) {
|
||||
|
@ -76,10 +66,6 @@ function compareLists(list1, list2, kind) {
|
|||
add_task(async function setup() {
|
||||
// Disable rcwn to make cache behavior deterministic.
|
||||
Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
|
||||
|
||||
// When WebRequest.jsm is used directly instead of through ext-webRequest.js,
|
||||
// ExtensionParent.apiManager is not automatically initialized. Do it here.
|
||||
await ExtensionParent.apiManager.lazyInit();
|
||||
});
|
||||
|
||||
add_task(async function filter_urls() {
|
||||
|
@ -104,7 +90,6 @@ add_task(async function filter_urls() {
|
|||
});
|
||||
|
||||
add_task(async function filter_types() {
|
||||
resetExpectations();
|
||||
let filter = { types: ["stylesheet"] };
|
||||
|
||||
WebRequest.onBeforeRequest.addListener(onBeforeRequest, filter, ["blocking"]);
|
||||
|
@ -124,51 +109,3 @@ add_task(async function filter_types() {
|
|||
WebRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
|
||||
WebRequest.onResponseStarted.removeListener(onResponseStarted);
|
||||
});
|
||||
|
||||
add_task(async function filter_windowId() {
|
||||
resetExpectations();
|
||||
// Check that adding windowId will exclude non-matching requests.
|
||||
// test_ext_webrequest_filter.html provides coverage for matching requests.
|
||||
let filter = { urls: new MatchPatternSet(["*://*/*_style_*"]), windowId: 0 };
|
||||
|
||||
WebRequest.onBeforeRequest.addListener(onBeforeRequest, filter, ["blocking"]);
|
||||
WebRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, filter, [
|
||||
"blocking",
|
||||
]);
|
||||
WebRequest.onResponseStarted.addListener(onResponseStarted, filter);
|
||||
|
||||
let contentPage = await ExtensionTestUtils.loadContentPage(URL);
|
||||
await contentPage.close();
|
||||
|
||||
compareLists(requested, [], "requested");
|
||||
compareLists(sendHeaders, [], "sendHeaders");
|
||||
compareLists(completed, [], "completed");
|
||||
|
||||
WebRequest.onBeforeRequest.removeListener(onBeforeRequest);
|
||||
WebRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
|
||||
WebRequest.onResponseStarted.removeListener(onResponseStarted);
|
||||
});
|
||||
|
||||
add_task(async function filter_tabId() {
|
||||
resetExpectations();
|
||||
// Check that adding tabId will exclude non-matching requests.
|
||||
// test_ext_webrequest_filter.html provides coverage for matching requests.
|
||||
let filter = { urls: new MatchPatternSet(["*://*/*_style_*"]), tabId: 0 };
|
||||
|
||||
WebRequest.onBeforeRequest.addListener(onBeforeRequest, filter, ["blocking"]);
|
||||
WebRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, filter, [
|
||||
"blocking",
|
||||
]);
|
||||
WebRequest.onResponseStarted.addListener(onResponseStarted, filter);
|
||||
|
||||
let contentPage = await ExtensionTestUtils.loadContentPage(URL);
|
||||
await contentPage.close();
|
||||
|
||||
compareLists(requested, [], "requested");
|
||||
compareLists(sendHeaders, [], "sendHeaders");
|
||||
compareLists(completed, [], "completed");
|
||||
|
||||
WebRequest.onBeforeRequest.removeListener(onBeforeRequest);
|
||||
WebRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
|
||||
WebRequest.onResponseStarted.removeListener(onResponseStarted);
|
||||
});
|
||||
|
|
|
@ -18,21 +18,11 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
ExtensionParent: "resource://gre/modules/ExtensionParent.jsm",
|
||||
ExtensionUtils: "resource://gre/modules/ExtensionUtils.jsm",
|
||||
WebRequestUpload: "resource://gre/modules/WebRequestUpload.jsm",
|
||||
SecurityInfo: "resource://gre/modules/SecurityInfo.jsm",
|
||||
});
|
||||
|
||||
// WebRequest.jsm's only consumer is ext-webRequest.js, so we can depend on
|
||||
// the apiManager.global being initialized.
|
||||
XPCOMUtils.defineLazyGetter(this, "tabTracker", () => {
|
||||
return ExtensionParent.apiManager.global.tabTracker;
|
||||
});
|
||||
XPCOMUtils.defineLazyGetter(this, "getCookieStoreIdForOriginAttributes", () => {
|
||||
return ExtensionParent.apiManager.global.getCookieStoreIdForOriginAttributes;
|
||||
});
|
||||
|
||||
function runLater(job) {
|
||||
Services.tm.dispatchToMainThread(job);
|
||||
}
|
||||
|
@ -42,12 +32,11 @@ function parseFilter(filter) {
|
|||
filter = {};
|
||||
}
|
||||
|
||||
// FIXME: Support windowId filtering.
|
||||
return {
|
||||
urls: filter.urls || null,
|
||||
types: filter.types || null,
|
||||
tabId: filter.tabId ?? null,
|
||||
windowId: filter.windowId ?? null,
|
||||
incognito: filter.incognito ?? null,
|
||||
incognito: filter.incognito !== undefined ? filter.incognito : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -236,7 +225,7 @@ const OPTIONAL_PROPERTIES = [
|
|||
"responseSize",
|
||||
];
|
||||
|
||||
function serializeRequestData(eventName, extension) {
|
||||
function serializeRequestData(eventName) {
|
||||
let data = {
|
||||
requestId: this.requestId,
|
||||
url: this.url,
|
||||
|
@ -245,19 +234,11 @@ function serializeRequestData(eventName, extension) {
|
|||
method: this.method,
|
||||
type: this.type,
|
||||
timeStamp: Date.now(),
|
||||
tabId: this.tabId,
|
||||
frameId: this.frameId,
|
||||
frameId: this.windowId,
|
||||
parentFrameId: this.parentWindowId,
|
||||
incognito: this.incognito,
|
||||
thirdParty: this.thirdParty,
|
||||
};
|
||||
|
||||
if (extension) {
|
||||
if (extension.hasPermission("cookies")) {
|
||||
data.cookieStoreId = this.cookieStoreId;
|
||||
}
|
||||
}
|
||||
|
||||
if (MAYBE_CACHED_EVENTS.has(eventName)) {
|
||||
data.fromCache = !!this.fromCache;
|
||||
}
|
||||
|
@ -722,21 +703,22 @@ HttpObserverManager = {
|
|||
},
|
||||
|
||||
getRequestData(channel, extraData) {
|
||||
let originAttributes = channel.loadInfo?.originAttributes;
|
||||
let originAttributes =
|
||||
channel.loadInfo && channel.loadInfo.originAttributes;
|
||||
let data = {
|
||||
requestId: String(channel.id),
|
||||
url: channel.finalURL,
|
||||
method: channel.method,
|
||||
browser: channel.browserElement,
|
||||
type: channel.type,
|
||||
fromCache: channel.fromCache,
|
||||
incognito: originAttributes?.privateBrowsingId > 0,
|
||||
originAttributes,
|
||||
thirdParty: channel.thirdParty,
|
||||
|
||||
originUrl: channel.originURL || undefined,
|
||||
documentUrl: channel.documentURL || undefined,
|
||||
|
||||
tabId: this.getBrowserData(channel).tabId,
|
||||
frameId: channel.windowId,
|
||||
windowId: channel.windowId,
|
||||
parentWindowId: channel.parentWindowId,
|
||||
|
||||
frameAncestors: channel.frameAncestors || undefined,
|
||||
|
@ -751,12 +733,6 @@ HttpObserverManager = {
|
|||
urlClassification: channel.urlClassification,
|
||||
};
|
||||
|
||||
if (originAttributes) {
|
||||
data.cookieStoreId = getCookieStoreIdForOriginAttributes(
|
||||
originAttributes
|
||||
);
|
||||
}
|
||||
|
||||
return Object.assign(data, extraData);
|
||||
},
|
||||
|
||||
|
@ -793,19 +769,6 @@ HttpObserverManager = {
|
|||
"onBeforeRedirect",
|
||||
]),
|
||||
|
||||
getBrowserData(wrapper) {
|
||||
let browserData = wrapper._browserData;
|
||||
if (!browserData) {
|
||||
if (wrapper.browserElement) {
|
||||
browserData = tabTracker.getBrowserData(wrapper.browserElement);
|
||||
} else {
|
||||
browserData = { tabId: -1, windowId: -1 };
|
||||
}
|
||||
wrapper._browserData = browserData;
|
||||
}
|
||||
return browserData;
|
||||
},
|
||||
|
||||
runChannelListener(channel, kind, extraData = null) {
|
||||
let handlerResults = [];
|
||||
let requestHeaders;
|
||||
|
@ -820,15 +783,6 @@ HttpObserverManager = {
|
|||
let commonData = null;
|
||||
let requestBody;
|
||||
this.listeners[kind].forEach((opts, callback) => {
|
||||
if (opts.filter.tabId !== null || opts.filter.windowId !== null) {
|
||||
const { tabId, windowId } = this.getBrowserData(channel);
|
||||
if (
|
||||
(opts.filter.tabId !== null && tabId != opts.filter.tabId) ||
|
||||
(opts.filter.windowId !== null && windowId != opts.filter.windowId)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!channel.matches(opts.filter, opts.policy, extraData)) {
|
||||
return;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче