1 /*
2  * Copyright (c) 2022 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_CREAT_WINDOW_H
17 #define NWEB_CREAT_WINDOW_H
18 
19 #include "nweb.h"
20 #include "nweb_init_params.h"
21 
22 #define private public
23 #include "ui/rs_surface_node.h"
24 #undef private
25 
26 namespace OHOS::NWeb {
27 std::shared_ptr<NWebEngineInitArgsImpl> GetInitArgs(void);
28 std::shared_ptr<NWeb> GetNwebForTest();
29 
30 class NWebMock : public NWeb {
31 public:
32     void Resize(uint32_t width, uint32_t height, bool isKeyboard = false) override {}
OnPause()33     void OnPause() override {}
OnContinue()34     void OnContinue() override {}
OnDestroy()35     void OnDestroy() override {}
36     void OnFocus(const FocusReason& focusReason = FocusReason::FOCUS_DEFAULT) override {}
OnBlur(const BlurReason & blurReason)37     void OnBlur(const BlurReason& blurReason) override {}
38     void OnTouchPress(int32_t id, double x, double y, bool fromOverlay = false) override {}
39     void OnTouchRelease(int32_t id, double x = 0, double y = 0, bool fromOverlay = false) override {}
40     void OnTouchMove(int32_t id, double x, double y, bool fromOverlay = false) override {}
41     void OnTouchMove(
42         const std::vector<std::shared_ptr<NWebTouchPointInfo>>& touch_point_infos, bool fromOverlay = false) override
43     {}
OnTouchCancel()44     void OnTouchCancel() override {}
OnNavigateBack()45     void OnNavigateBack() override {}
SendKeyEvent(int32_t keyCode,int32_t keyAction)46     bool SendKeyEvent(int32_t keyCode, int32_t keyAction) override
47     {
48         return true;
49     }
SendMouseWheelEvent(double x,double y,double deltaX,double deltaY)50     void SendMouseWheelEvent(double x, double y, double deltaX, double deltaY) override {}
SendMouseEvent(int x,int y,int button,int action,int count)51     void SendMouseEvent(int x, int y, int button, int action, int count) override {}
Load(const std::string & url)52     int Load(const std::string& url) override
53     {
54         return 0;
55     }
IsNavigatebackwardAllowed()56     bool IsNavigatebackwardAllowed() override
57     {
58         return true;
59     }
IsNavigateForwardAllowed()60     bool IsNavigateForwardAllowed() override
61     {
62         return true;
63     }
CanNavigateBackOrForward(int numSteps)64     bool CanNavigateBackOrForward(int numSteps) override
65     {
66         return true;
67     }
NavigateBack()68     void NavigateBack() override {}
NavigateForward()69     void NavigateForward() override {}
NavigateBackOrForward(int step)70     void NavigateBackOrForward(int step) override {}
DeleteNavigateHistory()71     void DeleteNavigateHistory() override {}
Reload()72     void Reload() override {}
Zoom(float zoomFactor)73     int Zoom(float zoomFactor) override
74     {
75         return 0;
76     }
ZoomIn()77     int ZoomIn() override
78     {
79         return 0;
80     }
ZoomOut()81     int ZoomOut() override
82     {
83         return 0;
84     }
Stop()85     void Stop() override {}
ExecuteJavaScript(const std::string & code)86     void ExecuteJavaScript(const std::string& code) override {}
ExecuteJavaScript(const std::string & code,std::shared_ptr<NWebMessageValueCallback> callback,bool extention)87     void ExecuteJavaScript(
88         const std::string& code, std::shared_ptr<NWebMessageValueCallback> callback, bool extention) override
89     {}
GetPreference()90     std::shared_ptr<NWebPreference> GetPreference() override
91     {
92         return nullptr;
93     }
GetWebId()94     unsigned int GetWebId() override
95     {
96         return 0;
97     }
GetHitTestResult()98     std::shared_ptr<HitTestResult> GetHitTestResult() override
99     {
100         std::shared_ptr<HitTestResult> test;
101         return test;
102     }
PutBackgroundColor(int color)103     void PutBackgroundColor(int color) override {}
InitialScale(float scale)104     void InitialScale(float scale) override {}
PutDownloadCallback(std::shared_ptr<NWebDownloadCallback> downloadListener)105     void PutDownloadCallback(std::shared_ptr<NWebDownloadCallback> downloadListener) override {}
PutReleaseSurfaceCallback(std::shared_ptr<NWebReleaseSurfaceCallback> releaseSurfaceListener)106     void PutReleaseSurfaceCallback(std::shared_ptr<NWebReleaseSurfaceCallback> releaseSurfaceListener) override {}
SetNWebHandler(std::shared_ptr<NWebHandler> handler)107     void SetNWebHandler(std::shared_ptr<NWebHandler> handler) override {}
Title()108     std::string Title() override
109     {
110         return nullptr;
111     }
PageLoadProgress()112     int PageLoadProgress() override
113     {
114         return 0;
115     }
ContentHeight()116     int ContentHeight() override
117     {
118         return 0;
119     }
Scale()120     float Scale() override
121     {
122         return 0;
123     }
Load(const std::string & url,const std::map<std::string,std::string> & additionalHttpHeaders)124     int Load(const std::string& url, const std::map<std::string, std::string>& additionalHttpHeaders) override
125     {
126         return 0;
127     }
LoadWithDataAndBaseUrl(const std::string & baseUrl,const std::string & data,const std::string & mimeType,const std::string & encoding,const std::string & historyUrl)128     int LoadWithDataAndBaseUrl(const std::string& baseUrl, const std::string& data, const std::string& mimeType,
129         const std::string& encoding, const std::string& historyUrl) override
130     {
131         return 0;
132     }
LoadWithData(const std::string & data,const std::string & mimeType,const std::string & encoding)133     int LoadWithData(const std::string& data, const std::string& mimeType, const std::string& encoding) override
134     {
135         return 0;
136     }
RegisterArkJSfunction(const std::string & object_name,const std::vector<std::string> & method_list,const int32_t object_id)137     void RegisterArkJSfunction(
138         const std::string& object_name, const std::vector<std::string>& method_list, const int32_t object_id) override
139     {}
UnregisterArkJSfunction(const std::string & object_name,const std::vector<std::string> & method_list)140     void UnregisterArkJSfunction(const std::string& object_name, const std::vector<std::string>& method_list) override
141     {}
SetNWebJavaScriptResultCallBack(std::shared_ptr<NWebJavaScriptResultCallBack> callback)142     void SetNWebJavaScriptResultCallBack(std::shared_ptr<NWebJavaScriptResultCallBack> callback) override {}
PutFindCallback(std::shared_ptr<NWebFindCallback> findListener)143     void PutFindCallback(std::shared_ptr<NWebFindCallback> findListener) override {}
FindAllAsync(const std::string & searchStr)144     void FindAllAsync(const std::string& searchStr) override {}
ClearMatches()145     void ClearMatches() override {}
FindNext(const bool forward)146     void FindNext(const bool forward) override {}
StoreWebArchive(const std::string & baseName,bool autoName,std::shared_ptr<NWebStringValueCallback> callback)147     void StoreWebArchive(
148         const std::string& baseName, bool autoName, std::shared_ptr<NWebStringValueCallback> callback) override
149     {}
CreateWebMessagePorts()150     std::vector<std::string> CreateWebMessagePorts() override
151     {
152         std::vector<std::string> empty;
153         return empty;
154     }
PostWebMessage(const std::string & message,const std::vector<std::string> & ports,const std::string & targetUri)155     void PostWebMessage(
156         const std::string& message, const std::vector<std::string>& ports, const std::string& targetUri) override
157     {}
ClosePort(const std::string & handle)158     void ClosePort(const std::string& handle) override {}
PostPortMessage(const std::string & handle,std::shared_ptr<NWebMessage> data)159     void PostPortMessage(const std::string& handle, std::shared_ptr<NWebMessage> data) override {}
SetPortMessageCallback(const std::string & handle,std::shared_ptr<NWebMessageValueCallback> callback)160     void SetPortMessageCallback(const std::string& handle, std::shared_ptr<NWebMessageValueCallback> callback) override
161     {}
SendDragEvent(std::shared_ptr<NWebDragEvent> dragEvent)162     void SendDragEvent(std::shared_ptr<NWebDragEvent> dragEvent) override {}
ClearSslCache()163     void ClearSslCache() override {}
GetUrl()164     std::string GetUrl() override
165     {
166         return "/data";
167     }
ClearClientAuthenticationCache()168     void ClearClientAuthenticationCache() override {}
UpdateLocale(const std::string & language,const std::string & region)169     void UpdateLocale(const std::string& language, const std::string& region) override {}
170 
GetOriginalUrl()171     const std::string GetOriginalUrl() override
172     {
173         return "";
174     }
GetFavicon(const void ** data,size_t & width,size_t & height,ImageColorType & colorType,ImageAlphaType & alphaType)175     bool GetFavicon(
176         const void** data, size_t& width, size_t& height, ImageColorType& colorType, ImageAlphaType& alphaType) override
177     {
178         return false;
179     }
PutNetworkAvailable(bool available)180     void PutNetworkAvailable(bool available) override {}
181 
HasImages(std::shared_ptr<NWebBoolValueCallback> callback)182     void HasImages(std::shared_ptr<NWebBoolValueCallback> callback) override {}
183 
RemoveCache(bool include_disk_files)184     void RemoveCache(bool include_disk_files) override {}
GetHistoryList()185     std::shared_ptr<NWebHistoryList> GetHistoryList() override
186     {
187         return nullptr;
188     }
SerializeWebState()189     std::vector<uint8_t> SerializeWebState() override
190     {
191         std::vector<uint8_t> empty;
192         return empty;
193     }
RestoreWebState(const std::vector<uint8_t> & state)194     bool RestoreWebState(const std::vector<uint8_t>& state) override
195     {
196         return false;
197     }
PageUp(bool top)198     void PageUp(bool top) override {}
PageDown(bool bottom)199     void PageDown(bool bottom) override {}
ScrollTo(float x,float y)200     void ScrollTo(float x, float y) override {}
ScrollBy(float deltaX,float deltaY)201     void ScrollBy(float deltaX, float deltaY) override {}
SlideScroll(float vx,float vy)202     void SlideScroll(float vx, float vy) override {}
GetCertChainDerData(std::vector<std::string> & certChainData,bool isSingleCert)203     bool GetCertChainDerData(std::vector<std::string>& certChainData, bool isSingleCert) override
204     {
205         return false;
206     }
SetScreenOffSet(double x,double y)207     void SetScreenOffSet(double x, double y) override {}
SetAudioMuted(bool muted)208     void SetAudioMuted(bool muted) override {}
SetShouldFrameSubmissionBeforeDraw(bool should)209     void SetShouldFrameSubmissionBeforeDraw(bool should) override {}
NotifyPopupWindowResult(bool result)210     void NotifyPopupWindowResult(bool result) override {}
SetAudioResumeInterval(int32_t resumeInterval)211     void SetAudioResumeInterval(int32_t resumeInterval) override {}
SetAudioExclusive(bool audioExclusive)212     void SetAudioExclusive(bool audioExclusive) override {}
RegisterScreenLockFunction(int32_t windowId,std::shared_ptr<NWebScreenLockCallback> callback)213     void RegisterScreenLockFunction(int32_t windowId, std::shared_ptr<NWebScreenLockCallback> callback) override {}
UnRegisterScreenLockFunction(int32_t windowId)214     void UnRegisterScreenLockFunction(int32_t windowId) override {}
GetOrCreateDragData()215     std::shared_ptr<NWebDragData> GetOrCreateDragData() override
216     {
217         return nullptr;
218     }
SendTouchpadFlingEvent(double x,double y,double vx,double vy)219     void SendTouchpadFlingEvent(double x, double y, double vx, double vy) override {}
SetUrlTrustList(const std::string & urlTrustList)220     int SetUrlTrustList(const std::string& urlTrustList) override
221     {
222         return 0;
223     }
SetUrlTrustListWithErrMsg(const std::string & urlTrustList,std::string & detailErrMsg)224     int SetUrlTrustListWithErrMsg(const std::string& urlTrustList, std::string& detailErrMsg) override
225     {
226         return 0;
227     }
228 };
229 } // namespace OHOS::NWeb
230 #endif
231