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 "third_party/WebKit/public/platform/WebURL.h"
14 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
15 media::MediaKeys* media_keys,
17 const SessionClosedCB& session_closed_cb)
18 : media_keys_(media_keys),
20 session_closed_cb_(session_closed_cb) {
22 // TODO(ddorwin): Populate session_id_ from the real implementation.
25 WebContentDecryptionModuleSessionImpl::
26 ~WebContentDecryptionModuleSessionImpl() {
29 WebKit::WebString WebContentDecryptionModuleSessionImpl::sessionId() const {
30 return WebKit::WebString::fromUTF8(session_id_);
33 void WebContentDecryptionModuleSessionImpl::generateKeyRequest(
34 const WebKit::WebString& mime_type,
35 const uint8* init_data, size_t init_data_length) {
36 // TODO(ddorwin): Guard against this in supported types check and remove this.
37 // Chromium only supports ASCII MIME types.
38 if (!IsStringASCII(mime_type)) {
40 KeyError(media::MediaKeys::kUnknownError, 0);
44 media_keys_->GenerateKeyRequest(UTF16ToASCII(mime_type),
45 init_data, init_data_length);
48 void WebContentDecryptionModuleSessionImpl::update(const uint8* key,
51 media_keys_->AddKey(key, key_length, NULL, 0, session_id_);
54 void WebContentDecryptionModuleSessionImpl::close() {
55 media_keys_->CancelKeyRequest(session_id_);
57 // Detach from the CDM.
58 if (!session_closed_cb_.is_null())
59 base::ResetAndReturn(&session_closed_cb_).Run(session_id_);
62 void WebContentDecryptionModuleSessionImpl::KeyAdded() {
66 void WebContentDecryptionModuleSessionImpl::KeyError(
67 media::MediaKeys::KeyError error_code,
69 client_->keyError(static_cast<Client::MediaKeyErrorCode>(error_code),
73 void WebContentDecryptionModuleSessionImpl::KeyMessage(
74 const std::vector<uint8>& message,
75 const std::string& destination_url) {
76 client_->keyMessage(message.empty() ? NULL : &message[0],
78 GURL(destination_url));
81 } // namespace content