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