1 /* 2 * Copyright (c) 2021-2024 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 "ability_runtime/context/environment_callback.h" 23 #include "base/memory/referenced.h" 24 #include "core/components_ng/render/render_surface.h" 25 #include "core/pipeline/pipeline_base.h" 26 #include "base/web/webview/arkweb_utils/arkweb_utils.h" 27 #if defined (OHOS_STANDARD_SYSTEM) && defined (ENABLE_ROSEN_BACKEND) 28 #include <ui/rs_surface_node.h> 29 #endif 30 31 #include <EGL/egl.h> 32 #include <EGL/eglext.h> 33 #include <GLES3/gl3.h> 34 #include "base/image/pixel_map.h" 35 #include "base/memory/ace_type.h" 36 #include "core/common/recorder/event_recorder.h" 37 #include "core/common/container.h" 38 #include "core/components/common/layout/constants.h" 39 #include "core/components/web/resource/web_client_impl.h" 40 #include "core/components/web/resource/web_resource.h" 41 #include "core/components/web/web_component.h" 42 #include "core/components/web/web_event.h" 43 #include "core/components_ng/pattern/web/web_event_hub.h" 44 #include "frameworks/core/components_ng/pattern/web/web_model_ng.h" 45 #include "core/components_ng/pattern/web/web_pattern.h" 46 #include "nweb_accessibility_node_info.h" 47 #include "surface_delegate.h" 48 #ifdef OHOS_STANDARD_SYSTEM 49 #include "nweb_handler.h" 50 #include "nweb_helper.h" 51 #include "nweb_hit_testresult.h" 52 #include "app_mgr_client.h" 53 #ifdef ENABLE_ROSEN_BACKEND 54 #include "surface.h" 55 #include "core/components_ng/render/adapter/rosen_render_surface.h" 56 #endif 57 #include "wm/window.h" 58 #endif 59 60 namespace OHOS::Ace { 61 62 typedef struct WindowsSurfaceInfoTag { 63 void* window; 64 EGLDisplay display; 65 EGLContext context; 66 EGLSurface surface; 67 } WindowsSurfaceInfo; 68 69 typedef NWeb::NativeArkWebOnJavaScriptProxyCallback NativeMethodCallback; 70 71 class WebMessagePortOhos : public WebMessagePort { 72 DECLARE_ACE_TYPE(WebMessagePortOhos, WebMessagePort); 73 74 public: WebMessagePortOhos(WeakPtr<WebDelegate> webDelegate)75 WebMessagePortOhos(WeakPtr<WebDelegate> webDelegate) : webDelegate_(webDelegate) {} 76 WebMessagePortOhos() = default; 77 ~WebMessagePortOhos() = default; 78 79 void Close() override; 80 void PostMessage(std::string& data) override; 81 void SetWebMessageCallback(std::function<void(const std::string&)>&& callback) override; 82 void SetPortHandle(std::string& handle) override; 83 std::string GetPortHandle() override; 84 85 private: 86 WeakPtr<WebDelegate> webDelegate_; 87 std::string handle_; 88 }; 89 90 class ConsoleLogOhos : public WebConsoleLog { 91 DECLARE_ACE_TYPE(ConsoleLogOhos, WebConsoleLog); 92 93 public: ConsoleLogOhos(std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message)94 explicit ConsoleLogOhos(std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message) : message_(message) {} 95 96 int GetLineNumber() override; 97 98 std::string GetLog() override; 99 100 int GetLogLevel() override; 101 102 std::string GetSourceId() override; 103 104 private: 105 std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message_; 106 }; 107 108 class ResultOhos : public Result { 109 DECLARE_ACE_TYPE(ResultOhos, Result); 110 111 public: ResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSDialogResult> result)112 explicit ResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSDialogResult> result) : result_(result) {} 113 114 void Confirm() override; 115 void Confirm(const std::string& message) override; 116 void Cancel() override; 117 118 private: 119 std::shared_ptr<OHOS::NWeb::NWebJSDialogResult> result_; 120 }; 121 122 class FullScreenExitHandlerOhos : public FullScreenExitHandler { 123 DECLARE_ACE_TYPE(FullScreenExitHandlerOhos, FullScreenExitHandler); 124 125 public: FullScreenExitHandlerOhos(std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler,WeakPtr<WebDelegate> webDelegate)126 FullScreenExitHandlerOhos(std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler, 127 WeakPtr<WebDelegate> webDelegate) : handler_(handler), webDelegate_(webDelegate) {} 128 void ExitFullScreen() override; 129 private: 130 std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler_; 131 WeakPtr<WebDelegate> webDelegate_; 132 }; 133 134 class WebCustomKeyboardHandlerOhos : public WebCustomKeyboardHandler { 135 DECLARE_ACE_TYPE(WebCustomKeyboardHandlerOhos, WebCustomKeyboardHandler); 136 137 public: WebCustomKeyboardHandlerOhos(std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler)138 explicit WebCustomKeyboardHandlerOhos(std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler) : 139 keyboardHandler_(keyboardHandler) {} 140 InsertText(const std::string & text)141 void InsertText(const std::string &text) override 142 { 143 if (keyboardHandler_) { 144 keyboardHandler_->InsertText(text); 145 } 146 } 147 DeleteForward(int32_t length)148 void DeleteForward(int32_t length) override 149 { 150 if (keyboardHandler_) { 151 keyboardHandler_->DeleteForward(length); 152 } 153 } 154 DeleteBackward(int32_t length)155 void DeleteBackward(int32_t length) override 156 { 157 if (keyboardHandler_) { 158 keyboardHandler_->DeleteBackward(length); 159 } 160 } 161 SendFunctionKey(int32_t key)162 void SendFunctionKey(int32_t key) override 163 { 164 if (keyboardHandler_) { 165 keyboardHandler_->SendFunctionKey(key); 166 } 167 } 168 Close()169 void Close() override 170 { 171 if (keyboardHandler_) { 172 keyboardHandler_->Close(); 173 } 174 } 175 176 private: 177 std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler_; 178 }; 179 180 class AuthResultOhos : public AuthResult { 181 DECLARE_ACE_TYPE(AuthResultOhos, AuthResult); 182 183 public: AuthResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSHttpAuthResult> result)184 explicit AuthResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSHttpAuthResult> result) : result_(result) {} 185 186 bool Confirm(std::string& userName, std::string& pwd) override; 187 bool IsHttpAuthInfoSaved() override; 188 void Cancel() override; 189 190 private: 191 std::shared_ptr<OHOS::NWeb::NWebJSHttpAuthResult> result_; 192 }; 193 194 class SslErrorResultOhos : public SslErrorResult { 195 DECLARE_ACE_TYPE(SslErrorResultOhos, SslErrorResult); 196 197 public: SslErrorResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSSslErrorResult> result)198 explicit SslErrorResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSSslErrorResult> result) : result_(result) {} 199 200 void HandleConfirm() override; 201 void HandleCancel() override; 202 203 private: 204 std::shared_ptr<OHOS::NWeb::NWebJSSslErrorResult> result_; 205 }; 206 207 class AllSslErrorResultOhos : public AllSslErrorResult { 208 DECLARE_ACE_TYPE(AllSslErrorResultOhos, AllSslErrorResult); 209 210 public: AllSslErrorResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSAllSslErrorResult> result)211 explicit AllSslErrorResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSAllSslErrorResult> result) : result_(result) {} 212 213 void HandleConfirm() override; 214 void HandleCancel(bool abortLoading) override; 215 216 private: 217 std::shared_ptr<OHOS::NWeb::NWebJSAllSslErrorResult> result_; 218 }; 219 220 class SslSelectCertResultOhos : public SslSelectCertResult { 221 DECLARE_ACE_TYPE(SslSelectCertResultOhos, SslSelectCertResult); 222 223 public: SslSelectCertResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSSslSelectCertResult> result)224 explicit SslSelectCertResultOhos(std::shared_ptr<OHOS::NWeb::NWebJSSslSelectCertResult> result) 225 : result_(result) {} 226 227 void HandleConfirm(const std::string& privateKeyFile, const std::string& certChainFile) override; 228 229 void HandleCancel() override; 230 231 void HandleIgnore() override; 232 private: 233 std::shared_ptr<OHOS::NWeb::NWebJSSslSelectCertResult> result_; 234 }; 235 236 class FileSelectorParamOhos : public WebFileSelectorParam { 237 DECLARE_ACE_TYPE(FileSelectorParamOhos, WebFileSelectorParam); 238 239 public: FileSelectorParamOhos(std::shared_ptr<OHOS::NWeb::NWebFileSelectorParams> param)240 explicit FileSelectorParamOhos(std::shared_ptr<OHOS::NWeb::NWebFileSelectorParams> param) : param_(param) {} 241 242 std::string GetTitle() override; 243 int GetMode() override; 244 std::string GetDefaultFileName() override; 245 std::vector<std::string> GetAcceptType() override; 246 bool IsCapture() override; 247 std::vector<std::string> GetMimeType() override; 248 249 private: 250 std::shared_ptr<OHOS::NWeb::NWebFileSelectorParams> param_; 251 }; 252 253 class FileSelectorResultOhos : public FileSelectorResult { 254 DECLARE_ACE_TYPE(FileSelectorResultOhos, FileSelectorResult); 255 256 public: FileSelectorResultOhos(std::shared_ptr<OHOS::NWeb::NWebStringVectorValueCallback> callback,const WeakPtr<WebDelegate> & delegate)257 FileSelectorResultOhos( 258 std::shared_ptr<OHOS::NWeb::NWebStringVectorValueCallback> callback, const WeakPtr<WebDelegate>& delegate) 259 : callback_(callback), delegate_(delegate) 260 {} 261 262 void HandleFileList(std::vector<std::string>& result) override; 263 264 private: 265 std::shared_ptr<OHOS::NWeb::NWebStringVectorValueCallback> callback_; 266 WeakPtr<WebDelegate> delegate_; 267 }; 268 269 class ContextMenuParamOhos : public WebContextMenuParam { 270 DECLARE_ACE_TYPE(ContextMenuParamOhos, WebContextMenuParam); 271 272 public: ContextMenuParamOhos(std::shared_ptr<OHOS::NWeb::NWebContextMenuParams> param)273 explicit ContextMenuParamOhos(std::shared_ptr<OHOS::NWeb::NWebContextMenuParams> param) : param_(param) {} 274 275 int32_t GetXCoord() const override; 276 int32_t GetYCoord() const override; 277 std::string GetLinkUrl() const override; 278 std::string GetUnfilteredLinkUrl() const override; 279 std::string GetSourceUrl() const override; 280 bool HasImageContents() const override; 281 bool IsEditable() const override; 282 int GetEditStateFlags() const override; 283 int GetSourceType() const override; 284 int GetMediaType() const override; 285 int GetInputFieldType() const override; 286 std::string GetSelectionText() const override; 287 void GetImageRect(int32_t& x, int32_t& y, int32_t& width, int32_t& height) const override; 288 bool IsAILink() const override; 289 290 private: 291 std::shared_ptr<OHOS::NWeb::NWebContextMenuParams> param_; 292 }; 293 294 class ContextMenuResultOhos : public ContextMenuResult { 295 DECLARE_ACE_TYPE(ContextMenuResultOhos, ContextMenuResult); 296 297 public: ContextMenuResultOhos(std::shared_ptr<OHOS::NWeb::NWebContextMenuCallback> callback)298 explicit ContextMenuResultOhos(std::shared_ptr<OHOS::NWeb::NWebContextMenuCallback> callback) 299 : callback_(callback) {} 300 301 void Cancel() const override; 302 void CopyImage() const override; 303 void Copy() const override; 304 void Paste() const override; 305 void Cut() const override; 306 void SelectAll() const override; 307 void Undo() const override; 308 void Redo() const override; 309 void PasteAndMatchStyle() const override; 310 311 private: 312 std::shared_ptr<OHOS::NWeb::NWebContextMenuCallback> callback_; 313 }; 314 315 class WebGeolocationOhos : public WebGeolocation { 316 DECLARE_ACE_TYPE(WebGeolocationOhos, WebGeolocation); 317 318 public: WebGeolocationOhos(const std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface> & callback,bool incognito)319 WebGeolocationOhos( 320 const std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface>& 321 callback, bool incognito) 322 : geolocationCallback_(callback), incognito_(incognito) {} 323 324 void Invoke(const std::string& origin, const bool& allow, const bool& retain) override; 325 326 private: 327 std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface> geolocationCallback_; 328 bool incognito_ = false; 329 }; 330 331 class WebPermissionRequestOhos : public WebPermissionRequest { 332 DECLARE_ACE_TYPE(WebPermissionRequestOhos, WebPermissionRequest); 333 334 public: WebPermissionRequestOhos(const std::shared_ptr<OHOS::NWeb::NWebAccessRequest> & request)335 explicit WebPermissionRequestOhos(const std::shared_ptr<OHOS::NWeb::NWebAccessRequest>& request) 336 : request_(request) {} 337 338 void Deny() const override; 339 340 std::string GetOrigin() const override; 341 342 std::vector<std::string> GetResources() const override; 343 344 void Grant(std::vector<std::string>& resources) const override; 345 346 private: 347 std::shared_ptr<OHOS::NWeb::NWebAccessRequest> request_; 348 }; 349 350 class NWebScreenCaptureConfigImpl : public OHOS::NWeb::NWebScreenCaptureConfig { 351 public: 352 NWebScreenCaptureConfigImpl() = default; 353 ~NWebScreenCaptureConfigImpl() = default; 354 GetMode()355 int32_t GetMode() override 356 { 357 return mode_; 358 } 359 SetMode(int32_t mode)360 void SetMode(int32_t mode) 361 { 362 mode_ = mode; 363 } 364 GetSourceId()365 int32_t GetSourceId() override 366 { 367 return source_id_; 368 } 369 SetSourceId(int32_t source_id)370 void SetSourceId(int32_t source_id) 371 { 372 source_id_ = source_id; 373 } 374 375 private: 376 int32_t mode_ = 0; 377 int32_t source_id_ = -1; 378 }; 379 380 class WebScreenCaptureRequestOhos : public WebScreenCaptureRequest { 381 DECLARE_ACE_TYPE(WebScreenCaptureRequestOhos, WebScreenCaptureRequest); 382 383 public: WebScreenCaptureRequestOhos(const std::shared_ptr<OHOS::NWeb::NWebScreenCaptureAccessRequest> & request)384 explicit WebScreenCaptureRequestOhos(const std::shared_ptr<OHOS::NWeb::NWebScreenCaptureAccessRequest>& request) 385 : request_(request) { 386 config_ = std::make_shared<NWebScreenCaptureConfigImpl>(); 387 } 388 389 void Deny() const override; 390 391 std::string GetOrigin() const override; 392 393 void SetCaptureMode(int32_t mode) override; 394 395 void SetSourceId(int32_t sourceId) override; 396 397 void Grant() const override; 398 399 private: 400 std::shared_ptr<OHOS::NWeb::NWebScreenCaptureAccessRequest> request_; 401 402 std::shared_ptr<NWebScreenCaptureConfigImpl> config_; 403 }; 404 405 class WebWindowNewHandlerOhos : public WebWindowNewHandler { 406 DECLARE_ACE_TYPE(WebWindowNewHandlerOhos, WebWindowNewHandler); 407 408 public: WebWindowNewHandlerOhos(const std::shared_ptr<OHOS::NWeb::NWebControllerHandler> & handler,int32_t parentNWebId)409 WebWindowNewHandlerOhos(const std::shared_ptr<OHOS::NWeb::NWebControllerHandler>& handler, int32_t parentNWebId) 410 : handler_(handler), parentNWebId_(parentNWebId) {} 411 412 void SetWebController(int32_t id) override; 413 414 bool IsFrist() const override; 415 416 int32_t GetId() const override; 417 418 int32_t GetParentNWebId() const override; 419 420 private: 421 std::shared_ptr<OHOS::NWeb::NWebControllerHandler> handler_; 422 int32_t parentNWebId_ = -1; 423 }; 424 425 class WebAppLinkCallbackOhos : public WebAppLinkCallback { 426 DECLARE_ACE_TYPE(WebAppLinkCallbackOhos, WebAppLinkCallback); 427 public: WebAppLinkCallbackOhos(const std::shared_ptr<OHOS::NWeb::NWebAppLinkCallback> & callback)428 explicit WebAppLinkCallbackOhos(const std::shared_ptr<OHOS::NWeb::NWebAppLinkCallback>& callback) 429 : callback_(callback) {} 430 ContinueLoad()431 void ContinueLoad() override 432 { 433 if (callback_) { 434 callback_->ContinueLoad(); 435 } 436 } 437 CancelLoad()438 void CancelLoad() override 439 { 440 if (callback_) { 441 callback_->CancelLoad(); 442 } 443 } 444 445 private: 446 std::shared_ptr<OHOS::NWeb::NWebAppLinkCallback> callback_; 447 }; 448 449 class DataResubmittedOhos : public DataResubmitted { 450 DECLARE_ACE_TYPE(DataResubmittedOhos, DataResubmitted); 451 452 public: DataResubmittedOhos(std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler)453 explicit DataResubmittedOhos(std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler) 454 : handler_(handler) {} 455 void Resend() override; 456 void Cancel() override; 457 458 private: 459 std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler_; 460 }; 461 462 class FaviconReceivedOhos : public WebFaviconReceived { 463 DECLARE_ACE_TYPE(FaviconReceivedOhos, WebFaviconReceived); 464 465 public: FaviconReceivedOhos(const void * data,size_t width,size_t height,OHOS::NWeb::ImageColorType colorType,OHOS::NWeb::ImageAlphaType alphaType)466 FaviconReceivedOhos( 467 const void* data, 468 size_t width, 469 size_t height, 470 OHOS::NWeb::ImageColorType colorType, 471 OHOS::NWeb::ImageAlphaType alphaType) 472 : data_(data), width_(width), height_(height), colorType_(colorType), alphaType_(alphaType) 473 { 474 SetPixelMap(); 475 } 476 const void* GetData() override; 477 size_t GetWidth() override; 478 size_t GetHeight() override; 479 int GetColorType() override; 480 int GetAlphaType() override; 481 Media::PixelFormat GetMediaPixelFormat() override; 482 Media::AlphaType GetMediaAlphaType() override; 483 std::shared_ptr<Media::PixelMap> GetPixelMap() override; 484 485 private: 486 void SetPixelMap() override; 487 488 const void* data_ = nullptr; 489 size_t width_ = 0; 490 size_t height_ = 0; 491 OHOS::NWeb::ImageColorType colorType_ = OHOS::NWeb::ImageColorType::COLOR_TYPE_UNKNOWN; 492 OHOS::NWeb::ImageAlphaType alphaType_ = OHOS::NWeb::ImageAlphaType::ALPHA_TYPE_UNKNOWN; 493 std::shared_ptr<Media::PixelMap> pixelMap_; 494 }; 495 496 class WebSurfaceCallback : public OHOS::SurfaceDelegate::ISurfaceCallback { 497 public: WebSurfaceCallback(const WeakPtr<WebDelegate> & delegate)498 explicit WebSurfaceCallback(const WeakPtr<WebDelegate>& delegate) : delegate_(delegate) {} 499 ~WebSurfaceCallback() = default; 500 501 void OnSurfaceCreated(const OHOS::sptr<OHOS::Surface>& surface) override; 502 void OnSurfaceChanged(const OHOS::sptr<OHOS::Surface>& surface, int32_t width, int32_t height) override; 503 void OnSurfaceDestroyed() override; 504 private: 505 WeakPtr<WebDelegate> delegate_; 506 507 }; 508 509 enum class DragAction { 510 DRAG_START = 0, 511 DRAG_ENTER, 512 DRAG_LEAVE, 513 DRAG_OVER, 514 DRAG_DROP, 515 DRAG_END, 516 DRAG_CANCEL, 517 }; 518 519 namespace NG { 520 class WebPattern; 521 }; // namespace NG 522 523 class RenderWeb; 524 525 class NWebDragEventImpl : public OHOS::NWeb::NWebDragEvent { 526 public: NWebDragEventImpl(double x,double y,NWeb::DragAction action)527 NWebDragEventImpl(double x, double y, NWeb::DragAction action) : x_(x), y_(y), action_(action) {} 528 ~NWebDragEventImpl() = default; 529 GetX()530 double GetX() override 531 { 532 return x_; 533 } 534 GetY()535 double GetY() override 536 { 537 return y_; 538 } 539 GetAction()540 NWeb::DragAction GetAction() override 541 { 542 return action_; 543 } 544 545 private: 546 double x_ = 0.0; 547 double y_ = 0.0; 548 NWeb::DragAction action_ = NWeb::DragAction::DRAG_START; 549 }; 550 551 class NWebTouchPointInfoImpl : public OHOS::NWeb::NWebTouchPointInfo { 552 public: NWebTouchPointInfoImpl(int id,double x,double y)553 NWebTouchPointInfoImpl(int id, double x, double y) : id_(id), x_(x), y_(y) {} 554 ~NWebTouchPointInfoImpl() = default; 555 GetId()556 int GetId() override 557 { 558 return id_; 559 } 560 GetX()561 double GetX() override 562 { 563 return x_; 564 } 565 GetY()566 double GetY() override 567 { 568 return y_; 569 } 570 571 private: 572 int id_ = 0; 573 double x_ = 0; 574 double y_ = 0; 575 }; 576 577 class NWebScreenLockCallbackImpl : public OHOS::NWeb::NWebScreenLockCallback { 578 public: 579 explicit NWebScreenLockCallbackImpl(const WeakPtr<PipelineBase>& context); 580 ~NWebScreenLockCallbackImpl() = default; 581 582 void Handle(bool key) override; 583 584 private: 585 WeakPtr<PipelineBase> context_ = nullptr; 586 }; 587 588 class WebDelegateObserver : public virtual AceType { 589 DECLARE_ACE_TYPE(WebDelegateObserver, AceType); 590 public: WebDelegateObserver(const RefPtr<WebDelegate> & delegate,WeakPtr<PipelineBase> context)591 WebDelegateObserver(const RefPtr<WebDelegate>& delegate, WeakPtr<PipelineBase> context) 592 : delegate_(delegate), context_(context) 593 {} 594 ~WebDelegateObserver(); 595 void NotifyDestory(); 596 void OnAttachContext(const RefPtr<NG::PipelineContext> &context); 597 void OnDetachContext(); 598 599 private: 600 RefPtr<WebDelegate> delegate_; 601 WeakPtr<PipelineBase> context_; 602 }; 603 604 class GestureEventResultOhos : public GestureEventResult { 605 DECLARE_ACE_TYPE(GestureEventResultOhos, GestureEventResult); 606 607 public: GestureEventResultOhos(std::shared_ptr<OHOS::NWeb::NWebGestureEventResult> result)608 explicit GestureEventResultOhos(std::shared_ptr<OHOS::NWeb::NWebGestureEventResult> result) 609 : result_(result) {} 610 GestureEventResultOhos(std::shared_ptr<OHOS::NWeb::NWebMouseEventResult> mouseResult)611 explicit GestureEventResultOhos(std::shared_ptr<OHOS::NWeb::NWebMouseEventResult> mouseResult) 612 : mouseResult_(mouseResult) {} 613 614 void SetGestureEventResult(bool result) override; 615 void SetGestureEventResult(bool result, bool stopPropagation) override; HasSendTask()616 bool HasSendTask() { return sendTask_; } SetSendTask()617 void SetSendTask() { sendTask_ = true; } GetEventResult()618 bool GetEventResult() { return eventResult_; } SetIsMouseToTouch(bool isMouseToTouch)619 void SetIsMouseToTouch(bool isMouseToTouch) { isMouseToTouch_ = isMouseToTouch; }; IsMouseToTouch()620 bool IsMouseToTouch() { return isMouseToTouch_; }; 621 622 private: 623 std::shared_ptr<OHOS::NWeb::NWebGestureEventResult> result_; 624 std::shared_ptr<OHOS::NWeb::NWebMouseEventResult> mouseResult_; 625 bool sendTask_ = false; 626 bool eventResult_ = false; 627 bool isMouseToTouch_ = false; 628 }; 629 630 class MouseEventResultOhos : public MouseEventResult { 631 DECLARE_ACE_TYPE(MouseEventResultOhos, MouseEventResult); 632 633 public: MouseEventResultOhos(std::shared_ptr<OHOS::NWeb::NWebMouseEventResult> result)634 explicit MouseEventResultOhos(std::shared_ptr<OHOS::NWeb::NWebMouseEventResult> result) 635 : result_(result) {} 636 637 void SetMouseEventResult(bool result, bool stopPropagation) override; HasSendTask()638 bool HasSendTask() { return sendTask_; } SetSendTask()639 void SetSendTask() { sendTask_ = true; } GetEventResult()640 bool GetEventResult() { return eventResult_; } 641 642 private: 643 std::shared_ptr<OHOS::NWeb::NWebMouseEventResult> result_; 644 bool sendTask_ = false; 645 bool eventResult_ = false; 646 }; 647 648 class WebAvoidAreaChangedListener : public OHOS::Rosen::IAvoidAreaChangedListener { 649 public: WebAvoidAreaChangedListener(WeakPtr<WebDelegate> webDelegate,WeakPtr<PipelineBase> context)650 explicit WebAvoidAreaChangedListener(WeakPtr<WebDelegate> webDelegate, WeakPtr<PipelineBase> context) 651 : webDelegate_(webDelegate), context_(context) {} 652 ~WebAvoidAreaChangedListener() = default; 653 654 void OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea avoidArea, OHOS::Rosen::AvoidAreaType type, 655 const sptr<OHOS::Rosen::OccupiedAreaChangeInfo>& info) override; 656 private: 657 WeakPtr<WebDelegate> webDelegate_; 658 WeakPtr<PipelineBase> context_; 659 }; 660 661 class WebWindowFocusChangedListener : public Rosen::IWindowLifeCycle { 662 public: WebWindowFocusChangedListener(WeakPtr<WebDelegate> webDelegate)663 explicit WebWindowFocusChangedListener(WeakPtr<WebDelegate> webDelegate) : webDelegate_(webDelegate) {} 664 ~WebWindowFocusChangedListener() = default; 665 666 void AfterFocused() override;; 667 private: 668 WeakPtr<WebDelegate> webDelegate_; 669 }; 670 671 enum class ScriptItemType { 672 DOCUMENT_START = 0, 673 DOCUMENT_END = 1, 674 DOCUMENT_HEAD_READY 675 }; 676 677 class NWebSystemConfigurationImpl : public OHOS::NWeb::NWebSystemConfiguration { 678 public: NWebSystemConfigurationImpl(uint8_t flags)679 explicit NWebSystemConfigurationImpl(uint8_t flags) : theme_flags_(flags) {} 680 ~NWebSystemConfigurationImpl() = default; 681 GetThemeFlags()682 uint8_t GetThemeFlags() override 683 { 684 return theme_flags_; 685 } 686 687 private: 688 uint8_t theme_flags_ = static_cast<uint8_t>(NWeb::SystemThemeFlags::NONE); 689 }; 690 691 class NWebKeyboardEventImpl : public OHOS::NWeb::NWebKeyboardEvent { 692 public: NWebKeyboardEventImpl(int32_t keyCode,int32_t action,int32_t unicode,bool enableCapsLock,std::vector<int32_t> pressedCodes)693 NWebKeyboardEventImpl( 694 int32_t keyCode, int32_t action, int32_t unicode, bool enableCapsLock, 695 std::vector<int32_t> pressedCodes) 696 : keyCode_(keyCode), action_(action), unicode_(unicode), enableCapsLock_(enableCapsLock), 697 pressedCodes_(pressedCodes) {} 698 ~NWebKeyboardEventImpl() = default; 699 GetKeyCode()700 int32_t GetKeyCode() override 701 { 702 return keyCode_; 703 } 704 GetAction()705 int32_t GetAction() override 706 { 707 return action_; 708 } 709 GetUnicode()710 int32_t GetUnicode() override 711 { 712 return unicode_; 713 } 714 IsEnableCapsLock()715 bool IsEnableCapsLock() override 716 { 717 return enableCapsLock_; 718 } 719 GetPressKeyCodes()720 std::vector<int32_t> GetPressKeyCodes() override 721 { 722 return pressedCodes_; 723 } 724 725 private: 726 int32_t keyCode_ = 0; 727 int32_t action_ = 0; 728 uint32_t unicode_ = 0; 729 bool enableCapsLock_ = false; 730 std::vector<int32_t> pressedCodes_ {}; 731 }; 732 733 class NWebMouseEventImpl : public OHOS::NWeb::NWebMouseEvent { 734 public: NWebMouseEventImpl(int32_t x,int32_t y,int32_t rawX,int32_t rawY,int32_t buttton,int32_t action,int32_t clickNum,std::vector<int32_t> pressedCodes)735 NWebMouseEventImpl(int32_t x, int32_t y, int32_t rawX, int32_t rawY, 736 int32_t buttton, int32_t action, 737 int32_t clickNum, std::vector<int32_t> pressedCodes) 738 : x_(x), y_(y), buttton_(buttton), action_(action), 739 clickNum_(clickNum), pressedCodes_(pressedCodes) {} 740 ~NWebMouseEventImpl() = default; 741 GetX()742 int32_t GetX() override 743 { 744 return x_; 745 } 746 GetY()747 int32_t GetY() override 748 { 749 return y_; 750 } 751 GetButton()752 int32_t GetButton() override 753 { 754 return buttton_; 755 } 756 GetAction()757 int32_t GetAction() override 758 { 759 return action_; 760 } 761 GetClickNum()762 int32_t GetClickNum() override 763 { 764 return clickNum_; 765 } 766 GetPressKeyCodes()767 std::vector<int32_t> GetPressKeyCodes() override 768 { 769 return pressedCodes_; 770 } 771 GetRawX()772 int32_t GetRawX() override 773 { 774 return raw_x_; 775 } 776 GetRawY()777 int32_t GetRawY() override 778 { 779 return raw_y_; 780 } 781 782 private: 783 int32_t x_ = 0; 784 int32_t y_ = 0; 785 int32_t raw_x_ = 0; 786 int32_t raw_y_ = 0; 787 int32_t buttton_ = 0; 788 int32_t action_ = 0; 789 int32_t clickNum_ = 0; 790 std::vector<int32_t> pressedCodes_ {}; 791 }; 792 793 class WebDelegate : public WebResource { 794 DECLARE_ACE_TYPE(WebDelegate, WebResource); 795 796 public: 797 using CreatedCallback = std::function<void()>; 798 using ReleasedCallback = std::function<void(bool)>; 799 using EventCallback = std::function<void(const std::string&)>; 800 using EventCallbackV2 = std::function<void(const std::shared_ptr<BaseEventInfo>&)>; 801 enum class State : char { 802 WAITINGFORSIZE, 803 CREATING, 804 CREATED, 805 CREATEFAILED, 806 RELEASED, 807 }; 808 809 // for webcontoller, the enum is same as web_webview and core side 810 enum class JavaScriptObjIdErrorCode : int32_t { WEBCONTROLLERERROR = -2, WEBVIEWCONTROLLERERROR = -1, END = 0 }; 811 812 WebDelegate() = delete; 813 ~WebDelegate() override; WebDelegate(const WeakPtr<PipelineBase> & context,ErrorCallback && onError,const std::string & type)814 WebDelegate(const WeakPtr<PipelineBase>& context, ErrorCallback&& onError, const std::string& type) 815 : WebResource(type, context, std::move(onError)), instanceId_(Container::CurrentId()) 816 {} WebDelegate(const WeakPtr<PipelineBase> & context,ErrorCallback && onError,const std::string & type,int32_t id)817 WebDelegate(const WeakPtr<PipelineBase>& context, ErrorCallback&& onError, const std::string& type, int32_t id) 818 : WebResource(type, context, std::move(onError)), instanceId_(id) 819 {} 820 821 void UnRegisterScreenLockFunction(); 822 SetObserver(const RefPtr<WebDelegateObserver> & observer)823 void SetObserver(const RefPtr<WebDelegateObserver>& observer) 824 { 825 observer_ = observer; 826 }; 827 void SetRenderWeb(const WeakPtr<RenderWeb>& renderWeb); 828 829 void CreatePlatformResource(const Size& size, const Offset& position, const WeakPtr<PipelineContext>& context); 830 void CreatePluginResource(const Size& size, const Offset& position, const WeakPtr<PipelineContext>& context); 831 void AddCreatedCallback(const CreatedCallback& createdCallback); 832 void RemoveCreatedCallback(); 833 void AddReleasedCallback(const ReleasedCallback& releasedCallback); 834 void SetComponent(const RefPtr<WebComponent>& component); 835 void RemoveReleasedCallback(); 836 void Reload(); 837 void UpdateUrl(const std::string& url); 838 #ifdef OHOS_STANDARD_SYSTEM 839 void InitOHOSWeb(const RefPtr<PipelineBase>& context, const RefPtr<NG::RenderSurface>& surface); 840 void InitOHOSWeb(const WeakPtr<PipelineBase>& context); 841 bool PrepareInitOHOSWeb(const WeakPtr<PipelineBase>& context); 842 void InitWebViewWithWindow(); 843 void ShowWebView(); 844 void HideWebView(); 845 void OnRenderToBackground(); 846 void OnRenderToForeground(); 847 void SetSurfaceDensity(const double& density); 848 void Resize(const double& width, const double& height, bool isKeyboard = false); GetRosenWindowId()849 int32_t GetRosenWindowId() 850 { 851 return rosenWindowId_; 852 } 853 void SetKeepScreenOn(bool key); 854 void UpdateUserAgent(const std::string& userAgent); 855 void UpdateBackgroundColor(const int backgroundColor); 856 void UpdateInitialScale(float scale); 857 void UpdateLayoutMode(WebLayoutMode mode); 858 void UpdateJavaScriptEnabled(const bool& isJsEnabled); 859 void UpdateAllowFileAccess(const bool& isFileAccessEnabled); 860 void UpdateBlockNetworkImage(const bool& onLineImageAccessEnabled); 861 void UpdateLoadsImagesAutomatically(const bool& isImageAccessEnabled); 862 void UpdateMixedContentMode(const MixedModeContent& mixedMode); 863 void UpdateSupportZoom(const bool& isZoomAccessEnabled); 864 void UpdateDomStorageEnabled(const bool& isDomStorageAccessEnabled); 865 void UpdateGeolocationEnabled(const bool& isGeolocationAccessEnabled); 866 void UpdateCacheMode(const WebCacheMode& mode); 867 std::shared_ptr<OHOS::NWeb::NWeb> GetNweb(); 868 bool GetForceDarkMode(); 869 void OnConfigurationUpdated(const OHOS::AppExecFwk::Configuration& configuration); 870 void UpdateDarkMode(const WebDarkMode& mode); 871 void UpdateDarkModeAuto(RefPtr<WebDelegate> delegate, std::shared_ptr<OHOS::NWeb::NWebPreference> setting); 872 void UpdateForceDarkAccess(const bool& access); 873 void UpdateAudioResumeInterval(const int32_t& resumeInterval); 874 void UpdateAudioExclusive(const bool& audioExclusive); 875 void UpdateAudioSessionType(const WebAudioSessionType& audioSessionType); 876 void UpdateOverviewModeEnabled(const bool& isOverviewModeAccessEnabled); 877 void UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled); 878 void UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled); 879 void UpdateTextZoomRatio(const int32_t& textZoomRatioNum); 880 void UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled); 881 void UpdateWebDebuggingAccessAndPort(bool enabled, int32_t port); 882 void UpdatePinchSmoothModeEnabled(bool isPinchSmoothModeEnabled); 883 void UpdateMediaPlayGestureAccess(bool isNeedGestureAccess); 884 void UpdateMultiWindowAccess(bool isMultiWindowAccessEnabled); 885 void UpdateAllowWindowOpenMethod(bool isAllowWindowOpenMethod); 886 void UpdateWebCursiveFont(const std::string& cursiveFontFamily); 887 void UpdateWebFantasyFont(const std::string& fantasyFontFamily); 888 void UpdateWebFixedFont(const std::string& fixedFontFamily); 889 void UpdateWebSansSerifFont(const std::string& sansSerifFontFamily); 890 void UpdateWebSerifFont(const std::string& serifFontFamily); 891 void UpdateWebStandardFont(const std::string& standardFontFamily); 892 void UpdateDefaultFixedFontSize(int32_t size); 893 void UpdateDefaultFontSize(int32_t defaultFontSize); 894 void UpdateDefaultTextEncodingFormat(const std::string& textEncodingFormat); 895 void UpdateMinFontSize(int32_t minFontSize); 896 void UpdateMinLogicalFontSize(int32_t minLogicalFontSize); 897 void UpdateBlockNetwork(bool isNetworkBlocked); 898 void UpdateHorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled); 899 void UpdateVerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled); 900 void UpdateOverlayScrollbarEnabled(bool isEnabled); 901 void UpdateScrollBarColor(const std::string& colorValue); 902 void UpdateOverScrollMode(const int32_t overscrollModeValue); 903 void UpdateBlurOnKeyboardHideMode(const int32_t isBlurOnKeyboardHideEnable); 904 void UpdateNativeEmbedModeEnabled(bool isEmbedModeEnabled); 905 void UpdateIntrinsicSizeEnabled(bool isIntrinsicSizeEnabled); 906 void UpdateCssDisplayChangeEnabled(bool isCssDisplayChangeEnabled); 907 void UpdateBypassVsyncCondition(const WebBypassVsyncCondition& condition); 908 void UpdateGestureFocusMode(const GestureFocusMode& mode); 909 void UpdateNativeEmbedRuleTag(const std::string& tag); 910 void UpdateNativeEmbedRuleType(const std::string& type); 911 void UpdateCopyOptionMode(const int32_t copyOptionModeValue); 912 void UpdateTextAutosizing(bool isTextAutosizing); 913 void UpdateMetaViewport(bool isMetaViewportEnabled); 914 void UpdateNativeVideoPlayerConfig(bool enable, bool shouldOverlay); 915 void UpdateEnableFollowSystemFontWeight(bool enableFollowSystemFontWeight); 916 void LoadUrl(); 917 void CreateWebMessagePorts(std::vector<RefPtr<WebMessagePort>>& ports); 918 void PostWebMessage(std::string& message, std::vector<RefPtr<WebMessagePort>>& ports, std::string& uri); 919 void ClosePort(std::string& handle); 920 void PostPortMessage(std::string& handle, std::string& data); 921 void SetPortMessageCallback(std::string& handle, std::function<void(const std::string&)>&& callback); 922 void HandleTouchDown(const int32_t& id, const double& x, const double& y, bool from_overlay = false); 923 void HandleTouchUp(const int32_t& id, const double& x, const double& y, bool from_overlay = false); 924 void HandleTouchMove(const int32_t& id, const double& x, const double& y, bool from_overlay = false); 925 void HandleTouchMove(const std::vector<std::shared_ptr<OHOS::NWeb::NWebTouchPointInfo>> &touch_point_infos, 926 bool fromOverlay = false); 927 void HandleTouchCancel(); 928 void HandleTouchpadFlingEvent(const double& x, const double& y, const double& vx, const double& vy); 929 void WebHandleTouchpadFlingEvent(const double& x, const double& y, 930 const double& vx, const double& vy, const std::vector<int32_t>& pressedCodes); 931 void HandleAxisEvent(const double& x, const double& y, const double& deltaX, const double& deltaY); 932 void WebHandleAxisEvent(const double& x, const double& y, 933 const double& deltaX, const double& deltaY, const std::vector<int32_t>& pressedCodes, const int32_t source); 934 bool OnKeyEvent(int32_t keyCode, int32_t keyAction); 935 bool WebOnKeyEvent(int32_t keyCode, int32_t keyAction, const std::vector<int32_t>& pressedCodes); 936 bool SendKeyboardEvent(const std::shared_ptr<OHOS::NWeb::NWebKeyboardEvent>& keyboardEvent); 937 void OnMouseEvent(int32_t x, int32_t y, const MouseButton button, const MouseAction action, int count); 938 void WebOnMouseEvent(const std::shared_ptr<OHOS::NWeb::NWebMouseEvent>& mouseEvent); 939 void OnFocus(const OHOS::NWeb::FocusReason& reason = OHOS::NWeb::FocusReason::EVENT_REQUEST); 940 bool NeedSoftKeyboard(); 941 void OnBlur(); 942 void OnPermissionRequestPrompt(const std::shared_ptr<OHOS::NWeb::NWebAccessRequest>& request); 943 void OnScreenCaptureRequest(const std::shared_ptr<OHOS::NWeb::NWebScreenCaptureAccessRequest>& request); 944 void UpdateClippedSelectionBounds(int32_t x, int32_t y, int32_t w, int32_t h); 945 bool RunQuickMenu(std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 946 std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback); 947 void OnQuickMenuDismissed(); 948 void HideHandleAndQuickMenuIfNecessary(bool hide); 949 void ChangeVisibilityOfQuickMenu(); 950 bool ChangeVisibilityOfQuickMenuV2(); 951 void OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle, 952 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle, 953 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle); 954 void HandleDragEvent(int32_t x, int32_t y, const DragAction& dragAction); 955 RefPtr<PixelMap> GetDragPixelMap(); 956 std::string GetUrl(); 957 void UpdateLocale(); 958 void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height); 959 void ReleaseResizeHold(); 960 bool GetPendingSizeStatus(); 961 void OnInactive(); 962 void OnActive(); 963 void GestureBackBlur(); 964 void OnWebviewHide(); 965 void OnWebviewShow(); 966 bool OnCursorChange(const OHOS::NWeb::CursorType& type, std::shared_ptr<OHOS::NWeb::NWebCursorInfo> info); 967 void OnSelectPopupMenu( 968 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params, 969 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback); 970 void SetShouldFrameSubmissionBeforeDraw(bool should); SetBackgroundColor(int32_t backgroundColor)971 void SetBackgroundColor(int32_t backgroundColor) 972 { 973 backgroundColor_ = backgroundColor; 974 } 975 void NotifyMemoryLevel(int32_t level); 976 void SetAudioMuted(bool muted); SetRichtextIdentifier(std::optional<std::string> & richtextData)977 void SetRichtextIdentifier(std::optional<std::string>& richtextData) 978 { 979 richtextData_ = richtextData; 980 } 981 void HandleAccessibilityHoverEvent( 982 const NG::PointF& point, SourceType source, NG::AccessibilityHoverEventType eventType, TimeStamp time); 983 void NotifyAutoFillViewData(const std::string& jsonStr); 984 void AutofillCancel(const std::string& fillContent); 985 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson); 986 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebHapValue>& viewDataJson); 987 void UpdateOptimizeParserBudgetEnabled(const bool enable); 988 #endif 989 void OnErrorReceive(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request, 990 std::shared_ptr<OHOS::NWeb::NWebUrlResourceError> error); 991 void OnHttpErrorReceive(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request, 992 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response); 993 RefPtr<WebResponse> OnInterceptRequest(const std::shared_ptr<BaseEventInfo>& info); 994 std::string OnOverrideErrorPage( 995 std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> webResourceRequest, 996 std::shared_ptr<OHOS::NWeb::NWebUrlResourceError> error); 997 bool IsEmptyOnInterceptRequest(); 998 void ReportDynamicFrameLossEvent(const std::string& sceneId, bool isStart); 999 void RecordWebEvent(Recorder::EventType eventType, const std::string& param) const; 1000 void OnPageStarted(const std::string& param); 1001 void OnPageFinished(const std::string& param); 1002 void SetPageFinishedState(const bool& state); 1003 bool GetPageFinishedState(); 1004 void OnProgressChanged(int param); 1005 void OnReceivedTitle(const std::string& title, bool isRealTitle = false); 1006 void ExitFullScreen(); 1007 void OnFullScreenExit(); 1008 void OnGeolocationPermissionsHidePrompt(); 1009 void OnGeolocationPermissionsShowPrompt( 1010 const std::string& origin, const std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface>& callback); 1011 void OnCompleteSwapWithNewSize(); 1012 void OnResizeNotWork(); 1013 void OnDateTimeChooserPopup( 1014 std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser, 1015 const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions, 1016 std::shared_ptr<OHOS::NWeb::NWebDateTimeChooserCallback> callback); 1017 void OnDateTimeChooserClose(); 1018 void OnRequestFocus(); 1019 bool OnCommonDialog(const std::shared_ptr<BaseEventInfo>& info, DialogEventType dialogEventType); 1020 bool OnHttpAuthRequest(const std::shared_ptr<BaseEventInfo>& info); 1021 bool OnSslErrorRequest(const std::shared_ptr<BaseEventInfo>& info); 1022 bool OnAllSslErrorRequest(const std::shared_ptr<BaseEventInfo>& info); 1023 bool OnSslSelectCertRequest(const std::shared_ptr<BaseEventInfo>& info); 1024 void OnDownloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, 1025 const std::string& mimetype, long contentLength); 1026 void OnAccessibilityEvent(int64_t accessibilityId, AccessibilityEventType eventType, const std::string& argument); 1027 void OnPageError(const std::string& param); 1028 void OnMessage(const std::string& param); 1029 void OnFullScreenEnter(std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler, int videoNaturalWidth, 1030 int videoNaturalHeight); 1031 bool OnConsoleLog(std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message); 1032 void OnRouterPush(const std::string& param); 1033 void OnRenderExited(OHOS::NWeb::RenderExitReason reason); 1034 void OnRefreshAccessedHistory(const std::string& url, bool isRefreshed); 1035 bool OnFileSelectorShow(const std::shared_ptr<BaseEventInfo>& info); 1036 bool OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info); 1037 void OnContextMenuHide(const std::string& info); 1038 bool OnHandleInterceptUrlLoading(const std::string& url); 1039 bool OnHandleInterceptLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request); 1040 void OnResourceLoad(const std::string& url); 1041 void OnScaleChange(float oldScaleFactor, float newScaleFactor); 1042 void OnScroll(double xOffset, double yOffset); 1043 bool LoadDataWithRichText(); 1044 void OnSearchResultReceive(int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting); 1045 bool OnDragAndDropData(const void* data, size_t len, int width, int height); 1046 bool OnDragAndDropDataUdmf(std::shared_ptr<OHOS::NWeb::NWebDragData> dragData); 1047 void OnTooltip(const std::string& tooltip); 1048 void OnPopupSize(int32_t x, int32_t y, int32_t width, int32_t height); 1049 void OnPopupShow(bool show); 1050 void OnShowAutofillPopup(const float offsetX, const float offsetY, const std::vector<std::string>& menu_items); 1051 void OnShowAutofillPopupV2(const float offsetX, const float offsetY, const float height, const float width, 1052 const std::vector<std::string>& menu_items); 1053 void SuggestionSelected(int32_t index); 1054 void OnHideAutofillPopup(); 1055 std::shared_ptr<OHOS::NWeb::NWebDragData> GetOrCreateDragData(); 1056 bool IsDragging(); 1057 bool IsImageDrag(); 1058 std::shared_ptr<OHOS::NWeb::NWebDragData> dragData_ = nullptr; 1059 std::string tempDir_; UpdateDragCursor(NWeb::NWebDragData::DragOperation op)1060 void UpdateDragCursor(NWeb::NWebDragData::DragOperation op) 1061 { 1062 op_ = op; 1063 } GetDragAcceptableStatus()1064 NWeb::NWebDragData::DragOperation GetDragAcceptableStatus() 1065 { 1066 return op_; 1067 } 1068 NWeb::NWebDragData::DragOperation op_ = NWeb::NWebDragData::DragOperation::DRAG_OPERATION_NONE; 1069 void OnWindowNew(const std::string& targetUrl, bool isAlert, bool isUserTrigger, 1070 const std::shared_ptr<OHOS::NWeb::NWebControllerHandler>& handler); 1071 void OnActivateContent(); 1072 void OnWindowExit(); 1073 void OnPageVisible(const std::string& url); 1074 void OnDataResubmitted(std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler); 1075 void OnNavigationEntryCommitted(std::shared_ptr<OHOS::NWeb::NWebLoadCommittedDetails> details); 1076 void OnFaviconReceived(const void* data, size_t width, size_t height, OHOS::NWeb::ImageColorType colorType, 1077 OHOS::NWeb::ImageAlphaType alphaType); 1078 void OnTouchIconUrl(const std::string& iconUrl, bool precomposed); 1079 void OnAudioStateChanged(bool audible); 1080 void OnFirstContentfulPaint(int64_t navigationStartTick, int64_t firstContentfulPaintMs); 1081 void OnFirstMeaningfulPaint(std::shared_ptr<OHOS::NWeb::NWebFirstMeaningfulPaintDetails> details); 1082 void OnLargestContentfulPaint(std::shared_ptr<OHOS::NWeb::NWebLargestContentfulPaintDetails> details); 1083 void OnSafeBrowsingCheckResult(int threat_type); 1084 void OnGetTouchHandleHotZone(std::shared_ptr<OHOS::NWeb::NWebTouchHandleHotZone> hotZone); 1085 void OnOverScroll(float xOffset, float yOffset); 1086 void OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling); 1087 void OnScrollState(bool scrollState); 1088 void OnScrollStart(const float x, const float y); 1089 void EnableSecurityLayer(bool isNeedSecurityLayer); 1090 void OnRootLayerChanged(int width, int height); 1091 bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity); 1092 void OnNativeEmbedAllDestory(); 1093 std::string GetSurfaceIdByHtmlElementId(const std::string& htmlElementId); 1094 std::string GetHtmlElementIdBySurfaceId(const std::string& surfaceId); 1095 int64_t GetWebAccessibilityIdBySurfaceId(const std::string& surfaceId); 1096 void OnNativeEmbedLifecycleChange(std::shared_ptr<NWeb::NWebNativeEmbedDataInfo> dataInfo); 1097 void OnNativeEmbedVisibilityChange(const std::string& embedId, bool visibility); 1098 void OnNativeEmbedGestureEvent(std::shared_ptr<NWeb::NWebNativeEmbedTouchEvent> event); 1099 void OnNativeEmbedMouseEvent(std::shared_ptr<NWeb::NWebNativeEmbedMouseEvent> event); 1100 void SetNGWebPattern(const RefPtr<NG::WebPattern>& webPattern); 1101 bool RequestFocus(OHOS::NWeb::NWebFocusSource source = OHOS::NWeb::NWebFocusSource::FOCUS_SOURCE_DEFAULT); 1102 bool IsCurrentFocus(); 1103 void SetDrawSize(const Size& drawSize); 1104 void SetEnhanceSurfaceFlag(const bool& isEnhanceSurface); 1105 EGLConfig GLGetConfig(int version, EGLDisplay eglDisplay); 1106 void GLContextInit(void* window); 1107 sptr<OHOS::SurfaceDelegate> GetSurfaceDelegateClient(); 1108 void SetBoundsOrResize(const Size& drawSize, const Offset& offset, bool isKeyboard = false); 1109 void ResizeVisibleViewport(const Size& visibleSize, bool isKeyboard = false); 1110 Offset GetWebRenderGlobalPos(); 1111 bool InitWebSurfaceDelegate(const WeakPtr<PipelineBase>& context); 1112 int GetWebId(); 1113 void JavaScriptOnDocumentStart(); 1114 void JavaScriptOnDocumentEnd(); 1115 void SetJavaScriptItems(const ScriptItems& scriptItems, const ScriptItemType& type); 1116 void JavaScriptOnDocumentStartByOrder(); 1117 void JavaScriptOnDocumentEndByOrder(); 1118 void JavaScriptOnHeadReadyByOrder(); 1119 void SetJavaScriptItemsByOrder(const ScriptItems& scriptItems, const ScriptItemType& type, 1120 const ScriptItemsByOrder& scriptItemsByOrder); 1121 void SetTouchEventInfo(std::shared_ptr<OHOS::NWeb::NWebNativeEmbedTouchEvent> touchEvent, 1122 TouchEventInfo& touchEventInfo); 1123 MouseInfo TransToMouseInfo(const std::shared_ptr<OHOS::NWeb::NWebNativeEmbedMouseEvent>& mouseEvent); 1124 bool SetTouchEventInfoFromMouse(const MouseInfo &mouseInfo, TouchEventInfo &touchEventInfo); 1125 bool GetIsSmoothDragResizeEnabled(); 1126 void DragResize(const double& width, const double& height, const double& pre_height, const double& pre_width); 1127 void SetDragResizeStartFlag(bool isDragResizeStart); 1128 void SetDragResizePreSize(const double& pre_height, const double& pre_width); 1129 std::string SpanstringConvertHtml(const std::vector<uint8_t> &content); 1130 bool CloseImageOverlaySelection(); 1131 void GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight); 1132 void RestoreRenderFit(); 1133 bool OnNestedScroll(float& x, float& y, float& xVelocity, float& yVelocity, bool& isAvailable); 1134 #if defined(ENABLE_ROSEN_BACKEND) 1135 void SetSurface(const sptr<Surface>& surface); 1136 void SetPopupSurface(const RefPtr<NG::RenderSurface>& popupSurface); 1137 sptr<Surface> surface_ = nullptr; 1138 sptr<Surface> popupSurface_ = nullptr; 1139 RefPtr<NG::RosenRenderSurface> renderSurface_ = nullptr; 1140 RefPtr<NG::RosenRenderSurface> popupRenderSurface_ = nullptr; 1141 #endif 1142 #ifdef OHOS_STANDARD_SYSTEM SetWebRendeGlobalPos(const Offset & pos)1143 void SetWebRendeGlobalPos(const Offset& pos) 1144 { 1145 offset_ = pos; 1146 } SetBlurReason(const OHOS::NWeb::BlurReason & blurReason)1147 void SetBlurReason(const OHOS::NWeb::BlurReason& blurReason) 1148 { 1149 blurReason_ = blurReason; 1150 } SetPopup(bool popup)1151 void SetPopup(bool popup) 1152 { 1153 isPopup_ = popup; 1154 } SetParentNWebId(int32_t parentNWebId)1155 void SetParentNWebId(int32_t parentNWebId) 1156 { 1157 parentNWebId_ = parentNWebId; 1158 } 1159 #endif 1160 void SetToken(); 1161 void SetRenderMode(RenderMode renderMode); 1162 void SetFitContentMode(WebLayoutMode layoutMode); 1163 void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard); 1164 bool ShouldVirtualKeyboardOverlay(); 1165 void ScrollBy(float deltaX, float deltaY); 1166 void ScrollByRefScreen(float deltaX, float deltaY, float vx = 0, float vy = 0); 1167 bool ExecuteAction(int64_t accessibilityId, AceAction action, 1168 const std::map<std::string, std::string>& actionArguments); 1169 bool GetAccessibilityNodeRectById( 1170 int64_t accessibilityId, int32_t* width, int32_t* height, int32_t* offsetX, int32_t* offsetY); 1171 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetFocusedAccessibilityNodeInfo( 1172 int64_t accessibilityId, bool isAccessibilityFocus); 1173 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeInfoById(int64_t accessibilityId); 1174 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeInfoByFocusMove( 1175 int64_t accessibilityId, int32_t direction); 1176 void SetAccessibilityState(bool state, bool isDelayed); 1177 void UpdateAccessibilityState(bool state); 1178 OHOS::NWeb::NWebPreference::CopyOptionMode GetCopyOptionMode() const; 1179 void OnIntelligentTrackingPreventionResult( 1180 const std::string& websiteHost, const std::string& trackerHost); 1181 bool OnHandleOverrideLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request); 1182 void ScaleGestureChange(double scale, double centerX, double centerY); 1183 void ScaleGestureChangeV2(int type, double scale, double originScale, double centerX, double centerY); 1184 std::vector<int8_t> GetWordSelection(const std::string& text, int8_t offset); 1185 // Backward 1186 void Backward(); 1187 bool AccessBackward(); 1188 bool OnOpenAppLink(const std::string& url, std::shared_ptr<OHOS::NWeb::NWebAppLinkCallback> callback); 1189 bool OnSetFaviconCallback(std::shared_ptr<FaviconReceivedEvent> param); 1190 1191 void OnRenderProcessNotResponding( 1192 const std::string& jsStack, int pid, OHOS::NWeb::RenderProcessNotRespondingReason reason); 1193 void OnRenderProcessResponding(); 1194 std::string GetSelectInfo() const; 1195 Offset GetPosition(const std::string& embedId); 1196 1197 void OnOnlineRenderToForeground(); 1198 void NotifyForNextTouchEvent(); 1199 1200 std::string GetAllTextInfo() const; 1201 int GetSelectStartIndex() const; 1202 int GetSelectEndIndex() const; 1203 1204 void OnViewportFitChange(OHOS::NWeb::ViewportFit viewportFit); 1205 void OnAreaChange(const OHOS::Ace::Rect& area); 1206 void OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea avoidArea, OHOS::Rosen::AvoidAreaType type); 1207 std::string GetWebInfoType(); 1208 void OnInterceptKeyboardAttach( 1209 const std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler, 1210 const std::map<std::string, std::string> &attributes, bool &useSystemKeyboard, int32_t &enterKeyType); 1211 1212 void OnCustomKeyboardAttach(); 1213 1214 void OnCustomKeyboardClose(); 1215 1216 void CreateOverlay(void* data, size_t len, int width, int height, int offsetX, int offsetY, int rectWidth, 1217 int rectHeight, int pointX, int pointY); 1218 1219 void OnOverlayStateChanged(int offsetX, int offsetY, int rectWidth, int rectHeight); 1220 1221 void OnTextSelected(); 1222 void OnDestroyImageAnalyzerOverlay(); 1223 1224 void OnAttachContext(const RefPtr<NG::PipelineContext> &context); 1225 void OnDetachContext(); 1226 GetInstanceId()1227 int32_t GetInstanceId() const 1228 { 1229 return instanceId_; 1230 } 1231 1232 void OnAdsBlocked(const std::string& url, const std::vector<std::string>& adsBlocked); 1233 void SetSurfaceId(const std::string& surfaceId); 1234 1235 void KeyboardReDispatch(const std::shared_ptr<OHOS::NWeb::NWebKeyEvent>& event, bool isUsed); 1236 1237 void OnTakeFocus(const std::shared_ptr<OHOS::NWeb::NWebKeyEvent>& event); 1238 1239 void OnCursorUpdate(double x, double y, double width, double height); 1240 CloseCustomKeyboard()1241 void CloseCustomKeyboard() 1242 { 1243 if (keyboardHandler_) { 1244 keyboardHandler_->Close(); 1245 } 1246 } 1247 1248 bool SetFocusByPosition(float x, float y); 1249 1250 void StartVibraFeedback(const std::string& vibratorType); 1251 GetTaskExecutor()1252 RefPtr<TaskExecutor> GetTaskExecutor() const 1253 { 1254 return taskExecutor_; 1255 } 1256 1257 bool GetAccessibilityVisible(int64_t accessibilityId); 1258 1259 void SetTransformHint(uint32_t rotation); 1260 1261 void MaximizeResize(); 1262 1263 void ExecuteTypeScript(const std::string& jscode, const std::function<void(std::string)>&& callback); 1264 1265 void RegisterNativeArkJSFunction(const std::string& objName, 1266 const std::vector<std::pair<std::string, NativeMethodCallback>>& methodList, bool isNeedRefresh); 1267 1268 void UnRegisterNativeArkJSFunction(const std::string& objName); 1269 1270 bool IsActivePolicyDisable(); 1271 1272 OHOS::NWeb::WebDestroyMode GetWebDestroyMode(); 1273 1274 void UpdateWebMediaAVSessionEnabled(bool isEnabled); 1275 1276 std::string GetCurrentLanguage(); 1277 void RegisterNativeJavaScriptProxy(const std::string& obj, const std::vector<std::string>& method, 1278 std::vector<std::function<void(const std::vector<std::string>&)>> callbackImpl, 1279 bool isAync, const std::string& permission, bool isNeedRefresh); 1280 1281 void RegisterWebWindowFocusChangedListener(); 1282 1283 void UnRegisterWebWindowFocusChangedListener(); 1284 1285 void OnDragAttach(); 1286 1287 bool IsNWebEx(); 1288 1289 void SetNativeInnerWeb(bool isInnerWeb); 1290 1291 void ResetStateOfDataDetectorJS(); 1292 void RunDataDetectorJS(); 1293 void SetDataDetectorEnable(bool enable); 1294 void OnDataDetectorSelectText(); 1295 void OnDataDetectorCopy(const std::vector<std::string>& recordMix); 1296 int GetLastHitTestResult(); 1297 int GetHitTestResult(); 1298 1299 void RemoveSnapshotFrameNode(int removeDelayTime); 1300 void CreateSnapshotFrameNode(const std::string& snapshotPath); 1301 void SetVisibility(bool isVisible); 1302 1303 void OnPip(int status, int delegate_id, int child_id, int frame_routing_id, int width, int height); 1304 void SetPipNativeWindow(int delegate_id, int child_id, int frame_routing_id, void* window); 1305 void SendPipEvent(int delegate_id, int child_id, int frame_routing_id, int event); 1306 void OnLoadStarted(const std::string& param); 1307 void OnLoadFinished(const std::string& param); SetIsFileSelectorShow(bool isFileSelectorShow)1308 void SetIsFileSelectorShow(bool isFileSelectorShow) { isFileSelectorShow_ = isFileSelectorShow; } IsFileSelectorShow()1309 bool IsFileSelectorShow() { return isFileSelectorShow_; } 1310 1311 1312 bool ShowMagnifier(); 1313 bool HideMagnifier(); 1314 void UpdateSingleHandleVisible(bool isVisible); 1315 void SetTouchHandleExistState(bool touchHandleExist); 1316 1317 void SetBorderRadiusFromWeb(double borderRadiusTopLeft, double borderRadiusTopRight, double borderRadiusBottomLeft, 1318 double borderRadiusBottomRight); 1319 1320 void SetViewportScaleState(); 1321 1322 void OnPdfScrollAtBottom(const std::string& url); 1323 void OnPdfLoadEvent(int32_t result, const std::string& url); 1324 HasOnNativeEmbedGestureEventV2()1325 bool HasOnNativeEmbedGestureEventV2() 1326 { 1327 #ifdef OHOS_STANDARD_SYSTEM 1328 return static_cast<bool>(OnNativeEmbedGestureEventV2_); 1329 #else 1330 return false; 1331 #endif 1332 } 1333 private: 1334 void InitWebEvent(); 1335 void RegisterWebEvent(); 1336 void ReleasePlatformResource(); 1337 void Stop(); 1338 void UnregisterEvent(); 1339 std::string GetUrlStringParam(const std::string& param, const std::string& name) const; 1340 void CallWebRouterBack(); 1341 void CallPopPageSuccessPageUrl(const std::string& url); 1342 void CallIsPagePathInvalid(const bool& isPageInvalid); 1343 1344 void BindRouterBackMethod(); 1345 void BindPopPageSuccessMethod(); 1346 void BindIsPagePathInvalidMethod(); 1347 void WebComponentClickReport(int64_t accessibilityId); 1348 void AccessibilityReleasePageEvent(); 1349 void AccessibilitySendPageChange(); 1350 1351 #ifdef OHOS_STANDARD_SYSTEM 1352 sptr<OHOS::Rosen::Window> CreateWindow(); 1353 void LoadUrl(const std::string& url, const std::map<std::string, std::string>& httpHeaders); 1354 void LoadDataWithBaseUrl(const std::string& baseUrl, const std::string& data, const std::string& mimeType, 1355 const std::string& encoding, const std::string& historyUrl); 1356 void Refresh(); 1357 void StopLoading(); 1358 void AddJavascriptInterface(const std::string& objectName, const std::vector<std::string>& methodList); 1359 void RemoveJavascriptInterface(const std::string& objectName, const std::vector<std::string>& methodList); 1360 void SetWebViewJavaScriptResultCallBack(const WebController::JavaScriptCallBackImpl&& javaScriptCallBackImpl); 1361 void Zoom(float factor); 1362 bool ZoomIn(); 1363 bool ZoomOut(); 1364 int ConverToWebHitTestType(int hitType); 1365 void GetHitTestValue(HitTestResult& result); 1366 int GetProgress(); 1367 int GetPageHeight(); 1368 std::string GetTitle(); 1369 std::string GetDefaultUserAgent(); 1370 bool SaveCookieSync(); 1371 bool SetCookie(const std::string& url, 1372 const std::string& value, 1373 bool incognito_mode); 1374 std::string GetCookie(const std::string& url, bool incognito_mode) const; 1375 void DeleteEntirelyCookie(bool incognito_mode); 1376 void RegisterOHOSWebEventAndMethord(); 1377 void SetWebCallBack(); 1378 void RunSetWebIdAndHapPathCallback(); 1379 void RunJsProxyCallback(); 1380 void RegisterConfigObserver(); 1381 void UnRegisterConfigObserver(); 1382 1383 // forward 1384 void Forward(); 1385 void ClearHistory(); 1386 void ClearSslCache(); 1387 void ClearClientAuthenticationCache(); 1388 bool AccessStep(int32_t step); 1389 void BackOrForward(int32_t step); 1390 bool AccessForward(); 1391 1392 void SearchAllAsync(const std::string& searchStr); 1393 void ClearMatches(); 1394 void SearchNext(bool forward); 1395 1396 void UpdateSettting(bool useNewPipe = false); 1397 1398 std::string GetCustomScheme(); 1399 void InitWebViewWithSurface(); 1400 Size GetEnhanceSurfaceSize(const Size& drawSize); 1401 void UpdateScreenOffSet(double& offsetX, double& offsetY); 1402 void RegisterSurfacePositionChangedCallback(); 1403 void UnregisterSurfacePositionChangedCallback(); 1404 1405 void NotifyPopupWindowResult(bool result); 1406 1407 EventCallbackV2 GetAudioStateChangedCallback(bool useNewPipe, const RefPtr<NG::WebEventHub>& eventHub); 1408 void SurfaceOcclusionCallback(float visibleRatio); 1409 void RegisterSurfaceOcclusionChangeFun(); 1410 void SetPartitionPoints(std::vector<float>& partition); 1411 void ratioStrToFloat(const std::string& str); 1412 void ratioStrToFloatV2(const std::string& str); 1413 // Return canonical encoding name according to the encoding alias name. 1414 std::string GetCanonicalEncodingName(const std::string& alias_name) const; 1415 void RegisterAvoidAreaChangeListener(int32_t instanceId); 1416 void UnregisterAvoidAreaChangeListener(int32_t instanceId); 1417 NG::SafeAreaInsets GetCombinedSafeArea(); 1418 void OnSafeInsetsChange(); 1419 void EnableHardware(); 1420 void HandleNativeMouseEvent(const std::shared_ptr<OHOS::NWeb::NWebMouseEventResult>& result, 1421 const MouseInfo& mouseInfo, std::string embedId, const RefPtr<WebDelegate>& delegate); 1422 void HandleNativeMouseToTouch(const std::shared_ptr<OHOS::NWeb::NWebMouseEventResult>& result, 1423 const MouseInfo& mouseInfo, std::string embedId, const RefPtr<WebDelegate>& delegate); 1424 #endif 1425 1426 WeakPtr<WebComponent> webComponent_; 1427 WeakPtr<RenderWeb> renderWeb_; 1428 1429 WeakPtr<NG::WebPattern> webPattern_; 1430 1431 std::list<CreatedCallback> createdCallbacks_; 1432 std::list<ReleasedCallback> releasedCallbacks_; 1433 EventCallback onPageStarted_; 1434 EventCallback onPageFinished_; 1435 EventCallback onPageError_; 1436 EventCallback onMessage_; 1437 EventCallback onLoadStarted_; 1438 EventCallback onLoadFinished_; 1439 Method reloadMethod_; 1440 Method updateUrlMethod_; 1441 Method routerBackMethod_; 1442 Method changePageUrlMethod_; 1443 Method isPagePathInvalidMethod_; 1444 State state_ { State::WAITINGFORSIZE }; 1445 bool isPageFinished_ = false; 1446 #ifdef OHOS_STANDARD_SYSTEM 1447 std::shared_ptr<OHOS::NWeb::NWeb> nweb_; 1448 std::shared_ptr<OHOS::NWeb::NWebCookieManager> cookieManager_ = nullptr; 1449 sptr<Rosen::Window> window_; 1450 bool isCreateWebView_ = false; 1451 int32_t callbackId_ = 0; 1452 1453 EventCallbackV2 onPageFinishedV2_; 1454 EventCallbackV2 onPageStartedV2_; 1455 EventCallbackV2 onProgressChangeV2_; 1456 EventCallbackV2 onTitleReceiveV2_; 1457 EventCallbackV2 onFullScreenExitV2_; 1458 EventCallbackV2 onGeolocationHideV2_; 1459 EventCallbackV2 onGeolocationShowV2_; 1460 EventCallbackV2 onRequestFocusV2_; 1461 EventCallbackV2 onErrorReceiveV2_; 1462 EventCallbackV2 onHttpErrorReceiveV2_; 1463 EventCallbackV2 onDownloadStartV2_; 1464 EventCallbackV2 onRefreshAccessedHistoryV2_; 1465 EventCallbackV2 onRenderExitedV2_; 1466 EventCallbackV2 onResourceLoadV2_; 1467 EventCallbackV2 onScaleChangeV2_; 1468 EventCallbackV2 onScrollV2_; 1469 EventCallbackV2 onPermissionRequestV2_; 1470 EventCallbackV2 onSearchResultReceiveV2_; 1471 EventCallbackV2 onActivateContentV2_; 1472 EventCallbackV2 onWindowExitV2_; 1473 EventCallbackV2 onPageVisibleV2_; 1474 EventCallbackV2 onTouchIconUrlV2_; 1475 EventCallbackV2 onAudioStateChangedV2_; 1476 EventCallbackV2 onFirstContentfulPaintV2_; 1477 EventCallbackV2 OnFirstMeaningfulPaintV2_; 1478 EventCallbackV2 OnLargestContentfulPaintV2_; 1479 EventCallbackV2 onOverScrollV2_; 1480 EventCallbackV2 onScreenCaptureRequestV2_; 1481 EventCallbackV2 onNavigationEntryCommittedV2_; 1482 EventCallbackV2 onSafeBrowsingCheckResultV2_; 1483 EventCallbackV2 OnNativeEmbedAllDestoryV2_; 1484 EventCallbackV2 OnNativeEmbedLifecycleChangeV2_; 1485 EventCallbackV2 OnNativeEmbedVisibilityChangeV2_; 1486 EventCallbackV2 OnNativeEmbedGestureEventV2_; 1487 EventCallbackV2 OnNativeEmbedMouseEventV2_; 1488 EventCallbackV2 onIntelligentTrackingPreventionResultV2_; 1489 EventCallbackV2 onRenderProcessNotRespondingV2_; 1490 EventCallbackV2 onRenderProcessRespondingV2_; 1491 EventCallbackV2 onViewportFitChangedV2_; 1492 std::function<WebKeyboardOption(const std::shared_ptr<BaseEventInfo>&)> onInterceptKeyboardAttachV2_; 1493 EventCallbackV2 onAdsBlockedV2_; 1494 EventCallbackV2 onLoadStartedV2_; 1495 EventCallbackV2 onLoadFinishedV2_; 1496 1497 int32_t renderMode_ = -1; 1498 int32_t layoutMode_ = -1; 1499 std::string bundlePath_; 1500 std::string bundleDataPath_; 1501 std::string hapPath_; 1502 RefPtr<PixelMap> pixelMap_ = nullptr; 1503 bool isRefreshPixelMap_ = false; 1504 Size drawSize_; 1505 Offset offset_; 1506 bool isEnhanceSurface_ = false; 1507 sptr<WebSurfaceCallback> surfaceCallback_; 1508 sptr<OHOS::SurfaceDelegate> surfaceDelegate_; 1509 EGLNativeWindowType mEglWindow = nullptr; 1510 EGLDisplay mEGLDisplay = EGL_NO_DISPLAY; 1511 EGLConfig mEGLConfig = nullptr; 1512 EGLContext mEGLContext = EGL_NO_CONTEXT; 1513 EGLContext mSharedEGLContext = EGL_NO_CONTEXT; 1514 EGLSurface mEGLSurface = nullptr; 1515 WindowsSurfaceInfo surfaceInfo_ = { nullptr, EGL_NO_DISPLAY, nullptr, EGL_NO_CONTEXT }; 1516 bool forceDarkMode_ = false; 1517 WebDarkMode current_dark_mode_ = WebDarkMode::Auto; 1518 std::shared_ptr<OHOS::AbilityRuntime::EnvironmentCallback> configChangeObserver_ = nullptr; 1519 OHOS::NWeb::BlurReason blurReason_ = OHOS::NWeb::BlurReason::FOCUS_SWITCH; 1520 bool isPopup_ = false; 1521 int32_t parentNWebId_ = -1; 1522 bool needResizeAtFirst_ = false; 1523 int32_t backgroundColor_ = 0xffffffff; 1524 uint32_t rosenWindowId_ = 0; 1525 RefPtr<WebDelegateObserver> observer_; 1526 std::shared_ptr<Rosen::RSNode> rsNode_; 1527 std::shared_ptr<Rosen::RSNode> surfaceRsNode_; 1528 Rosen::NodeId surfaceNodeId_ = 0; 1529 float visibleRatio_ = 1.0; 1530 uint32_t delayTime_ = 500; 1531 float lowerFrameRateVisibleRatio_ = 0.1; 1532 float halfFrameRateVisibleRatio_ = 0.3; 1533 bool isHalfFrame_ = false; 1534 std::optional<ScriptItems> onDocumentStartScriptItems_; 1535 std::optional<ScriptItems> onDocumentEndScriptItems_; 1536 std::optional<ScriptItems> onHeadReadyScriptItems_; 1537 std::optional<ScriptItemsByOrder> onDocumentStartScriptItemsByOrder_; 1538 std::optional<ScriptItemsByOrder> onDocumentEndScriptItemsByOrder_; 1539 std::optional<ScriptItemsByOrder> onHeadReadyScriptItemsByOrder_; 1540 bool accessibilityState_ = false; 1541 std::optional<std::string> richtextData_; 1542 bool incognitoMode_ = false; 1543 bool isEmbedModeEnabled_ = false; 1544 std::shared_mutex embedDataInfoMutex_; 1545 std::map<std::string, std::shared_ptr<OHOS::NWeb::NWebNativeEmbedDataInfo>> embedDataInfo_; 1546 std::string tag_; 1547 std::string tag_type_; 1548 double resizeWidth_ = 0.0; 1549 double resizeHeight_ = 0.0; 1550 double resizeVisibleWidth_ = -1.0; 1551 double resizeVisibleHeight_ = -1.0; 1552 OHOS::Ace::Rect currentArea_; 1553 NG::SafeAreaInsets systemSafeArea_; 1554 NG::SafeAreaInsets cutoutSafeArea_; 1555 NG::SafeAreaInsets navigationIndicatorSafeArea_; 1556 sptr<Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_ = nullptr; 1557 int32_t instanceId_; 1558 std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler_ = nullptr; 1559 sptr<WebWindowFocusChangedListener> webWindowFocusChangedListener_ = nullptr; 1560 std::string sharedRenderProcessToken_; 1561 int64_t lastFocusInputId_ = 0; 1562 int64_t lastFocusReportId_ = 0; 1563 RefPtr<TaskExecutor> taskExecutor_; 1564 bool isEnableHardwareComposition_ = false; 1565 bool isDragResizeStart_ = false; 1566 double dragResize_preHight_ = 0.0; 1567 double dragResize_preWidth_ = 0.0; 1568 bool enableFollowSystemFontWeight_ = false; 1569 1570 // data detector js state 1571 bool initDataDetectorJS_ = false; 1572 bool isFileSelectorShow_ = false; 1573 double density_ = 0.0; 1574 1575 bool isVisible_ = false; 1576 #endif 1577 }; 1578 1579 } // namespace OHOS::Ace 1580 1581 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_DELEGATE_H 1582