OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains common utilities to find video/audio elements on a page | 5 // This file contains common utilities to find video/audio elements on a page |
6 // and collect metrics for each. | 6 // and collect metrics for each. |
7 | 7 |
8 (function() { | 8 (function() { |
9 // MediaMetric class responsible for collecting metrics on a media element. | 9 // MediaMetric class responsible for collecting metrics on a media element. |
10 // It attaches required event listeners in order to collect different metrics. | 10 // It attaches required event listeners in order to collect different metrics. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 }, false); | 56 }, false); |
57 this.element.addEventListener('willLoop', function (e) { | 57 this.element.addEventListener('willLoop', function (e) { |
58 metric.onWillLoop(e); | 58 metric.onWillLoop(e); |
59 }, false); | 59 }, false); |
60 } | 60 } |
61 | 61 |
62 HTMLMediaMetric.prototype = new MediaMetricBase(); | 62 HTMLMediaMetric.prototype = new MediaMetricBase(); |
63 HTMLMediaMetric.prototype.constructor = HTMLMediaMetric; | 63 HTMLMediaMetric.prototype.constructor = HTMLMediaMetric; |
64 | 64 |
65 HTMLMediaMetric.prototype.setID = function() { | 65 HTMLMediaMetric.prototype.setID = function() { |
66 if (this.element.src) | 66 if (this.element.id) |
| 67 this.id = this.element.id; |
| 68 else if (this.element.src) |
67 this.id = this.element.src.substring(this.element.src.lastIndexOf("/")+1); | 69 this.id = this.element.src.substring(this.element.src.lastIndexOf("/")+1); |
68 else if (this.element.id) | |
69 this.id = this.element.id; | |
70 else | 70 else |
71 this.id = 'media_' + window.__globalCounter++; | 71 this.id = 'media_' + window.__globalCounter++; |
72 }; | 72 }; |
73 | 73 |
74 HTMLMediaMetric.prototype.onWillPlay = function(e) { | 74 HTMLMediaMetric.prototype.onWillPlay = function(e) { |
75 this.playbackTimer = new Timer(); | 75 this.playbackTimer = new Timer(); |
76 }; | 76 }; |
77 | 77 |
78 HTMLMediaMetric.prototype.onWillSeek = function(e) { | 78 HTMLMediaMetric.prototype.onWillSeek = function(e) { |
79 var seekLabel = ''; | 79 var seekLabel = ''; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 for (var i = 0; i < window.__mediaMetrics.length; i++) | 188 for (var i = 0; i < window.__mediaMetrics.length; i++) |
189 metrics.push(window.__mediaMetrics[i].getSummary()); | 189 metrics.push(window.__mediaMetrics[i].getSummary()); |
190 return metrics; | 190 return metrics; |
191 } | 191 } |
192 | 192 |
193 window.__globalCounter = 0; | 193 window.__globalCounter = 0; |
194 window.__mediaMetrics = []; | 194 window.__mediaMetrics = []; |
195 window.__getAllMetrics = getAllMetrics; | 195 window.__getAllMetrics = getAllMetrics; |
196 window.__createMediaMetricsForDocument = createMediaMetricsForDocument; | 196 window.__createMediaMetricsForDocument = createMediaMetricsForDocument; |
197 })(); | 197 })(); |
OLD | NEW |