1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H 18 19 #include <map> 20 21 #include "base/memory/ace_type.h" 22 #include "core/event/ace_events.h" 23 24 namespace OHOS::Ace { 25 26 enum DialogEventType { 27 DIALOG_EVENT_ALERT = 0, 28 DIALOG_EVENT_BEFORE_UNLOAD = 1, 29 DIALOG_EVENT_CONFIRM = 2, 30 DIALOG_EVENT_PROMPT = 3 31 }; 32 33 class WebConsoleLog : public AceType { 34 DECLARE_ACE_TYPE(WebConsoleLog, AceType) 35 public: 36 WebConsoleLog() = default; 37 ~WebConsoleLog() = default; 38 39 virtual int GetLineNumber() = 0; 40 virtual std::string GetLog() = 0; 41 virtual int GetLogLevel() = 0; 42 virtual std::string GetSourceId() = 0; 43 }; 44 45 class WebFileSelectorParam : public AceType { 46 DECLARE_ACE_TYPE(WebFileSelectorParam, AceType) 47 public: 48 WebFileSelectorParam() = default; 49 ~WebFileSelectorParam() = default; 50 51 virtual std::string GetTitle() = 0; 52 virtual int GetMode() = 0; 53 virtual std::string GetDefaultFileName() = 0; 54 virtual std::vector<std::string> GetAcceptType() = 0; 55 virtual bool IsCapture() = 0; 56 }; 57 58 class ACE_EXPORT WebError : public AceType { DECLARE_ACE_TYPE(WebError,AceType)59 DECLARE_ACE_TYPE(WebError, AceType) 60 61 public: 62 WebError(const std::string& info, int32_t code) : info_(info), code_(code) {} 63 ~WebError() = default; 64 GetInfo()65 const std::string& GetInfo() const 66 { 67 return info_; 68 } 69 GetCode()70 int32_t GetCode() const 71 { 72 return code_; 73 } 74 75 private: 76 std::string info_; 77 int32_t code_; 78 }; 79 80 enum class WebResponseDataType : int32_t { 81 STRING_TYPE, 82 FILE_TYPE, 83 }; 84 85 class WebResponseAsyncHandle : public AceType { 86 DECLARE_ACE_TYPE(WebResponseAsyncHandle, AceType) 87 public: 88 WebResponseAsyncHandle() = default; 89 virtual ~WebResponseAsyncHandle() = default; 90 91 virtual void HandleData(std::string& data) = 0; 92 virtual void HandleFileFd(int32_t fd) = 0; 93 virtual void HandleHeadersVal(const std::map<std::string, std::string>& response_headers) = 0; 94 virtual void HandleEncoding(std::string& encoding) = 0; 95 virtual void HandleMimeType(std::string& mimeType) = 0; 96 virtual void HandleStatusCodeAndReason(int32_t statusCode, std::string& reason) = 0; 97 virtual void HandleResponseStatus(bool isReady) = 0; 98 }; 99 100 class ACE_EXPORT WebResponse : public AceType { DECLARE_ACE_TYPE(WebResponse,AceType)101 DECLARE_ACE_TYPE(WebResponse, AceType) 102 103 public: 104 WebResponse(const std::map<std::string, std::string>& headers, const std::string& data, const std::string& encoding, 105 const std::string& mimeType, const std::string& reason, int32_t statusCode) 106 : headers_(headers), data_(data), encoding_(encoding), mimeType_(mimeType), reason_(reason), 107 statusCode_(statusCode) 108 {} 109 WebResponse() = default; 110 ~WebResponse() = default; 111 GetHeaders()112 const std::map<std::string, std::string>& GetHeaders() const 113 { 114 return headers_; 115 } 116 GetData()117 const std::string& GetData() const 118 { 119 return data_; 120 } 121 GetEncoding()122 const std::string& GetEncoding() const 123 { 124 return encoding_; 125 } 126 GetMimeType()127 const std::string& GetMimeType() const 128 { 129 return mimeType_; 130 } 131 GetReason()132 const std::string& GetReason() const 133 { 134 return reason_; 135 } 136 GetStatusCode()137 int32_t GetStatusCode() const 138 { 139 return statusCode_; 140 } 141 GetResponseStatus()142 bool GetResponseStatus() const 143 { 144 return isReady_; 145 } 146 GetFileHandle()147 int32_t GetFileHandle() const 148 { 149 return fd_; 150 } 151 SetHeadersVal(std::string & key,std::string & val)152 void SetHeadersVal(std::string& key, std::string& val) 153 { 154 headers_[key] = val; 155 } 156 SetData(std::string & data)157 void SetData(std::string& data) 158 { 159 data_ = data; 160 dataType_ = WebResponseDataType::STRING_TYPE; 161 fd_ = 0; 162 } 163 SetFileHandle(int32_t fd)164 void SetFileHandle(int32_t fd) 165 { 166 fd_ = fd; 167 data_.clear(); 168 dataType_ = WebResponseDataType::FILE_TYPE; 169 } 170 SetEncoding(std::string & encoding)171 void SetEncoding(std::string& encoding) 172 { 173 encoding_ = encoding; 174 } 175 SetMimeType(std::string & mimeType)176 void SetMimeType(std::string& mimeType) 177 { 178 mimeType_ = mimeType; 179 } 180 SetReason(std::string & reason)181 void SetReason(std::string& reason) 182 { 183 reason_ = reason; 184 } 185 SetStatusCode(int32_t statusCode)186 void SetStatusCode(int32_t statusCode) 187 { 188 statusCode_ = statusCode; 189 } 190 SetResponseStatus(bool isReady)191 void SetResponseStatus(bool isReady) 192 { 193 isReady_ = isReady; 194 if (handle_ == nullptr) { 195 return; 196 } 197 if (isReady_ == true) { 198 if (dataType_ == WebResponseDataType::FILE_TYPE) { 199 handle_->HandleFileFd(fd_); 200 } else { 201 handle_->HandleData(data_); 202 } 203 handle_->HandleHeadersVal(headers_); 204 handle_->HandleEncoding(encoding_); 205 handle_->HandleMimeType(mimeType_); 206 handle_->HandleStatusCodeAndReason(statusCode_, reason_); 207 } 208 handle_->HandleResponseStatus(isReady_); 209 } 210 SetAsyncHandle(std::shared_ptr<WebResponseAsyncHandle> handle)211 void SetAsyncHandle(std::shared_ptr<WebResponseAsyncHandle> handle) 212 { 213 handle_ = handle; 214 } 215 IsFileHandle()216 bool IsFileHandle() 217 { 218 if (dataType_ == WebResponseDataType::FILE_TYPE) { 219 return true; 220 } 221 return false; 222 } 223 224 private: 225 std::map<std::string, std::string> headers_; 226 std::string data_; 227 int32_t fd_; 228 WebResponseDataType dataType_; 229 std::string encoding_; 230 std::string mimeType_; 231 std::string reason_; 232 int32_t statusCode_; 233 bool isReady_ = true; 234 std::shared_ptr<WebResponseAsyncHandle> handle_; 235 }; 236 237 class ACE_EXPORT WebRequest : public AceType { DECLARE_ACE_TYPE(WebRequest,AceType)238 DECLARE_ACE_TYPE(WebRequest, AceType) 239 240 public: 241 WebRequest(const std::map<std::string, std::string>& headers, const std::string& method, const std::string& url, 242 bool hasGesture, bool isMainFrame, bool isRedirect) 243 : headers_(headers), method_(method), url_(url), hasGesture_(hasGesture), isMainFrame_(isMainFrame), 244 isRedirect_(isRedirect) 245 {} 246 ~WebRequest() = default; 247 GetHeaders()248 const std::map<std::string, std::string>& GetHeaders() const 249 { 250 return headers_; 251 } 252 GetMethod()253 const std::string& GetMethod() const 254 { 255 return method_; 256 } 257 GetUrl()258 const std::string& GetUrl() const 259 { 260 return url_; 261 } 262 HasGesture()263 bool HasGesture() const 264 { 265 return hasGesture_; 266 } 267 IsMainFrame()268 bool IsMainFrame() const 269 { 270 return isMainFrame_; 271 } 272 IsRedirect()273 bool IsRedirect() const 274 { 275 return isRedirect_; 276 } 277 278 private: 279 std::map<std::string, std::string> headers_; 280 std::string method_; 281 std::string url_; 282 bool hasGesture_; 283 bool isMainFrame_; 284 bool isRedirect_; 285 }; 286 287 class ACE_EXPORT Result : public AceType { 288 DECLARE_ACE_TYPE(Result, AceType) 289 290 public: 291 Result() = default; 292 ~Result() = default; 293 294 virtual void Confirm() = 0; 295 virtual void Confirm(const std::string& message) = 0; 296 virtual void Cancel() = 0; 297 }; 298 299 class ACE_EXPORT FileSelectorResult : public AceType { 300 DECLARE_ACE_TYPE(FileSelectorResult, AceType) 301 302 public: 303 FileSelectorResult() = default; 304 ~FileSelectorResult() = default; 305 306 virtual void HandleFileList(std::vector<std::string>& fileList) = 0; 307 }; 308 309 class ACE_EXPORT WebDialogEvent : public BaseEventInfo { 310 DECLARE_RELATIONSHIP_OF_CLASSES(WebDialogEvent, BaseEventInfo); 311 312 public: WebDialogEvent(const std::string & url,const std::string & message,const std::string & value,const DialogEventType & type,const RefPtr<Result> & result)313 WebDialogEvent(const std::string& url, const std::string& message, const std::string& value, 314 const DialogEventType& type, const RefPtr<Result>& result) 315 : BaseEventInfo("WebDialogEvent"), url_(url), message_(message), value_(value), type_(type), result_(result) 316 {} 317 ~WebDialogEvent() = default; 318 GetUrl()319 const std::string& GetUrl() const 320 { 321 return url_; 322 } 323 GetMessage()324 const std::string& GetMessage() const 325 { 326 return message_; 327 } 328 GetValue()329 const std::string& GetValue() const 330 { 331 return value_; 332 } 333 GetResult()334 const RefPtr<Result>& GetResult() const 335 { 336 return result_; 337 } 338 GetType()339 const DialogEventType& GetType() const 340 { 341 return type_; 342 } 343 344 private: 345 std::string url_; 346 std::string message_; 347 std::string value_; 348 DialogEventType type_; 349 RefPtr<Result> result_; 350 }; 351 352 class ACE_EXPORT AuthResult : public AceType { 353 DECLARE_ACE_TYPE(AuthResult, AceType) 354 355 public: 356 AuthResult() = default; 357 ~AuthResult() = default; 358 359 virtual bool Confirm(std::string& userName, std::string& pwd) = 0; 360 virtual bool IsHttpAuthInfoSaved() = 0; 361 virtual void Cancel() = 0; 362 }; 363 364 class ACE_EXPORT WebHttpAuthEvent : public BaseEventInfo { 365 DECLARE_RELATIONSHIP_OF_CLASSES(WebHttpAuthEvent, BaseEventInfo); 366 367 public: WebHttpAuthEvent(const RefPtr<AuthResult> & result,const std::string & host,const std::string & realm)368 WebHttpAuthEvent(const RefPtr<AuthResult>& result, const std::string& host, const std::string& realm) 369 : BaseEventInfo("WebHttpAuthEvent"), result_(result), host_(host), realm_(realm) 370 {} 371 ~WebHttpAuthEvent() = default; 372 GetResult()373 const RefPtr<AuthResult>& GetResult() const 374 { 375 return result_; 376 } 377 GetHost()378 const std::string& GetHost() const 379 { 380 return host_; 381 } 382 GetRealm()383 const std::string& GetRealm() const 384 { 385 return realm_; 386 } 387 388 private: 389 RefPtr<AuthResult> result_; 390 std::string host_; 391 std::string realm_; 392 }; 393 394 class ACE_EXPORT SslErrorResult : public AceType { 395 DECLARE_ACE_TYPE(SslErrorResult, AceType) 396 397 public: 398 SslErrorResult() = default; 399 ~SslErrorResult() = default; 400 virtual void HandleConfirm() = 0; 401 virtual void HandleCancel() = 0; 402 }; 403 404 class ACE_EXPORT WebSslErrorEvent : public BaseEventInfo { 405 DECLARE_RELATIONSHIP_OF_CLASSES(WebSslErrorEvent, BaseEventInfo); 406 407 public: WebSslErrorEvent(const RefPtr<SslErrorResult> & result,int32_t error)408 WebSslErrorEvent(const RefPtr<SslErrorResult>& result, int32_t error) 409 : BaseEventInfo("WebSslErrorEvent"), result_(result), error_(error) {} 410 ~WebSslErrorEvent() = default; 411 GetResult()412 const RefPtr<SslErrorResult>& GetResult() const 413 { 414 return result_; 415 } 416 GetError()417 int32_t GetError() const 418 { 419 return error_; 420 } 421 422 private: 423 RefPtr<SslErrorResult> result_; 424 int32_t error_; 425 }; 426 427 class ACE_EXPORT SslSelectCertResult : public AceType { 428 DECLARE_ACE_TYPE(SslSelectCertResult, AceType) 429 public: 430 SslSelectCertResult() = default; 431 ~SslSelectCertResult() = default; 432 433 virtual void HandleConfirm(const std::string& privateKeyFile, const std::string& certChainFile) = 0; 434 virtual void HandleCancel() = 0; 435 virtual void HandleIgnore() = 0; 436 }; 437 438 class ACE_EXPORT WebSslSelectCertEvent : public BaseEventInfo { 439 DECLARE_RELATIONSHIP_OF_CLASSES(WebSslSelectCertEvent, BaseEventInfo); 440 441 public: WebSslSelectCertEvent(const RefPtr<SslSelectCertResult> & result,const std::string & host,int port,const std::vector<std::string> & keyTypes,const std::vector<std::string> & issuers)442 WebSslSelectCertEvent(const RefPtr<SslSelectCertResult>& result, 443 const std::string& host, int port, 444 const std::vector<std::string>& keyTypes, 445 const std::vector<std::string>& issuers) 446 : BaseEventInfo("WebSslSelectCertEvent"), 447 result_(result), host_(host), port_(port), keyTypes_(keyTypes), issuers_(issuers) {} 448 449 ~WebSslSelectCertEvent() = default; 450 GetResult()451 const RefPtr<SslSelectCertResult>& GetResult() const 452 { 453 return result_; 454 } 455 GetHost()456 const std::string& GetHost() const 457 { 458 return host_; 459 } 460 GetPort()461 int32_t GetPort() const 462 { 463 return port_; 464 } 465 GetKeyTypes()466 const std::vector<std::string>& GetKeyTypes() const 467 { 468 return keyTypes_; 469 } 470 GetIssuers_()471 const std::vector<std::string>& GetIssuers_() const 472 { 473 return issuers_; 474 } 475 476 private: 477 RefPtr<SslSelectCertResult> result_; 478 std::string host_; 479 int32_t port_ = -1; 480 std::vector<std::string> keyTypes_; 481 std::vector<std::string> issuers_; 482 }; 483 484 class ACE_EXPORT WebGeolocation : public AceType { 485 DECLARE_ACE_TYPE(WebGeolocation, AceType) 486 487 public: 488 WebGeolocation() = default; 489 ~WebGeolocation() = default; 490 491 virtual void Invoke(const std::string& origin, const bool& allow, const bool& retain) = 0; 492 }; 493 494 class ACE_EXPORT WebPermissionRequest : public AceType { 495 DECLARE_ACE_TYPE(WebPermissionRequest, AceType) 496 497 public: 498 WebPermissionRequest() = default; 499 ~WebPermissionRequest() = default; 500 501 virtual void Deny() const = 0; 502 503 virtual std::string GetOrigin() const = 0; 504 505 virtual std::vector<std::string> GetResources() const = 0; 506 507 virtual void Grant(std::vector<std::string>& resources) const = 0; 508 }; 509 510 class ACE_EXPORT WebWindowNewHandler : public AceType { 511 DECLARE_ACE_TYPE(WebWindowNewHandler, AceType) 512 513 public: 514 WebWindowNewHandler() = default; 515 ~WebWindowNewHandler() = default; 516 517 virtual void SetWebController(int32_t id) = 0; 518 519 virtual bool IsFrist() const = 0; 520 521 virtual int32_t GetId() const = 0; 522 523 virtual int32_t GetParentNWebId() const = 0; 524 }; 525 526 class ACE_EXPORT LoadWebPageStartEvent : public BaseEventInfo { 527 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebPageStartEvent, BaseEventInfo); 528 529 public: LoadWebPageStartEvent(const std::string & url)530 explicit LoadWebPageStartEvent(const std::string& url) : BaseEventInfo("LoadWebPageStartEvent"), loadedUrl_(url) {} 531 ~LoadWebPageStartEvent() = default; 532 GetLoadedUrl()533 const std::string& GetLoadedUrl() const 534 { 535 return loadedUrl_; 536 } 537 538 private: 539 std::string loadedUrl_; 540 }; 541 542 class ACE_EXPORT LoadWebPageFinishEvent : public BaseEventInfo { 543 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebPageFinishEvent, BaseEventInfo); 544 545 public: LoadWebPageFinishEvent(const std::string & url)546 explicit LoadWebPageFinishEvent(const std::string& url) : BaseEventInfo("LoadWebPageFinishEvent"), loadedUrl_(url) 547 {} 548 ~LoadWebPageFinishEvent() = default; 549 GetLoadedUrl()550 const std::string& GetLoadedUrl() const 551 { 552 return loadedUrl_; 553 } 554 555 private: 556 std::string loadedUrl_; 557 }; 558 559 class ACE_EXPORT LoadWebProgressChangeEvent : public BaseEventInfo { 560 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebProgressChangeEvent, BaseEventInfo); 561 562 public: LoadWebProgressChangeEvent(const int & newProgress)563 explicit LoadWebProgressChangeEvent(const int& newProgress) 564 : BaseEventInfo("LoadWebProgressChangeEvent"), newProgress_(newProgress) 565 {} 566 ~LoadWebProgressChangeEvent() = default; 567 GetNewProgress()568 const int& GetNewProgress() const 569 { 570 return newProgress_; 571 } 572 573 private: 574 int newProgress_; 575 }; 576 577 class ACE_EXPORT LoadWebTitleReceiveEvent : public BaseEventInfo { 578 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebTitleReceiveEvent, BaseEventInfo); 579 580 public: LoadWebTitleReceiveEvent(const std::string & title)581 explicit LoadWebTitleReceiveEvent(const std::string& title) 582 : BaseEventInfo("LoadWebTitleReceiveEvent"), title_(title) 583 {} 584 ~LoadWebTitleReceiveEvent() = default; 585 GetTitle()586 const std::string& GetTitle() const 587 { 588 return title_; 589 } 590 591 private: 592 std::string title_; 593 }; 594 595 class ACE_EXPORT FullScreenExitHandler : public AceType { 596 DECLARE_ACE_TYPE(FullScreenExitHandler, AceType) 597 598 public: 599 FullScreenExitHandler() = default; 600 ~FullScreenExitHandler() = default; 601 602 virtual void ExitFullScreen() = 0; 603 }; 604 605 class ACE_EXPORT FullScreenEnterEvent : public BaseEventInfo { 606 DECLARE_RELATIONSHIP_OF_CLASSES(FullScreenEnterEvent, BaseEventInfo); 607 608 public: FullScreenEnterEvent(const RefPtr<FullScreenExitHandler> & handler)609 FullScreenEnterEvent(const RefPtr<FullScreenExitHandler>& handler) 610 : BaseEventInfo("FullScreenEnterEvent"), handler_(handler) {} 611 ~FullScreenEnterEvent() = default; 612 GetHandler()613 const RefPtr<FullScreenExitHandler>& GetHandler() const 614 { 615 return handler_; 616 } 617 618 private: 619 RefPtr<FullScreenExitHandler> handler_; 620 }; 621 622 class ACE_EXPORT FullScreenExitEvent : public BaseEventInfo { 623 DECLARE_RELATIONSHIP_OF_CLASSES(FullScreenExitEvent, BaseEventInfo); 624 625 public: 626 explicit FullScreenExitEvent(bool fullscreen = false) 627 : BaseEventInfo("FullScreenExitEvent"), fullscreen_(fullscreen) {} 628 ~FullScreenExitEvent() = default; 629 IsFullScreen()630 bool IsFullScreen() const 631 { 632 return fullscreen_; 633 } 634 635 private: 636 bool fullscreen_ = false; 637 }; 638 639 class ACE_EXPORT UrlLoadInterceptEvent : public BaseEventInfo { 640 DECLARE_RELATIONSHIP_OF_CLASSES(UrlLoadInterceptEvent, BaseEventInfo); 641 642 public: UrlLoadInterceptEvent(const std::string & data)643 explicit UrlLoadInterceptEvent(const std::string& data) : BaseEventInfo("UrlLoadInterceptEvent"), data_(data) {} 644 ~UrlLoadInterceptEvent() = default; 645 GetData()646 const std::string& GetData() const 647 { 648 return data_; 649 } 650 651 private: 652 std::string data_; 653 }; 654 655 class ACE_EXPORT LoadWebGeolocationHideEvent : public BaseEventInfo { 656 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebGeolocationHideEvent, BaseEventInfo); 657 658 public: LoadWebGeolocationHideEvent(const std::string & origin)659 explicit LoadWebGeolocationHideEvent(const std::string& origin) 660 : BaseEventInfo("LoadWebGeolocationHideEvent"), origin_(origin) 661 {} 662 ~LoadWebGeolocationHideEvent() = default; 663 GetOrigin()664 const std::string& GetOrigin() const 665 { 666 return origin_; 667 } 668 669 private: 670 std::string origin_; 671 }; 672 673 class ACE_EXPORT LoadWebGeolocationShowEvent : public BaseEventInfo { 674 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebGeolocationShowEvent, BaseEventInfo); 675 676 public: LoadWebGeolocationShowEvent(const std::string & origin,const RefPtr<WebGeolocation> & webGeolocation)677 LoadWebGeolocationShowEvent(const std::string& origin, const RefPtr<WebGeolocation>& webGeolocation) 678 : BaseEventInfo("LoadWebGeolocationShowEvent"), origin_(origin), webGeolocation_(webGeolocation) 679 {} 680 ~LoadWebGeolocationShowEvent() = default; 681 GetOrigin()682 const std::string& GetOrigin() const 683 { 684 return origin_; 685 } 686 GetWebGeolocation()687 const RefPtr<WebGeolocation>& GetWebGeolocation() const 688 { 689 return webGeolocation_; 690 } 691 692 private: 693 std::string origin_; 694 RefPtr<WebGeolocation> webGeolocation_; 695 }; 696 697 class ACE_EXPORT WebPermissionRequestEvent : public BaseEventInfo { 698 DECLARE_RELATIONSHIP_OF_CLASSES(WebPermissionRequestEvent, BaseEventInfo); 699 700 public: WebPermissionRequestEvent(const RefPtr<WebPermissionRequest> & webPermissionRequest)701 WebPermissionRequestEvent(const RefPtr<WebPermissionRequest>& webPermissionRequest) 702 : BaseEventInfo("WebPermissionRequestEvent"), webPermissionRequest_(webPermissionRequest) 703 {} 704 ~WebPermissionRequestEvent() = default; 705 GetWebPermissionRequest()706 const RefPtr<WebPermissionRequest>& GetWebPermissionRequest() const 707 { 708 return webPermissionRequest_; 709 } 710 711 private: 712 RefPtr<WebPermissionRequest> webPermissionRequest_; 713 }; 714 715 class ACE_EXPORT DownloadStartEvent : public BaseEventInfo { 716 DECLARE_RELATIONSHIP_OF_CLASSES(DownloadStartEvent, BaseEventInfo); 717 718 public: DownloadStartEvent(const std::string & url,const std::string & userAgent,const std::string & contentDisposition,const std::string & mimetype,long contentLength)719 DownloadStartEvent(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, 720 const std::string& mimetype, long contentLength) 721 : BaseEventInfo("DownloadStartEvent"), url_(url), userAgent_(userAgent), 722 contentDisposition_(contentDisposition), mimetype_(mimetype), contentLength_(contentLength) 723 {} 724 ~DownloadStartEvent() = default; 725 GetUrl()726 const std::string& GetUrl() const 727 { 728 return url_; 729 } 730 GetUserAgent()731 const std::string& GetUserAgent() const 732 { 733 return userAgent_; 734 } 735 GetContentDisposition()736 const std::string& GetContentDisposition() const 737 { 738 return contentDisposition_; 739 } 740 GetMimetype()741 const std::string& GetMimetype() const 742 { 743 return mimetype_; 744 } 745 GetContentLength()746 long GetContentLength() const 747 { 748 return contentLength_; 749 } 750 751 private: 752 std::string url_; 753 std::string userAgent_; 754 std::string contentDisposition_; 755 std::string mimetype_; 756 long contentLength_; 757 }; 758 759 class ACE_EXPORT ReceivedErrorEvent : public BaseEventInfo { 760 DECLARE_RELATIONSHIP_OF_CLASSES(ReceivedErrorEvent, BaseEventInfo); 761 762 public: ReceivedErrorEvent(const RefPtr<WebRequest> & request,const RefPtr<WebError> & error)763 ReceivedErrorEvent(const RefPtr<WebRequest>& request, const RefPtr<WebError>& error) 764 : BaseEventInfo("ReceivedErrorEvent"), request_(request), error_(error) 765 { 766 LOGI("ReceivedErrorEvent constructor"); 767 } 768 ~ReceivedErrorEvent() = default; 769 GetRequest()770 const RefPtr<WebRequest>& GetRequest() const 771 { 772 return request_; 773 } 774 GetError()775 const RefPtr<WebError>& GetError() const 776 { 777 return error_; 778 } 779 780 private: 781 RefPtr<WebRequest> request_; 782 RefPtr<WebError> error_; 783 }; 784 785 class ACE_EXPORT ReceivedHttpErrorEvent : public BaseEventInfo { 786 DECLARE_RELATIONSHIP_OF_CLASSES(ReceivedHttpErrorEvent, BaseEventInfo); 787 788 public: ReceivedHttpErrorEvent(const RefPtr<WebRequest> & request,const RefPtr<WebResponse> & response)789 ReceivedHttpErrorEvent(const RefPtr<WebRequest>& request, const RefPtr<WebResponse>& response) 790 : BaseEventInfo("ReceivedHttpErrorEvent"), request_(request), response_(response) 791 { 792 LOGI("ReceivedHttpErrorEvent constructor"); 793 } 794 ~ReceivedHttpErrorEvent() = default; 795 GetRequest()796 const RefPtr<WebRequest>& GetRequest() const 797 { 798 return request_; 799 } 800 GetResponse()801 const RefPtr<WebResponse>& GetResponse() const 802 { 803 return response_; 804 } 805 806 private: 807 RefPtr<WebRequest> request_; 808 RefPtr<WebResponse> response_; 809 }; 810 811 class ACE_EXPORT OnInterceptRequestEvent : public BaseEventInfo { 812 DECLARE_RELATIONSHIP_OF_CLASSES(OnInterceptRequestEvent, BaseEventInfo); 813 814 public: OnInterceptRequestEvent(const RefPtr<WebRequest> & request)815 OnInterceptRequestEvent(const RefPtr<WebRequest>& request) 816 : BaseEventInfo("OnInterceptRequestEvent"), request_(request) 817 { 818 LOGI("OnInterceptRequestEvent constructor"); 819 } 820 ~OnInterceptRequestEvent() = default; 821 GetRequest()822 const RefPtr<WebRequest>& GetRequest() const 823 { 824 return request_; 825 } 826 827 private: 828 RefPtr<WebRequest> request_; 829 }; 830 831 class ACE_EXPORT LoadWebRequestFocusEvent : public BaseEventInfo { 832 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebRequestFocusEvent, BaseEventInfo); 833 834 public: LoadWebRequestFocusEvent(const std::string & url)835 explicit LoadWebRequestFocusEvent(const std::string& url) 836 : BaseEventInfo("LoadWebRequestFocusEvent"), focusUrl_(url) 837 {} 838 ~LoadWebRequestFocusEvent() = default; 839 GetRequestFocus()840 const std::string& GetRequestFocus() const 841 { 842 return focusUrl_; 843 } 844 845 private: 846 std::string focusUrl_; 847 }; 848 849 class ACE_EXPORT LoadWebOnFocusEvent : public BaseEventInfo { 850 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebOnFocusEvent, BaseEventInfo); 851 852 public: LoadWebOnFocusEvent(const std::string & url)853 explicit LoadWebOnFocusEvent(const std::string& url) : BaseEventInfo("LoadWebOnFocusEvent"), focusUrl_(url) {} 854 ~LoadWebOnFocusEvent() = default; 855 GetOnFocus()856 const std::string& GetOnFocus() const 857 { 858 return focusUrl_; 859 } 860 861 private: 862 std::string focusUrl_; 863 }; 864 865 class ACE_EXPORT LoadWebConsoleLogEvent : public BaseEventInfo { 866 DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebConsoleLogEvent, BaseEventInfo); 867 868 public: LoadWebConsoleLogEvent(RefPtr<WebConsoleLog> message)869 LoadWebConsoleLogEvent(RefPtr<WebConsoleLog> message) : BaseEventInfo("LoadWebConsoleLogEvent"), message_(message) 870 {} 871 ~LoadWebConsoleLogEvent() = default; 872 GetMessage()873 const RefPtr<WebConsoleLog> GetMessage() const 874 { 875 return message_; 876 } 877 878 private: 879 RefPtr<WebConsoleLog> message_; 880 }; 881 882 class ACE_EXPORT RenderExitedEvent : public BaseEventInfo { 883 DECLARE_RELATIONSHIP_OF_CLASSES(RenderExitedEvent, BaseEventInfo); 884 885 public: RenderExitedEvent(int32_t exitedReason)886 RenderExitedEvent(int32_t exitedReason) : BaseEventInfo("RenderExitedEvent"), exitedReason_(exitedReason) {} 887 ~RenderExitedEvent() = default; 888 GetExitedReason()889 int32_t GetExitedReason() const 890 { 891 return exitedReason_; 892 } 893 894 private: 895 int32_t exitedReason_; 896 }; 897 898 class ACE_EXPORT RefreshAccessedHistoryEvent : public BaseEventInfo { 899 DECLARE_RELATIONSHIP_OF_CLASSES(RefreshAccessedHistoryEvent, BaseEventInfo); 900 901 public: RefreshAccessedHistoryEvent(const std::string & url,bool isRefreshed)902 RefreshAccessedHistoryEvent(const std::string& url, bool isRefreshed) 903 : BaseEventInfo("RefreshAccessedHistoryEvent"), url_(url), isRefreshed_(isRefreshed) 904 {} 905 906 ~RefreshAccessedHistoryEvent() = default; 907 GetVisitedUrl()908 const std::string& GetVisitedUrl() const 909 { 910 return url_; 911 } 912 IsRefreshed()913 bool IsRefreshed() const 914 { 915 return isRefreshed_; 916 } 917 918 private: 919 std::string url_; 920 bool isRefreshed_; 921 }; 922 923 class ACE_EXPORT FileSelectorEvent : public BaseEventInfo { 924 DECLARE_RELATIONSHIP_OF_CLASSES(FileSelectorEvent, BaseEventInfo); 925 926 public: FileSelectorEvent(const RefPtr<WebFileSelectorParam> & param,const RefPtr<FileSelectorResult> & result)927 FileSelectorEvent(const RefPtr<WebFileSelectorParam>& param, const RefPtr<FileSelectorResult>& result) 928 : BaseEventInfo("FileSelectorEvent"), param_(param), result_(result) 929 { 930 LOGI("FileSelectorEvent constructor"); 931 } 932 ~FileSelectorEvent() = default; 933 GetParam()934 const RefPtr<WebFileSelectorParam>& GetParam() const 935 { 936 return param_; 937 } 938 GetFileSelectorResult()939 const RefPtr<FileSelectorResult>& GetFileSelectorResult() const 940 { 941 return result_; 942 } 943 944 private: 945 RefPtr<WebFileSelectorParam> param_; 946 RefPtr<FileSelectorResult> result_; 947 }; 948 949 class ACE_EXPORT ResourceLoadEvent : public BaseEventInfo { 950 DECLARE_RELATIONSHIP_OF_CLASSES(ResourceLoadEvent, BaseEventInfo); 951 952 public: ResourceLoadEvent(const std::string & url)953 explicit ResourceLoadEvent(const std::string& url) : BaseEventInfo("ResourceLoadEvent"), loadUrl_(url) {} 954 ~ResourceLoadEvent() = default; 955 GetOnResourceLoadUrl()956 const std::string& GetOnResourceLoadUrl() const 957 { 958 return loadUrl_; 959 } 960 961 private: 962 std::string loadUrl_; 963 }; 964 965 class ACE_EXPORT ScaleChangeEvent : public BaseEventInfo { 966 DECLARE_RELATIONSHIP_OF_CLASSES(ScaleChangeEvent, BaseEventInfo); 967 968 public: ScaleChangeEvent(float oldScale,float newScale)969 ScaleChangeEvent(float oldScale, float newScale) 970 : BaseEventInfo("ScaleChangeEvent"), oldScale_(oldScale), newScale_(newScale) 971 {} 972 ~ScaleChangeEvent() = default; 973 GetOnScaleChangeOldScale()974 float GetOnScaleChangeOldScale() const 975 { 976 return oldScale_; 977 } 978 GetOnScaleChangeNewScale()979 float GetOnScaleChangeNewScale() const 980 { 981 return newScale_; 982 } 983 984 private: 985 float oldScale_ = 0.0f; 986 float newScale_ = 0.0f; 987 }; 988 989 class ACE_EXPORT WebOnScrollEvent : public BaseEventInfo { 990 DECLARE_RELATIONSHIP_OF_CLASSES(WebOnScrollEvent, BaseEventInfo); 991 992 public: WebOnScrollEvent(double xOffset,double yOffset)993 WebOnScrollEvent(double xOffset, double yOffset) 994 : BaseEventInfo("OnScrollEvent"), xOffset_(xOffset), yOffset_(yOffset) 995 {} 996 ~WebOnScrollEvent() = default; 997 GetX()998 float GetX() const 999 { 1000 return xOffset_; 1001 } 1002 GetY()1003 float GetY() const 1004 { 1005 return yOffset_; 1006 } 1007 1008 private: 1009 double xOffset_ = 0.0f; 1010 double yOffset_ = 0.0f; 1011 }; 1012 1013 class WebContextMenuParam : public AceType { 1014 DECLARE_ACE_TYPE(WebContextMenuParam, AceType) 1015 1016 public: 1017 WebContextMenuParam() = default; 1018 ~WebContextMenuParam() = default; 1019 1020 virtual int32_t GetXCoord() const = 0; 1021 virtual int32_t GetYCoord() const = 0; 1022 virtual std::string GetLinkUrl() const = 0; 1023 virtual std::string GetUnfilteredLinkUrl() const = 0; 1024 virtual std::string GetSourceUrl() const = 0; 1025 virtual bool HasImageContents() const = 0; 1026 virtual bool IsEditable() const = 0; 1027 virtual int GetEditStateFlags() const = 0; 1028 virtual int GetSourceType() const = 0; 1029 virtual int GetMediaType() const = 0; 1030 virtual int GetInputFieldType() const = 0; 1031 virtual std::string GetSelectionText() const = 0; 1032 }; 1033 1034 class ACE_EXPORT ContextMenuResult : public AceType { 1035 DECLARE_ACE_TYPE(ContextMenuResult, AceType) 1036 1037 public: 1038 ContextMenuResult() = default; 1039 ~ContextMenuResult() = default; 1040 1041 virtual void Cancel() const = 0; 1042 virtual void CopyImage() const = 0; 1043 virtual void Copy() const = 0; 1044 virtual void Paste() const = 0; 1045 virtual void Cut() const = 0; 1046 virtual void SelectAll() const = 0; 1047 }; 1048 1049 class ACE_EXPORT ContextMenuEvent : public BaseEventInfo { 1050 DECLARE_RELATIONSHIP_OF_CLASSES(ContextMenuEvent, BaseEventInfo); 1051 1052 public: ContextMenuEvent(const RefPtr<WebContextMenuParam> & param,const RefPtr<ContextMenuResult> & result)1053 ContextMenuEvent(const RefPtr<WebContextMenuParam>& param, const RefPtr<ContextMenuResult>& result) 1054 : BaseEventInfo("ContextShowEvent"), param_(param), result_(result) 1055 { 1056 LOGI("ContextShowEvent constructor"); 1057 } 1058 ~ContextMenuEvent() = default; 1059 GetParam()1060 const RefPtr<WebContextMenuParam>& GetParam() const 1061 { 1062 return param_; 1063 } 1064 GetContextMenuResult()1065 const RefPtr<ContextMenuResult>& GetContextMenuResult() const 1066 { 1067 return result_; 1068 } 1069 1070 private: 1071 RefPtr<WebContextMenuParam> param_; 1072 RefPtr<ContextMenuResult> result_; 1073 }; 1074 1075 class ACE_EXPORT SearchResultReceiveEvent : public BaseEventInfo { 1076 DECLARE_RELATIONSHIP_OF_CLASSES(SearchResultReceiveEvent, BaseEventInfo); 1077 1078 public: SearchResultReceiveEvent(int activeMatchOrdinal,int numberOfMatches,bool isDoneCounting)1079 SearchResultReceiveEvent(int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting) 1080 : BaseEventInfo("SearchResultReceiveEvent"), activeMatchOrdinal_(activeMatchOrdinal), 1081 numberOfMatches_(numberOfMatches), isDoneCounting_(isDoneCounting) 1082 {} 1083 ~SearchResultReceiveEvent() = default; 1084 GetActiveMatchOrdinal()1085 int GetActiveMatchOrdinal() const 1086 { 1087 return activeMatchOrdinal_; 1088 } 1089 GetNumberOfMatches()1090 int GetNumberOfMatches() const 1091 { 1092 return numberOfMatches_; 1093 } 1094 GetIsDoneCounting()1095 bool GetIsDoneCounting() const 1096 { 1097 return isDoneCounting_; 1098 } 1099 1100 private: 1101 int activeMatchOrdinal_; 1102 int numberOfMatches_; 1103 bool isDoneCounting_; 1104 }; 1105 1106 class ACE_EXPORT WebWindowNewEvent : public BaseEventInfo { 1107 DECLARE_RELATIONSHIP_OF_CLASSES(WebWindowNewEvent, BaseEventInfo); 1108 1109 public: WebWindowNewEvent(const std::string & targetUrl,bool isAlert,bool isUserTrigger,const RefPtr<WebWindowNewHandler> & handler)1110 WebWindowNewEvent(const std::string& targetUrl, bool isAlert, bool isUserTrigger, 1111 const RefPtr<WebWindowNewHandler>& handler) 1112 : BaseEventInfo("WebWindowNewEvent"), targetUrl_(targetUrl), isAlert_(isAlert), 1113 isUserTrigger_(isUserTrigger), handler_(handler) {} 1114 ~WebWindowNewEvent() = default; 1115 GetTargetUrl()1116 const std::string& GetTargetUrl() const 1117 { 1118 return targetUrl_; 1119 } 1120 IsAlert()1121 bool IsAlert() const 1122 { 1123 return isAlert_; 1124 } 1125 IsUserTrigger()1126 bool IsUserTrigger() const 1127 { 1128 return isUserTrigger_; 1129 } 1130 GetWebWindowNewHandler()1131 const RefPtr<WebWindowNewHandler>& GetWebWindowNewHandler() const 1132 { 1133 return handler_; 1134 } 1135 private: 1136 std::string targetUrl_; 1137 bool isAlert_; 1138 bool isUserTrigger_; 1139 RefPtr<WebWindowNewHandler> handler_; 1140 }; 1141 1142 class ACE_EXPORT WebWindowExitEvent : public BaseEventInfo { 1143 DECLARE_RELATIONSHIP_OF_CLASSES(WebWindowExitEvent, BaseEventInfo); 1144 1145 public: WebWindowExitEvent()1146 WebWindowExitEvent() : BaseEventInfo("WebWindowExitEvent") {} 1147 ~WebWindowExitEvent() = default; 1148 }; 1149 1150 class ACE_EXPORT PageVisibleEvent : public BaseEventInfo { 1151 DECLARE_RELATIONSHIP_OF_CLASSES(PageVisibleEvent, BaseEventInfo); 1152 1153 public: PageVisibleEvent(const std::string & url)1154 PageVisibleEvent(const std::string& url) 1155 : BaseEventInfo("PageVisibleEvent"), url_(url) 1156 {} 1157 1158 ~PageVisibleEvent() = default; 1159 GetUrl()1160 const std::string& GetUrl() const 1161 { 1162 return url_; 1163 } 1164 1165 private: 1166 std::string url_; 1167 }; 1168 1169 class ACE_EXPORT DataResubmitted : public AceType { 1170 DECLARE_ACE_TYPE(DataResubmitted, AceType) 1171 1172 public: 1173 DataResubmitted() = default; 1174 ~DataResubmitted() = default; 1175 1176 virtual void Resend() = 0; 1177 virtual void Cancel() = 0; 1178 }; 1179 1180 class ACE_EXPORT DataResubmittedEvent : public BaseEventInfo { 1181 DECLARE_RELATIONSHIP_OF_CLASSES(DataResubmittedEvent, BaseEventInfo); 1182 1183 public: DataResubmittedEvent(const RefPtr<DataResubmitted> & handler)1184 DataResubmittedEvent(const RefPtr<DataResubmitted>& handler) 1185 : BaseEventInfo("DataResubmittedEvent"), handler_(handler) {} 1186 ~DataResubmittedEvent() = default; 1187 GetHandler()1188 const RefPtr<DataResubmitted>& GetHandler() const 1189 { 1190 return handler_; 1191 } 1192 1193 private: 1194 RefPtr<DataResubmitted> handler_; 1195 }; 1196 1197 class ACE_EXPORT WebFaviconReceived : public AceType { 1198 DECLARE_ACE_TYPE(WebFaviconReceived, AceType) 1199 1200 public: 1201 WebFaviconReceived() = default; 1202 ~WebFaviconReceived() = default; 1203 1204 virtual const void* GetData() = 0; 1205 virtual size_t GetWidth() = 0; 1206 virtual size_t GetHeight() = 0; 1207 virtual int GetColorType() = 0; 1208 virtual int GetAlphaType() = 0; 1209 }; 1210 1211 class ACE_EXPORT FaviconReceivedEvent : public BaseEventInfo { 1212 DECLARE_RELATIONSHIP_OF_CLASSES(FaviconReceivedEvent, BaseEventInfo); 1213 1214 public: FaviconReceivedEvent(const RefPtr<WebFaviconReceived> & handler)1215 FaviconReceivedEvent(const RefPtr<WebFaviconReceived>& handler) 1216 : BaseEventInfo("FaviconReceivedEvent"), handler_(handler) {} 1217 ~FaviconReceivedEvent() = default; 1218 GetHandler()1219 const RefPtr<WebFaviconReceived>& GetHandler() const 1220 { 1221 return handler_; 1222 } 1223 1224 private: 1225 RefPtr<WebFaviconReceived> handler_; 1226 }; 1227 1228 class ACE_EXPORT TouchIconUrlEvent : public BaseEventInfo { 1229 DECLARE_RELATIONSHIP_OF_CLASSES(TouchIconUrlEvent, BaseEventInfo); 1230 1231 public: TouchIconUrlEvent(const std::string & iconUrl,bool precomposed)1232 TouchIconUrlEvent(const std::string& iconUrl, bool precomposed) 1233 : BaseEventInfo("TouchIconUrlEvent"), url_(iconUrl), precomposed_(precomposed) 1234 {} 1235 1236 ~TouchIconUrlEvent() = default; 1237 GetUrl()1238 const std::string& GetUrl() const 1239 { 1240 return url_; 1241 } 1242 GetPreComposed()1243 bool GetPreComposed() const 1244 { 1245 return precomposed_; 1246 } 1247 1248 private: 1249 std::string url_; 1250 bool precomposed_; 1251 }; 1252 } // namespace OHOS::Ace 1253 1254 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H 1255