| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/renderer/media/cdm_result_promise.h" | |
| 13 #include "content/renderer/media/cdm_session_adapter.h" | 12 #include "content/renderer/media/cdm_session_adapter.h" |
| 14 #include "media/base/cdm_promise.h" | 13 #include "media/base/cdm_promise.h" |
| 14 #include "media/base/media_keys.h" |
| 15 #include "media/blink/cdm_result_promise.h" |
| 16 #include "media/blink/new_session_cdm_result_promise.h" |
| 15 #include "third_party/WebKit/public/platform/WebURL.h" | 17 #include "third_party/WebKit/public/platform/WebURL.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 | 20 |
| 19 const char kCreateSessionUMAName[] = "CreateSession"; | 21 const char kCreateSessionUMAName[] = "CreateSession"; |
| 20 const char kLoadSessionUMAName[] = "LoadSession"; | 22 const char kLoadSessionUMAName[] = "LoadSession"; |
| 21 | 23 |
| 22 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( | 24 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
| 23 const scoped_refptr<CdmSessionAdapter>& adapter) | 25 const scoped_refptr<CdmSessionAdapter>& adapter) |
| 24 : adapter_(adapter), | 26 : adapter_(adapter), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 std::string init_data_type_as_ascii = base::UTF16ToASCII(init_data_type); | 86 std::string init_data_type_as_ascii = base::UTF16ToASCII(init_data_type); |
| 85 DLOG_IF(WARNING, init_data_type_as_ascii.find('/') != std::string::npos) | 87 DLOG_IF(WARNING, init_data_type_as_ascii.find('/') != std::string::npos) |
| 86 << "init_data_type '" << init_data_type_as_ascii | 88 << "init_data_type '" << init_data_type_as_ascii |
| 87 << "' may be a MIME type"; | 89 << "' may be a MIME type"; |
| 88 | 90 |
| 89 adapter_->InitializeNewSession( | 91 adapter_->InitializeNewSession( |
| 90 init_data_type_as_ascii, | 92 init_data_type_as_ascii, |
| 91 init_data, | 93 init_data, |
| 92 init_data_length, | 94 init_data_length, |
| 93 media::MediaKeys::TEMPORARY_SESSION, | 95 media::MediaKeys::TEMPORARY_SESSION, |
| 94 scoped_ptr<media::NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 96 scoped_ptr<media::NewSessionCdmPromise>( |
| 95 result, | 97 new media::NewSessionCdmResultPromise( |
| 96 adapter_->GetKeySystemUMAPrefix() + kCreateSessionUMAName, | 98 result, |
| 97 base::Bind( | 99 adapter_->GetKeySystemUMAPrefix() + kCreateSessionUMAName, |
| 98 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 100 base::Bind( |
| 99 base::Unretained(this))))); | 101 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
| 102 base::Unretained(this))))); |
| 100 } | 103 } |
| 101 | 104 |
| 102 void WebContentDecryptionModuleSessionImpl::load( | 105 void WebContentDecryptionModuleSessionImpl::load( |
| 103 const blink::WebString& session_id, | 106 const blink::WebString& session_id, |
| 104 blink::WebContentDecryptionModuleResult result) { | 107 blink::WebContentDecryptionModuleResult result) { |
| 105 DCHECK(!session_id.isEmpty()); | 108 DCHECK(!session_id.isEmpty()); |
| 106 DCHECK(web_session_id_.empty()); | 109 DCHECK(web_session_id_.empty()); |
| 107 | 110 |
| 108 adapter_->LoadSession( | 111 adapter_->LoadSession( |
| 109 base::UTF16ToASCII(session_id), | 112 base::UTF16ToASCII(session_id), |
| 110 scoped_ptr<media::NewSessionCdmPromise>(new NewSessionCdmResultPromise( | 113 scoped_ptr<media::NewSessionCdmPromise>( |
| 111 result, | 114 new media::NewSessionCdmResultPromise( |
| 112 adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, | 115 result, |
| 113 base::Bind( | 116 adapter_->GetKeySystemUMAPrefix() + kLoadSessionUMAName, |
| 114 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, | 117 base::Bind( |
| 115 base::Unretained(this))))); | 118 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
| 119 base::Unretained(this))))); |
| 116 } | 120 } |
| 117 | 121 |
| 118 void WebContentDecryptionModuleSessionImpl::update( | 122 void WebContentDecryptionModuleSessionImpl::update( |
| 119 const uint8* response, | 123 const uint8* response, |
| 120 size_t response_length, | 124 size_t response_length, |
| 121 blink::WebContentDecryptionModuleResult result) { | 125 blink::WebContentDecryptionModuleResult result) { |
| 122 DCHECK(response); | 126 DCHECK(response); |
| 123 DCHECK(!web_session_id_.empty()); | 127 DCHECK(!web_session_id_.empty()); |
| 124 adapter_->UpdateSession(web_session_id_, | 128 adapter_->UpdateSession( |
| 125 response, | 129 web_session_id_, |
| 126 response_length, | 130 response, |
| 127 scoped_ptr<media::SimpleCdmPromise>( | 131 response_length, |
| 128 new CdmResultPromise<>(result, std::string()))); | 132 scoped_ptr<media::SimpleCdmPromise>( |
| 133 new media::CdmResultPromise<>(result, std::string()))); |
| 129 } | 134 } |
| 130 | 135 |
| 131 void WebContentDecryptionModuleSessionImpl::close( | 136 void WebContentDecryptionModuleSessionImpl::close( |
| 132 blink::WebContentDecryptionModuleResult result) { | 137 blink::WebContentDecryptionModuleResult result) { |
| 133 DCHECK(!web_session_id_.empty()); | 138 DCHECK(!web_session_id_.empty()); |
| 134 adapter_->CloseSession(web_session_id_, | 139 adapter_->CloseSession( |
| 135 scoped_ptr<media::SimpleCdmPromise>( | 140 web_session_id_, |
| 136 new CdmResultPromise<>(result, std::string()))); | 141 scoped_ptr<media::SimpleCdmPromise>( |
| 142 new media::CdmResultPromise<>(result, std::string()))); |
| 137 } | 143 } |
| 138 | 144 |
| 139 void WebContentDecryptionModuleSessionImpl::remove( | 145 void WebContentDecryptionModuleSessionImpl::remove( |
| 140 blink::WebContentDecryptionModuleResult result) { | 146 blink::WebContentDecryptionModuleResult result) { |
| 141 DCHECK(!web_session_id_.empty()); | 147 DCHECK(!web_session_id_.empty()); |
| 142 adapter_->RemoveSession(web_session_id_, | 148 adapter_->RemoveSession( |
| 143 scoped_ptr<media::SimpleCdmPromise>( | 149 web_session_id_, |
| 144 new CdmResultPromise<>(result, std::string()))); | 150 scoped_ptr<media::SimpleCdmPromise>( |
| 151 new media::CdmResultPromise<>(result, std::string()))); |
| 145 } | 152 } |
| 146 | 153 |
| 147 void WebContentDecryptionModuleSessionImpl::getUsableKeyIds( | 154 void WebContentDecryptionModuleSessionImpl::getUsableKeyIds( |
| 148 blink::WebContentDecryptionModuleResult result) { | 155 blink::WebContentDecryptionModuleResult result) { |
| 149 DCHECK(!web_session_id_.empty()); | 156 DCHECK(!web_session_id_.empty()); |
| 150 adapter_->GetUsableKeyIds( | 157 adapter_->GetUsableKeyIds( |
| 151 web_session_id_, | 158 web_session_id_, |
| 152 scoped_ptr<media::KeyIdsPromise>( | 159 scoped_ptr<media::KeyIdsPromise>( |
| 153 new CdmResultPromise<media::KeyIdsVector>(result, std::string()))); | 160 new media::CdmResultPromise<media::KeyIdsVector>(result, |
| 161 std::string()))); |
| 154 } | 162 } |
| 155 | 163 |
| 156 void WebContentDecryptionModuleSessionImpl::release( | 164 void WebContentDecryptionModuleSessionImpl::release( |
| 157 blink::WebContentDecryptionModuleResult result) { | 165 blink::WebContentDecryptionModuleResult result) { |
| 158 close(result); | 166 close(result); |
| 159 } | 167 } |
| 160 | 168 |
| 161 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( | 169 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
| 162 const std::vector<uint8>& message, | 170 const std::vector<uint8>& message, |
| 163 const GURL& destination_url) { | 171 const GURL& destination_url) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 176 // TODO(jrummell): Update this once Blink client supports this. | 184 // TODO(jrummell): Update this once Blink client supports this. |
| 177 // The EME spec has expiration attribute as the time in milliseconds, so use | 185 // The EME spec has expiration attribute as the time in milliseconds, so use |
| 178 // InMillisecondsF() to convert. | 186 // InMillisecondsF() to convert. |
| 179 } | 187 } |
| 180 | 188 |
| 181 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { | 189 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { |
| 182 client_->ready(); | 190 client_->ready(); |
| 183 } | 191 } |
| 184 | 192 |
| 185 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { | 193 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { |
| 186 if (!is_closed_) { | 194 if (is_closed_) |
| 187 is_closed_ = true; | 195 return; |
| 188 client_->close(); | 196 |
| 189 } | 197 is_closed_ = true; |
| 198 client_->close(); |
| 190 } | 199 } |
| 191 | 200 |
| 192 void WebContentDecryptionModuleSessionImpl::OnSessionError( | 201 void WebContentDecryptionModuleSessionImpl::OnSessionError( |
| 193 media::MediaKeys::Exception exception_code, | 202 media::MediaKeys::Exception exception_code, |
| 194 uint32 system_code, | 203 uint32 system_code, |
| 195 const std::string& error_message) { | 204 const std::string& error_message) { |
| 196 // Convert |exception_code| back to MediaKeyErrorCode if possible. | 205 // Convert |exception_code| back to MediaKeyErrorCode if possible. |
| 197 // TODO(jrummell): Update this conversion when promises flow | 206 // TODO(jrummell): Update this conversion when promises flow |
| 198 // back into blink:: (as blink:: will have its own error definition). | 207 // back into blink:: (as blink:: will have its own error definition). |
| 199 switch (exception_code) { | 208 switch (exception_code) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 217 | 226 |
| 218 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; | 227 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; |
| 219 web_session_id_ = web_session_id; | 228 web_session_id_ = web_session_id; |
| 220 return adapter_->RegisterSession(web_session_id_, | 229 return adapter_->RegisterSession(web_session_id_, |
| 221 weak_ptr_factory_.GetWeakPtr()) | 230 weak_ptr_factory_.GetWeakPtr()) |
| 222 ? blink::WebContentDecryptionModuleResult::NewSession | 231 ? blink::WebContentDecryptionModuleResult::NewSession |
| 223 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; | 232 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
| 224 } | 233 } |
| 225 | 234 |
| 226 } // namespace content | 235 } // namespace content |
| OLD | NEW |