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 #ifndef ARK_WEB_JS_RESULT_CALLBACK_IMPL_H_
17 #define ARK_WEB_JS_RESULT_CALLBACK_IMPL_H_
18 #pragma once
19 
20 #include "include/nweb_javascript_result_callback.h"
21 #include "ohos_nweb/include/ark_web_js_result_callback.h"
22 
23 namespace OHOS::ArkWeb {
24 
25 class ArkWebJsResultCallbackImpl : public ArkWebJsResultCallback {
26     IMPLEMENT_REFCOUNTING(ArkWebJsResultCallbackImpl);
27 
28 public:
29     ArkWebJsResultCallbackImpl(std::shared_ptr<OHOS::NWeb::NWebJavaScriptResultCallBack> nweb_js_result_callback);
30     ~ArkWebJsResultCallbackImpl() = default;
31 
32     ArkWebValue GetJavaScriptResult(ArkWebValueVector args, const ArkWebString& method, const ArkWebString& object_name,
33         int32_t routing_id, int32_t object_id) override;
34 
35     ArkWebValue GetJavaScriptResultFlowbuf(ArkWebValueVector args, const ArkWebString& method,
36         const ArkWebString& object_name, int fd, int32_t routing_id, int32_t object_id) override;
37 
38     /**
39      * @brief GetJavaScriptObjectMethods
40      *
41      * @param object_id: means the JavaScript object id
42      * @param object_id: means the method name
43      */
44     bool HasJavaScriptObjectMethods(int32_t object_id, const ArkWebString& method_name) override;
45 
46     /**
47      * @brief GetJavaScriptObjectMethods
48      *
49      * @param object_id: means the JavaScript object id
50      */
51     ArkWebValue GetJavaScriptObjectMethods(int32_t object_id) override;
52 
53     /**
54      * @brief RemoveJavaScriptObjectHolder
55      *
56      * @param holder: means the JavaScript object is holded by
57      * it(routing_id)
58      * @param object_id: means the JavaScript object id
59      */
60     void RemoveJavaScriptObjectHolder(int32_t holder, int32_t object_id) override;
61 
62     /**
63      * @brief Remove Transient JavaScript Object
64      */
65     void RemoveTransientJavaScriptObject() override;
66 
67 private:
68     std::shared_ptr<OHOS::NWeb::NWebJavaScriptResultCallBack> nweb_js_result_callback_;
69 };
70 
71 } // namespace OHOS::ArkWeb
72 
73 #endif // ARK_WEB_JS_RESULT_CALLBACK_IMPL_H_
74