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 OHOS_FORM_FWK_FORM_RENDER_IMPL_H 17 #define OHOS_FORM_FWK_FORM_RENDER_IMPL_H 18 19 #include "form_render_stub.h" 20 21 #include <memory> 22 #include <singleton.h> 23 24 #include "bundle_mgr_interface.h" 25 #include "context_impl.h" 26 #include "event_handler.h" 27 #include "form_render_record.h" 28 #include "js_runtime.h" 29 #include "runtime.h" 30 #include "want.h" 31 32 namespace OHOS { 33 namespace AppExecFwk { 34 namespace FormRender { 35 using OHOS::AAFwk::Want; 36 using namespace AbilityRuntime; 37 38 class FormRenderImpl : public FormRenderStub, 39 public std::enable_shared_from_this<FormRenderImpl> { 40 DECLARE_DELAYED_SINGLETON(FormRenderImpl) 41 public: 42 /** 43 * @brief Render form. This is sync API. 44 * @param formJsInfo The form js info. 45 * @param want Indicates the {@link Want} structure containing form info. 46 * @param callerToken Caller ability token. 47 * @return Returns ERR_OK on success, others on failure. 48 */ 49 int32_t RenderForm(const FormJsInfo &formJsInfo, const Want &want, 50 const sptr<IRemoteObject> &callerToken) override; 51 52 /** 53 * @brief Stop rendering form. This is sync API. 54 * @param formJsInfo The form js info. 55 * @param want Indicates the {@link Want} structure containing form info. 56 * @param callerToken Caller ability token. 57 * @return Returns ERR_OK on success, others on failure. 58 */ 59 int32_t StopRenderingForm( 60 const FormJsInfo &formJsInfo, const Want &want, const sptr<IRemoteObject> &callerToken) override; 61 62 /** 63 * @brief When host is died, clean resources. This is async API. 64 * @param hostToken Caller ability token. 65 * @return Returns ERR_OK on success, others on failure. 66 */ 67 int32_t CleanFormHost(const sptr<IRemoteObject> &hostToken) override; 68 69 /** 70 * @brief Reload form When app updated. This is sync API. 71 * @param formIds the form id need to update. 72 * @param want Indicates the {@link Want} structure containing form info. 73 * @return int32_t Returns ERR_OK on success, others on failure. 74 */ 75 int32_t ReloadForm(const std::vector<int64_t> &&formIds, const Want &want) override; 76 77 /** 78 * @brief Called when the system configuration is updated. 79 * @param configuration Indicates the updated configuration information. 80 */ 81 void OnConfigurationUpdated(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& configuration); 82 83 private: 84 std::mutex renderRecordMutex_; 85 std::unordered_map<std::string, std::shared_ptr<FormRenderRecord>> renderRecordMap_; // <uid(userId + bundleName), renderRecord> 86 }; 87 } // namespace FormRender 88 } // namespace AppExecFwk 89 } // namespace OHOS 90 #endif // OHOS_FORM_FWK_FORM_RENDER_IMPL_H 91