// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef ANDROID_WEBVIEW_BROWSER_AW_SETTINGS_H_ #define ANDROID_WEBVIEW_BROWSER_AW_SETTINGS_H_ #include "base/android/jni_weak_ref.h" #include "base/android/scoped_java_ref.h" #include "content/public/browser/web_contents_observer.h" namespace blink { namespace web_pref { struct WebPreferences; } } // namespace blink namespace android_webview { class AwRenderViewHostExt; class AwSettings : public content::WebContentsObserver { public: // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.settings enum ForceDarkMode { FORCE_DARK_OFF = 0, FORCE_DARK_AUTO = 1, FORCE_DARK_ON = 2, }; // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.settings enum ForceDarkBehavior { FORCE_DARK_ONLY = 0, MEDIA_QUERY_ONLY = 1, PREFER_MEDIA_QUERY_OVER_FORCE_DARK = 2, }; // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.settings enum RequestedWithHeaderMode { NO_HEADER = 0, APP_PACKAGE_NAME = 1, CONSTANT_WEBVIEW = 2, }; static AwSettings* FromWebContents(content::WebContents* web_contents); static bool GetAllowSniffingFileUrls(); // Static accessor to get the currently configured default value based // on feature flags and trial config static RequestedWithHeaderMode GetDefaultRequestedWithHeaderMode(); AwSettings(JNIEnv* env, jobject obj, content::WebContents* web_contents); ~AwSettings() override; bool GetJavaScriptCanOpenWindowsAutomatically(); bool GetAllowThirdPartyCookies(); // Called from Java. Methods with "Locked" suffix require that the settings // access lock is held during their execution. void Destroy(JNIEnv* env, const base::android::JavaParamRef& obj); void PopulateWebPreferencesLocked( JNIEnv* env, const base::android::JavaParamRef& obj, jlong web_prefs); void ResetScrollAndScaleState( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateEverythingLocked(JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateInitialPageScaleLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateWillSuppressErrorStateLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateUserAgentLocked(JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateWebkitPreferencesLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateFormDataPreferencesLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateRendererPreferencesLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateCookiePolicyLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateOffscreenPreRasterLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void UpdateAllowFileAccessLocked( JNIEnv* env, const base::android::JavaParamRef& obj); void PopulateWebPreferences(blink::web_pref::WebPreferences* web_prefs); bool GetAllowFileAccess(); bool IsForceDarkApplied(JNIEnv* env, const base::android::JavaParamRef& obj); void SetEnterpriseAuthenticationAppLinkPolicyEnabled( JNIEnv* env, const base::android::JavaParamRef& obj, jboolean enabled); bool GetEnterpriseAuthenticationAppLinkPolicyEnabled( JNIEnv* env, const base::android::JavaParamRef& obj); inline bool enterprise_authentication_app_link_policy_enabled() { return enterprise_authentication_app_link_policy_enabled_; } private: AwRenderViewHostExt* GetAwRenderViewHostExt(); void UpdateEverything(); // WebContentsObserver overrides: void RenderViewHostChanged(content::RenderViewHost* old_host, content::RenderViewHost* new_host) override; void WebContentsDestroyed() override; bool renderer_prefs_initialized_; bool javascript_can_open_windows_automatically_; bool allow_third_party_cookies_; bool allow_file_access_; bool enterprise_authentication_app_link_policy_enabled_; JavaObjectWeakGlobalRef aw_settings_; }; } // namespace android_webview #endif // ANDROID_WEBVIEW_BROWSER_AW_SETTINGS_H_