Revert of ui: Clean up damaged rects and clear them after painting. (patchset #2...
[chromium-blink-merge.git] / components / cdm / renderer / android_key_systems.cc
blob28b45eb09be80801f57c7a57ab4abbfc494309d0
1 // Copyright 2014 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 "components/cdm/renderer/android_key_systems.h"
7 #include <string>
8 #include <vector>
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "components/cdm/common/cdm_messages_android.h"
13 #include "components/cdm/renderer/widevine_key_systems.h"
14 #include "content/public/renderer/render_thread.h"
15 #include "media/base/eme_constants.h"
16 #include "media/base/media_switches.h"
18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
20 using media::EmeRobustness;
21 using media::KeySystemInfo;
22 using media::SupportedCodecs;
24 namespace cdm {
26 static SupportedKeySystemResponse QueryKeySystemSupport(
27 const std::string& key_system) {
28 SupportedKeySystemRequest request;
29 SupportedKeySystemResponse response;
31 request.key_system = key_system;
32 request.codecs = media::EME_CODEC_ALL;
33 content::RenderThread::Get()->Send(
34 new ChromeViewHostMsg_QueryKeySystemSupport(request, &response));
35 DCHECK(!(response.compositing_codecs & ~media::EME_CODEC_ALL))
36 << "unrecognized codec";
37 DCHECK(!(response.non_compositing_codecs & ~media::EME_CODEC_ALL))
38 << "unrecognized codec";
39 return response;
42 void AddAndroidWidevine(std::vector<KeySystemInfo>* concrete_key_systems,
43 bool is_non_compositing_supported) {
44 SupportedKeySystemResponse response = QueryKeySystemSupport(
45 kWidevineKeySystem);
47 // When creating the WIDEVINE key system, BrowserCdmFactoryAndroid configures
48 // the CDM's security level based on a pref. Therefore the supported
49 // codec/robustenss combinations depend on that pref, represented by
50 // |bool is_non_compositing_supported|.
51 // TODO(sandersd): For unprefixed, set the security level based on the
52 // requested robustness instead of the flag. http://crbug.com/467779
53 // We should also stop using the term "non_compositing."
54 SupportedCodecs codecs = response.compositing_codecs;
55 EmeRobustness max_audio_robustness = EmeRobustness::SW_SECURE_CRYPTO;
56 EmeRobustness max_video_robustness = EmeRobustness::SW_SECURE_CRYPTO;
57 if (is_non_compositing_supported) {
58 codecs = response.non_compositing_codecs;
59 max_audio_robustness = EmeRobustness::HW_SECURE_CRYPTO;
60 max_video_robustness = EmeRobustness::HW_SECURE_ALL;
63 // We are using MediaDrm API on Android and we cannot guarantee that API
64 // doesn't use persistent storage on the device. Therefore always set
65 // persistent state to EmeFeatureSupport::ALWAYS_ENABLED to err on the
66 // safe side.
68 if (codecs != media::EME_CODEC_NONE) {
69 AddWidevineWithCodecs(
70 WIDEVINE, codecs, max_audio_robustness, max_video_robustness,
71 media::EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license.
72 media::EmeSessionTypeSupport::
73 NOT_SUPPORTED, // persistent-release-message.
74 media::EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state.
75 media::EmeFeatureSupport::ALWAYS_ENABLED, // Distinctive
76 // identifier.
77 concrete_key_systems);
80 // For compatibility with the prefixed API, register a separate L1 key system.
81 // When creating the WIDEVINE_HR_NON_COMPOSITING key system,
82 // BrowserCdmFactoryAndroid does not configure the CDM's security level (that
83 // is, leaves it as L1); therefore only secure codecs are supported.
84 // TODO(ddorwin): Remove with unprefixed. http://crbug.com/249976
85 if (response.non_compositing_codecs != media::EME_CODEC_NONE) {
86 AddWidevineWithCodecs(
87 WIDEVINE_HR_NON_COMPOSITING, response.non_compositing_codecs,
88 EmeRobustness::HW_SECURE_CRYPTO, // Max audio robustness.
89 EmeRobustness::HW_SECURE_ALL, // Max video robustness.
90 media::EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license.
91 media::EmeSessionTypeSupport::
92 NOT_SUPPORTED, // persistent-release-message.
93 media::EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state.
94 media::EmeFeatureSupport::ALWAYS_ENABLED, // Distinctive
95 // identifier.
96 concrete_key_systems);
100 void AddAndroidPlatformKeySystems(
101 std::vector<KeySystemInfo>* concrete_key_systems) {
102 std::vector<std::string> key_system_names;
103 content::RenderThread::Get()->Send(
104 new ChromeViewHostMsg_GetPlatformKeySystemNames(&key_system_names));
106 for (std::vector<std::string>::const_iterator it = key_system_names.begin();
107 it != key_system_names.end(); ++it) {
108 SupportedKeySystemResponse response = QueryKeySystemSupport(*it);
109 if (response.compositing_codecs != media::EME_CODEC_NONE) {
110 KeySystemInfo info;
111 info.key_system = *it;
112 info.supported_codecs = response.compositing_codecs;
113 // Here we assume that support for a container implies support for the
114 // associated initialization data type. KeySystems handles validating
115 // |init_data_type| x |container| pairings.
116 if (response.compositing_codecs & media::EME_CODEC_WEBM_ALL)
117 info.supported_init_data_types |= media::kInitDataTypeMaskWebM;
118 #if defined(USE_PROPRIETARY_CODECS)
119 if (response.compositing_codecs & media::EME_CODEC_MP4_ALL)
120 info.supported_init_data_types |= media::kInitDataTypeMaskCenc;
121 #endif // defined(USE_PROPRIETARY_CODECS)
122 info.max_audio_robustness = EmeRobustness::EMPTY;
123 info.max_video_robustness = EmeRobustness::EMPTY;
124 // Assume the worst case (from a user point of view).
125 info.persistent_license_support =
126 media::EmeSessionTypeSupport::NOT_SUPPORTED;
127 info.persistent_release_message_support =
128 media::EmeSessionTypeSupport::NOT_SUPPORTED;
129 info.persistent_state_support = media::EmeFeatureSupport::ALWAYS_ENABLED;
130 info.distinctive_identifier_support =
131 media::EmeFeatureSupport::ALWAYS_ENABLED;
132 concrete_key_systems->push_back(info);
137 } // namespace cdm