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

Side by Side Diff: media/blink/webcontentdecryptionmodulesession_impl.cc

Issue 955993004: Use blink::initDataType and blink::sessionType as enums (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: default Created 5 years, 9 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 "webcontentdecryptionmodulesession_impl.h" 5 #include "webcontentdecryptionmodulesession_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 13 matching lines...) Expand all
24 #include "third_party/WebKit/public/platform/WebVector.h" 24 #include "third_party/WebKit/public/platform/WebVector.h"
25 25
26 namespace media { 26 namespace media {
27 27
28 const char kCloseSessionUMAName[] = "CloseSession"; 28 const char kCloseSessionUMAName[] = "CloseSession";
29 const char kGenerateRequestUMAName[] = "GenerateRequest"; 29 const char kGenerateRequestUMAName[] = "GenerateRequest";
30 const char kLoadSessionUMAName[] = "LoadSession"; 30 const char kLoadSessionUMAName[] = "LoadSession";
31 const char kRemoveSessionUMAName[] = "RemoveSession"; 31 const char kRemoveSessionUMAName[] = "RemoveSession";
32 const char kUpdateSessionUMAName[] = "UpdateSession"; 32 const char kUpdateSessionUMAName[] = "UpdateSession";
33 33
34 // TODO(jrummell): Pass an enum from blink. http://crbug.com/418239.
35 const char kTemporarySessionType[] = "temporary";
36 const char kPersistentLicenseSessionType[] = "persistent-license";
37 const char kPersistentReleaseMessageSessionType[] =
38 "persistent-release-message";
39
40 static blink::WebContentDecryptionModuleSession::Client::MessageType 34 static blink::WebContentDecryptionModuleSession::Client::MessageType
41 convertMessageType(MediaKeys::MessageType message_type) { 35 convertMessageType(MediaKeys::MessageType message_type) {
42 switch (message_type) { 36 switch (message_type) {
43 case media::MediaKeys::LICENSE_REQUEST: 37 case media::MediaKeys::LICENSE_REQUEST:
44 return blink::WebContentDecryptionModuleSession::Client::MessageType:: 38 return blink::WebContentDecryptionModuleSession::Client::MessageType::
45 LicenseRequest; 39 LicenseRequest;
46 case media::MediaKeys::LICENSE_RENEWAL: 40 case media::MediaKeys::LICENSE_RENEWAL:
47 return blink::WebContentDecryptionModuleSession::Client::MessageType:: 41 return blink::WebContentDecryptionModuleSession::Client::MessageType::
48 LicenseRenewal; 42 LicenseRenewal;
49 case media::MediaKeys::LICENSE_RELEASE: 43 case media::MediaKeys::LICENSE_RELEASE:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 81
88 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { 82 void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) {
89 client_ = client; 83 client_ = client;
90 } 84 }
91 85
92 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { 86 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const {
93 return blink::WebString::fromUTF8(session_id_); 87 return blink::WebString::fromUTF8(session_id_);
94 } 88 }
95 89
96 void WebContentDecryptionModuleSessionImpl::initializeNewSession( 90 void WebContentDecryptionModuleSessionImpl::initializeNewSession(
97 const blink::WebString& init_data_type, 91 blink::WebEncryptedMediaInitDataType init_data_type,
98 const uint8* init_data, 92 const unsigned char* init_data,
99 size_t init_data_length, 93 size_t init_data_length,
100 const blink::WebString& session_type, 94 blink::WebEncryptedMediaSessionType session_type,
101 blink::WebContentDecryptionModuleResult result) { 95 blink::WebContentDecryptionModuleResult result) {
102 DCHECK(session_id_.empty()); 96 DCHECK(session_id_.empty());
103 97
104 // TODO(ddorwin): Guard against this in supported types check and remove this. 98 // TODO(jrummell): |init_data_type| should be an enum all the way through
105 // Chromium only supports ASCII MIME types. 99 // Chromium. http://crbug.com/417440
106 if (!base::IsStringASCII(init_data_type)) { 100 std::string init_data_type_as_ascii = "unknown";
107 NOTREACHED(); 101 switch (init_data_type) {
108 std::string message = "The initialization data type " + 102 case blink::WebEncryptedMediaInitDataType::Cenc:
109 init_data_type.utf8() + 103 init_data_type_as_ascii = "cenc";
110 " is not supported by the key system."; 104 break;
111 result.completeWithError( 105 case blink::WebEncryptedMediaInitDataType::Keyids:
112 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, 106 init_data_type_as_ascii = "keyids";
113 blink::WebString::fromUTF8(message)); 107 break;
114 return; 108 case blink::WebEncryptedMediaInitDataType::Webm:
109 init_data_type_as_ascii = "webm";
110 break;
111 case blink::WebEncryptedMediaInitDataType::Unknown:
112 NOTREACHED() << "unexpected init_data_type";
113 break;
115 } 114 }
116 115
117 std::string init_data_type_as_ascii = base::UTF16ToASCII(init_data_type);
118 DLOG_IF(WARNING, init_data_type_as_ascii.find('/') != std::string::npos)
119 << "init_data_type '" << init_data_type_as_ascii
120 << "' may be a MIME type";
121
122 // Step 5 from https://w3c.github.io/encrypted-media/#generateRequest. 116 // Step 5 from https://w3c.github.io/encrypted-media/#generateRequest.
123 // 5. If the Key System implementation represented by this object's cdm 117 // 5. If the Key System implementation represented by this object's cdm
124 // implementation value does not support initDataType as an Initialization 118 // implementation value does not support initDataType as an Initialization
125 // Data Type, return a promise rejected with a new DOMException whose name 119 // Data Type, return a promise rejected with a new DOMException whose name
126 // is NotSupportedError. String comparison is case-sensitive. 120 // is NotSupportedError. String comparison is case-sensitive.
127 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(), 121 if (!IsSupportedKeySystemWithInitDataType(adapter_->GetKeySystem(),
128 init_data_type_as_ascii)) { 122 init_data_type_as_ascii)) {
129 std::string message = "The initialization data type " + 123 std::string message = "The initialization data type " +
130 init_data_type_as_ascii + 124 init_data_type_as_ascii +
131 " is not supported by the key system."; 125 " is not supported by the key system.";
132 result.completeWithError( 126 result.completeWithError(
133 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, 127 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
134 blink::WebString::fromUTF8(message)); 128 blink::WebString::fromUTF8(message));
135 return; 129 return;
136 } 130 }
137 131
138 MediaKeys::SessionType session_type_enum; 132 MediaKeys::SessionType session_type_enum = MediaKeys::TEMPORARY_SESSION;
139 if (session_type == kPersistentLicenseSessionType) { 133 switch (session_type) {
140 session_type_enum = MediaKeys::PERSISTENT_LICENSE_SESSION; 134 case blink::WebEncryptedMediaSessionType::Temporary:
141 } else if (session_type == kPersistentReleaseMessageSessionType) { 135 session_type_enum = MediaKeys::TEMPORARY_SESSION;
142 session_type_enum = MediaKeys::PERSISTENT_RELEASE_MESSAGE_SESSION; 136 break;
143 } else { 137 case blink::WebEncryptedMediaSessionType::PersistentLicense:
144 DCHECK(session_type == kTemporarySessionType); 138 session_type_enum = MediaKeys::PERSISTENT_LICENSE_SESSION;
145 session_type_enum = MediaKeys::TEMPORARY_SESSION; 139 break;
140 case blink::WebEncryptedMediaSessionType::PersistentReleaseMessage:
141 session_type_enum = MediaKeys::PERSISTENT_RELEASE_MESSAGE_SESSION;
142 break;
143 case blink::WebEncryptedMediaSessionType::Unknown:
144 NOTREACHED() << "unexpected session_type";
145 break;
146 } 146 }
147 147
148 adapter_->InitializeNewSession( 148 adapter_->InitializeNewSession(
149 init_data_type_as_ascii, init_data, 149 init_data_type_as_ascii, init_data,
150 base::saturated_cast<int>(init_data_length), session_type_enum, 150 base::saturated_cast<int>(init_data_length), session_type_enum,
151 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( 151 scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise(
152 result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName, 152 result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName,
153 base::Bind( 153 base::Bind(
154 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, 154 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized,
155 base::Unretained(this))))); 155 base::Unretained(this)))));
156 } 156 }
157 157
158 // TODO(jrummell): Remove this. http://crbug.com/418239.
159 void WebContentDecryptionModuleSessionImpl::initializeNewSession(
160 const blink::WebString& init_data_type,
161 const uint8* init_data,
162 size_t init_data_length,
163 const blink::WebString& session_type,
164 blink::WebContentDecryptionModuleResult result) {
165 NOTREACHED();
166 }
167
158 void WebContentDecryptionModuleSessionImpl::load( 168 void WebContentDecryptionModuleSessionImpl::load(
159 const blink::WebString& session_id, 169 const blink::WebString& session_id,
160 blink::WebContentDecryptionModuleResult result) { 170 blink::WebContentDecryptionModuleResult result) {
161 DCHECK(!session_id.isEmpty()); 171 DCHECK(!session_id.isEmpty());
162 DCHECK(session_id_.empty()); 172 DCHECK(session_id_.empty());
163 173
164 // TODO(jrummell): Now that there are 2 types of persistent sessions, the 174 // TODO(jrummell): Now that there are 2 types of persistent sessions, the
165 // session type should be passed from blink. Type should also be passed in the 175 // session type should be passed from blink. Type should also be passed in the
166 // constructor (and removed from initializeNewSession()). 176 // constructor (and removed from initializeNewSession()).
167 adapter_->LoadSession( 177 adapter_->LoadSession(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 return blink::WebContentDecryptionModuleResult::SessionNotFound; 259 return blink::WebContentDecryptionModuleResult::SessionNotFound;
250 260
251 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; 261 DCHECK(session_id_.empty()) << "Session ID may not be changed once set.";
252 session_id_ = session_id; 262 session_id_ = session_id;
253 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) 263 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr())
254 ? blink::WebContentDecryptionModuleResult::NewSession 264 ? blink::WebContentDecryptionModuleResult::NewSession
255 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; 265 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists;
256 } 266 }
257 267
258 } // namespace media 268 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webcontentdecryptionmodulesession_impl.h ('k') | media/blink/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698