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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<ContentDecryptionModule
> cdm) | 71 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<ContentDecryptionModule
> cdm) |
72 : m_mediaElement(0) | 72 : m_mediaElement(0) |
73 , m_keySystem(keySystem) | 73 , m_keySystem(keySystem) |
74 , m_cdm(cdm) | 74 , m_cdm(cdm) |
75 { | 75 { |
76 ScriptWrappable::init(this); | 76 ScriptWrappable::init(this); |
77 } | 77 } |
78 | 78 |
79 MediaKeys::~MediaKeys() | 79 MediaKeys::~MediaKeys() |
80 { | 80 { |
81 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-media-keys-constructor>: | 81 // FIXME: Make sure MediaKeySessions are torn down correctly. |
82 // When destroying a MediaKeys object, follow the steps in close(). | |
83 for (size_t i = 0; i < m_sessions.size(); ++i) | |
84 m_sessions[i]->close(); | |
85 } | 82 } |
86 | 83 |
87 PassRefPtr<MediaKeySession> MediaKeys::createSession(ExecutionContext* context,
const String& type, Uint8Array* initData, ExceptionState& exceptionState) | 84 PassRefPtr<MediaKeySession> MediaKeys::createSession(ExecutionContext* context,
const String& type, Uint8Array* initData, ExceptionState& exceptionState) |
88 { | 85 { |
89 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-createsession>: | 86 // 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: | 87 // The createSession(type, initData) method must run the following steps: |
91 // Note: The contents of initData are container-specific Initialization Data
. | 88 // Note: The contents of initData are container-specific Initialization Data
. |
92 | 89 |
93 // 1. If type is null or an empty string and initData is not null or an empt
y string, throw an | 90 // FIXME: Follow the latest spec to check |type| and |initData|. |
| 91 // If type is null or an empty string and initData is not null or an empty s
tring, throw an |
94 // InvalidAccessError exception and abort these steps. | 92 // InvalidAccessError exception and abort these steps. |
95 if ((type.isEmpty()) && (!initData || initData->length())) { | 93 if ((type.isEmpty()) && (!initData || initData->length())) { |
96 exceptionState.throwDOMException(InvalidAccessError, "The type provided
is empty, but initData is not empty."); | 94 exceptionState.throwDOMException(InvalidAccessError, "The type provided
is empty, but initData is not empty."); |
97 return 0; | 95 return 0; |
98 } | 96 } |
99 | 97 |
100 // 2. If type contains a MIME type that is not supported or is not supported
by the keySystem, throw | 98 // 1. If type contains a MIME type that is not supported or is not supported
by the keySystem, |
101 // a NotSupportedError exception and abort these steps. | 99 // throw a NOT_SUPPORTED_ERR exception and abort these steps. |
102 ASSERT(!type.isEmpty()); | 100 ASSERT(!type.isEmpty()); |
103 if (type.isEmpty() || !m_cdm->supportsMIMEType(type)) { | 101 if (type.isEmpty() || !m_cdm->supportsMIMEType(type)) { |
104 exceptionState.throwDOMException(NotSupportedError, "The type provided (
'" + type + "') is unsupported."); | 102 exceptionState.throwDOMException(NotSupportedError, "The type provided (
'" + type + "') is unsupported."); |
105 return 0; | 103 return 0; |
106 } | 104 } |
107 | 105 |
108 // 3. Create a new MediaKeySession object. | 106 // 2. Create a new MediaKeySession object. |
109 RefPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get
(), this); | 107 RefPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get
(), this); |
110 // 3.1 Let the keySystem attribute be keySystem. | 108 // 2.1 Let the keySystem attribute be keySystem. |
111 ASSERT(!session->keySystem().isEmpty()); | 109 ASSERT(!session->keySystem().isEmpty()); |
112 // 3.2 Let the sessionId attribute be a unique Session ID string. It may be
generated by cdm. | 110 // FIXME: 2.2 Let the state of the session be CREATED. |
113 // This is handled by m_cdm and may happen asynchronously. | |
114 | 111 |
115 // 4. Add the new object to an internal list of session objects. | 112 // 3. Add the new object to an internal list of session objects. |
116 m_sessions.append(session); | 113 m_sessions.append(session); |
117 | 114 |
118 // 5. Schedule a task to generate a key request, providing type, initData, a
nd the new object. | 115 // 4. Schedule a task to initialize the session, providing type, initData, a
nd the new object. |
119 session->generateKeyRequest(type, initData); | 116 // FIXME: The spec says "schedule a task". We should move the timer here. |
| 117 // FIXME: |initData| may be 0. We need to add more check before we dereferen
ce it. |
| 118 // Note that this may become obsolete when the FIXME on l.90 is fixed. |
| 119 session->initializeNewSession(type, initData); |
120 | 120 |
121 // 6. Return the new object to the caller. | 121 // 5. Return the new object to the caller. |
122 return session; | 122 return session; |
123 } | 123 } |
124 | 124 |
125 void MediaKeys::setMediaElement(HTMLMediaElement* element) | 125 void MediaKeys::setMediaElement(HTMLMediaElement* element) |
126 { | 126 { |
127 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_
mediaElement is not 0 | 127 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_
mediaElement is not 0 |
128 // and remove the code that prevents the assert below in HTMLMediaElement. | 128 // and remove the code that prevents the assert below in HTMLMediaElement. |
129 ASSERT(!m_mediaElement != !element); | 129 ASSERT(!m_mediaElement != !element); |
130 m_mediaElement = element; | 130 m_mediaElement = element; |
131 } | 131 } |
132 | 132 |
133 blink::WebContentDecryptionModule* MediaKeys::contentDecryptionModule() | 133 blink::WebContentDecryptionModule* MediaKeys::contentDecryptionModule() |
134 { | 134 { |
135 return m_cdm ? m_cdm->contentDecryptionModule() : 0; | 135 return m_cdm ? m_cdm->contentDecryptionModule() : 0; |
136 } | 136 } |
137 | 137 |
138 } | 138 } |
OLD | NEW |