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