diff options
author | Elliott Slaughter <eds@google.com> | 2010-07-14 18:10:36 -0700 |
---|---|---|
committer | Elliott Slaughter <eds@google.com> | 2010-08-05 16:24:03 -0700 |
commit | f0f03954b3092296c58dcb040e2dabd1696dd5c4 (patch) | |
tree | a68a168dfefea8cf5eaea41243367f339c72d520 /src | |
parent | 80f32627140aefe828ad539f66fc439d1580bae7 (diff) | |
download | packages_apps_browser-f0f03954b3092296c58dcb040e2dabd1696dd5c4.zip packages_apps_browser-f0f03954b3092296c58dcb040e2dabd1696dd5c4.tar.gz packages_apps_browser-f0f03954b3092296c58dcb040e2dabd1696dd5c4.tar.bz2 |
Initial work on browser incognito mode history feature.
Change-Id: I5d1575a9b74704abc313b322ae08ca7caaccdc69
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/ActiveTabsPage.java | 26 | ||||
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 37 | ||||
-rw-r--r-- | src/com/android/browser/TabControl.java | 21 |
3 files changed, 60 insertions, 24 deletions
diff --git a/src/com/android/browser/ActiveTabsPage.java b/src/com/android/browser/ActiveTabsPage.java index 52828b3..e450a99 100644 --- a/src/com/android/browser/ActiveTabsPage.java +++ b/src/com/android/browser/ActiveTabsPage.java @@ -53,12 +53,15 @@ public class ActiveTabsPage extends LinearLayout { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mControl.canCreateNewTab()) { - position--; + position -= 2; } boolean needToAttach = false; - if (position == -1) { + if (position == -2) { // Create a new tab mBrowserActivity.openTabToHomePage(); + } else if (position == -1) { + // Create a new incognito tab + mBrowserActivity.openIncognitoTab(); } else { // Open the corresponding tab // If the tab is the current one, switchToTab will @@ -100,7 +103,7 @@ public class ActiveTabsPage extends LinearLayout { public int getCount() { int count = mControl.getTabCount(); if (mControl.canCreateNewTab()) { - count++; + count += 2; } // XXX: This is a workaround to be more like a real adapter. Most // adapters call notifyDataSetChanged() whenever the internal data @@ -130,23 +133,28 @@ public class ActiveTabsPage extends LinearLayout { } public int getItemViewType(int position) { if (mControl.canCreateNewTab()) { - position--; + position -= 2; } // Do not recycle the "add new tab" item. - return position == -1 ? IGNORE_ITEM_VIEW_TYPE : 1; + return position < 0 ? IGNORE_ITEM_VIEW_TYPE : 1; } public View getView(int position, View convertView, ViewGroup parent) { final int tabCount = mControl.getTabCount(); if (mControl.canCreateNewTab()) { - position--; + position -= 2; } if (convertView == null) { - convertView = mFactory.inflate(position == -1 ? - R.layout.tab_view_add_tab : R.layout.tab_view, null); + if (position == -2) { + convertView = mFactory.inflate(R.layout.tab_view_add_tab, null); + } else if (position == -1) { + convertView = mFactory.inflate(R.layout.tab_view_add_incognito_tab, null); + } else { + convertView = mFactory.inflate(R.layout.tab_view, null); + } } - if (position != -1) { + if (position >= 0) { TextView title = (TextView) convertView.findViewById(R.id.title); TextView url = (TextView) convertView.findViewById(R.id.url); diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 69e0ee5..b9f5f01 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -348,7 +348,8 @@ public class BrowserActivity extends Activity intent.getData() != null) || RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS .equals(action), - intent.getStringExtra(Browser.EXTRA_APPLICATION_ID), urlData.mUrl); + intent.getStringExtra(Browser.EXTRA_APPLICATION_ID), + urlData.mUrl, false); mTabControl.setCurrentTab(t); attachTabToContentView(t); WebView webView = t.getWebView(); @@ -632,14 +633,16 @@ public class BrowserActivity extends Activity final ContentResolver cr = mResolver; final String newUrl = url; - new AsyncTask<Void, Void, Void>() { - @Override - protected Void doInBackground(Void... unused) { - Browser.updateVisitedHistory(cr, newUrl, false); - Browser.addSearchUrl(cr, newUrl); - return null; - } - }.execute(); + if (!mTabControl.getCurrentWebView().isPrivateBrowsingEnabled()) { + new AsyncTask<Void, Void, Void>() { + @Override + protected Void doInBackground(Void... unused) { + Browser.updateVisitedHistory(cr, newUrl, false); + Browser.addSearchUrl(cr, newUrl); + return null; + } + }.execute(); + } Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.addCategory(Intent.CATEGORY_DEFAULT); @@ -1864,7 +1867,7 @@ public class BrowserActivity extends Activity final Tab currentTab = mTabControl.getCurrentTab(); if (mTabControl.canCreateNewTab()) { final Tab tab = mTabControl.createNewTab(closeOnExit, appId, - urlData.mUrl); + urlData.mUrl, false); WebView webview = tab.getWebView(); // If the last tab was removed from the active tabs page, currentTab // will be null. @@ -1903,6 +1906,20 @@ public class BrowserActivity extends Activity } } + /* package */ Tab openIncognitoTab() { + if (mTabControl.canCreateNewTab()) { + Tab currentTab = mTabControl.getCurrentTab(); + Tab tab = mTabControl.createNewTab(false, null, null, true); + if (currentTab != null) { + removeTabFromContentView(currentTab); + } + mTabControl.setCurrentTab(tab); + attachTabToContentView(tab); + return tab; + } + return null; + } + private class Copy implements OnMenuItemClickListener { private CharSequence mText; diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java index 0fbdd7a..d850b1e 100644 --- a/src/com/android/browser/TabControl.java +++ b/src/com/android/browser/TabControl.java @@ -154,13 +154,14 @@ class TabControl { * @return The newly createTab or null if we have reached the maximum * number of open tabs. */ - Tab createNewTab(boolean closeOnExit, String appId, String url) { + Tab createNewTab(boolean closeOnExit, String appId, String url, + boolean privateBrowsing) { int size = mTabs.size(); // Return false if we have maxed out on tabs if (MAX_TABS == size) { return null; } - final WebView w = createNewWebView(); + final WebView w = createNewWebView(privateBrowsing); // Create a new tab and add it to the tab list Tab t = new Tab(mActivity, w, closeOnExit, appId, url); @@ -175,10 +176,10 @@ class TabControl { /** * Create a new tab with default values for closeOnExit(false), - * appId(null), and url(null). + * appId(null), url(null), and privateBrowsing(false). */ Tab createNewTab() { - return createNewTab(false, null, null); + return createNewTab(false, null, null, false); } /** @@ -535,8 +536,18 @@ class TabControl { * Creates a new WebView and registers it with the global settings. */ private WebView createNewWebView() { + return createNewWebView(false); + } + + /** + * Creates a new WebView and registers it with the global settings. + * @param privateBrowsing When true, enables private browsing in the new + * WebView. + */ + private WebView createNewWebView(boolean privateBrowsing) { // Create a new WebView - WebView w = new WebView(mActivity); + WebView w = new WebView(mActivity, null, + com.android.internal.R.attr.webViewStyle, privateBrowsing); w.setScrollbarFadingEnabled(true); w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); w.setMapTrackballToArrowKeys(false); // use trackball directly |