1 /* 2 * Copyright (c) 2021-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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_DELEGATE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_DELEGATE_H 18 19 #include <list> 20 #include <map> 21 22 #include "base/memory/referenced.h" 23 #include "core/components_ng/render/render_surface.h" 24 #include "core/pipeline/pipeline_base.h" 25 #if defined (OHOS_STANDARD_SYSTEM) && defined (ENABLE_ROSEN_BACKEND) 26 #include <ui/rs_surface_node.h> 27 #endif 28 29 #include <EGL/egl.h> 30 #include <EGL/eglext.h> 31 #include <GLES3/gl3.h> 32 #include "base/image/pixel_map.h" 33 #include "core/components/common/layout/constants.h" 34 #include "core/components/web/resource/web_client_impl.h" 35 #include "core/components/web/resource/web_resource.h" 36 #include "core/components/web/web_component.h" 37 #include "core/components/web/web_event.h" 38 #include "surface_delegate.h" 39 #ifdef OHOS_STANDARD_SYSTEM 40 #include "nweb_handler.h" 41 #include "nweb_helper.h" 42 #include "nweb_hit_testresult.h" 43 #include "app_mgr_client.h" 44 #ifdef ENABLE_ROSEN_BACKEND 45 #include "surface.h" 46 #endif 47 #include "window.h" 48 #endif 49 50 namespace OHOS::Ace { 51 52 typedef struct WindowsSurfaceInfoTag { 53 void* window; 54 EGLDisplay display; 55 EGLContext context; 56 EGLSurface surface; 57 } WindowsSurfaceInfo; 58 59 class WebMessagePortOhos : public WebMessagePort { DECLARE_ACE_TYPE(WebMessagePortOhos,WebMessagePort)60 DECLARE_ACE_TYPE(WebMessagePortOhos, WebMessagePort) 61 62 public: 63 WebMessagePortOhos(WeakPtr<WebDelegate> webDelegate) : webDelegate_(webDelegate) {} 64 WebMessagePortOhos() = default; 65 ~WebMessagePortOhos() = default; 66 67 void Close() override; 68 void PostMessage(std::string& data) override; 69 void SetWebMessageCallback(std::function<void(const std::string&)>&& callback) override; 70 void SetPortHandle(std::string& handle) override; 71 std::string GetPortHandle() override; 72 73 private: 74 WeakPtr<WebDelegate> webDelegate_; 75 std::string handle_; 76 }; 77 78 class ConsoleLogOhos : public WebConsoleLog { DECLARE_ACE_TYPE(ConsoleLogOhos,WebConsoleLog)79 DECLARE_ACE_TYPE(ConsoleLogOhos, WebConsoleLog) 80 81 public: 82 ConsoleLogOhos(std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message) : message_(message) {} 83 84 int GetLineNumber() override; 85 86 std::string GetLog() override; 87 88 int GetLogLevel() override; 89 90 std::string GetSourceId() override; 91 92 private: 93 std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message_; 94 }; 95 96 class ResultOhos : public Result { DECLARE_ACE_TYPE(ResultOhos,Result)97 DECLARE_ACE_TYPE(ResultOhos, Result) 98 99 public: 100 ResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSDialogResult> result) : result_(result) {} 101 102 void Confirm() override; 103 void Confirm(const std::string& message) override; 104 void Cancel() override; 105 106 private: 107 std::shared_ptr<OHOS::NWeb::NWebJSDialogResult> result_; 108 }; 109 110 class FullScreenExitHandlerOhos : public FullScreenExitHandler { DECLARE_ACE_TYPE(FullScreenExitHandlerOhos,FullScreenExitHandler)111 DECLARE_ACE_TYPE(FullScreenExitHandlerOhos, FullScreenExitHandler) 112 113 public: 114 FullScreenExitHandlerOhos(std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler, 115 WeakPtr<WebDelegate> webDelegate) : handler_(handler), webDelegate_(webDelegate) {} 116 void ExitFullScreen() override; 117 private: 118 std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler_; 119 WeakPtr<WebDelegate> webDelegate_; 120 }; 121 122 class AuthResultOhos : public AuthResult { DECLARE_ACE_TYPE(AuthResultOhos,AuthResult)123 DECLARE_ACE_TYPE(AuthResultOhos, AuthResult) 124 125 public: 126 AuthResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSHttpAuthResult> result) : result_(result) {} 127 128 bool Confirm(std::string& userName, std::string& pwd) override; 129 bool IsHttpAuthInfoSaved() override; 130 void Cancel() override; 131 132 private: 133 std::shared_ptr<OHOS::NWeb::NWebJSHttpAuthResult> result_; 134 }; 135 136 class SslErrorResultOhos : public SslErrorResult { DECLARE_ACE_TYPE(SslErrorResultOhos,SslErrorResult)137 DECLARE_ACE_TYPE(SslErrorResultOhos, SslErrorResult) 138 139 public: 140 SslErrorResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSSslErrorResult> result) : result_(result) {} 141 142 void HandleConfirm() override; 143 void HandleCancel() override; 144 145 private: 146 std::shared_ptr<OHOS::NWeb::NWebJSSslErrorResult> result_; 147 }; 148 149 class SslSelectCertResultOhos : public SslSelectCertResult { DECLARE_ACE_TYPE(SslSelectCertResultOhos,SslSelectCertResult)150 DECLARE_ACE_TYPE(SslSelectCertResultOhos, SslSelectCertResult) 151 152 public: 153 explicit SslSelectCertResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSSslSelectCertResult> result) 154 : result_(result) {} 155 156 void HandleConfirm(const std::string& privateKeyFile, const std::string& certChainFile) override; 157 158 void HandleCancel() override; 159 160 void HandleIgnore() override; 161 private: 162 std::shared_ptr<OHOS::NWeb::NWebJSSslSelectCertResult> result_; 163 }; 164 165 class FileSelectorParamOhos : public WebFileSelectorParam { DECLARE_ACE_TYPE(FileSelectorParamOhos,WebFileSelectorParam)166 DECLARE_ACE_TYPE(FileSelectorParamOhos, WebFileSelectorParam) 167 168 public: 169 FileSelectorParamOhos(std::shared_ptr<OHOS::NWeb::NWebFileSelectorParams> param) : param_(param) {} 170 171 std::string GetTitle() override; 172 int GetMode() override; 173 std::string GetDefaultFileName() override; 174 std::vector<std::string> GetAcceptType() override; 175 bool IsCapture() override; 176 177 private: 178 std::shared_ptr<OHOS::NWeb::NWebFileSelectorParams> param_; 179 }; 180 181 class FileSelectorResultOhos : public FileSelectorResult { DECLARE_ACE_TYPE(FileSelectorResultOhos,FileSelectorResult)182 DECLARE_ACE_TYPE(FileSelectorResultOhos, FileSelectorResult) 183 184 public: 185 FileSelectorResultOhos(std::shared_ptr<OHOS::NWeb::FileSelectorCallback> callback) : callback_(callback) {} 186 187 void HandleFileList(std::vector<std::string>& result) override; 188 189 private: 190 std::shared_ptr<OHOS::NWeb::FileSelectorCallback> callback_; 191 }; 192 193 class ContextMenuParamOhos : public WebContextMenuParam { DECLARE_ACE_TYPE(ContextMenuParamOhos,WebContextMenuParam)194 DECLARE_ACE_TYPE(ContextMenuParamOhos, WebContextMenuParam) 195 196 public: 197 ContextMenuParamOhos(std::shared_ptr<OHOS::NWeb::NWebContextMenuParams> param) : param_(param) {} 198 199 int32_t GetXCoord() const override; 200 int32_t GetYCoord() const override; 201 std::string GetLinkUrl() const override; 202 std::string GetUnfilteredLinkUrl() const override; 203 std::string GetSourceUrl() const override; 204 bool HasImageContents() const override; 205 bool IsEditable() const override; 206 int GetEditStateFlags() const override; 207 int GetSourceType() const override; 208 int GetMediaType() const override; 209 int GetInputFieldType() const override; 210 std::string GetSelectionText() const override; 211 212 private: 213 std::shared_ptr<OHOS::NWeb::NWebContextMenuParams> param_; 214 }; 215 216 class ContextMenuResultOhos : public ContextMenuResult { DECLARE_ACE_TYPE(ContextMenuResultOhos,ContextMenuResult)217 DECLARE_ACE_TYPE(ContextMenuResultOhos, ContextMenuResult) 218 219 public: 220 ContextMenuResultOhos(std::shared_ptr<OHOS::NWeb::NWebContextMenuCallback> callback) : callback_(callback) {} 221 222 void Cancel() const override; 223 void CopyImage() const override; 224 void Copy() const override; 225 void Paste() const override; 226 void Cut() const override; 227 void SelectAll() const override; 228 229 private: 230 std::shared_ptr<OHOS::NWeb::NWebContextMenuCallback> callback_; 231 }; 232 233 class WebGeolocationOhos : public WebGeolocation { DECLARE_ACE_TYPE(WebGeolocationOhos,WebGeolocation)234 DECLARE_ACE_TYPE(WebGeolocationOhos, WebGeolocation) 235 236 public: 237 WebGeolocationOhos(const std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface>& callback) 238 : geolocationCallback_(callback) {} 239 240 void Invoke(const std::string& origin, const bool& allow, const bool& retain) override; 241 242 private: 243 std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface> geolocationCallback_; 244 }; 245 246 class WebPermissionRequestOhos : public WebPermissionRequest { DECLARE_ACE_TYPE(WebPermissionRequestOhos,WebPermissionRequest)247 DECLARE_ACE_TYPE(WebPermissionRequestOhos, WebPermissionRequest) 248 249 public: 250 WebPermissionRequestOhos(const std::shared_ptr<OHOS::NWeb::NWebAccessRequest>& request) : request_(request) {} 251 252 void Deny() const override; 253 254 std::string GetOrigin() const override; 255 256 std::vector<std::string> GetResources() const override; 257 258 void Grant(std::vector<std::string>& resources) const override; 259 260 private: 261 std::shared_ptr<OHOS::NWeb::NWebAccessRequest> request_; 262 }; 263 264 class WebWindowNewHandlerOhos : public WebWindowNewHandler { DECLARE_ACE_TYPE(WebWindowNewHandlerOhos,WebWindowNewHandler)265 DECLARE_ACE_TYPE(WebWindowNewHandlerOhos, WebWindowNewHandler) 266 267 public: 268 WebWindowNewHandlerOhos(const std::shared_ptr<OHOS::NWeb::NWebControllerHandler>& handler, int32_t parentNWebId) 269 : handler_(handler), parentNWebId_(parentNWebId) {} 270 271 void SetWebController(int32_t id) override; 272 273 bool IsFrist() const override; 274 275 int32_t GetId() const override; 276 277 int32_t GetParentNWebId() const override; 278 279 private: 280 std::shared_ptr<OHOS::NWeb::NWebControllerHandler> handler_; 281 int32_t parentNWebId_ = -1; 282 }; 283 284 class DataResubmittedOhos : public DataResubmitted { DECLARE_ACE_TYPE(DataResubmittedOhos,DataResubmitted)285 DECLARE_ACE_TYPE(DataResubmittedOhos, DataResubmitted) 286 287 public: 288 DataResubmittedOhos(std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler) : handler_(handler) {} 289 void Resend() override; 290 void Cancel() override; 291 292 private: 293 std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler_; 294 }; 295 296 class FaviconReceivedOhos : public WebFaviconReceived { DECLARE_ACE_TYPE(FaviconReceivedOhos,WebFaviconReceived)297 DECLARE_ACE_TYPE(FaviconReceivedOhos, WebFaviconReceived) 298 299 public: 300 FaviconReceivedOhos( 301 const void* data, 302 size_t width, 303 size_t height, 304 OHOS::NWeb::ImageColorType colorType, 305 OHOS::NWeb::ImageAlphaType alphaType) 306 : data_(data), width_(width), height_(height), colorType_(colorType), alphaType_(alphaType) {} 307 const void* GetData() override; 308 size_t GetWidth() override; 309 size_t GetHeight() override; 310 int GetColorType() override; 311 int GetAlphaType() override; 312 313 private: 314 const void* data_ = nullptr; 315 size_t width_ = 0; 316 size_t height_ = 0; 317 OHOS::NWeb::ImageColorType colorType_ = OHOS::NWeb::ImageColorType::COLOR_TYPE_UNKNOWN; 318 OHOS::NWeb::ImageAlphaType alphaType_ = OHOS::NWeb::ImageAlphaType::ALPHA_TYPE_UNKNOWN; 319 }; 320 321 class WebSurfaceCallback : public OHOS::SurfaceDelegate::ISurfaceCallback { 322 323 public: WebSurfaceCallback(const WeakPtr<WebDelegate> & delegate)324 WebSurfaceCallback(const WeakPtr<WebDelegate>& delegate) : delegate_(delegate) {} 325 ~WebSurfaceCallback() = default; 326 327 void OnSurfaceCreated(const OHOS::sptr<OHOS::Surface>& surface) override; 328 void OnSurfaceChanged(const OHOS::sptr<OHOS::Surface>& surface, int32_t width, int32_t height) override; 329 void OnSurfaceDestroyed() override; 330 private: 331 WeakPtr<WebDelegate> delegate_; 332 333 }; 334 335 enum class DragAction { 336 DRAG_START = 0, 337 DRAG_ENTER, 338 DRAG_LEAVE, 339 DRAG_OVER, 340 DRAG_DROP, 341 DRAG_END, 342 DRAG_CANCEL, 343 }; 344 345 namespace NG { 346 class WebPattern; 347 }; // namespace NG 348 349 class RenderWeb; 350 class WebDelegate : public WebResource { 351 DECLARE_ACE_TYPE(WebDelegate, WebResource); 352 353 public: 354 using CreatedCallback = std::function<void()>; 355 using ReleasedCallback = std::function<void(bool)>; 356 using EventCallback = std::function<void(const std::string&)>; 357 using EventCallbackV2 = std::function<void(const std::shared_ptr<BaseEventInfo>&)>; 358 enum class State : char { 359 WAITINGFORSIZE, 360 CREATING, 361 CREATED, 362 CREATEFAILED, 363 RELEASED, 364 }; 365 366 WebDelegate() = delete; 367 ~WebDelegate() override; WebDelegate(const WeakPtr<PipelineBase> & context,ErrorCallback && onError,const std::string & type)368 WebDelegate(const WeakPtr<PipelineBase>& context, ErrorCallback&& onError, const std::string& type) 369 : WebResource(type, context, std::move(onError)) 370 {} 371 372 void SetRenderWeb(const WeakPtr<RenderWeb>& renderWeb); 373 374 void CreatePlatformResource(const Size& size, const Offset& position, const WeakPtr<PipelineContext>& context); 375 void CreatePluginResource(const Size& size, const Offset& position, const WeakPtr<PipelineContext>& context); 376 void AddCreatedCallback(const CreatedCallback& createdCallback); 377 void RemoveCreatedCallback(); 378 void AddReleasedCallback(const ReleasedCallback& releasedCallback); 379 void SetComponent(const RefPtr<WebComponent>& component); 380 void RemoveReleasedCallback(); 381 void Reload(); 382 void UpdateUrl(const std::string& url); 383 #ifdef OHOS_STANDARD_SYSTEM 384 // TODO: add to separate this file into three file, base file, component impl and ng impl. 385 void InitOHOSWeb(const RefPtr<PipelineBase>& context, const RefPtr<NG::RenderSurface>& surface); 386 void InitOHOSWeb(const WeakPtr<PipelineBase>& context); 387 bool PrepareInitOHOSWeb(const WeakPtr<PipelineBase>& context); 388 void InitWebViewWithWindow(); 389 void ShowWebView(); 390 void HideWebView(); 391 void Resize(const double& width, const double& height); 392 void UpdateUserAgent(const std::string& userAgent); 393 void UpdateBackgroundColor(const int backgroundColor); 394 void UpdateInitialScale(float scale); 395 void UpdateJavaScriptEnabled(const bool& isJsEnabled); 396 void UpdateAllowFileAccess(const bool& isFileAccessEnabled); 397 void UpdateBlockNetworkImage(const bool& onLineImageAccessEnabled); 398 void UpdateLoadsImagesAutomatically(const bool& isImageAccessEnabled); 399 void UpdateMixedContentMode(const MixedModeContent& mixedMode); 400 void UpdateSupportZoom(const bool& isZoomAccessEnabled); 401 void UpdateDomStorageEnabled(const bool& isDomStorageAccessEnabled); 402 void UpdateGeolocationEnabled(const bool& isGeolocationAccessEnabled); 403 void UpdateCacheMode(const WebCacheMode& mode); 404 std::shared_ptr<OHOS::NWeb::NWeb> GetNweb(); 405 bool GetForceDarkMode(); 406 void UpdateDarkMode(const WebDarkMode& mode); 407 void UpdateDarkModeAuto(RefPtr<WebDelegate> delegate, std::shared_ptr<OHOS::NWeb::NWebPreference> setting); 408 void UpdateForceDarkAccess(const bool& access); 409 void UpdateOverviewModeEnabled(const bool& isOverviewModeAccessEnabled); 410 void UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled); 411 void UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled); 412 void UpdateTextZoomRatio(const int32_t& textZoomRatioNum); 413 void UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled); 414 void UpdatePinchSmoothModeEnabled(bool isPinchSmoothModeEnabled); 415 void UpdateMediaPlayGestureAccess(bool isNeedGestureAccess); 416 void UpdateMultiWindowAccess(bool isMultiWindowAccessEnabled); 417 void UpdateWebCursiveFont(const std::string& cursiveFontFamily); 418 void UpdateWebFantasyFont(const std::string& fantasyFontFamily); 419 void UpdateWebFixedFont(const std::string& fixedFontFamily); 420 void UpdateWebSansSerifFont(const std::string& sansSerifFontFamily); 421 void UpdateWebSerifFont(const std::string& serifFontFamily); 422 void UpdateWebStandardFont(const std::string& standardFontFamily); 423 void UpdateDefaultFixedFontSize(int32_t size); 424 void UpdateDefaultFontSize(int32_t defaultFontSize); 425 void UpdateMinFontSize(int32_t minFontSize); 426 void UpdateMinLogicalFontSize(int32_t minLogicalFontSize); 427 void UpdateBlockNetwork(bool isNetworkBlocked); 428 void UpdateHorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled); 429 void UpdateVerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled); 430 void LoadUrl(); 431 void CreateWebMessagePorts(std::vector<RefPtr<WebMessagePort>>& ports); 432 void PostWebMessage(std::string& message, std::vector<RefPtr<WebMessagePort>>& ports, std::string& uri); 433 void ClosePort(std::string& handle); 434 void PostPortMessage(std::string& handle, std::string& data); 435 void SetPortMessageCallback(std::string& handle, std::function<void(const std::string&)>&& callback); 436 void HandleTouchDown(const int32_t& id, const double& x, const double& y); 437 void HandleTouchUp(const int32_t& id, const double& x, const double& y); 438 void HandleTouchMove(const int32_t& id, const double& x, const double& y); 439 void HandleTouchCancel(); 440 void HandleAxisEvent(const double& x, const double& y, const double& deltaX, const double& deltaY); 441 bool OnKeyEvent(int32_t keyCode, int32_t keyAction); 442 void OnMouseEvent(int32_t x, int32_t y, const MouseButton button, const MouseAction action, int count); 443 void OnFocus(); 444 void OnBlur(); 445 void OnPermissionRequestPrompt(const std::shared_ptr<OHOS::NWeb::NWebAccessRequest>& request); 446 bool RunQuickMenu(std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 447 std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback); 448 void OnQuickMenuDismissed(); 449 void OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle, 450 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle, 451 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle); 452 void HandleDragEvent(int32_t x, int32_t y, const DragAction& dragAction); 453 RefPtr<PixelMap> GetDragPixelMap(); 454 std::string GetUrl(); 455 void UpdateLocale(); 456 void OnInactive(); 457 void OnActive(); 458 bool OnCursorChange(const OHOS::NWeb::CursorType& type, const OHOS::NWeb::NWebCursorInfo& info); 459 void OnSelectPopupMenu( 460 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params, 461 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback); 462 #endif 463 void OnErrorReceive(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request, 464 std::shared_ptr<OHOS::NWeb::NWebUrlResourceError> error); 465 void OnHttpErrorReceive(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request, 466 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response); 467 RefPtr<WebResponse> OnInterceptRequest(const std::shared_ptr<BaseEventInfo>& info); 468 bool IsEmptyOnInterceptRequest(); 469 void OnPageStarted(const std::string& param); 470 void OnPageFinished(const std::string& param); 471 void OnProgressChanged(int param); 472 void OnReceivedTitle(const std::string& param); 473 void ExitFullScreen(); 474 void OnFullScreenExit(); 475 void OnGeolocationPermissionsHidePrompt(); 476 void OnGeolocationPermissionsShowPrompt( 477 const std::string& origin, const std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface>& callback); 478 void OnRequestFocus(); 479 bool OnCommonDialog(const std::shared_ptr<BaseEventInfo>& info, DialogEventType dialogEventType); 480 bool OnHttpAuthRequest(const std::shared_ptr<BaseEventInfo>& info); 481 bool OnSslErrorRequest(const std::shared_ptr<BaseEventInfo>& info); 482 bool OnSslSelectCertRequest(const std::shared_ptr<BaseEventInfo>& info); 483 void OnDownloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, 484 const std::string& mimetype, long contentLength); 485 void OnPageError(const std::string& param); 486 void OnMessage(const std::string& param); 487 void OnFullScreenEnter(std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler); 488 bool OnConsoleLog(std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message); 489 void OnRouterPush(const std::string& param); 490 void OnRenderExited(OHOS::NWeb::RenderExitReason reason); 491 void OnRefreshAccessedHistory(const std::string& url, bool isRefreshed); 492 bool OnFileSelectorShow(const std::shared_ptr<BaseEventInfo>& info); 493 bool OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info); 494 bool OnHandleInterceptUrlLoading(const std::string& url); 495 void OnResourceLoad(const std::string& url); 496 void OnScaleChange(float oldScaleFactor, float newScaleFactor); 497 void OnScroll(double xOffset, double yOffset); 498 bool LoadDataWithRichText(); 499 void OnSearchResultReceive(int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting); 500 bool OnDragAndDropData(const void* data, size_t len, int width, int height); 501 void OnWindowNew(const std::string& targetUrl, bool isAlert, bool isUserTrigger, 502 const std::shared_ptr<OHOS::NWeb::NWebControllerHandler>& handler); 503 void OnWindowExit(); 504 void OnPageVisible(const std::string& url); 505 void OnDataResubmitted(std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler); 506 void OnFaviconReceived(const void* data, size_t width, size_t height, OHOS::NWeb::ImageColorType colorType, 507 OHOS::NWeb::ImageAlphaType alphaType); 508 void OnTouchIconUrl(const std::string& iconUrl, bool precomposed); 509 510 void SetNGWebPattern(const RefPtr<NG::WebPattern>& webPattern); 511 void RequestFocus(); 512 void SetDrawSize(const Size& drawSize); 513 void SetEnhanceSurfaceFlag(const bool& isEnhanceSurface); 514 EGLConfig GLGetConfig(int version, EGLDisplay eglDisplay); 515 void GLContextInit(void* window); 516 sptr<OHOS::SurfaceDelegate> GetSurfaceDelegateClient(); 517 void SetBoundsOrResize(const Size& drawSize, const Offset& offset); 518 Offset GetWebRenderGlobalPos(); 519 bool InitWebSurfaceDelegate(const WeakPtr<PipelineBase>& context); 520 #if defined(ENABLE_ROSEN_BACKEND) 521 void SetSurface(const sptr<Surface>& surface); 522 sptr<Surface> surface_ = nullptr; 523 #endif SetWebRendeGlobalPos(const Offset & pos)524 void SetWebRendeGlobalPos(const Offset& pos) 525 { 526 offset_ = pos; 527 } SetBlurReason(const OHOS::NWeb::BlurReason & blurReason)528 void SetBlurReason(const OHOS::NWeb::BlurReason& blurReason) 529 { 530 blurReason_ = blurReason; 531 } SetPopup(bool popup)532 void SetPopup(bool popup) 533 { 534 isPopup_ = popup; 535 } SetParentNWebId(int32_t parentNWebId)536 void SetParentNWebId(int32_t parentNWebId) 537 { 538 parentNWebId_ = parentNWebId; 539 } 540 private: 541 void InitWebEvent(); 542 void RegisterWebEvent(); 543 void ReleasePlatformResource(); 544 void Stop(); 545 void UnregisterEvent(); 546 std::string GetUrlStringParam(const std::string& param, const std::string& name) const; 547 void CallWebRouterBack(); 548 void CallPopPageSuccessPageUrl(const std::string& url); 549 void CallIsPagePathInvalid(const bool& isPageInvalid); 550 551 void BindRouterBackMethod(); 552 void BindPopPageSuccessMethod(); 553 void BindIsPagePathInvalidMethod(); 554 555 #ifdef OHOS_STANDARD_SYSTEM 556 sptr<OHOS::Rosen::Window> CreateWindow(); 557 void LoadUrl(const std::string& url, const std::map<std::string, std::string>& httpHeaders); 558 void ExecuteTypeScript(const std::string& jscode, const std::function<void(std::string)>&& callback); 559 void LoadDataWithBaseUrl(const std::string& baseUrl, const std::string& data, const std::string& mimeType, 560 const std::string& encoding, const std::string& historyUrl); 561 void Refresh(); 562 void StopLoading(); 563 void AddJavascriptInterface(const std::string& objectName, const std::vector<std::string>& methodList); 564 void RemoveJavascriptInterface(const std::string& objectName, const std::vector<std::string>& methodList); 565 void SetWebViewJavaScriptResultCallBack(const WebController::JavaScriptCallBackImpl&& javaScriptCallBackImpl); 566 void Zoom(float factor); 567 bool ZoomIn(); 568 bool ZoomOut(); 569 int ConverToWebHitTestType(int hitType); 570 int GetHitTestResult(); 571 void GetHitTestValue(HitTestResult& result); 572 int GetPageHeight(); 573 int GetWebId(); 574 std::string GetTitle(); 575 std::string GetDefaultUserAgent(); 576 bool SaveCookieSync(); 577 bool SetCookie(const std::string& url, const std::string& value); 578 std::string GetCookie(const std::string& url) const; 579 void DeleteEntirelyCookie(); 580 void RegisterOHOSWebEventAndMethord(); 581 void SetWebCallBack(); 582 void RunSetWebIdCallback(); 583 void RunJsProxyCallback(); 584 void RegisterConfigObserver(); 585 void UnRegisterConfigObserver(); 586 587 // Backward and forward 588 void Backward(); 589 void Forward(); 590 void ClearHistory(); 591 void ClearSslCache(); 592 void ClearClientAuthenticationCache(); 593 bool AccessStep(int32_t step); 594 void BackOrForward(int32_t step); 595 bool AccessBackward(); 596 bool AccessForward(); 597 598 void SearchAllAsync(const std::string& searchStr); 599 void ClearMatches(); 600 void SearchNext(bool forward); 601 602 void UpdateSettting(bool useNewPipe = false); 603 604 std::string GetCustomScheme(); 605 void InitWebViewWithSurface(); 606 Size GetEnhanceSurfaceSize(const Size& drawSize); 607 void NotifyPopupWindowResult(bool result); 608 #endif 609 610 WeakPtr<WebComponent> webComponent_; 611 WeakPtr<RenderWeb> renderWeb_; 612 613 WeakPtr<NG::WebPattern> webPattern_; 614 615 std::list<CreatedCallback> createdCallbacks_; 616 std::list<ReleasedCallback> releasedCallbacks_; 617 EventCallback onPageStarted_; 618 EventCallback onPageFinished_; 619 EventCallback onPageError_; 620 EventCallback onMessage_; 621 Method reloadMethod_; 622 Method updateUrlMethod_; 623 Method routerBackMethod_; 624 Method changePageUrlMethod_; 625 Method isPagePathInvalidMethod_; 626 State state_ { State::WAITINGFORSIZE }; 627 #ifdef OHOS_STANDARD_SYSTEM 628 std::shared_ptr<OHOS::NWeb::NWeb> nweb_; 629 OHOS::NWeb::NWebCookieManager* cookieManager_ = nullptr; 630 sptr<Rosen::Window> window_; 631 bool isCreateWebView_ = false; 632 633 EventCallbackV2 onPageFinishedV2_; 634 EventCallbackV2 onPageStartedV2_; 635 EventCallbackV2 onProgressChangeV2_; 636 EventCallbackV2 onTitleReceiveV2_; 637 EventCallbackV2 onFullScreenExitV2_; 638 EventCallbackV2 onGeolocationHideV2_; 639 EventCallbackV2 onGeolocationShowV2_; 640 EventCallbackV2 onRequestFocusV2_; 641 EventCallbackV2 onErrorReceiveV2_; 642 EventCallbackV2 onHttpErrorReceiveV2_; 643 EventCallbackV2 onDownloadStartV2_; 644 EventCallbackV2 onRefreshAccessedHistoryV2_; 645 EventCallbackV2 onRenderExitedV2_; 646 EventCallbackV2 onResourceLoadV2_; 647 EventCallbackV2 onScaleChangeV2_; 648 EventCallbackV2 onScrollV2_; 649 EventCallbackV2 onPermissionRequestV2_; 650 EventCallbackV2 onSearchResultReceiveV2_; 651 EventCallbackV2 onWindowExitV2_; 652 EventCallbackV2 onPageVisibleV2_; 653 EventCallbackV2 onTouchIconUrlV2_; 654 655 std::string bundlePath_; 656 std::string bundleDataPath_; 657 RefPtr<PixelMap> pixelMap_ = nullptr; 658 bool isRefreshPixelMap_ = false; 659 Size drawSize_; 660 Offset offset_; 661 bool isEnhanceSurface_ = false; 662 sptr<WebSurfaceCallback> surfaceCallback_; 663 sptr<OHOS::SurfaceDelegate> surfaceDelegate_; 664 EGLNativeWindowType mEglWindow; 665 EGLDisplay mEGLDisplay = EGL_NO_DISPLAY; 666 EGLConfig mEGLConfig = nullptr; 667 EGLContext mEGLContext = EGL_NO_CONTEXT; 668 EGLContext mSharedEGLContext = EGL_NO_CONTEXT; 669 EGLSurface mEGLSurface = nullptr; 670 WindowsSurfaceInfo surfaceInfo_; 671 bool forceDarkMode_ = false; 672 sptr<AppExecFwk::IConfigurationObserver> configChangeObserver_ = nullptr; 673 OHOS::NWeb::BlurReason blurReason_ = OHOS::NWeb::BlurReason::FOCUS_SWITCH; 674 bool isPopup_ = false; 675 int32_t parentNWebId_ = -1; 676 bool needResizeAtFirst_ = false; 677 #endif 678 }; 679 680 } // namespace OHOS::Ace 681 682 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_DELEGATE_H 683