1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "android_webview/browser/aw_media_client_android.h"
9 #include "base/logging.h"
10 #include "base/stl_util.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h"
15 namespace android_webview
{
19 const size_t kGUIDLength
= 36U;
23 LOG(ERROR) << "Can't parse key-system mapping: " \
24 << key_system_uuid_mapping; \
25 return std::make_pair("", uuid); \
28 media::MediaClientAndroid::KeySystemUuidMap::value_type
CreateMappingFromString(
29 const std::string
& key_system_uuid_mapping
) {
30 std::vector
<uint8_t> uuid
;
32 std::vector
<std::string
> tokens
=
33 base::SplitString(key_system_uuid_mapping
, ",", base::KEEP_WHITESPACE
,
34 base::SPLIT_WANT_NONEMPTY
);
35 RCHECK(tokens
.size() == 2);
37 std::string key_system
;
38 base::TrimWhitespaceASCII(tokens
[0], base::TRIM_ALL
, &key_system
);
40 std::string
guid(tokens
[1]);
41 RCHECK(guid
.length() == kGUIDLength
);
42 base::RemoveChars(guid
, "-", &guid
);
43 RCHECK(base::HexStringToBytes(guid
, &uuid
));
45 return std::make_pair(key_system
, uuid
);
50 AwMediaClientAndroid::AwMediaClientAndroid(
51 const std::vector
<std::string
>& key_system_uuid_mappings
)
52 : key_system_uuid_mappings_(key_system_uuid_mappings
) {
55 AwMediaClientAndroid::~AwMediaClientAndroid() {
58 void AwMediaClientAndroid::AddKeySystemUUIDMappings(KeySystemUuidMap
* map
) {
59 for (const std::string
& key_system_uuid_mapping
: key_system_uuid_mappings_
) {
60 auto mapping
= CreateMappingFromString(key_system_uuid_mapping
);
61 if (!mapping
.first
.empty())
66 media::MediaDrmBridgeDelegate
* AwMediaClientAndroid::GetMediaDrmBridgeDelegate(
67 const media::UUID
& scheme_uuid
) {
68 if (scheme_uuid
== widevine_delegate_
.GetUUID())
69 return &widevine_delegate_
;
73 } // namespace android_webview