summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscottfr@chromium.org <scottfr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 18:29:16 +0000
committerscottfr@chromium.org <scottfr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-18 18:29:16 +0000
commitbe7d6c9aa8da1072c08ecb2ff3c21bd52a306c26 (patch)
treefab9190be3b231c33dc73ab8eac4cb6982137a04
parent5461067e0985187cc8b01043c2b57ef242ff2f6c (diff)
downloadchromium_src-be7d6c9aa8da1072c08ecb2ff3c21bd52a306c26.zip
chromium_src-be7d6c9aa8da1072c08ecb2ff3c21bd52a306c26.tar.gz
chromium_src-be7d6c9aa8da1072c08ecb2ff3c21bd52a306c26.tar.bz2
Display active audio streams on chrome://media-internals.
BUG=none TEST=navigate to chrome://media-internals and open an audio stream Review URL: http://codereview.chromium.org/7273089 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92873 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/media/media_internals.cc6
-rw-r--r--chrome/browser/resources/media_internals.html12
-rw-r--r--chrome/browser/resources/media_internals/item_store.js70
-rw-r--r--chrome/browser/resources/media_internals/media_internals.css16
-rw-r--r--chrome/browser/resources/media_internals/media_internals.js101
5 files changed, 197 insertions, 8 deletions
diff --git a/chrome/browser/media/media_internals.cc b/chrome/browser/media/media_internals.cc
index 67ac28d..bf63281 100644
--- a/chrome/browser/media/media_internals.cc
+++ b/chrome/browser/media/media_internals.cc
@@ -12,9 +12,9 @@
#include "content/browser/webui/web_ui.h"
// The names of the javascript functions to call with updates.
-static const char kDeleteItemFunction[] = "onItemDeleted";
-static const char kAudioUpdateFunction[] = "onAudioUpdate";
-static const char kSendEverythingFunction[] = "onReceiveEverything";
+static const char kDeleteItemFunction[] = "media.onItemDeleted";
+static const char kAudioUpdateFunction[] = "media.addAudioStream";
+static const char kSendEverythingFunction[] = "media.onReceiveEverything";
MediaInternals::~MediaInternals() {}
diff --git a/chrome/browser/resources/media_internals.html b/chrome/browser/resources/media_internals.html
index e56edb1..51f01b8 100644
--- a/chrome/browser/resources/media_internals.html
+++ b/chrome/browser/resources/media_internals.html
@@ -6,13 +6,15 @@ Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
- <link rel="stylesheet" href="webui.css">
+ <link rel="stylesheet" href="webui.css" />
+ <link rel="stylesheet" href="media_internals/media_internals.css" />
+ <script src="shared/js/cr.js"></script>
+ <script src="media_internals/item_store.js"></script>
+ <script src="media_internals/media_internals.js"></script>
<title>Media Internals</title>
</head>
<body>
- <p>
- Placeholder page for
- <a href="chrome://media-internals">chrome://media-internals</a>.
- </p>
+ <h2>Active audio streams:</h2>
+ <div id="audio-streams"></div>
</body>
</html>
diff --git a/chrome/browser/resources/media_internals/item_store.js b/chrome/browser/resources/media_internals/item_store.js
new file mode 100644
index 0000000..8c3e9b2
--- /dev/null
+++ b/chrome/browser/resources/media_internals/item_store.js
@@ -0,0 +1,70 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('media', function() {
+
+ /**
+ * This class stores hashes by their id field and provides basic methods for
+ * iterating over the collection.
+ * @constructor
+ */
+ function ItemStore() {
+ this.items_ = {};
+ };
+
+ ItemStore.prototype = {
+ /**
+ * Get a sorted list of item ids.
+ * @return {Array} A sorted array of ids.
+ */
+ ids: function() {
+ var ids = [];
+ for (var i in this.items_)
+ ids.push(i);
+ return ids.sort();
+ },
+
+ /**
+ * Add an item to the store.
+ * @param {Object} item The item to be added.
+ * @param {string} item.id The id of the item.
+ */
+ addItem: function(item) {
+ this.items_[item.id] = item;
+ },
+
+ /**
+ * Add a dictionary of items to the store.
+ * @param {Object} items A dictionary of individual items. The keys are
+ * irrelevant but each must have an id field.
+ */
+ addItems: function(items) {
+ for (id in items)
+ this.addItem(items[id]);
+ },
+
+ /**
+ * Remove an item from the store.
+ * @param {string} id The id of the item to be removed.
+ */
+ removeItem: function(id) {
+ delete this.items_[id];
+ },
+
+ /**
+ * Map this itemStore to an Array. Items are sorted by id.
+ * @param {function(*)} mapper The mapping function applied to each item.
+ * @return {Array} An array of mapped items.
+ */
+ map: function(mapper) {
+ var items = this.items_;
+ var ids = this.ids();
+ return ids.map(function(id) { return mapper(items[id]); });
+ }
+ };
+
+ return {
+ ItemStore: ItemStore
+ };
+});
diff --git a/chrome/browser/resources/media_internals/media_internals.css b/chrome/browser/resources/media_internals/media_internals.css
new file mode 100644
index 0000000..7198d9b
--- /dev/null
+++ b/chrome/browser/resources/media_internals/media_internals.css
@@ -0,0 +1,16 @@
+/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+.audio-stream[status='created'] {
+ color: blue;
+}
+
+.audio-stream[status='closed'] {
+ text-decoration: line-through;
+}
+
+.audio-stream[status='error'] {
+ color: red;
+}
diff --git a/chrome/browser/resources/media_internals/media_internals.js b/chrome/browser/resources/media_internals/media_internals.js
new file mode 100644
index 0000000..c046889
--- /dev/null
+++ b/chrome/browser/resources/media_internals/media_internals.js
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('media', function() {
+
+ // Stores information on open audio streams, referenced by id.
+ var audioStreams = new media.ItemStore;
+ // The <div> on the page in which to display audio stream data.
+ var audioStreamDiv;
+
+ /**
+ * Initialize variables and ask MediaInternals for all its data.
+ */
+ initialize = function() {
+ audioStreamDiv = document.getElementById('audio-streams');
+ // Get information about all currently active media.
+ chrome.send('getEverything');
+ };
+
+ /**
+ * Write the set of audio streams to the DOM.
+ */
+ printAudioStreams = function() {
+
+ /**
+ * Render a single stream as a <li>.
+ * @param {Object} stream The stream to render.
+ * @return {HTMLElement} A <li> containing the stream information.
+ */
+ printStream = function(stream) {
+ var out = document.createElement('li');
+ out.id = stream.id;
+ out.className = 'audio-stream';
+ out.setAttribute('status', stream.status);
+
+ out.innerHTML += 'Audio stream ' + stream.id.split('.')[1];
+ out.innerHTML += ' is ' + (stream.playing ? 'playing' : 'paused');
+ out.innerHTML += ' at ' + Math.round(stream.volume * 100) + '% volume.';
+ return out;
+ };
+
+ var out = document.createElement('ul');
+ audioStreams.map(printStream).forEach(function(s) {
+ out.appendChild(s)
+ });
+
+ audioStreamDiv.textContent = '';
+ audioStreamDiv.appendChild(out);
+ };
+
+ /**
+ * Receiving data for an audio stream.
+ * Add it to audioStreams and update the page.
+ * @param {Object} stream JSON representation of an audio stream.
+ */
+ addAudioStream = function(stream) {
+ audioStreams.addItem(stream);
+ printAudioStreams();
+ };
+
+ /**
+ * Receiving all data.
+ * Add it all to the appropriate stores and update the page.
+ * @param {Object} stuff JSON containing lists of data.
+ * @param {Object} stuff.audio_streams A dictionary of audio streams.
+ */
+ onReceiveEverything = function(stuff) {
+ audioStreams.addItems(stuff.audio_streams);
+ printAudioStreams();
+ };
+
+ /**
+ * Removing an item from the appropriate store.
+ * @param {string} id The id of the item to be removed, in the format
+ * "item_type.identifying_info".
+ */
+ onItemDeleted = function(id) {
+ var type = id.split('.')[0];
+ switch (type) {
+ case 'audio_streams':
+ audioStreams.removeItem(id);
+ printAudioStreams();
+ break;
+ }
+ };
+
+ return {
+ initialize: initialize,
+ addAudioStream: addAudioStream,
+ onReceiveEverything: onReceiveEverything,
+ onItemDeleted: onItemDeleted,
+ };
+});
+
+/**
+ * Initialize everything once we have access to the DOM.
+ */
+window.onload = function() {
+ media.initialize();
+};