Bug 1601660 - Part 1: Make GeckoView to get the content blocking log in the parent process. r=geckoview-reviewers,Ehsan,snorp

This patch is doing two things.
1. Make GeckoView directly gets the ContentBlockingLog in the parent
process when it gets the bundle event 'ContentBlocking:RequestLog'. It
will get the top-level browsingContext and get the log from the
WindowGlobal of this browsingContext.
2. Remove the GeckoViewContentBlockingChild. The child module of
ContentBlocking is no longer needed since it serves nothing after we move
the functionality of getting log to the parent process.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tim Huang 2020-01-06 20:00:16 +00:00
Родитель d3d110bba7
Коммит 91e877c5cd
5 изменённых файлов: 13 добавлений и 106 удалений

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

@ -1,44 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { GeckoViewChildModule } = ChromeUtils.import(
"resource://gre/modules/GeckoViewChildModule.jsm"
);
class GeckoViewContentBlockingChild extends GeckoViewChildModule {
onEnable() {
debug`onEnable`;
this.messageManager.addMessageListener("ContentBlocking:RequestLog", this);
}
receiveMessage(aMsg) {
debug`receiveMessage: ${aMsg.name}`;
switch (aMsg.name) {
case "ContentBlocking:RequestLog": {
docShell.getContentBlockingLog().then(
val =>
sendAsyncMessage("ContentBlocking:ExportLog", {
log: JSON.parse(val),
id: aMsg.data.id,
}),
reason =>
sendAsyncMessage("ContentBlocking:ExportLog", {
error: reason,
id: aMsg.data.id,
})
);
break;
}
}
}
}
const { debug, warn } = GeckoViewContentBlockingChild.initLogging(
"GeckoViewContentBlocking"
); // eslint-disable-line no-unused-vars
const module = GeckoViewContentBlockingChild.create(this);

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

@ -523,10 +523,6 @@ function startup() {
onInit: {
resource: "resource://gre/modules/GeckoViewContentBlocking.jsm",
},
onEnable: {
frameScript:
"chrome://geckoview/content/GeckoViewContentBlockingChild.js",
},
},
{
name: "SessionStateAggregator",

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

@ -13,7 +13,6 @@ geckoview.jar:
content/geckoview.xhtml
content/geckoview.js
content/GeckoViewAutofillChild.js
content/GeckoViewContentBlockingChild.js
content/GeckoViewContentChild.js
content/GeckoViewMediaChild.js
content/GeckoViewProgressChild.js

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

@ -209,10 +209,7 @@ class ContentBlockingControllerTest : BaseSessionTest() {
@AssertCalled(count = 1)
override fun onContentBlocked(session: GeckoSession,
event: ContentBlocking.BlockEvent) {
// A workaround for waiting until the log is actually recorded
// in the content process.
// TODO: This should be removed after Bug 1599046.
Thread.sleep(500);
}
})

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

@ -20,8 +20,6 @@ class GeckoViewContentBlocking extends GeckoViewModule {
this.browser.addProgressListener(this.progressFilter, flags);
this.registerListener(["ContentBlocking:RequestLog"]);
this.messageManager.addMessageListener("ContentBlocking:ExportLog", this);
}
onDisable() {
@ -32,11 +30,6 @@ class GeckoViewContentBlocking extends GeckoViewModule {
}
this.unregisterListener(["ContentBlocking:RequestLog"]);
this.messageManager.removeMessageListener(
"ContentBlocking:ExportLog",
this
);
}
// Bundle event handler.
@ -45,60 +38,26 @@ class GeckoViewContentBlocking extends GeckoViewModule {
switch (aEvent) {
case "ContentBlocking:RequestLog": {
if (!this._requestLogCallbacks) {
this._requestLogCallbacks = new Map();
this._requestLogId = 0;
}
this._requestLogCallbacks.set(this._requestLogId, aCallback);
this.messageManager.sendAsyncMessage("ContentBlocking:RequestLog", {
id: this._requestLogId,
});
this._requestLogId++;
break;
}
}
}
let bc = this.browser.browsingContext;
// Message manager event handler.
receiveMessage(aMsg) {
debug`receiveMessage: ${aMsg.name}`;
switch (aMsg.name) {
case "ContentBlocking:ExportLog": {
if (
!this._requestLogCallbacks ||
!this._requestLogCallbacks.has(aMsg.data.id)
) {
if (!bc) {
warn`Failed to export content blocking log.`;
return;
break;
}
const callback = this._requestLogCallbacks.get(aMsg.data.id);
// Get the top-level browsingContext. The ContentBlockingLog is located
// in its current window global.
bc = bc.top();
if (!aMsg.data.log) {
const topWindowGlobal = bc.currentWindowGlobal;
if (!topWindowGlobal) {
warn`Failed to export content blocking log.`;
callback.onError(aMsg.data.error);
// Clean up the callback even on a failed response.
this._requestLogCallbacks.delete(aMsg.data.id);
return;
break;
}
const log = topWindowGlobal.contentBlockingLog;
const res = Object.keys(aMsg.data.log).map(key => {
const blockData = aMsg.data.log[key].map(data => {
return {
category: data[0],
blocked: data[1],
count: data[2],
};
});
return {
origin: key,
blockData: blockData,
};
});
callback.onSuccess({ log: res });
this._requestLogCallbacks.delete(aMsg.data.id);
aCallback.onSuccess({ log });
break;
}
}