1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/* 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 Services = require("Services");
const WebConsole = require("devtools/client/webconsole/webconsole");
const { TargetList } = require("devtools/shared/resources/target-list");
const {
ResourceWatcher,
} = require("devtools/shared/resources/resource-watcher");
const { Utils } = require("devtools/client/webconsole/utils");
loader.lazyRequireGetter(this, "Telemetry", "devtools/client/shared/telemetry");
loader.lazyRequireGetter(
this,
"BrowserConsoleManager",
"devtools/client/webconsole/browser-console-manager",
true
);
/**
* A BrowserConsole instance is an interactive console initialized *per target*
* that displays console log data as well as provides an interactive terminal to
* manipulate the target's document content.
*
* This object only wraps the iframe that holds the Browser Console UI. This is
* meant to be an integration point between the Firefox UI and the Browser Console
* UI and features.
*
* This object extends the WebConsole object located in webconsole.js
*/
class BrowserConsole extends WebConsole {
/*
* @constructor
* @param object target
* The target that the browser console will connect to.
* @param nsIDOMWindow iframeWindow
* The window where the browser console UI is already loaded.
* @param nsIDOMWindow chromeWindow
* The window of the browser console owner.
*/
constructor(target, iframeWindow, chromeWindow) {
super(null, iframeWindow, chromeWindow, true);
this._browserConsoleTarget = target;
this._targetList = new TargetList(target.client.mainRoot, target);
this._resourceWatcher = new ResourceWatcher(this._targetList);
this._telemetry = new Telemetry();
this._bcInitializer = null;
this._bcDestroyer = null;
}
get currentTarget() {
return this._browserConsoleTarget;
}
get targetList() {
return this._targetList;
}
get resourceWatcher() {
return this._resourceWatcher;
}
/**
* Initialize the Browser Console instance.
*
* @return object
* A promise for the initialization.
*/
init() {
if (this._bcInitializer) {
return this._bcInitializer;
}
this._bcInitializer = (async () => {
// Only add the shutdown observer if we've opened a Browser Console window.
ShutdownObserver.init();
// browserconsole is not connected with a toolbox so we pass -1 as the
// toolbox session id.
this._telemetry.toolOpened("browserconsole", -1, this);
// Bug 1605763: Call super.init before fetching targets in order to build the
// console UI first; have it listen for targets and be able to display first
// targets as soon as they get available.
await super.init(false);
await this.targetList.startListening();
// Reports the console as created only after everything is done,
// including TargetList.startListening.
const id = Utils.supportsString(this.hudId);
Services.obs.notifyObservers(id, "web-console-created");
})();
return this._bcInitializer;
}
/**
* Destroy the object.
*
* @return object
* A promise object that is resolved once the Browser Console is closed.
*/
destroy() {
if (this._bcDestroyer) {
return this._bcDestroyer;
}
this._bcDestroyer = (async () => {
// browserconsole is not connected with a toolbox so we pass -1 as the
// toolbox session id.
this._telemetry.toolClosed("browserconsole", -1, this);
this.targetList.destroy();
// Wait for any pending connection initialization.
await Promise.all(
this.ui.getAllProxies().map(proxy => proxy.getConnectionPromise())
);
await super.destroy();
await this.currentTarget.destroy();
this.chromeWindow.close();
})();
return this._bcDestroyer;
}
}
/**
* The ShutdownObserver listens for app shutdown and saves the current state
* of the Browser Console for session restore.
*/
var ShutdownObserver = {
_initialized: false,
init() {
if (this._initialized) {
return;
}
Services.obs.addObserver(this, "quit-application-granted");
this._initialized = true;
},
observe(message, topic) {
if (topic == "quit-application-granted") {
BrowserConsoleManager.storeBrowserConsoleSessionState();
this.uninit();
}
},
uninit() {
Services.obs.removeObserver(this, "quit-application-granted");
},
};
module.exports = BrowserConsole;
|