| 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 16 matching lines...) Expand all Loading... |
| 27 #include "modules/encryptedmedia/MediaKeySession.h" | 27 #include "modules/encryptedmedia/MediaKeySession.h" |
| 28 | 28 |
| 29 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
| 30 #include "core/events/Event.h" | 30 #include "core/events/Event.h" |
| 31 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
| 32 #include "core/events/GenericEventQueue.h" | 32 #include "core/events/GenericEventQueue.h" |
| 33 #include "core/html/MediaKeyError.h" | 33 #include "core/html/MediaKeyError.h" |
| 34 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" | 34 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" |
| 35 #include "modules/encryptedmedia/MediaKeys.h" | 35 #include "modules/encryptedmedia/MediaKeys.h" |
| 36 #include "platform/Logging.h" | 36 #include "platform/Logging.h" |
| 37 #include "platform/drm/ContentDecryptionModule.h" | 37 #include "public/platform/WebContentDecryptionModule.h" |
| 38 #include "public/platform/WebString.h" |
| 39 #include "public/platform/WebURL.h" |
| 38 | 40 |
| 39 namespace WebCore { | 41 namespace WebCore { |
| 40 | 42 |
| 41 PassOwnPtr<MediaKeySession::PendingAction> MediaKeySession::PendingAction::Creat
ePendingUpdate(PassRefPtr<Uint8Array> data) | 43 PassOwnPtr<MediaKeySession::PendingAction> MediaKeySession::PendingAction::Creat
ePendingUpdate(PassRefPtr<Uint8Array> data) |
| 42 { | 44 { |
| 45 ASSERT(data); |
| 43 return adoptPtr(new PendingAction(Update, data)); | 46 return adoptPtr(new PendingAction(Update, data)); |
| 44 } | 47 } |
| 45 | 48 |
| 46 PassOwnPtr<MediaKeySession::PendingAction> MediaKeySession::PendingAction::Creat
ePendingRelease() | 49 PassOwnPtr<MediaKeySession::PendingAction> MediaKeySession::PendingAction::Creat
ePendingRelease() |
| 47 { | 50 { |
| 48 return adoptPtr(new PendingAction(Release, PassRefPtr<Uint8Array>())); | 51 return adoptPtr(new PendingAction(Release, PassRefPtr<Uint8Array>())); |
| 49 } | 52 } |
| 50 | 53 |
| 51 MediaKeySession::PendingAction::PendingAction(Type type, PassRefPtr<Uint8Array>
data) | 54 MediaKeySession::PendingAction::PendingAction(Type type, PassRefPtr<Uint8Array>
data) |
| 52 : type(type) | 55 : type(type) |
| 53 , data(data) | 56 , data(data) |
| 54 { | 57 { |
| 55 } | 58 } |
| 56 | 59 |
| 57 MediaKeySession::PendingAction::~PendingAction() | 60 MediaKeySession::PendingAction::~PendingAction() |
| 58 { | 61 { |
| 59 } | 62 } |
| 60 | 63 |
| 61 PassRefPtrWillBeRawPtr<MediaKeySession> MediaKeySession::create(ExecutionContext
* context, ContentDecryptionModule* cdm, WeakPtr<MediaKeys> keys) | 64 PassRefPtrWillBeRawPtr<MediaKeySession> MediaKeySession::create(ExecutionContext
* context, blink::WebContentDecryptionModule* cdm, WeakPtr<MediaKeys> keys) |
| 62 { | 65 { |
| 63 RefPtrWillBeRawPtr<MediaKeySession> session(adoptRefWillBeRefCountedGarbageC
ollected(new MediaKeySession(context, cdm, keys))); | 66 RefPtrWillBeRawPtr<MediaKeySession> session(adoptRefWillBeRefCountedGarbageC
ollected(new MediaKeySession(context, cdm, keys))); |
| 64 session->suspendIfNeeded(); | 67 session->suspendIfNeeded(); |
| 65 return session.release(); | 68 return session.release(); |
| 66 } | 69 } |
| 67 | 70 |
| 68 MediaKeySession::MediaKeySession(ExecutionContext* context, ContentDecryptionMod
ule* cdm, WeakPtr<MediaKeys> keys) | 71 MediaKeySession::MediaKeySession(ExecutionContext* context, blink::WebContentDec
ryptionModule* cdm, WeakPtr<MediaKeys> keys) |
| 69 : ActiveDOMObject(context) | 72 : ActiveDOMObject(context) |
| 70 , m_keySystem(keys->keySystem()) | 73 , m_keySystem(keys->keySystem()) |
| 71 , m_asyncEventQueue(GenericEventQueue::create(this)) | 74 , m_asyncEventQueue(GenericEventQueue::create(this)) |
| 72 , m_session(cdm->createSession(this)) | 75 , m_session(adoptPtr(cdm->createSession(this))) |
| 73 , m_keys(keys) | 76 , m_keys(keys) |
| 74 , m_isClosed(false) | 77 , m_isClosed(false) |
| 75 , m_actionTimer(this, &MediaKeySession::actionTimerFired) | 78 , m_actionTimer(this, &MediaKeySession::actionTimerFired) |
| 76 { | 79 { |
| 77 WTF_LOG(Media, "MediaKeySession::MediaKeySession"); | 80 WTF_LOG(Media, "MediaKeySession::MediaKeySession"); |
| 78 ScriptWrappable::init(this); | 81 ScriptWrappable::init(this); |
| 79 ASSERT(m_session); | 82 ASSERT(m_session); |
| 80 } | 83 } |
| 81 | 84 |
| 82 MediaKeySession::~MediaKeySession() | 85 MediaKeySession::~MediaKeySession() |
| 83 { | 86 { |
| 84 m_session.clear(); | 87 m_session.clear(); |
| 85 m_asyncEventQueue->cancelAllEvents(); | 88 m_asyncEventQueue->cancelAllEvents(); |
| 86 } | 89 } |
| 87 | 90 |
| 88 void MediaKeySession::setError(MediaKeyError* error) | 91 void MediaKeySession::setError(MediaKeyError* error) |
| 89 { | 92 { |
| 90 m_error = error; | 93 m_error = error; |
| 91 } | 94 } |
| 92 | 95 |
| 93 String MediaKeySession::sessionId() const | 96 String MediaKeySession::sessionId() const |
| 94 { | 97 { |
| 95 return m_session->sessionId(); | 98 return m_session->sessionId(); |
| 96 } | 99 } |
| 97 | 100 |
| 98 void MediaKeySession::initializeNewSession(const String& mimeType, const Uint8Ar
ray& initData) | 101 void MediaKeySession::initializeNewSession(const String& mimeType, const Uint8Ar
ray& initData) |
| 99 { | 102 { |
| 100 ASSERT(!m_isClosed); | 103 ASSERT(!m_isClosed); |
| 101 m_session->initializeNewSession(mimeType, initData); | 104 m_session->initializeNewSession(mimeType, initData.data(), initData.length()
); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void MediaKeySession::update(Uint8Array* response, ExceptionState& exceptionStat
e) | 107 void MediaKeySession::update(Uint8Array* response, ExceptionState& exceptionStat
e) |
| 105 { | 108 { |
| 106 WTF_LOG(Media, "MediaKeySession::update"); | 109 WTF_LOG(Media, "MediaKeySession::update"); |
| 107 ASSERT(!m_isClosed); | 110 ASSERT(!m_isClosed); |
| 108 | 111 |
| 109 // From <https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/
encrypted-media.html#dom-update>: | 112 // From <https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/
encrypted-media.html#dom-update>: |
| 110 // The update(response) method must run the following steps: | 113 // The update(response) method must run the following steps: |
| 111 // 1. If response is null or an empty array, throw an INVALID_ACCESS_ERR | 114 // 1. If response is null or an empty array, throw an INVALID_ACCESS_ERR |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 while (!m_pendingActions.isEmpty()) { | 154 while (!m_pendingActions.isEmpty()) { |
| 152 OwnPtr<PendingAction> pendingAction(m_pendingActions.takeFirst()); | 155 OwnPtr<PendingAction> pendingAction(m_pendingActions.takeFirst()); |
| 153 | 156 |
| 154 switch (pendingAction->type) { | 157 switch (pendingAction->type) { |
| 155 case PendingAction::Update: | 158 case PendingAction::Update: |
| 156 // NOTE: Continued from step 3. of MediaKeySession::update() | 159 // NOTE: Continued from step 3. of MediaKeySession::update() |
| 157 // 3.1. Let cdm be the cdm loaded in the MediaKeys constructor. | 160 // 3.1. Let cdm be the cdm loaded in the MediaKeys constructor. |
| 158 // 3.2. Let request be null. | 161 // 3.2. Let request be null. |
| 159 // 3.3. Use cdm to execute the following steps: | 162 // 3.3. Use cdm to execute the following steps: |
| 160 // 3.3.1 Process response. | 163 // 3.3.1 Process response. |
| 161 m_session->update(*(pendingAction->data)); | 164 m_session->update(pendingAction->data->data(), pendingAction->data->
length()); |
| 162 break; | 165 break; |
| 163 case PendingAction::Release: | 166 case PendingAction::Release: |
| 164 // NOTE: Continued from step 3. of MediaKeySession::release(). | 167 // NOTE: Continued from step 3. of MediaKeySession::release(). |
| 165 // 3.1 Let cdm be the cdm loaded in the MediaKeys constructor. | 168 // 3.1 Let cdm be the cdm loaded in the MediaKeys constructor. |
| 166 // 3.2 Use cdm to execute the following steps: | 169 // 3.2 Use cdm to execute the following steps: |
| 167 // 3.2.1 Process the release request. | 170 // 3.2.1 Process the release request. |
| 168 m_session->release(); | 171 m_session->release(); |
| 169 break; | 172 break; |
| 170 } | 173 } |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 // Queue a task to fire a simple event named keymessage at the new object | 177 // Queue a task to fire a simple event named keymessage at the new object |
| 175 void MediaKeySession::message(const unsigned char* message, size_t messageLength
, const KURL& destinationURL) | 178 void MediaKeySession::message(const unsigned char* message, size_t messageLength
, const blink::WebURL& destinationURL) |
| 176 { | 179 { |
| 177 WTF_LOG(Media, "MediaKeySession::message"); | 180 WTF_LOG(Media, "MediaKeySession::message"); |
| 178 | 181 |
| 179 MediaKeyMessageEventInit init; | 182 MediaKeyMessageEventInit init; |
| 180 init.bubbles = false; | 183 init.bubbles = false; |
| 181 init.cancelable = false; | 184 init.cancelable = false; |
| 182 init.message = Uint8Array::create(message, messageLength); | 185 init.message = Uint8Array::create(message, messageLength); |
| 183 init.destinationURL = destinationURL; | 186 init.destinationURL = destinationURL.string(); |
| 184 | 187 |
| 185 RefPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::create(EventTypeN
ames::message, init); | 188 RefPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::create(EventTypeN
ames::message, init); |
| 186 event->setTarget(this); | 189 event->setTarget(this); |
| 187 m_asyncEventQueue->enqueueEvent(event.release()); | 190 m_asyncEventQueue->enqueueEvent(event.release()); |
| 188 } | 191 } |
| 189 | 192 |
| 190 void MediaKeySession::ready() | 193 void MediaKeySession::ready() |
| 191 { | 194 { |
| 192 WTF_LOG(Media, "MediaKeySession::ready"); | 195 WTF_LOG(Media, "MediaKeySession::ready"); |
| 193 | 196 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 209 m_isClosed = true; | 212 m_isClosed = true; |
| 210 } | 213 } |
| 211 | 214 |
| 212 // Queue a task to fire a simple event named keyadded at the MediaKeySession obj
ect. | 215 // Queue a task to fire a simple event named keyadded at the MediaKeySession obj
ect. |
| 213 void MediaKeySession::error(MediaKeyErrorCode errorCode, unsigned long systemCod
e) | 216 void MediaKeySession::error(MediaKeyErrorCode errorCode, unsigned long systemCod
e) |
| 214 { | 217 { |
| 215 WTF_LOG(Media, "MediaKeySession::error: errorCode=%d, systemCode=%lu", error
Code, systemCode); | 218 WTF_LOG(Media, "MediaKeySession::error: errorCode=%d, systemCode=%lu", error
Code, systemCode); |
| 216 | 219 |
| 217 MediaKeyError::Code mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_UNKNOWN; | 220 MediaKeyError::Code mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_UNKNOWN; |
| 218 switch (errorCode) { | 221 switch (errorCode) { |
| 219 case UnknownError: | 222 case MediaKeyErrorCodeUnknown: |
| 220 mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_UNKNOWN; | 223 mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_UNKNOWN; |
| 221 break; | 224 break; |
| 222 case ClientError: | 225 case MediaKeyErrorCodeClient: |
| 223 mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_CLIENT; | 226 mediaKeyErrorCode = MediaKeyError::MEDIA_KEYERR_CLIENT; |
| 224 break; | 227 break; |
| 225 } | 228 } |
| 226 | 229 |
| 227 // 1. Create a new MediaKeyError object with the following attributes: | 230 // 1. Create a new MediaKeyError object with the following attributes: |
| 228 // code = the appropriate MediaKeyError code | 231 // code = the appropriate MediaKeyError code |
| 229 // systemCode = a Key System-specific value, if provided, and 0 otherwise | 232 // systemCode = a Key System-specific value, if provided, and 0 otherwise |
| 230 // 2. Set the MediaKeySession object's error attribute to the error object c
reated in the previous step. | 233 // 2. Set the MediaKeySession object's error attribute to the error object c
reated in the previous step. |
| 231 m_error = MediaKeyError::create(mediaKeyErrorCode, systemCode); | 234 m_error = MediaKeyError::create(mediaKeyErrorCode, systemCode); |
| 232 | 235 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 262 m_session.clear(); | 265 m_session.clear(); |
| 263 m_isClosed = true; | 266 m_isClosed = true; |
| 264 | 267 |
| 265 if (m_actionTimer.isActive()) | 268 if (m_actionTimer.isActive()) |
| 266 m_actionTimer.stop(); | 269 m_actionTimer.stop(); |
| 267 m_pendingActions.clear(); | 270 m_pendingActions.clear(); |
| 268 m_asyncEventQueue->close(); | 271 m_asyncEventQueue->close(); |
| 269 } | 272 } |
| 270 | 273 |
| 271 } | 274 } |
| OLD | NEW |