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

Side by Side Diff: trunk/src/content/renderer/media/crypto/key_systems.cc

Issue 23708020: Revert 222074 "Refactor KeySystems code to call a function to po..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 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 | Annotate | Revision Log
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/crypto/key_systems.h" 5 #include "content/renderer/media/crypto/key_systems.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "content/public/common/content_client.h"
13 #include "content/public/renderer/content_renderer_client.h"
14 #include "content/public/renderer/key_system_info.h"
15 #include "content/renderer/media/crypto/key_systems_info.h" 12 #include "content/renderer/media/crypto/key_systems_info.h"
16 #include "net/base/mime_util.h" 13 #include "net/base/mime_util.h"
17 #include "third_party/WebKit/public/platform/WebCString.h" 14 #include "third_party/WebKit/public/platform/WebCString.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
19 16
20 namespace content { 17 namespace content {
21 18
22 // Convert a WebString to ASCII, falling back on an empty string in the case 19 // Convert a WebString to ASCII, falling back on an empty string in the case
23 // of a non-ASCII string. 20 // of a non-ASCII string.
24 static std::string ToASCIIOrEmpty(const WebKit::WebString& string) { 21 static std::string ToASCIIOrEmpty(const WebKit::WebString& string) {
25 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); 22 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string();
26 } 23 }
27 24
28 class KeySystems { 25 class KeySystems {
29 public: 26 public:
30 static KeySystems& GetInstance(); 27 static KeySystems* GetInstance();
28
29 void AddConcreteSupportedKeySystem(
30 const std::string& key_system,
31 bool use_aes_decryptor,
32 #if defined(ENABLE_PEPPER_CDMS)
33 const std::string& pepper_type,
34 #elif defined(OS_ANDROID)
35 const uint8 uuid[16],
36 #endif
37 const std::string& parent_key_system);
38
39 void AddSupportedType(const std::string& key_system,
40 const std::string& mime_type,
41 const std::string& codecs_list);
31 42
32 bool IsConcreteSupportedKeySystem(const std::string& key_system); 43 bool IsConcreteSupportedKeySystem(const std::string& key_system);
33 44
34 bool IsSupportedKeySystemWithMediaMimeType( 45 bool IsSupportedKeySystemWithMediaMimeType(
35 const std::string& mime_type, 46 const std::string& mime_type,
36 const std::vector<std::string>& codecs, 47 const std::vector<std::string>& codecs,
37 const std::string& key_system); 48 const std::string& key_system);
38 49
39 bool UseAesDecryptor(const std::string& concrete_key_system); 50 bool UseAesDecryptor(const std::string& concrete_key_system);
40 51
41 #if defined(ENABLE_PEPPER_CDMS) 52 #if defined(ENABLE_PEPPER_CDMS)
42 std::string GetPepperType(const std::string& concrete_key_system); 53 std::string GetPepperType(const std::string& concrete_key_system);
43 #elif defined(OS_ANDROID) 54 #elif defined(OS_ANDROID)
44 std::vector<uint8> GetUUID(const std::string& concrete_key_system); 55 std::vector<uint8> GetUUID(const std::string& concrete_key_system);
45 #endif 56 #endif
46 57
47 private: 58 private:
48 void AddConcreteSupportedKeySystems(
49 const std::vector<KeySystemInfo>& concrete_key_systems);
50
51 void AddConcreteSupportedKeySystem(
52 const std::string& key_system,
53 bool use_aes_decryptor,
54 #if defined(ENABLE_PEPPER_CDMS)
55 const std::string& pepper_type,
56 #elif defined(OS_ANDROID)
57 const std::vector<uint8>& uuid,
58 #endif
59 const std::vector<KeySystemInfo::ContainerCodecsPair>& supported_types,
60 const std::string& parent_key_system);
61
62
63 friend struct base::DefaultLazyInstanceTraits<KeySystems>; 59 friend struct base::DefaultLazyInstanceTraits<KeySystems>;
64 60
65 typedef base::hash_set<std::string> CodecSet; 61 typedef base::hash_set<std::string> CodecSet;
66 typedef std::map<std::string, CodecSet> MimeTypeMap; 62 typedef std::map<std::string, CodecSet> MimeTypeMap;
67 63
68 struct KeySystemProperties { 64 struct KeySystemProperties {
69 KeySystemProperties() : use_aes_decryptor(false) {} 65 KeySystemProperties() : use_aes_decryptor(false) {}
70 66
71 bool use_aes_decryptor; 67 bool use_aes_decryptor;
72 #if defined(ENABLE_PEPPER_CDMS) 68 #if defined(ENABLE_PEPPER_CDMS)
73 std::string pepper_type; 69 std::string pepper_type;
74 #elif defined(OS_ANDROID) 70 #elif defined(OS_ANDROID)
75 std::vector<uint8> uuid; 71 std::vector<uint8> uuid;
76 #endif 72 #endif
77 MimeTypeMap types; 73 MimeTypeMap types;
78 }; 74 };
79 75
80 typedef std::map<std::string, KeySystemProperties> KeySystemPropertiesMap; 76 typedef std::map<std::string, KeySystemProperties> KeySystemPropertiesMap;
81 77
82 typedef std::map<std::string, std::string> ParentKeySystemMap; 78 typedef std::map<std::string, std::string> ParentKeySystemMap;
83 79
84 KeySystems(); 80 KeySystems() {}
85 ~KeySystems() {}
86
87 void AddSupportedType(const std::string& mime_type,
88 const std::string& codecs_list,
89 KeySystemProperties* properties);
90 81
91 bool IsSupportedKeySystemWithContainerAndCodec( 82 bool IsSupportedKeySystemWithContainerAndCodec(
92 const std::string& mime_type, 83 const std::string& mime_type,
93 const std::string& codec, 84 const std::string& codec,
94 const std::string& key_system); 85 const std::string& key_system);
95 86
96 // Map from key system string to capabilities. 87 // Map from key system string to capabilities.
97 KeySystemPropertiesMap concrete_key_system_map_; 88 KeySystemPropertiesMap concrete_key_system_map_;
98 89
99 // Map from parent key system to the concrete key system that should be used 90 // Map from parent key system to the concrete key system that should be used
100 // to represent its capabilities. 91 // to represent its capabilities.
101 ParentKeySystemMap parent_key_system_map_; 92 ParentKeySystemMap parent_key_system_map_;
102 93
103 DISALLOW_COPY_AND_ASSIGN(KeySystems); 94 DISALLOW_COPY_AND_ASSIGN(KeySystems);
104 }; 95 };
105 96
106 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; 97 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER;
107 98
108 KeySystems& KeySystems::GetInstance() { 99 KeySystems* KeySystems::GetInstance() {
109 return g_key_systems.Get(); 100 KeySystems* key_systems = &g_key_systems.Get();
110 } 101 // TODO(ddorwin): Call out to ContentClient to register key systems.
111 102 static bool is_registered = false;
112 // Because we use a LazyInstance, the key systems info must be populated when 103 if (!is_registered) {
113 // the instance is lazily initiated. 104 is_registered = true; // Prevent reentrancy when Add*() is called.
114 KeySystems::KeySystems() { 105 RegisterKeySystems();
115 std::vector<KeySystemInfo> key_systems_info;
116 GetContentClient()->renderer()->AddKeySystems(&key_systems_info);
117 // TODO(ddorwin): Remove in next CL after moving info to
118 // ChromeContentRendererClient.
119 AddKeySystems(&key_systems_info);
120 AddConcreteSupportedKeySystems(key_systems_info);
121 }
122
123 void KeySystems::AddConcreteSupportedKeySystems(
124 const std::vector<KeySystemInfo>& concrete_key_systems) {
125 for (size_t i = 0; i < concrete_key_systems.size(); ++i) {
126 const KeySystemInfo& key_system_info = concrete_key_systems[i];
127 AddConcreteSupportedKeySystem(key_system_info.key_system,
128 key_system_info.use_aes_decryptor,
129 #if defined(ENABLE_PEPPER_CDMS)
130 key_system_info.pepper_type,
131 #elif defined(OS_ANDROID)
132 key_system_info.uuid,
133 #endif
134 key_system_info.supported_types,
135 key_system_info.parent_key_system);
136 } 106 }
107 return key_systems;
137 } 108 }
138 109
139 void KeySystems::AddConcreteSupportedKeySystem( 110 void KeySystems::AddConcreteSupportedKeySystem(
140 const std::string& concrete_key_system, 111 const std::string& concrete_key_system,
141 bool use_aes_decryptor, 112 bool use_aes_decryptor,
142 #if defined(ENABLE_PEPPER_CDMS) 113 #if defined(ENABLE_PEPPER_CDMS)
143 const std::string& pepper_type, 114 const std::string& pepper_type,
144 #elif defined(OS_ANDROID) 115 #elif defined(OS_ANDROID)
145 const std::vector<uint8>& uuid, 116 const uint8 uuid[16],
146 #endif 117 #endif
147 const std::vector<KeySystemInfo::ContainerCodecsPair>& supported_types,
148 const std::string& parent_key_system) { 118 const std::string& parent_key_system) {
149 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) 119 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system))
150 << "Key system '" << concrete_key_system << "' already registered"; 120 << "Key system '" << concrete_key_system << "' already registered";
151 DCHECK(parent_key_system_map_.find(concrete_key_system) ==
152 parent_key_system_map_.end())
153 << "'" << concrete_key_system << " is already registered as a parent";
154 121
155 KeySystemProperties properties; 122 KeySystemProperties properties;
156 properties.use_aes_decryptor = use_aes_decryptor; 123 properties.use_aes_decryptor = use_aes_decryptor;
157 #if defined(ENABLE_PEPPER_CDMS) 124 #if defined(ENABLE_PEPPER_CDMS)
158 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); 125 DCHECK_EQ(use_aes_decryptor, pepper_type.empty());
159 properties.pepper_type = pepper_type; 126 properties.pepper_type = pepper_type;
160 #elif defined(OS_ANDROID) 127 #elif defined(OS_ANDROID)
161 DCHECK_EQ(use_aes_decryptor, uuid.empty()); 128 // Since |uuid| can't be empty, use |use_aes_decryptor|.
162 DCHECK(use_aes_decryptor || uuid.size() == 16); 129 if (!use_aes_decryptor)
163 properties.uuid = uuid; 130 properties.uuid.assign(uuid, uuid + 16);
164 #endif 131 #endif
165
166 for (size_t i = 0; i < supported_types.size(); ++i) {
167 const KeySystemInfo::ContainerCodecsPair& pair = supported_types[i];
168 const std::string& mime_type = pair.first;
169 const std::string& codecs_list = pair.second;
170 AddSupportedType(mime_type, codecs_list, &properties);
171 }
172
173 concrete_key_system_map_[concrete_key_system] = properties; 132 concrete_key_system_map_[concrete_key_system] = properties;
174 133
175 if (!parent_key_system.empty()) { 134 if (!parent_key_system.empty()) {
176 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system))
177 << "Parent '" << parent_key_system << "' already registered concrete";
178 DCHECK(parent_key_system_map_.find(parent_key_system) == 135 DCHECK(parent_key_system_map_.find(parent_key_system) ==
179 parent_key_system_map_.end()) 136 parent_key_system_map_.end())
180 << "Parent '" << parent_key_system << "' already registered"; 137 << "Parent '" << parent_key_system.c_str() << "' already registered.";
181 parent_key_system_map_[parent_key_system] = concrete_key_system; 138 parent_key_system_map_[parent_key_system] = concrete_key_system;
182 } 139 }
183 } 140 }
184 141
185 void KeySystems::AddSupportedType(const std::string& mime_type, 142 void KeySystems::AddSupportedType(const std::string& concrete_key_system,
186 const std::string& codecs_list, 143 const std::string& mime_type,
187 KeySystemProperties* properties) { 144 const std::string& codecs_list) {
188 std::vector<std::string> mime_type_codecs; 145 std::vector<std::string> mime_type_codecs;
189 net::ParseCodecString(codecs_list, &mime_type_codecs, false); 146 net::ParseCodecString(codecs_list, &mime_type_codecs, false);
190 147
191 CodecSet codecs(mime_type_codecs.begin(), mime_type_codecs.end()); 148 CodecSet codecs(mime_type_codecs.begin(), mime_type_codecs.end());
192 // Support the MIME type string alone, without codec(s) specified. 149 // Support the MIME type string alone, without codec(s) specified.
193 codecs.insert(std::string()); 150 codecs.insert(std::string());
194 151
195 MimeTypeMap& mime_types_map = properties->types; 152 KeySystemPropertiesMap::iterator key_system_iter =
153 concrete_key_system_map_.find(concrete_key_system);
154 DCHECK(key_system_iter != concrete_key_system_map_.end());
155 MimeTypeMap& mime_types_map = key_system_iter->second.types;
196 // mime_types_map must not be repeated for a given key system. 156 // mime_types_map must not be repeated for a given key system.
197 DCHECK(mime_types_map.find(mime_type) == mime_types_map.end()); 157 DCHECK(mime_types_map.find(mime_type) == mime_types_map.end());
198 mime_types_map[mime_type] = codecs; 158 mime_types_map[mime_type] = codecs;
199 } 159 }
200 160
201 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) { 161 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) {
202 return concrete_key_system_map_.find(key_system) != 162 return concrete_key_system_map_.find(key_system) !=
203 concrete_key_system_map_.end(); 163 concrete_key_system_map_.end();
204 } 164 }
205 165
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; 247 DLOG(FATAL) << concrete_key_system << " is not a known concrete system";
288 return std::vector<uint8>(); 248 return std::vector<uint8>();
289 } 249 }
290 250
291 return key_system_iter->second.uuid; 251 return key_system_iter->second.uuid;
292 } 252 }
293 #endif 253 #endif
294 254
295 //------------------------------------------------------------------------------ 255 //------------------------------------------------------------------------------
296 256
257 void AddConcreteSupportedKeySystem(
258 const std::string& key_system,
259 bool use_aes_decryptor,
260 #if defined(ENABLE_PEPPER_CDMS)
261 const std::string& pepper_type,
262 #elif defined(OS_ANDROID)
263 const uint8 uuid[16],
264 #endif
265 const std::string& parent_key_system) {
266 KeySystems::GetInstance()->AddConcreteSupportedKeySystem(key_system,
267 use_aes_decryptor,
268 #if defined(ENABLE_PEPPER_CDMS)
269 pepper_type,
270 #elif defined(OS_ANDROID)
271 uuid,
272 #endif
273 parent_key_system);
274 }
275
276 void AddSupportedType(const std::string& key_system,
277 const std::string& mime_type,
278 const std::string& codecs_list) {
279 KeySystems::GetInstance()->AddSupportedType(key_system,
280 mime_type, codecs_list);
281 }
282
297 bool IsConcreteSupportedKeySystem(const WebKit::WebString& key_system) { 283 bool IsConcreteSupportedKeySystem(const WebKit::WebString& key_system) {
298 return KeySystems::GetInstance().IsConcreteSupportedKeySystem( 284 return KeySystems::GetInstance()->IsConcreteSupportedKeySystem(
299 ToASCIIOrEmpty(key_system)); 285 ToASCIIOrEmpty(key_system));
300 } 286 }
301 287
302 bool IsSupportedKeySystemWithMediaMimeType( 288 bool IsSupportedKeySystemWithMediaMimeType(
303 const std::string& mime_type, 289 const std::string& mime_type,
304 const std::vector<std::string>& codecs, 290 const std::vector<std::string>& codecs,
305 const std::string& key_system) { 291 const std::string& key_system) {
306 return KeySystems::GetInstance().IsSupportedKeySystemWithMediaMimeType( 292 return KeySystems::GetInstance()->IsSupportedKeySystemWithMediaMimeType(
307 mime_type, codecs, key_system); 293 mime_type, codecs, key_system);
308 } 294 }
309 295
310 std::string KeySystemNameForUMA(const WebKit::WebString& key_system) { 296 std::string KeySystemNameForUMA(const WebKit::WebString& key_system) {
311 return KeySystemNameForUMAInternal(key_system); 297 return KeySystemNameForUMAInternal(key_system);
312 } 298 }
313 299
314 bool CanUseAesDecryptor(const std::string& concrete_key_system) { 300 bool CanUseAesDecryptor(const std::string& concrete_key_system) {
315 return KeySystems::GetInstance().UseAesDecryptor(concrete_key_system); 301 return KeySystems::GetInstance()->UseAesDecryptor(concrete_key_system);
316 } 302 }
317 303
318 #if defined(ENABLE_PEPPER_CDMS) 304 #if defined(ENABLE_PEPPER_CDMS)
319 std::string GetPepperType(const std::string& concrete_key_system) { 305 std::string GetPepperType(const std::string& concrete_key_system) {
320 return KeySystems::GetInstance().GetPepperType(concrete_key_system); 306 return KeySystems::GetInstance()->GetPepperType(concrete_key_system);
321 } 307 }
322 #elif defined(OS_ANDROID) 308 #elif defined(OS_ANDROID)
323 std::vector<uint8> GetUUID(const std::string& concrete_key_system) { 309 std::vector<uint8> GetUUID(const std::string& concrete_key_system) {
324 return KeySystems::GetInstance().GetUUID(concrete_key_system); 310 return KeySystems::GetInstance()->GetUUID(concrete_key_system);
325 } 311 }
326 #endif 312 #endif
327 313
328 } // namespace content 314 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/renderer/media/crypto/key_systems.h ('k') | trunk/src/content/renderer/media/crypto/key_systems_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698