• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NWEB_H
17 #define NWEB_H
18 
19 #include <list>
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 #include "nweb_accessibility_event_callback.h"
25 #include "nweb_accessibility_node_info.h"
26 #include "nweb_download_callback.h"
27 #include "nweb_drag_data.h"
28 #include "nweb_export.h"
29 #include "nweb_find_callback.h"
30 #include "nweb_history_list.h"
31 #include "nweb_hit_testresult.h"
32 #include "nweb_javascript_result_callback.h"
33 #include "nweb_preference.h"
34 #include "nweb_release_surface_callback.h"
35 #include "nweb_value_callback.h"
36 #include "nweb_web_message.h"
37 
38 namespace OHOS::NWeb {
39 class NWebHandler;
40 class NWebValue;
41 
42 /**
43  * @brief Describes how pixel bits encoder color data.
44  */
45 enum class ImageColorType {
46     // Unknown color type.
47     COLOR_TYPE_UNKNOWN = -1,
48 
49     // RGBA with 8 bits per pixel (32bits total).
50     COLOR_TYPE_RGBA_8888 = 0,
51 
52     // BGRA with 8 bits per pixel (32bits total).
53     COLOR_TYPE_BGRA_8888 = 1,
54 };
55 
56 /**
57  * @brief Describes how to interpret the alpha value of a pixel.
58  */
59 enum class ImageAlphaType {
60     // Unknown alpha type.
61     ALPHA_TYPE_UNKNOWN = -1,
62 
63     // No transparency. The alpha component is ignored.
64     ALPHA_TYPE_OPAQUE = 0,
65 
66     // Transparency with pre-multiplied alpha component.
67     ALPHA_TYPE_PREMULTIPLIED = 1,
68 
69     // Transparency with post-multiplied alpha component.
70     ALPHA_TYPE_POSTMULTIPLIED = 2,
71 };
72 
73 struct OHOS_NWEB_EXPORT NWebInitArgs {
74     std::string dump_path = "";
75     bool frame_info_dump = false;
76     std::list<std::string> web_engine_args_to_add;
77     std::list<std::string> web_engine_args_to_delete;
78     bool multi_renderer_process = false;
79     bool is_enhance_surface = false;
80     bool is_popup = false;
81 };
82 
83 struct OHOS_NWEB_EXPORT NWebCreateInfo {
84     /* size info */
85     uint32_t width = 0;
86     uint32_t height = 0;
87 
88     /* output frame cb */
89     std::function<bool(const char*, uint32_t, uint32_t)> output_render_frame = nullptr;
90 
91     /* init args */
92     NWebInitArgs init_args;
93 
94     void* producer_surface = nullptr;
95 
96     void* enhance_surface_info = nullptr;
97 
98     bool incognito_mode = false;
99 };
100 
101 enum class OHOS_NWEB_EXPORT DragAction {
102     DRAG_START = 0,
103     DRAG_ENTER,
104     DRAG_LEAVE,
105     DRAG_OVER,
106     DRAG_DROP,
107     DRAG_END,
108     DRAG_CANCEL,
109 };
110 
111 struct OHOS_NWEB_EXPORT DragEvent {
112     double x;
113     double y;
114     DragAction action;
115 };
116 
117 enum class BlurReason : int32_t {
118     FOCUS_SWITCH = 0,
119     WINDOW_BLUR = 1,
120     FRAME_DESTROY = 2,
121 };
122 
123 enum class FocusReason : int32_t {
124     FOCUS_DEFAULT = 0,
125     EVENT_REQUEST = 1,
126 };
127 
128 struct OHOS_NWEB_EXPORT NWebDOHConfig {
129     /*
130      * 0: OFF
131      * 1: AUTO
132      * 2: SECURE_ONLY
133      */
134     int dohMode = -1;
135     std::string dohConfig = "";
136 };
137 
138 enum class NestedScrollMode : int32_t {
139     SELF_ONLY = 0,
140     SELF_FIRST = 1,
141     PARENT_FIRST = 2,
142     PARALLEL = 3,
143 };
144 
145 using ScriptItems = std::map<std::string, std::vector<std::string>>;
146 using WebState = std::shared_ptr<std::vector<uint8_t>>;
147 using SetKeepScreenOn = std::function<void(bool)>;
148 
149 struct TouchPointInfo {
150     int id_ = 0;
151     double x_ = 0;
152     double y_ = 0;
153 };
154 
155 class OHOS_NWEB_EXPORT NWeb : public std::enable_shared_from_this<NWeb> {
156 public:
157     NWeb() = default;
158     virtual ~NWeb() = default;
159 
160     virtual void Resize(uint32_t width, uint32_t height, bool isKeyboard = false) = 0;
161 
162     /* lifecycle interface */
163     virtual void OnPause() const = 0;
164     virtual void OnContinue() const = 0;
165     virtual void OnDestroy() = 0;
166 
167     /* focus event */
168     virtual void OnFocus(const FocusReason& focusReason = FocusReason::FOCUS_DEFAULT) const = 0;
169     virtual void OnBlur(const BlurReason& blurReason) const = 0;
170 
171     /* event interface */
172     virtual void OnTouchPress(int32_t id, double x, double y, bool fromOverlay = false) = 0;
173     virtual void OnTouchRelease(int32_t id, double x = 0, double y = 0, bool fromOverlay = false) = 0;
174     virtual void OnTouchMove(int32_t id, double x, double y, bool fromOverlay = false) = 0;
175     virtual void OnTouchMove(const std::list<TouchPointInfo> touchPointInfoList, bool fromOverlay = false) = 0;
176     virtual void OnTouchCancel() = 0;
177     virtual void OnNavigateBack() = 0;
178     virtual bool SendKeyEvent(int32_t keyCode, int32_t keyAction) = 0;
179     virtual void SendMouseWheelEvent(double x, double y, double deltaX, double deltaY) = 0;
180     virtual void SendMouseEvent(int x, int y, int button, int action, int count) = 0;
181 
182     /**
183      * Load the given URL.
184      *
185      * @param url String: the URL of the resource to load. This value cannot be
186      * null.
187      *
188      * @return title string for the current page.
189      */
190     virtual int Load(const std::string& url) const = 0;
191 
192     /**
193      * Get whether this NWeb has a back history item.
194      *
195      * @return true if this NWeb has a back history item
196      */
197     virtual bool IsNavigatebackwardAllowed() const = 0;
198 
199     /**
200      * Get whether this NWeb has a forward history item.
201      *
202      * @return true if this NWeb has a forward history item
203      */
204     virtual bool IsNavigateForwardAllowed() const = 0;
205 
206     /**
207      * Get whether this NWeb has a back or forward history item for number of
208      * steps.
209      *
210      * @param numSteps int: the negative or positive number of steps to move the
211      * history.
212      * @return true if this NWeb has a forward history item
213      */
214     virtual bool CanNavigateBackOrForward(int numSteps) const = 0;
215 
216     /**
217      * Go back in the history of this NWeb.
218      *
219      */
220     virtual void NavigateBack() const = 0;
221 
222     /**
223      * Go forward in the history of this NWeb.
224      *
225      */
226     virtual void NavigateForward() const = 0;
227 
228     /**
229      * Goes to the history item that is the number of steps away from the current item.
230      *
231      */
232     virtual void NavigateBackOrForward(int step) const = 0;
233 
234     /**
235      * Delete back and forward history list.
236      */
237     virtual void DeleteNavigateHistory() = 0;
238 
239     /**
240      * Reload the current URL.
241      *
242      */
243     virtual void Reload() const = 0;
244 
245     /**
246      * Perform a zoom operation in this NWeb.
247      *
248      * @param zoomFactor float: the zoom factor to apply. The zoom factor will be
249      * clamped to the NWeb's zoom limits. This value must be in the range 0.01
250      * to 100.0 inclusive.
251      *
252      * @return the error id.
253      *
254      */
255     virtual int Zoom(float zoomFactor) const = 0;
256 
257     /**
258      * Performs a zooming in operation in this NWeb.
259      *
260      * @return the error id.
261      *
262      */
263     virtual int ZoomIn() const = 0;
264 
265     /**
266      * Performs a zooming out operation in this NWeb.
267      *
268      * @return the error id.
269      *
270      */
271     virtual int ZoomOut() const = 0;
272 
273     /**
274      * Stop the current load.
275      *
276      * @param code string: javascript code
277      */
278     virtual void Stop() const = 0;
279 
280     /**
281      * ExecuteJavaScript
282      *
283      */
284     virtual void ExecuteJavaScript(const std::string& code) const = 0;
285 
286     /**
287      * ExecuteJavaScript plus
288      *
289      * @param code string: javascript code
290      *
291      * @param callback NWebValueCallback: javascript running result
292      *
293      */
294     virtual void ExecuteJavaScript(
295         const std::string& code,
296         std::shared_ptr<NWebValueCallback<std::shared_ptr<NWebMessage>>> callback,
297         bool extention) const = 0;
298 
299     /**
300      * Get the NWebPreference object used to control the settings for this
301      * NWeb.
302      *
303      * @return a NWebPreference object that can be used to control this NWeb's
304      * settings This value cannot be null.
305      */
306     virtual const std::shared_ptr<NWebPreference> GetPreference() const = 0;
307 
308     /**
309      * Gets the web id.
310      *
311      * @return the web id
312      */
313     virtual unsigned int GetWebId() const = 0;
314 
315     /**
316      * Get the last hit test result.
317      *
318      * @return the last HitTestResult
319      */
320     virtual HitTestResult GetHitTestResult() const = 0;
321 
322     /**
323      * Set the background color for this view.
324      *
325      * @param color int: the color of the background
326      *
327      */
328     virtual void PutBackgroundColor(int color) const = 0;
329 
330     /**
331      * Sets the initla scale for the page.
332      *
333      * @param scale float: the initla scale of the page.
334      *
335      */
336     virtual void InitialScale(float scale) const = 0;
337 
338     /**
339      * Set the NWebDownloadCallback that will receive download event.
340      * This will replace the current handler.
341      *
342      * @param downloadListener NWebDownloadCallback.
343      */
344     virtual void PutDownloadCallback(
345         std::shared_ptr<NWebDownloadCallback> downloadListener) = 0;
346 
347      /**
348      * Set the NWebAccessibilityEventCallback that will receive accessibility event.
349      * This will replace the current handler.
350      *
351      * @param accessibilityEventListener NWebDownloadCallback.
352      */
353     virtual void PutAccessibilityEventCallback(
354         std::shared_ptr<NWebAccessibilityEventCallback> accessibilityEventListener) = 0;
355 
356      /**
357      * Set the accessibility id generator that will generate accessibility id for accessibility nodes in the web.
358      * This will replace the current handler.
359      *
360      * @param accessibilityIdGenerator Accessibility id generator.
361      */
362     virtual void PutAccessibilityIdGenerator(std::function<int64_t()> accessibilityIdGenerator) = 0;
363 
364     /**
365      * Set the NWebHandler that will receive various notifications and
366      * requests. This will replace the current handler.
367      *
368      * @param client NWebHandler: an implementation of NWebHandler. This value
369      * cannot be null.
370      */
371     virtual void SetNWebHandler(std::shared_ptr<NWebHandler> handler) = 0;
372 
373     /**
374      * Get the NWebHandler.
375      *
376      * @return Gets the NWebHandler.
377      */
378     virtual const std::shared_ptr<NWebHandler> GetNWebHandler() const = 0;
379 
380     /**
381      * Get the title for the current page.
382      *
383      * @return title string for the current page.
384      */
385     virtual std::string Title() = 0;
386 
387     /**
388      * Get the progress for the current page.
389      *
390      * @return progress for the current page.
391      */
392     virtual int PageLoadProgress() = 0;
393 
394     /**
395      * Get the height of the HTML content.
396      *
397      * @return the height of the HTML content.
398      */
399     virtual int ContentHeight() = 0;
400 
401     /**
402      * Get the current scale of this NWeb.
403      *
404      * @return the current scale
405      */
406     virtual float Scale() = 0;
407 
408     /**
409      * Load the given URL with additional HTTP headers, specified as a map
410      * from name to value. Note that if this map contains any of the headers that
411      * are set by default by this NWeb, such as those controlling caching,
412      * accept types or the User-Agent, their values may be overridden by this
413      * NWeb's defaults.
414      *
415      * @param url  String: the URL of the resource to load This value cannot be
416      * null.
417      *
418      * @param additionalHttpHeaders additionalHttpHeaders
419      */
420     virtual int Load(
421         std::string& url,
422         std::map<std::string, std::string> additionalHttpHeaders) = 0;
423 
424     /**
425      * Load the given data into this NWeb, using baseUrl as the base URL for
426      * the content. The base URL is used both to resolve relative URLs and when
427      * applying JavaScript's same origin policy. The historyUrl is used for the
428      * history entry.
429      *
430      * @param baseUrl  String: the URL to use as the page's base URL. If null
431      * defaults to 'about:blank'. This value may be null.
432      * @param data String: the URL to use as the page's base URL. If null defaults
433      * to 'about:blank'. This value may be null.
434      * @param mimeType String: the MIME type of the data, e.g. 'text/html'. This
435      * value may be null.
436      * @param encoding String: the encoding of the data This value may be null.
437      * @param historyUrl String: the URL to use as the history entry. If null
438      * defaults to 'about:blank'. If non-null, this must be a valid URL. This
439      * value may be null.
440      */
441     virtual int LoadWithDataAndBaseUrl(const std::string& baseUrl,
442                                         const std::string& data,
443                                         const std::string& mimeType,
444                                         const std::string& encoding,
445                                         const std::string& historyUrl) = 0;
446 
447     /**
448      * Load the given data into this NWeb.
449      *
450      * @param data String: the URL to use as the page's base URL. If null defaults
451      * to 'about:blank'. This value may be null.
452      * @param mimeType String: the MIME type of the data, e.g. 'text/html'. This
453      * value may be null.
454      * @param encoding String: the encoding of the data This value may be null.
455      */
456     virtual int LoadWithData(const std::string& data,
457                               const std::string& mimeType,
458                               const std::string& encoding) = 0;
459 
460     /**
461      * RegisterArkJSfunction
462      *
463      * @param object_name  String: objector name
464      * @param method_list vector<String>: vector list, method list
465      */
466     virtual void RegisterArkJSfunction(
467         const std::string& object_name,
468         const std::vector<std::string>& method_list) = 0;
469 
470     /**
471      * UnregisterArkJSfunction
472      *
473      * @param object_name  String: objector name
474      * @param method_list vector<String>: vector list, method list
475      */
476     virtual void UnregisterArkJSfunction(
477         const std::string& object_name,
478         const std::vector<std::string>& method_list) = 0;
479 
480     /**
481      * SetNWebJavaScriptResultCallBack
482      *
483      * @param callback  NWebJavaScriptResultCallBack: callback client
484      */
485     virtual void SetNWebJavaScriptResultCallBack(
486         std::shared_ptr<NWebJavaScriptResultCallBack> callback) = 0;
487 
488     /**
489      * Set the NWebFindCallback that will receive find event.
490      * This will replace the current handler.
491      *
492      * @param findListener NWebFindCallback : find callback
493      */
494     virtual void PutFindCallback(
495         std::shared_ptr<NWebFindCallback> findListener) = 0;
496 
497     /**
498      * Finds all instances of find on the page and highlights them,
499      * asynchronously.
500      *
501      * @param searchStr String: target string to find.
502      */
503     virtual void FindAllAsync(const std::string &searchStr) const = 0;
504 
505     /**
506      * Clears the highlighting surrounding text matches created by findAllAsync
507      */
508     virtual void ClearMatches() const = 0;
509 
510     /**
511      * Highlights and scrolls to the next match found by findAllAsync(String),
512      * wrapping around page boundaries as necessary.
513      *
514      * @param forward bool: find back or forward.
515      */
516     virtual void FindNext(const bool forward) const = 0;
517 
518     /**
519      * Saves the current view as a web archive.
520      *
521      * @param baseName the filename where the archive should be placed This value cannot be null.
522      * @param autoName if false, takes basename to be a file. If true, basename is assumed to be
523      * a directory in which a filename will be chosen according to the URL of the
524      * current page.
525      */
526     virtual void StoreWebArchive(const std::string &baseName, bool autoName,
527         std::shared_ptr<NWebValueCallback<std::string>> callback) const = 0;
528 
529     /**
530      * create two web message ports.
531      * @param ports the web message ports.
532      */
533     virtual void CreateWebMessagePorts(std::vector<std::string>& ports) = 0;
534 
535     /**
536      * post messag event to the html main frame.
537      * @param message the message
538      * @param ports the web message ports.
539      * @param uri the uri
540      */
541     virtual void PostWebMessage(std::string& message, std::vector<std::string>& ports, std::string& targetUri) = 0;
542 
543     /**
544      * close the message port.
545      * @param handle the web message port handle.
546      */
547     virtual void ClosePort(std::string& handle) = 0;
548 
549     /**
550      * use the port to send message.
551      * @param handle the web message port handle.
552      * @param data the message send to html5.
553      */
554     virtual void PostPortMessage(std::string& handle, std::shared_ptr<NWebMessage> data) = 0;
555 
556     /**
557      * set the callback of th port handle.
558      * @param handle the web message port handle.
559      * @param callback to receive the message when th other port post message.
560      */
561     virtual void SetPortMessageCallback(std::string& handle,
562         std::shared_ptr<NWebValueCallback<std::shared_ptr<NWebMessage>>> callback) = 0;
563 
564     /**
565      * send drag event to nweb.
566      * @param dragEvent the drag event information.
567      */
568     virtual void SendDragEvent(const DragEvent& dragEvent) const = 0;
569 
570     /**
571      * Clear ssl cache.
572      *
573      */
574     virtual void ClearSslCache() = 0;
575 
576     /**
577      * get web page url.
578      *
579      * @return web page url.
580      */
581     virtual std::string GetUrl() const = 0;
582 
583     /**
584      * Clears the client authentication certificate cache in the Web.
585      * @since 9
586      */
587     virtual void ClearClientAuthenticationCache() = 0;
588 
589     /**
590      * set the locale name of current system setting.
591      *
592      * @param locale the locale name of current system setting.
593      */
594     virtual void UpdateLocale(const std::string& language, const std::string& region) = 0;
595 
596     /**
597      * Get the original url of the current web page.
598      *
599      * @return original url
600      */
601     virtual const std::string GetOriginalUrl() const = 0;
602 
603     /**
604      * get the favicon of the request web page.
605      *
606      * @param data the raw data of the favicon.
607      * @param width the width of the favicon.
608      * @param height the height of the favicon.
609      * @param colorType the color type of the favicon.
610      * @param alphaType the alpha type of the favicon.
611      * @return true if get the favicon successfully, otherwise return false.
612      */
613     virtual bool GetFavicon(const void** data, size_t& width, size_t& height,
614         ImageColorType& colorType, ImageAlphaType& alphaType) = 0;
615 
616     /**
617      * Set the network status, just notify the webview to change the property of navigator.online.
618      *
619      * @param available the status of the network.
620      */
621     virtual void PutNetworkAvailable(bool available) = 0;
622 
623     /**
624      * web has image or not
625      *
626      * @param callback has image or not
627      */
628     virtual void HasImages(std::shared_ptr<NWebValueCallback<bool>> callback) = 0;
629 
630     /**
631      * web remove cache
632      *
633      * @param include_disk_files bool:if false, only tje RAM cache is removed
634      */
635     virtual void RemoveCache(bool include_disk_files) = 0;
636 
637     /**
638      * Get navigation history list
639      *
640      * @return navigation history list
641      */
642     virtual std::shared_ptr<NWebHistoryList> GetHistoryList() = 0;
643 
644     /**
645      * Set the NWebReleaseSurfaceCallback that will receive release surface
646      * event. This will replace the current handler.
647      *
648      * @param releaseSurfaceListener NWebReleaseSurfaceCallback.
649      */
650     virtual void PutReleaseSurfaceCallback(
651         std::shared_ptr<NWebReleaseSurfaceCallback> releaseSurfaceListener) = 0;
652 
653     /**
654      * Get Web back forward state.
655      *
656      * @return web back forward state.
657      */
658     virtual WebState SerializeWebState() = 0;
659 
660     /**
661      * Restore Web back forward state.
662      *
663      * @param web back forward state.
664      */
665     virtual bool RestoreWebState(WebState state) = 0;
666 
667     /**
668      * Move page up.
669      *
670      * @param top whether move to the top.
671      */
672     virtual void PageUp(bool top) = 0;
673 
674     /**
675      * Move page down.
676      *
677      * @param bottom whether move to the bottom.
678      */
679     virtual void PageDown(bool bottom) = 0;
680 
681     /**
682      * Scroll to the position.
683      *
684      * @param x the x of the position.
685      * @param y the y of the position.
686      */
687     virtual void ScrollTo(float x, float y) = 0;
688 
689     /**
690      * Scroll by the delta position.
691      *
692      * @param deltaX the deltaX of the position.
693      * @param deltaY the deltaY of the position.
694      */
695     virtual void ScrollBy(float deltaX, float deltaY) = 0;
696 
697     /**
698      * Slide by the speed.
699      *
700      * @param vx the vx of the speed.
701      * @param vy the vy of the speed.
702      */
703     virtual void SlideScroll(float vx, float vy) = 0;
704 
705     /**
706      * Get current website certificate.
707      *
708      * @param certChainData current website certificate array.
709      * @param isSingleCert true if only get one certificate of current website,
710      *                     false if get certificate chain of the website.
711      * @return true if get certificate successfully, otherwise false.
712     */
713     virtual bool GetCertChainDerData(std::vector<std::string>& certChainData, bool isSingleCert) = 0;
714 
715     /**
716      * Set screen offset.
717      *
718      * @param x the offset in x direction.
719      * @param y the offset in y direction.
720     */
721     virtual void SetScreenOffSet(double x, double y) = 0;
722 
723     /**
724      * Set audio muted.
725      *
726      * @param muted Aduio mute state.
727      */
728     virtual void SetAudioMuted(bool muted) = 0;
729 
730     /**
731      * Set should frame submission before draw.
732      *
733      * @param should whether wait render frame submission.
734     */
735     virtual void SetShouldFrameSubmissionBeforeDraw(bool should) = 0;
736 
737     /**
738      * Notify whether the popup window is initialized successfully.
739      *
740      * @param result whether success.
741      */
742     virtual void NotifyPopupWindowResult(bool result) = 0;
743 
744     /**
745      * Set audio resume interval.
746      *
747      * @param resumeInterval Aduio resume interval.
748      */
749     virtual void SetAudioResumeInterval(int32_t resumeInterval) = 0;
750 
751     /**
752      * Set audio exclusive state.
753      *
754      * @param audioExclusive Aduio exclusive state.
755      */
756     virtual void SetAudioExclusive(bool audioExclusive) = 0;
757 
758     /**
759      * Rigest the keep srceen on interface.
760      *
761      * @param windowId the window id.
762      * @param SetKeepScreenOn the screenon handle.
763      */
764     virtual void RegisterScreenLockFunction(int32_t windowId, const SetKeepScreenOn&& handle) = 0;
765 
766     /**
767      * UnRigest the keep srceen on interface.
768      *
769      * @param windowId the window id.
770      */
771     virtual void UnRegisterScreenLockFunction(int32_t windowId) = 0;
772 
773     /**
774      * Notify memory level.
775      *
776      * @param level the memory level.
777      */
778     virtual void NotifyMemoryLevel(int32_t level) = 0;
779 
780     /**
781      * Notify webview window status.
782      */
783     virtual void OnWebviewHide() const = 0;
784     virtual void OnWebviewShow() const = 0;
785 
786     /**
787      * Get the drag data.
788      *
789      * @return the data being dragged.
790     */
791     virtual std::shared_ptr<NWebDragData> GetOrCreateDragData() = 0;
792 
793     /**
794      * Prefetch the resources required by the page, but will not execute js or
795      * render the page.
796      *
797      * @param url  String: Which url to preresolve/preconnect.
798      * @param additionalHttpHeaders Additional HTTP request headers of the URL.
799      */
800     virtual void PrefetchPage(
801         std::string& url,
802         std::map<std::string, std::string> additionalHttpHeaders) = 0;
803 
804     /**
805      * Set the window id.
806      */
807     virtual void SetWindowId(uint32_t window_id) = 0;
808 
809     /**
810      * Notify that browser was occluded by other windows.
811      */
812     virtual void OnOccluded() const = 0;
813 
814     /**
815      * Notify that browser was unoccluded by other windows.
816      */
817     virtual void OnUnoccluded() const = 0;
818 
819     /**
820      * Set the token.
821      */
822     virtual void SetToken(void* token) = 0;
823 
824     /**
825      * Set the nested scroll mode.
826      */
827     virtual void SetNestedScrollMode(const NestedScrollMode& nestedScrollMode) = 0;
828 
829     /**
830      * Set enable lower the frame rate.
831      */
832     virtual void SetEnableLowerFrameRate(bool enabled) const = 0;
833 
834     /**
835      * Set the property values for width, height, and keyboard height.
836      */
837     virtual void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard) = 0;
838 
839     /**
840      * Set the virtual keyboard to override the web status.
841      */
842     virtual bool ShouldVirtualKeyboardOverlay() = 0;
843 
844     /**
845      * Set draw rectmessage
846      * @param x mean origin.x.
847      * @param y mean origin.y.
848      * @param width mean visible area'width.
849      * @param height mean visible area.height.
850      */
851     virtual void SetDrawRect(const int32_t x, const int32_t y, const int32_t width, const int32_t height) = 0;
852 
853     /**
854      * Set draw mode.
855      *
856     */
857     virtual void SetDrawMode(const int32_t mode) = 0;
858 
859     /**
860      * Create the web print document adapter.
861      */
862     virtual void* CreateWebPrintDocumentAdapter(const std::string& jobName) = 0;
863 
864     /**
865      * Loads the URL with postData using "POST" method into this WebView.
866      * If url is not a network URL, it will be loaded with loadUrl(String) instead.
867      *
868      * @param url String: the URL of the resource to load This value cannot be null.
869      * @param postData the data will be passed to "POST" request,
870      * whilch must be "application/x-www-form-urlencoded" encoded.
871      *
872      * @return title string for the current page.
873      */
874     virtual int PostUrl(const std::string& url, std::vector<char>& postData) = 0;
875 
876     /**
877      * Inject the JavaScript before WebView loads the DOM tree and run JavaScripts.
878      */
879     virtual void JavaScriptOnDocumentStart(const ScriptItems& scriptItems) = 0;
880 
881     /**
882      * Execute an accessibility action on an accessibility node in the browser.
883      * @param accessibilityId The id of the accessibility node.
884      * @param action The action to be performed on the accessibility node.
885      */
886     virtual void ExecuteAction(int64_t accessibilityId, uint32_t action) const = 0;
887 
888     /**
889      * Get the information of the focused accessibility node on the given accessibility node in the browser.
890      * @param accessibilityId Indicate the accessibility id of the parent node of the focused accessibility node.
891      * @param isAccessibilityFocus Indicate whether the focused accessibility node is accessibility focused or input
892      * focused.
893      * @param nodeInfo The obtained information of the accessibility node.
894      * @return true if get accessibility node info successfully, otherwise false.
895      */
896     virtual bool GetFocusedAccessibilityNodeInfo(
897         int64_t accessibilityId, bool isAccessibilityFocus, OHOS::NWeb::NWebAccessibilityNodeInfo& nodeInfo) const = 0;
898 
899     /**
900      * Get the information of the accessibility node by its accessibility id in the browser.
901      * @param accessibilityId The accessibility id of the accessibility node.
902      * @param nodeInfo The obtained information of the accessibility node.
903      * @return true if get accessibility node info successfully, otherwise false.
904      */
905     virtual bool GetAccessibilityNodeInfoById(
906         int64_t accessibilityId, OHOS::NWeb::NWebAccessibilityNodeInfo& nodeInfo) const = 0;
907 
908     /**
909      * Get the information of the accessibility node by focus move in the browser.
910      * @param accessibilityId The accessibility id of the original accessibility node.
911      * @param direction The focus move direction of the original accessibility node.
912      * @param nodeInfo The obtained information of the accessibility node.
913      * @return true if get accessibility node info successfully, otherwise false.
914      */
915     virtual bool GetAccessibilityNodeInfoByFocusMove(
916         int64_t accessibilityId, int32_t direction, OHOS::NWeb::NWebAccessibilityNodeInfo& nodeInfo) const = 0;
917 
918     /**
919      * Set the accessibility state in the browser.
920      * @param state Indicate whether the accessibility state is enabled or disabled.
921      */
922     virtual void SetAccessibilityState(bool state) = 0;
923 
924     /**
925      * RegisterArkJSfunctionExt
926      *
927      * @param object_name  String: objector name
928      * @param method_list  vector<String>: vector list, method list
929      * @param object_id    int32_t: object id
930      */
931     virtual void RegisterArkJSfunctionExt(
932         const std::string& object_name, const std::vector<std::string>& method_list, const int32_t object_id) = 0;
933 
934      /**
935      * Get whether need soft keyboard.
936      *
937      * @return true if need soft keyboard, otherwise false.
938      */
939     virtual bool NeedSoftKeyboard() const = 0;
940 
941     /**
942      * Discard the webview window.
943      * @return true if the discarding success, otherwise false.
944      */
945     virtual bool Discard() = 0;
946 
947     /**
948      * Reload the webview window that has been discarded before.
949      * @return true if the discarded window reload success, otherwise false.
950      */
951     virtual bool Restore() = 0;
952 
953     /**
954      * Get the security level of current page.
955      * @return security level for current page.
956      */
957     virtual int GetSecurityLevel() = 0;
958 
959     /**
960      * CallH5Function
961      *
962      * @param routingId         int32_t: the h5 frame routing id
963      * @param h5ObjectId        int32_t: the h5 side object id
964      * @param h5MethodName      string: the h5 side object method name
965      * @param args              vector<shared_ptr<NWebValue>>: the call args
966      */
967     virtual void CallH5Function(int32_t routingId, int32_t h5ObjectId, const std::string h5MethodName,
968         const std::vector<std::shared_ptr<NWebValue>> args) = 0;
969 
970     /**
971      * Get web weather has been set incognito mode.
972      *
973      * @return true if web is in incognito mode; otherwise fase.
974      */
975     virtual bool IsIncognitoMode() const = 0;
976 
977     /**
978      * Register native function.
979      */
980     virtual void RegisterNativeArkJSFunction(const char* objName, const char** methodName,
981         std::vector<std::function<char*(const char** argv, int32_t argc)>> callback, int32_t size) = 0;
982 
983     /**
984      * Unregister native function.
985      */
986     virtual void UnRegisterNativeArkJSFunction(const char* objName) = 0;
987 
988     /**
989      * Register native valide callback function.
990      */
991     virtual void RegisterNativeValideCallback(const char* webName, std::function<void(const char*)> callback) = 0;
992 
993     /**
994      * Register native destroy callback function.
995      */
996     virtual void RegisterNativeDestroyCallback(const char* webName, std::function<void(const char*)> callback) = 0;
997 
998     /**
999      * Inject the JavaScript after WebView loads the DOM tree and run JavaScripts.
1000      */
1001     virtual void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems) = 0;
1002 
1003    /**
1004      * Enable the ability to check website security risks.
1005      * Illegal and fraudulent websites are mandatory enabled and cann't be disabled by this function.
1006      */
1007     virtual void EnableSafeBrowsing(bool enable) = 0;
1008 
1009     /**
1010      * Get whether checking website security risks is enabled.
1011      * @return true if enable the ability to check website security risks else false.
1012      */
1013     virtual bool IsSafeBrowsingEnabled() = 0;
1014 };
1015 }  // namespace OHOS::NWeb
1016 
1017 #endif // NWEB_H
1018