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
3 // found in the LICENSE file.
5 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
7 #include "base/callback_helpers.h"
8 #include "base/logging.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "content/renderer/media/cdm_session_adapter.h"
12 #include "third_party/WebKit/public/platform/WebURL.h"
16 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
19 const scoped_refptr
<CdmSessionAdapter
>& adapter
)
22 session_id_(session_id
) {
25 WebContentDecryptionModuleSessionImpl::
26 ~WebContentDecryptionModuleSessionImpl() {
27 adapter_
->RemoveSession(session_id_
);
30 blink::WebString
WebContentDecryptionModuleSessionImpl::sessionId() const {
31 return web_session_id_
;
34 void WebContentDecryptionModuleSessionImpl::initializeNewSession(
35 const blink::WebString
& mime_type
,
36 const uint8
* init_data
, size_t init_data_length
) {
37 // TODO(ddorwin): Guard against this in supported types check and remove this.
38 // Chromium only supports ASCII MIME types.
39 if (!base::IsStringASCII(mime_type
)) {
41 OnSessionError(media::MediaKeys::kUnknownError
, 0);
45 adapter_
->InitializeNewSession(
46 session_id_
, base::UTF16ToASCII(mime_type
), init_data
, init_data_length
);
49 void WebContentDecryptionModuleSessionImpl::update(const uint8
* response
,
50 size_t response_length
) {
52 adapter_
->UpdateSession(session_id_
, response
, response_length
);
55 void WebContentDecryptionModuleSessionImpl::release() {
56 adapter_
->ReleaseSession(session_id_
);
59 void WebContentDecryptionModuleSessionImpl::OnSessionCreated(
60 const std::string
& web_session_id
) {
61 // Due to heartbeat messages, OnSessionCreated() can get called multiple
63 // TODO(jrummell): Once all CDMs are updated to support reference ids,
64 // OnSessionCreated() should only be called once, and the second check can be
66 blink::WebString id
= blink::WebString::fromUTF8(web_session_id
);
67 DCHECK(web_session_id_
.isEmpty() || web_session_id_
== id
)
68 << "Session ID may not be changed once set.";
72 void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
73 const std::vector
<uint8
>& message
,
74 const GURL
& destination_url
) {
76 message
.empty() ? NULL
: &message
[0], message
.size(), destination_url
);
79 void WebContentDecryptionModuleSessionImpl::OnSessionReady() {
83 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() {
87 void WebContentDecryptionModuleSessionImpl::OnSessionError(
88 media::MediaKeys::KeyError error_code
,
90 client_
->error(static_cast<Client::MediaKeyErrorCode
>(error_code
),
94 } // namespace content