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 for this NWeb. 124 */ 125 virtual void PutDarkModeEnabled(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 /* get methods */ 253 /** 254 * Get if content URL(content from a content provider installed 255 * in the system) access within NWeb is supported. 256 * 257 * @see PutEnableContentAccess 258 */ 259 virtual bool EnableContentAccess() = 0; 260 261 /** 262 * Get if file system access within NWeb is supported. Notified files in the 263 * path of AppData are always accessible. 264 * 265 * @see PutEnableRawFileAccess 266 */ 267 virtual bool EnableRawFileAccess() = 0; 268 269 /** 270 * Get if JavaScript running in a file scheme URL to access 271 * content from other file scheme URLs is supported. 272 * 273 * @see PutEnableRawFileAccessFromFileURLs 274 */ 275 virtual bool EnableRawFileAccessFromFileURLs() = 0; 276 277 /** 278 * Get if JavaScript running in a file scheme URL to access 279 * content from any origin is supported. This includes access to content from other file 280 * scheme URLs. 281 * 282 * @see PutEnableUniversalAccessFromFileURLs 283 */ 284 virtual bool EnableUniversalAccessFromFileURLs() = 0; 285 286 /** 287 * Get if the NWeb from loading image resources from the 288 * network (http and https URI schemes) is supported. 289 * 290 * @see PutLoadImageFromNetworkDisabled 291 */ 292 virtual bool IsLoadImageFromNetworkDisabled() = 0; 293 294 /** 295 * Get the cursive font family name. 296 * 297 * @see PutCursiveFontFamilyName 298 */ 299 virtual std::string CursiveFontFamilyName() = 0; 300 301 /** 302 * Get if the database storage API is supported. 303 * 304 * @see PutDatabaseAllowed 305 */ 306 virtual bool IsDataBaseEnabled() = 0; 307 308 /** 309 * Get the size of default fixed font. 310 * 311 * @see PutDefaultFixedFontSize 312 */ 313 virtual int DefaultFixedFontSize() = 0; 314 315 /** 316 * Get the size of default font. 317 * 318 * @see PutDefaultFontSize 319 */ 320 virtual int DefaultFontSize() = 0; 321 322 /** 323 * Get the default text encoding format that uses to decode html pages. 324 * 325 * @see PutDefaultTextEncodingFormat 326 */ 327 virtual std::string DefaultTextEncodingFormat() = 0; 328 329 /** 330 * Get the default user-agent string to the nweb. 331 * An instance of NWeb could use a different User-Agent that 332 * NWebPreference#PutUserAgent(String) set to. 333 * 334 * @see PutUserAgent 335 */ 336 virtual std::string DefaultUserAgent() = 0; 337 338 /** 339 * Get if the DOM storage API is supported. 340 * 341 * @see PutDomStorageEnabled 342 */ 343 virtual bool IsDomStorageEnabled() = 0; 344 345 /** 346 * Get the fantasy font family name. 347 * 348 * @see PutFantasyFontFamilyName 349 */ 350 virtual std::string FantasyFontFamilyName() = 0; 351 352 /** 353 * Get the fixed font family name. 354 * 355 * @see PutFixedFontFamilyName 356 */ 357 virtual std::string FixedFontFamilyName() = 0; 358 359 /** 360 * Get if the dark mode for this NWeb is supported. 361 * 362 * @see PutDarkModeEnabled 363 */ 364 virtual int DarkModeEnabled() = 0; 365 366 /** 367 * Get if JavaScript can open windows. 368 * 369 * @see PutIsCreateWindowsByJavaScriptAllowed 370 */ 371 virtual bool IsCreateWindowsByJavaScriptAllowed() = 0; 372 373 /** 374 * Get if the NWeb can execute JavaScript. 375 * 376 * @see PutJavaScriptEnabled 377 */ 378 virtual bool IsJavaScriptAllowed() = 0; 379 380 /** 381 * Get if the NWeb can load image. 382 * 383 * @see PutImageLoadingAllowed 384 */ 385 virtual bool IsImageLoadingAllowed() = 0; 386 387 /** 388 * Get the lower limit of the minimum font size. 389 * 390 * @see PutFontSizeLowerLimit 391 */ 392 virtual int FontSizeLowerLimit() = 0; 393 394 /** 395 * Get the lower limit of the minimum logical font size. 396 * 397 * @see PutLogicalFontSizeLowerLimit 398 */ 399 virtual int LogicalFontSizeLowerLimit() = 0; 400 401 /** 402 * Get the swith for the overview mode. 403 * 404 * @see PutLoadWithOverviewMode 405 */ 406 virtual bool IsLoadWithOverviewMode() = 0; 407 408 /** 409 * Get the sans-serif font family name. 410 * 411 * @see PutSansSerifFontFamilyName 412 */ 413 virtual std::string SansSerifFontFamilyName() = 0; 414 415 /** 416 * Get the serif font family name. 417 * 418 * @see PutSerifFontFamilyName 419 */ 420 virtual std::string SerifFontFamilyName() = 0; 421 422 /** 423 * Get the standard font family name. 424 * 425 * @see PutStandardFontFamilyName 426 */ 427 virtual std::string StandardFontFamilyName() = 0; 428 429 /** 430 * Get the user-agent string to the nweb. 431 * 432 * @see PutUserAgent 433 */ 434 virtual std::string UserAgent() = 0; 435 436 /** 437 * Get the zoom percentage of the page text. 438 * 439 * @see PutZoomingForTextFactor 440 */ 441 virtual int ZoomingForTextFactor() = 0; 442 443 /** 444 * Get if the NWeb can get geolocation. 445 * 446 * @see PutGeolocationAllowed 447 */ 448 virtual bool GeolocationAllowed() = 0; 449 450 /** 451 * Get the NWeb's behavior when a secure origin attempts to load a 452 * resource from an insecure origin. 453 * 454 * @see PutAccessModeForSecureOriginLoadFromInsecure 455 */ 456 virtual AccessMode AccessModeForSecureOriginLoadFromInsecure() = 0; 457 458 /** 459 * Get if the NWeb supports zooming. 460 * 461 * @see PutZoomingFunctionEnabled 462 */ 463 virtual bool ZoomingfunctionEnabled() = 0; 464 465 /** 466 * Get if the NWeb block loading resources from the network. 467 * 468 * @see PutBlockNetwork 469 */ 470 virtual bool IsNetworkBlocked() = 0; 471 472 /** 473 * Get cache mode 474 * 475 * @see PutCacheMode 476 */ 477 virtual CacheModeFlag CacheMode() = 0; 478 479 /** 480 * Get if the NWeb allow to remote debugging. 481 * 482 * @see PutWebDebuggingAccess 483 */ 484 virtual bool IsWebDebuggingAccess() = 0; 485 }; 486 } // namespace OHOS::NWeb 487 #endif // NWEB_PREFERENCE_H 488