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 <memory> 20 21 #include "nweb.h" 22 #include "nweb_adsblock_manager.h" 23 #include "nweb_cookie_manager.h" 24 #include "nweb_data_base.h" 25 #include "nweb_download_manager.h" 26 #include "nweb_web_storage.h" 27 #include "nweb_proxy_changed_callback.h" 28 29 namespace OHOS::NWeb { 30 31 class OHOS_NWEB_EXPORT NWebEngine { 32 public: 33 virtual ~NWebEngine() = default; 34 35 static std::shared_ptr<NWebEngine> GetInstance(); 36 37 virtual std::shared_ptr<NWeb> CreateNWeb(std::shared_ptr<NWebCreateInfo> create_info) = 0; 38 39 virtual std::shared_ptr<NWeb> GetNWeb(int32_t nweb_id) = 0; 40 41 virtual std::shared_ptr<NWebDataBase> GetDataBase() = 0; 42 43 virtual std::shared_ptr<NWebWebStorage> GetWebStorage() = 0; 44 45 virtual std::shared_ptr<NWebCookieManager> GetCookieManager() = 0; 46 47 virtual std::shared_ptr<NWebDownloadManager> GetDownloadManager() = 0; 48 49 virtual void SetWebTag(int32_t nweb_id, const char* web_tag) = 0; 50 51 virtual void InitializeWebEngine(std::shared_ptr<NWebEngineInitArgs> init_args) = 0; 52 53 virtual void PrepareForPageLoad(const std::string& url, bool preconnectable, int32_t num_sockets) = 0; 54 55 virtual void SetWebDebuggingAccess(bool isEnableDebug) = 0; 56 57 virtual void AddIntelligentTrackingPreventionBypassingList(const std::vector<std::string>& hosts) = 0; 58 59 virtual void RemoveIntelligentTrackingPreventionBypassingList(const std::vector<std::string>& hosts) = 0; 60 61 virtual void ClearIntelligentTrackingPreventionBypassingList() = 0; 62 63 virtual void PauseAllTimers() = 0; 64 65 virtual void ResumeAllTimers() = 0; 66 67 virtual void PrefetchResource(const std::shared_ptr<NWebEnginePrefetchArgs>& pre_args, 68 const std::map<std::string, std::string>& additional_http_headers, const std::string& cache_key, 69 const uint32_t& cache_valid_time) = 0; 70 71 virtual void SetRenderProcessMode(RenderProcessMode mode) = 0; 72 73 virtual RenderProcessMode GetRenderProcessMode() = 0; 74 75 virtual void ClearPrefetchedResource(const std::vector<std::string>& cache_key_list) = 0; 76 77 virtual void WarmupServiceWorker(const std::string& url) = 0; 78 79 virtual void SetHostIP(const std::string& hostName, const std::string& address, int32_t aliveTime) = 0; 80 81 virtual void ClearHostIP(const std::string& hostName) = 0; 82 EnableWholeWebPageDrawing()83 virtual void EnableWholeWebPageDrawing() {} 84 GetAdsBlockManager()85 virtual std::shared_ptr<NWebAdsBlockManager> GetAdsBlockManager() 86 { 87 return nullptr; 88 } 89 TrimMemoryByPressureLevel(int32_t memoryLevel)90 virtual void TrimMemoryByPressureLevel(int32_t memoryLevel) {} 91 SetArkWebRomApiLevel(int apiLevel)92 virtual void SetArkWebRomApiLevel(int apiLevel) {} 93 GetArkWebCoreApiLevel()94 virtual int GetArkWebCoreApiLevel() 95 { 96 return 0; 97 } 98 GetDefaultUserAgent()99 virtual std::string GetDefaultUserAgent() { 100 return ""; 101 } 102 RemoveAllCache(bool include_disk_files)103 virtual void RemoveAllCache(bool include_disk_files) {} 104 SetProxyOverride(const std::vector<std::string> & proxyUrls,const std::vector<std::string> & proxySchemeFilters,const std::vector<std::string> & bypassRules,const bool & reverseBypass,std::shared_ptr<NWebProxyChangedCallback> callback)105 virtual void SetProxyOverride(const std::vector<std::string>& proxyUrls, 106 const std::vector<std::string>& proxySchemeFilters, 107 const std::vector<std::string>& bypassRules, 108 const bool& reverseBypass, 109 std::shared_ptr<NWebProxyChangedCallback> callback) {} 110 RemoveProxyOverride(std::shared_ptr<NWebProxyChangedCallback> callback)111 virtual void RemoveProxyOverride(std::shared_ptr<NWebProxyChangedCallback> callback) {} 112 SetAppCustomUserAgent(const std::string & userAgent)113 virtual void SetAppCustomUserAgent(const std::string& userAgent) {} 114 SetUserAgentForHosts(const std::string & userAgent,const std::vector<std::string> & hosts)115 virtual void SetUserAgentForHosts(const std::string& userAgent, const std::vector<std::string>& hosts) {} 116 SetWebDebuggingAccessAndPort(bool isEnableDebug,int32_t port)117 virtual void SetWebDebuggingAccessAndPort(bool isEnableDebug, int32_t port) {} 118 AddBlanklessLoadingUrls(const std::vector<std::string> & urls)119 virtual uint32_t AddBlanklessLoadingUrls(const std::vector<std::string>& urls) { return 0; } 120 RemoveBlanklessLoadingUrls(const std::vector<std::string> & urls)121 virtual void RemoveBlanklessLoadingUrls(const std::vector<std::string>& urls) {} 122 ClearBlanklessLoadingCache(const std::vector<std::string> & urls)123 virtual void ClearBlanklessLoadingCache(const std::vector<std::string>& urls) {} 124 CheckBlankOptEnable(const std::string & url,int32_t nweb_id)125 virtual std::string CheckBlankOptEnable(const std::string& url, int32_t nweb_id) { return ""; } 126 SetBlanklessLoadingCacheCapacity(int32_t capacity)127 virtual void SetBlanklessLoadingCacheCapacity(int32_t capacity) {} 128 EnablePrivateNetworkAccess(bool enable)129 virtual void EnablePrivateNetworkAccess(bool enable) {} 130 IsPrivateNetworkAccessEnabled()131 virtual bool IsPrivateNetworkAccessEnabled() { 132 return false; 133 } 134 SetWebDestroyMode(WebDestroyMode mode)135 virtual void SetWebDestroyMode(WebDestroyMode mode) {} 136 }; 137 138 } // namespace OHOS::NWeb 139 140 #endif // NWEB_ENGINE_H 141