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