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