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