| 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 "third_party/WebKit/public/platform/WebURL.h" | 10 #include "third_party/WebKit/public/platform/WebURL.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 static const uint32 kStartingReferenceId = 1; | |
| 15 uint32 WebContentDecryptionModuleSessionImpl::next_reference_id_ = | |
| 16 kStartingReferenceId; | |
| 17 COMPILE_ASSERT(kStartingReferenceId != media::MediaKeys::kInvalidReferenceId, | |
| 18 invalid_starting_value); | |
| 19 | |
| 20 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( | 14 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
| 15 uint32 session_id, |
| 21 media::MediaKeys* media_keys, | 16 media::MediaKeys* media_keys, |
| 22 Client* client, | 17 Client* client, |
| 23 const SessionClosedCB& session_closed_cb) | 18 const SessionClosedCB& session_closed_cb) |
| 24 : media_keys_(media_keys), | 19 : media_keys_(media_keys), |
| 25 client_(client), | 20 client_(client), |
| 26 session_closed_cb_(session_closed_cb), | 21 session_closed_cb_(session_closed_cb), |
| 27 reference_id_(next_reference_id_++) { | 22 session_id_(session_id) { |
| 28 DCHECK(media_keys_); | 23 DCHECK(media_keys_); |
| 29 } | 24 } |
| 30 | 25 |
| 31 WebContentDecryptionModuleSessionImpl:: | 26 WebContentDecryptionModuleSessionImpl:: |
| 32 ~WebContentDecryptionModuleSessionImpl() { | 27 ~WebContentDecryptionModuleSessionImpl() { |
| 33 } | 28 } |
| 34 | 29 |
| 35 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { | 30 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { |
| 36 return blink::WebString::fromUTF8(session_id_); | 31 return web_session_id_; |
| 37 } | 32 } |
| 38 | 33 |
| 39 void WebContentDecryptionModuleSessionImpl::generateKeyRequest( | 34 void WebContentDecryptionModuleSessionImpl::generateKeyRequest( |
| 40 const blink::WebString& mime_type, | 35 const blink::WebString& mime_type, |
| 41 const uint8* init_data, size_t init_data_length) { | 36 const uint8* init_data, size_t init_data_length) { |
| 42 // TODO(ddorwin): Guard against this in supported types check and remove this. | 37 // TODO(ddorwin): Guard against this in supported types check and remove this. |
| 43 // Chromium only supports ASCII MIME types. | 38 // Chromium only supports ASCII MIME types. |
| 44 if (!IsStringASCII(mime_type)) { | 39 if (!IsStringASCII(mime_type)) { |
| 45 NOTREACHED(); | 40 NOTREACHED(); |
| 46 OnSessionError(media::MediaKeys::kUnknownError, 0); | 41 OnSessionError(media::MediaKeys::kUnknownError, 0); |
| 47 return; | 42 return; |
| 48 } | 43 } |
| 49 | 44 |
| 50 media_keys_->CreateSession( | 45 media_keys_->CreateSession( |
| 51 reference_id_, UTF16ToASCII(mime_type), init_data, init_data_length); | 46 session_id_, UTF16ToASCII(mime_type), init_data, init_data_length); |
| 52 } | 47 } |
| 53 | 48 |
| 54 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, | 49 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, |
| 55 size_t response_length) { | 50 size_t response_length) { |
| 56 DCHECK(response); | 51 DCHECK(response); |
| 57 media_keys_->UpdateSession(reference_id_, response, response_length); | 52 media_keys_->UpdateSession(session_id_, response, response_length); |
| 58 } | 53 } |
| 59 | 54 |
| 60 void WebContentDecryptionModuleSessionImpl::close() { | 55 void WebContentDecryptionModuleSessionImpl::close() { |
| 61 media_keys_->ReleaseSession(reference_id_); | 56 media_keys_->ReleaseSession(session_id_); |
| 62 } | 57 } |
| 63 | 58 |
| 64 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( | 59 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( |
| 65 const std::string& session_id) { | 60 const std::string& web_session_id) { |
| 66 // Due to heartbeat messages, OnSessionCreated() can get called multiple | 61 // Due to heartbeat messages, OnSessionCreated() can get called multiple |
| 67 // times. | 62 // times. |
| 68 // TODO(jrummell): Once all CDMs are updated to support reference ids, | 63 // TODO(jrummell): Once all CDMs are updated to support reference ids, |
| 69 // OnSessionCreated() should only be called once, and the second check can be | 64 // OnSessionCreated() should only be called once, and the second check can be |
| 70 // removed. | 65 // removed. |
| 71 DCHECK(session_id_.empty() || session_id_ == session_id) | 66 blink::WebString id = blink::WebString::fromUTF8(web_session_id); |
| 67 DCHECK(web_session_id_.isEmpty() || web_session_id_ == id) |
| 72 << "Session ID may not be changed once set."; | 68 << "Session ID may not be changed once set."; |
| 73 session_id_ = session_id; | 69 web_session_id_ = id; |
| 74 } | 70 } |
| 75 | 71 |
| 76 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 72 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
| 77 const std::vector<uint8>& message, | 73 const std::vector<uint8>& message, |
| 78 const std::string& destination_url) { | 74 const std::string& destination_url) { |
| 79 client_->keyMessage(message.empty() ? NULL : &message[0], | 75 client_->keyMessage(message.empty() ? NULL : &message[0], |
| 80 message.size(), | 76 message.size(), |
| 81 GURL(destination_url)); | 77 GURL(destination_url)); |
| 82 } | 78 } |
| 83 | 79 |
| 84 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { | 80 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { |
| 85 // TODO(jrummell): Blink APIs need to be updated to the new EME API. For now, | 81 // TODO(jrummell): Blink APIs need to be updated to the new EME API. For now, |
| 86 // convert the response to the old v0.1b API. | 82 // convert the response to the old v0.1b API. |
| 87 client_->keyAdded(); | 83 client_->keyAdded(); |
| 88 } | 84 } |
| 89 | 85 |
| 90 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { | 86 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
| 91 if (!session_closed_cb_.is_null()) | 87 if (!session_closed_cb_.is_null()) |
| 92 base::ResetAndReturn(&session_closed_cb_).Run(reference_id_); | 88 base::ResetAndReturn(&session_closed_cb_).Run(session_id_); |
| 93 } | 89 } |
| 94 | 90 |
| 95 void WebContentDecryptionModuleSessionImpl::OnSessionError( | 91 void WebContentDecryptionModuleSessionImpl::OnSessionError( |
| 96 media::MediaKeys::KeyError error_code, | 92 media::MediaKeys::KeyError error_code, |
| 97 int system_code) { | 93 int system_code) { |
| 98 client_->keyError(static_cast<Client::MediaKeyErrorCode>(error_code), | 94 client_->keyError(static_cast<Client::MediaKeyErrorCode>(error_code), |
| 99 system_code); | 95 system_code); |
| 100 } | 96 } |
| 101 | 97 |
| 102 } // namespace content | 98 } // namespace content |
| OLD | NEW |