Chromium Code Reviews| Index: media/test/data/eme_player_js/utils.js |
| diff --git a/media/test/data/eme_player_js/utils.js b/media/test/data/eme_player_js/utils.js |
| index 491bac7892a7370b9d23809e7284384f3996c759..604f8c897dfb75f0fde60a7e730446ed5f737e9b 100644 |
| --- a/media/test/data/eme_player_js/utils.js |
| +++ b/media/test/data/eme_player_js/utils.js |
| @@ -79,6 +79,28 @@ Utils.createJWKData = function(keyId, key) { |
| return Utils.convertToUint8Array(createJWKSet(createJWK(keyId, key))); |
| }; |
| +Utils.extractFirstLicenseKey = function(message) { |
| + // Decodes data (Uint8Array) from base64 string. |
| + // TODO(jrummell): Update once the EME spec is updated to say base64url |
| + // encoding. |
| + function base64Decode(data) { |
| + return atob(data); |
| + } |
| + |
| + function convertToString(data) { |
| + return String.fromCharCode.apply(null, Utils.convertToUint8Array(data)); |
| + } |
| + |
| + try { |
| + var json = JSON.parse(convertToString(message)); |
| + // Decode the first element of 'kids', return it as an Uint8Array. |
| + return Utils.convertToUint8Array(base64Decode(json.kids[0])); |
| + } catch (o) { |
|
xhwang
2014/07/30 05:56:08
replace "o" with something more readable?
jrummell
2014/07/30 18:44:16
Done.
|
| + // Not valid JSON, so return message untouched as Uint8Array. |
| + return Utils.convertToUint8Array(message); |
| + } |
| +} |
| + |
| Utils.documentLog = function(log, success, time) { |
| if (!docLogs) |
| return; |
| @@ -154,13 +176,17 @@ Utils.getHexString = function(uintArray) { |
| return hex_str; |
| }; |
| -Utils.getInitDataFromMessage = function(message, mediaType) { |
| - var initData = Utils.convertToUint8Array(message.message); |
| +Utils.getInitDataFromMessage = function(message, mediaType, decodeJSONMessage) { |
| + var initData; |
| if (mediaType.indexOf('mp4') != -1) { |
| // Temporary hack for Clear Key in v0.1. |
| // If content uses mp4, then message.message is PSSH data. Instead of |
| // parsing that data we hard code the initData. |
| initData = Utils.convertToUint8Array(KEY_ID); |
| + } else if (decodeJSONMessage) { |
| + initData = Utils.extractFirstLicenseKey(message.message); |
| + } else { |
| + initData = Utils.convertToUint8Array(message.message); |
| } |
| return initData; |
| }; |