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     int safeGetPropAsInt(xmlNode* node, const xmlChar* propName, int defaultValue);
35 
36 private:
37     NWebConfigHelper() = default;
38     std::string GetConfigPath(const std::string &configFileName);
39     void ParseNWebLTPOConfig(xmlNodePtr nodePtr);
40     void ReadConfig(const xmlNodePtr &rootPtr, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
41     xmlNodePtr GetChildrenNode(xmlNodePtr NodePtr, const std::string &childrenNodeName);
42     void ParsePerfConfig(xmlNodePtr NodePtr);
43     void ParseWebConfigXml(const std::string &configFilePath, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
44     void WriteConfigValueToSysPara(const std::string &configName, const std::string &value);
45     void ParseDeleteConfig(const xmlNodePtr &rootPtr, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
46     std::map<std::string, std::string> perfConfig_;
47     std::map<std::string, std::vector<FrameRateSetting>> ltpoConfig_;
48 };
49 } // namespace OHOS
50 
51 #endif // NWEB_CONFIG_HELPER_H
52