| 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 "webcontentdecryptionmodulesession_impl.h" | 5 #include "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/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { | 109 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { |
| 110 return blink::WebString::fromUTF8(session_id_); | 110 return blink::WebString::fromUTF8(session_id_); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void WebContentDecryptionModuleSessionImpl::initializeNewSession( | 113 void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
| 114 blink::WebEncryptedMediaInitDataType init_data_type, | 114 blink::WebEncryptedMediaInitDataType init_data_type, |
| 115 const unsigned char* init_data, | 115 const unsigned char* init_data, |
| 116 size_t init_data_length, | 116 size_t init_data_length, |
| 117 blink::WebEncryptedMediaSessionType session_type, | 117 blink::WebEncryptedMediaSessionType session_type, |
| 118 blink::WebContentDecryptionModuleResult result) { | 118 blink::WebContentDecryptionModuleResult result) { |
| 119 DCHECK(init_data); |
| 119 DCHECK(session_id_.empty()); | 120 DCHECK(session_id_.empty()); |
| 120 | 121 |
| 121 // Step 5 from https://w3c.github.io/encrypted-media/#generateRequest. | 122 // Step 5 from https://w3c.github.io/encrypted-media/#generateRequest. |
| 122 // 5. If the Key System implementation represented by this object's cdm | 123 // 5. If the Key System implementation represented by this object's cdm |
| 123 // implementation value does not support initDataType as an Initialization | 124 // implementation value does not support initDataType as an Initialization |
| 124 // Data Type, return a promise rejected with a new DOMException whose name | 125 // Data Type, return a promise rejected with a new DOMException whose name |
| 125 // is NotSupportedError. String comparison is case-sensitive. | 126 // is NotSupportedError. String comparison is case-sensitive. |
| 126 EmeInitDataType eme_init_data_type = ConvertToEmeInitDataType(init_data_type); | 127 EmeInitDataType eme_init_data_type = ConvertToEmeInitDataType(init_data_type); |
| 127 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(), | 128 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(), |
| 128 eme_init_data_type)) { | 129 eme_init_data_type)) { |
| 129 std::string message = | 130 std::string message = |
| 130 "The initialization data type is not supported by the key system."; | 131 "The initialization data type is not supported by the key system."; |
| 131 result.completeWithError( | 132 result.completeWithError( |
| 132 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, | 133 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, |
| 133 blink::WebString::fromUTF8(message)); | 134 blink::WebString::fromUTF8(message)); |
| 134 return; | 135 return; |
| 135 } | 136 } |
| 136 | 137 |
| 137 adapter_->InitializeNewSession( | 138 adapter_->InitializeNewSession( |
| 138 eme_init_data_type, init_data, | 139 eme_init_data_type, |
| 139 base::saturated_cast<int>(init_data_length), | 140 std::vector<uint8>(init_data, init_data + init_data_length), |
| 140 convertSessionType(session_type), | 141 convertSessionType(session_type), |
| 141 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 142 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( |
| 142 result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName, | 143 result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName, |
| 143 base::Bind( | 144 base::Bind( |
| 144 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 145 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
| 145 base::Unretained(this))))); | 146 base::Unretained(this))))); |
| 146 } | 147 } |
| 147 | 148 |
| 148 // TODO(jrummell): Remove this. http://crbug.com/418239. | 149 // TODO(jrummell): Remove this. http://crbug.com/418239. |
| 149 void WebContentDecryptionModuleSessionImpl::initializeNewSession( | 150 void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 173 base::Unretained(this))))); | 174 base::Unretained(this))))); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void WebContentDecryptionModuleSessionImpl::update( | 177 void WebContentDecryptionModuleSessionImpl::update( |
| 177 const uint8* response, | 178 const uint8* response, |
| 178 size_t response_length, | 179 size_t response_length, |
| 179 blink::WebContentDecryptionModuleResult result) { | 180 blink::WebContentDecryptionModuleResult result) { |
| 180 DCHECK(response); | 181 DCHECK(response); |
| 181 DCHECK(!session_id_.empty()); | 182 DCHECK(!session_id_.empty()); |
| 182 adapter_->UpdateSession( | 183 adapter_->UpdateSession( |
| 183 session_id_, response, base::saturated_cast<int>(response_length), | 184 session_id_, std::vector<uint8>(response, response + response_length), |
| 184 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 185 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| 185 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); | 186 result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void WebContentDecryptionModuleSessionImpl::close( | 189 void WebContentDecryptionModuleSessionImpl::close( |
| 189 blink::WebContentDecryptionModuleResult result) { | 190 blink::WebContentDecryptionModuleResult result) { |
| 190 DCHECK(!session_id_.empty()); | 191 DCHECK(!session_id_.empty()); |
| 191 adapter_->CloseSession( | 192 adapter_->CloseSession( |
| 192 session_id_, | 193 session_id_, |
| 193 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( | 194 scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return blink::WebContentDecryptionModuleResult::SessionNotFound; | 250 return blink::WebContentDecryptionModuleResult::SessionNotFound; |
| 250 | 251 |
| 251 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; | 252 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; |
| 252 session_id_ = session_id; | 253 session_id_ = session_id; |
| 253 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) | 254 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) |
| 254 ? blink::WebContentDecryptionModuleResult::NewSession | 255 ? blink::WebContentDecryptionModuleResult::NewSession |
| 255 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; | 256 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
| 256 } | 257 } |
| 257 | 258 |
| 258 } // namespace media | 259 } // namespace media |
| OLD | NEW |