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

Side by Side Diff: content/browser/resources/media/client_renderer.js

Issue 2481213004: Add a "Save log" button to media-internals (Closed)
Patch Set: set default style Created 4 years, 1 month 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
« no previous file with comments | « no previous file | content/browser/resources/media/media_internals.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 var ClientRenderer = (function() { 5 var ClientRenderer = (function() {
6 var ClientRenderer = function() { 6 var ClientRenderer = function() {
7 this.playerListElement = document.getElementById('player-list'); 7 this.playerListElement = document.getElementById('player-list');
8 this.audioPropertiesTable = 8 this.audioPropertiesTable =
9 document.getElementById('audio-property-table').querySelector('tbody'); 9 document.getElementById('audio-property-table').querySelector('tbody');
10 this.playerPropertiesTable = 10 this.playerPropertiesTable =
11 document.getElementById('player-property-table').querySelector('tbody'); 11 document.getElementById('player-property-table').querySelector('tbody');
12 this.logTable = document.getElementById('log').querySelector('tbody'); 12 this.logTable = document.getElementById('log').querySelector('tbody');
13 this.graphElement = document.getElementById('graphs'); 13 this.graphElement = document.getElementById('graphs');
14 this.audioPropertyName = document.getElementById('audio-property-name'); 14 this.audioPropertyName = document.getElementById('audio-property-name');
15 15
16 this.players = null;
16 this.selectedPlayer = null; 17 this.selectedPlayer = null;
17 this.selectedAudioComponentType = null; 18 this.selectedAudioComponentType = null;
18 this.selectedAudioComponentId = null; 19 this.selectedAudioComponentId = null;
19 this.selectedAudioCompontentData = null; 20 this.selectedAudioCompontentData = null;
20 21
21 this.selectedPlayerLogIndex = 0; 22 this.selectedPlayerLogIndex = 0;
22 23
23 this.filterFunction = function() { return true; }; 24 this.filterFunction = function() { return true; };
24 this.filterText = document.getElementById('filter-text'); 25 this.filterText = document.getElementById('filter-text');
25 this.filterText.onkeyup = this.onTextChange_.bind(this); 26 this.filterText.onkeyup = this.onTextChange_.bind(this);
26 27
27 this.bufferCanvas = document.createElement('canvas'); 28 this.bufferCanvas = document.createElement('canvas');
28 this.bufferCanvas.width = media.BAR_WIDTH; 29 this.bufferCanvas.width = media.BAR_WIDTH;
29 this.bufferCanvas.height = media.BAR_HEIGHT; 30 this.bufferCanvas.height = media.BAR_HEIGHT;
30 31
31 this.clipboardTextarea = document.getElementById('clipboard-textarea'); 32 this.clipboardTextarea = document.getElementById('clipboard-textarea');
32 var clipboardButtons = document.getElementsByClassName('copy-button'); 33 var clipboardButtons = document.getElementsByClassName('copy-button');
33 for (var i = 0; i < clipboardButtons.length; i++) { 34 for (var i = 0; i < clipboardButtons.length; i++) {
34 clipboardButtons[i].onclick = this.copyToClipboard_.bind(this); 35 clipboardButtons[i].onclick = this.copyToClipboard_.bind(this);
35 } 36 }
36 37
38 this.saveLogButton = document.getElementById('save-log-button');
39 this.saveLogButton.onclick = this.saveLog_.bind(this);
40
37 this.hiddenKeys = ['component_id', 'component_type', 'owner_id']; 41 this.hiddenKeys = ['component_id', 'component_type', 'owner_id'];
38 42
39 // Tell CSS to hide certain content prior to making selections. 43 // Tell CSS to hide certain content prior to making selections.
40 document.body.classList.add(ClientRenderer.Css_.NO_PLAYERS_SELECTED); 44 document.body.classList.add(ClientRenderer.Css_.NO_PLAYERS_SELECTED);
41 document.body.classList.add(ClientRenderer.Css_.NO_COMPONENTS_SELECTED); 45 document.body.classList.add(ClientRenderer.Css_.NO_COMPONENTS_SELECTED);
42 }; 46 };
43 47
44 /** 48 /**
45 * CSS classes added / removed in JS to trigger styling changes. 49 * CSS classes added / removed in JS to trigger styling changes.
46 * @private @enum {string} 50 * @private @enum {string}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 function selectSelectableButton(id) { 90 function selectSelectableButton(id) {
87 var element = document.getElementById(id); 91 var element = document.getElementById(id);
88 if (!element) { 92 if (!element) {
89 console.error('failed to select button with id: ' + id); 93 console.error('failed to select button with id: ' + id);
90 return; 94 return;
91 } 95 }
92 96
93 element.checked = true; 97 element.checked = true;
94 } 98 }
95 99
100 function downloadLog(text) {
101 var file = new Blob([text], {type: 'text/plain'});
102 var a = document.createElement('a');
103 a.href = URL.createObjectURL(file);
104 a.download = "media-internals.txt";
105 a.click();
106 }
107
96 ClientRenderer.prototype = { 108 ClientRenderer.prototype = {
97 /** 109 /**
98 * Called when an audio component is added to the collection. 110 * Called when an audio component is added to the collection.
99 * @param componentType Integer AudioComponent enum value; must match values 111 * @param componentType Integer AudioComponent enum value; must match values
100 * from the AudioLogFactory::AudioComponent enum. 112 * from the AudioLogFactory::AudioComponent enum.
101 * @param components The entire map of components (name -> dict). 113 * @param components The entire map of components (name -> dict).
102 */ 114 */
103 audioComponentAdded: function(componentType, components) { 115 audioComponentAdded: function(componentType, components) {
104 this.redrawAudioComponentList_(componentType, components); 116 this.redrawAudioComponentList_(componentType, components);
105 117
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 cellElement = document.createTextNode( 235 cellElement = document.createTextNode(
224 ((typeof value) == 'undefined') ? 'n/a' : value); 236 ((typeof value) == 'undefined') ? 'n/a' : value);
225 } 237 }
226 tableCell.appendChild(cellElement) 238 tableCell.appendChild(cellElement)
227 tableRow.appendChild(tableCell); 239 tableRow.appendChild(tableCell);
228 } 240 }
229 videoTableBodyElement.appendChild(tableRow); 241 videoTableBodyElement.appendChild(tableRow);
230 } 242 }
231 }, 243 },
232 244
233 getAudioComponentName_ : function(componentType, id) { 245 getAudioComponentName_: function(componentType, id) {
234 var baseName; 246 var baseName;
235 switch (componentType) { 247 switch (componentType) {
236 case 0: 248 case 0:
237 case 1: 249 case 1:
238 baseName = 'Controller'; 250 baseName = 'Controller';
239 break; 251 break;
240 case 2: 252 case 2:
241 baseName = 'Stream'; 253 baseName = 'Stream';
242 break; 254 break;
243 default: 255 default:
244 baseName = 'UnknownType' 256 baseName = 'UnknownType'
245 console.error('Unrecognized component type: ' + componentType); 257 console.error('Unrecognized component type: ' + componentType);
246 break; 258 break;
247 } 259 }
248 return baseName + ' ' + id; 260 return baseName + ' ' + id;
249 }, 261 },
250 262
251 getListElementForAudioComponent_ : function(componentType) { 263 getListElementForAudioComponent_: function(componentType) {
252 var listElement; 264 var listElement;
253 switch (componentType) { 265 switch (componentType) {
254 case 0: 266 case 0:
255 listElement = document.getElementById( 267 listElement = document.getElementById(
256 'audio-input-controller-list'); 268 'audio-input-controller-list');
257 break; 269 break;
258 case 1: 270 case 1:
259 listElement = document.getElementById( 271 listElement = document.getElementById(
260 'audio-output-controller-list'); 272 'audio-output-controller-list');
261 break; 273 break;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 listElement.appendChild(fragment); 309 listElement.appendChild(fragment);
298 310
299 if (this.selectedAudioComponentType && 311 if (this.selectedAudioComponentType &&
300 this.selectedAudioComponentType == componentType && 312 this.selectedAudioComponentType == componentType &&
301 this.selectedAudioComponentId in components) { 313 this.selectedAudioComponentId in components) {
302 // Re-select the selected component since the button was just recreated. 314 // Re-select the selected component since the button was just recreated.
303 selectSelectableButton(this.selectedAudioComponentId); 315 selectSelectableButton(this.selectedAudioComponentId);
304 } 316 }
305 }, 317 },
306 318
307 selectAudioComponent_: function( 319 selectAudioComponent_: function(componentType, componentId, componentData) {
308 componentType, componentId, componentData) {
309 document.body.classList.remove( 320 document.body.classList.remove(
310 ClientRenderer.Css_.NO_COMPONENTS_SELECTED); 321 ClientRenderer.Css_.NO_COMPONENTS_SELECTED);
311 322
312 this.selectedAudioComponentType = componentType; 323 this.selectedAudioComponentType = componentType;
313 this.selectedAudioComponentId = componentId; 324 this.selectedAudioComponentId = componentId;
314 this.selectedAudioCompontentData = componentData; 325 this.selectedAudioCompontentData = componentData;
315 this.drawProperties_(componentData, this.audioPropertiesTable); 326 this.drawProperties_(componentData, this.audioPropertiesTable);
316 327
317 removeChildren(this.audioPropertyName); 328 removeChildren(this.audioPropertyName);
318 this.audioPropertyName.appendChild(document.createTextNode( 329 this.audioPropertyName.appendChild(document.createTextNode(
319 this.getAudioComponentName_(componentType, componentId))); 330 this.getAudioComponentName_(componentType, componentId)));
320 }, 331 },
321 332
322 redrawPlayerList_: function(players) { 333 redrawPlayerList_: function(players) {
334 this.players = players;
335
323 // Group name imposes rule that only one component can be selected 336 // Group name imposes rule that only one component can be selected
324 // (and have its properties displayed) at a time. 337 // (and have its properties displayed) at a time.
325 var buttonGroupName = 'player-buttons'; 338 var buttonGroupName = 'player-buttons';
326 339
340 var hasPlayers = false;
327 var fragment = document.createDocumentFragment(); 341 var fragment = document.createDocumentFragment();
328 for (id in players) { 342 for (id in players) {
343 hasPlayers = true;
329 var player = players[id]; 344 var player = players[id];
330 var usableName = player.properties.name || 345 var usableName = player.properties.name ||
331 player.properties.url || 346 player.properties.url ||
332 'Player ' + player.id; 347 'Player ' + player.id;
333 348
334 var li = document.createElement('li'); 349 var li = document.createElement('li');
335 var button_cb = this.selectPlayer_.bind(this, player); 350 var button_cb = this.selectPlayer_.bind(this, player);
336 li.appendChild(createSelectableButton( 351 li.appendChild(createSelectableButton(
337 id, buttonGroupName, usableName, button_cb)); 352 id, buttonGroupName, usableName, button_cb));
338 fragment.appendChild(li); 353 fragment.appendChild(li);
339 } 354 }
340 removeChildren(this.playerListElement); 355 removeChildren(this.playerListElement);
341 this.playerListElement.appendChild(fragment); 356 this.playerListElement.appendChild(fragment);
342 357
343 if (this.selectedPlayer && this.selectedPlayer.id in players) { 358 if (this.selectedPlayer && this.selectedPlayer.id in players) {
344 // Re-select the selected player since the button was just recreated. 359 // Re-select the selected player since the button was just recreated.
345 selectSelectableButton(this.selectedPlayer.id); 360 selectSelectableButton(this.selectedPlayer.id);
346 } 361 }
362
363 this.saveLogButton.style.display = hasPlayers ? "inline-block" : "none";
347 }, 364 },
348 365
349 selectPlayer_: function(player) { 366 selectPlayer_: function(player) {
350 document.body.classList.remove(ClientRenderer.Css_.NO_PLAYERS_SELECTED); 367 document.body.classList.remove(ClientRenderer.Css_.NO_PLAYERS_SELECTED);
351 368
352 this.selectedPlayer = player; 369 this.selectedPlayer = player;
353 this.selectedPlayerLogIndex = 0; 370 this.selectedPlayerLogIndex = 0;
354 this.selectedAudioComponentType = null; 371 this.selectedAudioComponentType = null;
355 this.selectedAudioComponentId = null; 372 this.selectedAudioComponentId = null;
356 this.selectedAudioCompontentData = null; 373 this.selectedAudioCompontentData = null;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 410 }
394 }, 411 },
395 412
396 drawLog_: function() { 413 drawLog_: function() {
397 var toDraw = this.selectedPlayer.allEvents.slice( 414 var toDraw = this.selectedPlayer.allEvents.slice(
398 this.selectedPlayerLogIndex); 415 this.selectedPlayerLogIndex);
399 toDraw.forEach(this.appendEventToLog_.bind(this)); 416 toDraw.forEach(this.appendEventToLog_.bind(this));
400 this.selectedPlayerLogIndex = this.selectedPlayer.allEvents.length; 417 this.selectedPlayerLogIndex = this.selectedPlayer.allEvents.length;
401 }, 418 },
402 419
420 saveLog_: function() {
421 var strippedPlayers = []
422 for (id in this.players) {
423 var p = this.players[id];
424 strippedPlayers.push({properties: p.properties, events: p.allEvents});
425 }
426 downloadLog(JSON.stringify(strippedPlayers, null, 2));
427 },
428
403 drawGraphs_: function() { 429 drawGraphs_: function() {
404 function addToGraphs(name, graph, graphElement) { 430 function addToGraphs(name, graph, graphElement) {
405 var li = document.createElement('li'); 431 var li = document.createElement('li');
406 li.appendChild(graph); 432 li.appendChild(graph);
407 li.appendChild(document.createTextNode(name)); 433 li.appendChild(document.createTextNode(name));
408 graphElement.appendChild(li); 434 graphElement.appendChild(li);
409 } 435 }
410 436
411 var url = this.selectedPlayer.properties.url; 437 var url = this.selectedPlayer.properties.url;
412 if (!url) { 438 if (!url) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 if (this.selectedPlayer) { 543 if (this.selectedPlayer) {
518 removeChildren(this.logTable); 544 removeChildren(this.logTable);
519 this.selectedPlayerLogIndex = 0; 545 this.selectedPlayerLogIndex = 0;
520 this.drawLog_(); 546 this.drawLog_();
521 } 547 }
522 }, 548 },
523 }; 549 };
524 550
525 return ClientRenderer; 551 return ClientRenderer;
526 })(); 552 })();
OLDNEW
« no previous file with comments | « no previous file | content/browser/resources/media/media_internals.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698