From 8d464436b97de1aace612fbcb4cb40af6f3eec83 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Sat, 18 Jan 2014 19:22:47 +0000 Subject: 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 --- src/com/android/browser/Tab.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/com/android/browser/Tab.java') diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index a4d2ce01a..907f7a1f3 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 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; } -- cgit v1.2.3