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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
|
/* 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 osString = Services.appinfo.OS;
// Panels
loader.lazyGetter(
this,
"OptionsPanel",
() =>
require("resource://devtools/client/framework/toolbox-options.js")
.OptionsPanel
);
loader.lazyGetter(
this,
"InspectorPanel",
() => require("resource://devtools/client/inspector/panel.js").InspectorPanel
);
loader.lazyGetter(
this,
"WebConsolePanel",
() =>
require("resource://devtools/client/webconsole/panel.js").WebConsolePanel
);
loader.lazyGetter(
this,
"DebuggerPanel",
() => require("resource://devtools/client/debugger/panel.js").DebuggerPanel
);
loader.lazyGetter(
this,
"StyleEditorPanel",
() =>
require("resource://devtools/client/styleeditor/panel.js").StyleEditorPanel
);
loader.lazyGetter(
this,
"MemoryPanel",
() => require("resource://devtools/client/memory/panel.js").MemoryPanel
);
loader.lazyGetter(
this,
"NewPerformancePanel",
() =>
require("resource://devtools/client/performance-new/panel/panel.js")
.PerformancePanel
);
loader.lazyGetter(
this,
"NetMonitorPanel",
() =>
require("resource://devtools/client/netmonitor/panel.js").NetMonitorPanel
);
loader.lazyGetter(
this,
"StoragePanel",
() => require("resource://devtools/client/storage/panel.js").StoragePanel
);
loader.lazyGetter(
this,
"DomPanel",
() => require("resource://devtools/client/dom/panel.js").DomPanel
);
loader.lazyGetter(
this,
"AccessibilityPanel",
() =>
require("resource://devtools/client/accessibility/panel.js")
.AccessibilityPanel
);
loader.lazyGetter(
this,
"ApplicationPanel",
() =>
require("resource://devtools/client/application/panel.js").ApplicationPanel
);
// Other dependencies
loader.lazyRequireGetter(
this,
"ResponsiveUIManager",
"resource://devtools/client/responsive/manager.js"
);
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AppConstants: "resource://gre/modules/AppConstants.sys.mjs",
});
loader.lazyRequireGetter(
this,
"DevToolsExperimentalPrefs",
"resource://devtools/client/devtools-experimental-prefs.js"
);
loader.lazyRequireGetter(
this,
"captureAndSaveScreenshot",
"resource://devtools/client/shared/screenshot.js",
true
);
const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
const L10N = new LocalizationHelper(
"devtools/client/locales/startup.properties"
);
const CommandKeys = new Localization(
["devtools/startup/key-shortcuts.ftl"],
true
);
var Tools = {};
exports.Tools = Tools;
// Definitions
Tools.options = {
id: "options",
ordinal: 0,
url: "chrome://devtools/content/framework/toolbox-options.html",
icon: "chrome://devtools/skin/images/settings.svg",
bgTheme: "theme-body",
label: l10n("options.label"),
iconOnly: true,
panelLabel: l10n("options.panelLabel"),
tooltip: l10n("optionsButton.tooltip"),
inMenu: false,
isToolSupported() {
return true;
},
build(iframeWindow, toolbox, commands) {
return new OptionsPanel(iframeWindow, toolbox, commands);
},
};
Tools.inspector = {
id: "inspector",
accesskey: l10n("inspector.accesskey"),
ordinal: 1,
icon: "chrome://devtools/skin/images/tool-inspector.svg",
url: "chrome://devtools/content/inspector/index.xhtml",
label: l10n("inspector.label"),
panelLabel: l10n("inspector.panelLabel"),
get tooltip() {
const key = commandkey("devtools-commandkey-inspector");
if (osString == "Darwin") {
const cmdShiftC = "Cmd+Shift+" + key;
const cmdOptC = "Cmd+Opt+" + key;
return l10n("inspector.mac.tooltip", cmdShiftC, cmdOptC);
}
const ctrlShiftC = "Ctrl+Shift+" + key;
return l10n("inspector.tooltip2", ctrlShiftC);
},
inMenu: false,
preventClosingOnKey: true,
// preventRaisingOnKey is used to keep the focus on the content window for shortcuts
// that trigger the element picker.
preventRaisingOnKey: true,
onkey(panel, toolbox) {
if (
Services.prefs.getBoolPref("devtools.command-button-pick.enabled", false)
) {
toolbox.nodePicker.togglePicker();
}
},
isToolSupported(toolbox) {
return toolbox.target.hasActor("inspector");
},
build(iframeWindow, toolbox, commands) {
return new InspectorPanel(iframeWindow, toolbox, commands);
},
};
Tools.webConsole = {
id: "webconsole",
accesskey: l10n("webConsoleCmd.accesskey"),
ordinal: 2,
url: "chrome://devtools/content/webconsole/index.html",
icon: "chrome://devtools/skin/images/tool-webconsole.svg",
label: l10n("ToolboxTabWebconsole.label"),
menuLabel: l10n("MenuWebconsole.label"),
panelLabel: l10n("ToolboxWebConsole.panelLabel"),
get tooltip() {
return l10n(
"ToolboxWebconsole.tooltip2",
(osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") +
commandkey("devtools-commandkey-webconsole")
);
},
inMenu: false,
preventClosingOnKey: true,
onkey(panel, toolbox) {
if (toolbox.splitConsole) {
return toolbox.focusConsoleInput();
}
panel.focusInput();
return undefined;
},
isToolSupported() {
return true;
},
build(iframeWindow, toolbox, commands) {
return new WebConsolePanel(iframeWindow, toolbox, commands);
},
};
Tools.jsdebugger = {
id: "jsdebugger",
accesskey: l10n("debuggerMenu.accesskey"),
ordinal: 3,
icon: "chrome://devtools/skin/images/tool-debugger.svg",
url: "chrome://devtools/content/debugger/index.html",
label: l10n("ToolboxDebugger.label"),
panelLabel: l10n("ToolboxDebugger.panelLabel"),
get tooltip() {
return l10n(
"ToolboxDebugger.tooltip4",
(osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") +
commandkey("devtools-commandkey-jsdebugger")
);
},
inMenu: false,
isToolSupported() {
return true;
},
build(iframeWindow, toolbox, commands) {
return new DebuggerPanel(iframeWindow, toolbox, commands);
},
};
Tools.styleEditor = {
id: "styleeditor",
ordinal: 5,
visibilityswitch: "devtools.styleeditor.enabled",
accesskey: l10n("open.accesskey"),
icon: "chrome://devtools/skin/images/tool-styleeditor.svg",
url: "chrome://devtools/content/styleeditor/index.xhtml",
label: l10n("ToolboxStyleEditor.label"),
panelLabel: l10n("ToolboxStyleEditor.panelLabel"),
get tooltip() {
return l10n(
"ToolboxStyleEditor.tooltip3",
"Shift+" + functionkey(commandkey("devtools-commandkey-styleeditor"))
);
},
inMenu: false,
isToolSupported(toolbox) {
return toolbox.target.hasActor("styleSheets");
},
build(iframeWindow, toolbox, commands) {
return new StyleEditorPanel(iframeWindow, toolbox, commands);
},
};
Tools.performance = {
id: "performance",
ordinal: 6,
icon: "chrome://devtools/skin/images/tool-profiler.svg",
url: "chrome://devtools/content/performance-new/panel/index.xhtml",
visibilityswitch: "devtools.performance.enabled",
label: l10n("performance.label"),
panelLabel: l10n("performance.panelLabel"),
get tooltip() {
return l10n(
"performance.tooltip",
"Shift+" + functionkey(commandkey("devtools-commandkey-performance"))
);
},
accesskey: l10n("performance.accesskey"),
inMenu: false,
isToolSupported(toolbox) {
// Only use the new performance panel on local tab toolboxes, as they are guaranteed
// to have a performance actor.
// Remote tab toolboxes (eg about:devtools-toolbox from about:debugging) should not
// use the performance panel; about:debugging provides a "Profile performance" button
// which can be used instead, without having the overhead of starting a remote toolbox.
// Also accept the Browser Toolbox, so that we can profile its process via a second browser toolbox.
return (
toolbox.commands.descriptorFront.isLocalTab || toolbox.isBrowserToolbox
);
},
build(frame, toolbox, commands) {
return new NewPerformancePanel(frame, toolbox, commands);
},
};
Tools.memory = {
id: "memory",
ordinal: 7,
icon: "chrome://devtools/skin/images/tool-memory.svg",
url: "chrome://devtools/content/memory/index.xhtml",
visibilityswitch: "devtools.memory.enabled",
label: l10n("memory.label"),
panelLabel: l10n("memory.panelLabel"),
tooltip: l10n("memory.tooltip"),
isToolSupported(toolbox) {
const { descriptorFront } = toolbox.commands;
return (
!descriptorFront.isWebExtensionDescriptor &&
!descriptorFront.isWorkerDescriptor
);
},
build(frame, toolbox, commands) {
return new MemoryPanel(frame, toolbox, commands);
},
};
Tools.netMonitor = {
id: "netmonitor",
accesskey: l10n("netmonitor.accesskey"),
ordinal: 4,
visibilityswitch: "devtools.netmonitor.enabled",
icon: "chrome://devtools/skin/images/tool-network.svg",
url: "chrome://devtools/content/netmonitor/index.html",
label: l10n("netmonitor.label"),
panelLabel: l10n("netmonitor.panelLabel"),
get tooltip() {
return l10n(
"netmonitor.tooltip2",
(osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") +
commandkey("devtools-commandkey-netmonitor")
);
},
inMenu: false,
isToolSupported(toolbox) {
return (
toolbox.target.getTrait("networkMonitor") &&
!toolbox.target.isWorkerTarget
);
},
build(iframeWindow, toolbox, commands) {
return new NetMonitorPanel(iframeWindow, toolbox, commands);
},
};
Tools.storage = {
id: "storage",
ordinal: 8,
accesskey: l10n("storage.accesskey"),
visibilityswitch: "devtools.storage.enabled",
icon: "chrome://devtools/skin/images/tool-storage.svg",
url: "chrome://devtools/content/storage/index.xhtml",
label: l10n("storage.label"),
menuLabel: l10n("storage.menuLabel"),
panelLabel: l10n("storage.panelLabel"),
get tooltip() {
return l10n(
"storage.tooltip3",
"Shift+" + functionkey(commandkey("devtools-commandkey-storage"))
);
},
inMenu: false,
isToolSupported(toolbox) {
const { descriptorFront } = toolbox.commands;
// Storage is available on all contexts debugging a BrowsingContext.
// As of today, this is all but worker toolboxes.
return (
descriptorFront.isTabDescriptor ||
descriptorFront.isParentProcessDescriptor ||
descriptorFront.isWebExtensionDescriptor
);
},
build(iframeWindow, toolbox, commands) {
return new StoragePanel(iframeWindow, toolbox, commands);
},
};
Tools.dom = {
id: "dom",
accesskey: l10n("dom.accesskey"),
ordinal: 11,
visibilityswitch: "devtools.dom.enabled",
icon: "chrome://devtools/skin/images/tool-dom.svg",
url: "chrome://devtools/content/dom/index.html",
label: l10n("dom.label"),
panelLabel: l10n("dom.panelLabel"),
get tooltip() {
return l10n(
"dom.tooltip",
(osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") +
commandkey("devtools-commandkey-dom")
);
},
inMenu: false,
isToolSupported() {
return true;
},
build(iframeWindow, toolbox, commands) {
return new DomPanel(iframeWindow, toolbox, commands);
},
};
Tools.accessibility = {
id: "accessibility",
accesskey: l10n("accessibility.accesskey"),
ordinal: 9,
modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
visibilityswitch: "devtools.accessibility.enabled",
icon: "chrome://devtools/skin/images/tool-accessibility.svg",
url: "chrome://devtools/content/accessibility/index.html",
label: l10n("accessibility.label"),
panelLabel: l10n("accessibility.panelLabel"),
get tooltip() {
return l10n(
"accessibility.tooltip3",
"Shift+" +
functionkey(commandkey("devtools-commandkey-accessibility-f12"))
);
},
inMenu: false,
isToolSupported(toolbox) {
return toolbox.target.hasActor("accessibility");
},
build(iframeWindow, toolbox, commands) {
return new AccessibilityPanel(iframeWindow, toolbox, commands);
},
};
Tools.application = {
id: "application",
ordinal: 10,
visibilityswitch: "devtools.application.enabled",
icon: "chrome://devtools/skin/images/tool-application.svg",
url: "chrome://devtools/content/application/index.html",
label: l10n("application.label"),
panelLabel: l10n("application.panelLabel"),
tooltip: l10n("application.tooltip"),
inMenu: false,
isToolSupported(toolbox) {
return toolbox.target.hasActor("manifest");
},
build(iframeWindow, toolbox, commands) {
return new ApplicationPanel(iframeWindow, toolbox, commands);
},
};
var defaultTools = [
Tools.options,
Tools.webConsole,
Tools.inspector,
Tools.jsdebugger,
Tools.styleEditor,
Tools.performance,
Tools.netMonitor,
Tools.storage,
Tools.memory,
Tools.dom,
Tools.accessibility,
Tools.application,
];
exports.defaultTools = defaultTools;
Tools.darkTheme = {
id: "dark",
label: l10n("options.darkTheme.label2"),
ordinal: 1,
stylesheets: ["chrome://devtools/skin/dark-theme.css"],
classList: ["theme-dark"],
};
Tools.lightTheme = {
id: "light",
label: l10n("options.lightTheme.label2"),
ordinal: 2,
stylesheets: ["chrome://devtools/skin/light-theme.css"],
classList: ["theme-light"],
};
exports.defaultThemes = [Tools.darkTheme, Tools.lightTheme];
// List buttons that can be toggled to prevent adding prefs for
// addons that have manually inserted toolbarbuttons into DOM.
// (By default, supported target is only local tab)
exports.ToolboxButtons = [
{
id: "command-button-experimental-prefs",
description: "DevTools Experimental preferences",
isToolSupported: () => !lazy.AppConstants.MOZILLA_OFFICIAL,
onClick: (event, toolbox) => DevToolsExperimentalPrefs.showTooltip(toolbox),
isChecked: () => DevToolsExperimentalPrefs.isAnyPreferenceEnabled(),
},
{
id: "command-button-responsive",
description: l10n(
"toolbox.buttons.responsive",
osString == "Darwin" ? "Cmd+Opt+M" : "Ctrl+Shift+M"
),
isToolSupported: toolbox => toolbox.commands.descriptorFront.isLocalTab,
onClick(event, toolbox) {
const { localTab } = toolbox.commands.descriptorFront;
const browserWindow = localTab.ownerDocument.defaultView;
ResponsiveUIManager.toggle(browserWindow, localTab, {
trigger: "toolbox",
});
},
isChecked(toolbox) {
const { localTab } = toolbox.commands.descriptorFront;
if (!localTab) {
return false;
}
return ResponsiveUIManager.isActiveForTab(localTab);
},
isToggle: true,
setup(toolbox, onChange) {
ResponsiveUIManager.on("on", onChange);
ResponsiveUIManager.on("off", onChange);
},
teardown(toolbox, onChange) {
ResponsiveUIManager.off("on", onChange);
ResponsiveUIManager.off("off", onChange);
},
},
{
id: "command-button-screenshot",
description: l10n("toolbox.buttons.screenshot"),
isToolSupported: toolbox => {
return (
// @backward-compat { version 87 } We need to check for the screenshot actor as well
// when connecting to older server that does not have the screenshotContentActor
toolbox.target.hasActor("screenshotContent") ||
toolbox.target.hasActor("screenshot")
);
},
async onClick(event, toolbox) {
// Special case for screenshot button to check for clipboard preference
const clipboardEnabled = Services.prefs.getBoolPref(
"devtools.screenshot.clipboard.enabled"
);
// When screenshot to clipboard is enabled disabling saving to file
const args = {
fullpage: true,
file: !clipboardEnabled,
clipboard: clipboardEnabled,
};
const messages = await captureAndSaveScreenshot(
toolbox.target,
toolbox.win,
args
);
const notificationBox = toolbox.getNotificationBox();
const priorityMap = {
error: notificationBox.PRIORITY_CRITICAL_HIGH,
warn: notificationBox.PRIORITY_WARNING_HIGH,
};
for (const { text, level } of messages) {
// captureAndSaveScreenshot returns "saved" messages, that indicate where the
// screenshot was saved. In regular toolbox, we don't want to display them as
// the download UI can be used to open them.
// But in the browser toolbox, we can't see the download UI, so we'll display the
// saved message so the user knows there the file was saved.
if (
!toolbox.isBrowserToolbox &&
level !== "warn" &&
level !== "error"
) {
continue;
}
notificationBox.appendNotification(
text,
null,
null,
priorityMap[level] || notificationBox.PRIORITY_INFO_MEDIUM
);
}
},
},
createHighlightButton(
["RulersHighlighter", "ViewportSizeHighlighter"],
"rulers"
),
createHighlightButton(["MeasuringToolHighlighter"], "measure"),
];
function createHighlightButton(highlighters, id) {
return {
id: `command-button-${id}`,
description: l10n(`toolbox.buttons.${id}`),
isToolSupported: toolbox =>
toolbox.commands.descriptorFront.isTabDescriptor,
async onClick(event, toolbox) {
const inspectorFront = await toolbox.target.getFront("inspector");
await Promise.all(
highlighters.map(async name => {
const highlighter = await inspectorFront.getOrCreateHighlighterByType(
name
);
if (highlighter.isShown()) {
await highlighter.hide();
} else {
await highlighter.show();
}
})
);
},
isChecked(toolbox) {
// if the inspector doesn't exist, then the highlighter has not yet been connected
// to the front end.
const inspectorFront = toolbox.target.getCachedFront("inspector");
if (!inspectorFront) {
// initialize the inspector front asyncronously. There is a potential for buggy
// behavior here, but we need to change how the buttons get data (have them
// consume data from reducers rather than writing our own version) in order to
// fix this properly.
return false;
}
return highlighters.every(name =>
inspectorFront.getKnownHighlighter(name)?.isShown()
);
},
isToggle: true,
};
}
/**
* Lookup l10n string from a string bundle.
*
* @param {string} name
* The key to lookup.
* @param {...string} args
* Optional format argument.
* @returns A localized version of the given key.
*/
function l10n(name, ...args) {
try {
return args ? L10N.getFormatStr(name, ...args) : L10N.getStr(name);
} catch (ex) {
console.log("Error reading '" + name + "'");
throw new Error("l10n error with " + name);
}
}
function commandkey(name) {
try {
return CommandKeys.formatValueSync(name);
} catch (ex) {
console.log("Error reading '" + name + "'");
throw new Error("l10n error with " + name);
}
}
function functionkey(shortkey) {
return shortkey.split("_")[1];
}
|