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_ENGINE_H
17#define NWEB_ENGINE_H
18
19#include "nweb.h"
20#include "nweb_adsblock_manager.h"
21#include "nweb_cookie_manager.h"
22#include "nweb_data_base.h"
23#include "nweb_download_manager.h"
24#include "nweb_web_storage.h"
25
26namespace OHOS::NWeb {
27
28class OHOS_NWEB_EXPORT NWebEngine {
29public:
30    virtual ~NWebEngine() = default;
31
32    static std::shared_ptr<NWebEngine> GetInstance();
33
34    virtual std::shared_ptr<NWeb> CreateNWeb(std::shared_ptr<NWebCreateInfo> create_info) = 0;
35
36    virtual std::shared_ptr<NWeb> GetNWeb(int32_t nweb_id) = 0;
37
38    virtual std::shared_ptr<NWebDataBase> GetDataBase() = 0;
39
40    virtual std::shared_ptr<NWebWebStorage> GetWebStorage() = 0;
41
42    virtual std::shared_ptr<NWebCookieManager> GetCookieManager() = 0;
43
44    virtual std::shared_ptr<NWebDownloadManager> GetDownloadManager() = 0;
45
46    virtual void SetWebTag(int32_t nweb_id, const char* web_tag) = 0;
47
48    virtual void InitializeWebEngine(std::shared_ptr<NWebEngineInitArgs> init_args) = 0;
49
50    virtual void PrepareForPageLoad(const std::string& url, bool preconnectable, int32_t num_sockets) = 0;
51
52    virtual void SetWebDebuggingAccess(bool isEnableDebug) = 0;
53
54    virtual void AddIntelligentTrackingPreventionBypassingList(const std::vector<std::string>& hosts) = 0;
55
56    virtual void RemoveIntelligentTrackingPreventionBypassingList(const std::vector<std::string>& hosts) = 0;
57
58    virtual void ClearIntelligentTrackingPreventionBypassingList() = 0;
59
60    virtual void PauseAllTimers() = 0;
61
62    virtual void ResumeAllTimers() = 0;
63
64    virtual void PrefetchResource(const std::shared_ptr<NWebEnginePrefetchArgs>& pre_args,
65        const std::map<std::string, std::string>& additional_http_headers, const std::string& cache_key,
66        const uint32_t& cache_valid_time) = 0;
67
68    virtual void SetRenderProcessMode(RenderProcessMode mode) = 0;
69
70    virtual RenderProcessMode GetRenderProcessMode() = 0;
71
72    virtual void ClearPrefetchedResource(const std::vector<std::string>& cache_key_list) = 0;
73
74    virtual void WarmupServiceWorker(const std::string& url) = 0;
75
76    virtual void SetHostIP(const std::string& hostName, const std::string& address, int32_t aliveTime) = 0;
77
78    virtual void ClearHostIP(const std::string& hostName) = 0;
79
80    virtual void EnableWholeWebPageDrawing() {}
81
82    virtual std::shared_ptr<NWebAdsBlockManager> GetAdsBlockManager()
83    {
84        return nullptr;
85    }
86
87    virtual void TrimMemoryByPressureLevel(int32_t memoryLevel) {}
88
89    virtual void SetArkWebRomApiLevel(int apiLevel) {}
90
91    virtual int GetArkWebCoreApiLevel()
92    {
93        return 0;
94    }
95
96    virtual std::string GetDefaultUserAgent() {
97        return "";
98    }
99};
100
101} // namespace OHOS::NWeb
102
103#endif // NWEB_ENGINE_H
104