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

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

Issue 2056053003: Change MediaKeys.setServerCertificate() to return Promise<boolean> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolve false Created 4 years, 6 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 PendingAction(ContentDecryptionModuleResult* result, DOMArrayBuffer* data) 73 PendingAction(ContentDecryptionModuleResult* result, DOMArrayBuffer* data)
74 : m_result(result) 74 : m_result(result)
75 , m_data(data) 75 , m_data(data)
76 { 76 {
77 } 77 }
78 78
79 const Member<ContentDecryptionModuleResult> m_result; 79 const Member<ContentDecryptionModuleResult> m_result;
80 const Member<DOMArrayBuffer> m_data; 80 const Member<DOMArrayBuffer> m_data;
81 }; 81 };
82 82
83 // This class wraps the promise resolver used when setting the certificate
84 // and is passed to Chromium to fullfill the promise. This implementation of
85 // complete() will resolve the promise with true, while completeWithError()
86 // will reject the promise with an exception. completeWithSession()
87 // is not expected to be called, and will reject the promise.
88 class SetCertificateResultPromise : public ContentDecryptionModuleResultPromise {
89 public:
90 SetCertificateResultPromise(ScriptState* scriptState)
91 : ContentDecryptionModuleResultPromise(scriptState)
92 {
93 }
94
95 ~SetCertificateResultPromise() override
96 {
97 }
98
99 // ContentDecryptionModuleResult implementation.
100 void complete() override
101 {
102 resolve(true);
103 }
104
105 void completeWithError(WebContentDecryptionModuleException exceptionCode, un signed long systemCode, const WebString& errorMessage) override
106 {
107 // The EME spec specifies that "If the Key System implementation does
108 // not support server certificates, return a promise resolved with
109 // false." So convert any NOTSUPPORTEDERRORS into resolving with false.
xhwang 2016/06/13 17:45:49 s/NOTSUPPORTEDERRORS/NOTSUPPORTEDERROR/
jrummell 2016/06/13 18:54:13 Done.
110 if (exceptionCode == WebContentDecryptionModuleExceptionNotSupportedErro r) {
111 resolve(false);
112 return;
113 }
114
115 ContentDecryptionModuleResultPromise::completeWithError(exceptionCode, s ystemCode, errorMessage);
116 }
117 };
118
83 MediaKeys* MediaKeys::create(ExecutionContext* context, const WebVector<WebEncry ptedMediaSessionType>& supportedSessionTypes, PassOwnPtr<WebContentDecryptionMod ule> cdm) 119 MediaKeys* MediaKeys::create(ExecutionContext* context, const WebVector<WebEncry ptedMediaSessionType>& supportedSessionTypes, PassOwnPtr<WebContentDecryptionMod ule> cdm)
84 { 120 {
85 MediaKeys* mediaKeys = new MediaKeys(context, supportedSessionTypes, std::mo ve(cdm)); 121 MediaKeys* mediaKeys = new MediaKeys(context, supportedSessionTypes, std::mo ve(cdm));
86 mediaKeys->suspendIfNeeded(); 122 mediaKeys->suspendIfNeeded();
87 return mediaKeys; 123 return mediaKeys;
88 } 124 }
89 125
90 MediaKeys::MediaKeys(ExecutionContext* context, const WebVector<WebEncryptedMedi aSessionType>& supportedSessionTypes, PassOwnPtr<WebContentDecryptionModule> cdm ) 126 MediaKeys::MediaKeys(ExecutionContext* context, const WebVector<WebEncryptedMedi aSessionType>& supportedSessionTypes, PassOwnPtr<WebContentDecryptionModule> cdm )
91 : ActiveScriptWrappable(this) 127 : ActiveScriptWrappable(this)
92 , ActiveDOMObject(context) 128 , ActiveDOMObject(context)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // 2. If the keySystem does not support server certificates, return a 184 // 2. If the keySystem does not support server certificates, return a
149 // promise rejected with a new DOMException whose name is 185 // promise rejected with a new DOMException whose name is
150 // "NotSupportedError". 186 // "NotSupportedError".
151 // (Let the CDM decide whether to support this or not.) 187 // (Let the CDM decide whether to support this or not.)
152 188
153 // 3. Let certificate be a copy of the contents of the serverCertificate 189 // 3. Let certificate be a copy of the contents of the serverCertificate
154 // parameter. 190 // parameter.
155 DOMArrayBuffer* serverCertificateBuffer = DOMArrayBuffer::create(serverCerti ficate.data(), serverCertificate.byteLength()); 191 DOMArrayBuffer* serverCertificateBuffer = DOMArrayBuffer::create(serverCerti ficate.data(), serverCertificate.byteLength());
156 192
157 // 4. Let promise be a new promise. 193 // 4. Let promise be a new promise.
158 SimpleContentDecryptionModuleResultPromise* result = new SimpleContentDecryp tionModuleResultPromise(scriptState); 194 SetCertificateResultPromise* result = new SetCertificateResultPromise(script State);
159 ScriptPromise promise = result->promise(); 195 ScriptPromise promise = result->promise();
160 196
161 // 5. Run the following steps asynchronously (documented in timerFired()). 197 // 5. Run the following steps asynchronously (documented in timerFired()).
162 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate(res ult, serverCertificateBuffer)); 198 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate(res ult, serverCertificateBuffer));
163 if (!m_timer.isActive()) 199 if (!m_timer.isActive())
164 m_timer.startOneShot(0, BLINK_FROM_HERE); 200 m_timer.startOneShot(0, BLINK_FROM_HERE);
165 201
166 // 6. Return promise. 202 // 6. Return promise.
167 return promise; 203 return promise;
168 } 204 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 void MediaKeys::stop() 300 void MediaKeys::stop()
265 { 301 {
266 ActiveDOMObject::stop(); 302 ActiveDOMObject::stop();
267 303
268 if (m_timer.isActive()) 304 if (m_timer.isActive())
269 m_timer.stop(); 305 m_timer.stop();
270 m_pendingActions.clear(); 306 m_pendingActions.clear();
271 } 307 }
272 308
273 } // namespace blink 309 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698