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_DECLARATIVE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CARD_FRONTEND_FORM_FRONTEND_DECLARATIVE_H 18 19 #include <memory> 20 21 #include "base/memory/ace_type.h" 22 #include "core/common/ace_page.h" 23 #include "core/common/frontend.h" 24 #include "frameworks/bridge/card_frontend/form_frontend_delegate_declarative.h" 25 #include "frameworks/bridge/card_frontend/js_card_parser.h" 26 #include "frameworks/bridge/common/accessibility/accessibility_node_manager.h" 27 #include "frameworks/bridge/common/manifest/manifest_parser.h" 28 #include "frameworks/bridge/common/utils/page_id_pool.h" 29 #include "frameworks/bridge/declarative_frontend/declarative_frontend.h" 30 #include "frameworks/bridge/declarative_frontend/ng/page_router_manager.h" 31 #include "frameworks/bridge/declarative_frontend/ng/declarative_frontend_ng.h" 32 #include "frameworks/bridge/js_frontend/frontend_delegate_impl.h" 33 34 namespace OHOS::Ace { 35 class ACE_EXPORT FormFrontendDeclarative : public DeclarativeFrontend { 36 DECLARE_ACE_TYPE(FormFrontendDeclarative, DeclarativeFrontend); 37 public: 38 FormFrontendDeclarative() = default; 39 40 // Card 41 void UpdateData(const std::string& dataList); 42 void HandleSurfaceChanged(int32_t width, int32_t height); 43 void UpdatePageData(const std::string& dataList); 44 void OnMediaFeatureUpdate(); 45 46 void RunPage(int32_t pageId, const std::string& url, const std::string& params) override; 47 48 void SetErrorEventHandler( 49 std::function<void(const std::string&, const std::string&)>&& errorCallback) override; 50 51 void OnSurfaceChanged(int32_t width, int32_t height) override; 52 void SetColorMode(ColorMode colorMode) override; 53 SetLoadCardCallBack(const WeakPtr<PipelineBase> & outSidePipelineContext)54 void SetLoadCardCallBack(const WeakPtr<PipelineBase>& outSidePipelineContext) 55 { 56 const auto& loadCallback = [outSidePipelineContext](const std::string& url, int64_t cardId) -> bool { 57 auto context = outSidePipelineContext.Upgrade(); 58 if (!context) { 59 LOGE("Load card callback failed, host pipeline nullptr"); 60 return false; 61 } 62 63 auto outSidefrontend = AceType::DynamicCast<DeclarativeFrontend>(context->GetFrontend()); 64 if (!outSidefrontend) { 65 LOGE("Load card callback failed, host frontend nullptr"); 66 return false; 67 } 68 69 // Use the same js engine with host pipeline 70 auto jsEngine = outSidefrontend->GetJsEngine(); 71 if (!jsEngine) { 72 return false; 73 } 74 return jsEngine->LoadCard(url, cardId); 75 }; 76 77 auto delegate = AceType::DynamicCast<Framework::FormFrontendDelegateDeclarative>(delegate_); 78 if (delegate) { 79 delegate->SetLoadCardCallBack(loadCallback); 80 } 81 } 82 GetDelegate()83 RefPtr<Framework::FormFrontendDelegateDeclarative> GetDelegate() 84 { 85 return AceType::DynamicCast<Framework::FormFrontendDelegateDeclarative>(delegate_); 86 } 87 88 std::string GetFormSrcPath(const std::string& uri, const std::string& suffix) const; 89 SetFormSrc(std::string formSrc)90 void SetFormSrc(std::string formSrc) 91 { 92 formSrc_ = formSrc; 93 } 94 GetFormSrc()95 std::string GetFormSrc() const 96 { 97 return formSrc_; 98 } 99 SetRunningCardId(int64_t cardId)100 void SetRunningCardId(int64_t cardId) 101 { 102 cardId_ = cardId; 103 } 104 SetIsFormRender(bool isCardfront)105 void SetIsFormRender(bool isCardfront) 106 { 107 isFormRender_ = isCardfront; 108 } 109 IsFormRender()110 bool IsFormRender() 111 { 112 return isFormRender_; 113 } 114 SetTaskExecutor(RefPtr<TaskExecutor> taskExecutor)115 void SetTaskExecutor(RefPtr<TaskExecutor> taskExecutor) 116 { 117 taskExecutor_ = taskExecutor; 118 } 119 SetModuleName(const std::string & moduleName)120 void SetModuleName(const std::string& moduleName) 121 { 122 moduleName_ = moduleName; 123 } SetBundleName(const std::string & bundleName)124 void SetBundleName(const std::string& bundleName) 125 { 126 bundleName_ = bundleName; 127 } GetModuleName()128 std::string GetModuleName() const 129 { 130 return moduleName_; 131 } GetBundleName()132 std::string GetBundleName() const 133 { 134 return bundleName_; 135 } SetIsBundle(bool isBundle)136 void SetIsBundle(bool isBundle) 137 { 138 isBundle_ = isBundle; 139 } IsBundle()140 bool IsBundle() const 141 { 142 return isBundle_; 143 } 144 145 ColorMode colorMode_ = ColorMode::LIGHT; 146 bool foregroundFrontend_ = false; 147 double density_ = 1.0; 148 std::string cardHapPath_; 149 150 Framework::PipelineContextHolder holder_; 151 RefPtr<AssetManager> assetManager_; 152 153 mutable std::once_flag onceFlag_; 154 RefPtr<TaskExecutor> taskExecutor_; 155 RefPtr<AceEventHandler> eventHandler_; 156 std::string formSrc_; 157 WindowConfig cardWindowConfig_; 158 uint64_t cardId_ = 0; // cardId != formId, cardId is the nodeId of component. 159 160 std::string bundleName_; 161 std::string moduleName_; 162 bool isBundle_ = false; 163 }; 164 } // namespace OHOS::Ace 165 166 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CARD_FRONTEND_FORM_FRONTEND_DECLARATIVE_H 167