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

Side by Side Diff: Source/modules/encryptedmedia/MediaKeys.cpp

Issue 397463005: Change EME WebIDL to use ArrayBuffer/ArrayBufferView. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase 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
« no previous file with comments | « Source/modules/encryptedmedia/MediaKeys.h ('k') | Source/modules/encryptedmedia/MediaKeys.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 24 matching lines...) Expand all
35 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" 35 #include "modules/encryptedmedia/MediaKeyMessageEvent.h"
36 #include "modules/encryptedmedia/MediaKeySession.h" 36 #include "modules/encryptedmedia/MediaKeySession.h"
37 #include "modules/encryptedmedia/MediaKeysController.h" 37 #include "modules/encryptedmedia/MediaKeysController.h"
38 #include "platform/ContentType.h" 38 #include "platform/ContentType.h"
39 #include "platform/Logging.h" 39 #include "platform/Logging.h"
40 #include "platform/MIMETypeRegistry.h" 40 #include "platform/MIMETypeRegistry.h"
41 #include "platform/Timer.h" 41 #include "platform/Timer.h"
42 #include "platform/UUID.h" 42 #include "platform/UUID.h"
43 #include "public/platform/Platform.h" 43 #include "public/platform/Platform.h"
44 #include "public/platform/WebContentDecryptionModule.h" 44 #include "public/platform/WebContentDecryptionModule.h"
45 #include "wtf/ArrayBuffer.h"
46 #include "wtf/ArrayBufferView.h"
45 #include "wtf/RefPtr.h" 47 #include "wtf/RefPtr.h"
46 #include "wtf/Uint8Array.h"
47 48
48 #if ENABLE(ASSERT) 49 #if ENABLE(ASSERT)
49 namespace { 50 namespace {
50 51
51 // The list of possible values for |sessionType| passed to createSession(). 52 // The list of possible values for |sessionType| passed to createSession().
52 const char* kTemporary = "temporary"; 53 const char* kTemporary = "temporary";
53 const char* kPersistent = "persistent"; 54 const char* kPersistent = "persistent";
54 55
55 } // namespace 56 } // namespace
56 #endif 57 #endif
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // Step 4.4 of MediaKeys::create(): 191 // Step 4.4 of MediaKeys::create():
191 // 4.4.1 Set the keySystem attribute to keySystem. 192 // 4.4.1 Set the keySystem attribute to keySystem.
192 ASSERT(!m_keySystem.isEmpty()); 193 ASSERT(!m_keySystem.isEmpty());
193 } 194 }
194 195
195 MediaKeys::~MediaKeys() 196 MediaKeys::~MediaKeys()
196 { 197 {
197 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); 198 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this);
198 } 199 }
199 200
200 ScriptPromise MediaKeys::createSession(ScriptState* scriptState, const String& i nitDataType, Uint8Array* initData, const String& sessionType) 201 ScriptPromise MediaKeys::createSession(ScriptState* scriptState, const String& i nitDataType, ArrayBuffer* initData, const String& sessionType)
201 { 202 {
202 WTF_LOG(Media, "MediaKeys(%p)::createSession(%s, %d)", this, initDataType.as cii().data(), initData->length()); 203 RefPtr<ArrayBuffer> initDataCopy = ArrayBuffer::create(initData->data(), ini tData->byteLength());
204 return createSessionInternal(scriptState, initDataType, initDataCopy.release (), sessionType);
205 }
206
207 ScriptPromise MediaKeys::createSession(ScriptState* scriptState, const String& i nitDataType, ArrayBufferView* initData, const String& sessionType)
208 {
209 RefPtr<ArrayBuffer> initDataCopy = ArrayBuffer::create(initData->baseAddress (), initData->byteLength());
210 return createSessionInternal(scriptState, initDataType, initDataCopy.release (), sessionType);
211 }
212
213 ScriptPromise MediaKeys::createSessionInternal(ScriptState* scriptState, const S tring& initDataType, PassRefPtr<ArrayBuffer> initData, const String& sessionType )
214 {
215 WTF_LOG(Media, "MediaKeys(%p)::createSession(%s, %d)", this, initDataType.as cii().data(), initData->byteLength());
203 216
204 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-createsession>: 217 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-createsession>:
205 // The createSession(initDataType, initData, sessionType) method creates a 218 // The createSession(initDataType, initData, sessionType) method creates a
206 // new MediaKeySession object for the initData. It must run the following st eps: 219 // new MediaKeySession object for the initData. It must run the following st eps:
207 220
208 // 1. If initDataType is an empty string, return a promise rejected with a 221 // 1. If initDataType is an empty string, return a promise rejected with a
209 // new DOMException whose name is "InvalidAccessError". 222 // new DOMException whose name is "InvalidAccessError".
210 if (initDataType.isEmpty()) { 223 if (initDataType.isEmpty()) {
211 return createRejectedPromise(scriptState, InvalidAccessError, "The initD ataType parameter is empty."); 224 return createRejectedPromise(scriptState, InvalidAccessError, "The initD ataType parameter is empty.");
212 } 225 }
213 226
214 // 2. If initData is an empty array, return a promise rejected with a new 227 // 2. If initData is an empty array, return a promise rejected with a new
215 // DOMException whose name is"InvalidAccessError". 228 // DOMException whose name is"InvalidAccessError".
216 if (!initData->length()) { 229 if (!initData->byteLength()) {
217 return createRejectedPromise(scriptState, InvalidAccessError, "The initD ata parameter is empty."); 230 return createRejectedPromise(scriptState, InvalidAccessError, "The initD ata parameter is empty.");
218 } 231 }
219 232
220 // 3. If initDataType is not an initialization data type supported by the 233 // 3. If initDataType is not an initialization data type supported by the
221 // content decryption module corresponding to the keySystem, return a 234 // content decryption module corresponding to the keySystem, return a
222 // promise rejected with a new DOMException whose name is 235 // promise rejected with a new DOMException whose name is
223 // "NotSupportedError". String comparison is case-sensitive. 236 // "NotSupportedError". String comparison is case-sensitive.
224 if (!isKeySystemSupportedWithInitDataType(m_keySystem, initDataType)) { 237 if (!isKeySystemSupportedWithInitDataType(m_keySystem, initDataType)) {
225 return createRejectedPromise(scriptState, NotSupportedError, "The initia lization data type '" + initDataType + "' is not supported by the key system."); 238 return createRejectedPromise(scriptState, NotSupportedError, "The initia lization data type '" + initDataType + "' is not supported by the key system.");
226 } 239 }
227 240
228 // 4. If sessionType is not supported by the content decryption module 241 // 4. If sessionType is not supported by the content decryption module
229 // corresponding to the keySystem, return a promise rejected with a new 242 // corresponding to the keySystem, return a promise rejected with a new
230 // DOMException whose name is "NotSupportedError". 243 // DOMException whose name is "NotSupportedError".
231 // Since this is typed by the IDL, we should not see any invalid values. 244 // Since this is typed by the IDL, we should not see any invalid values.
232 // FIXME: Check whether sessionType is actually supported by the CDM. 245 // FIXME: Check whether sessionType is actually supported by the CDM.
233 ASSERT(sessionType == kTemporary || sessionType == kPersistent); 246 ASSERT(sessionType == kTemporary || sessionType == kPersistent);
234 247
235 // 5. Let init data be a copy of the contents of the initData parameter. 248 // 5. Let init data be a copy of the contents of the initData parameter.
236 RefPtr<Uint8Array> initDataCopy = Uint8Array::create(initData->data(), initD ata->length()); 249 // (Copied in the caller.)
237
238 // 6. Let promise be a new promise. 250 // 6. Let promise be a new promise.
239 // 7. Asynchronously create and initialize the session. 251 // 7. Asynchronously create and initialize the session.
240 // 8. Return promise. 252 // 8. Return promise.
241 return MediaKeySession::create(scriptState, this, initDataType, initDataCopy .release(), sessionType); 253 return MediaKeySession::create(scriptState, this, initDataType, initData, se ssionType);
242 } 254 }
243 255
244 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy pe) 256 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy pe)
245 { 257 {
246 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data( ), contentType.ascii().data()); 258 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data( ), contentType.ascii().data());
247 259
248 // 1. If keySystem is an empty string, return false and abort these steps. 260 // 1. If keySystem is an empty string, return false and abort these steps.
249 if (keySystem.isEmpty()) 261 if (keySystem.isEmpty())
250 return false; 262 return false;
251 263
(...skipping 22 matching lines...) Expand all
274 286
275 void MediaKeys::contextDestroyed() 287 void MediaKeys::contextDestroyed()
276 { 288 {
277 ContextLifecycleObserver::contextDestroyed(); 289 ContextLifecycleObserver::contextDestroyed();
278 290
279 // We don't need the CDM anymore. 291 // We don't need the CDM anymore.
280 m_cdm.clear(); 292 m_cdm.clear();
281 } 293 }
282 294
283 } 295 }
OLDNEW
« no previous file with comments | « Source/modules/encryptedmedia/MediaKeys.h ('k') | Source/modules/encryptedmedia/MediaKeys.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698