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

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

Issue 16387015: Make unprefixed EME APIs use platform and Chromium. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: KURL.h moved Created 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/encryptedmedia/MediaKeys.h ('k') | Source/modules/modules.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "modules/encryptedmedia/MediaKeys.h" 27 #include "modules/encryptedmedia/MediaKeys.h"
28 28
29 #if ENABLE(ENCRYPTED_MEDIA_V2)
30
31 #include "core/dom/EventNames.h" 29 #include "core/dom/EventNames.h"
32 #include "core/html/HTMLMediaElement.h" 30 #include "core/html/HTMLMediaElement.h"
33 #include "core/platform/UUID.h" 31 #include "core/platform/UUID.h"
34 #include "modules/encryptedmedia/CDM.h" 32 #include "core/platform/graphics/ContentDecryptionModule.h"
35 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" 33 #include "modules/encryptedmedia/MediaKeyMessageEvent.h"
36 #include "modules/encryptedmedia/MediaKeySession.h" 34 #include "modules/encryptedmedia/MediaKeySession.h"
37 #include "wtf/HashSet.h" 35 #include "wtf/HashSet.h"
38 36
39 namespace WebCore { 37 namespace WebCore {
40 38
41 PassRefPtr<MediaKeys> MediaKeys::create(const String& keySystem, ExceptionCode& ec) 39 PassRefPtr<MediaKeys> MediaKeys::create(const String& keySystem, ExceptionCode& ec)
42 { 40 {
43 // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encry pted-media.html#dom-media-keys-constructor>: 41 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-media-keys-constructor>:
44 // The MediaKeys(keySystem) constructor must run the following steps: 42 // The MediaKeys(keySystem) constructor must run the following steps:
45 43
46 // 1. If keySystem is null or an empty string, throw an INVALID_ACCESS_ERR e xception and abort these steps. 44 // 1. If keySystem is null or an empty string, throw an INVALID_ACCESS_ERR e xception and abort these steps.
47 if (keySystem.isNull() || keySystem.isEmpty()) { 45 if (keySystem.isEmpty()) {
48 ec = INVALID_ACCESS_ERR; 46 ec = INVALID_ACCESS_ERR;
49 return 0; 47 return 0;
50 } 48 }
51 49
52 // 2. If keySystem is not one of the user agent's supported Key Systems, thr ow a NOT_SUPPORTED_ERR and abort these steps. 50 // 2. If keySystem is not one of the user agent's supported Key Systems, thr ow a NOT_SUPPORTED_ERR and abort these steps.
53 if (!CDM::supportsKeySystem(keySystem)) { 51 if (!ContentDecryptionModule::supportsKeySystem(keySystem)) {
54 ec = NOT_SUPPORTED_ERR; 52 ec = NOT_SUPPORTED_ERR;
55 return 0; 53 return 0;
56 } 54 }
57 55
58 // 3. Let cdm be the content decryption module corresponding to keySystem. 56 // 3. Let cdm be the content decryption module corresponding to keySystem.
59 // 4. Load cdm if necessary. 57 // 4. Load cdm if necessary.
60 OwnPtr<CDM> cdm = CDM::create(keySystem); 58 OwnPtr<ContentDecryptionModule> cdm = ContentDecryptionModule::create(keySys tem);
59 if (!cdm) {
60 ec = NOT_SUPPORTED_ERR;
61 return 0;
62 }
61 63
62 // 5. Create a new MediaKeys object. 64 // 5. Create a new MediaKeys object.
63 // 5.1 Let the keySystem attribute be keySystem. 65 // 5.1 Let the keySystem attribute be keySystem.
64 // 6. Return the new object to the caller. 66 // 6. Return the new object to the caller.
65 return adoptRef(new MediaKeys(keySystem, cdm.release())); 67 return adoptRef(new MediaKeys(keySystem, cdm.release()));
66 } 68 }
67 69
68 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<CDM> cdm) 70 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<ContentDecryptionModule > cdm)
69 : m_mediaElement(0) 71 : m_mediaElement(0)
70 , m_keySystem(keySystem) 72 , m_keySystem(keySystem)
71 , m_cdm(cdm) 73 , m_cdm(cdm)
72 { 74 {
73 ScriptWrappable::init(this); 75 ScriptWrappable::init(this);
74 m_cdm->setClient(this);
75 } 76 }
76 77
77 MediaKeys::~MediaKeys() 78 MediaKeys::~MediaKeys()
78 { 79 {
79 // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encry pted-media.html#dom-media-keys-constructor>: 80 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-media-keys-constructor>:
80 // When destroying a MediaKeys object, follow the steps in close(). 81 // When destroying a MediaKeys object, follow the steps in close().
81 for (size_t i = 0; i < m_sessions.size(); ++i) { 82 for (size_t i = 0; i < m_sessions.size(); ++i)
82 m_sessions[i]->close(); 83 m_sessions[i]->close();
83 m_sessions[i]->setKeys(0);
84 }
85 } 84 }
86 85
87 PassRefPtr<MediaKeySession> MediaKeys::createSession(ScriptExecutionContext* con text, const String& type, Uint8Array* initData, ExceptionCode& ec) 86 PassRefPtr<MediaKeySession> MediaKeys::createSession(ScriptExecutionContext* con text, const String& type, Uint8Array* initData, ExceptionCode& ec)
88 { 87 {
89 // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encry pted-media.html#dom-createsession>: 88 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-createsession>:
90 // The createSession(type, initData) method must run the following steps: 89 // The createSession(type, initData) method must run the following steps:
91 // Note: The contents of initData are container-specific Initialization Data . 90 // Note: The contents of initData are container-specific Initialization Data .
92 91
93 // 1. If type is null or an empty string and initData is not null or an empt y string, throw an 92 // 1. If type is null or an empty string and initData is not null or an empt y string, throw an
94 // INVALID_ACCESS_ERR exception and abort these steps. 93 // INVALID_ACCESS_ERR exception and abort these steps.
95 if ((type.isNull() || type.isEmpty()) && (!initData || initData->length())) { 94 if ((type.isEmpty()) && (!initData || initData->length())) {
96 ec = INVALID_ACCESS_ERR; 95 ec = INVALID_ACCESS_ERR;
97 return 0; 96 return 0;
98 } 97 }
99 98
100 // 2. If type contains a MIME type that is not supported or is not supported by the keySystem, throw 99 // 2. If type contains a MIME type that is not supported or is not supported by the keySystem, throw
101 // a NOT_SUPPORTED_ERR exception and abort these steps. 100 // a NOT_SUPPORTED_ERR exception and abort these steps.
102 if (!type.isNull() && !type.isEmpty() && !m_cdm->supportsMIMEType(type)) { 101 ASSERT(!type.isEmpty());
102 if (type.isEmpty() || !m_cdm->supportsMIMEType(type)) {
103 ec = NOT_SUPPORTED_ERR; 103 ec = NOT_SUPPORTED_ERR;
104 return 0; 104 return 0;
105 } 105 }
106 106
107 // 3. Create a new MediaKeySession object. 107 // 3. Create a new MediaKeySession object.
108 RefPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get (), this);
108 // 3.1 Let the keySystem attribute be keySystem. 109 // 3.1 Let the keySystem attribute be keySystem.
110 ASSERT(!session->keySystem().isEmpty());
109 // 3.2 Let the sessionId attribute be a unique Session ID string. It may be generated by cdm. 111 // 3.2 Let the sessionId attribute be a unique Session ID string. It may be generated by cdm.
110 RefPtr<MediaKeySession> session = MediaKeySession::create(context, this, key System()); 112 // This is handled by m_cdm and may happen asynchronously.
111 113
112 // 4. Add the new object to an internal list of session objects. 114 // 4. Add the new object to an internal list of session objects.
113 m_sessions.append(session); 115 m_sessions.append(session);
114 116
115 // 5. Schedule a task to generate a key request, providing type, initData, a nd the new object. 117 // 5. Schedule a task to generate a key request, providing type, initData, a nd the new object.
116 session->generateKeyRequest(type, initData); 118 session->generateKeyRequest(type, initData);
117 119
118 // 6. Return the new object to the caller. 120 // 6. Return the new object to the caller.
119 return session; 121 return session;
120 } 122 }
121 123
122 void MediaKeys::setMediaElement(HTMLMediaElement* element) 124 void MediaKeys::setMediaElement(HTMLMediaElement* element)
123 { 125 {
126 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_ mediaElement is not 0.
127 // FIXME: Hook up the CDM to the WebMediaPlayer in Chromium.
128 ASSERT(!m_mediaElement);
124 m_mediaElement = element; 129 m_mediaElement = element;
125 } 130 }
126 131
127 MediaPlayer* MediaKeys::cdmMediaPlayer(const CDM*) const
128 {
129 if (m_mediaElement)
130 return m_mediaElement->player();
131 return 0;
132 } 132 }
133
134 }
135
136 #endif
OLDNEW
« no previous file with comments | « Source/modules/encryptedmedia/MediaKeys.h ('k') | Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698