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