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