Implement getMediaDevices.
[chromium-blink-merge.git] / content / renderer / media / webcontentdecryptionmodulesession_impl.cc
blob343397f32ddf464b482098448378a9b2ccb640bb
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"
14 namespace content {
16 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
17 uint32 session_id,
18 Client* client,
19 const scoped_refptr<CdmSessionAdapter>& adapter)
20 : adapter_(adapter),
21 client_(client),
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)) {
40 NOTREACHED();
41 OnSessionError(media::MediaKeys::kUnknownError, 0);
42 return;
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) {
51 DCHECK(response);
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
62 // times.
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
65 // removed.
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.";
69 web_session_id_ = id;
72 void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
73 const std::vector<uint8>& message,
74 const GURL& destination_url) {
75 client_->message(
76 message.empty() ? NULL : &message[0], message.size(), destination_url);
79 void WebContentDecryptionModuleSessionImpl::OnSessionReady() {
80 client_->ready();
83 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() {
84 client_->close();
87 void WebContentDecryptionModuleSessionImpl::OnSessionError(
88 media::MediaKeys::KeyError error_code,
89 uint32 system_code) {
90 client_->error(static_cast<Client::MediaKeyErrorCode>(error_code),
91 system_code);
94 } // namespace content