• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_BRIDGE_CARD_FRONTEND_FORM_FRONTEND_DELEGATE_DECLARATIVE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CARD_FRONTEND_FORM_FRONTEND_DELEGATE_DECLARATIVE_H
18 
19 #include <mutex>
20 
21 #include "frameworks/base/memory/ace_type.h"
22 #include "frameworks/base/utils/noncopyable.h"
23 #include "frameworks/bridge/common/accessibility/accessibility_node_manager.h"
24 #include "frameworks/bridge/declarative_frontend/ng/page_router_manager.h"
25 #include "frameworks/bridge/declarative_frontend/frontend_delegate_declarative.h"
26 
27 namespace OHOS::Ace::Framework {
28 // This is the primary class by which the CardFrontend delegates
29 
30 using LoadCardCallback = std::function<bool(const std::string&, int64_t cardId)>;
31 using UpdateCardDataCallback = std::function<void(const std::string&)>;
32 
33 class ACE_EXPORT FormFrontendDelegateDeclarative : public FrontendDelegateDeclarative {
34     DECLARE_ACE_TYPE(FormFrontendDelegateDeclarative, FrontendDelegateDeclarative);
35 public:
FormFrontendDelegateDeclarative(const RefPtr<TaskExecutor> & taskExecutor,const LoadJsCallback & loadCallback,const JsMessageDispatcherSetterCallback & transferCallback,const EventCallback & asyncEventCallback,const EventCallback & syncEventCallback,const UpdatePageCallback & updatePageCallback,const ResetStagingPageCallback & resetLoadingPageCallback,const DestroyPageCallback & destroyPageCallback,const DestroyApplicationCallback & destroyApplicationCallback,const UpdateApplicationStateCallback & updateApplicationStateCallback,const TimerCallback & timerCallback,const MediaQueryCallback & mediaQueryCallback,const RequestAnimationCallback & requestAnimationCallback,const JsCallback & jsCallback,const OnWindowDisplayModeChangedCallBack & onWindowDisplayModeChangedCallBack,const OnConfigurationUpdatedCallBack & onConfigurationUpdatedCallBack,const OnSaveAbilityStateCallBack & onSaveAbilityStateCallBack,const OnRestoreAbilityStateCallBack & onRestoreAbilityStateCallBack,const OnNewWantCallBack & onNewWantCallBack,const OnMemoryLevelCallBack & onMemoryLevelCallBack,const OnStartContinuationCallBack & onStartContinuationCallBack,const OnCompleteContinuationCallBack & onCompleteContinuationCallBack,const OnRemoteTerminatedCallBack & onRemoteTerminatedCallBack,const OnSaveDataCallBack & onSaveDataCallBack,const OnRestoreDataCallBack & onRestoreDataCallBack,const ExternalEventCallback & externalEventCallback)36     FormFrontendDelegateDeclarative(const RefPtr<TaskExecutor>& taskExecutor, const LoadJsCallback& loadCallback,
37         const JsMessageDispatcherSetterCallback& transferCallback, const EventCallback& asyncEventCallback,
38         const EventCallback& syncEventCallback, const UpdatePageCallback& updatePageCallback,
39         const ResetStagingPageCallback& resetLoadingPageCallback, const DestroyPageCallback& destroyPageCallback,
40         const DestroyApplicationCallback& destroyApplicationCallback,
41         const UpdateApplicationStateCallback& updateApplicationStateCallback, const TimerCallback& timerCallback,
42         const MediaQueryCallback& mediaQueryCallback, const RequestAnimationCallback& requestAnimationCallback,
43         const JsCallback& jsCallback, const OnWindowDisplayModeChangedCallBack& onWindowDisplayModeChangedCallBack,
44         const OnConfigurationUpdatedCallBack& onConfigurationUpdatedCallBack,
45         const OnSaveAbilityStateCallBack& onSaveAbilityStateCallBack,
46         const OnRestoreAbilityStateCallBack& onRestoreAbilityStateCallBack, const OnNewWantCallBack& onNewWantCallBack,
47         const OnMemoryLevelCallBack& onMemoryLevelCallBack,
48         const OnStartContinuationCallBack& onStartContinuationCallBack,
49         const OnCompleteContinuationCallBack& onCompleteContinuationCallBack,
50         const OnRemoteTerminatedCallBack& onRemoteTerminatedCallBack, const OnSaveDataCallBack& onSaveDataCallBack,
51         const OnRestoreDataCallBack& onRestoreDataCallBack, const ExternalEventCallback& externalEventCallback) :
52             FrontendDelegateDeclarative(taskExecutor, loadCallback, transferCallback, asyncEventCallback,
53                 syncEventCallback, updatePageCallback,
54                 resetLoadingPageCallback, destroyPageCallback,
55                 destroyApplicationCallback,
56                 updateApplicationStateCallback, timerCallback,
57                 mediaQueryCallback, requestAnimationCallback,
58                 jsCallback, onWindowDisplayModeChangedCallBack,
59                 onConfigurationUpdatedCallBack,
60                 onSaveAbilityStateCallBack,
61                 onRestoreAbilityStateCallBack, onNewWantCallBack,
62                 onMemoryLevelCallBack,
63                 onStartContinuationCallBack,
64                 onCompleteContinuationCallBack,
65                 onRemoteTerminatedCallBack, onSaveDataCallBack,
66                 onRestoreDataCallBack, externalEventCallback)
67     {
68         LOGI("FormFrontendDelegateDeclarative constructor");
69     }
70 
71     ~FormFrontendDelegateDeclarative() override;
72 
73     void RunCard(const std::string& url, const std::string& params, const std::string& profile, int64_t cardId);
74 
75     void FireCardEvent(const EventMarker& eventMarker, const std::string& params = "");
76 
77     void FireCardAction(const std::string& action);
78 
SetLoadCardCallBack(const LoadCardCallback & loadCallback)79     void SetLoadCardCallBack(const LoadCardCallback& loadCallback)
80     {
81         auto pageRouterManager = GetPageRouterManager();
82         CHECK_NULL_VOID(pageRouterManager);
83         pageRouterManager->SetLoadCardCallback(loadCallback);
84     }
LoadResourceConfiguration(std::map<std::string,std::string> & mediaResourceFileMap,std::unique_ptr<JsonValue> & currentResourceData)85     void LoadResourceConfiguration(std::map<std::string, std::string>& mediaResourceFileMap,
86                                     std::unique_ptr<JsonValue>& currentResourceData) override
87     {
88         LOGI("FormFrontendDelegateDeclarative LoadResourceConfiguration");
89     }
UpdatePageData(const std::string & dataList)90     void UpdatePageData(const std::string& dataList)
91     {
92         std::lock_guard<std::mutex> lock(mutex_);
93         if (updateCardData_) {
94             updateCardData_(dataList);
95         } else {
96             cardData_ = dataList;
97         }
98     }
99 
SetUpdateCardDataCallback(UpdateCardDataCallback && callback)100     void SetUpdateCardDataCallback(UpdateCardDataCallback&& callback)
101     {
102         std::lock_guard<std::mutex> lock(mutex_);
103         updateCardData_ = std::move(callback);
104     }
105 
UpdatePageDataImmediately()106     void UpdatePageDataImmediately()
107     {
108         std::lock_guard<std::mutex> lock(mutex_);
109         if (!cardData_.empty() && updateCardData_) {
110             updateCardData_(cardData_);
111         }
112     }
113 
114 private:
115     UpdateCardDataCallback updateCardData_;
116     std::string cardData_;
117     mutable std::mutex mutex_;
118 };
119 } // namespace OHOS::Ace::Framework
120 
121 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CARD_FRONTEND_FORM_FRONTEND_DELEGATE_DECLARATIVE_H
122