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