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