aw_settings.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ANDROID_WEBVIEW_BROWSER_AW_SETTINGS_H_
  5. #define ANDROID_WEBVIEW_BROWSER_AW_SETTINGS_H_
  6. #include "base/android/jni_weak_ref.h"
  7. #include "base/android/scoped_java_ref.h"
  8. #include "content/public/browser/web_contents_observer.h"
  9. namespace blink {
  10. namespace web_pref {
  11. struct WebPreferences;
  12. }
  13. } // namespace blink
  14. namespace android_webview {
  15. class AwRenderViewHostExt;
  16. class AwSettings : public content::WebContentsObserver {
  17. public:
  18. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.settings
  19. enum ForceDarkMode {
  20. FORCE_DARK_OFF = 0,
  21. FORCE_DARK_AUTO = 1,
  22. FORCE_DARK_ON = 2,
  23. };
  24. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.settings
  25. enum ForceDarkBehavior {
  26. FORCE_DARK_ONLY = 0,
  27. MEDIA_QUERY_ONLY = 1,
  28. PREFER_MEDIA_QUERY_OVER_FORCE_DARK = 2,
  29. };
  30. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.settings
  31. enum RequestedWithHeaderMode {
  32. NO_HEADER = 0,
  33. APP_PACKAGE_NAME = 1,
  34. CONSTANT_WEBVIEW = 2,
  35. };
  36. static AwSettings* FromWebContents(content::WebContents* web_contents);
  37. static bool GetAllowSniffingFileUrls();
  38. // Static accessor to get the currently configured default value based
  39. // on feature flags and trial config
  40. static RequestedWithHeaderMode GetDefaultRequestedWithHeaderMode();
  41. AwSettings(JNIEnv* env, jobject obj, content::WebContents* web_contents);
  42. ~AwSettings() override;
  43. bool GetJavaScriptCanOpenWindowsAutomatically();
  44. bool GetAllowThirdPartyCookies();
  45. // Called from Java. Methods with "Locked" suffix require that the settings
  46. // access lock is held during their execution.
  47. void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
  48. void PopulateWebPreferencesLocked(
  49. JNIEnv* env,
  50. const base::android::JavaParamRef<jobject>& obj,
  51. jlong web_prefs);
  52. void ResetScrollAndScaleState(
  53. JNIEnv* env,
  54. const base::android::JavaParamRef<jobject>& obj);
  55. void UpdateEverythingLocked(JNIEnv* env,
  56. const base::android::JavaParamRef<jobject>& obj);
  57. void UpdateInitialPageScaleLocked(
  58. JNIEnv* env,
  59. const base::android::JavaParamRef<jobject>& obj);
  60. void UpdateWillSuppressErrorStateLocked(
  61. JNIEnv* env,
  62. const base::android::JavaParamRef<jobject>& obj);
  63. void UpdateUserAgentLocked(JNIEnv* env,
  64. const base::android::JavaParamRef<jobject>& obj);
  65. void UpdateWebkitPreferencesLocked(
  66. JNIEnv* env,
  67. const base::android::JavaParamRef<jobject>& obj);
  68. void UpdateFormDataPreferencesLocked(
  69. JNIEnv* env,
  70. const base::android::JavaParamRef<jobject>& obj);
  71. void UpdateRendererPreferencesLocked(
  72. JNIEnv* env,
  73. const base::android::JavaParamRef<jobject>& obj);
  74. void UpdateCookiePolicyLocked(
  75. JNIEnv* env,
  76. const base::android::JavaParamRef<jobject>& obj);
  77. void UpdateOffscreenPreRasterLocked(
  78. JNIEnv* env,
  79. const base::android::JavaParamRef<jobject>& obj);
  80. void UpdateAllowFileAccessLocked(
  81. JNIEnv* env,
  82. const base::android::JavaParamRef<jobject>& obj);
  83. void PopulateWebPreferences(blink::web_pref::WebPreferences* web_prefs);
  84. bool GetAllowFileAccess();
  85. bool IsForceDarkApplied(JNIEnv* env,
  86. const base::android::JavaParamRef<jobject>& obj);
  87. void SetEnterpriseAuthenticationAppLinkPolicyEnabled(
  88. JNIEnv* env,
  89. const base::android::JavaParamRef<jobject>& obj,
  90. jboolean enabled);
  91. bool GetEnterpriseAuthenticationAppLinkPolicyEnabled(
  92. JNIEnv* env,
  93. const base::android::JavaParamRef<jobject>& obj);
  94. inline bool enterprise_authentication_app_link_policy_enabled() {
  95. return enterprise_authentication_app_link_policy_enabled_;
  96. }
  97. private:
  98. AwRenderViewHostExt* GetAwRenderViewHostExt();
  99. void UpdateEverything();
  100. // WebContentsObserver overrides:
  101. void RenderViewHostChanged(content::RenderViewHost* old_host,
  102. content::RenderViewHost* new_host) override;
  103. void WebContentsDestroyed() override;
  104. bool renderer_prefs_initialized_;
  105. bool javascript_can_open_windows_automatically_;
  106. bool allow_third_party_cookies_;
  107. bool allow_file_access_;
  108. bool enterprise_authentication_app_link_policy_enabled_;
  109. JavaObjectWeakGlobalRef aw_settings_;
  110. };
  111. } // namespace android_webview
  112. #endif // ANDROID_WEBVIEW_BROWSER_AW_SETTINGS_H_