• 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_PREFERENCE_H
17 #define NWEB_PREFERENCE_H
18 
19 #include <string>
20 #include "nweb_export.h"
21 
22 namespace OHOS::NWeb {
23 class OHOS_NWEB_EXPORT NWebPreference {
24 public:
25     NWebPreference() = default;
26     virtual ~NWebPreference() = default;
27     enum class AccessMode { ALWAYS_ALLOW = 0, NEVER_ALLOW = 1, COMPATIBILITY_MODE = 2 };
28     /* synchronous set NWebPreference and web preferences */
29     /**
30      * Enables or disables content URL(content from a content provider installed
31      * in the system) access within NWeb. The default is true.
32      */
33     virtual void PutEnableContentAccess(bool flag) = 0;
34 
35     /**
36      * Enables or disables file system access within NWeb. But files in the
37      * path of AppData are still accessible. The default is false.
38      */
39     virtual void PutEnableRawFileAccess(bool flag) = 0;
40 
41     /**
42      * Put whether to allow JavaScript running in a file scheme URL to access
43      * content from other file scheme URLs. The default is false.
44      */
45     virtual void PutEnableRawFileAccessFromFileURLs(bool flag) = 0;
46 
47     /**
48      * Put whether to allow JavaScript running in a file scheme URL to access
49      * content from any origin. This includes access to content from other file
50      * scheme URLs. See {@link #PutEnableRawFileAccessFromFileURLs}. The default is
51      * false.
52      */
53     virtual void PutEnableUniversalAccessFromFileURLs(bool flag) = 0;
54 
55     /**
56      * Put whether to block the NWeb from loading image resources from the
57      * network (http and https URI schemes). This settings is invalid, if {@link
58      * #IsImageLoadingAllowed} returns false. The default is false.
59      */
60     virtual void PutLoadImageFromNetworkDisabled(bool flag) = 0;
61 
62     /**
63      * Put the cursive font family name. The default is "cursive".
64      *
65      * @param font a font family name
66      */
67     virtual void PutCursiveFontFamilyName(std::string font) = 0;
68 
69     /**
70      * Enables or disables the database storage API. The default is false.
71      * This setting is global and effectd all NWeb instances in a
72      * process. You must modify this before loading any NWeb page so that the
73      * changes won't be ignored.
74      */
75     virtual void PutDatabaseAllowed(bool flag) = 0;
76 
77     /**
78      * Put the size of default fixed font. The default is 13.
79      *
80      * @param size A positive integer that ranges from 1 to 72. Any number outside
81      *             the specified range will be pinned.
82      */
83     virtual void PutDefaultFixedFontSize(int size) = 0;
84 
85     /**
86      * Put the size of default font. The default is 16.
87      *
88      * @param size A positive integer that ranges from 1 to 72. Any number outside
89      *             the specified range will be pinned.
90      */
91     virtual void PutDefaultFontSize(int size) = 0;
92 
93     /**
94      * Put the default text encoding format that uses to decode html pages.
95      * The default is "UTF-8".
96      *
97      * @param the text encoding format
98      */
99     virtual void PutDefaultTextEncodingFormat(std::string encoding) = 0;
100 
101     /**
102      * Enables or disables the DOM storage API. The default value is false.
103      */
104     virtual void PutDomStorageEnabled(bool flag) = 0;
105 
106     /**
107      * Put the fantasy font family name. The default is "fantasy".
108      *
109      * @param font a font family name
110      */
111     virtual void PutFantasyFontFamilyName(std::string font) = 0;
112 
113     /**
114      * Put the fixed font family name. The default is "monospace".
115      *
116      * @param font a font family name
117      */
118     virtual void PutFixedFontFamilyName(std::string font) = 0;
119 
120     /**
121      * Enables or disables the force dark mode for this NWeb.
122      *
123      * @param forceDark True if set the force dark mode enabled for this NWeb.
124      */
125     virtual void PutForceDarkModeEnabled(int forceDark) = 0;
126 
127     /**
128      * Put whether JavaScript can open windows by JavaScript. This applies to the
129      * JavaScript function {@code window.open()}. The default is false.
130      */
131     virtual void PutIsCreateWindowsByJavaScriptAllowed(bool flag) = 0;
132 
133     /**
134      * Put whether the NWeb can execute JavaScript. The default is false.
135      */
136     virtual void PutJavaScriptEnabled(bool flag) = 0;
137 
138     /**
139      * Put whether the NWeb can load image. The default is true.
140      */
141     virtual void PutImageLoadingAllowed(bool flag) = 0;
142 
143     /**
144      * Put the lower limit of the minimum font size. The default is 8.
145      *
146      * @param size A positive integer that ranges from 1 to 72. Any number outside
147      *             the specified range will be pinned.
148      */
149     virtual void PutFontSizeLowerLimit(int size) = 0;
150 
151     /**
152      * Put the lower limit of the minimum logical font size. The default is 8.
153      *
154      * @param size A positive integer that ranges from 1 to 72. Any number outside
155      *             the specified range will be pinned.
156      */
157     virtual void PutLogicalFontSizeLowerLimit(int size) = 0;
158 
159     /**
160      * Sets whether the WebView loads pages in overview mode, that is, zooms out the
161      * content to fit on screen by width.
162      *
163      */
164     virtual void PutLoadWithOverviewMode(bool flag) = 0;
165 
166     /**
167      * Put the sans-serif font family name. The default is "sans-serif".
168      *
169      * @param font a font family name
170      */
171     virtual void PutSansSerifFontFamilyName(std::string font) = 0;
172 
173     /**
174      * Put the serif font family name. The default is "serif".
175      *
176      * @param font a font family name
177      */
178     virtual void PutSerifFontFamilyName(std::string font) = 0;
179 
180     /**
181      * Put the standard font family name. The default is "sans-serif".
182      *
183      * @param font a font family name
184      */
185     virtual void PutStandardFontFamilyName(std::string font) = 0;
186 
187     /**
188      * Put the user-agent string to the nweb. If it is null or empty,
189      * NWeb will use the system default value. Changing the user-agent
190      * while loading a web page will cause the web page to reload.
191      *
192      * @param ua user-agent string. The value may be null.
193      */
194     virtual void PutUserAgent(std::string ua) = 0;
195 
196     /**
197      * Put the zoom percentage of the page text. The default is 100.
198      *
199      * @param textZoom the zoom percentage of the page text
200      */
201     virtual void PutZoomingForTextFactor(int textZoom) = 0;
202 
203     /**
204      * Put whether the NWeb can get geolocation. The default is true.
205      * To get geolocation, an application must have permission to access
206      * the device location, see ohos.permission.LOCATION and
207      * ohos.permission.LOCATION_IN_BACKGROUND and implement the
208      * NWebHandler#OnGeolocationShow callback to receive notifications of
209      * the location request via the JavaScript Geolocation API.
210      */
211     virtual void PutGeolocationAllowed(bool flag) = 0;
212 
213     /**
214      * Put the NWeb's behavior when a secure origin attempts to load a
215      * resource from an insecure origin. The default is NEVER_ALLOW.
216      *
217      * @param mode The mixed content mode to use.
218      */
219     virtual void PutAccessModeForSecureOriginLoadFromInsecure(
220         AccessMode mode) = 0;
221 
222     /**
223      * Put whether the NWeb supports zooming. The default is true.
224      */
225     virtual void PutZoomingFunctionEnabled(bool flag) = 0;
226 
227     /**
228      * Put whether the NWeb block loading resources from the network. The
229      * default value is false if the hap has the
230      * ohos.permission.INTERNET permission, otherwise it is true.If the
231      * hap does not have the ohos.permission.INTERNET permission,
232      * attempts to set a value of false will be failed.
233      */
234     virtual void PutBlockNetwork(bool flag) = 0;
235 
236     enum CacheModeFlag {
237         USE_DEFAULT = 0,
238         USE_CACHE_ELSE_NETWORK,
239         USE_NO_CACHE,
240         USE_CACHE_ONLY
241     };
242     /**
243      * PutCacheMode
244      */
245     virtual void PutCacheMode(CacheModeFlag flag) = 0;
246 
247     /**
248      * Put whether the NWeb allows to remote debugging, default value is false.
249      */
250     virtual void PutWebDebuggingAccess(bool flag) = 0;
251 
252     /**
253      * Put whether media playback needs to be triggered by user gestures, default value is false.
254      */
255     virtual void PutMediaPlayGestureAccess(bool flag) = 0;
256 
257     /**
258      * Put whether smooth mode is supported.
259      */
260     virtual void PutPinchSmoothMode(bool flag) = 0;
261 
262     /**
263      * Whether multiple windows are supported, the default value is false.
264      */
265     virtual void PutMultiWindowAccess(bool flag) = 0;
266 
267     /* get methods */
268     /**
269      * Get if content URL(content from a content provider installed
270      * in the system) access within NWeb is supported.
271      *
272      * @see PutEnableContentAccess
273      */
274     virtual bool EnableContentAccess() = 0;
275 
276     /**
277      * Get if file system access within NWeb is supported. Notified files in the
278      * path of AppData are always accessible.
279      *
280      * @see PutEnableRawFileAccess
281      */
282     virtual bool EnableRawFileAccess() = 0;
283 
284     /**
285      * Get if JavaScript running in a file scheme URL to access
286      * content from other file scheme URLs is supported.
287      *
288      * @see PutEnableRawFileAccessFromFileURLs
289      */
290     virtual bool EnableRawFileAccessFromFileURLs() = 0;
291 
292     /**
293      * Get if JavaScript running in a file scheme URL to access
294      * content from any origin is supported. This includes access to content from other file
295      * scheme URLs.
296      *
297      * @see PutEnableUniversalAccessFromFileURLs
298      */
299     virtual bool EnableUniversalAccessFromFileURLs() = 0;
300 
301     /**
302      * Get if the NWeb from loading image resources from the
303      * network (http and https URI schemes) is supported.
304      *
305      * @see PutLoadImageFromNetworkDisabled
306      */
307     virtual bool IsLoadImageFromNetworkDisabled() = 0;
308 
309     /**
310      * Get the cursive font family name.
311      *
312      * @see PutCursiveFontFamilyName
313      */
314     virtual std::string CursiveFontFamilyName() = 0;
315 
316     /**
317      * Get if the database storage API is supported.
318      *
319      * @see PutDatabaseAllowed
320      */
321     virtual bool IsDataBaseEnabled() = 0;
322 
323     /**
324      * Get the size of default fixed font.
325      *
326      * @see PutDefaultFixedFontSize
327      */
328     virtual int DefaultFixedFontSize() = 0;
329 
330     /**
331      * Get the size of default font.
332      *
333      * @see PutDefaultFontSize
334      */
335     virtual int DefaultFontSize() = 0;
336 
337     /**
338      * Get the default text encoding format that uses to decode html pages.
339      *
340      * @see PutDefaultTextEncodingFormat
341      */
342     virtual std::string DefaultTextEncodingFormat() = 0;
343 
344     /**
345      * Get the default user-agent string to the nweb.
346      * An instance of NWeb could use a different User-Agent that
347      * NWebPreference#PutUserAgent(String) set to.
348      *
349      * @see PutUserAgent
350      */
351     virtual std::string DefaultUserAgent() = 0;
352 
353     /**
354      * Get if the DOM storage API is supported.
355      *
356      * @see PutDomStorageEnabled
357      */
358     virtual bool IsDomStorageEnabled() = 0;
359 
360     /**
361      * Get the fantasy font family name.
362      *
363      * @see PutFantasyFontFamilyName
364      */
365     virtual std::string FantasyFontFamilyName() = 0;
366 
367     /**
368      * Get the fixed font family name.
369      *
370      * @see PutFixedFontFamilyName
371      */
372     virtual std::string FixedFontFamilyName() = 0;
373 
374     /**
375      * Get whether the force dark mode is enabled for this NWeb.
376      *
377      * @see PutForceDarkModeEnabled
378      */
379     virtual int ForceDarkModeEnabled() = 0;
380 
381     /**
382      * Get if JavaScript can open windows.
383      *
384      * @see PutIsCreateWindowsByJavaScriptAllowed
385      */
386     virtual bool IsCreateWindowsByJavaScriptAllowed() = 0;
387 
388     /**
389      * Get if the NWeb can execute JavaScript.
390      *
391      * @see PutJavaScriptEnabled
392      */
393     virtual bool IsJavaScriptAllowed() = 0;
394 
395     /**
396      * Get if the NWeb can load image.
397      *
398      * @see PutImageLoadingAllowed
399      */
400     virtual bool IsImageLoadingAllowed() = 0;
401 
402     /**
403      * Get the lower limit of the minimum font size.
404      *
405      * @see PutFontSizeLowerLimit
406      */
407     virtual int FontSizeLowerLimit() = 0;
408 
409     /**
410      * Get the lower limit of the minimum logical font size.
411      *
412      * @see PutLogicalFontSizeLowerLimit
413      */
414     virtual int LogicalFontSizeLowerLimit() = 0;
415 
416     /**
417      * Get the swith for the overview mode.
418      *
419      * @see PutLoadWithOverviewMode
420      */
421     virtual bool IsLoadWithOverviewMode() = 0;
422 
423     /**
424      * Get the sans-serif font family name.
425      *
426      * @see PutSansSerifFontFamilyName
427      */
428     virtual std::string SansSerifFontFamilyName() = 0;
429 
430     /**
431      * Get the serif font family name.
432      *
433      * @see PutSerifFontFamilyName
434      */
435     virtual std::string SerifFontFamilyName() = 0;
436 
437     /**
438      * Get the standard font family name.
439      *
440      * @see PutStandardFontFamilyName
441      */
442     virtual std::string StandardFontFamilyName() = 0;
443 
444     /**
445      * Get the user-agent string to the nweb.
446      *
447      * @see PutUserAgent
448      */
449     virtual std::string UserAgent() = 0;
450 
451     /**
452      * Get the zoom percentage of the page text.
453      *
454      * @see PutZoomingForTextFactor
455      */
456     virtual int ZoomingForTextFactor() = 0;
457 
458     /**
459      * Get if the NWeb can get geolocation.
460      *
461      * @see PutGeolocationAllowed
462      */
463     virtual bool GeolocationAllowed() = 0;
464 
465     /**
466      * Get the NWeb's behavior when a secure origin attempts to load a
467      * resource from an insecure origin.
468      *
469      * @see PutAccessModeForSecureOriginLoadFromInsecure
470      */
471     virtual AccessMode AccessModeForSecureOriginLoadFromInsecure() = 0;
472 
473     /**
474      * Get if the NWeb supports zooming.
475      *
476      * @see PutZoomingFunctionEnabled
477      */
478     virtual bool ZoomingfunctionEnabled() = 0;
479 
480     /**
481      * Get if the NWeb block loading resources from the network.
482      *
483      * @see PutBlockNetwork
484      */
485     virtual bool IsNetworkBlocked() = 0;
486 
487     /**
488      * Get cache mode
489      *
490      * @see PutCacheMode
491      */
492     virtual CacheModeFlag CacheMode() = 0;
493 
494     /**
495      * Get if the NWeb allow to remote debugging.
496      *
497      * @see PutWebDebuggingAccess
498      */
499     virtual bool IsWebDebuggingAccess() = 0;
500 
501     /**
502      * Get whether media playback needs to be triggered by user gestures.
503      */
504     virtual bool GetMediaPlayGestureAccess() = 0;
505 
506     /**
507      * Get whether smooth mode is supported.
508      */
509     virtual bool GetPinchSmoothMode() = 0;
510 
511     /**
512      * Get if the NWeb supported to multiple windows.
513      *
514      * @see PutMultiWindowAccess
515      */
516     virtual bool IsMultiWindowAccess() = 0;
517 
518     /**
519      * Enables or disables the dark mode prefer-color-scheme for this NWeb.
520      *
521      * @param darkScheme True if set the dark mode prefer-color-scheme enabled for this NWeb.
522      */
523     virtual void PutDarkSchemeEnabled(int darkScheme) = 0;
524 
525     /**
526      * Get whether the dark mode prefer-color-scheme is enabled for this NWeb.
527      *
528      * @see PutDarkSchemeEnabled
529      */
530     virtual int DarkSchemeEnabled() = 0;
531 
532     /**
533      * Get whether enable horizontal scroll bar.
534      *
535      * @see PutHorizontalScrollBarAcces
536      */
537     virtual bool IsHorizontalScrollBarAccess() = 0;
538 
539     /**
540      * Get whether enable vertical scroll bar.
541      *
542      * @see PutVerticalScrollBarAcces
543      */
544     virtual bool IsVerticalScrollBarAccess() = 0;
545 
546     /**
547      * Put whether the horizontal scroll bar. The default is true.
548      */
549     virtual void PutHorizontalScrollBarAccess(bool flag) = 0;
550 
551     /**
552      * Put whether the vertical scroll bar. The default is true.
553      */
554     virtual void PutVerticalScrollBarAccess(bool flag) = 0;
555 
556     /**
557      * Get the color of scrollbar.
558      *
559      * @see PutScrollbarColor
560      */
561     virtual uint32_t GetScrollBarColor() = 0;
562 
563     /**
564      * Put the UX color of scrollbar.
565      */
566     virtual void PutScrollBarColor(uint32_t colorValue) = 0;
567 
568 };
569 }  // namespace OHOS::NWeb
570 #endif  // NWEB_PREFERENCE_H
571