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