1 /*
2  * Copyright (c) 2024 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 NWEB_CONFIG_HELPER_H
17 #define NWEB_CONFIG_HELPER_H
18 
19 #include "libxml/parser.h"
20 #include "libxml/tree.h"
21 #include "nweb_init_params.h"
22 #include "nweb_helper.h"
23 namespace OHOS::NWeb {
24 
25 class OHOS_NWEB_EXPORT NWebConfigHelper {
26 public:
27     static NWebConfigHelper &Instance();
28     ~NWebConfigHelper() = default;
29 
30     void ParseConfig(std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
31     void ReadConfigIfNeeded();
32     std::string ParsePerfConfig(const std::string &configNodeName, const std::string &argsNodeName);
33     std::vector<FrameRateSetting> GetPerfConfig(const std::string& settingName);
34     bool IsLTPODynamicApp(const std::string& bundleName);
35     int32_t GetLTPOStrategy();
36 
37 private:
38     NWebConfigHelper() = default;
39     std::string GetConfigPath(const std::string &configFileName);
40     void ParseNWebLTPOConfig(xmlNodePtr nodePtr);
41     void ReadConfig(const xmlNodePtr &rootPtr, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
42     xmlNodePtr GetChildrenNode(xmlNodePtr NodePtr, const std::string &childrenNodeName);
43     void ParsePerfConfig(xmlNodePtr NodePtr);
44     void ParseWebConfigXml(const std::string &configFilePath, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
45     void WriteConfigValueToSysPara(const std::string &configName, const std::string &value);
46     void ParseDeleteConfig(const xmlNodePtr &rootPtr, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
47     void ParseNWebLTPOApp(xmlNodePtr nodePtr);
48     void ParseNWebLTPOStrategy(xmlNodePtr nodePtr);
49 
50     std::map<std::string, std::string> perfConfig_;
51     std::map<std::string, std::vector<FrameRateSetting>> ltpoConfig_;
52     std::set<std::string> ltpoAllowedApps_ {};
53     int32_t ltpoStrategy_ {0};
54 };
55 } // namespace OHOS
56 
57 #endif // NWEB_CONFIG_HELPER_H