OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The Chromium Authors. All rights reserved. | 2 * Copyright 2015 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
| 6 /** |
| 7 * @unrestricted |
| 8 */ |
| 9 WebInspector.FilmStripModel = class { |
| 10 /** |
| 11 * @param {!WebInspector.TracingModel} tracingModel |
| 12 * @param {number=} zeroTime |
| 13 */ |
| 14 constructor(tracingModel, zeroTime) { |
| 15 this.reset(tracingModel, zeroTime); |
| 16 } |
6 | 17 |
7 /** | 18 /** |
8 * @constructor | 19 * @param {!WebInspector.TracingModel} tracingModel |
9 * @param {!WebInspector.TracingModel} tracingModel | 20 * @param {number=} zeroTime |
10 * @param {number=} zeroTime | 21 */ |
11 */ | 22 reset(tracingModel, zeroTime) { |
12 WebInspector.FilmStripModel = function(tracingModel, zeroTime) | 23 this._zeroTime = zeroTime || tracingModel.minimumRecordTime(); |
13 { | 24 this._spanTime = tracingModel.maximumRecordTime() - this._zeroTime; |
14 this.reset(tracingModel, zeroTime); | 25 |
| 26 /** @type {!Array<!WebInspector.FilmStripModel.Frame>} */ |
| 27 this._frames = []; |
| 28 var browserMain = WebInspector.TracingModel.browserMainThread(tracingModel); |
| 29 if (!browserMain) |
| 30 return; |
| 31 |
| 32 var events = browserMain.events(); |
| 33 for (var i = 0; i < events.length; ++i) { |
| 34 var event = events[i]; |
| 35 if (event.startTime < this._zeroTime) |
| 36 continue; |
| 37 if (!event.hasCategory(WebInspector.FilmStripModel._category)) |
| 38 continue; |
| 39 if (event.name === WebInspector.FilmStripModel.TraceEvents.CaptureFrame) { |
| 40 var data = event.args['data']; |
| 41 if (data) |
| 42 this._frames.push(WebInspector.FilmStripModel.Frame._fromEvent(this, e
vent, this._frames.length)); |
| 43 } else if (event.name === WebInspector.FilmStripModel.TraceEvents.Screensh
ot) { |
| 44 this._frames.push(WebInspector.FilmStripModel.Frame._fromSnapshot( |
| 45 this, /** @type {!WebInspector.TracingModel.ObjectSnapshot} */ (even
t), this._frames.length)); |
| 46 } |
| 47 } |
| 48 } |
| 49 |
| 50 /** |
| 51 * @return {!Array<!WebInspector.FilmStripModel.Frame>} |
| 52 */ |
| 53 frames() { |
| 54 return this._frames; |
| 55 } |
| 56 |
| 57 /** |
| 58 * @return {number} |
| 59 */ |
| 60 zeroTime() { |
| 61 return this._zeroTime; |
| 62 } |
| 63 |
| 64 /** |
| 65 * @return {number} |
| 66 */ |
| 67 spanTime() { |
| 68 return this._spanTime; |
| 69 } |
| 70 |
| 71 /** |
| 72 * @param {number} timestamp |
| 73 * @return {?WebInspector.FilmStripModel.Frame} |
| 74 */ |
| 75 frameByTimestamp(timestamp) { |
| 76 var index = this._frames.upperBound(timestamp, (timestamp, frame) => timesta
mp - frame.timestamp) - 1; |
| 77 return index >= 0 ? this._frames[index] : null; |
| 78 } |
15 }; | 79 }; |
16 | 80 |
17 WebInspector.FilmStripModel._category = "disabled-by-default-devtools.screenshot
"; | 81 WebInspector.FilmStripModel._category = 'disabled-by-default-devtools.screenshot
'; |
18 | 82 |
19 WebInspector.FilmStripModel.TraceEvents = { | 83 WebInspector.FilmStripModel.TraceEvents = { |
20 CaptureFrame: "CaptureFrame", | 84 CaptureFrame: 'CaptureFrame', |
21 Screenshot: "Screenshot" | 85 Screenshot: 'Screenshot' |
22 }; | |
23 | |
24 WebInspector.FilmStripModel.prototype = { | |
25 /** | |
26 * @param {!WebInspector.TracingModel} tracingModel | |
27 * @param {number=} zeroTime | |
28 */ | |
29 reset: function(tracingModel, zeroTime) | |
30 { | |
31 this._zeroTime = zeroTime || tracingModel.minimumRecordTime(); | |
32 this._spanTime = tracingModel.maximumRecordTime() - this._zeroTime; | |
33 | |
34 /** @type {!Array<!WebInspector.FilmStripModel.Frame>} */ | |
35 this._frames = []; | |
36 var browserMain = WebInspector.TracingModel.browserMainThread(tracingMod
el); | |
37 if (!browserMain) | |
38 return; | |
39 | |
40 var events = browserMain.events(); | |
41 for (var i = 0; i < events.length; ++i) { | |
42 var event = events[i]; | |
43 if (event.startTime < this._zeroTime) | |
44 continue; | |
45 if (!event.hasCategory(WebInspector.FilmStripModel._category)) | |
46 continue; | |
47 if (event.name === WebInspector.FilmStripModel.TraceEvents.CaptureFr
ame) { | |
48 var data = event.args["data"]; | |
49 if (data) | |
50 this._frames.push(WebInspector.FilmStripModel.Frame._fromEve
nt(this, event, this._frames.length)); | |
51 } else if (event.name === WebInspector.FilmStripModel.TraceEvents.Sc
reenshot) { | |
52 this._frames.push(WebInspector.FilmStripModel.Frame._fromSnapsho
t(this, /** @type {!WebInspector.TracingModel.ObjectSnapshot} */ (event), this._
frames.length)); | |
53 } | |
54 } | |
55 }, | |
56 | |
57 /** | |
58 * @return {!Array<!WebInspector.FilmStripModel.Frame>} | |
59 */ | |
60 frames: function() | |
61 { | |
62 return this._frames; | |
63 }, | |
64 | |
65 /** | |
66 * @return {number} | |
67 */ | |
68 zeroTime: function() | |
69 { | |
70 return this._zeroTime; | |
71 }, | |
72 | |
73 /** | |
74 * @return {number} | |
75 */ | |
76 spanTime: function() | |
77 { | |
78 return this._spanTime; | |
79 }, | |
80 | |
81 /** | |
82 * @param {number} timestamp | |
83 * @return {?WebInspector.FilmStripModel.Frame} | |
84 */ | |
85 frameByTimestamp: function(timestamp) | |
86 { | |
87 var index = this._frames.upperBound(timestamp, (timestamp, frame) => tim
estamp - frame.timestamp) - 1; | |
88 return index >= 0 ? this._frames[index] : null; | |
89 } | |
90 }; | 86 }; |
91 | 87 |
92 /** | 88 /** |
93 * @constructor | 89 * @unrestricted |
94 * @param {!WebInspector.FilmStripModel} model | |
95 * @param {number} timestamp | |
96 * @param {number} index | |
97 */ | 90 */ |
98 WebInspector.FilmStripModel.Frame = function(model, timestamp, index) | 91 WebInspector.FilmStripModel.Frame = class { |
99 { | 92 /** |
| 93 * @param {!WebInspector.FilmStripModel} model |
| 94 * @param {number} timestamp |
| 95 * @param {number} index |
| 96 */ |
| 97 constructor(model, timestamp, index) { |
100 this._model = model; | 98 this._model = model; |
101 this.timestamp = timestamp; | 99 this.timestamp = timestamp; |
102 this.index = index; | 100 this.index = index; |
103 /** @type {?string} */ | 101 /** @type {?string} */ |
104 this._imageData = null; | 102 this._imageData = null; |
105 /** @type {?WebInspector.TracingModel.ObjectSnapshot} */ | 103 /** @type {?WebInspector.TracingModel.ObjectSnapshot} */ |
106 this._snapshot = null; | 104 this._snapshot = null; |
107 }; | 105 } |
108 | 106 |
109 /** | 107 /** |
110 * @param {!WebInspector.FilmStripModel} model | 108 * @param {!WebInspector.FilmStripModel} model |
111 * @param {!WebInspector.TracingModel.Event} event | 109 * @param {!WebInspector.TracingModel.Event} event |
112 * @param {number} index | 110 * @param {number} index |
113 * @return {!WebInspector.FilmStripModel.Frame} | 111 * @return {!WebInspector.FilmStripModel.Frame} |
114 */ | 112 */ |
115 WebInspector.FilmStripModel.Frame._fromEvent = function(model, event, index) | 113 static _fromEvent(model, event, index) { |
116 { | |
117 var frame = new WebInspector.FilmStripModel.Frame(model, event.startTime, in
dex); | 114 var frame = new WebInspector.FilmStripModel.Frame(model, event.startTime, in
dex); |
118 frame._imageData = event.args["data"]; | 115 frame._imageData = event.args['data']; |
119 return frame; | 116 return frame; |
120 }; | 117 } |
121 | 118 |
122 /** | 119 /** |
123 * @param {!WebInspector.FilmStripModel} model | 120 * @param {!WebInspector.FilmStripModel} model |
124 * @param {!WebInspector.TracingModel.ObjectSnapshot} snapshot | 121 * @param {!WebInspector.TracingModel.ObjectSnapshot} snapshot |
125 * @param {number} index | 122 * @param {number} index |
126 * @return {!WebInspector.FilmStripModel.Frame} | 123 * @return {!WebInspector.FilmStripModel.Frame} |
127 */ | 124 */ |
128 WebInspector.FilmStripModel.Frame._fromSnapshot = function(model, snapshot, inde
x) | 125 static _fromSnapshot(model, snapshot, index) { |
129 { | |
130 var frame = new WebInspector.FilmStripModel.Frame(model, snapshot.startTime,
index); | 126 var frame = new WebInspector.FilmStripModel.Frame(model, snapshot.startTime,
index); |
131 frame._snapshot = snapshot; | 127 frame._snapshot = snapshot; |
132 return frame; | 128 return frame; |
| 129 } |
| 130 |
| 131 /** |
| 132 * @return {!WebInspector.FilmStripModel} |
| 133 */ |
| 134 model() { |
| 135 return this._model; |
| 136 } |
| 137 |
| 138 /** |
| 139 * @return {!Promise<?string>} |
| 140 */ |
| 141 imageDataPromise() { |
| 142 if (this._imageData || !this._snapshot) |
| 143 return Promise.resolve(this._imageData); |
| 144 |
| 145 return /** @type {!Promise<?string>} */ (this._snapshot.objectPromise()); |
| 146 } |
133 }; | 147 }; |
134 | 148 |
135 WebInspector.FilmStripModel.Frame.prototype = { | |
136 /** | |
137 * @return {!WebInspector.FilmStripModel} | |
138 */ | |
139 model: function() | |
140 { | |
141 return this._model; | |
142 }, | |
143 | 149 |
144 /** | |
145 * @return {!Promise<?string>} | |
146 */ | |
147 imageDataPromise: function() | |
148 { | |
149 if (this._imageData || !this._snapshot) | |
150 return Promise.resolve(this._imageData); | |
151 | |
152 return /** @type {!Promise<?string>} */ (this._snapshot.objectPromise())
; | |
153 } | |
154 }; | |
OLD | NEW |