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

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

Issue 2407013002: EME: Improve promise lifetime (Closed)
Patch Set: more checks Created 4 years, 2 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 20 matching lines...) Expand all
31 #include "bindings/core/v8/ScriptState.h" 31 #include "bindings/core/v8/ScriptState.h"
32 #include "core/dom/DOMArrayBuffer.h" 32 #include "core/dom/DOMArrayBuffer.h"
33 #include "core/dom/DOMException.h" 33 #include "core/dom/DOMException.h"
34 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
35 #include "core/events/Event.h" 35 #include "core/events/Event.h"
36 #include "core/events/GenericEventQueue.h" 36 #include "core/events/GenericEventQueue.h"
37 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h" 37 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h"
38 #include "modules/encryptedmedia/EncryptedMediaUtils.h" 38 #include "modules/encryptedmedia/EncryptedMediaUtils.h"
39 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" 39 #include "modules/encryptedmedia/MediaKeyMessageEvent.h"
40 #include "modules/encryptedmedia/MediaKeys.h" 40 #include "modules/encryptedmedia/MediaKeys.h"
41 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResultPromise.h"
42 #include "platform/ContentDecryptionModuleResult.h" 41 #include "platform/ContentDecryptionModuleResult.h"
43 #include "platform/ContentType.h" 42 #include "platform/ContentType.h"
44 #include "platform/Timer.h" 43 #include "platform/Timer.h"
45 #include "public/platform/WebContentDecryptionModule.h" 44 #include "public/platform/WebContentDecryptionModule.h"
46 #include "public/platform/WebContentDecryptionModuleException.h" 45 #include "public/platform/WebContentDecryptionModuleException.h"
47 #include "public/platform/WebContentDecryptionModuleSession.h" 46 #include "public/platform/WebContentDecryptionModuleSession.h"
48 #include "public/platform/WebEncryptedMediaKeyInformation.h" 47 #include "public/platform/WebEncryptedMediaKeyInformation.h"
49 #include "public/platform/WebString.h" 48 #include "public/platform/WebString.h"
50 #include "public/platform/WebURL.h" 49 #include "public/platform/WebURL.h"
51 #include "wtf/ASCIICType.h" 50 #include "wtf/ASCIICType.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 class NewSessionResultPromise : public ContentDecryptionModuleResultPromise { 223 class NewSessionResultPromise : public ContentDecryptionModuleResultPromise {
225 public: 224 public:
226 NewSessionResultPromise(ScriptState* scriptState, MediaKeySession* session) 225 NewSessionResultPromise(ScriptState* scriptState, MediaKeySession* session)
227 : ContentDecryptionModuleResultPromise(scriptState), m_session(session) {} 226 : ContentDecryptionModuleResultPromise(scriptState), m_session(session) {}
228 227
229 ~NewSessionResultPromise() override {} 228 ~NewSessionResultPromise() override {}
230 229
231 // ContentDecryptionModuleResult implementation. 230 // ContentDecryptionModuleResult implementation.
232 void completeWithSession( 231 void completeWithSession(
233 WebContentDecryptionModuleResult::SessionStatus status) override { 232 WebContentDecryptionModuleResult::SessionStatus status) override {
233 if (!isValidToFulfillPromise())
234 return;
235
234 if (status != WebContentDecryptionModuleResult::NewSession) { 236 if (status != WebContentDecryptionModuleResult::NewSession) {
235 NOTREACHED(); 237 NOTREACHED();
236 reject(InvalidStateError, "Unexpected completion."); 238 reject(InvalidStateError, "Unexpected completion.");
237 } 239 }
238 240
239 m_session->finishGenerateRequest(); 241 m_session->finishGenerateRequest();
240 resolve(); 242 resolve();
241 } 243 }
242 244
243 DEFINE_INLINE_TRACE() { 245 DEFINE_INLINE_TRACE() {
(...skipping 13 matching lines...) Expand all
257 class LoadSessionResultPromise : public ContentDecryptionModuleResultPromise { 259 class LoadSessionResultPromise : public ContentDecryptionModuleResultPromise {
258 public: 260 public:
259 LoadSessionResultPromise(ScriptState* scriptState, MediaKeySession* session) 261 LoadSessionResultPromise(ScriptState* scriptState, MediaKeySession* session)
260 : ContentDecryptionModuleResultPromise(scriptState), m_session(session) {} 262 : ContentDecryptionModuleResultPromise(scriptState), m_session(session) {}
261 263
262 ~LoadSessionResultPromise() override {} 264 ~LoadSessionResultPromise() override {}
263 265
264 // ContentDecryptionModuleResult implementation. 266 // ContentDecryptionModuleResult implementation.
265 void completeWithSession( 267 void completeWithSession(
266 WebContentDecryptionModuleResult::SessionStatus status) override { 268 WebContentDecryptionModuleResult::SessionStatus status) override {
269 if (!isValidToFulfillPromise())
270 return;
271
267 switch (status) { 272 switch (status) {
268 case WebContentDecryptionModuleResult::NewSession: 273 case WebContentDecryptionModuleResult::NewSession:
269 m_session->finishLoad(); 274 m_session->finishLoad();
270 resolve(true); 275 resolve(true);
271 return; 276 return;
272 277
273 case WebContentDecryptionModuleResult::SessionNotFound: 278 case WebContentDecryptionModuleResult::SessionNotFound:
274 resolve(false); 279 resolve(false);
275 return; 280 return;
276 281
277 case WebContentDecryptionModuleResult::SessionAlreadyExists: 282 case WebContentDecryptionModuleResult::SessionAlreadyExists:
278 NOTREACHED(); 283 NOTREACHED();
279 reject(InvalidStateError, "Unexpected completion."); 284 reject(InvalidStateError, "Unexpected completion.");
280 return; 285 return;
281 } 286 }
282 287
283 NOTREACHED(); 288 NOTREACHED();
284 } 289 }
285 290
286 DEFINE_INLINE_TRACE() { 291 DEFINE_INLINE_TRACE() {
287 visitor->trace(m_session); 292 visitor->trace(m_session);
288 ContentDecryptionModuleResultPromise::trace(visitor); 293 ContentDecryptionModuleResultPromise::trace(visitor);
289 } 294 }
290 295
291 private: 296 private:
292 Member<MediaKeySession> m_session; 297 Member<MediaKeySession> m_session;
293 }; 298 };
294 299
300 // This class wraps the promise resolver used by update/close/remove. The
301 // implementation of complete() will resolve the promise with void. All other
302 // complete() methods are not expected to be called (and will reject the
303 // promise).
304 class SimpleResultPromise : public ContentDecryptionModuleResultPromise {
305 public:
306 SimpleResultPromise(ScriptState* scriptState, MediaKeySession* session)
307 : ContentDecryptionModuleResultPromise(scriptState), m_session(session) {}
308
309 ~SimpleResultPromise() override {}
310
311 // ContentDecryptionModuleResultPromise implementation.
312 void complete() override {
313 if (!isValidToFulfillPromise())
314 return;
315
316 resolve();
317 }
318
319 DEFINE_INLINE_TRACE() {
320 visitor->trace(m_session);
321 ContentDecryptionModuleResultPromise::trace(visitor);
322 }
323
324 private:
325 // Keep track of the MediaKeySession that created this promise so that it
326 // remains reachable as long as this promise is reachable.
327 Member<MediaKeySession> m_session;
328 };
329
295 MediaKeySession* MediaKeySession::create( 330 MediaKeySession* MediaKeySession::create(
296 ScriptState* scriptState, 331 ScriptState* scriptState,
297 MediaKeys* mediaKeys, 332 MediaKeys* mediaKeys,
298 WebEncryptedMediaSessionType sessionType) { 333 WebEncryptedMediaSessionType sessionType) {
299 MediaKeySession* session = 334 MediaKeySession* session =
300 new MediaKeySession(scriptState, mediaKeys, sessionType); 335 new MediaKeySession(scriptState, mediaKeys, sessionType);
301 session->suspendIfNeeded(); 336 session->suspendIfNeeded();
302 return session; 337 return session;
303 } 338 }
304 339
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 return ScriptPromise::rejectWithDOMException( 574 return ScriptPromise::rejectWithDOMException(
540 scriptState, DOMException::create(InvalidAccessError, 575 scriptState, DOMException::create(InvalidAccessError,
541 "The response parameter is empty.")); 576 "The response parameter is empty."));
542 } 577 }
543 578
544 // 3. Let response copy be a copy of the contents of the response parameter. 579 // 3. Let response copy be a copy of the contents of the response parameter.
545 DOMArrayBuffer* responseCopy = 580 DOMArrayBuffer* responseCopy =
546 DOMArrayBuffer::create(response.data(), response.byteLength()); 581 DOMArrayBuffer::create(response.data(), response.byteLength());
547 582
548 // 4. Let promise be a new promise. 583 // 4. Let promise be a new promise.
549 SimpleContentDecryptionModuleResultPromise* result = 584 SimpleResultPromise* result = new SimpleResultPromise(scriptState, this);
550 new SimpleContentDecryptionModuleResultPromise(scriptState);
551 ScriptPromise promise = result->promise(); 585 ScriptPromise promise = result->promise();
552 586
553 // 5. Run the following steps asynchronously (documented in 587 // 5. Run the following steps asynchronously (documented in
554 // actionTimerFired()) 588 // actionTimerFired())
555 m_pendingActions.append( 589 m_pendingActions.append(
556 PendingAction::CreatePendingUpdate(result, responseCopy)); 590 PendingAction::CreatePendingUpdate(result, responseCopy));
557 if (!m_actionTimer.isActive()) 591 if (!m_actionTimer.isActive())
558 m_actionTimer.startOneShot(0, BLINK_FROM_HERE); 592 m_actionTimer.startOneShot(0, BLINK_FROM_HERE);
559 593
560 // 6. Return promise. 594 // 6. Return promise.
(...skipping 12 matching lines...) Expand all
573 // with a new DOMException whose name is "InvalidStateError". 607 // with a new DOMException whose name is "InvalidStateError".
574 if (!m_isCallable) 608 if (!m_isCallable)
575 return CreateRejectedPromiseNotCallable(scriptState); 609 return CreateRejectedPromiseNotCallable(scriptState);
576 610
577 // 2. If the Session Close algorithm has been run on this object, 611 // 2. If the Session Close algorithm has been run on this object,
578 // return a resolved promise. 612 // return a resolved promise.
579 if (m_isClosed) 613 if (m_isClosed)
580 return ScriptPromise::cast(scriptState, ScriptValue()); 614 return ScriptPromise::cast(scriptState, ScriptValue());
581 615
582 // 3. Let promise be a new promise. 616 // 3. Let promise be a new promise.
583 SimpleContentDecryptionModuleResultPromise* result = 617 SimpleResultPromise* result = new SimpleResultPromise(scriptState, this);
584 new SimpleContentDecryptionModuleResultPromise(scriptState);
585 ScriptPromise promise = result->promise(); 618 ScriptPromise promise = result->promise();
586 619
587 // 4. Run the following steps asynchronously (documented in 620 // 4. Run the following steps asynchronously (documented in
588 // actionTimerFired()). 621 // actionTimerFired()).
589 m_pendingActions.append(PendingAction::CreatePendingClose(result)); 622 m_pendingActions.append(PendingAction::CreatePendingClose(result));
590 if (!m_actionTimer.isActive()) 623 if (!m_actionTimer.isActive())
591 m_actionTimer.startOneShot(0, BLINK_FROM_HERE); 624 m_actionTimer.startOneShot(0, BLINK_FROM_HERE);
592 625
593 // 5. Return promise. 626 // 5. Return promise.
594 return promise; 627 return promise;
(...skipping 25 matching lines...) Expand all
620 // 3. If the Session Close algorithm has been run on this object, return a 653 // 3. If the Session Close algorithm has been run on this object, return a
621 // promise rejected with a new DOMException whose name is 654 // promise rejected with a new DOMException whose name is
622 // "InvalidStateError". 655 // "InvalidStateError".
623 if (m_isClosed) { 656 if (m_isClosed) {
624 return ScriptPromise::rejectWithDOMException( 657 return ScriptPromise::rejectWithDOMException(
625 scriptState, DOMException::create(InvalidStateError, 658 scriptState, DOMException::create(InvalidStateError,
626 "The session is already closed.")); 659 "The session is already closed."));
627 } 660 }
628 661
629 // 4. Let promise be a new promise. 662 // 4. Let promise be a new promise.
630 SimpleContentDecryptionModuleResultPromise* result = 663 SimpleResultPromise* result = new SimpleResultPromise(scriptState, this);
631 new SimpleContentDecryptionModuleResultPromise(scriptState);
632 ScriptPromise promise = result->promise(); 664 ScriptPromise promise = result->promise();
633 665
634 // 5. Run the following steps asynchronously (documented in 666 // 5. Run the following steps asynchronously (documented in
635 // actionTimerFired()). 667 // actionTimerFired()).
636 m_pendingActions.append(PendingAction::CreatePendingRemove(result)); 668 m_pendingActions.append(PendingAction::CreatePendingRemove(result));
637 if (!m_actionTimer.isActive()) 669 if (!m_actionTimer.isActive())
638 m_actionTimer.startOneShot(0, BLINK_FROM_HERE); 670 m_actionTimer.startOneShot(0, BLINK_FROM_HERE);
639 671
640 // 6. Return promise. 672 // 6. Return promise.
641 return promise; 673 return promise;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 visitor->trace(m_asyncEventQueue); 989 visitor->trace(m_asyncEventQueue);
958 visitor->trace(m_pendingActions); 990 visitor->trace(m_pendingActions);
959 visitor->trace(m_mediaKeys); 991 visitor->trace(m_mediaKeys);
960 visitor->trace(m_keyStatusesMap); 992 visitor->trace(m_keyStatusesMap);
961 visitor->trace(m_closedPromise); 993 visitor->trace(m_closedPromise);
962 EventTargetWithInlineData::trace(visitor); 994 EventTargetWithInlineData::trace(visitor);
963 ActiveDOMObject::trace(visitor); 995 ActiveDOMObject::trace(visitor);
964 } 996 }
965 997
966 } // namespace blink 998 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698