1 /*
2  * Copyright (c) 2024 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 
16 #include "ohos_nweb/bridge/ark_web_js_result_callback_impl.h"
17 
18 #include "ohos_nweb/ctocpp/ark_web_value_vector_ctocpp.h"
19 
20 #include "base/bridge/ark_web_bridge_macros.h"
21 
22 namespace OHOS::ArkWeb {
23 
ArkWebJsResultCallbackImpl(std::shared_ptr<OHOS::NWeb::NWebJavaScriptResultCallBack> nweb_js_result_callback)24 ArkWebJsResultCallbackImpl::ArkWebJsResultCallbackImpl(
25     std::shared_ptr<OHOS::NWeb::NWebJavaScriptResultCallBack> nweb_js_result_callback)
26     : nweb_js_result_callback_(nweb_js_result_callback)
27 {}
28 
GetJavaScriptResult(ArkWebValueVector args,const ArkWebString & method,const ArkWebString & object_name,int32_t routing_id,int32_t object_id)29 ArkWebValue ArkWebJsResultCallbackImpl::GetJavaScriptResult(ArkWebValueVector args, const ArkWebString& method,
30     const ArkWebString& object_name, int32_t routing_id, int32_t object_id)
31 {
32     ArkWebValue ark_web_value;
33     ark_web_value.nweb_value = nweb_js_result_callback_->GetJavaScriptResult(ArkWebValueVectorStructToClass(args),
34         ArkWebStringStructToClass(method), ArkWebStringStructToClass(object_name), routing_id, object_id);
35     return ark_web_value;
36 }
37 
GetJavaScriptResultFlowbuf(ArkWebValueVector args,const ArkWebString & method,const ArkWebString & object_name,int fd,int32_t routing_id,int32_t object_id)38 ArkWebValue ArkWebJsResultCallbackImpl::GetJavaScriptResultFlowbuf(ArkWebValueVector args, const ArkWebString& method,
39     const ArkWebString& object_name, int fd, int32_t routing_id, int32_t object_id)
40 {
41     ArkWebValue ark_web_value;
42     ark_web_value.nweb_value =
43         nweb_js_result_callback_->GetJavaScriptResultFlowbuf(ArkWebValueVectorStructToClass(args),
44             ArkWebStringStructToClass(method), ArkWebStringStructToClass(object_name), fd, routing_id, object_id);
45     return ark_web_value;
46 }
47 
HasJavaScriptObjectMethods(int32_t object_id,const ArkWebString & method_name)48 bool ArkWebJsResultCallbackImpl::HasJavaScriptObjectMethods(int32_t object_id, const ArkWebString& method_name)
49 {
50     return nweb_js_result_callback_->HasJavaScriptObjectMethods(object_id, ArkWebStringStructToClass(method_name));
51 }
52 
GetJavaScriptObjectMethods(int32_t object_id)53 ArkWebValue ArkWebJsResultCallbackImpl::GetJavaScriptObjectMethods(int32_t object_id)
54 {
55     ArkWebValue ark_web_value;
56     ark_web_value.nweb_value = nweb_js_result_callback_->GetJavaScriptObjectMethods(object_id);
57     return ark_web_value;
58 }
59 
RemoveJavaScriptObjectHolder(int32_t holder,int32_t object_id)60 void ArkWebJsResultCallbackImpl::RemoveJavaScriptObjectHolder(int32_t holder, int32_t object_id)
61 {
62     nweb_js_result_callback_->RemoveJavaScriptObjectHolder(holder, object_id);
63 }
64 
RemoveTransientJavaScriptObject()65 void ArkWebJsResultCallbackImpl::RemoveTransientJavaScriptObject()
66 {
67     nweb_js_result_callback_->RemoveTransientJavaScriptObject();
68 }
69 
70 } // namespace OHOS::ArkWeb
71