OLD | NEW |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 manager, | 70 manager, |
70 #endif | 71 #endif |
71 key_system_ascii, | 72 key_system_ascii, |
72 security_origin_as_gurl)) { | 73 security_origin_as_gurl)) { |
73 return NULL; | 74 return NULL; |
74 } | 75 } |
75 | 76 |
76 return new WebContentDecryptionModuleImpl(adapter); | 77 return new WebContentDecryptionModuleImpl(adapter); |
77 } | 78 } |
78 | 79 |
| 80 // static |
| 81 blink::WebContentDecryptionModule::KeySystemSupportedResult |
| 82 WebContentDecryptionModuleImpl::IsKeySystemSupported( |
| 83 const blink::WebString& key_system, |
| 84 const blink::WebString& init_data_type, |
| 85 const blink::WebString& container, |
| 86 const blink::WebString& codecs, |
| 87 const blink::WebString& capability) { |
| 88 // Continuation (from Blink) of MediaKeys.isTypeSupported() algorithm. |
| 89 |
| 90 // 1. If keySystem is an empty string or contains an unrecognized or |
| 91 // unsupported Key System, return the empty string and abort these steps. |
| 92 // String comparison is case-sensitive. |
| 93 // 2. If the keySystem implementation is not available and usable, return the |
| 94 // empty string and abort these steps. |
| 95 // (Emptiness check is in Blink.) |
| 96 // TODO(sandersd): Implement ASCII checks on Blink side. |
| 97 const std::string key_system_ascii = key_system.utf8(); |
| 98 if (!IsSupportedKeySystem(key_system_ascii)) |
| 99 return blink::WebContentDecryptionModule::NotSupported; |
| 100 |
| 101 // 3. Follow the steps for the first matching condition from the following |
| 102 // list: |
| 103 // - If keySystem is a value that may be successfully passed to create() |
| 104 // Let probably result be "probably" |
| 105 // - Otherwise (as may be the case for strings that are only used for |
| 106 // discovery) |
| 107 // Let probably result be "maybe". |
| 108 blink::WebContentDecryptionModule::KeySystemSupportedResult probably_result = |
| 109 IsConcreteSupportedKeySystem(key_system_ascii) ? |
| 110 blink::WebContentDecryptionModule::ProbablySupported : |
| 111 blink::WebContentDecryptionModule::MaybeSupported; |
| 112 |
| 113 // 4. If initDataType was not provided, follow the steps for the first |
| 114 // matching condition from the following list and abort these steps: |
| 115 // - If the user agent is not confident that the keySystem implementation |
| 116 // is available and usable |
| 117 // Return "maybe" |
| 118 // - Otherwise |
| 119 // Return probably result. |
| 120 if (init_data_type.isEmpty()) |
| 121 return probably_result; |
| 122 |
| 123 // 5. If initDataType is an empty string or contains an unrecognized or |
| 124 // unsupported initialization data type, return the empty string and abort |
| 125 // these steps. String comparison is case-sensitive. |
| 126 // 6. If initDataType is not an initialization data type supported by the |
| 127 // keySystem implementation, return the empty string and abort these steps. |
| 128 // 7. If the keySystem implementation supporting initDataType is not available |
| 129 // and usable, return the empty string and abort these steps. |
| 130 // (Emptiness check is in Blink.) |
| 131 const std::string init_data_type_ascii = init_data_type.utf8(); |
| 132 if (!IsSupportedKeySystemWithInitDataType(key_system_ascii, |
| 133 init_data_type_ascii)) |
| 134 return blink::WebContentDecryptionModule::NotSupported; |
| 135 |
| 136 // 8. If contentType was not provided, follow the steps for the first matching |
| 137 // condition from the following list and abort these steps: |
| 138 // - If the user agent is not confident that the keySystem implementation |
| 139 // supporting initDataType is available and usable |
| 140 // Return "maybe" |
| 141 // - Otherwise |
| 142 // Return probably result. |
| 143 if (container.isEmpty()) |
| 144 return probably_result; |
| 145 |
| 146 // 9. If contentType is an empty string or contains an invalid or |
| 147 // unrecognized MIME type, return the empty string and abort these steps. |
| 148 // 10. Let container be the container type specified by contentType. |
| 149 // 11. Let parameters be the RFC 6381 parameters, if any, specified by |
| 150 // contentType. |
| 151 // 12. Let media types be the set of media types specified by parameters. It |
| 152 // may be empty. The case-sensitivity of string comparisons is determined |
| 153 // by the appropriate RFC or other specification. |
| 154 // 13. If the user agent does not support container, return the empty string |
| 155 // and abort these steps. The case-sensitivity of string comparisons is |
| 156 // determined by the appropriate RFC. |
| 157 // 14. If the user agent and keySystem implementation do not support playback |
| 158 // of encrypted media data for all media types, return the empty string |
| 159 // and abort these steps. |
| 160 // (Emptiness check is in Blink.) |
| 161 const std::string container_ascii = container.utf8(); |
| 162 if (!IsSaneInitDataTypeWithContainer(init_data_type_ascii, container_ascii)) |
| 163 return blink::WebContentDecryptionModule::NotSupported; |
| 164 |
| 165 // TODO(sandersd): Check the suffixes rather than stripping them. |
| 166 // http://crbug.com/374751 |
| 167 bool strip_codec_suffixes = !net::IsStrictMediaMimeType(container_ascii); |
| 168 std::vector<std::string> codec_vector; |
| 169 net::ParseCodecString(codecs.utf8(), &codec_vector, strip_codec_suffixes); |
| 170 if (!IsSupportedKeySystemWithMediaMimeType( |
| 171 container_ascii, codec_vector, key_system_ascii)) |
| 172 return blink::WebContentDecryptionModule::NotSupported; |
| 173 |
| 174 // 15-18. (Capabilities.) |
| 175 // TODO(sandersd): Support capabilities. |
| 176 if (!capability.isEmpty()) |
| 177 return blink::WebContentDecryptionModule::NotSupported; |
| 178 |
| 179 // TODO(sandersd): If the codecs are all unambiguous and supported, return |
| 180 // |probably_result|. http://crbug.com/374751 |
| 181 return blink::WebContentDecryptionModule::MaybeSupported; |
| 182 } |
| 183 |
79 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( | 184 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( |
80 scoped_refptr<CdmSessionAdapter> adapter) | 185 scoped_refptr<CdmSessionAdapter> adapter) |
81 : adapter_(adapter) {} | 186 : adapter_(adapter) {} |
82 | 187 |
83 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() { | 188 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() { |
84 } | 189 } |
85 | 190 |
86 // The caller owns the created session. | 191 // The caller owns the created session. |
87 blink::WebContentDecryptionModuleSession* | 192 blink::WebContentDecryptionModuleSession* |
88 WebContentDecryptionModuleImpl::createSession() { | 193 WebContentDecryptionModuleImpl::createSession() { |
(...skipping 12 matching lines...) Expand all Loading... |
101 return adapter_->GetDecryptor(); | 206 return adapter_->GetDecryptor(); |
102 } | 207 } |
103 | 208 |
104 #if defined(ENABLE_BROWSER_CDMS) | 209 #if defined(ENABLE_BROWSER_CDMS) |
105 int WebContentDecryptionModuleImpl::GetCdmId() const { | 210 int WebContentDecryptionModuleImpl::GetCdmId() const { |
106 return adapter_->GetCdmId(); | 211 return adapter_->GetCdmId(); |
107 } | 212 } |
108 #endif // defined(ENABLE_BROWSER_CDMS) | 213 #endif // defined(ENABLE_BROWSER_CDMS) |
109 | 214 |
110 } // namespace content | 215 } // namespace content |
OLD | NEW |