OLD | NEW |
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 Loading... |
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) | 29 #if ENABLE(ENCRYPTED_MEDIA_V2) |
30 | 30 |
31 #include "core/dom/EventNames.h" | 31 #include "core/dom/EventNames.h" |
32 #include "core/html/HTMLMediaElement.h" | 32 #include "core/html/HTMLMediaElement.h" |
33 #include "core/platform/UUID.h" | 33 #include "core/platform/UUID.h" |
34 #include "modules/encryptedmedia/CDM.h" | 34 #include "core/platform/graphics/CDM.h" |
35 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" | 35 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" |
36 #include "modules/encryptedmedia/MediaKeySession.h" | 36 #include "modules/encryptedmedia/MediaKeySession.h" |
37 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 PassRefPtr<MediaKeys> MediaKeys::create(const String& keySystem, ExceptionCode&
ec) | 41 PassRefPtr<MediaKeys> MediaKeys::create(const String& keySystem, ExceptionCode&
ec) |
42 { | 42 { |
43 // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encry
pted-media.html#dom-media-keys-constructor>: | 43 // 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: | 44 // The MediaKeys(keySystem) constructor must run the following steps: |
45 | 45 |
46 // 1. If keySystem is null or an empty string, throw an INVALID_ACCESS_ERR e
xception and abort these steps. | 46 // 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()) { | 47 if (keySystem.isNull() || keySystem.isEmpty()) { |
48 ec = INVALID_ACCESS_ERR; | 48 ec = INVALID_ACCESS_ERR; |
49 return 0; | 49 return 0; |
50 } | 50 } |
51 | 51 |
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. | 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. |
53 if (!CDM::supportsKeySystem(keySystem)) { | 53 if (!CDM::supportsKeySystem(keySystem)) { |
54 ec = NOT_SUPPORTED_ERR; | 54 ec = NOT_SUPPORTED_ERR; |
55 return 0; | 55 return 0; |
56 } | 56 } |
57 | 57 |
58 // 3. Let cdm be the content decryption module corresponding to keySystem. | 58 // 3. Let cdm be the content decryption module corresponding to keySystem. |
59 // 4. Load cdm if necessary. | 59 // 4. Load cdm if necessary. |
60 OwnPtr<CDM> cdm = CDM::create(keySystem); | 60 OwnPtr<CDM> cdm = CDM::create(keySystem); |
| 61 if (!cdm) { |
| 62 ec = NOT_SUPPORTED_ERR; |
| 63 return 0; |
| 64 } |
61 | 65 |
62 // 5. Create a new MediaKeys object. | 66 // 5. Create a new MediaKeys object. |
63 // 5.1 Let the keySystem attribute be keySystem. | 67 // 5.1 Let the keySystem attribute be keySystem. |
64 // 6. Return the new object to the caller. | 68 // 6. Return the new object to the caller. |
65 return adoptRef(new MediaKeys(keySystem, cdm.release())); | 69 return adoptRef(new MediaKeys(keySystem, cdm.release())); |
66 } | 70 } |
67 | 71 |
68 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<CDM> cdm) | 72 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<CDM> cdm) |
69 : m_mediaElement(0) | 73 : m_mediaElement(0) |
70 , m_keySystem(keySystem) | 74 , m_keySystem(keySystem) |
71 , m_cdm(cdm) | 75 , m_cdm(cdm) |
72 { | 76 { |
73 ScriptWrappable::init(this); | 77 ScriptWrappable::init(this); |
74 m_cdm->setClient(this); | |
75 } | 78 } |
76 | 79 |
77 MediaKeys::~MediaKeys() | 80 MediaKeys::~MediaKeys() |
78 { | 81 { |
79 // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encry
pted-media.html#dom-media-keys-constructor>: | 82 // 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(). | 83 // When destroying a MediaKeys object, follow the steps in close(). |
81 for (size_t i = 0; i < m_sessions.size(); ++i) { | 84 for (size_t i = 0; i < m_sessions.size(); ++i) |
82 m_sessions[i]->close(); | 85 m_sessions[i]->close(); |
83 m_sessions[i]->setKeys(0); | |
84 } | |
85 } | 86 } |
86 | 87 |
87 PassRefPtr<MediaKeySession> MediaKeys::createSession(ScriptExecutionContext* con
text, const String& type, Uint8Array* initData, ExceptionCode& ec) | 88 PassRefPtr<MediaKeySession> MediaKeys::createSession(ScriptExecutionContext* con
text, const String& type, Uint8Array* initData, ExceptionCode& ec) |
88 { | 89 { |
89 // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encry
pted-media.html#dom-createsession>: | 90 // 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: | 91 // The createSession(type, initData) method must run the following steps: |
91 // Note: The contents of initData are container-specific Initialization Data
. | 92 // Note: The contents of initData are container-specific Initialization Data
. |
92 | 93 |
93 // 1. If type is null or an empty string and initData is not null or an empt
y string, throw an | 94 // 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. | 95 // INVALID_ACCESS_ERR exception and abort these steps. |
95 if ((type.isNull() || type.isEmpty()) && (!initData || initData->length()))
{ | 96 if ((type.isNull() || type.isEmpty()) && (!initData || initData->length()))
{ |
96 ec = INVALID_ACCESS_ERR; | 97 ec = INVALID_ACCESS_ERR; |
97 return 0; | 98 return 0; |
98 } | 99 } |
99 | 100 |
100 // 2. If type contains a MIME type that is not supported or is not supported
by the keySystem, throw | 101 // 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. | 102 // a NOT_SUPPORTED_ERR exception and abort these steps. |
102 if (!type.isNull() && !type.isEmpty() && !m_cdm->supportsMIMEType(type)) { | 103 ASSERT(!type.isNull() && !type.isEmpty()); |
| 104 if (type.isNull() || type.isEmpty() || !m_cdm->supportsMIMEType(type)) { |
103 ec = NOT_SUPPORTED_ERR; | 105 ec = NOT_SUPPORTED_ERR; |
104 return 0; | 106 return 0; |
105 } | 107 } |
106 | 108 |
107 // 3. Create a new MediaKeySession object. | 109 // 3. Create a new MediaKeySession object. |
| 110 RefPtr<MediaKeySession> session = MediaKeySession::create(context, *m_cdm, t
his); |
108 // 3.1 Let the keySystem attribute be keySystem. | 111 // 3.1 Let the keySystem attribute be keySystem. |
| 112 ASSERT(!session->keySystem().isEmpty()); |
109 // 3.2 Let the sessionId attribute be a unique Session ID string. It may be
generated by cdm. | 113 // 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()); | 114 // This is handled by m_cdm and may happen asynchronously. |
111 | 115 |
112 // 4. Add the new object to an internal list of session objects. | 116 // 4. Add the new object to an internal list of session objects. |
113 m_sessions.append(session); | 117 m_sessions.append(session); |
114 | 118 |
115 // 5. Schedule a task to generate a key request, providing type, initData, a
nd the new object. | 119 // 5. Schedule a task to generate a key request, providing type, initData, a
nd the new object. |
116 session->generateKeyRequest(type, initData); | 120 session->generateKeyRequest(type, initData); |
117 | 121 |
118 // 6. Return the new object to the caller. | 122 // 6. Return the new object to the caller. |
119 return session; | 123 return session; |
120 } | 124 } |
121 | 125 |
122 void MediaKeys::setMediaElement(HTMLMediaElement* element) | 126 void MediaKeys::setMediaElement(HTMLMediaElement* element) |
123 { | 127 { |
| 128 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_
mediaElement is not 0. |
| 129 // FIXME: Hook up the CDM to the WebMediaPlayer in Chromium. |
| 130 ASSERT(!m_mediaElement); |
124 m_mediaElement = element; | 131 m_mediaElement = element; |
125 } | 132 } |
126 | 133 |
127 MediaPlayer* MediaKeys::cdmMediaPlayer(const CDM*) const | |
128 { | |
129 if (m_mediaElement) | |
130 return m_mediaElement->player(); | |
131 return 0; | |
132 } | |
133 | |
134 } | 134 } |
135 | 135 |
136 #endif | 136 #endif |
OLD | NEW |