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