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