Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(932)

Side by Side Diff: content/renderer/media/webcontentdecryptionmodulesession_impl.cc

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/callback_helpers.h" 8 #include "base/callback_helpers.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "content/renderer/media/cdm_session_adapter.h" 12 #include "content/renderer/media/cdm_session_adapter.h"
13 #include "media/base/cdm_promise.h"
12 #include "third_party/WebKit/public/platform/WebURL.h" 14 #include "third_party/WebKit/public/platform/WebURL.h"
13 15
14 namespace content { 16 namespace content {
15 17
16 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( 18 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
17 uint32 session_id,
18 Client* client, 19 Client* client,
19 const scoped_refptr<CdmSessionAdapter>& adapter) 20 const scoped_refptr<CdmSessionAdapter>& adapter)
20 : adapter_(adapter), 21 : adapter_(adapter),
21 client_(client), 22 client_(client),
22 session_id_(session_id) { 23 weak_ptr_factory_(this) {
23 } 24 }
24 25
25 WebContentDecryptionModuleSessionImpl:: 26 WebContentDecryptionModuleSessionImpl::
26 ~WebContentDecryptionModuleSessionImpl() { 27 ~WebContentDecryptionModuleSessionImpl() {
27 adapter_->RemoveSession(session_id_); 28 if (!web_session_id_.empty())
29 adapter_->RemoveSession(web_session_id_);
28 } 30 }
29 31
30 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { 32 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const {
31 return web_session_id_; 33 return blink::WebString::fromUTF8(web_session_id_);
32 } 34 }
33 35
34 void WebContentDecryptionModuleSessionImpl::initializeNewSession( 36 void WebContentDecryptionModuleSessionImpl::initializeNewSession(
35 const blink::WebString& mime_type, 37 const blink::WebString& init_data_type,
36 const uint8* init_data, size_t init_data_length) { 38 const uint8* init_data,
39 size_t init_data_length) {
37 // TODO(ddorwin): Guard against this in supported types check and remove this. 40 // TODO(ddorwin): Guard against this in supported types check and remove this.
38 // Chromium only supports ASCII MIME types. 41 // Chromium only supports ASCII MIME types.
39 if (!base::IsStringASCII(mime_type)) { 42 if (!base::IsStringASCII(init_data_type)) {
40 NOTREACHED(); 43 NOTREACHED();
41 OnSessionError(media::MediaKeys::kUnknownError, 0); 44 OnSessionError(media::MediaKeys::EXCEPTION_NOT_SUPPORTED_ERROR,
45 0,
46 "The initialization data type " + init_data_type.utf8() +
47 " is not supported by the key system.");
42 return; 48 return;
43 } 49 }
44 50
45 adapter_->InitializeNewSession( 51 std::string init_data_type_as_ascii = base::UTF16ToASCII(init_data_type);
46 session_id_, base::UTF16ToASCII(mime_type), init_data, init_data_length); 52 DLOG_IF(WARNING, init_data_type_as_ascii.find('/') != std::string::npos)
53 << "init_data_type '" << init_data_type_as_ascii
54 << "' may be a MIME type";
55
56 scoped_ptr<media::NewSessionCdmPromise> promise(
57 new media::NewSessionCdmPromise(
58 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionCreated,
59 weak_ptr_factory_.GetWeakPtr()),
60 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError,
ddorwin 2014/05/15 23:15:32 Once the Blink changes are made, will we construct
jrummell 2014/05/16 00:49:53 I was just going to pass the blink promise to each
61 weak_ptr_factory_.GetWeakPtr())));
62 adapter_->InitializeNewSession(init_data_type_as_ascii,
63 init_data,
64 init_data_length,
65 media::MediaKeys::SESSION_TYPE_TEMPORARY,
66 promise.Pass());
47 } 67 }
48 68
49 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, 69 void WebContentDecryptionModuleSessionImpl::update(const uint8* response,
50 size_t response_length) { 70 size_t response_length) {
51 DCHECK(response); 71 DCHECK(response);
52 adapter_->UpdateSession(session_id_, response, response_length); 72 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise(
73 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionUpdated,
74 weak_ptr_factory_.GetWeakPtr()),
75 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError,
76 weak_ptr_factory_.GetWeakPtr())));
77 adapter_->UpdateSession(
78 web_session_id_, response, response_length, promise.Pass());
53 } 79 }
54 80
55 void WebContentDecryptionModuleSessionImpl::release() { 81 void WebContentDecryptionModuleSessionImpl::release() {
56 adapter_->ReleaseSession(session_id_); 82 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise(
57 } 83 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionReleased,
58 84 weak_ptr_factory_.GetWeakPtr()),
59 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( 85 base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError,
60 const std::string& web_session_id) { 86 weak_ptr_factory_.GetWeakPtr())));
61 // Due to heartbeat messages, OnSessionCreated() can get called multiple 87 adapter_->ReleaseSession(web_session_id_, promise.Pass());
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;
70 } 88 }
71 89
72 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( 90 void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
73 const std::vector<uint8>& message, 91 const std::vector<uint8>& message,
74 const std::string& destination_url) { 92 const std::string& destination_url) {
75 client_->message(message.empty() ? NULL : &message[0], 93 client_->message(message.empty() ? NULL : &message[0],
76 message.size(), 94 message.size(),
77 GURL(destination_url)); 95 GURL(destination_url));
78 } 96 }
79 97
80 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { 98 void WebContentDecryptionModuleSessionImpl::OnSessionReady() {
81 client_->ready(); 99 client_->ready();
82 } 100 }
83 101
84 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { 102 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() {
85 client_->close(); 103 client_->close();
86 } 104 }
87 105
88 void WebContentDecryptionModuleSessionImpl::OnSessionError( 106 void WebContentDecryptionModuleSessionImpl::OnSessionError(
89 media::MediaKeys::KeyError error_code, 107 media::MediaKeys::Exception exception_code,
90 uint32 system_code) { 108 uint32 system_code,
91 client_->error(static_cast<Client::MediaKeyErrorCode>(error_code), 109 const std::string& error_message) {
92 system_code); 110 // Convert |exception_code| back to MediaKeyErrorCode if possible.
111 // TODO(jrummell): Update this conversion when promises flow
112 // back into blink:: (as blink:: will have its own error definition).
113 switch (exception_code) {
114 case media::MediaKeys::EXCEPTION_CLIENT_ERROR:
115 client_->error(Client::MediaKeyErrorCodeClient, system_code);
116 break;
117 default:
118 // This will include all other CDM4 errors and any error generated
119 // by CDM5 or later.
120 client_->error(Client::MediaKeyErrorCodeUnknown, system_code);
121 break;
122 }
123 }
124
125 void WebContentDecryptionModuleSessionImpl::SessionCreated(
126 const std::string& web_session_id) {
127 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set.";
128 web_session_id_ = web_session_id;
129 adapter_->RegisterSession(web_session_id_, weak_ptr_factory_.GetWeakPtr());
130 }
131
132 void WebContentDecryptionModuleSessionImpl::SessionUpdated() {
133 // For now, pass back to blink:: as a ready event.
134 OnSessionReady();
135 }
136
137 void WebContentDecryptionModuleSessionImpl::SessionReleased() {
138 // For now, pass back to blink:: as a closed event.
139 OnSessionClosed();
140 }
141
142 void WebContentDecryptionModuleSessionImpl::SessionError(
143 media::MediaKeys::Exception exception_code,
144 uint32 system_code,
145 const std::string& error_message) {
146 // For now, just report this as an error back to blink::.
147 OnSessionError(exception_code, system_code, error_message);
93 } 148 }
94 149
95 } // namespace content 150 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698