• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_RESULT_CALLBACK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_RESULT_CALLBACK_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "nweb_javascript_result_callback.h"
23 #include "nweb_value.h"
24 #include "core/components/web/resource/web_javascript_value.h"
25 
26 namespace OHOS::Ace {
27 using namespace OHOS::NWeb;
28 class WebJavaScriptResultCallBack : public NWebJavaScriptResultCallBack {
29 public:
WebJavaScriptResultCallBack(int32_t instanceId)30     WebJavaScriptResultCallBack(int32_t instanceId) : instanceId_(instanceId) {}
31 
32     ~WebJavaScriptResultCallBack() = default;
33 
34     std::shared_ptr<NWebValue> GetJavaScriptResult(std::vector<std::shared_ptr<NWebValue>> args,
35         const std::string& method, const std::string& object_name, int32_t routing_id, int32_t object_id) override;
36 
37     bool HasJavaScriptObjectMethods(int32_t object_id, const std::string& method_name) override;
38 
39     std::shared_ptr<NWebValue> GetJavaScriptObjectMethods(int32_t object_id) override;
40 
41     void RemoveJavaScriptObjectHolder(int32_t holder, int32_t object_id) override;
42 
43     void RemoveTransientJavaScriptObject() override;
44 
45     using JavaScriptCallBackImpl = std::function<std::shared_ptr<WebJSValue>(
46         const std::string& objectName,
47         const std::string& objectMethod,
48         const std::vector<std::shared_ptr<WebJSValue>>& args)>;
49 
SetJavaScriptCallBack(const JavaScriptCallBackImpl && javaScriptCallBackImpl)50     void SetJavaScriptCallBack(const JavaScriptCallBackImpl&& javaScriptCallBackImpl)
51     {
52         javaScriptCallBackImpl_ = javaScriptCallBackImpl;
53     }
54 
55 protected:
56     JavaScriptCallBackImpl javaScriptCallBackImpl_;
57 
58 private:
59     int32_t instanceId_ = -1;
60 };
61 } // namespace OHOS::Ace
62 
63 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_RESULT_CALLBACK_H
64