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_id_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<CdmSessionIdAdapter> adapter) |
19 : media_keys_(media_keys), | 19 : adapter_(adapter), |
20 client_(client), | 20 client_(client), |
21 session_closed_cb_(session_closed_cb), | |
22 session_id_(session_id) { | 21 session_id_(session_id) { |
23 DCHECK(media_keys_); | 22 adapter_->AddSession(session_id, this); |
24 } | 23 } |
25 | 24 |
26 WebContentDecryptionModuleSessionImpl:: | 25 WebContentDecryptionModuleSessionImpl:: |
27 ~WebContentDecryptionModuleSessionImpl() { | 26 ~WebContentDecryptionModuleSessionImpl() { |
28 } | 27 } |
29 | 28 |
30 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { | 29 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { |
31 return web_session_id_; | 30 return web_session_id_; |
32 } | 31 } |
33 | 32 |
34 void WebContentDecryptionModuleSessionImpl::initializeNewSession( | 33 void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
35 const blink::WebString& mime_type, | 34 const blink::WebString& mime_type, |
36 const uint8* init_data, size_t init_data_length) { | 35 const uint8* init_data, size_t init_data_length) { |
37 // TODO(ddorwin): Guard against this in supported types check and remove this. | 36 // TODO(ddorwin): Guard against this in supported types check and remove this. |
38 // Chromium only supports ASCII MIME types. | 37 // Chromium only supports ASCII MIME types. |
39 if (!IsStringASCII(mime_type)) { | 38 if (!IsStringASCII(mime_type)) { |
40 NOTREACHED(); | 39 NOTREACHED(); |
41 OnSessionError(media::MediaKeys::kUnknownError, 0); | 40 OnSessionError(media::MediaKeys::kUnknownError, 0); |
42 return; | 41 return; |
43 } | 42 } |
44 | 43 |
45 media_keys_->CreateSession( | 44 adapter_->CreateSession( |
ddorwin
2014/02/18 20:59:42
It really is the CDM interface! All the more reaso
| |
46 session_id_, UTF16ToASCII(mime_type), init_data, init_data_length); | 45 session_id_, UTF16ToASCII(mime_type), init_data, init_data_length); |
47 } | 46 } |
48 | 47 |
49 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, | 48 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, |
50 size_t response_length) { | 49 size_t response_length) { |
51 DCHECK(response); | 50 DCHECK(response); |
52 media_keys_->UpdateSession(session_id_, response, response_length); | 51 adapter_->UpdateSession(session_id_, response, response_length); |
53 } | 52 } |
54 | 53 |
55 void WebContentDecryptionModuleSessionImpl::release() { | 54 void WebContentDecryptionModuleSessionImpl::release() { |
56 media_keys_->ReleaseSession(session_id_); | 55 adapter_->ReleaseSession(session_id_); |
57 } | 56 } |
58 | 57 |
59 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( | 58 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( |
60 const std::string& web_session_id) { | 59 const std::string& web_session_id) { |
61 // Due to heartbeat messages, OnSessionCreated() can get called multiple | 60 // Due to heartbeat messages, OnSessionCreated() can get called multiple |
62 // times. | 61 // times. |
63 // TODO(jrummell): Once all CDMs are updated to support reference ids, | 62 // TODO(jrummell): Once all CDMs are updated to support reference ids, |
64 // OnSessionCreated() should only be called once, and the second check can be | 63 // OnSessionCreated() should only be called once, and the second check can be |
65 // removed. | 64 // removed. |
66 blink::WebString id = blink::WebString::fromUTF8(web_session_id); | 65 blink::WebString id = blink::WebString::fromUTF8(web_session_id); |
67 DCHECK(web_session_id_.isEmpty() || web_session_id_ == id) | 66 DCHECK(web_session_id_.isEmpty() || web_session_id_ == id) |
68 << "Session ID may not be changed once set."; | 67 << "Session ID may not be changed once set."; |
69 web_session_id_ = id; | 68 web_session_id_ = id; |
70 } | 69 } |
71 | 70 |
72 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 71 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
73 const std::vector<uint8>& message, | 72 const std::vector<uint8>& message, |
74 const std::string& destination_url) { | 73 const std::string& destination_url) { |
75 client_->message(message.empty() ? NULL : &message[0], | 74 client_->message(message.empty() ? NULL : &message[0], |
76 message.size(), | 75 message.size(), |
77 GURL(destination_url)); | 76 GURL(destination_url)); |
78 } | 77 } |
79 | 78 |
80 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { | 79 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { |
81 client_->ready(); | 80 client_->ready(); |
82 } | 81 } |
83 | 82 |
84 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { | 83 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
85 client_->close(); | 84 client_->close(); |
86 if (!session_closed_cb_.is_null()) | 85 adapter_->RemoveSession(session_id_); |
87 base::ResetAndReturn(&session_closed_cb_).Run(session_id_); | |
88 } | 86 } |
89 | 87 |
90 void WebContentDecryptionModuleSessionImpl::OnSessionError( | 88 void WebContentDecryptionModuleSessionImpl::OnSessionError( |
91 media::MediaKeys::KeyError error_code, | 89 media::MediaKeys::KeyError error_code, |
92 int system_code) { | 90 int system_code) { |
93 client_->error(static_cast<Client::MediaKeyErrorCode>(error_code), | 91 client_->error(static_cast<Client::MediaKeyErrorCode>(error_code), |
94 system_code); | 92 system_code); |
95 } | 93 } |
96 | 94 |
97 } // namespace content | 95 } // namespace content |
OLD | NEW |