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_INTERFACE_INNERKITS_FORM_RENDERER_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H 18 19 #include "ability_context.h" 20 #include "form_js_info.h" 21 #include "form_renderer_delegate_interface.h" 22 #include "form_renderer_dispatcher_impl.h" 23 #include "js_runtime.h" 24 #include "runtime.h" 25 #include "ui_content.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class Configuration; 30 } 31 namespace Ace { 32 /** 33 * @class FormRenderer 34 */ 35 class FormRenderer : public std::enable_shared_from_this<FormRenderer> { 36 public: 37 FormRenderer(const std::shared_ptr<OHOS::AbilityRuntime::Context> context, 38 const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime); 39 ~FormRenderer() = default; 40 41 void AddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 42 void UpdateForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 43 void ReloadForm(const std::string& url); 44 void Destroy(); 45 void ResetRenderDelegate(); 46 void SetAllowUpdate(bool allowUpdate); 47 bool IsAllowUpdate(); 48 49 void OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 50 void OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 51 void OnActionEvent(const std::string& action); 52 void OnError(const std::string& code, const std::string& msg); 53 void OnSurfaceChange(float width, float height); 54 void OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos); 55 void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config); 56 void AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 57 58 private: 59 void InitUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 60 void ParseWant(const OHOS::AAFwk::Want& want); 61 void SetRenderDelegate(const sptr<IRemoteObject>& renderRemoteObj); 62 void AttachUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 63 64 bool allowUpdate_ = true; 65 float width_ = 0.0f; 66 float height_ = 0.0f; 67 std::vector<std::string> cachedInfos_; 68 std::shared_ptr<OHOS::AbilityRuntime::Context> context_; 69 std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime_; 70 sptr<FormRendererDispatcherImpl> formRendererDispatcherImpl_; 71 sptr<IFormRendererDelegate> formRendererDelegate_; 72 std::shared_ptr<UIContent> uiContent_; 73 sptr<IRemoteObject::DeathRecipient> renderDelegateDeathRecipient_; 74 sptr<IRemoteObject> proxy_; 75 }; 76 77 /** 78 * @class FormRenderDelegateRecipient 79 * FormRenderDelegateRecipient notices IRemoteBroker died. 80 */ 81 class FormRenderDelegateRecipient : public IRemoteObject::DeathRecipient { 82 public: 83 using RemoteDiedHandler = std::function<void()>; FormRenderDelegateRecipient(RemoteDiedHandler handler)84 explicit FormRenderDelegateRecipient(RemoteDiedHandler handler) : handler_(std::move(handler)) {} 85 86 ~FormRenderDelegateRecipient() override = default; 87 88 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 89 90 private: 91 RemoteDiedHandler handler_; 92 }; 93 } // namespace Ace 94 } // namespace OHOS 95 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H 96