diff options
author | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2014-01-18 19:22:47 +0000 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-11-07 13:57:46 -0800 |
commit | 8d464436b97de1aace612fbcb4cb40af6f3eec83 (patch) | |
tree | 57631743403f391d0a1ba83a774ba7d8eca628e1 | |
parent | 6a5657f340b059c92c4e085ba95705c356779780 (diff) | |
download | packages_apps_browser-8d464436b97de1aace612fbcb4cb40af6f3eec83.zip packages_apps_browser-8d464436b97de1aace612fbcb4cb40af6f3eec83.tar.gz packages_apps_browser-8d464436b97de1aace612fbcb4cb40af6f3eec83.tar.bz2 |
Implement client-side incognito mode
Since WebView deprecated privateBrowsing in API 17 (and killed it
for good in API 19), we were left without incognito in the Browser
app. Follow the docs' recommendations and implement it with "manual"
control of privacy-related engine options
* Internally track incognito state for tabs
* Disable all forms of storage and cache on private webviews
* Disable all cookie activity while an incognito tab is active
* Stop trying to use the deprecated "privateBrowsing" argument
when creating webViews, always set to false
Change-Id: I23f2e34ee125635bba8981f0711ba4986a9beaab
-rw-r--r-- | src/com/android/browser/BrowserWebView.java | 32 | ||||
-rw-r--r-- | src/com/android/browser/BrowserWebViewFactory.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 21 |
3 files changed, 51 insertions, 3 deletions
diff --git a/src/com/android/browser/BrowserWebView.java b/src/com/android/browser/BrowserWebView.java index 3e3672c..eabb0e0 100644 --- a/src/com/android/browser/BrowserWebView.java +++ b/src/com/android/browser/BrowserWebView.java @@ -21,6 +21,7 @@ import android.graphics.Canvas; import android.util.AttributeSet; import android.view.View; import android.webkit.WebChromeClient; +import android.webkit.WebSettings; import android.webkit.WebStorage; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -41,6 +42,7 @@ public class BrowserWebView extends WebView { private OnScrollChangedListener mOnScrollChangedListener; private WebChromeClient mWebChromeClient; private WebViewClient mWebViewClient; + private boolean mPrivateBrowsing = false; /** * @param context @@ -50,7 +52,9 @@ public class BrowserWebView extends WebView { */ public BrowserWebView(Context context, AttributeSet attrs, int defStyle, Map<String, Object> javascriptInterfaces, boolean privateBrowsing) { - super(context, attrs, defStyle, javascriptInterfaces, privateBrowsing); + super(context, attrs, defStyle, javascriptInterfaces, false); + // WebView doesn't support it, but save it here for internal use + mPrivateBrowsing = privateBrowsing; } /** @@ -60,7 +64,9 @@ public class BrowserWebView extends WebView { */ public BrowserWebView( Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { - super(context, attrs, defStyle, privateBrowsing); + super(context, attrs, defStyle, false); + // WebView doesn't support it, but save it here for internal use + mPrivateBrowsing = privateBrowsing; } /** @@ -153,4 +159,26 @@ public class BrowserWebView extends WebView { super.destroy(); } + @Override + public boolean isPrivateBrowsingEnabled() { + return mPrivateBrowsing; + } + + /* Make sure the local webview remains in sync, since the engine won't retain that data */ + public void setPrivateBrowsing(boolean state) { + mPrivateBrowsing = state; + if (state) { + // Disable ALL the things + this.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); + this.getSettings().setAppCacheEnabled(false); + this.getSettings().setDomStorageEnabled(false); + this.getSettings().setDatabaseEnabled(false); + this.getSettings().setGeolocationEnabled(false); + this.getSettings().setSaveFormData(false); + this.getSettings().setSavePassword(false); + this.getSettings().setSupportMultipleWindows(false); + this.getSettings().setAppCacheMaxSize(0); + this.clearHistory(); + } + } } diff --git a/src/com/android/browser/BrowserWebViewFactory.java b/src/com/android/browser/BrowserWebViewFactory.java index 2349c28..64e4da7 100644 --- a/src/com/android/browser/BrowserWebViewFactory.java +++ b/src/com/android/browser/BrowserWebViewFactory.java @@ -47,6 +47,7 @@ public class BrowserWebViewFactory implements WebViewFactory { public WebView createWebView(boolean privateBrowsing) { WebView w = instantiateWebView(null, android.R.attr.webViewStyle, privateBrowsing); initWebViewSettings(w); + ((BrowserWebView)w).setPrivateBrowsing(privateBrowsing); return w; } diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index a4d2ce0..907f7a1 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -347,6 +347,11 @@ class Tab implements PictureListener { view.isPrivateBrowsingEnabled(), url, favicon); mLoadStartTime = SystemClock.uptimeMillis(); + if (isPrivateBrowsingEnabled()) { + // Ignore all the cookies while an incognito tab has activity + CookieManager.getInstance().setAcceptCookie(false); + } + // If we start a touch icon load and then load a new page, we don't // want to cancel the current touch icon loader. But, we do want to // create a new one when the touch icon url is known. @@ -382,6 +387,10 @@ class Tab implements PictureListener { if (!isPrivateBrowsingEnabled()) { LogTag.logPageFinishedLoading( url, SystemClock.uptimeMillis() - mLoadStartTime); + } else { + // Ignored all the cookies while an incognito tab had activity, + // restore default after completion + CookieManager.getInstance().setAcceptCookie(mSettings.acceptCookies()); } syncCurrentState(view, url); mWebViewController.onPageFinished(Tab.this); @@ -1016,7 +1025,11 @@ class Tab implements PictureListener { */ @Override public void getVisitedHistory(final ValueCallback<String[]> callback) { - mWebViewController.getVisitedHistory(callback); + if (isPrivateBrowsingEnabled()) { + callback.onReceiveValue(new String[0]); + } else { + mWebViewController.getVisitedHistory(callback); + } } }; @@ -1507,6 +1520,12 @@ class Tab implements PictureListener { * @return The main WebView of this tab. */ WebView getWebView() { + /* Ensure the root webview object is in sync with our internal incognito status */ + if (mMainView instanceof BrowserWebView) { + if (isPrivateBrowsingEnabled() && !mMainView.isPrivateBrowsingEnabled()) { + ((BrowserWebView)mMainView).setPrivateBrowsing(isPrivateBrowsingEnabled()); + } + } return mMainView; } |