1 /*
2  * Copyright (c) 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 ARK_WEB_PREFERENCE_H_
17 #define ARK_WEB_PREFERENCE_H_
18 #pragma once
19 
20 #include "base/include/ark_web_base_ref_counted.h"
21 #include "base/include/ark_web_types.h"
22 
23 namespace OHOS::ArkWeb {
24 
25 /*--ark web(source=webcore)--*/
26 class ArkWebPreference : public virtual ArkWebBaseRefCounted {
27 public:
28     /**
29      * @brief Get the user-agent string to the nweb.
30      *
31      * @see PutUserAgent
32      */
33     /*--ark web()--*/
34     virtual ArkWebString UserAgent() = 0;
35 
36     /**
37      * @brief Put the user-agent string to the nweb. If it is null or empty,
38      *        webview will use the system default value. Changing the user-agent
39      *        while loading a web page will cause the web page to reload.
40      *
41      * @param ua user-agent string. The value may be null.
42      */
43     /*--ark web()--*/
44     virtual void PutUserAgent(const ArkWebString& ua) = 0;
45 
46     /**
47      * @brief Get the default user-agent string to the nweb. An instance of
48      *        WebView could use a different User-Agent that
49      *        NWebPreference#PutUserAgent(String) set to.
50      *
51      * @see PutUserAgent
52      */
53     /*--ark web()--*/
54     virtual ArkWebString DefaultUserAgent() = 0;
55 
56     /**
57      * @brief Get cache mode
58      *
59      * @see PutCacheMode
60      */
61     /*--ark web()--*/
62     virtual int CacheMode() = 0;
63 
64     /**
65      * @brief PutCacheMode
66      */
67     /*--ark web()--*/
68     virtual void PutCacheMode(int flag) = 0;
69 
70     /**
71      * @brief Get if the WebView block loading resources from the network.
72      *
73      * @see PutBlockNetwork
74      */
75     /*--ark web()--*/
76     virtual bool IsNetworkBlocked() = 0;
77 
78     /**
79      * @brief Put whether the WebView block loading resources from the network.
80      *        The default value is false if the hap has the
81      *        ohos.permission.INTERNET permission, otherwise it is true.If the hap
82      *        does not have the ohos.permission.INTERNET permission, attempts to
83      *        set a value of false will be failed.
84      */
85     /*--ark web()--*/
86     virtual void PutBlockNetwork(bool flag) = 0;
87 
88     /**
89      * @brief Get the color of scrollbar.
90      *
91      * @see PutScrollbarColor
92      */
93     /*--ark web()--*/
94     virtual uint32_t GetScrollBarColor() = 0;
95 
96     /**
97      * @brief Put the UX color of scrollbar.
98      */
99     /*--ark web()--*/
100     virtual void PutScrollBarColor(uint32_t color_value) = 0;
101 
102     /**
103      * @brief Get over-scroll Mode.
104      *
105      * @see PutScrollbarColor
106      */
107     /*--ark web()--*/
108     virtual int GetOverscrollMode() = 0;
109 
110     /**
111      * @brief Put over-scroll Mode.
112      */
113     /*--ark web()--*/
114     virtual void PutOverscrollMode(int over_scroll_mode) = 0;
115 
116     /**
117      * @brief Get the size of default font.
118      *
119      * @see PutDefaultFontSize
120      */
121     /*--ark web()--*/
122     virtual int DefaultFontSize() = 0;
123 
124     /**
125      * @brief Put the size of default font. The default is 16.
126      *
127      * @param size A positive integer that ranges from 1 to 72. Any number outside
128      *        the specified range will be pinned.
129      */
130     /*--ark web()--*/
131     virtual void PutDefaultFontSize(int size) = 0;
132 
133     /**
134      * @brief Get whether smooth mode is supported.
135      */
136     /*--ark web()--*/
137     virtual bool GetPinchSmoothMode() = 0;
138 
139     /**
140      * @brief Put whether smooth mode is supported.
141      */
142     /*--ark web()--*/
143     virtual void PutPinchSmoothMode(bool flag) = 0;
144 
145     /**
146      * @brief Get if the database storage API is supported.
147      *
148      * @see PutDatabaseAllowed
149      */
150     /*--ark web()--*/
151     virtual bool IsDataBaseEnabled() = 0;
152 
153     /**
154      * @brief Enables or disables the database storage API. The default is false.
155      *        This setting is global and effectd all WebView instances in a
156      *        process. You must modify this before loading any webView page so
157      *        that the changes won't be ignored.
158      */
159     /*--ark web()--*/
160     virtual void PutDatabaseAllowed(bool flag) = 0;
161 
162     /**
163      * @brief Get whether support multi window.
164      *
165      * @see PutMultiWindowAccess
166      */
167     /*--ark web()--*/
168     virtual bool IsMultiWindowAccess() = 0;
169 
170     /**
171      * @brief Put whether support multi window, default value is false.
172      */
173     /*--ark web()--*/
174     virtual void PutMultiWindowAccess(bool flag) = 0;
175 
176     /**
177      * @brief Get if the WebView can execute JavaScript.
178      *
179      * @see PutJavaScriptEnabled
180      */
181     /*--ark web()--*/
182     virtual bool IsJavaScriptAllowed() = 0;
183 
184     /**
185      * @brief Put whether the WebView can execute JavaScript. The default is
186      *        false.
187      */
188     /*--ark web()--*/
189     virtual void PutJavaScriptEnabled(bool flag) = 0;
190 
191     /**
192      * @brief Get whether the dark mode prefer-color-scheme is enabled for this
193      *        NWeb.
194      *
195      * @see PutDarkSchemeEnabled
196      */
197     /*--ark web()--*/
198     virtual int DarkSchemeEnabled() = 0;
199 
200     /**
201      * @brief Enables or disables the dark mode prefer-color-scheme for this NWeb.
202      *
203      * @param dark_scheme True if set the dark mode prefer-color-scheme enabled
204      *        for this NWeb.
205      */
206     /*--ark web()--*/
207     virtual void PutDarkSchemeEnabled(int dark_scheme) = 0;
208 
209     /**
210      * @brief Get if the DOM storage API is supported.
211      *
212      * @see PutDomStorageEnabled
213      */
214     /*--ark web()--*/
215     virtual bool IsDomStorageEnabled() = 0;
216 
217     /**
218      * @brief Enables or disables the DOM storage API. The default value is false.
219      */
220     /*--ark web()--*/
221     virtual void PutDomStorageEnabled(bool flag) = 0;
222 
223     /**
224      * @brief Get the lower limit of the minimum font size.
225      *
226      * @see PutFontSizeLowerLimit
227      */
228     /*--ark web()--*/
229     virtual int FontSizeLowerLimit() = 0;
230 
231     /**
232      * @brief Put the lower limit of the minimum font size. The default is 8.
233      *
234      * @param size A positive integer that ranges from 1 to 72. Any number outside
235      *        the specified range will be pinned.
236      */
237     /*--ark web()--*/
238     virtual void PutFontSizeLowerLimit(int size) = 0;
239 
240     /**
241      * @brief Get if the WebView can get geo location.
242      *
243      * @see PutGeoLocationAllowed
244      */
245     /*--ark web()--*/
246     virtual bool GeoLocationAllowed() = 0;
247 
248     /**
249      * @brief Put whether the WebView can get geo location. The default is true.
250      *        To get geo location, an application must have permission to access
251      *        the device location, see ohos.permission.LOCATION and
252      *        ohos.permission.LOCATION_IN_BACKGROUND and implement the
253      *        NWebHandler#OnGeoLocationShow callback to receive notifications of
254      *        the location request via the JavaScript Geo Location API.
255      */
256     /*--ark web()--*/
257     virtual void PutGeoLocationAllowed(bool flag) = 0;
258 
259     /**
260      * @brief Get if the NWeb can be debugging.
261      *
262      * @see PutWebDebuggingAccess
263      */
264     /*--ark web()--*/
265     virtual bool IsWebDebuggingAccess() = 0;
266 
267     /**
268      * @brief Put whether the NWeb can be debugging, default value is false.
269      */
270     /*--ark web()--*/
271     virtual void PutWebDebuggingAccess(bool flag) = 0;
272 
273     /**
274      * @brief Get if content URL(content from a content provider installed in the
275      *        system) access within WebView is supported.
276      *
277      * @see PutEnableContentAccess
278      */
279     /*--ark web()--*/
280     virtual bool EnableContentAccess() = 0;
281 
282     /**
283      * @brief Enables or disables content URL(content from a content provider
284      *        installed in the system) access within WebView. The default is true.
285      */
286     /*--ark web()--*/
287     virtual void PutEnableContentAccess(bool flag) = 0;
288 
289     /**
290      * @brief Get if file system access within WebView is supported. Notified
291      *        files in the path of AppData are always accessible.
292      *
293      * @see PutEnableRawFileAccess
294      */
295     /*--ark web()--*/
296     virtual bool EnableRawFileAccess() = 0;
297 
298     /**
299      * @brief Enables or disables file system access within WebView. But files in
300      *        the path of AppData are still accessible. The default is false.
301      */
302     /*--ark web()--*/
303     virtual void PutEnableRawFileAccess(bool flag) = 0;
304 
305     /**
306      * @brief Get if the WebView can load image.
307      *
308      * @see PutImageLoadingAllowed
309      */
310     /*--ark web()--*/
311     virtual bool IsImageLoadingAllowed() = 0;
312 
313     /**
314      * @brief Put whether the WebView can load image. The default is true.
315      */
316     /*--ark web()--*/
317     virtual void PutImageLoadingAllowed(bool flag) = 0;
318 
319     /**
320      * @brief Get the fixed font family name.
321      *
322      * @see PutFixedFontFamilyName
323      */
324     /*--ark web()--*/
325     virtual ArkWebString FixedFontFamilyName() = 0;
326 
327     /**
328      * @brief Put the fixed font family name. The default is "monospace".
329      *
330      * @param font a font family name
331      */
332     /*--ark web()--*/
333     virtual void PutFixedFontFamilyName(const ArkWebString& font) = 0;
334 
335     /**
336      * @brief Get the serif font family name.
337      *
338      * @see PutSerifFontFamilyName
339      */
340     /*--ark web()--*/
341     virtual ArkWebString SerifFontFamilyName() = 0;
342 
343     /**
344      * @brief Put the serif font family name. The default is "serif".
345      *
346      * @param font a font family name
347      */
348     /*--ark web()--*/
349     virtual void PutSerifFontFamilyName(const ArkWebString& font) = 0;
350 
351     /**
352      * @brief Get the zoom percentage of the page text.
353      *
354      * @see PutZoomingForTextFactor
355      */
356     /*--ark web()--*/
357     virtual int ZoomingForTextFactor() = 0;
358 
359     /**
360      * @brief Put the zoom percentage of the page text. The default is 100.
361      *
362      * @param text_zoom the zoom percentage of the page text
363      */
364     /*--ark web()--*/
365     virtual void PutZoomingForTextFactor(int text_zoom) = 0;
366 
367     /**
368      * @brief Get whether the force dark mode is enabled for this NWeb.
369      *
370      * @see PutForceDarkModeEnabled
371      */
372     /*--ark web()--*/
373     virtual int ForceDarkModeEnabled() = 0;
374 
375     /**
376      * @brief Enables or disables the force dark mode for this NWeb.
377      *
378      * @param force_dark True if set the force dark mode enabled for this NWeb.
379      */
380     /*--ark web()--*/
381     virtual void PutForceDarkModeEnabled(int force_dark) = 0;
382 
383     /**
384      * @brief Get the swith for the overview mode.
385      *
386      * @see PutLoadWithOverviewMode
387      */
388     /*--ark web()--*/
389     virtual bool IsLoadWithOverviewMode() = 0;
390 
391     /**
392      * @brief Sets whether the WebView loads pages in overview mode, that is,
393      *        zooms out the content to fit on screen by width.
394      */
395     /*--ark web()--*/
396     virtual void PutLoadWithOverviewMode(bool flag) = 0;
397 
398     /**
399      * @brief Get the size of default fixed font.
400      *
401      * @see PutDefaultFixedFontSize
402      */
403     /*--ark web()--*/
404     virtual int DefaultFixedFontSize() = 0;
405 
406     /**
407      * @brief Put the size of default fixed font. The default is 13.
408      *
409      * @param size A positive integer that ranges from 1 to 72. Any number outside
410      *        the specified range will be pinned.
411      */
412     /*--ark web()--*/
413     virtual void PutDefaultFixedFontSize(int size) = 0;
414 
415     /**
416      * @brief Get the cursive font family name.
417      *
418      * @see PutCursiveFontFamilyName
419      */
420     /*--ark web()--*/
421     virtual ArkWebString CursiveFontFamilyName() = 0;
422 
423     /**
424      * @brief Put the cursive font family name. The default is "cursive".
425      *
426      * @param font a font family name
427      */
428     /*--ark web()--*/
429     virtual void PutCursiveFontFamilyName(const ArkWebString& font) = 0;
430 
431     /**
432      * @brief Get the fantasy font family name.
433      *
434      * @see PutFantasyFontFamilyName
435      */
436     /*--ark web()--*/
437     virtual ArkWebString FantasyFontFamilyName() = 0;
438 
439     /**
440      * @brief Put the fantasy font family name. The default is "fantasy".
441      *
442      * @param font a font family name
443      */
444     /*--ark web()--*/
445     virtual void PutFantasyFontFamilyName(const ArkWebString& font) = 0;
446 
447     /**
448      * @brief Get if the WebView supports zooming.
449      *
450      * @see PutZoomingFunctionEnabled
451      */
452     /*--ark web()--*/
453     virtual bool ZoomingfunctionEnabled() = 0;
454 
455     /**
456      * @brief Put whether the WebView supports zooming. The default is true.
457      */
458     /*--ark web()--*/
459     virtual void PutZoomingFunctionEnabled(bool flag) = 0;
460 
461     /**
462      * @brief Get whether media playback needs to be triggered by user gestures.
463      *
464      * @see PutMediaPlayGestureAccess
465      */
466     /*--ark web()--*/
467     virtual bool GetMediaPlayGestureAccess() = 0;
468 
469     /**
470      * @brief Put whether media playback needs to be triggered by user gestures,
471      *        default value is false.
472      */
473     /*--ark web()--*/
474     virtual void PutMediaPlayGestureAccess(bool flag) = 0;
475 
476     /**
477      * @brief Get the standard font family name.
478      *
479      * @see PutStandardFontFamilyName
480      */
481     /*--ark web()--*/
482     virtual ArkWebString StandardFontFamilyName() = 0;
483 
484     /**
485      * @brief Put the standard font family name. The default is "sans-serif".
486      *
487      * @param font a font family name
488      */
489     /*--ark web()--*/
490     virtual void PutStandardFontFamilyName(const ArkWebString& font) = 0;
491 
492     /**
493      * @brief Get the sans-serif font family name.
494      *
495      * @see PutSansSerifFontFamilyName
496      */
497     /*--ark web()--*/
498     virtual ArkWebString SansSerifFontFamilyName() = 0;
499 
500     /**
501      * @brief Put the sans-serif font family name. The default is "sans-serif".
502      *
503      * @param font a font family name
504      */
505     /*--ark web()--*/
506     virtual void PutSansSerifFontFamilyName(const ArkWebString& font) = 0;
507 
508     /**
509      * @brief Get whether enable vertical scroll bar.
510      *
511      * @see PutVerticalScrollBarAccess
512      */
513     /*--ark web()--*/
514     virtual bool IsVerticalScrollBarAccess() = 0;
515 
516     /**
517      * @brief Put whether enable vertical scroll bar, default value is false.
518      */
519     /*--ark web()--*/
520     virtual void PutVerticalScrollBarAccess(bool flag) = 0;
521 
522     /**
523      * @brief Get whether enable horizontal scroll bar.
524      *
525      * @see PutHorizontalScrollBarAccess
526      */
527     /*--ark web()--*/
528     virtual bool IsHorizontalScrollBarAccess() = 0;
529 
530     /**
531      * @brief Put whether enable horizontal scroll bar, default value is false.
532      */
533     /*--ark web()--*/
534     virtual void PutHorizontalScrollBarAccess(bool flag) = 0;
535 
536     /**
537      * @brief Get the lower limit of the minimum logical font size.
538      *
539      * @see PutLogicalFontSizeLowerLimit
540      */
541     /*--ark web()--*/
542     virtual int LogicalFontSizeLowerLimit() = 0;
543 
544     /**
545      * @brief Put the lower limit of the minimum logical font size. The default
546      *        is 8.
547      *
548      * @param size A positive integer that ranges from 1 to 72. Any number outside
549      *        the specified range will be pinned.
550      */
551     /*--ark web()--*/
552     virtual void PutLogicalFontSizeLowerLimit(int size) = 0;
553 
554     /**
555      * @brief Get the default text encoding format that uses to decode html pages.
556      *
557      * @see PutDefaultTextEncodingFormat
558      */
559     /*--ark web()--*/
560     virtual ArkWebString DefaultTextEncodingFormat() = 0;
561 
562     /**
563      * @brief Put the default text encoding format that uses to decode html pages.
564      *        The default is "UTF-8".
565      *
566      * @param the text encoding format
567      */
568     /*--ark web()--*/
569     virtual void PutDefaultTextEncodingFormat(const ArkWebString& encoding) = 0;
570 
571     /**
572      * @brief Get if the WebView from loading image resources from the network
573      *        (http and https URI schemes) is supported.
574      *
575      * @see PutLoadImageFromNetworkDisabled
576      */
577     /*--ark web()--*/
578     virtual bool IsLoadImageFromNetworkDisabled() = 0;
579 
580     /**
581      * @brief Put whether to block the WebView from loading image resources from
582      *        the network (http and https URI schemes). This settings is invalid,
583      *        if {@link #IsImageLoadingAllowed} returns false. The default is
584      *        false.
585      */
586     /*--ark web()--*/
587     virtual void PutLoadImageFromNetworkDisabled(bool flag) = 0;
588 
589     /**
590      * @brief Get if JavaScript running in a file scheme URL to access content
591      *        from other file scheme URLs is supported.
592      *
593      * @see PutEnableRawFileAccessFromFileURLs
594      */
595     /*--ark web()--*/
596     virtual bool EnableRawFileAccessFromFileURLs() = 0;
597 
598     /**
599      * @brief Put whether to allow JavaScript running in a file scheme URL to
600      *        access content from other file scheme URLs. The default is false.
601      */
602     /*--ark web()--*/
603     virtual void PutEnableRawFileAccessFromFileURLs(bool flag) = 0;
604 
605     /**
606      * @brief Get if JavaScript running in a file scheme URL to access content
607      *        from any origin is supported. This includes access to content from
608      *        other file scheme URLs.
609      *
610      * @see PutEnableUniversalAccessFromFileURLs
611      */
612     /*--ark web()--*/
613     virtual bool EnableUniversalAccessFromFileURLs() = 0;
614 
615     /**
616      * @brief Put whether to allow JavaScript running in a file scheme URL to
617      *        access content from any origin. This includes access to content from
618      *        other file scheme URLs. See {@link
619      *        #PutEnableRawFileAccessFromFileURLs}. The default is false.
620      */
621     /*--ark web()--*/
622     virtual void PutEnableUniversalAccessFromFileURLs(bool flag) = 0;
623 
624     /**
625      * @brief Get if JavaScript can open windows.
626      *
627      * @see PutIsCreateWindowsByJavaScriptAllowed
628      */
629     /*--ark web()--*/
630     virtual bool IsCreateWindowsByJavaScriptAllowed() = 0;
631 
632     /**
633      * @brief Put whether JavaScript can open windows by JavaScript. This applies
634      *        to the JavaScript function {@code window.open()}. The default is
635      *        false.
636      */
637     /*--ark web()--*/
638     virtual void PutIsCreateWindowsByJavaScriptAllowed(bool flag) = 0;
639 
640     /**
641      * @brief Get the WebView's behavior when a secure origin attempts to load a
642      *        resource from an insecure origin.
643      *
644      * @see PutAccessModeForSecureOriginLoadFromInsecure
645      */
646     /*--ark web()--*/
647     virtual int AccessModeForSecureOriginLoadFromInsecure() = 0;
648 
649     /**
650      * @brief Put the WebView's behavior when a secure origin attempts to load a
651      *        resource from an insecure origin. The default is NEVER_ALLOW.
652      *
653      * @param mode The mixed content mode to use.
654      */
655     /*--ark web()--*/
656     virtual void PutAccessModeForSecureOriginLoadFromInsecure(int mode) = 0;
657 
658     /**
659      * @brief Get copy-option Mode.
660      *
661      * @see PutCopyOptionMode
662      */
663     /*--ark web()--*/
664     virtual int GetCopyOptionMode() = 0;
665 
666     /**
667      * @brief Put copy-option.
668      */
669     /*--ark web()--*/
670     virtual void PutCopyOptionMode(int copyOption) = 0;
671 
672     /**
673      * @brief Put whether the embed mode. The default is false.
674      */
675     /*--ark web()--*/
676     virtual void SetNativeEmbedMode(bool flag) = 0;
677 
678     /**
679      * @brief Get whether the embed mode. The default is false.
680      */
681     /*--ark web()--*/
682     virtual bool GetNativeEmbedMode() = 0;
683 
684     /**
685      * @brief Register native embed rule. The default pattern is ["embed", "native/"].
686      */
687     /*--ark web()--*/
688     virtual void RegisterNativeEmbedRule(const ArkWebString& tag, const ArkWebString& type) = 0;
689 
690     /**
691      * @brief Set whether the scroll is enabled.
692      */
693     /*--ark web()--*/
694     virtual void SetScrollable(bool enable) = 0;
695 
696     /**
697      * @brief Get whether the scroll is enabled.
698      */
699     /*--ark web()--*/
700     virtual bool GetScrollable() = 0;
701 
702     /**
703      * @brief Put whether enable horizontal scroll bar, default value is false.
704      */
705     /*--ark web()--*/
706     virtual void PutTextAutosizingEnabled(bool flag) = 0;
707 
708     /**
709      * @brief Set whether to support the viewport attribute of the meta tag in the frontend page.
710      */
711     /*--ark web()--*/
712     virtual void SetViewportEnable(bool enable) = 0;
713 
714     /**
715      * @brief Set native video player config.
716      */
717     /*--ark web()--*/
718     virtual void SetNativeVideoPlayerConfig(bool enable, bool shouldOverlay) = 0;
719 
720     /**
721      * @brief Get surfaceId.
722      */
723     /*--ark web()--*/
724     virtual ArkWebString GetSurfaceId() = 0;
725 
726     /**
727      * @brief Set surfaceId.
728      */
729     /*--ark web()--*/
730     virtual void SetSurfaceId(const ArkWebString& surfaceId) = 0;
731 
732     /**
733      * @brief Set whether the scollbar is displayed.
734      */
735     /*--ark web()--*/
736     virtual void PutOverlayScrollbarEnabled(bool enable) = 0;
737 
738     /**
739      * @brief Set whether the scroll is enabled.
740      */
741     /*--ark web()--*/
742     virtual void SetScrollable(bool enable, int32_t scrollType) = 0;
743 
744     /**
745      * @brief Set whether to support the blur when the keyboard is hidden by manual.
746      * @param enable set whether blur is allowed.
747      */
748     /*--ark web()--*/
749     virtual void SetBlurOnKeyboardHideMode(int enable) = 0;
750 };
751 
752 } // namespace OHOS::ArkWeb
753 
754 #endif // ARK_WEB_PREFERENCE_H_
755