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

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

Issue 379343003: Set callback interface on WebCDMSession after creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on promises 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 /* 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 virtual ~MediaKeySessionInitializer(); 106 virtual ~MediaKeySessionInitializer();
107 107
108 void completeWithSession(blink::WebContentDecryptionModuleResult::SessionSta tus); 108 void completeWithSession(blink::WebContentDecryptionModuleResult::SessionSta tus);
109 void completeWithDOMException(ExceptionCode, const String& errorMessage); 109 void completeWithDOMException(ExceptionCode, const String& errorMessage);
110 110
111 private: 111 private:
112 MediaKeySessionInitializer(ScriptState*, MediaKeys*, const String& initDataT ype, PassRefPtr<Uint8Array> initData, const String& sessionType); 112 MediaKeySessionInitializer(ScriptState*, MediaKeys*, const String& initDataT ype, PassRefPtr<Uint8Array> initData, const String& sessionType);
113 void timerFired(Timer<MediaKeySessionInitializer>*); 113 void timerFired(Timer<MediaKeySessionInitializer>*);
114 114
115 Persistent<MediaKeys> m_mediaKeys; 115 Persistent<MediaKeys> m_mediaKeys;
116 Persistent<MediaKeySession> m_session;
117 OwnPtr<blink::WebContentDecryptionModuleSession> m_cdmSession; 116 OwnPtr<blink::WebContentDecryptionModuleSession> m_cdmSession;
118 117
119 // The next 3 values are simply the initialization data saved so that the 118 // The next 3 values are simply the initialization data saved so that the
120 // asynchronous creation has the data needed. 119 // asynchronous creation has the data needed.
121 String m_initDataType; 120 String m_initDataType;
122 RefPtr<Uint8Array> m_initData; 121 RefPtr<Uint8Array> m_initData;
123 String m_sessionType; 122 String m_sessionType;
124 123
125 Timer<MediaKeySessionInitializer> m_timer; 124 Timer<MediaKeySessionInitializer> m_timer;
126 }; 125 };
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // with a new DOMException whose name is "InvalidAccessError". 198 // with a new DOMException whose name is "InvalidAccessError".
200 // 7.4.2 If the init data is not supported by the cdm, reject promise with 199 // 7.4.2 If the init data is not supported by the cdm, reject promise with
201 // a new DOMException whose name is "NotSupportedError". 200 // a new DOMException whose name is "NotSupportedError".
202 // 7.4.3 Let request be a request (e.g. a license request) generated based 201 // 7.4.3 Let request be a request (e.g. a license request) generated based
203 // on the init data, which is interpreteted per initDataType, and 202 // on the init data, which is interpreteted per initDataType, and
204 // sessionType. If sessionType is "temporary", the request is for a 203 // sessionType. If sessionType is "temporary", the request is for a
205 // temporary non-persisted license. If sessionType is "persistent", 204 // temporary non-persisted license. If sessionType is "persistent",
206 // the request is for a persistable license. 205 // the request is for a persistable license.
207 // 7.4.4 If the init data indicates a default URL, let default URL be 206 // 7.4.4 If the init data indicates a default URL, let default URL be
208 // that URL. The URL may be validated and/or normalized. 207 // that URL. The URL may be validated and/or normalized.
209 208 m_cdmSession = adoptPtr(cdm->createSession());
210 // Currently the client callback interface is passed to Chromium when
211 // creating the session on the Chromium side. As a result, we need to
212 // create the session now.
213 // FIXME: Add an API to allow the client interface to be specified later
214 // to WebContentDecryptionModuleSession, and then creating the
215 // MediaKeySession object can be done in completeWithSession().
216 m_session = adoptRefCountedGarbageCollectedWillBeNoop(new MediaKeySession(ex ecutionContext(), m_mediaKeys));
217 m_session->suspendIfNeeded();
218
219 m_cdmSession = adoptPtr(cdm->createSession(m_session));
220 NewMediaKeySessionResult* result = new NewMediaKeySessionResult(this); 209 NewMediaKeySessionResult* result = new NewMediaKeySessionResult(this);
221 m_cdmSession->initializeNewSession(m_initDataType, m_initData->data(), m_ini tData->length(), m_sessionType, result->result()); 210 m_cdmSession->initializeNewSession(m_initDataType, m_initData->data(), m_ini tData->length(), m_sessionType, result->result());
222 211
223 WTF_LOG(Media, "MediaKeySessionInitializer::timerFired done"); 212 WTF_LOG(Media, "MediaKeySessionInitializer::timerFired done");
224 // Note: As soon as the promise is resolved (or rejected), the 213 // Note: As soon as the promise is resolved (or rejected), the
225 // ScriptPromiseResolver object (|this|) is freed. So if 214 // ScriptPromiseResolver object (|this|) is freed. So if
226 // initializeNewSession() is synchronous, access to any members will crash. 215 // initializeNewSession() is synchronous, access to any members will crash.
227 } 216 }
228 217
229 void MediaKeySessionInitializer::completeWithSession(blink::WebContentDecryption ModuleResult::SessionStatus status) 218 void MediaKeySessionInitializer::completeWithSession(blink::WebContentDecryption ModuleResult::SessionStatus status)
230 { 219 {
231 WTF_LOG(Media, "MediaKeySessionInitializer::completeWithSession"); 220 WTF_LOG(Media, "MediaKeySessionInitializer::completeWithSession");
232 221
233 switch (status) { 222 switch (status) {
234 case blink::WebContentDecryptionModuleResult::NewSession: 223 case blink::WebContentDecryptionModuleResult::NewSession: {
235 // Resume MediaKeys::createSession(). 224 // Resume MediaKeys::createSession().
236 // 7.5 Let the session ID be a unique Session ID string. It may be 225 // 7.5 Let the session ID be a unique Session ID string. It may be
237 // obtained from cdm (it is). 226 // obtained from cdm (it is).
238 // 7.6 Let session be a new MediaKeySession object, and initialize it. 227 // 7.6 Let session be a new MediaKeySession object, and initialize it.
239 // (Object was created previously, complete the steps for 7.6). 228 // (Object was created previously, complete the steps for 7.6).
240 m_session->finishInitialization(m_cdmSession.release()); 229 MediaKeySession* session = adoptRefCountedGarbageCollectedWillBeNoop(new MediaKeySession(executionContext(), m_mediaKeys, m_cdmSession.release()));
acolwell GONE FROM CHROMIUM 2014/07/17 17:45:25 Isn't this a memory leak for a non-Oilpan build?
jrummell 2014/07/17 19:03:07 Shouldn't be. The object is passed back to JavaScr
acolwell GONE FROM CHROMIUM 2014/07/17 19:16:04 Ok. I'm just not used to the return value of adopt
jrummell 2014/07/17 21:33:48 For clarity, changed to use RefPtrWillBeRawPtr<>.
230 session->suspendIfNeeded();
241 231
242 // 7.7 If any of the preceding steps failed, reject promise with a 232 // 7.7 If any of the preceding steps failed, reject promise with a
243 // new DOMException whose name is the appropriate error name 233 // new DOMException whose name is the appropriate error name
244 // and that has an appropriate message. 234 // and that has an appropriate message.
245 // (Implemented by CDM/Chromium calling completeWithError()). 235 // (Implemented by CDM/Chromium calling completeWithError()).
246 236
247 // 7.8 Add an entry for the value of the sessionId attribute to the 237 // 7.8 Add an entry for the value of the sessionId attribute to the
248 // list of active session IDs for this object. 238 // list of active session IDs for this object.
249 // (Implemented in SessionIdAdapter). 239 // (Implemented in SessionIdAdapter).
250 240
251 // 7.9 Run the Queue a "message" Event algorithm on the session, 241 // 7.9 Run the Queue a "message" Event algorithm on the session,
252 // providing request and default URL. 242 // providing request and default URL.
253 // (Done by the CDM). 243 // (Done by the CDM).
254 244
255 // 7.10 Resolve promise with session. 245 // 7.10 Resolve promise with session.
256 resolve(m_session.get()); 246 resolve(session);
257 WTF_LOG(Media, "MediaKeySessionInitializer::completeWithSession done w/s ession"); 247 WTF_LOG(Media, "MediaKeySessionInitializer::completeWithSession done w/s ession");
258 return; 248 return;
249 }
259 250
260 case blink::WebContentDecryptionModuleResult::SessionNotFound: 251 case blink::WebContentDecryptionModuleResult::SessionNotFound:
261 // Step 4.7.1 of MediaKeys::loadSession(): If there is no data 252 // Step 4.7.1 of MediaKeys::loadSession(): If there is no data
262 // stored for the sessionId in the origin, resolve promise with 253 // stored for the sessionId in the origin, resolve promise with
263 // undefined. 254 // undefined.
264 resolve(V8UndefinedType()); 255 resolve(V8UndefinedType());
265 WTF_LOG(Media, "MediaKeySessionInitializer::completeWithSession done w/u ndefined"); 256 WTF_LOG(Media, "MediaKeySessionInitializer::completeWithSession done w/u ndefined");
266 return; 257 return;
267 258
268 case blink::WebContentDecryptionModuleResult::SessionAlreadyExists: 259 case blink::WebContentDecryptionModuleResult::SessionAlreadyExists:
(...skipping 11 matching lines...) Expand all
280 reject(DOMException::create(code, errorMessage)); 271 reject(DOMException::create(code, errorMessage));
281 } 272 }
282 273
283 ScriptPromise MediaKeySession::create(ScriptState* scriptState, MediaKeys* media Keys, const String& initDataType, PassRefPtr<Uint8Array> initData, const String& sessionType) 274 ScriptPromise MediaKeySession::create(ScriptState* scriptState, MediaKeys* media Keys, const String& initDataType, PassRefPtr<Uint8Array> initData, const String& sessionType)
284 { 275 {
285 // Since creation is done asynchronously, use MediaKeySessionInitializer 276 // Since creation is done asynchronously, use MediaKeySessionInitializer
286 // to do it. 277 // to do it.
287 return MediaKeySessionInitializer::create(scriptState, mediaKeys, initDataTy pe, initData, sessionType); 278 return MediaKeySessionInitializer::create(scriptState, mediaKeys, initDataTy pe, initData, sessionType);
288 } 279 }
289 280
290 MediaKeySession::MediaKeySession(ExecutionContext* context, MediaKeys* keys) 281 MediaKeySession::MediaKeySession(ExecutionContext* context, MediaKeys* keys, Pas sOwnPtr<blink::WebContentDecryptionModuleSession> cdmSession)
291 : ActiveDOMObject(context) 282 : ActiveDOMObject(context)
292 , m_keySystem(keys->keySystem()) 283 , m_keySystem(keys->keySystem())
293 , m_asyncEventQueue(GenericEventQueue::create(this)) 284 , m_asyncEventQueue(GenericEventQueue::create(this))
285 , m_session(cdmSession)
294 , m_keys(keys) 286 , m_keys(keys)
295 , m_isClosed(false) 287 , m_isClosed(false)
296 , m_actionTimer(this, &MediaKeySession::actionTimerFired) 288 , m_actionTimer(this, &MediaKeySession::actionTimerFired)
297 { 289 {
298 WTF_LOG(Media, "MediaKeySession(%p)::MediaKeySession", this); 290 WTF_LOG(Media, "MediaKeySession(%p)::MediaKeySession", this);
299 ScriptWrappable::init(this); 291 ScriptWrappable::init(this);
292 m_session->setClientInterface(this);
293
294 // Resume MediaKeys::createSession() at step 7.6.
295 // 7.6.1 Set the error attribute to null.
296 ASSERT(!m_error);
297
298 // 7.6.2 Set the sessionId attribute to session ID.
299 ASSERT(!sessionId().isEmpty());
300
301 // 7.6.3 Let expiration be NaN.
302 // 7.6.4 Let closed be a new promise.
303 // 7.6.5 Let the session type be sessionType.
304 // FIXME: Implement the previous 3 values.
300 } 305 }
301 306
302 MediaKeySession::~MediaKeySession() 307 MediaKeySession::~MediaKeySession()
303 { 308 {
304 WTF_LOG(Media, "MediaKeySession(%p)::~MediaKeySession", this); 309 WTF_LOG(Media, "MediaKeySession(%p)::~MediaKeySession", this);
305 m_session.clear(); 310 m_session.clear();
306 #if !ENABLE(OILPAN) 311 #if !ENABLE(OILPAN)
307 // MediaKeySession and m_asyncEventQueue always become unreachable 312 // MediaKeySession and m_asyncEventQueue always become unreachable
308 // together. So MediaKeySession and m_asyncEventQueue are destructed in the 313 // together. So MediaKeySession and m_asyncEventQueue are destructed in the
309 // same GC. We don't need to call cancelAllEvents explicitly in Oilpan. 314 // same GC. We don't need to call cancelAllEvents explicitly in Oilpan.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // 3.2.1 Process the close request. Do not remove stored session dat a. 422 // 3.2.1 Process the close request. Do not remove stored session dat a.
418 // 3.2.2 If the previous step caused the session to be closed, run t he 423 // 3.2.2 If the previous step caused the session to be closed, run t he
419 // Session Close algorithm on this object. 424 // Session Close algorithm on this object.
420 // 3.3 Resolve promise with undefined. 425 // 3.3 Resolve promise with undefined.
421 m_session->release(action->result()->result()); 426 m_session->release(action->result()->result());
422 break; 427 break;
423 } 428 }
424 } 429 }
425 } 430 }
426 431
427 void MediaKeySession::finishInitialization(PassOwnPtr<blink::WebContentDecryptio nModuleSession> cdmSession)
428 {
429 ASSERT(cdmSession);
430 m_session = cdmSession;
431
432 // Resume MediaKeys::createSession() at step 7.6.
433 // 7.6.1 Set the error attribute to null.
434 ASSERT(!m_error);
435
436 // 7.6.2 Set the sessionId attribute to session ID.
437 ASSERT(!sessionId().isEmpty());
438
439 // 7.6.3 Let expiration be NaN..
440 // 7.6.4 Let closed be a new promise.
441 // 7.6.5 Let the session type be sessionType.
442 // FIXME: Implement the previous 3 values.
443 }
444
445 // Queue a task to fire a simple event named keymessage at the new object 432 // Queue a task to fire a simple event named keymessage at the new object
446 void MediaKeySession::message(const unsigned char* message, size_t messageLength , const blink::WebURL& destinationURL) 433 void MediaKeySession::message(const unsigned char* message, size_t messageLength , const blink::WebURL& destinationURL)
447 { 434 {
448 WTF_LOG(Media, "MediaKeySession(%p)::message", this); 435 WTF_LOG(Media, "MediaKeySession(%p)::message", this);
449 436
450 MediaKeyMessageEventInit init; 437 MediaKeyMessageEventInit init;
451 init.bubbles = false; 438 init.bubbles = false;
452 init.cancelable = false; 439 init.cancelable = false;
453 init.message = Uint8Array::create(message, messageLength); 440 init.message = Uint8Array::create(message, messageLength);
454 init.destinationURL = destinationURL.string(); 441 init.destinationURL = destinationURL.string();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 void MediaKeySession::trace(Visitor* visitor) 554 void MediaKeySession::trace(Visitor* visitor)
568 { 555 {
569 visitor->trace(m_error); 556 visitor->trace(m_error);
570 visitor->trace(m_asyncEventQueue); 557 visitor->trace(m_asyncEventQueue);
571 visitor->trace(m_pendingActions); 558 visitor->trace(m_pendingActions);
572 visitor->trace(m_keys); 559 visitor->trace(m_keys);
573 EventTargetWithInlineData::trace(visitor); 560 EventTargetWithInlineData::trace(visitor);
574 } 561 }
575 562
576 } 563 }
OLDNEW
« no previous file with comments | « Source/modules/encryptedmedia/MediaKeySession.h ('k') | public/platform/WebContentDecryptionModule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698