IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / renderer / media / webcontentdecryptionmodulesession_impl.cc
blob93cab724256b85675df96502bc0e41af4eb1eb7e
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"
12 namespace content {
14 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
15 uint32 session_id,
16 media::MediaKeys* media_keys,
17 Client* client,
18 const SessionClosedCB& session_closed_cb)
19 : media_keys_(media_keys),
20 client_(client),
21 session_closed_cb_(session_closed_cb),
22 session_id_(session_id) {
23 DCHECK(media_keys_);
26 WebContentDecryptionModuleSessionImpl::
27 ~WebContentDecryptionModuleSessionImpl() {
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 (!IsStringASCII(mime_type)) {
40 NOTREACHED();
41 OnSessionError(media::MediaKeys::kUnknownError, 0);
42 return;
45 media_keys_->CreateSession(
46 session_id_, UTF16ToASCII(mime_type), init_data, init_data_length);
49 void WebContentDecryptionModuleSessionImpl::generateKeyRequest(
50 const blink::WebString& mime_type,
51 const uint8* init_data, size_t init_data_length) {
52 initializeNewSession(mime_type, init_data, init_data_length);
55 void WebContentDecryptionModuleSessionImpl::update(const uint8* response,
56 size_t response_length) {
57 DCHECK(response);
58 media_keys_->UpdateSession(session_id_, response, response_length);
61 void WebContentDecryptionModuleSessionImpl::release() {
62 media_keys_->ReleaseSession(session_id_);
65 void WebContentDecryptionModuleSessionImpl::close() {
66 release();
69 void WebContentDecryptionModuleSessionImpl::OnSessionCreated(
70 const std::string& web_session_id) {
71 // Due to heartbeat messages, OnSessionCreated() can get called multiple
72 // times.
73 // TODO(jrummell): Once all CDMs are updated to support reference ids,
74 // OnSessionCreated() should only be called once, and the second check can be
75 // removed.
76 blink::WebString id = blink::WebString::fromUTF8(web_session_id);
77 DCHECK(web_session_id_.isEmpty() || web_session_id_ == id)
78 << "Session ID may not be changed once set.";
79 web_session_id_ = id;
82 void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
83 const std::vector<uint8>& message,
84 const std::string& destination_url) {
85 client_->keyMessage(message.empty() ? NULL : &message[0],
86 message.size(),
87 GURL(destination_url));
90 void WebContentDecryptionModuleSessionImpl::OnSessionReady() {
91 // TODO(jrummell): Blink APIs need to be updated to the new EME API. For now,
92 // convert the response to the old v0.1b API.
93 client_->keyAdded();
96 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() {
97 if (!session_closed_cb_.is_null())
98 base::ResetAndReturn(&session_closed_cb_).Run(session_id_);
101 void WebContentDecryptionModuleSessionImpl::OnSessionError(
102 media::MediaKeys::KeyError error_code,
103 int system_code) {
104 client_->keyError(static_cast<Client::MediaKeyErrorCode>(error_code),
105 system_code);
108 } // namespace content