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
|
/* 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 {
connect,
} = require("resource://devtools/client/shared/vendor/react-redux.js");
const {
createFactory,
PureComponent,
} = require("resource://devtools/client/shared/vendor/react.js");
const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.js");
const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js");
const Localized = createFactory(FluentReact.Localized);
const Actions = require("resource://devtools/client/aboutdebugging/src/actions/index.js");
const Types = require("resource://devtools/client/aboutdebugging/src/types/index.js");
const {
PROFILER_PAGE_CONTEXT,
} = require("resource://devtools/client/aboutdebugging/src/constants.js");
/**
* This component is a modal dialog containing the performance profiler UI. It uses
* the simplified DevTools panel located in devtools/client/performance-new. When
* using a custom preset, and editing the settings, the page context switches
* to about:profiling, which receives the PerfFront of the remote debuggee.
*/
class ProfilerDialog extends PureComponent {
static get propTypes() {
return {
runtimeDetails: Types.runtimeDetails.isRequired,
profilerContext: PropTypes.string.isRequired,
hideProfilerDialog: PropTypes.func.isRequired,
switchProfilerContext: PropTypes.func.isRequired,
};
}
hide() {
this.props.hideProfilerDialog();
}
setProfilerIframeDirection(frameWindow) {
// Set iframe direction according to the parent document direction.
const { documentElement } = document;
const dir = window.getComputedStyle(documentElement).direction;
frameWindow.document.documentElement.setAttribute("dir", dir);
}
/**
* The profiler iframe can either be the simplified devtools recording panel,
* or the more detailed about:profiling settings page.
*/
renderProfilerIframe() {
const {
runtimeDetails: { clientWrapper },
switchProfilerContext,
profilerContext,
} = this.props;
let src, onLoad;
switch (profilerContext) {
case PROFILER_PAGE_CONTEXT.DEVTOOLS_REMOTE:
src = clientWrapper.getPerformancePanelUrl();
onLoad = e => {
const frameWindow = e.target.contentWindow;
this.setProfilerIframeDirection(frameWindow);
clientWrapper.loadPerformanceProfiler(frameWindow, () => {
switchProfilerContext(PROFILER_PAGE_CONTEXT.ABOUTPROFILING_REMOTE);
});
};
break;
case PROFILER_PAGE_CONTEXT.ABOUTPROFILING_REMOTE:
src = "about:profiling#remote";
onLoad = e => {
const frameWindow = e.target.contentWindow;
this.setProfilerIframeDirection(frameWindow);
clientWrapper.loadAboutProfiling(frameWindow, () => {
switchProfilerContext(PROFILER_PAGE_CONTEXT.DEVTOOLS_REMOTE);
});
};
break;
default:
throw new Error(`Unhandled profiler context: "${profilerContext}"`);
}
return dom.iframe({
key: profilerContext,
className: "profiler-dialog__frame",
src,
onLoad,
});
}
render() {
const { profilerContext, switchProfilerContext } = this.props;
const dialogSizeClassName =
profilerContext === PROFILER_PAGE_CONTEXT.DEVTOOLS_REMOTE
? "profiler-dialog__inner--medium"
: "profiler-dialog__inner--large";
return dom.div(
{
className: "profiler-dialog__mask qa-profiler-dialog-mask",
onClick: () => this.hide(),
},
dom.article(
{
className: `profiler-dialog__inner ${dialogSizeClassName} qa-profiler-dialog`,
onClick: e => e.stopPropagation(),
},
dom.header(
{
className: "profiler-dialog__header",
},
Localized(
{
id: "about-debugging-profiler-dialog-title2",
},
dom.h1(
{
className: "profiler-dialog__header__title",
},
"about-debugging-profiler-dialog-title2"
)
),
dom.button(
{
className: "ghost-button qa-profiler-dialog-close",
onClick: () => {
if (profilerContext === PROFILER_PAGE_CONTEXT.DEVTOOLS_REMOTE) {
this.hide();
} else {
switchProfilerContext(PROFILER_PAGE_CONTEXT.DEVTOOLS_REMOTE);
}
},
},
dom.img({
src: "chrome://devtools/skin/images/close.svg",
})
)
),
this.renderProfilerIframe()
)
);
}
}
const mapStateToProps = state => {
return {
profilerContext: state.ui.profilerContext,
};
};
const mapDispatchToProps = {
hideProfilerDialog: Actions.hideProfilerDialog,
switchProfilerContext: Actions.switchProfilerContext,
};
module.exports = connect(mapStateToProps, mapDispatchToProps)(ProfilerDialog);
|