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