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
 
432
 
433
   @ReactProp(name = "incognito")
433
   @ReactProp(name = "incognito")
434
   public void setIncognito(WebView view, boolean enabled) {
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
     // Remove all previous cookies
440
     // Remove all previous cookies
436
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
441
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
437
       CookieManager.getInstance().removeAllCookies(null);
442
       CookieManager.getInstance().removeAllCookies(null);
441
 
446
 
442
     // Disable caching
447
     // Disable caching
443
     view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
448
     view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
444
-    view.getSettings().setAppCacheEnabled(!enabled);
449
+    view.getSettings().setAppCacheEnabled(false);
445
     view.clearHistory();
450
     view.clearHistory();
446
-    view.clearCache(enabled);
451
+    view.clearCache(true);
447
 
452
 
448
     // No form data or autofill enabled
453
     // No form data or autofill enabled
449
     view.clearFormData();
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
   @ReactProp(name = "source")
459
   @ReactProp(name = "source")