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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 return blink::WebContentDecryptionModuleExceptionClientError; | 39 return blink::WebContentDecryptionModuleExceptionClientError; |
40 case media::MediaKeys::OUTPUT_ERROR: | 40 case media::MediaKeys::OUTPUT_ERROR: |
41 return blink::WebContentDecryptionModuleExceptionOutputError; | 41 return blink::WebContentDecryptionModuleExceptionOutputError; |
42 default: | 42 default: |
43 NOTREACHED(); | 43 NOTREACHED(); |
44 return blink::WebContentDecryptionModuleExceptionUnknownError; | 44 return blink::WebContentDecryptionModuleExceptionUnknownError; |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( | 48 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
49 Client* client, | |
50 const scoped_refptr<CdmSessionAdapter>& adapter) | 49 const scoped_refptr<CdmSessionAdapter>& adapter) |
51 : adapter_(adapter), | 50 : adapter_(adapter), |
52 client_(client), | |
53 is_closed_(false), | 51 is_closed_(false), |
54 next_available_result_index_(1), | 52 next_available_result_index_(1), |
55 weak_ptr_factory_(this) { | 53 weak_ptr_factory_(this) { |
56 } | 54 } |
57 | 55 |
58 WebContentDecryptionModuleSessionImpl:: | 56 WebContentDecryptionModuleSessionImpl:: |
59 ~WebContentDecryptionModuleSessionImpl() { | 57 ~WebContentDecryptionModuleSessionImpl() { |
60 if (!web_session_id_.empty()) | 58 if (!web_session_id_.empty()) |
61 adapter_->RemoveSession(web_session_id_); | 59 adapter_->RemoveSession(web_session_id_); |
62 | 60 |
63 // Release any WebContentDecryptionModuleResult objects that are left. Their | 61 // Release any WebContentDecryptionModuleResult objects that are left. Their |
64 // index will have been passed down via a CdmPromise, but it uses a WeakPtr. | 62 // index will have been passed down via a CdmPromise, but it uses a WeakPtr. |
65 DLOG_IF(WARNING, outstanding_results_.size() > 0) | 63 DLOG_IF(WARNING, outstanding_results_.size() > 0) |
66 << "Clearing " << outstanding_results_.size() << " results"; | 64 << "Clearing " << outstanding_results_.size() << " results"; |
67 for (ResultMap::iterator it = outstanding_results_.begin(); | 65 for (ResultMap::iterator it = outstanding_results_.begin(); |
68 it != outstanding_results_.end(); | 66 it != outstanding_results_.end(); |
69 ++it) { | 67 ++it) { |
70 it->second.completeWithError( | 68 it->second.completeWithError( |
71 blink::WebContentDecryptionModuleExceptionInvalidStateError, | 69 blink::WebContentDecryptionModuleExceptionInvalidStateError, |
72 0, | 70 0, |
73 "Outstanding request being cancelled."); | 71 "Outstanding request being cancelled."); |
74 } | 72 } |
75 outstanding_results_.clear(); | 73 outstanding_results_.clear(); |
76 } | 74 } |
77 | 75 |
| 76 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { |
| 77 client_ = client; |
| 78 } |
| 79 |
78 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { | 80 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { |
79 return blink::WebString::fromUTF8(web_session_id_); | 81 return blink::WebString::fromUTF8(web_session_id_); |
80 } | 82 } |
81 | 83 |
82 void WebContentDecryptionModuleSessionImpl::initializeNewSession( | 84 void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
83 const blink::WebString& init_data_type, | 85 const blink::WebString& init_data_type, |
84 const uint8* init_data, | 86 const uint8* init_data, |
85 size_t init_data_length) { | 87 size_t init_data_length) { |
86 // TODO(ddorwin): Guard against this in supported types check and remove this. | 88 // TODO(ddorwin): Guard against this in supported types check and remove this. |
87 // Chromium only supports ASCII MIME types. | 89 // Chromium only supports ASCII MIME types. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 result_index), | 204 result_index), |
203 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError, | 205 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError, |
204 weak_ptr_factory_.GetWeakPtr(), | 206 weak_ptr_factory_.GetWeakPtr(), |
205 result_index))); | 207 result_index))); |
206 adapter_->ReleaseSession(web_session_id_, promise.Pass()); | 208 adapter_->ReleaseSession(web_session_id_, promise.Pass()); |
207 } | 209 } |
208 | 210 |
209 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 211 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
210 const std::vector<uint8>& message, | 212 const std::vector<uint8>& message, |
211 const GURL& destination_url) { | 213 const GURL& destination_url) { |
| 214 DCHECK(client_) << "Client not set before message event"; |
212 client_->message( | 215 client_->message( |
213 message.empty() ? NULL : &message[0], message.size(), destination_url); | 216 message.empty() ? NULL : &message[0], message.size(), destination_url); |
214 } | 217 } |
215 | 218 |
216 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { | 219 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { |
217 client_->ready(); | 220 client_->ready(); |
218 } | 221 } |
219 | 222 |
220 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { | 223 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
221 if (!is_closed_) { | 224 if (!is_closed_) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 298 |
296 uint32 WebContentDecryptionModuleSessionImpl::AddResult( | 299 uint32 WebContentDecryptionModuleSessionImpl::AddResult( |
297 blink::WebContentDecryptionModuleResult result) { | 300 blink::WebContentDecryptionModuleResult result) { |
298 uint32 result_index = next_available_result_index_++; | 301 uint32 result_index = next_available_result_index_++; |
299 DCHECK(result_index != kReservedIndex); | 302 DCHECK(result_index != kReservedIndex); |
300 outstanding_results_.insert(std::make_pair(result_index, result)); | 303 outstanding_results_.insert(std::make_pair(result_index, result)); |
301 return result_index; | 304 return result_index; |
302 } | 305 } |
303 | 306 |
304 } // namespace content | 307 } // namespace content |
OLD | NEW |