diff options
author | John Reck <jreck@google.com> | 2010-12-09 11:08:31 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2010-12-10 10:25:27 -0800 |
commit | b77aa7a93d1993174a832d0f2c7b380d0e65a0a7 (patch) | |
tree | dff61d1fe89df2145ad7725f09d44b12f2474298 | |
parent | 523772b2af82b8a9a7e7af02ac21601830c39bf1 (diff) | |
download | packages_apps_browser-b77aa7a93d1993174a832d0f2c7b380d0e65a0a7.zip packages_apps_browser-b77aa7a93d1993174a832d0f2c7b380d0e65a0a7.tar.gz packages_apps_browser-b77aa7a93d1993174a832d0f2c7b380d0e65a0a7.tar.bz2 |
Adds client id URL filtering to the provider
Bug: 3270662
Moves the client id URL filtering into the provider so that it is
applied to all history queries, updates, and inserts. We do this
because we do not want the client id in the history.
Change-Id: Ifb77debcb1c2102bd72701910bfbf07ed23c45ef
-rw-r--r-- | src/com/android/browser/provider/BrowserProvider2.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java index 8d9f1fe..0f51695 100644 --- a/src/com/android/browser/provider/BrowserProvider2.java +++ b/src/com/android/browser/provider/BrowserProvider2.java @@ -697,6 +697,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { // fall through } case HISTORY: { + filterSearchClient(selectionArgs); if (sortOrder == null) { sortOrder = DEFAULT_SORT_HISTORY; } @@ -803,6 +804,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { // fall through } case HISTORY: { + filterSearchClient(selectionArgs); return db.delete(TABLE_HISTORY, selection, selectionArgs); } @@ -877,6 +879,9 @@ public class BrowserProvider2 extends SQLiteContentProvider { if (!values.containsKey(History.DATE_CREATED)) { values.put(History.DATE_CREATED, System.currentTimeMillis()); } + String url = values.getAsString(History.URL); + url = filterSearchClient(url); + values.put(History.URL, url); // Extract out the image values so they can be inserted into the images table ContentValues imageValues = extractImageValues(values, @@ -917,6 +922,32 @@ public class BrowserProvider2 extends SQLiteContentProvider { } } + private void filterSearchClient(String[] selectionArgs) { + if (selectionArgs != null) { + for (int i = 0; i < selectionArgs.length; i++) { + selectionArgs[i] = filterSearchClient(selectionArgs[i]); + } + } + } + + // Filters out the client=ms- param for search urls + private String filterSearchClient(String url) { + // remove "client" before updating it to the history so that it wont + // show up in the auto-complete list. + int index = url.indexOf("client=ms-"); + if (index > 0 && url.contains(".google.")) { + int end = url.indexOf('&', index); + if (end > 0) { + url = url.substring(0, index) + .concat(url.substring(end + 1)); + } else { + // the url.charAt(index-1) should be either '?' or '&' + url = url.substring(0, index-1); + } + } + return url; + } + /** * Searches are unique, so perform an UPSERT manually since SQLite doesn't support them. */ @@ -1086,6 +1117,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { int updateHistoryInTransaction(ContentValues values, String selection, String[] selectionArgs) { int count = 0; final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); + filterSearchClient(selectionArgs); Cursor cursor = query(History.CONTENT_URI, new String[] { History._ID, History.URL }, selection, selectionArgs, null); @@ -1095,7 +1127,8 @@ public class BrowserProvider2 extends SQLiteContentProvider { boolean updatingUrl = values.containsKey(History.URL); String url = null; if (updatingUrl) { - url = values.getAsString(History.URL); + url = filterSearchClient(values.getAsString(History.URL)); + values.put(History.URL, url); } ContentValues imageValues = extractImageValues(values, url); |