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

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

Issue 2407013002: EME: Improve promise lifetime (Closed)
Patch Set: remove m_contextDestroyed 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;
xhwang 2016/10/13 19:29:58 We are checking this in both the sub class and bas
jrummell 2016/10/14 00:03:31 We need to check before we attempt to create any o
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 { resolve(); }
xhwang 2016/10/13 19:29:58 Just FWIW, we are not checking isValidToFulfillPro
jrummell 2016/10/14 00:03:31 Added.
313
314 DEFINE_INLINE_TRACE() {
315 visitor->trace(m_session);
316 ContentDecryptionModuleResultPromise::trace(visitor);
317 }
318
319 private:
320 Member<MediaKeySession> m_session;
xhwang 2016/10/13 19:29:58 Add a comment about why we need this here.
jrummell 2016/10/14 00:03:31 Done.
321 };
322
295 MediaKeySession* MediaKeySession::create( 323 MediaKeySession* MediaKeySession::create(
296 ScriptState* scriptState, 324 ScriptState* scriptState,
297 MediaKeys* mediaKeys, 325 MediaKeys* mediaKeys,
298 WebEncryptedMediaSessionType sessionType) { 326 WebEncryptedMediaSessionType sessionType) {
299 MediaKeySession* session = 327 MediaKeySession* session =
300 new MediaKeySession(scriptState, mediaKeys, sessionType); 328 new MediaKeySession(scriptState, mediaKeys, sessionType);
301 session->suspendIfNeeded(); 329 session->suspendIfNeeded();
302 return session; 330 return session;
303 } 331 }
304 332
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 return ScriptPromise::rejectWithDOMException( 567 return ScriptPromise::rejectWithDOMException(
540 scriptState, DOMException::create(InvalidAccessError, 568 scriptState, DOMException::create(InvalidAccessError,
541 "The response parameter is empty.")); 569 "The response parameter is empty."));
542 } 570 }
543 571
544 // 3. Let response copy be a copy of the contents of the response parameter. 572 // 3. Let response copy be a copy of the contents of the response parameter.
545 DOMArrayBuffer* responseCopy = 573 DOMArrayBuffer* responseCopy =
546 DOMArrayBuffer::create(response.data(), response.byteLength()); 574 DOMArrayBuffer::create(response.data(), response.byteLength());
547 575
548 // 4. Let promise be a new promise. 576 // 4. Let promise be a new promise.
549 SimpleContentDecryptionModuleResultPromise* result = 577 SimpleResultPromise* result = new SimpleResultPromise(scriptState, this);
550 new SimpleContentDecryptionModuleResultPromise(scriptState);
551 ScriptPromise promise = result->promise(); 578 ScriptPromise promise = result->promise();
552 579
553 // 5. Run the following steps asynchronously (documented in 580 // 5. Run the following steps asynchronously (documented in
554 // actionTimerFired()) 581 // actionTimerFired())
555 m_pendingActions.append( 582 m_pendingActions.append(
556 PendingAction::CreatePendingUpdate(result, responseCopy)); 583 PendingAction::CreatePendingUpdate(result, responseCopy));
557 if (!m_actionTimer.isActive()) 584 if (!m_actionTimer.isActive())
558 m_actionTimer.startOneShot(0, BLINK_FROM_HERE); 585 m_actionTimer.startOneShot(0, BLINK_FROM_HERE);
559 586
560 // 6. Return promise. 587 // 6. Return promise.
(...skipping 12 matching lines...) Expand all
573 // with a new DOMException whose name is "InvalidStateError". 600 // with a new DOMException whose name is "InvalidStateError".
574 if (!m_isCallable) 601 if (!m_isCallable)
575 return CreateRejectedPromiseNotCallable(scriptState); 602 return CreateRejectedPromiseNotCallable(scriptState);
576 603
577 // 2. If the Session Close algorithm has been run on this object, 604 // 2. If the Session Close algorithm has been run on this object,
578 // return a resolved promise. 605 // return a resolved promise.
579 if (m_isClosed) 606 if (m_isClosed)
580 return ScriptPromise::cast(scriptState, ScriptValue()); 607 return ScriptPromise::cast(scriptState, ScriptValue());
581 608
582 // 3. Let promise be a new promise. 609 // 3. Let promise be a new promise.
583 SimpleContentDecryptionModuleResultPromise* result = 610 SimpleResultPromise* result = new SimpleResultPromise(scriptState, this);
584 new SimpleContentDecryptionModuleResultPromise(scriptState);
585 ScriptPromise promise = result->promise(); 611 ScriptPromise promise = result->promise();
586 612
587 // 4. Run the following steps asynchronously (documented in 613 // 4. Run the following steps asynchronously (documented in
588 // actionTimerFired()). 614 // actionTimerFired()).
589 m_pendingActions.append(PendingAction::CreatePendingClose(result)); 615 m_pendingActions.append(PendingAction::CreatePendingClose(result));
590 if (!m_actionTimer.isActive()) 616 if (!m_actionTimer.isActive())
591 m_actionTimer.startOneShot(0, BLINK_FROM_HERE); 617 m_actionTimer.startOneShot(0, BLINK_FROM_HERE);
592 618
593 // 5. Return promise. 619 // 5. Return promise.
594 return promise; 620 return promise;
(...skipping 25 matching lines...) Expand all
620 // 3. If the Session Close algorithm has been run on this object, return a 646 // 3. If the Session Close algorithm has been run on this object, return a
621 // promise rejected with a new DOMException whose name is 647 // promise rejected with a new DOMException whose name is
622 // "InvalidStateError". 648 // "InvalidStateError".
623 if (m_isClosed) { 649 if (m_isClosed) {
624 return ScriptPromise::rejectWithDOMException( 650 return ScriptPromise::rejectWithDOMException(
625 scriptState, DOMException::create(InvalidStateError, 651 scriptState, DOMException::create(InvalidStateError,
626 "The session is already closed.")); 652 "The session is already closed."));
627 } 653 }
628 654
629 // 4. Let promise be a new promise. 655 // 4. Let promise be a new promise.
630 SimpleContentDecryptionModuleResultPromise* result = 656 SimpleResultPromise* result = new SimpleResultPromise(scriptState, this);
631 new SimpleContentDecryptionModuleResultPromise(scriptState);
632 ScriptPromise promise = result->promise(); 657 ScriptPromise promise = result->promise();
633 658
634 // 5. Run the following steps asynchronously (documented in 659 // 5. Run the following steps asynchronously (documented in
635 // actionTimerFired()). 660 // actionTimerFired()).
636 m_pendingActions.append(PendingAction::CreatePendingRemove(result)); 661 m_pendingActions.append(PendingAction::CreatePendingRemove(result));
637 if (!m_actionTimer.isActive()) 662 if (!m_actionTimer.isActive())
638 m_actionTimer.startOneShot(0, BLINK_FROM_HERE); 663 m_actionTimer.startOneShot(0, BLINK_FROM_HERE);
639 664
640 // 6. Return promise. 665 // 6. Return promise.
641 return promise; 666 return promise;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 visitor->trace(m_asyncEventQueue); 982 visitor->trace(m_asyncEventQueue);
958 visitor->trace(m_pendingActions); 983 visitor->trace(m_pendingActions);
959 visitor->trace(m_mediaKeys); 984 visitor->trace(m_mediaKeys);
960 visitor->trace(m_keyStatusesMap); 985 visitor->trace(m_keyStatusesMap);
961 visitor->trace(m_closedPromise); 986 visitor->trace(m_closedPromise);
962 EventTargetWithInlineData::trace(visitor); 987 EventTargetWithInlineData::trace(visitor);
963 ActiveDOMObject::trace(visitor); 988 ActiveDOMObject::trace(visitor);
964 } 989 }
965 990
966 } // namespace blink 991 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698