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
4 * found in the LICENSE file.
9 * @param {!WebInspector.TracingModel} tracingModel
10 * @param {number=} zeroTime
12 WebInspector
.FilmStripModel = function(tracingModel
, zeroTime
)
14 this._tracingModel
= tracingModel
;
15 this._zeroTime
= zeroTime
|| tracingModel
.minimumRecordTime();
17 /** @type {!Array<!WebInspector.FilmStripModel.Frame>} */
20 var browserProcess
= tracingModel
.processByName("Browser");
23 var mainThread
= browserProcess
.threadByName("CrBrowserMain");
27 var events
= mainThread
.events();
28 for (var i
= 0; i
< events
.length
; ++i
) {
29 var event
= events
[i
];
30 if (event
.startTime
< this._zeroTime
)
32 if (!event
.hasCategory(WebInspector
.FilmStripModel
._category
))
34 if (event
.name
=== WebInspector
.FilmStripModel
.TraceEvents
.CaptureFrame
) {
35 var data
= event
.args
["data"];
37 this._frames
.push(WebInspector
.FilmStripModel
.Frame
._fromEvent(this, event
, this._frames
.length
));
38 } else if (event
.name
=== WebInspector
.FilmStripModel
.TraceEvents
.Screenshot
) {
39 this._frames
.push(WebInspector
.FilmStripModel
.Frame
._fromSnapshot(this, /** @type {!WebInspector.TracingModel.ObjectSnapshot} */ (event
), this._frames
.length
));
44 WebInspector
.FilmStripModel
._category
= "disabled-by-default-devtools.screenshot";
46 WebInspector
.FilmStripModel
.TraceEvents
= {
47 CaptureFrame
: "CaptureFrame",
48 Screenshot
: "Screenshot"
51 WebInspector
.FilmStripModel
.prototype = {
53 * @return {!Array<!WebInspector.FilmStripModel.Frame>}
65 return this._zeroTime
;
69 * @param {number} timestamp
70 * @return {?WebInspector.FilmStripModel.Frame}
72 frameByTimestamp: function(timestamp
)
75 * @param {number} timestamp
76 * @param {!WebInspector.FilmStripModel.Frame} frame
79 function comparator(timestamp
, frame
)
81 return timestamp
- frame
.timestamp
;
83 var index
= this._frames
.lowerBound(timestamp
, comparator
);
84 return index
< this._frames
.length
? this._frames
[index
] : null;
90 * @param {!WebInspector.FilmStripModel} model
91 * @param {number} timestamp
92 * @param {number} index
94 WebInspector
.FilmStripModel
.Frame = function(model
, timestamp
, index
)
97 this.timestamp
= timestamp
;
99 /** @type {?string} */
100 this._imageData
= null;
101 /** @type {?WebInspector.TracingModel.ObjectSnapshot} */
102 this._snapshot
= null;
106 * @param {!WebInspector.FilmStripModel} model
107 * @param {!WebInspector.TracingModel.Event} event
108 * @param {number} index
109 * @return {!WebInspector.FilmStripModel.Frame}
111 WebInspector
.FilmStripModel
.Frame
._fromEvent = function(model
, event
, index
)
113 var frame
= new WebInspector
.FilmStripModel
.Frame(model
, event
.startTime
, index
);
114 frame
._imageData
= event
.args
["data"];
119 * @param {!WebInspector.FilmStripModel} model
120 * @param {!WebInspector.TracingModel.ObjectSnapshot} snapshot
121 * @param {number} index
122 * @return {!WebInspector.FilmStripModel.Frame}
124 WebInspector
.FilmStripModel
.Frame
._fromSnapshot = function(model
, snapshot
, index
)
126 var frame
= new WebInspector
.FilmStripModel
.Frame(model
, snapshot
.startTime
, index
);
127 frame
._snapshot
= snapshot
;
131 WebInspector
.FilmStripModel
.Frame
.prototype = {
133 * @return {!WebInspector.FilmStripModel}
141 * @return {!Promise<?string>}
143 imageDataPromise: function()
145 if (this._imageData
|| !this._snapshot
)
146 return Promise
.resolve(this._imageData
);
148 return /** @type {!Promise<?string>} */ (this._snapshot
.objectPromise());