diff --git a/Libraries/Components/WebView/WebView.android.js b/Libraries/Components/WebView/WebView.android.js index cd05617c855..1735adf631f 100644 --- a/Libraries/Components/WebView/WebView.android.js +++ b/Libraries/Components/WebView/WebView.android.js @@ -120,6 +120,13 @@ class WebView extends React.Component { */ javaScriptEnabled: PropTypes.bool, + /** + * Used on Android Lollipop and above only, third party cookies are enabled + * by default for WebView on Android Kitkat and below and on iOS + * @platform android + */ + thirdPartyCookiesEnabled: PropTypes.bool, + /** * Used on Android only, controls whether DOM Storage is enabled or not * @platform android @@ -192,6 +199,7 @@ class WebView extends React.Component { static defaultProps = { javaScriptEnabled : true, + thirdPartyCookiesEnabled: true, scalesPageToFit: true, saveFormDataDisabled: false }; @@ -253,6 +261,7 @@ class WebView extends React.Component { injectedJavaScript={this.props.injectedJavaScript} userAgent={this.props.userAgent} javaScriptEnabled={this.props.javaScriptEnabled} + thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled} domStorageEnabled={this.props.domStorageEnabled} messagingEnabled={typeof this.props.onMessage === 'function'} onMessage={this.onMessage} diff --git a/Libraries/Components/WebView/WebView.ios.js b/Libraries/Components/WebView/WebView.ios.js index 21f4397c04e..485af395619 100644 --- a/Libraries/Components/WebView/WebView.ios.js +++ b/Libraries/Components/WebView/WebView.ios.js @@ -285,6 +285,14 @@ class WebView extends React.Component { */ javaScriptEnabled: PropTypes.bool, + /** + * Boolean value to enable third party cookies in the `WebView`. Used on + * Android Lollipop and above only as third party cookies are enabled by + * default on Android Kitkat and below and on iOS. The default value is `true`. + * @platform android + */ + thirdPartyCookiesEnabled: PropTypes.bool, + /** * Boolean value to control whether DOM Storage is enabled. Used only in * Android. diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java index a22824294d9..5847515791e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java @@ -32,6 +32,7 @@ import android.webkit.WebViewClient; import android.webkit.JavascriptInterface; import android.webkit.ValueCallback; import android.webkit.WebSettings; +import android.webkit.CookieManager; import com.facebook.common.logging.FLog; import com.facebook.react.common.ReactConstants; @@ -370,6 +371,13 @@ public class ReactWebViewManager extends SimpleViewManager { view.getSettings().setJavaScriptEnabled(enabled); } + @ReactProp(name = "thirdPartyCookiesEnabled") + public void setThirdPartyCookiesEnabled(WebView view, boolean enabled) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + CookieManager.getInstance().setAcceptThirdPartyCookies(view, enabled); + } + } + @ReactProp(name = "scalesPageToFit") public void setScalesPageToFit(WebView view, boolean enabled) { view.getSettings().setUseWideViewPort(!enabled);