Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Side by Side Diff: chrome/browser/resources/media_internals/media_player.js

Issue 7972028: Display active media players on chrome://media-internals. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: fixes Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('media', function() {
6 'use strict';
7
8 /**
9 * This class inherits from <li> and is designed to store and display
10 * information about an open media player.
11 */
12 var MediaPlayer = cr.ui.define('li');
13
14 MediaPlayer.prototype = {
15 __proto__: HTMLLIElement.prototype,
16 renderer: null,
17 id: null,
18
19 /**
20 * Decorate this <li> as a MediaPlayer.
21 */
22 decorate: function() {
23 this.properties = {};
24
25 this.details_ = document.createElement('details');
26 this.summary_ = document.createElement('summary');
27 this.summary_.className = 'ellipsis';
28 this.details_.open = true;
29 this.details_.appendChild(this.summary_);
30
31 this.propertyTable_ = document.createElement('table');
32 this.events_ = new media.EventList;
33 this.metrics_ = new media.Metrics;
34
35 var properties = media.createDetailsLi();
36 properties.summary.textContent = 'Properties:';
37 properties.details.appendChild(this.propertyTable_);
38
39 var ul = document.createElement('ul');
40 ul.appendChild(properties);
41 ul.appendChild(this.metrics_);
42 ul.appendChild(this.events_);
43 this.details_.appendChild(ul);
44
45 this.appendChild(this.details_);
46 document.getElementById('media-players').appendChild(this);
47 },
48
49 /**
50 * Record an event and update statistics etc.
51 * @param {Object} event The event that occurred.
52 */
53 addEvent: function(event) {
54 for (var key in event.params) {
55 this.properties[key] = event.params[key];
56 }
57
58 if (event.type == 'BUFFERED_EXTENTS_CHANGED')
59 return;
60 this.events_.addEvent(event);
61 this.metrics_.addEvent(event);
62 },
63
64 /**
65 * Update the summary line and properties table and redraw the canvas.
66 * @return {HTMLElement} A <li> representing this MediaPlayer.
67 */
68 redraw: function() {
69 media.printDictionaryToTable(this.properties, this.propertyTable_);
70
71 this.setAttribute('status', this.properties.state);
72 this.summary_.textContent = '';
73 this.summary_.appendChild(document.createTextNode(
74 this.id + ' (' + this.properties.url + '):'));
75 this.summary_.appendChild(document.createElement('br'));
76
77 // Draw the state of BufferedResourceLoader.
78 var canvas = document.createElement('canvas');
79 canvas.width = media.BAR_WIDTH;
80 canvas.height = 3 * media.BAR_HEIGHT + 2;
81 canvas.className = 'buffer-canvas';
82 this.summary_.appendChild(canvas);
83
84 var context = canvas.getContext('2d');
85 context.textAlign = 'center';
86 context.textBaseline = 'middle';
87 context.fillStyle = '#aaa';
88 context.fillRect(0, 0, canvas.width, canvas.height);
89
90 var size = this.properties.total_bytes;
91 if (!size) {
92 context.fillStyle = '#fff';
93 context.fillText('Unknown file size.', canvas.width / 2,
94 canvas.height / 2);
95 return;
96 }
97
98 var left = this.properties.buffer_start / size * canvas.width;
99 var middle = this.properties.buffer_current / size * canvas.width;
100 var right = this.properties.buffer_end / size * canvas.width;
101 context.fillStyle = '#a0a';
102 context.fillRect(left, 0, middle - left, media.BAR_HEIGHT);
103 context.fillStyle = '#aa0';
104 context.fillRect(middle, 0, right - middle, media.BAR_HEIGHT);
105
106 media.drawLine(context, media.BAR_HEIGHT + 0.5);
107
108 context.fillStyle = '#fff';
109 context.fillText('Buffered by player.', canvas.width / 2,
110 media.BAR_HEIGHT / 2);
111
112 if (!media.cacheEntriesByKey[this.properties.url]) {
113 context.fillText('No cache entry for this file.', canvas.width / 2,
114 2 * canvas.height / 3);
115 } else {
116 var cached = media.cacheEntriesByKey[this.properties.url].canvas;
117 var data = cached.getContext('2d').getImageData(0, 0, cached.width,
118 cached.height);
119 context.putImageData(data, 0, media.BAR_HEIGHT + 1);
120 }
121 },
122 };
123
124 return {
125 MediaPlayer: MediaPlayer
126 };
127 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698