• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "ohos_adapter/bridge/ark_drm_adapter_wrapper.h"
16 
17 #include "ohos_adapter/bridge/ark_drm_callback_adapter_impl.h"
18 
19 #include "base/bridge/ark_web_bridge_macros.h"
20 
21 namespace OHOS::ArkWeb {
22 
ArkDrmAdapterWrapper(ArkWebRefPtr<ArkDrmAdapter> ref)23 ArkDrmAdapterWrapper::ArkDrmAdapterWrapper(ArkWebRefPtr<ArkDrmAdapter> ref) : ctocpp_(ref) {}
24 
IsSupported(const std::string & name)25 bool ArkDrmAdapterWrapper::IsSupported(const std::string& name)
26 {
27     ArkWebString ark_name = ArkWebStringClassToStruct(name);
28     bool ret = ctocpp_->IsSupported(ark_name);
29     ArkWebStringStructRelease(ark_name);
30 
31     return ret;
32 }
33 
IsSupported2(const std::string & name,const std::string & mimeType)34 bool ArkDrmAdapterWrapper::IsSupported2(const std::string& name, const std::string& mimeType)
35 {
36     ArkWebString ark_name = ArkWebStringClassToStruct(name);
37     ArkWebString ark_mimeType = ArkWebStringClassToStruct(mimeType);
38     bool ret = ctocpp_->IsSupported2(ark_name, ark_mimeType);
39     ArkWebStringStructRelease(ark_name);
40     ArkWebStringStructRelease(ark_mimeType);
41 
42     return ret;
43 }
44 
IsSupported3(const std::string & name,const std::string & mimeType,int32_t level)45 bool ArkDrmAdapterWrapper::IsSupported3(const std::string& name, const std::string& mimeType, int32_t level)
46 {
47     ArkWebString ark_name = ArkWebStringClassToStruct(name);
48     ArkWebString ark_mimeType = ArkWebStringClassToStruct(mimeType);
49     bool ret = ctocpp_->IsSupported3(ark_name, ark_mimeType, level);
50     ArkWebStringStructRelease(ark_name);
51     ArkWebStringStructRelease(ark_mimeType);
52 
53     return ret;
54 }
55 
GetUUID(const std::string & name)56 std::vector<uint8_t> ArkDrmAdapterWrapper::GetUUID(const std::string& name)
57 {
58     ArkWebString ark_name = ArkWebStringClassToStruct(name);
59     ArkWebUint8Vector ark_uuid = ctocpp_->GetUUID(ark_name);
60     std::vector<uint8_t> uuid = ArkWebBasicVectorStructToClass<uint8_t, ArkWebUint8Vector>(ark_uuid);
61     ArkWebBasicVectorStructRelease<ArkWebUint8Vector>(ark_uuid);
62     ArkWebStringStructRelease(ark_name);
63     return uuid;
64 }
65 
StorageProvisionedResult(bool result)66 void ArkDrmAdapterWrapper::StorageProvisionedResult(bool result)
67 {
68     ctocpp_->StorageProvisionedResult(result);
69 }
70 
StorageSaveInfoResult(bool result,int32_t type)71 void ArkDrmAdapterWrapper::StorageSaveInfoResult(bool result, int32_t type)
72 {
73     ctocpp_->StorageSaveInfoResult(result, type);
74 }
75 
StorageLoadInfoResult(const std::string & sessionId,const std::vector<uint8_t> & keySetId,const std::string & mimeType,uint32_t keyType)76 void ArkDrmAdapterWrapper::StorageLoadInfoResult(
77     const std::string& sessionId, const std::vector<uint8_t>& keySetId, const std::string& mimeType, uint32_t keyType)
78 {
79     ArkWebString arkSessionId = ArkWebStringClassToStruct(sessionId);
80     ArkWebUint8Vector arkKeySetId = ArkWebBasicVectorClassToStruct<uint8_t, ArkWebUint8Vector>(keySetId);
81     ArkWebString arkMimeType = ArkWebStringClassToStruct(mimeType);
82     ctocpp_->StorageLoadInfoResult(arkSessionId, arkKeySetId, arkMimeType, keyType);
83     ArkWebStringStructRelease(arkSessionId);
84     ArkWebBasicVectorStructRelease(arkKeySetId);
85     ArkWebStringStructRelease(arkMimeType);
86 }
87 
StorageClearInfoResult(bool result,int32_t type)88 void ArkDrmAdapterWrapper::StorageClearInfoResult(bool result, int32_t type)
89 {
90     ctocpp_->StorageClearInfoResult(result, type);
91 }
92 
CreateKeySystem(const std::string & name,const std::string & origin,int32_t securityLevel)93 int32_t ArkDrmAdapterWrapper::CreateKeySystem(const std::string& name, const std::string& origin, int32_t securityLevel)
94 {
95     ArkWebString ark_name = ArkWebStringClassToStruct(name);
96     ArkWebString ark_origin = ArkWebStringClassToStruct(origin);
97     int32_t ret = ctocpp_->CreateKeySystem(ark_name, ark_origin, securityLevel);
98     ArkWebStringStructRelease(ark_name);
99     ArkWebStringStructRelease(ark_origin);
100     return ret;
101 }
102 
ReleaseMediaKeySystem()103 int32_t ArkDrmAdapterWrapper::ReleaseMediaKeySystem()
104 {
105     return ctocpp_->ReleaseMediaKeySystem();
106 }
107 
ReleaseMediaKeySession()108 int32_t ArkDrmAdapterWrapper::ReleaseMediaKeySession()
109 {
110     return ctocpp_->ReleaseMediaKeySession();
111 }
112 
SetConfigurationString(const std::string & configName,const std::string & value)113 int32_t ArkDrmAdapterWrapper::SetConfigurationString(const std::string& configName, const std::string& value)
114 {
115     ArkWebString config = ArkWebStringClassToStruct(configName);
116     ArkWebString val = ArkWebStringClassToStruct(value);
117     int32_t ret = ctocpp_->SetConfigurationString(config, val);
118     ArkWebStringStructRelease(config);
119     ArkWebStringStructRelease(val);
120 
121     return ret;
122 }
123 
GetConfigurationString(const std::string & configName,char * value,int32_t valueLen)124 int32_t ArkDrmAdapterWrapper::GetConfigurationString(const std::string& configName, char* value, int32_t valueLen)
125 {
126     ArkWebString config = ArkWebStringClassToStruct(configName);
127     int32_t ret = ctocpp_->GetConfigurationString(config, value, valueLen);
128     ArkWebStringStructRelease(config);
129 
130     return ret;
131 }
132 
SetConfigurationByteArray(const std::string & configName,const uint8_t * value,int32_t valueLen)133 int32_t ArkDrmAdapterWrapper::SetConfigurationByteArray(
134     const std::string& configName, const uint8_t* value, int32_t valueLen)
135 {
136     ArkWebString config = ArkWebStringClassToStruct(configName);
137     int32_t ret = ctocpp_->SetConfigurationByteArray(config, value, valueLen);
138     ArkWebStringStructRelease(config);
139 
140     return ret;
141 }
142 
GetConfigurationByteArray(const std::string & configName,uint8_t * value,int32_t * valueLen)143 int32_t ArkDrmAdapterWrapper::GetConfigurationByteArray(
144     const std::string& configName, uint8_t* value, int32_t* valueLen)
145 {
146     ArkWebString config = ArkWebStringClassToStruct(configName);
147     int32_t ret = ctocpp_->GetConfigurationByteArray(config, value, valueLen);
148     ArkWebStringStructRelease(config);
149 
150     return ret;
151 }
152 
GetMaxContentProtectionLevel(int32_t & level)153 int32_t ArkDrmAdapterWrapper::GetMaxContentProtectionLevel(int32_t& level)
154 {
155     return ctocpp_->GetMaxContentProtectionLevel(level);
156 }
157 
ProcessKeySystemResponse(const std::string & response,bool isResponseReceived)158 int32_t ArkDrmAdapterWrapper::ProcessKeySystemResponse(const std::string& response, bool isResponseReceived)
159 {
160     ArkWebString ark_response = ArkWebStringClassToStruct(response);
161     int32_t ret = ctocpp_->ProcessKeySystemResponse(ark_response, isResponseReceived);
162     ArkWebStringStructRelease(ark_response);
163     return ret;
164 }
165 
GetCertificateStatus(int32_t & certStatus)166 int32_t ArkDrmAdapterWrapper::GetCertificateStatus(int32_t& certStatus)
167 {
168     return ctocpp_->GetCertificateStatus(certStatus);
169 }
170 
RegistDrmCallback(std::shared_ptr<NWeb::DrmCallbackAdapter> callbackAdapter)171 int32_t ArkDrmAdapterWrapper::RegistDrmCallback(std::shared_ptr<NWeb::DrmCallbackAdapter> callbackAdapter)
172 {
173     if (CHECK_SHARED_PTR_IS_NULL(callbackAdapter)) {
174         return ctocpp_->RegistDrmCallback(nullptr);
175     }
176 
177     return ctocpp_->RegistDrmCallback(new ArkDrmCallbackAdapterImpl(callbackAdapter));
178 }
179 
UpdateSession(uint32_t promiseId,const std::string & sessionId,std::vector<uint8_t> response)180 int32_t ArkDrmAdapterWrapper::UpdateSession(
181     uint32_t promiseId, const std::string& sessionId, std::vector<uint8_t> response)
182 {
183     ArkWebString arkSessionId = ArkWebStringClassToStruct(sessionId);
184     ArkWebUint8Vector arkResponse = ArkWebBasicVectorClassToStruct<uint8_t, ArkWebUint8Vector>(response);
185     int32_t ret = ctocpp_->UpdateSession(promiseId, arkSessionId, arkResponse);
186     ArkWebStringStructRelease(arkSessionId);
187     ArkWebBasicVectorStructRelease(arkResponse);
188     return ret;
189 }
190 
CloseSession(uint32_t promiseId,const std::string & sessionId)191 int32_t ArkDrmAdapterWrapper::CloseSession(uint32_t promiseId, const std::string& sessionId)
192 {
193     ArkWebString arkSessionId = ArkWebStringClassToStruct(sessionId);
194     int32_t ret = ctocpp_->CloseSession(promiseId, arkSessionId);
195     ArkWebStringStructRelease(arkSessionId);
196     return ret;
197 }
198 
RemoveSession(uint32_t promiseId,const std::string & sessionId)199 int32_t ArkDrmAdapterWrapper::RemoveSession(uint32_t promiseId, const std::string& sessionId)
200 {
201     ArkWebString arkSessionId = ArkWebStringClassToStruct(sessionId);
202     int32_t ret = ctocpp_->RemoveSession(promiseId, arkSessionId);
203     ArkWebStringStructRelease(arkSessionId);
204     return ret;
205 }
206 
LoadSession(uint32_t promiseId,const std::string & sessionId)207 int32_t ArkDrmAdapterWrapper::LoadSession(uint32_t promiseId, const std::string& sessionId)
208 {
209     ArkWebString arkSessionId = ArkWebStringClassToStruct(sessionId);
210     int32_t ret = ctocpp_->LoadSession(promiseId, arkSessionId);
211     ArkWebStringStructRelease(arkSessionId);
212     return ret;
213 }
214 
ClearMediaKeys()215 int32_t ArkDrmAdapterWrapper::ClearMediaKeys()
216 {
217     return ctocpp_->ClearMediaKeys();
218 }
219 
GetSecurityLevel()220 int32_t ArkDrmAdapterWrapper::GetSecurityLevel()
221 {
222     return ctocpp_->GetSecurityLevel();
223 }
224 
RequireSecureDecoderModule(const std::string & mimeType,bool & status)225 int32_t ArkDrmAdapterWrapper::RequireSecureDecoderModule(const std::string& mimeType, bool& status)
226 {
227     ArkWebString ark_mimeType = ArkWebStringClassToStruct(mimeType);
228     int32_t ret = ctocpp_->RequireSecureDecoderModule(ark_mimeType, status);
229     ArkWebStringStructRelease(ark_mimeType);
230 
231     return ret;
232 }
233 
GenerateMediaKeyRequest(const std::string & sessionId,int32_t type,int32_t initDataLen,const std::vector<uint8_t> & initData,const std::string & mimeType,uint32_t promiseId)234 int32_t ArkDrmAdapterWrapper::GenerateMediaKeyRequest(const std::string& sessionId, int32_t type, int32_t initDataLen,
235     const std::vector<uint8_t>& initData, const std::string& mimeType, uint32_t promiseId)
236 {
237     ArkWebString ark_mimeType = ArkWebStringClassToStruct(mimeType);
238     ArkWebString ark_sessionId = ArkWebStringClassToStruct(sessionId);
239     ArkWebUint8Vector ark_initData = ArkWebBasicVectorClassToStruct<uint8_t, ArkWebUint8Vector>(initData);
240     int32_t ret =
241         ctocpp_->GenerateMediaKeyRequest(ark_sessionId, type, initDataLen, ark_initData, ark_mimeType, promiseId);
242     ArkWebStringStructRelease(ark_mimeType);
243     ArkWebStringStructRelease(ark_sessionId);
244     ArkWebBasicVectorStructRelease(ark_initData);
245     return ret;
246 }
247 } // namespace OHOS::ArkWeb
248