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 continue; | |
29 | |
30 if (events[i].name === WebInspector.FilmStripModel.TraceEvents.CaptureFr ame) { | |
28 var data = events[i].args.data; | 31 var data = events[i].args.data; |
alph
2015/06/17 09:41:59
nit: we usually write args["data"]
| |
29 if (!data) | 32 if (data) |
30 continue; | 33 this._frames.push(WebInspector.FilmStripModel.Frame._fromEvent(t his, events[i], this._frames.length)); |
31 this._frames.push(new WebInspector.FilmStripModel.Frame(this, data, events[i].startTime, 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 } | |
alph
2015/06/17 09:41:59
nit: add a line
| |
36 WebInspector.FilmStripModel.prototype = { | 44 WebInspector.FilmStripModel.prototype = { |
37 /** | 45 /** |
38 * @return {!Array<!WebInspector.FilmStripModel.Frame>} | 46 * @return {!Array<!WebInspector.FilmStripModel.Frame>} |
39 */ | 47 */ |
40 frames: function() | 48 frames: function() |
41 { | 49 { |
42 return this._frames; | 50 return this._frames; |
43 }, | 51 }, |
44 | 52 |
45 /** | 53 /** |
(...skipping 20 matching lines...) Expand all Loading... | |
66 return timestamp - frame.timestamp; | 74 return timestamp - frame.timestamp; |
67 } | 75 } |
68 var index = this._frames.lowerBound(timestamp, comparator); | 76 var index = this._frames.lowerBound(timestamp, comparator); |
69 return index < this._frames.length ? this._frames[index] : null; | 77 return index < this._frames.length ? this._frames[index] : null; |
70 } | 78 } |
71 } | 79 } |
72 | 80 |
73 /** | 81 /** |
74 * @constructor | 82 * @constructor |
75 * @param {!WebInspector.FilmStripModel} model | 83 * @param {!WebInspector.FilmStripModel} model |
76 * @param {string} imageData | |
77 * @param {number} timestamp | 84 * @param {number} timestamp |
78 * @param {number} index | 85 * @param {number} index |
79 */ | 86 */ |
80 WebInspector.FilmStripModel.Frame = function(model, imageData, timestamp, index) | 87 WebInspector.FilmStripModel.Frame = function(model, timestamp, index) |
81 { | 88 { |
82 this._model = model; | 89 this._model = model; |
83 this.imageData = imageData; | |
84 this.timestamp = timestamp; | 90 this.timestamp = timestamp; |
85 this.index = index; | 91 this.index = index; |
92 /** @type {?string} */ | |
93 this._imageData = null; | |
94 /** @type {?WebInspector.TracingModel.ObjectSnapshot} */ | |
95 this._snapshot = null; | |
96 } | |
97 | |
98 /** | |
99 * @param {!WebInspector.FilmStripModel} model | |
100 * @param {!WebInspector.TracingModel.Event} event | |
101 * @param {number} index | |
102 */ | |
103 WebInspector.FilmStripModel.Frame._fromEvent = function(model, event, index) | |
104 { | |
105 var frame = new WebInspector.FilmStripModel.Frame(model, event.startTime, in dex); | |
106 frame._imageData = event.args.data; | |
107 return frame; | |
108 } | |
109 | |
110 /** | |
111 * @param {!WebInspector.FilmStripModel} model | |
112 * @param {!WebInspector.TracingModel.ObjectSnapshot} snapshot | |
113 * @param {number} index | |
114 */ | |
115 WebInspector.FilmStripModel.Frame._fromSnapshot = function(model, snapshot, inde x) | |
116 { | |
117 var frame = new WebInspector.FilmStripModel.Frame(model, snapshot.startTime, index); | |
118 frame._snapshot = snapshot; | |
119 return frame; | |
86 } | 120 } |
87 | 121 |
88 WebInspector.FilmStripModel.Frame.prototype = { | 122 WebInspector.FilmStripModel.Frame.prototype = { |
89 /** | 123 /** |
90 * @return {!WebInspector.FilmStripModel} | 124 * @return {!WebInspector.FilmStripModel} |
91 */ | 125 */ |
92 model: function() | 126 model: function() |
93 { | 127 { |
94 return this._model; | 128 return this._model; |
129 }, | |
130 | |
131 /** | |
132 * @param {function(?string)} callback | |
133 */ | |
134 requestImageData: function(callback) | |
135 { | |
136 if (this._imageData || !this._snapshot) { | |
137 callback(this._imageData); | |
alph
2015/06/17 09:41:59
Consider setting up frame.imageData rather than pr
| |
138 return; | |
139 } | |
140 this._snapshot.requestObject(/** @type {function(?Object)} */ (callback) ); | |
95 } | 141 } |
96 } | 142 } |
OLD | NEW |