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

Side by Side Diff: media/test/data/eme_player_js/utils.js

Issue 427993002: Implement ClearKey message format as JSON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 4 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
« no previous file with comments | « media/test/data/eme_player_js/prefixed_clearkey_player.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // Utils provide logging functions and other JS functions commonly used by the 5 // Utils provide logging functions and other JS functions commonly used by the
6 // app and media players. 6 // app and media players.
7 var Utils = new function() { 7 var Utils = new function() {
8 this.titleChanged = false; 8 this.titleChanged = false;
9 }; 9 };
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 jwkSet += ','; 72 jwkSet += ',';
73 jwkSet += arguments[i]; 73 jwkSet += arguments[i];
74 } 74 }
75 jwkSet += ']}'; 75 jwkSet += ']}';
76 return jwkSet; 76 return jwkSet;
77 } 77 }
78 78
79 return Utils.convertToUint8Array(createJWKSet(createJWK(keyId, key))); 79 return Utils.convertToUint8Array(createJWKSet(createJWK(keyId, key)));
80 }; 80 };
81 81
82 Utils.extractFirstLicenseKey = function(message) {
83 // Decodes data (Uint8Array) from base64 string.
84 // TODO(jrummell): Update once the EME spec is updated to say base64url
85 // encoding.
86 function base64Decode(data) {
87 return atob(data);
88 }
89
90 function convertToString(data) {
91 return String.fromCharCode.apply(null, Utils.convertToUint8Array(data));
92 }
93
94 try {
95 var json = JSON.parse(convertToString(message));
96 // Decode the first element of 'kids', return it as an Uint8Array.
97 return Utils.convertToUint8Array(base64Decode(json.kids[0]));
98 } catch (error) {
99 // Not valid JSON, so return message untouched as Uint8Array.
100 return Utils.convertToUint8Array(message);
101 }
102 }
103
82 Utils.documentLog = function(log, success, time) { 104 Utils.documentLog = function(log, success, time) {
83 if (!docLogs) 105 if (!docLogs)
84 return; 106 return;
85 time = time || Utils.getCurrentTimeString(); 107 time = time || Utils.getCurrentTimeString();
86 var timeLog = '<span style="color: green">' + time + '</span>'; 108 var timeLog = '<span style="color: green">' + time + '</span>';
87 var logColor = !success ? 'red' : 'black'; // default is true. 109 var logColor = !success ? 'red' : 'black'; // default is true.
88 log = '<span style="color: "' + logColor + '>' + log + '</span>'; 110 log = '<span style="color: "' + logColor + '>' + log + '</span>';
89 docLogs.innerHTML = timeLog + ' - ' + log + '<br>' + docLogs.innerHTML; 111 docLogs.innerHTML = timeLog + ' - ' + log + '<br>' + docLogs.innerHTML;
90 }; 112 };
91 113
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 var hex_str = ''; 169 var hex_str = '';
148 for (var i = 0; i < uintArray.length; i++) { 170 for (var i = 0; i < uintArray.length; i++) {
149 var hex = uintArray[i].toString(16); 171 var hex = uintArray[i].toString(16);
150 if (hex.length == 1) 172 if (hex.length == 1)
151 hex = '0' + hex; 173 hex = '0' + hex;
152 hex_str += hex; 174 hex_str += hex;
153 } 175 }
154 return hex_str; 176 return hex_str;
155 }; 177 };
156 178
157 Utils.getInitDataFromMessage = function(message, mediaType) { 179 Utils.getInitDataFromMessage = function(message, mediaType, decodeJSONMessage) {
158 var initData = Utils.convertToUint8Array(message.message); 180 var initData;
159 if (mediaType.indexOf('mp4') != -1) { 181 if (mediaType.indexOf('mp4') != -1) {
160 // Temporary hack for Clear Key in v0.1. 182 // Temporary hack for Clear Key in v0.1.
161 // If content uses mp4, then message.message is PSSH data. Instead of 183 // If content uses mp4, then message.message is PSSH data. Instead of
162 // parsing that data we hard code the initData. 184 // parsing that data we hard code the initData.
163 initData = Utils.convertToUint8Array(KEY_ID); 185 initData = Utils.convertToUint8Array(KEY_ID);
186 } else if (decodeJSONMessage) {
187 initData = Utils.extractFirstLicenseKey(message.message);
188 } else {
189 initData = Utils.convertToUint8Array(message.message);
164 } 190 }
165 return initData; 191 return initData;
166 }; 192 };
167 193
168 Utils.hasPrefix = function(msg, prefix) { 194 Utils.hasPrefix = function(msg, prefix) {
169 var message = String.fromCharCode.apply(null, msg); 195 var message = String.fromCharCode.apply(null, msg);
170 return message.substring(0, prefix.length) == prefix; 196 return message.substring(0, prefix.length) == prefix;
171 }; 197 };
172 198
173 Utils.installTitleEventHandler = function(element, event) { 199 Utils.installTitleEventHandler = function(element, event) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 var time = Utils.getCurrentTimeString(); 267 var time = Utils.getCurrentTimeString();
242 // Log to document. 268 // Log to document.
243 Utils.documentLog(arguments[0], time); 269 Utils.documentLog(arguments[0], time);
244 // Log to JS console. 270 // Log to JS console.
245 var logString = time + ' - '; 271 var logString = time + ' - ';
246 for (var i = 0; i < arguments.length; i++) { 272 for (var i = 0; i < arguments.length; i++) {
247 logString += ' ' + arguments[i]; 273 logString += ' ' + arguments[i];
248 } 274 }
249 console.log(logString); 275 console.log(logString);
250 }; 276 };
OLDNEW
« no previous file with comments | « media/test/data/eme_player_js/prefixed_clearkey_player.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698