Browse Source

fix(incognito): Ensures that incognito doesn't clear cookies when not enabled (#1447 by @jasonkellydk)

Co-authored-by: Jason Kelly <jason.kelly@isobar.com>
Co-authored-by: Jamon Holmgren <jamonholmgren@gmail.com>
Co-authored-by: Jason Safaiyeh <safaiyeh@protonmail.com>
Jason Kelly 4 years ago
parent
commit
63c584c647
No account linked to committer's email address

+ 9
- 4
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

@@ -432,6 +432,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
432 432
 
433 433
   @ReactProp(name = "incognito")
434 434
   public void setIncognito(WebView view, boolean enabled) {
435
+    // Don't do anything when incognito is disabled
436
+    if (!enabled) {
437
+      return;
438
+    }
439
+
435 440
     // Remove all previous cookies
436 441
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
437 442
       CookieManager.getInstance().removeAllCookies(null);
@@ -441,14 +446,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
441 446
 
442 447
     // Disable caching
443 448
     view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
444
-    view.getSettings().setAppCacheEnabled(!enabled);
449
+    view.getSettings().setAppCacheEnabled(false);
445 450
     view.clearHistory();
446
-    view.clearCache(enabled);
451
+    view.clearCache(true);
447 452
 
448 453
     // No form data or autofill enabled
449 454
     view.clearFormData();
450
-    view.getSettings().setSavePassword(!enabled);
451
-    view.getSettings().setSaveFormData(!enabled);
455
+    view.getSettings().setSavePassword(false);
456
+    view.getSettings().setSaveFormData(false);
452 457
   }
453 458
 
454 459
   @ReactProp(name = "source")