Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" | 5 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "content/renderer/media/cdm_session_adapter.h" | |
| 10 #include "third_party/WebKit/public/platform/WebURL.h" | 11 #include "third_party/WebKit/public/platform/WebURL.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( | 15 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
| 15 uint32 session_id, | 16 uint32 session_id, |
| 16 media::MediaKeys* media_keys, | |
| 17 Client* client, | 17 Client* client, |
| 18 const SessionClosedCB& session_closed_cb) | 18 scoped_refptr<CdmSessionAdapter> adapter) |
| 19 : media_keys_(media_keys), | 19 : adapter_(adapter), |
| 20 client_(client), | 20 client_(client), |
| 21 session_closed_cb_(session_closed_cb), | 21 session_id_(session_id), |
| 22 session_id_(session_id) { | 22 is_closed_(false) { |
| 23 DCHECK(media_keys_); | |
| 24 } | 23 } |
| 25 | 24 |
| 26 WebContentDecryptionModuleSessionImpl:: | 25 WebContentDecryptionModuleSessionImpl:: |
| 27 ~WebContentDecryptionModuleSessionImpl() { | 26 ~WebContentDecryptionModuleSessionImpl() { |
| 27 if (!is_closed_) | |
| 28 adapter_->RemoveSession(session_id_); | |
| 28 } | 29 } |
| 29 | 30 |
| 30 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { | 31 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { |
| 31 return web_session_id_; | 32 return web_session_id_; |
| 32 } | 33 } |
| 33 | 34 |
| 34 void WebContentDecryptionModuleSessionImpl::initializeNewSession( | 35 void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
| 35 const blink::WebString& mime_type, | 36 const blink::WebString& mime_type, |
| 36 const uint8* init_data, size_t init_data_length) { | 37 const uint8* init_data, size_t init_data_length) { |
| 37 // TODO(ddorwin): Guard against this in supported types check and remove this. | 38 // TODO(ddorwin): Guard against this in supported types check and remove this. |
| 38 // Chromium only supports ASCII MIME types. | 39 // Chromium only supports ASCII MIME types. |
| 39 if (!IsStringASCII(mime_type)) { | 40 if (!IsStringASCII(mime_type)) { |
| 40 NOTREACHED(); | 41 NOTREACHED(); |
| 41 OnSessionError(media::MediaKeys::kUnknownError, 0); | 42 OnSessionError(media::MediaKeys::kUnknownError, 0); |
| 42 return; | 43 return; |
| 43 } | 44 } |
| 44 | 45 |
| 45 media_keys_->CreateSession( | 46 adapter_->CreateSession( |
| 46 session_id_, UTF16ToASCII(mime_type), init_data, init_data_length); | 47 session_id_, UTF16ToASCII(mime_type), init_data, init_data_length); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, | 50 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, |
| 50 size_t response_length) { | 51 size_t response_length) { |
| 51 DCHECK(response); | 52 DCHECK(response); |
| 52 media_keys_->UpdateSession(session_id_, response, response_length); | 53 adapter_->UpdateSession(session_id_, response, response_length); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void WebContentDecryptionModuleSessionImpl::release() { | 56 void WebContentDecryptionModuleSessionImpl::release() { |
| 56 media_keys_->ReleaseSession(session_id_); | 57 adapter_->ReleaseSession(session_id_); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( | 60 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( |
| 60 const std::string& web_session_id) { | 61 const std::string& web_session_id) { |
| 61 // Due to heartbeat messages, OnSessionCreated() can get called multiple | 62 // Due to heartbeat messages, OnSessionCreated() can get called multiple |
| 62 // times. | 63 // times. |
| 63 // TODO(jrummell): Once all CDMs are updated to support reference ids, | 64 // TODO(jrummell): Once all CDMs are updated to support reference ids, |
| 64 // OnSessionCreated() should only be called once, and the second check can be | 65 // OnSessionCreated() should only be called once, and the second check can be |
| 65 // removed. | 66 // removed. |
| 66 blink::WebString id = blink::WebString::fromUTF8(web_session_id); | 67 blink::WebString id = blink::WebString::fromUTF8(web_session_id); |
| 67 DCHECK(web_session_id_.isEmpty() || web_session_id_ == id) | 68 DCHECK(web_session_id_.isEmpty() || web_session_id_ == id) |
| 68 << "Session ID may not be changed once set."; | 69 << "Session ID may not be changed once set."; |
| 69 web_session_id_ = id; | 70 web_session_id_ = id; |
| 70 } | 71 } |
| 71 | 72 |
| 72 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 73 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
| 73 const std::vector<uint8>& message, | 74 const std::vector<uint8>& message, |
| 74 const std::string& destination_url) { | 75 const std::string& destination_url) { |
| 75 client_->message(message.empty() ? NULL : &message[0], | 76 client_->message(message.empty() ? NULL : &message[0], |
| 76 message.size(), | 77 message.size(), |
| 77 GURL(destination_url)); | 78 GURL(destination_url)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { | 81 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { |
| 81 client_->ready(); | 82 client_->ready(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { | 85 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
| 85 client_->close(); | 86 client_->close(); |
| 86 if (!session_closed_cb_.is_null()) | 87 |
| 87 base::ResetAndReturn(&session_closed_cb_).Run(session_id_); | 88 // Now that the session is closed, no more events will come from the CDM. |
| 89 is_closed_ = true; | |
| 90 adapter_->RemoveSession(session_id_); | |
|
ddorwin
2014/02/19 01:41:53
Is there any advantage in de-registering the sessi
jrummell
2014/02/19 20:42:10
Not really. I just added it here in case the Blink
| |
| 88 } | 91 } |
| 89 | 92 |
| 90 void WebContentDecryptionModuleSessionImpl::OnSessionError( | 93 void WebContentDecryptionModuleSessionImpl::OnSessionError( |
| 91 media::MediaKeys::KeyError error_code, | 94 media::MediaKeys::KeyError error_code, |
| 92 int system_code) { | 95 int system_code) { |
| 93 client_->error(static_cast<Client::MediaKeyErrorCode>(error_code), | 96 client_->error(static_cast<Client::MediaKeyErrorCode>(error_code), |
| 94 system_code); | 97 system_code); |
| 95 } | 98 } |
| 96 | 99 |
| 97 } // namespace content | 100 } // namespace content |
| OLD | NEW |