зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1644195: Implement document event watcher. r=jdescottes,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D83900
This commit is contained in:
Родитель
19143855ba
Коммит
f89e71f3a5
|
@ -151,8 +151,9 @@ class FirefoxConnector {
|
|||
|
||||
async onResourceAvailable({ resourceType, targetFront, resource }) {
|
||||
const { TYPES } = this.toolbox.resourceWatcher;
|
||||
|
||||
if (resourceType === TYPES.DOCUMENT_EVENT) {
|
||||
this.onDocEvent(resource);
|
||||
this.onDocEvent(targetFront, resource);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -317,9 +318,15 @@ class FirefoxConnector {
|
|||
/**
|
||||
* The "DOMContentLoaded" and "Load" events sent by the console actor.
|
||||
*
|
||||
* @param {object} marker
|
||||
* @param {object} targetFront
|
||||
* @param {object} event
|
||||
*/
|
||||
onDocEvent(event) {
|
||||
onDocEvent(targetFront, event) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
// Only handle document events for the top level target.
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.name === "dom-loading") {
|
||||
// Netmonitor does not support dom-loading event yet.
|
||||
return;
|
||||
|
|
|
@ -108,6 +108,8 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
|
|||
enableServerWatcher && hasBrowserElement,
|
||||
[Resources.TYPES.CSS_MESSAGE]:
|
||||
enableServerWatcher && hasBrowserElement,
|
||||
[Resources.TYPES.DOCUMENT_EVENT]:
|
||||
enableServerWatcher && hasBrowserElement,
|
||||
[Resources.TYPES.ERROR_MESSAGE]:
|
||||
enableServerWatcher && hasBrowserElement,
|
||||
[Resources.TYPES.PLATFORM_MESSAGE]: enableServerWatcher,
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
TYPES: { DOCUMENT_EVENT },
|
||||
} = require("devtools/server/actors/resources/index");
|
||||
const {
|
||||
DocumentEventsListener,
|
||||
} = require("devtools/server/actors/webconsole/listeners/document-events");
|
||||
|
||||
/**
|
||||
* Start watching for all document event related to a given Target Actor.
|
||||
*
|
||||
* @param TargetActor targetActor
|
||||
* The target actor from which we should observe document event
|
||||
* @param Object options
|
||||
* Dictionary object with following attributes:
|
||||
* - onAvailable: mandatory function
|
||||
* This will be called for each resource.
|
||||
*/
|
||||
class DocumentEventWatcher {
|
||||
constructor(targetActor, { onAvailable }) {
|
||||
if (isWorker) {
|
||||
return;
|
||||
}
|
||||
|
||||
const onDocumentEvent = (name, time) => {
|
||||
onAvailable([
|
||||
{
|
||||
resourceType: DOCUMENT_EVENT,
|
||||
name,
|
||||
time,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
this.listener = new DocumentEventsListener(targetActor);
|
||||
this.listener.on("*", onDocumentEvent);
|
||||
this.listener.listen();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.listener) {
|
||||
this.listener.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DocumentEventWatcher;
|
|
@ -7,6 +7,7 @@
|
|||
const TYPES = {
|
||||
CONSOLE_MESSAGE: "console-message",
|
||||
CSS_MESSAGE: "css-message",
|
||||
DOCUMENT_EVENT: "document-event",
|
||||
ERROR_MESSAGE: "error-message",
|
||||
PLATFORM_MESSAGE: "platform-message",
|
||||
};
|
||||
|
@ -29,6 +30,9 @@ const Resources = {
|
|||
[TYPES.CSS_MESSAGE]: {
|
||||
path: "devtools/server/actors/resources/css-messages",
|
||||
},
|
||||
[TYPES.DOCUMENT_EVENT]: {
|
||||
path: "devtools/server/actors/resources/document-event",
|
||||
},
|
||||
[TYPES.ERROR_MESSAGE]: {
|
||||
path: "devtools/server/actors/resources/error-messages",
|
||||
},
|
||||
|
|
|
@ -11,6 +11,7 @@ DIRS += [
|
|||
DevToolsModules(
|
||||
'console-messages.js',
|
||||
'css-messages.js',
|
||||
'document-event.js',
|
||||
'error-messages.js',
|
||||
'index.js',
|
||||
'platform-messages.js',
|
||||
|
|
Загрузка…
Ссылка в новой задаче