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/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) { |
| 212 client_->message( | 214 client_->message( |
|
ddorwin
2014/07/10 23:22:41
This is the interesting point, especially after th
jrummell
2014/07/17 00:56:54
Done.
| |
| 213 message.empty() ? NULL : &message[0], message.size(), destination_url); | 215 message.empty() ? NULL : &message[0], message.size(), destination_url); |
| 214 } | 216 } |
| 215 | 217 |
| 216 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { | 218 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { |
| 217 client_->ready(); | 219 client_->ready(); |
| 218 } | 220 } |
| 219 | 221 |
| 220 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { | 222 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
| 221 if (!is_closed_) { | 223 if (!is_closed_) { |
| 222 is_closed_ = true; | 224 is_closed_ = true; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 | 297 |
| 296 uint32 WebContentDecryptionModuleSessionImpl::AddResult( | 298 uint32 WebContentDecryptionModuleSessionImpl::AddResult( |
| 297 blink::WebContentDecryptionModuleResult result) { | 299 blink::WebContentDecryptionModuleResult result) { |
| 298 uint32 result_index = next_available_result_index_++; | 300 uint32 result_index = next_available_result_index_++; |
| 299 DCHECK(result_index != kReservedIndex); | 301 DCHECK(result_index != kReservedIndex); |
| 300 outstanding_results_.insert(std::make_pair(result_index, result)); | 302 outstanding_results_.insert(std::make_pair(result_index, result)); |
| 301 return result_index; | 303 return result_index; |
| 302 } | 304 } |
| 303 | 305 |
| 304 } // namespace content | 306 } // namespace content |
| OLD | NEW |