Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add android version for incognito web view
  • Loading branch information
Kaushik Iska committed Jan 31, 2019
commit 02f74bb290252dab70cf230d316697f197719cd6
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.flutter.plugins.webviewflutter;

import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
Expand All @@ -12,6 +16,7 @@
import java.util.Map;

public class FlutterWebView implements PlatformView, MethodCallHandler {

private final WebView webView;
private final MethodChannel methodChannel;

Expand Down Expand Up @@ -131,6 +136,11 @@ private void applySettings(Map<String, Object> settings) {
case "jsMode":
updateJsMode((Integer) settings.get(key));
break;
case "incognito":
boolean isIncognito = (Boolean) settings.get(key);
if (isIncognito) {
Incognito.makeWebViewIncognito(webView);
}
default:
throw new IllegalArgumentException("Unknown WebView setting: " + key);
}
Expand All @@ -151,5 +161,6 @@ private void updateJsMode(int mode) {
}

@Override
public void dispose() {}
public void dispose() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.flutter.plugins.webviewflutter;

import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import io.flutter.util.Preconditions;

public final class Incognito {

private Incognito() {
// Utility cache. Do not instantiate.
}

public static void makeWebViewIncognito(WebView webView) {
Preconditions.checkNotNull(webView);
clearAndDisableAppCache(webView);
clearAndDisableCookies();
clearHistory(webView);
}

private static void clearAndDisableCookies() {
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(null);
} else {
cookieManager.removeAllCookie();
}
cookieManager.setAcceptCookie(false);
}

private static void clearAndDisableAppCache(WebView webView) {
webView.clearCache(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setAppCacheEnabled(false);
}

/**
* Tells this WebView to clear its internal back/forward list. Not the global history.
*/
private static void clearHistory(WebView webView) {
webView.clearHistory();
}

}