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)598 explicit WebAvoidAreaChangedListener(WeakPtr<WebDelegate> webDelegate) : webDelegate_(webDelegate) {} 599 ~WebAvoidAreaChangedListener() = default; 600 601 void OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea avoidArea, OHOS::Rosen::AvoidAreaType type) override; 602 private: 603 WeakPtr<WebDelegate> webDelegate_; 604 }; 605 606 enum class ScriptItemType { 607 DOCUMENT_START = 0, 608 DOCUMENT_END 609 }; 610 611 class NWebSystemConfigurationImpl : public OHOS::NWeb::NWebSystemConfiguration { 612 public: NWebSystemConfigurationImpl(uint8_t flags)613 explicit NWebSystemConfigurationImpl(uint8_t flags) : theme_flags_(flags) {} 614 ~NWebSystemConfigurationImpl() = default; 615 GetThemeFlags()616 uint8_t GetThemeFlags() override 617 { 618 return theme_flags_; 619 } 620 621 private: 622 uint8_t theme_flags_ = static_cast<uint8_t>(NWeb::SystemThemeFlags::NONE); 623 }; 624 625 class WebDelegate : public WebResource { 626 DECLARE_ACE_TYPE(WebDelegate, WebResource); 627 628 public: 629 using CreatedCallback = std::function<void()>; 630 using ReleasedCallback = std::function<void(bool)>; 631 using EventCallback = std::function<void(const std::string&)>; 632 using EventCallbackV2 = std::function<void(const std::shared_ptr<BaseEventInfo>&)>; 633 enum class State : char { 634 WAITINGFORSIZE, 635 CREATING, 636 CREATED, 637 CREATEFAILED, 638 RELEASED, 639 }; 640 641 // for webcontoller, the enum is same as web_webview and core side 642 enum class JavaScriptObjIdErrorCode : int32_t { WEBCONTROLLERERROR = -2, WEBVIEWCONTROLLERERROR = -1, END = 0 }; 643 644 WebDelegate() = delete; 645 ~WebDelegate() override; WebDelegate(const WeakPtr<PipelineBase> & context,ErrorCallback && onError,const std::string & type)646 WebDelegate(const WeakPtr<PipelineBase>& context, ErrorCallback&& onError, const std::string& type) 647 : WebResource(type, context, std::move(onError)), instanceId_(Container::CurrentId()) 648 {} WebDelegate(const WeakPtr<PipelineBase> & context,ErrorCallback && onError,const std::string & type,int32_t id)649 WebDelegate(const WeakPtr<PipelineBase>& context, ErrorCallback&& onError, const std::string& type, int32_t id) 650 : WebResource(type, context, std::move(onError)), instanceId_(id) 651 {} 652 653 void UnRegisterScreenLockFunction(); 654 SetObserver(const RefPtr<WebDelegateObserver> & observer)655 void SetObserver(const RefPtr<WebDelegateObserver>& observer) 656 { 657 observer_ = observer; 658 }; 659 void SetRenderWeb(const WeakPtr<RenderWeb>& renderWeb); 660 661 void CreatePlatformResource(const Size& size, const Offset& position, const WeakPtr<PipelineContext>& context); 662 void CreatePluginResource(const Size& size, const Offset& position, const WeakPtr<PipelineContext>& context); 663 void AddCreatedCallback(const CreatedCallback& createdCallback); 664 void RemoveCreatedCallback(); 665 void AddReleasedCallback(const ReleasedCallback& releasedCallback); 666 void SetComponent(const RefPtr<WebComponent>& component); 667 void RemoveReleasedCallback(); 668 void Reload(); 669 void UpdateUrl(const std::string& url); 670 #ifdef OHOS_STANDARD_SYSTEM 671 void InitOHOSWeb(const RefPtr<PipelineBase>& context, const RefPtr<NG::RenderSurface>& surface); 672 void InitOHOSWeb(const WeakPtr<PipelineBase>& context); 673 bool PrepareInitOHOSWeb(const WeakPtr<PipelineBase>& context); 674 void InitWebViewWithWindow(); 675 void ShowWebView(); 676 void HideWebView(); 677 void OnRenderToBackground(); 678 void OnRenderToForeground(); 679 void SetSurfaceDensity(const double& density); 680 void Resize(const double& width, const double& height, bool isKeyboard = false); GetRosenWindowId()681 int32_t GetRosenWindowId() 682 { 683 return rosenWindowId_; 684 } 685 void SetKeepScreenOn(bool key); 686 void UpdateUserAgent(const std::string& userAgent); 687 void UpdateBackgroundColor(const int backgroundColor); 688 void UpdateInitialScale(float scale); 689 void UpdateLayoutMode(WebLayoutMode mode); 690 void UpdateJavaScriptEnabled(const bool& isJsEnabled); 691 void UpdateAllowFileAccess(const bool& isFileAccessEnabled); 692 void UpdateBlockNetworkImage(const bool& onLineImageAccessEnabled); 693 void UpdateLoadsImagesAutomatically(const bool& isImageAccessEnabled); 694 void UpdateMixedContentMode(const MixedModeContent& mixedMode); 695 void UpdateSupportZoom(const bool& isZoomAccessEnabled); 696 void UpdateDomStorageEnabled(const bool& isDomStorageAccessEnabled); 697 void UpdateGeolocationEnabled(const bool& isGeolocationAccessEnabled); 698 void UpdateCacheMode(const WebCacheMode& mode); 699 std::shared_ptr<OHOS::NWeb::NWeb> GetNweb(); 700 bool GetForceDarkMode(); 701 void OnConfigurationUpdated(const OHOS::AppExecFwk::Configuration& configuration); 702 void UpdateDarkMode(const WebDarkMode& mode); 703 void UpdateDarkModeAuto(RefPtr<WebDelegate> delegate, std::shared_ptr<OHOS::NWeb::NWebPreference> setting); 704 void UpdateForceDarkAccess(const bool& access); 705 void UpdateAudioResumeInterval(const int32_t& resumeInterval); 706 void UpdateAudioExclusive(const bool& audioExclusive); 707 void UpdateOverviewModeEnabled(const bool& isOverviewModeAccessEnabled); 708 void UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled); 709 void UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled); 710 void UpdateTextZoomRatio(const int32_t& textZoomRatioNum); 711 void UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled); 712 void UpdatePinchSmoothModeEnabled(bool isPinchSmoothModeEnabled); 713 void UpdateMediaPlayGestureAccess(bool isNeedGestureAccess); 714 void UpdateMultiWindowAccess(bool isMultiWindowAccessEnabled); 715 void UpdateAllowWindowOpenMethod(bool isAllowWindowOpenMethod); 716 void UpdateWebCursiveFont(const std::string& cursiveFontFamily); 717 void UpdateWebFantasyFont(const std::string& fantasyFontFamily); 718 void UpdateWebFixedFont(const std::string& fixedFontFamily); 719 void UpdateWebSansSerifFont(const std::string& sansSerifFontFamily); 720 void UpdateWebSerifFont(const std::string& serifFontFamily); 721 void UpdateWebStandardFont(const std::string& standardFontFamily); 722 void UpdateDefaultFixedFontSize(int32_t size); 723 void UpdateDefaultFontSize(int32_t defaultFontSize); 724 void UpdateDefaultTextEncodingFormat(const std::string& textEncodingFormat); 725 void UpdateMinFontSize(int32_t minFontSize); 726 void UpdateMinLogicalFontSize(int32_t minLogicalFontSize); 727 void UpdateBlockNetwork(bool isNetworkBlocked); 728 void UpdateHorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled); 729 void UpdateVerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled); 730 void UpdateOverlayScrollbarEnabled(bool isEnabled); 731 void UpdateScrollBarColor(const std::string& colorValue); 732 void UpdateOverScrollMode(const int32_t overscrollModeValue); 733 void UpdateBlurOnKeyboardHideMode(const int32_t isBlurOnKeyboardHideEnable); 734 void UpdateNativeEmbedModeEnabled(bool isEmbedModeEnabled); 735 void UpdateNativeEmbedRuleTag(const std::string& tag); 736 void UpdateNativeEmbedRuleType(const std::string& type); 737 void UpdateCopyOptionMode(const int32_t copyOptionModeValue); 738 void UpdateTextAutosizing(bool isTextAutosizing); 739 void UpdateNativeVideoPlayerConfig(bool enable, bool shouldOverlay); 740 void UpdateMetaViewport(bool isMetaViewportEnabled); 741 void LoadUrl(); 742 void CreateWebMessagePorts(std::vector<RefPtr<WebMessagePort>>& ports); 743 void PostWebMessage(std::string& message, std::vector<RefPtr<WebMessagePort>>& ports, std::string& uri); 744 void ClosePort(std::string& handle); 745 void PostPortMessage(std::string& handle, std::string& data); 746 void SetPortMessageCallback(std::string& handle, std::function<void(const std::string&)>&& callback); 747 void HandleTouchDown(const int32_t& id, const double& x, const double& y, bool from_overlay = false); 748 void HandleTouchUp(const int32_t& id, const double& x, const double& y, bool from_overlay = false); 749 void HandleTouchMove(const int32_t& id, const double& x, const double& y, bool from_overlay = false); 750 void HandleTouchMove(const std::vector<std::shared_ptr<OHOS::NWeb::NWebTouchPointInfo>> &touch_point_infos, 751 bool fromOverlay = false); 752 void HandleTouchCancel(); 753 void HandleTouchpadFlingEvent(const double& x, const double& y, const double& vx, const double& vy); 754 void WebHandleTouchpadFlingEvent(const double& x, const double& y, 755 const double& vx, const double& vy, const std::vector<int32_t>& pressedCodes); 756 void HandleAxisEvent(const double& x, const double& y, const double& deltaX, const double& deltaY); 757 void WebHandleAxisEvent(const double& x, const double& y, 758 const double& deltaX, const double& deltaY, const std::vector<int32_t>& pressedCodes); 759 bool OnKeyEvent(int32_t keyCode, int32_t keyAction); 760 bool WebOnKeyEvent(int32_t keyCode, int32_t keyAction, const std::vector<int32_t>& pressedCodes); 761 void OnMouseEvent(int32_t x, int32_t y, const MouseButton button, const MouseAction action, int count); 762 void OnFocus(const OHOS::NWeb::FocusReason& reason = OHOS::NWeb::FocusReason::EVENT_REQUEST); 763 bool NeedSoftKeyboard(); 764 void OnBlur(); 765 void OnPermissionRequestPrompt(const std::shared_ptr<OHOS::NWeb::NWebAccessRequest>& request); 766 void OnScreenCaptureRequest(const std::shared_ptr<OHOS::NWeb::NWebScreenCaptureAccessRequest>& request); 767 void UpdateClippedSelectionBounds(int32_t x, int32_t y, int32_t w, int32_t h); 768 bool RunQuickMenu(std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 769 std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback); 770 void OnQuickMenuDismissed(); 771 void HideHandleAndQuickMenuIfNecessary(bool hide); 772 void ChangeVisibilityOfQuickMenu(); 773 void OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle, 774 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle, 775 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle); 776 void HandleDragEvent(int32_t x, int32_t y, const DragAction& dragAction); 777 RefPtr<PixelMap> GetDragPixelMap(); 778 std::string GetUrl(); 779 void UpdateLocale(); 780 void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height); 781 void ReleaseResizeHold(); 782 bool GetPendingSizeStatus(); 783 void OnInactive(); 784 void OnActive(); 785 void GestureBackBlur(); 786 void OnWebviewHide(); 787 void OnWebviewShow(); 788 bool OnCursorChange(const OHOS::NWeb::CursorType& type, std::shared_ptr<OHOS::NWeb::NWebCursorInfo> info); 789 void OnSelectPopupMenu( 790 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params, 791 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback); 792 void SetShouldFrameSubmissionBeforeDraw(bool should); SetBackgroundColor(int32_t backgroundColor)793 void SetBackgroundColor(int32_t backgroundColor) 794 { 795 backgroundColor_ = backgroundColor; 796 } 797 void NotifyMemoryLevel(int32_t level); 798 void SetAudioMuted(bool muted); SetRichtextIdentifier(std::optional<std::string> & richtextData)799 void SetRichtextIdentifier(std::optional<std::string>& richtextData) 800 { 801 richtextData_ = richtextData; 802 } 803 void NotifyAutoFillViewData(const std::string& jsonStr); 804 void AutofillCancel(const std::string& fillContent); 805 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson); 806 void HandleAccessibilityHoverEvent(int32_t x, int32_t y); 807 #endif 808 void OnErrorReceive(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request, 809 std::shared_ptr<OHOS::NWeb::NWebUrlResourceError> error); 810 void OnHttpErrorReceive(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request, 811 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response); 812 RefPtr<WebResponse> OnInterceptRequest(const std::shared_ptr<BaseEventInfo>& info); 813 bool IsEmptyOnInterceptRequest(); 814 void RecordWebEvent(Recorder::EventType eventType, const std::string& param) const; 815 void OnPageStarted(const std::string& param); 816 void OnPageFinished(const std::string& param); 817 void OnProgressChanged(int param); 818 void OnReceivedTitle(const std::string& param); 819 void ExitFullScreen(); 820 void OnFullScreenExit(); 821 void OnGeolocationPermissionsHidePrompt(); 822 void OnGeolocationPermissionsShowPrompt( 823 const std::string& origin, const std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface>& callback); 824 void OnCompleteSwapWithNewSize(); 825 void OnResizeNotWork(); 826 void OnDateTimeChooserPopup( 827 std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser, 828 const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions, 829 std::shared_ptr<OHOS::NWeb::NWebDateTimeChooserCallback> callback); 830 void OnDateTimeChooserClose(); 831 void OnRequestFocus(); 832 bool OnCommonDialog(const std::shared_ptr<BaseEventInfo>& info, DialogEventType dialogEventType); 833 bool OnHttpAuthRequest(const std::shared_ptr<BaseEventInfo>& info); 834 bool OnSslErrorRequest(const std::shared_ptr<BaseEventInfo>& info); 835 bool OnAllSslErrorRequest(const std::shared_ptr<BaseEventInfo>& info); 836 bool OnSslSelectCertRequest(const std::shared_ptr<BaseEventInfo>& info); 837 void OnDownloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, 838 const std::string& mimetype, long contentLength); 839 void OnAccessibilityEvent(int64_t accessibilityId, AccessibilityEventType eventType); 840 void OnPageError(const std::string& param); 841 void OnMessage(const std::string& param); 842 void OnFullScreenEnter(std::shared_ptr<OHOS::NWeb::NWebFullScreenExitHandler> handler, int videoNaturalWidth, 843 int videoNaturalHeight); 844 bool OnConsoleLog(std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message); 845 void OnRouterPush(const std::string& param); 846 void OnRenderExited(OHOS::NWeb::RenderExitReason reason); 847 void OnRefreshAccessedHistory(const std::string& url, bool isRefreshed); 848 bool OnFileSelectorShow(const std::shared_ptr<BaseEventInfo>& info); 849 bool OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info); 850 void OnContextMenuHide(const std::string& info); 851 bool OnHandleInterceptUrlLoading(const std::string& url); 852 bool OnHandleInterceptLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request); 853 void OnResourceLoad(const std::string& url); 854 void OnScaleChange(float oldScaleFactor, float newScaleFactor); 855 void OnScroll(double xOffset, double yOffset); 856 bool LoadDataWithRichText(); 857 void OnSearchResultReceive(int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting); 858 bool OnDragAndDropData(const void* data, size_t len, int width, int height); 859 bool OnDragAndDropDataUdmf(std::shared_ptr<OHOS::NWeb::NWebDragData> dragData); 860 void OnTooltip(const std::string& tooltip); 861 void OnShowAutofillPopup(const float offsetX, const float offsetY, const std::vector<std::string>& menu_items); 862 void SuggestionSelected(int32_t index); 863 void OnHideAutofillPopup(); 864 std::shared_ptr<OHOS::NWeb::NWebDragData> GetOrCreateDragData(); 865 bool IsDragging(); 866 bool IsImageDrag(); 867 std::shared_ptr<OHOS::NWeb::NWebDragData> dragData_ = nullptr; 868 std::string tempDir_; UpdateDragCursor(NWeb::NWebDragData::DragOperation op)869 void UpdateDragCursor(NWeb::NWebDragData::DragOperation op) 870 { 871 op_ = op; 872 } GetDragAcceptableStatus()873 NWeb::NWebDragData::DragOperation GetDragAcceptableStatus() 874 { 875 return op_; 876 } 877 NWeb::NWebDragData::DragOperation op_ = NWeb::NWebDragData::DragOperation::DRAG_OPERATION_NONE; 878 void OnWindowNew(const std::string& targetUrl, bool isAlert, bool isUserTrigger, 879 const std::shared_ptr<OHOS::NWeb::NWebControllerHandler>& handler); 880 void OnWindowExit(); 881 void OnPageVisible(const std::string& url); 882 void OnDataResubmitted(std::shared_ptr<OHOS::NWeb::NWebDataResubmissionCallback> handler); 883 void OnNavigationEntryCommitted(std::shared_ptr<OHOS::NWeb::NWebLoadCommittedDetails> details); 884 void OnFaviconReceived(const void* data, size_t width, size_t height, OHOS::NWeb::ImageColorType colorType, 885 OHOS::NWeb::ImageAlphaType alphaType); 886 void OnTouchIconUrl(const std::string& iconUrl, bool precomposed); 887 void OnAudioStateChanged(bool audible); 888 void OnFirstContentfulPaint(int64_t navigationStartTick, int64_t firstContentfulPaintMs); 889 void OnFirstMeaningfulPaint(std::shared_ptr<OHOS::NWeb::NWebFirstMeaningfulPaintDetails> details); 890 void OnLargestContentfulPaint(std::shared_ptr<OHOS::NWeb::NWebLargestContentfulPaintDetails> details); 891 void OnSafeBrowsingCheckResult(int threat_type); 892 void OnGetTouchHandleHotZone(std::shared_ptr<OHOS::NWeb::NWebTouchHandleHotZone> hotZone); 893 void OnOverScroll(float xOffset, float yOffset); 894 void OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling); 895 void OnScrollState(bool scrollState); 896 void OnRootLayerChanged(int width, int height); 897 bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity); 898 void OnNativeEmbedAllDestory(); 899 void OnNativeEmbedLifecycleChange(std::shared_ptr<NWeb::NWebNativeEmbedDataInfo> dataInfo); 900 void OnNativeEmbedVisibilityChange(const std::string& embed_id, bool visibility); 901 void OnNativeEmbedGestureEvent(std::shared_ptr<NWeb::NWebNativeEmbedTouchEvent> event); 902 void SetNGWebPattern(const RefPtr<NG::WebPattern>& webPattern); 903 bool RequestFocus(OHOS::NWeb::NWebFocusSource source = OHOS::NWeb::NWebFocusSource::FOCUS_SOURCE_DEFAULT); 904 void SetDrawSize(const Size& drawSize); 905 void SetEnhanceSurfaceFlag(const bool& isEnhanceSurface); 906 EGLConfig GLGetConfig(int version, EGLDisplay eglDisplay); 907 void GLContextInit(void* window); 908 sptr<OHOS::SurfaceDelegate> GetSurfaceDelegateClient(); 909 void SetBoundsOrResize(const Size& drawSize, const Offset& offset, bool isKeyboard = false); 910 void ResizeVisibleViewport(const Size& visibleSize, bool isKeyboard = false); 911 Offset GetWebRenderGlobalPos(); 912 bool InitWebSurfaceDelegate(const WeakPtr<PipelineBase>& context); 913 int GetWebId(); 914 void JavaScriptOnDocumentStart(); 915 void JavaScriptOnDocumentEnd(); 916 void SetJavaScriptItems(const ScriptItems& scriptItems, const ScriptItemType& type); 917 void SetTouchEventInfo(std::shared_ptr<OHOS::NWeb::NWebNativeEmbedTouchEvent> touchEvent, 918 TouchEventInfo& touchEventInfo); 919 std::string SpanstringConvertHtml(const std::vector<uint8_t> &content); 920 bool CloseImageOverlaySelection(); 921 void GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight); 922 #if defined(ENABLE_ROSEN_BACKEND) 923 void SetSurface(const sptr<Surface>& surface); 924 sptr<Surface> surface_ = nullptr; 925 RefPtr<NG::RosenRenderSurface> renderSurface_ = nullptr; 926 #endif 927 #ifdef OHOS_STANDARD_SYSTEM SetWebRendeGlobalPos(const Offset & pos)928 void SetWebRendeGlobalPos(const Offset& pos) 929 { 930 offset_ = pos; 931 } SetBlurReason(const OHOS::NWeb::BlurReason & blurReason)932 void SetBlurReason(const OHOS::NWeb::BlurReason& blurReason) 933 { 934 blurReason_ = blurReason; 935 } SetPopup(bool popup)936 void SetPopup(bool popup) 937 { 938 isPopup_ = popup; 939 } SetParentNWebId(int32_t parentNWebId)940 void SetParentNWebId(int32_t parentNWebId) 941 { 942 parentNWebId_ = parentNWebId; 943 } 944 #endif 945 void SetToken(); 946 void ScrollBy(float deltaX, float deltaY); 947 void ScrollByRefScreen(float deltaX, float deltaY, float vx = 0, float vy = 0); 948 void SetRenderMode(RenderMode renderMode); 949 void SetFitContentMode(WebLayoutMode layoutMode); 950 void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard); 951 bool ShouldVirtualKeyboardOverlay(); 952 bool ExecuteAction(int64_t accessibilityId, AceAction action, 953 const std::map<std::string, std::string>& actionArguments); 954 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetFocusedAccessibilityNodeInfo( 955 int64_t accessibilityId, bool isAccessibilityFocus); 956 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeInfoById(int64_t accessibilityId); 957 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeInfoByFocusMove( 958 int64_t accessibilityId, int32_t direction); 959 void SetAccessibilityState(bool state); 960 void UpdateAccessibilityState(bool state); 961 OHOS::NWeb::NWebPreference::CopyOptionMode GetCopyOptionMode() const; 962 void OnIntelligentTrackingPreventionResult( 963 const std::string& websiteHost, const std::string& trackerHost); 964 bool OnHandleOverrideLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request); 965 std::vector<int8_t> GetWordSelection(const std::string& text, int8_t offset); 966 967 void OnRenderProcessNotResponding( 968 const std::string& jsStack, int pid, OHOS::NWeb::RenderProcessNotRespondingReason reason); 969 void OnRenderProcessResponding(); 970 Offset GetPosition(const std::string& embedId); 971 972 void OnOnlineRenderToForeground(); 973 void NotifyForNextTouchEvent(); 974 975 bool OnOpenAppLink(const std::string& url, std::shared_ptr<OHOS::NWeb::NWebAppLinkCallback> callback); 976 977 // Backward 978 void Backward(); 979 bool AccessBackward(); 980 981 void ScaleGestureChange(double scale, double centerX, double centerY); 982 std::string GetSelectInfo() const; 983 984 void OnViewportFitChange(OHOS::NWeb::ViewportFit viewportFit); 985 void OnAreaChange(const OHOS::Ace::Rect& area); 986 void OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea avoidArea, OHOS::Rosen::AvoidAreaType type); 987 std::string GetWebInfoType(); 988 989 void CreateOverlay(void* data, size_t len, int width, int height, int offsetX, int offsetY, int rectWidth, 990 int rectHeight, int pointX, int pointY); 991 992 void OnOverlayStateChanged(int offsetX, int offsetY, int rectWidth, int rectHeight); 993 994 void OnTextSelected(); 995 void OnDestroyImageAnalyzerOverlay(); 996 997 void SetSurfaceId(const std::string& surfaceId); 998 999 void OnAdsBlocked(const std::string& url, const std::vector<std::string>& adsBlocked); 1000 void OnInterceptKeyboardAttach( 1001 const std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler, 1002 const std::map<std::string, std::string> &attributes, bool &useSystemKeyboard, int32_t &enterKeyType); 1003 1004 void KeyboardReDispatch(const std::shared_ptr<OHOS::NWeb::NWebKeyEvent>& event, bool isUsed); 1005 1006 void OnCursorUpdate(double x, double y, double width, double height); 1007 1008 void OnCustomKeyboardAttach(); 1009 1010 void OnCustomKeyboardClose(); 1011 CloseCustomKeyboard()1012 void CloseCustomKeyboard() 1013 { 1014 if (keyboardHandler_) { 1015 keyboardHandler_->Close(); 1016 } 1017 } 1018 1019 void OnAttachContext(const RefPtr<NG::PipelineContext> &context); 1020 void OnDetachContext(); 1021 GetInstanceId()1022 int32_t GetInstanceId() const 1023 { 1024 return instanceId_; 1025 } 1026 1027 void StartVibraFeedback(const std::string& vibratorType); 1028 1029 bool GetAccessibilityVisible(int64_t accessibilityId); 1030 1031 private: 1032 void InitWebEvent(); 1033 void RegisterWebEvent(); 1034 void ReleasePlatformResource(); 1035 void Stop(); 1036 void UnregisterEvent(); 1037 std::string GetUrlStringParam(const std::string& param, const std::string& name) const; 1038 void CallWebRouterBack(); 1039 void CallPopPageSuccessPageUrl(const std::string& url); 1040 void CallIsPagePathInvalid(const bool& isPageInvalid); 1041 1042 void BindRouterBackMethod(); 1043 void BindPopPageSuccessMethod(); 1044 void BindIsPagePathInvalidMethod(); 1045 void WebComponentClickReport(int64_t accessibilityId); 1046 void TextBlurReportByFocusEvent(int64_t accessibilityId); 1047 void TextBlurReportByBlurEvent(int64_t accessibilityId); 1048 1049 #ifdef OHOS_STANDARD_SYSTEM 1050 sptr<OHOS::Rosen::Window> CreateWindow(); 1051 void LoadUrl(const std::string& url, const std::map<std::string, std::string>& httpHeaders); 1052 void ExecuteTypeScript(const std::string& jscode, const std::function<void(std::string)>&& callback); 1053 void LoadDataWithBaseUrl(const std::string& baseUrl, const std::string& data, const std::string& mimeType, 1054 const std::string& encoding, const std::string& historyUrl); 1055 void Refresh(); 1056 void StopLoading(); 1057 void AddJavascriptInterface(const std::string& objectName, const std::vector<std::string>& methodList); 1058 void RemoveJavascriptInterface(const std::string& objectName, const std::vector<std::string>& methodList); 1059 void SetWebViewJavaScriptResultCallBack(const WebController::JavaScriptCallBackImpl&& javaScriptCallBackImpl); 1060 void Zoom(float factor); 1061 bool ZoomIn(); 1062 bool ZoomOut(); 1063 int ConverToWebHitTestType(int hitType); 1064 int GetHitTestResult(); 1065 void GetHitTestValue(HitTestResult& result); 1066 int GetPageHeight(); 1067 std::string GetTitle(); 1068 std::string GetDefaultUserAgent(); 1069 bool SaveCookieSync(); 1070 bool SetCookie(const std::string& url, 1071 const std::string& value, 1072 bool incognito_mode); 1073 std::string GetCookie(const std::string& url, bool incognito_mode) const; 1074 void DeleteEntirelyCookie(bool incognito_mode); 1075 void RegisterOHOSWebEventAndMethord(); 1076 void SetWebCallBack(); 1077 void RunSetWebIdAndHapPathCallback(); 1078 void RunJsProxyCallback(); 1079 void RegisterConfigObserver(); 1080 void UnRegisterConfigObserver(); 1081 1082 // forward 1083 1084 void Forward(); 1085 void ClearHistory(); 1086 void ClearSslCache(); 1087 void ClearClientAuthenticationCache(); 1088 bool AccessStep(int32_t step); 1089 void BackOrForward(int32_t step); 1090 bool AccessForward(); 1091 1092 void SearchAllAsync(const std::string& searchStr); 1093 void ClearMatches(); 1094 void SearchNext(bool forward); 1095 1096 void UpdateSettting(bool useNewPipe = false); 1097 1098 std::string GetCustomScheme(); 1099 void InitWebViewWithSurface(); 1100 Size GetEnhanceSurfaceSize(const Size& drawSize); 1101 void UpdateScreenOffSet(double& offsetX, double& offsetY); 1102 void RegisterSurfacePositionChangedCallback(); 1103 void UnregisterSurfacePositionChangedCallback(); 1104 1105 void NotifyPopupWindowResult(bool result); 1106 1107 EventCallbackV2 GetAudioStateChangedCallback(bool useNewPipe, const RefPtr<NG::WebEventHub>& eventHub); 1108 void SurfaceOcclusionCallback(float visibleRatio); 1109 void RegisterSurfaceOcclusionChangeFun(); 1110 void ratioStrToFloat(const std::string& str); 1111 // Return canonical encoding name according to the encoding alias name. 1112 std::string GetCanonicalEncodingName(const std::string& alias_name) const; 1113 void RegisterAvoidAreaChangeListener(); 1114 void UnregisterAvoidAreaChangeListener(); 1115 void OnSafeInsetsChange(); 1116 void EnableHardware(); 1117 #endif 1118 1119 WeakPtr<WebComponent> webComponent_; 1120 WeakPtr<RenderWeb> renderWeb_; 1121 1122 WeakPtr<NG::WebPattern> webPattern_; 1123 1124 std::list<CreatedCallback> createdCallbacks_; 1125 std::list<ReleasedCallback> releasedCallbacks_; 1126 EventCallback onPageStarted_; 1127 EventCallback onPageFinished_; 1128 EventCallback onPageError_; 1129 EventCallback onMessage_; 1130 Method reloadMethod_; 1131 Method updateUrlMethod_; 1132 Method routerBackMethod_; 1133 Method changePageUrlMethod_; 1134 Method isPagePathInvalidMethod_; 1135 State state_ { State::WAITINGFORSIZE }; 1136 #ifdef OHOS_STANDARD_SYSTEM 1137 std::shared_ptr<OHOS::NWeb::NWeb> nweb_; 1138 std::shared_ptr<OHOS::NWeb::NWebCookieManager> cookieManager_ = nullptr; 1139 sptr<Rosen::Window> window_; 1140 bool isCreateWebView_ = false; 1141 int32_t callbackId_ = 0; 1142 1143 EventCallbackV2 onPageFinishedV2_; 1144 EventCallbackV2 onPageStartedV2_; 1145 EventCallbackV2 onProgressChangeV2_; 1146 EventCallbackV2 onTitleReceiveV2_; 1147 EventCallbackV2 onFullScreenExitV2_; 1148 EventCallbackV2 onGeolocationHideV2_; 1149 EventCallbackV2 onGeolocationShowV2_; 1150 EventCallbackV2 onRequestFocusV2_; 1151 EventCallbackV2 onErrorReceiveV2_; 1152 EventCallbackV2 onHttpErrorReceiveV2_; 1153 EventCallbackV2 onDownloadStartV2_; 1154 EventCallbackV2 onRefreshAccessedHistoryV2_; 1155 EventCallbackV2 onRenderExitedV2_; 1156 EventCallbackV2 onResourceLoadV2_; 1157 EventCallbackV2 onScaleChangeV2_; 1158 EventCallbackV2 onScrollV2_; 1159 EventCallbackV2 onPermissionRequestV2_; 1160 EventCallbackV2 onSearchResultReceiveV2_; 1161 EventCallbackV2 onWindowExitV2_; 1162 EventCallbackV2 onPageVisibleV2_; 1163 EventCallbackV2 onTouchIconUrlV2_; 1164 EventCallbackV2 onAudioStateChangedV2_; 1165 EventCallbackV2 onFirstContentfulPaintV2_; 1166 EventCallbackV2 OnFirstMeaningfulPaintV2_; 1167 EventCallbackV2 OnLargestContentfulPaintV2_; 1168 EventCallbackV2 onOverScrollV2_; 1169 EventCallbackV2 onScreenCaptureRequestV2_; 1170 EventCallbackV2 onSafeBrowsingCheckResultV2_; 1171 EventCallbackV2 onNavigationEntryCommittedV2_; 1172 EventCallbackV2 OnNativeEmbedAllDestoryV2_; 1173 EventCallbackV2 OnNativeEmbedLifecycleChangeV2_; 1174 EventCallbackV2 OnNativeEmbedVisibilityChangeV2_; 1175 EventCallbackV2 OnNativeEmbedGestureEventV2_; 1176 EventCallbackV2 onIntelligentTrackingPreventionResultV2_; 1177 EventCallbackV2 onRenderProcessNotRespondingV2_; 1178 EventCallbackV2 onRenderProcessRespondingV2_; 1179 EventCallbackV2 onViewportFitChangedV2_; 1180 EventCallbackV2 onAdsBlockedV2_; 1181 std::function<WebKeyboardOption(const std::shared_ptr<BaseEventInfo>&)> onInterceptKeyboardAttachV2_; 1182 1183 int32_t renderMode_ = -1; 1184 int32_t layoutMode_ = -1; 1185 std::string bundlePath_; 1186 std::string bundleDataPath_; 1187 std::string hapPath_; 1188 RefPtr<PixelMap> pixelMap_ = nullptr; 1189 bool isRefreshPixelMap_ = false; 1190 Size drawSize_; 1191 Offset offset_; 1192 bool isEnhanceSurface_ = false; 1193 sptr<WebSurfaceCallback> surfaceCallback_; 1194 sptr<OHOS::SurfaceDelegate> surfaceDelegate_; 1195 EGLNativeWindowType mEglWindow = nullptr; 1196 EGLDisplay mEGLDisplay = EGL_NO_DISPLAY; 1197 EGLConfig mEGLConfig = nullptr; 1198 EGLContext mEGLContext = EGL_NO_CONTEXT; 1199 EGLContext mSharedEGLContext = EGL_NO_CONTEXT; 1200 EGLSurface mEGLSurface = nullptr; 1201 WindowsSurfaceInfo surfaceInfo_ = { nullptr, EGL_NO_DISPLAY, nullptr, EGL_NO_CONTEXT }; 1202 bool forceDarkMode_ = false; 1203 WebDarkMode current_dark_mode_ = WebDarkMode::Auto; 1204 std::shared_ptr<OHOS::AbilityRuntime::EnvironmentCallback> configChangeObserver_ = nullptr; 1205 OHOS::NWeb::BlurReason blurReason_ = OHOS::NWeb::BlurReason::FOCUS_SWITCH; 1206 bool isPopup_ = false; 1207 int32_t parentNWebId_ = -1; 1208 bool needResizeAtFirst_ = false; 1209 int32_t backgroundColor_ = 0xffffffff; 1210 uint32_t rosenWindowId_ = 0; 1211 RefPtr<WebDelegateObserver> observer_; 1212 std::shared_ptr<Rosen::RSNode> rsNode_; 1213 std::shared_ptr<Rosen::RSNode> surfaceRsNode_; 1214 Rosen::NodeId surfaceNodeId_ = 0; 1215 float visibleRatio_ = 1.0; 1216 uint32_t delayTime_ = 500; 1217 float lowerFrameRateVisibleRatio_ = 0.1; 1218 std::optional<ScriptItems> onDocumentStartScriptItems_; 1219 std::optional<ScriptItems> onDocumentEndScriptItems_; 1220 std::optional<std::string> richtextData_; 1221 bool incognitoMode_ = false; 1222 bool accessibilityState_ = false; 1223 bool isEmbedModeEnabled_ = false; 1224 std::map<std::string, std::shared_ptr<OHOS::NWeb::NWebNativeEmbedDataInfo>> embedDataInfo_; 1225 std::string tag_; 1226 std::string tag_type_; 1227 double resizeWidth_ = 0.0; 1228 double resizeHeight_ = 0.0; 1229 double resizeVisibleWidth_ = -1.0; 1230 double resizeVisibleHeight_ = -1.0; 1231 OHOS::Ace::Rect currentArea_; 1232 NG::SafeAreaInsets systemSafeArea_; 1233 NG::SafeAreaInsets cutoutSafeArea_; 1234 NG::SafeAreaInsets navigationIndicatorSafeArea_; 1235 sptr<Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_ = nullptr; 1236 std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler_ = nullptr; 1237 int32_t instanceId_; 1238 std::string sharedRenderProcessToken_; 1239 int64_t lastFocusInputId_ = 0; 1240 int64_t lastFocusReportId_ = 0; 1241 bool isEnableHardwareComposition_ = false; 1242 #endif 1243 }; 1244 } // namespace OHOS::Ace 1245 1246 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_DELEGATE_H 1247