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

Side by Side Diff: third_party/WebKit/Source/modules/encryptedmedia/MediaKeys.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 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #include "modules/encryptedmedia/MediaKeys.h" 26 #include "modules/encryptedmedia/MediaKeys.h"
27 27
28 #include "bindings/core/v8/ScriptState.h" 28 #include "bindings/core/v8/ScriptState.h"
29 #include "core/dom/DOMArrayBuffer.h" 29 #include "core/dom/DOMArrayBuffer.h"
30 #include "core/dom/DOMException.h" 30 #include "core/dom/DOMException.h"
31 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
32 #include "core/dom/ExecutionContext.h" 32 #include "core/dom/ExecutionContext.h"
33 #include "core/html/HTMLMediaElement.h" 33 #include "core/html/HTMLMediaElement.h"
34 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h"
34 #include "modules/encryptedmedia/EncryptedMediaUtils.h" 35 #include "modules/encryptedmedia/EncryptedMediaUtils.h"
35 #include "modules/encryptedmedia/MediaKeySession.h" 36 #include "modules/encryptedmedia/MediaKeySession.h"
36 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResultPromise.h"
37 #include "platform/Timer.h" 37 #include "platform/Timer.h"
38 #include "public/platform/WebContentDecryptionModule.h" 38 #include "public/platform/WebContentDecryptionModule.h"
39 #include "wtf/RefPtr.h" 39 #include "wtf/RefPtr.h"
40 #include <memory> 40 #include <memory>
41 41
42 #define MEDIA_KEYS_LOG_LEVEL 3 42 #define MEDIA_KEYS_LOG_LEVEL 3
43 43
44 namespace blink { 44 namespace blink {
45 45
46 // A class holding a pending action. 46 // A class holding a pending action.
(...skipping 28 matching lines...) Expand all
75 }; 75 };
76 76
77 // This class wraps the promise resolver used when setting the certificate 77 // This class wraps the promise resolver used when setting the certificate
78 // and is passed to Chromium to fullfill the promise. This implementation of 78 // and is passed to Chromium to fullfill the promise. This implementation of
79 // complete() will resolve the promise with true, while completeWithError() 79 // complete() will resolve the promise with true, while completeWithError()
80 // will reject the promise with an exception. completeWithSession() 80 // will reject the promise with an exception. completeWithSession()
81 // is not expected to be called, and will reject the promise. 81 // is not expected to be called, and will reject the promise.
82 class SetCertificateResultPromise 82 class SetCertificateResultPromise
83 : public ContentDecryptionModuleResultPromise { 83 : public ContentDecryptionModuleResultPromise {
84 public: 84 public:
85 SetCertificateResultPromise(ScriptState* scriptState) 85 SetCertificateResultPromise(ScriptState* scriptState, MediaKeys* mediaKeys)
86 : ContentDecryptionModuleResultPromise(scriptState) {} 86 : ContentDecryptionModuleResultPromise(scriptState),
87 m_mediaKeys(mediaKeys) {}
87 88
88 ~SetCertificateResultPromise() override {} 89 ~SetCertificateResultPromise() override {}
89 90
90 // ContentDecryptionModuleResult implementation. 91 // ContentDecryptionModuleResult implementation.
91 void complete() override { resolve(true); } 92 void complete() override {
93 if (!isValidToFulfillPromise())
94 return;
95
96 resolve(true);
97 }
92 98
93 void completeWithError(WebContentDecryptionModuleException exceptionCode, 99 void completeWithError(WebContentDecryptionModuleException exceptionCode,
94 unsigned long systemCode, 100 unsigned long systemCode,
95 const WebString& errorMessage) override { 101 const WebString& errorMessage) override {
102 if (!isValidToFulfillPromise())
103 return;
104
96 // The EME spec specifies that "If the Key System implementation does 105 // The EME spec specifies that "If the Key System implementation does
97 // not support server certificates, return a promise resolved with 106 // not support server certificates, return a promise resolved with
98 // false." So convert any NOTSUPPORTEDERROR into resolving with false. 107 // false." So convert any NOTSUPPORTEDERROR into resolving with false.
99 if (exceptionCode == WebContentDecryptionModuleExceptionNotSupportedError) { 108 if (exceptionCode == WebContentDecryptionModuleExceptionNotSupportedError) {
100 resolve(false); 109 resolve(false);
101 return; 110 return;
102 } 111 }
103 112
104 ContentDecryptionModuleResultPromise::completeWithError( 113 ContentDecryptionModuleResultPromise::completeWithError(
105 exceptionCode, systemCode, errorMessage); 114 exceptionCode, systemCode, errorMessage);
106 } 115 }
116
117 DEFINE_INLINE_TRACE() {
118 visitor->trace(m_mediaKeys);
119 ContentDecryptionModuleResultPromise::trace(visitor);
120 }
121
122 private:
123 Member<MediaKeys> m_mediaKeys;
107 }; 124 };
108 125
109 MediaKeys* MediaKeys::create( 126 MediaKeys* MediaKeys::create(
110 ExecutionContext* context, 127 ExecutionContext* context,
111 const WebVector<WebEncryptedMediaSessionType>& supportedSessionTypes, 128 const WebVector<WebEncryptedMediaSessionType>& supportedSessionTypes,
112 std::unique_ptr<WebContentDecryptionModule> cdm) { 129 std::unique_ptr<WebContentDecryptionModule> cdm) {
113 MediaKeys* mediaKeys = 130 MediaKeys* mediaKeys =
114 new MediaKeys(context, supportedSessionTypes, std::move(cdm)); 131 new MediaKeys(context, supportedSessionTypes, std::move(cdm));
115 mediaKeys->suspendIfNeeded(); 132 mediaKeys->suspendIfNeeded();
116 return mediaKeys; 133 return mediaKeys;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // "NotSupportedError". 204 // "NotSupportedError".
188 // (Let the CDM decide whether to support this or not.) 205 // (Let the CDM decide whether to support this or not.)
189 206
190 // 3. Let certificate be a copy of the contents of the serverCertificate 207 // 3. Let certificate be a copy of the contents of the serverCertificate
191 // parameter. 208 // parameter.
192 DOMArrayBuffer* serverCertificateBuffer = DOMArrayBuffer::create( 209 DOMArrayBuffer* serverCertificateBuffer = DOMArrayBuffer::create(
193 serverCertificate.data(), serverCertificate.byteLength()); 210 serverCertificate.data(), serverCertificate.byteLength());
194 211
195 // 4. Let promise be a new promise. 212 // 4. Let promise be a new promise.
196 SetCertificateResultPromise* result = 213 SetCertificateResultPromise* result =
197 new SetCertificateResultPromise(scriptState); 214 new SetCertificateResultPromise(scriptState, this);
198 ScriptPromise promise = result->promise(); 215 ScriptPromise promise = result->promise();
199 216
200 // 5. Run the following steps asynchronously (documented in timerFired()). 217 // 5. Run the following steps asynchronously (documented in timerFired()).
201 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate( 218 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate(
202 result, serverCertificateBuffer)); 219 result, serverCertificateBuffer));
203 if (!m_timer.isActive()) 220 if (!m_timer.isActive())
204 m_timer.startOneShot(0, BLINK_FROM_HERE); 221 m_timer.startOneShot(0, BLINK_FROM_HERE);
205 222
206 // 6. Return promise. 223 // 6. Return promise.
207 return promise; 224 return promise;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Remain around if there are pending events. 307 // Remain around if there are pending events.
291 DVLOG(MEDIA_KEYS_LOG_LEVEL) 308 DVLOG(MEDIA_KEYS_LOG_LEVEL)
292 << __func__ << "(" << this << ")" 309 << __func__ << "(" << this << ")"
293 << (!m_pendingActions.isEmpty() ? " !m_pendingActions.isEmpty()" : "") 310 << (!m_pendingActions.isEmpty() ? " !m_pendingActions.isEmpty()" : "")
294 << (m_reservedForMediaElement ? " m_reservedForMediaElement" : ""); 311 << (m_reservedForMediaElement ? " m_reservedForMediaElement" : "");
295 312
296 return !m_pendingActions.isEmpty() || m_reservedForMediaElement; 313 return !m_pendingActions.isEmpty() || m_reservedForMediaElement;
297 } 314 }
298 315
299 } // namespace blink 316 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698