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

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

Issue 557723003: Implement Chromium side of MediaKeys.isTypeSupported(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DEP from components/cdm/renderer to content/public/common. Created 6 years, 3 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/webcontentdecryptionmodule_impl.h" 5 #include "content/renderer/media/webcontentdecryptionmodule_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "content/renderer/media/cdm_session_adapter.h" 15 #include "content/renderer/media/cdm_session_adapter.h"
16 #include "content/renderer/media/crypto/key_systems.h" 16 #include "content/renderer/media/crypto/key_systems.h"
17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" 17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
18 #include "media/base/media_keys.h" 18 #include "media/base/media_keys.h"
19 #include "net/base/mime_util.h"
19 #include "third_party/WebKit/public/platform/WebString.h" 20 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 21 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 #if defined(ENABLE_PEPPER_CDMS) 24 #if defined(ENABLE_PEPPER_CDMS)
24 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" 25 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
25 #endif 26 #endif
26 27
27 namespace content { 28 namespace content {
28 29
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return new WebContentDecryptionModuleImpl(adapter); 77 return new WebContentDecryptionModuleImpl(adapter);
77 } 78 }
78 79
79 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( 80 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
80 scoped_refptr<CdmSessionAdapter> adapter) 81 scoped_refptr<CdmSessionAdapter> adapter)
81 : adapter_(adapter) {} 82 : adapter_(adapter) {}
82 83
83 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() { 84 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() {
84 } 85 }
85 86
87 // static
88 blink::WebContentDecryptionModule::SupportsKeySystem
89 WebContentDecryptionModuleImpl::IsKeySystemSupported(
90 const blink::WebString& key_system,
91 const blink::WebString& init_data_type,
92 const blink::WebString& container,
93 const blink::WebString& codecs,
94 const blink::WebString& capability) {
95 // 15-18.
ddorwin 2014/09/13 01:20:46 It might help to say something like: // Continue t
sandersd (OOO until July 31) 2014/09/22 23:45:54 Done.
96 if (!capability.isEmpty())
ddorwin 2014/09/13 01:20:46 I believe we need the following: // Not currently
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
97 return blink::WebContentDecryptionModule::IsNotSupported;
ddorwin 2014/09/13 01:20:46 Should we move this to the end where it will be ev
sandersd (OOO until July 31) 2014/09/22 23:45:54 The only reason was that an early exit seemed like
98
99 // 1. If keySystem is an empty string or contains an unrecognized or
ddorwin 2014/09/13 01:20:46 Half of step 1 is handled in Blink. The other half
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
100 // unsupported Key System, return the empty string and abort these steps.
101 // String comparison is case-sensitive.
102 // 2. If the keySystem implementation is not available and usable, return the
103 // empty string and abort these steps.
104 const std::string key_system_ascii = key_system.utf8();
ddorwin 2014/09/13 01:20:46 Are we checking and rejecting non-ascii values in
sandersd (OOO until July 31) 2014/09/22 23:45:54 Because the spec didn't say to do that check, this
ddorwin 2014/09/23 22:48:15 FWIW, there is a note in the spec that lower-case
105 if (!IsSupportedKeySystem(key_system_ascii))
106 return blink::WebContentDecryptionModule::IsNotSupported;
107
108 // 3. Follow the steps for the first matching condition from the following
109 // list:
110 // - If keySystem is a value that may be successfully passed to create()
111 // Let probably result be "probably"
112 // - Otherwise (as may be the case for strings that are only used for
113 // discovery)
114 // Let probably result be "maybe".
115 blink::WebContentDecryptionModule::SupportsKeySystem probably_result =
116 blink::WebContentDecryptionModule::MayBeSupported;
117 if (IsConcreteSupportedKeySystem(key_system_ascii))
ddorwin 2014/09/13 01:20:46 nit: Convert to ? :.
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
118 probably_result = blink::WebContentDecryptionModule::IsSupported;
119
120 // 4. If initDataType was not provided, follow the steps for the first
121 // matching condition from the following list and abort these steps:
122 // - If the user agent is not confident that the keySystem implementation
123 // is available and usable
124 // Return "maybe"
125 // - Otherwise
126 // Return probably result.
127 if (init_data_type.isEmpty())
128 return probably_result;
129
130 // 5. If initDataType is an empty string or contains an unrecognized or
131 // unsupported initialization data type, return the empty string and abort
132 // these steps. String comparison is case-sensitive.
133 // 6. If initDataType is not an initialization data type supported by the
134 // keySystem implementation, return the empty string and abort these steps.
135 // 7. If the keySystem implementation supporting initDataType is not available
136 // and usable, return the empty string and abort these steps.
137 const std::string init_data_type_ascii = init_data_type.utf8();
138 if (!IsSupportedKeySystemWithInitDataType(key_system_ascii,
139 init_data_type_ascii))
140 return blink::WebContentDecryptionModule::IsNotSupported;
141
142 // Exclude some specific combinations that don't make much sense.
143 if ((key_system_ascii == "mp4" && init_data_type_ascii == "webm") ||
ddorwin 2014/09/13 01:20:46 This should be comparing the container.
sandersd (OOO until July 31) 2014/09/22 23:45:53 Whoops, thanks!
144 (key_system_ascii == "webm" && init_data_type_ascii == "cenc"))
ddorwin 2014/09/13 01:20:46 Let's move this code to key_systems.cc into a func
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
145 return blink::WebContentDecryptionModule::IsNotSupported;
146
147 // 8. If contentType was not provided, follow the steps for the first matching
148 // condition from the following list and abort these steps:
149 // - If the user agent is not confident that the keySystem implementation
150 // supporting initDataType is available and usable
151 // Return "maybe"
152 // - Otherwise
153 // Return probably result.
154 if (container.isEmpty())
155 return probably_result;
156
157 // 9. If contentType is an empty string or contains an invalid or
ddorwin 2014/09/13 01:20:46 As noted in the Blink CL, these should be there, e
sandersd (OOO until July 31) 2014/09/22 23:45:54 Done.
158 // unrecognized MIME type, return the empty string and abort these steps.
159 // 10. Let container be the container type specified by contentType.
160 // 11. Let parameters be the RFC 6381 parameters, if any, specified by
161 // contentType.
162 // 12. Let media types be the set of media types specified by parameters. It
163 // may be empty. The case-sensitivity of string comparisons is determined
164 // by the appropriate RFC or other specification.
165 // 13. If the user agent does not support container, return the empty string
166 // and abort these steps. The case-sensitivity of string comparisons is
167 // determined by the appropriate RFC.
168 // 14. If the user agent and keySystem implementation do not support playback
169 // of encrypted media data for all media types, return the empty string
170 // and abort these steps.
171 const std::string container_ascii = container.utf8();
172 bool strip_codec_suffixes = !net::IsStrictMediaMimeType(container_ascii);
ddorwin 2014/09/13 01:20:46 TODO: Do a better job validating codecs: crbug.com
sandersd (OOO until July 31) 2014/09/22 23:45:54 Done.
173 std::vector<std::string> codec_vector;
174 net::ParseCodecString(codecs.utf8(), &codec_vector, strip_codec_suffixes);
ddorwin 2014/09/13 01:20:46 note: need to ensure we have checked ASCII before
sandersd (OOO until July 31) 2014/09/22 23:45:54 Acknowledged.
175 if (!IsSupportedKeySystemWithMediaMimeType(
176 container_ascii, codec_vector, key_system_ascii))
177 return blink::WebContentDecryptionModule::IsNotSupported;
178
179 // TODO(sandersd): If the codecs are all unambiguous and supported, return
180 // IsSupported.
ddorwin 2014/09/13 01:20:46 probably_result, right?
sandersd (OOO until July 31) 2014/09/22 23:45:54 That's correct, but because we don't check that th
181 return blink::WebContentDecryptionModule::MayBeSupported;
182 }
183
86 // The caller owns the created session. 184 // The caller owns the created session.
87 blink::WebContentDecryptionModuleSession* 185 blink::WebContentDecryptionModuleSession*
88 WebContentDecryptionModuleImpl::createSession() { 186 WebContentDecryptionModuleImpl::createSession() {
89 return adapter_->CreateSession(); 187 return adapter_->CreateSession();
90 } 188 }
91 189
92 blink::WebContentDecryptionModuleSession* 190 blink::WebContentDecryptionModuleSession*
93 WebContentDecryptionModuleImpl::createSession( 191 WebContentDecryptionModuleImpl::createSession(
94 blink::WebContentDecryptionModuleSession::Client* client) { 192 blink::WebContentDecryptionModuleSession::Client* client) {
95 WebContentDecryptionModuleSessionImpl* session = adapter_->CreateSession(); 193 WebContentDecryptionModuleSessionImpl* session = adapter_->CreateSession();
96 session->setClientInterface(client); 194 session->setClientInterface(client);
97 return session; 195 return session;
98 } 196 }
99 197
100 media::Decryptor* WebContentDecryptionModuleImpl::GetDecryptor() { 198 media::Decryptor* WebContentDecryptionModuleImpl::GetDecryptor() {
101 return adapter_->GetDecryptor(); 199 return adapter_->GetDecryptor();
102 } 200 }
103 201
104 #if defined(ENABLE_BROWSER_CDMS) 202 #if defined(ENABLE_BROWSER_CDMS)
105 int WebContentDecryptionModuleImpl::GetCdmId() const { 203 int WebContentDecryptionModuleImpl::GetCdmId() const {
106 return adapter_->GetCdmId(); 204 return adapter_->GetCdmId();
107 } 205 }
108 #endif // defined(ENABLE_BROWSER_CDMS) 206 #endif // defined(ENABLE_BROWSER_CDMS)
109 207
110 } // namespace content 208 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698