• 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_EXECUTE_CALLBACK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_EXECUTE_CALLBACK_H
18 
19 #include <string>
20 
21 #include "nweb_value_callback.h"
22 #include "foundation/arkui/ace_engine/frameworks/base/memory/referenced.h"
23 
24 namespace OHOS::Ace {
25 using namespace OHOS::NWeb;
26 
27 class WebDelegate;
28 
29 class WebJavaScriptExecuteCallBack : public OHOS::NWeb::NWebMessageValueCallback {
30 public:
31     WebJavaScriptExecuteCallBack() = default;
WebJavaScriptExecuteCallBack(const WeakPtr<WebDelegate> & delegate)32     explicit WebJavaScriptExecuteCallBack(const WeakPtr<WebDelegate>& delegate) : webDelegate_(delegate) {}
33     virtual ~WebJavaScriptExecuteCallBack() = default;
34 
35     virtual void OnReceiveValue(std::shared_ptr<NWebMessage> result) override;
36     virtual void OnReceiveValueV2(std::shared_ptr<NWebHapValue> value) override;
SetCallBack(const std::function<void (std::string)> && callback)37     void SetCallBack(const std::function<void(std::string)>&& callback)
38     {
39         callback_ = callback;
40     }
41 
42     std::function<void(std::string)> callback_;
43 private:
44     WeakPtr<WebDelegate> webDelegate_;
45 };
46 
47 class WebMessageValueCallBackImpl : public OHOS::NWeb::NWebMessageValueCallback {
48 public:
49     WebMessageValueCallBackImpl() = default;
WebMessageValueCallBackImpl(const WeakPtr<WebDelegate> & delegate)50     explicit WebMessageValueCallBackImpl(const WeakPtr<WebDelegate>& delegate) : webDelegate_(delegate) {}
51     virtual ~WebMessageValueCallBackImpl() = default;
52 
53     virtual void OnReceiveValue(std::shared_ptr<NWebMessage> result) override;
54     virtual void OnReceiveValueV2(std::shared_ptr<NWebHapValue> value) override;
SetCallBack(const std::function<void (std::string)> && callback)55     void SetCallBack(const std::function<void(std::string)>&& callback)
56     {
57         callback_ = callback;
58     }
59 
60     std::function<void(std::string)> callback_;
61 private:
62     WeakPtr<WebDelegate> webDelegate_;
63 };
64 } // namespace OHOS::Ace
65 
66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_EXECUTE_CALLBACK_H
67