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

Side by Side Diff: LayoutTests/media/encrypted-media/encrypted-media-utils.js

Issue 397463005: Change EME WebIDL to use ArrayBuffer/ArrayBufferView. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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
OLDNEW
1 var console = null; 1 var console = null;
2 2
3 function consoleWrite(text) 3 function consoleWrite(text)
4 { 4 {
5 if (!console && document.body) { 5 if (!console && document.body) {
6 console = document.createElement('div'); 6 console = document.createElement('div');
7 document.body.appendChild(console); 7 document.body.appendChild(console);
8 } 8 }
9 var span = document.createElement('span'); 9 var span = document.createElement('span');
10 span.appendChild(document.createTextNode(text)); 10 span.appendChild(document.createTextNode(text));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 function stringToUint8Array(str) 64 function stringToUint8Array(str)
65 { 65 {
66 var result = new Uint8Array(str.length); 66 var result = new Uint8Array(str.length);
67 for(var i = 0; i < str.length; i++) { 67 for(var i = 0; i < str.length; i++) {
68 result[i] = str.charCodeAt(i); 68 result[i] = str.charCodeAt(i);
69 } 69 }
70 return result; 70 return result;
71 } 71 }
72 72
73 function decodeMessageAttribute(event)
ddorwin 2014/07/16 22:34:57 I'm not sure this is worth hiding. Part of the pur
jrummell 2014/07/18 21:56:00 Removed. We can do the conversion when ClearKey is
74 {
75 var decoder = new TextDecoder('utf-8');
ddorwin 2014/07/16 22:34:57 FYI, the Intent to Ship email was just sent, so th
jrummell 2014/07/18 21:56:00 Acknowledged.
76 var data = new Uint8Array(event.message);
77 return decoder.decode(data);
78 }
79
73 // For Clear Key, MediaKeySession.update() takes a JSON Web Key (JWK) Set, 80 // For Clear Key, MediaKeySession.update() takes a JSON Web Key (JWK) Set,
74 // which contains a set of cryptographic keys represented by JSON. These helper 81 // which contains a set of cryptographic keys represented by JSON. These helper
75 // functions help wrap raw keys into a JWK set. 82 // functions help wrap raw keys into a JWK set.
76 // See: 83 // See:
77 // https://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-medi a.html#simple-decryption-clear-key 84 // https://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-medi a.html#simple-decryption-clear-key
78 // http://tools.ietf.org/html/draft-ietf-jose-json-web-key 85 // http://tools.ietf.org/html/draft-ietf-jose-json-web-key
79 86
80 // Encodes data into base64 string without trailing '='. 87 // Encodes data into base64 string without trailing '='.
81 function base64Encode(data) 88 function base64Encode(data)
82 { 89 {
83 var result = btoa(String.fromCharCode.apply(null, data)); 90 var result = btoa(data);
84 return result.replace(/=+$/g, ''); 91 return result.replace(/=+$/g, '');
85 } 92 }
86 93
87 // Creates a JWK from raw key ID and key. 94 // Creates a JWK from raw key ID and key.
95 // keyId is expected to be a string, key is ArrayBufferView.
ddorwin 2014/07/16 22:34:57 nit: "key is an"
ddorwin 2014/07/16 22:34:57 Why are these types different? They contain the sa
jrummell 2014/07/18 21:56:00 Updated.
jrummell 2014/07/18 21:56:00 They do now.
88 function createJWK(keyId, key) 96 function createJWK(keyId, key)
89 { 97 {
90 var jwk = '{"kty":"oct","kid":"'; 98 var jwk = '{"kty":"oct","kid":"';
91 jwk += base64Encode(keyId); 99 jwk += base64Encode(keyId);
ddorwin 2014/07/16 22:34:57 FIXME: base64URLEncode()
jrummell 2014/07/18 21:56:00 Done.
92 jwk += '","k":"'; 100 jwk += '","k":"';
93 jwk += base64Encode(key); 101 jwk += base64Encode(String.fromCharCode.apply(null, key));
94 jwk += '"}'; 102 jwk += '"}';
95 return jwk; 103 return jwk;
96 } 104 }
97 105
98 // Creates a JWK Set from multiple JWKs. 106 // Creates a JWK Set from multiple JWKs.
99 function createJWKSet() 107 function createJWKSet()
100 { 108 {
101 var jwkSet = '{"keys":['; 109 var jwkSet = '{"keys":[';
102 for (var i = 0; i < arguments.length; i++) { 110 for (var i = 0; i < arguments.length; i++) {
103 if (i != 0) 111 if (i != 0)
(...skipping 10 matching lines...) Expand all
114 // currently no way to report a failed test in the test harness, errors 122 // currently no way to report a failed test in the test harness, errors
115 // are reported using force_timeout(). 123 // are reported using force_timeout().
116 if (message) 124 if (message)
117 consoleWrite(message + ': ' + error.message); 125 consoleWrite(message + ': ' + error.message);
118 else if (error) 126 else if (error)
119 consoleWrite(error.message); 127 consoleWrite(error.message);
120 128
121 test.force_timeout(); 129 test.force_timeout();
122 test.done(); 130 test.done();
123 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698