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 | 6 |
7 /** | 7 /** |
8 * @constructor | 8 * @constructor |
9 * @param {!WebInspector.TracingModel} tracingModel | 9 * @param {!WebInspector.TracingModel} tracingModel |
10 */ | 10 */ |
11 WebInspector.FilmStripModel = function(tracingModel) | 11 WebInspector.FilmStripModel = function(tracingModel) |
12 { | 12 { |
13 this._tracingModel = tracingModel; | 13 this._tracingModel = tracingModel; |
14 | 14 |
15 /** @type {!Array<!WebInspector.FilmStripModel.Frame>} */ | 15 /** @type {!Array<!WebInspector.FilmStripModel.Frame>} */ |
16 this._frames = []; | 16 this._frames = []; |
17 | 17 |
18 var browserProcess = tracingModel.processByName("Browser"); | 18 var browserProcess = tracingModel.processByName("Browser"); |
19 if (!browserProcess) | 19 if (!browserProcess) |
20 return; | 20 return; |
21 var mainThread = browserProcess.threadByName("CrBrowserMain"); | 21 var mainThread = browserProcess.threadByName("CrBrowserMain"); |
22 if (!mainThread) | 22 if (!mainThread) |
23 return; | 23 return; |
24 | 24 |
25 var events = mainThread.events(); | 25 var events = mainThread.events(); |
26 for (var i = 0; i < events.length; ++i) { | 26 for (var i = 0; i < events.length; ++i) { |
27 if (events[i].category === "disabled-by-default-devtools.screenshot" && events[i].name === "CaptureFrame") { | 27 if (events[i].category !== "disabled-by-default-devtools.screenshot") |
28 var data = events[i].args.data; | 28 continue; |
29 if (!data) | 29 |
30 continue; | 30 if (events[i].name === WebInspector.FilmStripModel.TraceEvents.CaptureFr ame) { |
31 this._frames.push(new WebInspector.FilmStripModel.Frame(this, data, events[i].startTime, this._frames.length)); | 31 var data = events[i].args["data"]; |
32 if (data) | |
33 this._frames.push(WebInspector.FilmStripModel.Frame._fromEvent(t his, events[i], this._frames.length)); | |
34 } else if (events[i].name === WebInspector.FilmStripModel.TraceEvents.Sc reenshot) { | |
35 this._frames.push(WebInspector.FilmStripModel.Frame._fromSnapshot(th is, /** @type {!WebInspector.TracingModel.ObjectSnapshot} */ (events[i]), this._ frames.length)); | |
32 } | 36 } |
33 } | 37 } |
34 } | 38 } |
35 | 39 |
40 WebInspector.FilmStripModel.TraceEvents = { | |
41 CaptureFrame: "CaptureFrame", | |
42 Screenshot: "Screenshot" | |
43 } | |
44 | |
36 WebInspector.FilmStripModel.prototype = { | 45 WebInspector.FilmStripModel.prototype = { |
37 /** | 46 /** |
38 * @return {!Array<!WebInspector.FilmStripModel.Frame>} | 47 * @return {!Array<!WebInspector.FilmStripModel.Frame>} |
39 */ | 48 */ |
40 frames: function() | 49 frames: function() |
41 { | 50 { |
42 return this._frames; | 51 return this._frames; |
43 }, | 52 }, |
44 | 53 |
45 /** | 54 /** |
(...skipping 20 matching lines...) Expand all Loading... | |
66 return timestamp - frame.timestamp; | 75 return timestamp - frame.timestamp; |
67 } | 76 } |
68 var index = this._frames.lowerBound(timestamp, comparator); | 77 var index = this._frames.lowerBound(timestamp, comparator); |
69 return index < this._frames.length ? this._frames[index] : null; | 78 return index < this._frames.length ? this._frames[index] : null; |
70 } | 79 } |
71 } | 80 } |
72 | 81 |
73 /** | 82 /** |
74 * @constructor | 83 * @constructor |
75 * @param {!WebInspector.FilmStripModel} model | 84 * @param {!WebInspector.FilmStripModel} model |
76 * @param {string} imageData | |
77 * @param {number} timestamp | 85 * @param {number} timestamp |
78 * @param {number} index | 86 * @param {number} index |
79 */ | 87 */ |
80 WebInspector.FilmStripModel.Frame = function(model, imageData, timestamp, index) | 88 WebInspector.FilmStripModel.Frame = function(model, timestamp, index) |
81 { | 89 { |
82 this._model = model; | 90 this._model = model; |
83 this.imageData = imageData; | |
84 this.timestamp = timestamp; | 91 this.timestamp = timestamp; |
85 this.index = index; | 92 this.index = index; |
93 /** @type {?string} */ | |
94 this._imageData = null; | |
95 /** @type {?WebInspector.TracingModel.ObjectSnapshot} */ | |
96 this._snapshot = null; | |
97 } | |
98 | |
99 /** | |
100 * @param {!WebInspector.FilmStripModel} model | |
101 * @param {!WebInspector.TracingModel.Event} event | |
102 * @param {number} index | |
alph
2015/06/17 16:59:50
@return
| |
103 */ | |
104 WebInspector.FilmStripModel.Frame._fromEvent = function(model, event, index) | |
105 { | |
106 var frame = new WebInspector.FilmStripModel.Frame(model, event.startTime, in dex); | |
107 frame._imageData = event.args.data; | |
alph
2015/06/17 16:59:50
nit: args["data"]
| |
108 return frame; | |
109 } | |
110 | |
111 /** | |
112 * @param {!WebInspector.FilmStripModel} model | |
113 * @param {!WebInspector.TracingModel.ObjectSnapshot} snapshot | |
114 * @param {number} index | |
alph
2015/06/17 16:59:50
@return
| |
115 */ | |
116 WebInspector.FilmStripModel.Frame._fromSnapshot = function(model, snapshot, inde x) | |
117 { | |
118 var frame = new WebInspector.FilmStripModel.Frame(model, snapshot.startTime, index); | |
119 frame._snapshot = snapshot; | |
120 return frame; | |
86 } | 121 } |
87 | 122 |
88 WebInspector.FilmStripModel.Frame.prototype = { | 123 WebInspector.FilmStripModel.Frame.prototype = { |
89 /** | 124 /** |
90 * @return {!WebInspector.FilmStripModel} | 125 * @return {!WebInspector.FilmStripModel} |
91 */ | 126 */ |
92 model: function() | 127 model: function() |
93 { | 128 { |
94 return this._model; | 129 return this._model; |
130 }, | |
131 | |
132 /** | |
133 * @return {!Promise<?string>} | |
134 */ | |
135 imageDataPromise: function() | |
136 { | |
137 if (this._imageData || !this._snapshot) | |
138 return Promise.resolve(this._imageData); | |
139 | |
140 return /** @type {!Promise<?string>} */ (this._snapshot.objectPromise()) ; | |
95 } | 141 } |
96 } | 142 } |
OLD | NEW |