• 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_INTERFACE_INNERKITS_FORM_RENDERER_GROUP_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_GROUP_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "form_js_info.h"
24 #include "want.h"
25 
26 namespace OHOS {
27 namespace AbilityRuntime {
28 class Context;
29 class Runtime;
30 }
31 
32 namespace AppExecFwk {
33 class Configuration;
34 }
35 
36 namespace Ace {
37 #ifndef ACE_EXPORT
38 #define ACE_EXPORT __attribute__((visibility("default")))
39 #endif
40 
41 class FormRenderer;
42 
43 struct FormRequest {
44     std::string compId;
45     OHOS::AAFwk::Want want;
46     OHOS::AppExecFwk::FormJsInfo formJsInfo;
47     bool isDynamic = true;
48     bool hasRelease = false;
operatorFormRequest49     bool operator() (const FormRequest& info) const
50     {
51         return compId == info.compId && formJsInfo.formId == info.formJsInfo.formId;
52     }
53 };
54 
55 /**
56  * @class FormRendererGroup
57  * FormRendererGroup interface is used to form renderer group.
58  * Provider:FormRendererGroup:runtime = 1:1:1
59  * FormRendererGroup:FormRenderer = 1:1
60  */
61 class ACE_EXPORT FormRendererGroup {
62 public:
63     static std::shared_ptr<FormRendererGroup> Create(const std::shared_ptr<OHOS::AbilityRuntime::Context> context,
64                                                      const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime);
65 
66     FormRendererGroup(const std::shared_ptr<OHOS::AbilityRuntime::Context> context,
67                       const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime);
68     ~FormRendererGroup();
69 
70     void AddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
71     void OnUnlock();
72     void UpdateForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
73     void DeleteForm();
74     void DeleteForm(const std::string& compId);
75     void ReloadForm(const AppExecFwk::FormJsInfo& formJsInfo);
76     void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
77     bool IsFormRequestsEmpty();
78     const std::vector<FormRequest>& GetAllRendererFormRequests() const;
79 private:
80     void InnerAddForm(const FormRequest& formRequest);
81     std::shared_ptr<OHOS::AbilityRuntime::Context> context_;
82     std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime_;
83     std::shared_ptr<FormRenderer> formRenderer_;
84     std::vector<FormRequest> formRequests_;
85     std::string currentCompId_;
86 };
87 }  // namespace Ace
88 }  // namespace OHOS
89 #endif  // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_GROUP_H
90