2011-12-08 16:37:21 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-08 16:37:21 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko.db;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
|
2012-07-28 00:53:54 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Combined;
|
2012-11-13 18:56:58 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
|
|
|
|
import org.mozilla.gecko.db.BrowserContract.FaviconColumns;
|
2013-04-08 07:51:56 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Favicons;
|
2011-12-08 16:37:21 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.History;
|
2012-06-25 22:30:47 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.SyncColumns;
|
2012-11-13 18:56:58 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Thumbnails;
|
2012-07-28 00:53:54 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.URLColumns;
|
2013-04-23 01:03:01 +00:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.content.ContentProviderOperation;
|
2011-12-08 16:37:21 +00:00
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentValues;
|
2012-02-15 00:23:06 +00:00
|
|
|
import android.database.ContentObserver;
|
2011-12-08 16:37:21 +00:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.CursorWrapper;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.provider.Browser;
|
2012-09-26 21:27:06 +00:00
|
|
|
import android.text.TextUtils;
|
2012-02-15 01:10:18 +00:00
|
|
|
import android.util.Log;
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
2012-10-31 12:34:31 +00:00
|
|
|
import java.util.List;
|
2012-07-28 00:53:54 +00:00
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
|
2012-02-15 01:10:18 +00:00
|
|
|
// Calculate these once, at initialization. isLoggable is too expensive to
|
|
|
|
// have in-line in each log call.
|
|
|
|
private static final String LOGTAG = "GeckoLocalBrowserDB";
|
|
|
|
private static boolean logDebug = Log.isLoggable(LOGTAG, Log.DEBUG);
|
|
|
|
protected static void debug(String message) {
|
|
|
|
if (logDebug) {
|
|
|
|
Log.d(LOGTAG, message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 16:37:21 +00:00
|
|
|
private final String mProfile;
|
2012-03-19 18:22:33 +00:00
|
|
|
|
2012-05-10 19:08:36 +00:00
|
|
|
// Map of folder GUIDs to IDs. Used for caching.
|
|
|
|
private HashMap<String, Long> mFolderIdMap;
|
|
|
|
|
2012-03-19 18:22:33 +00:00
|
|
|
// Use wrapped Boolean so that we can have a null state
|
|
|
|
private Boolean mDesktopBookmarksExist;
|
2012-06-02 18:23:45 +00:00
|
|
|
private Boolean mReadingListItemsExist;
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-02-15 19:24:21 +00:00
|
|
|
private final Uri mBookmarksUriWithProfile;
|
|
|
|
private final Uri mParentsUriWithProfile;
|
|
|
|
private final Uri mHistoryUriWithProfile;
|
2012-10-20 00:35:37 +00:00
|
|
|
private final Uri mHistoryExpireUriWithProfile;
|
2012-03-23 22:52:42 +00:00
|
|
|
private final Uri mCombinedUriWithProfile;
|
2012-02-15 19:24:21 +00:00
|
|
|
private final Uri mDeletedHistoryUriWithProfile;
|
2012-04-10 00:28:59 +00:00
|
|
|
private final Uri mUpdateHistoryUriWithProfile;
|
2012-11-13 18:56:58 +00:00
|
|
|
private final Uri mFaviconsUriWithProfile;
|
|
|
|
private final Uri mThumbnailsUriWithProfile;
|
2012-02-15 19:24:21 +00:00
|
|
|
|
2012-02-23 18:48:47 +00:00
|
|
|
private static final String[] DEFAULT_BOOKMARK_COLUMNS =
|
|
|
|
new String[] { Bookmarks._ID,
|
2012-03-07 19:13:03 +00:00
|
|
|
Bookmarks.GUID,
|
2012-02-23 18:48:47 +00:00
|
|
|
Bookmarks.URL,
|
|
|
|
Bookmarks.TITLE,
|
2012-03-20 11:44:32 +00:00
|
|
|
Bookmarks.TYPE,
|
2012-02-23 18:48:47 +00:00
|
|
|
Bookmarks.PARENT,
|
2012-03-23 01:36:09 +00:00
|
|
|
Bookmarks.KEYWORD,
|
2012-02-23 18:48:47 +00:00
|
|
|
Bookmarks.FAVICON };
|
|
|
|
|
2011-12-08 16:37:21 +00:00
|
|
|
public LocalBrowserDB(String profile) {
|
|
|
|
mProfile = profile;
|
2012-05-10 19:08:36 +00:00
|
|
|
mFolderIdMap = new HashMap<String, Long>();
|
2012-03-19 18:22:33 +00:00
|
|
|
mDesktopBookmarksExist = null;
|
2012-06-02 18:23:45 +00:00
|
|
|
mReadingListItemsExist = null;
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-02-15 19:24:21 +00:00
|
|
|
mBookmarksUriWithProfile = appendProfile(Bookmarks.CONTENT_URI);
|
|
|
|
mParentsUriWithProfile = appendProfile(Bookmarks.PARENTS_CONTENT_URI);
|
|
|
|
mHistoryUriWithProfile = appendProfile(History.CONTENT_URI);
|
2012-10-20 00:35:37 +00:00
|
|
|
mHistoryExpireUriWithProfile = appendProfile(History.CONTENT_OLD_URI);
|
2012-03-23 22:52:42 +00:00
|
|
|
mCombinedUriWithProfile = appendProfile(Combined.CONTENT_URI);
|
2012-11-13 18:56:58 +00:00
|
|
|
mFaviconsUriWithProfile = appendProfile(Favicons.CONTENT_URI);
|
|
|
|
mThumbnailsUriWithProfile = appendProfile(Thumbnails.CONTENT_URI);
|
2012-02-15 19:24:21 +00:00
|
|
|
|
|
|
|
mDeletedHistoryUriWithProfile = mHistoryUriWithProfile.buildUpon().
|
|
|
|
appendQueryParameter(BrowserContract.PARAM_SHOW_DELETED, "1").build();
|
2012-04-10 00:28:59 +00:00
|
|
|
|
|
|
|
mUpdateHistoryUriWithProfile = mHistoryUriWithProfile.buildUpon().
|
|
|
|
appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").
|
|
|
|
appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 18:22:33 +00:00
|
|
|
// Invalidate cached data
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-03-19 18:22:33 +00:00
|
|
|
public void invalidateCachedState() {
|
|
|
|
mDesktopBookmarksExist = null;
|
2012-06-02 18:23:45 +00:00
|
|
|
mReadingListItemsExist = null;
|
2012-03-19 18:22:33 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 19:24:21 +00:00
|
|
|
private Uri historyUriWithLimit(int limit) {
|
|
|
|
return mHistoryUriWithProfile.buildUpon().appendQueryParameter(BrowserContract.PARAM_LIMIT,
|
|
|
|
String.valueOf(limit)).build();
|
2012-02-15 15:05:03 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 18:22:33 +00:00
|
|
|
private Uri bookmarksUriWithLimit(int limit) {
|
|
|
|
return mBookmarksUriWithProfile.buildUpon().appendQueryParameter(BrowserContract.PARAM_LIMIT,
|
|
|
|
String.valueOf(limit)).build();
|
|
|
|
}
|
|
|
|
|
2012-03-23 22:52:42 +00:00
|
|
|
private Uri combinedUriWithLimit(int limit) {
|
|
|
|
return mCombinedUriWithProfile.buildUpon().appendQueryParameter(BrowserContract.PARAM_LIMIT,
|
|
|
|
String.valueOf(limit)).build();
|
|
|
|
}
|
|
|
|
|
2011-12-08 16:37:21 +00:00
|
|
|
private Uri appendProfile(Uri uri) {
|
|
|
|
return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, mProfile).build();
|
|
|
|
}
|
|
|
|
|
2012-06-25 22:30:47 +00:00
|
|
|
private Uri getAllBookmarksUri() {
|
|
|
|
Uri.Builder uriBuilder = mBookmarksUriWithProfile.buildUpon()
|
|
|
|
.appendQueryParameter(BrowserContract.PARAM_SHOW_DELETED, "1");
|
|
|
|
return uriBuilder.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Uri getAllHistoryUri() {
|
|
|
|
Uri.Builder uriBuilder = mHistoryUriWithProfile.buildUpon()
|
|
|
|
.appendQueryParameter(BrowserContract.PARAM_SHOW_DELETED, "1");
|
|
|
|
return uriBuilder.build();
|
|
|
|
}
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
private Uri getAllFaviconsUri() {
|
|
|
|
Uri.Builder uriBuilder = mFaviconsUriWithProfile.buildUpon()
|
2012-06-25 22:30:47 +00:00
|
|
|
.appendQueryParameter(BrowserContract.PARAM_SHOW_DELETED, "1");
|
|
|
|
return uriBuilder.build();
|
|
|
|
}
|
|
|
|
|
2012-03-16 18:36:31 +00:00
|
|
|
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint,
|
|
|
|
int limit, CharSequence urlFilter) {
|
2012-12-28 21:46:06 +00:00
|
|
|
return filterAllSites(cr, projection, constraint, limit, urlFilter, "", null);
|
|
|
|
}
|
2012-04-02 18:56:48 +00:00
|
|
|
|
2012-12-28 21:46:06 +00:00
|
|
|
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint,
|
|
|
|
int limit, CharSequence urlFilter, String selection, String[] selectionArgs) {
|
2012-04-02 18:56:48 +00:00
|
|
|
// The combined history/bookmarks selection queries for sites with a url or title containing
|
|
|
|
// the constraint string(s), treating space-separated words as separate constraints
|
2012-09-26 21:27:06 +00:00
|
|
|
if (!TextUtils.isEmpty(constraint)) {
|
|
|
|
String[] constraintWords = constraint.toString().split(" ");
|
|
|
|
for (int i = 0; i < constraintWords.length; i++) {
|
|
|
|
selection = DBUtils.concatenateWhere(selection, "(" + Combined.URL + " LIKE ? OR " +
|
|
|
|
Combined.TITLE + " LIKE ?)");
|
|
|
|
String constraintWord = "%" + constraintWords[i] + "%";
|
|
|
|
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
|
|
|
|
new String[] { constraintWord, constraintWord });
|
|
|
|
}
|
2012-04-02 18:56:48 +00:00
|
|
|
}
|
2012-03-16 18:36:31 +00:00
|
|
|
|
|
|
|
if (urlFilter != null) {
|
2012-03-23 22:52:42 +00:00
|
|
|
selection = DBUtils.concatenateWhere(selection, "(" + Combined.URL + " NOT LIKE ?)");
|
2012-03-16 18:36:31 +00:00
|
|
|
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs, new String[] { urlFilter.toString() });
|
|
|
|
}
|
|
|
|
|
2012-03-16 18:36:34 +00:00
|
|
|
// Our version of frecency is computed by scaling the number of visits by a multiplier
|
|
|
|
// that approximates Gaussian decay, based on how long ago the entry was last visited.
|
|
|
|
// Since we're limited by the math we can do with sqlite, we're calculating this
|
|
|
|
// approximation using the Cauchy distribution: multiplier = 15^2 / (age^2 + 15^2).
|
|
|
|
// Using 15 as our scale parameter, we get a constant 15^2 = 225. Following this math,
|
|
|
|
// frecencyScore = numVisits * max(1, 100 * 225 / (age*age + 225)). (See bug 704977)
|
2012-05-02 16:07:58 +00:00
|
|
|
// We also give bookmarks an extra bonus boost by adding 100 points to their frecency score.
|
2012-10-20 00:35:43 +00:00
|
|
|
final String sortOrder = BrowserContract.getFrecencySortOrder(true, false);
|
2012-03-16 18:36:31 +00:00
|
|
|
|
2012-03-23 22:52:42 +00:00
|
|
|
Cursor c = cr.query(combinedUriWithLimit(limit),
|
2012-01-19 17:23:10 +00:00
|
|
|
projection,
|
2012-03-16 18:36:31 +00:00
|
|
|
selection,
|
|
|
|
selectionArgs,
|
|
|
|
sortOrder);
|
2011-12-08 16:37:21 +00:00
|
|
|
|
|
|
|
return new LocalDBCursor(c);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-11-03 00:44:20 +00:00
|
|
|
public int getCount(ContentResolver cr, String database) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
int count = 0;
|
2013-02-19 20:53:03 +00:00
|
|
|
String[] columns = null;
|
2012-11-03 00:44:20 +00:00
|
|
|
String constraint = null;
|
|
|
|
try {
|
|
|
|
Uri uri = null;
|
|
|
|
if ("history".equals(database)) {
|
|
|
|
uri = mHistoryUriWithProfile;
|
2013-02-19 20:53:03 +00:00
|
|
|
columns = new String[] { History._ID };
|
2012-11-03 00:44:20 +00:00
|
|
|
constraint = Combined.VISITS + " > 0";
|
|
|
|
} else if ("bookmarks".equals(database)) {
|
|
|
|
uri = mBookmarksUriWithProfile;
|
2013-02-19 20:53:03 +00:00
|
|
|
columns = new String[] { Bookmarks._ID };
|
2012-11-03 00:44:20 +00:00
|
|
|
// ignore folders, tags, keywords, separators, etc.
|
|
|
|
constraint = Bookmarks.TYPE + " = " + Bookmarks.TYPE_BOOKMARK;
|
|
|
|
} else if ("thumbnails".equals(database)) {
|
2012-11-13 18:56:58 +00:00
|
|
|
uri = mThumbnailsUriWithProfile;
|
2013-02-19 20:53:03 +00:00
|
|
|
columns = new String[] { Thumbnails._ID };
|
2012-11-03 00:44:20 +00:00
|
|
|
} else if ("favicons".equals(database)) {
|
2012-11-13 18:56:58 +00:00
|
|
|
uri = mFaviconsUriWithProfile;
|
2013-02-19 20:53:03 +00:00
|
|
|
columns = new String[] { Favicons._ID };
|
2012-11-03 00:44:20 +00:00
|
|
|
}
|
|
|
|
if (uri != null) {
|
2013-02-19 20:53:03 +00:00
|
|
|
cursor = cr.query(uri, columns, constraint, null, null);
|
2012-11-03 00:44:20 +00:00
|
|
|
count = cursor.getCount();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
debug("Got count " + count + " for " + database);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-01-19 17:23:10 +00:00
|
|
|
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
|
|
|
|
return filterAllSites(cr,
|
2012-03-23 22:52:42 +00:00
|
|
|
new String[] { Combined._ID,
|
|
|
|
Combined.URL,
|
|
|
|
Combined.TITLE,
|
2012-06-02 18:23:45 +00:00
|
|
|
Combined.DISPLAY,
|
2012-05-14 18:44:34 +00:00
|
|
|
Combined.BOOKMARK_ID,
|
|
|
|
Combined.HISTORY_ID },
|
2012-01-19 17:23:10 +00:00
|
|
|
constraint,
|
|
|
|
limit,
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-01-19 17:23:10 +00:00
|
|
|
public Cursor getTopSites(ContentResolver cr, int limit) {
|
2012-12-28 21:46:06 +00:00
|
|
|
// Filter out sites that are pinned
|
|
|
|
String selection = DBUtils.concatenateWhere("", Combined.URL + " NOT IN (SELECT " +
|
2013-05-06 20:14:03 +00:00
|
|
|
Bookmarks.URL + " FROM bookmarks WHERE " +
|
|
|
|
DBUtils.qualifyColumn("bookmarks", Bookmarks.PARENT) + " == ? AND " +
|
|
|
|
DBUtils.qualifyColumn("bookmarks", Bookmarks.IS_DELETED) + " == 0)");
|
2012-12-28 21:46:06 +00:00
|
|
|
String[] selectionArgs = DBUtils.appendSelectionArgs(new String[0], new String[] { String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) });
|
2012-01-19 17:23:10 +00:00
|
|
|
return filterAllSites(cr,
|
2012-03-23 22:52:42 +00:00
|
|
|
new String[] { Combined._ID,
|
|
|
|
Combined.URL,
|
2012-10-31 12:34:32 +00:00
|
|
|
Combined.TITLE },
|
2012-01-19 17:23:10 +00:00
|
|
|
"",
|
|
|
|
limit,
|
2012-12-28 21:46:06 +00:00
|
|
|
BrowserDB.ABOUT_PAGES_URL_FILTER,
|
|
|
|
selection,
|
|
|
|
selectionArgs);
|
2012-01-19 17:23:10 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-08 16:37:21 +00:00
|
|
|
public void updateVisitedHistory(ContentResolver cr, String uri) {
|
2012-04-10 00:28:59 +00:00
|
|
|
ContentValues values = new ContentValues();
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-04-10 00:28:59 +00:00
|
|
|
values.put(History.URL, uri);
|
|
|
|
values.put(History.DATE_LAST_VISITED, System.currentTimeMillis());
|
|
|
|
values.put(History.IS_DELETED, 0);
|
|
|
|
|
|
|
|
// This will insert a new history entry if one for this URL
|
|
|
|
// doesn't already exist
|
2012-04-12 17:28:50 +00:00
|
|
|
cr.update(mUpdateHistoryUriWithProfile,
|
|
|
|
values,
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { uri });
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-08 16:37:21 +00:00
|
|
|
public void updateHistoryTitle(ContentResolver cr, String uri, String title) {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(History.TITLE, title);
|
|
|
|
|
2012-02-15 19:24:21 +00:00
|
|
|
cr.update(mHistoryUriWithProfile,
|
2011-12-08 16:37:21 +00:00
|
|
|
values,
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { uri });
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-01-25 21:10:01 +00:00
|
|
|
public void updateHistoryEntry(ContentResolver cr, String uri, String title,
|
|
|
|
long date, int visits) {
|
|
|
|
int oldVisits = 0;
|
|
|
|
Cursor cursor = null;
|
|
|
|
try {
|
2012-02-15 19:24:21 +00:00
|
|
|
cursor = cr.query(mHistoryUriWithProfile,
|
2012-01-25 21:10:01 +00:00
|
|
|
new String[] { History.VISITS },
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { uri },
|
|
|
|
null);
|
|
|
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
oldVisits = cursor.getInt(0);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:56:11 +00:00
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(History.DATE_LAST_VISITED, date);
|
2012-01-25 21:10:01 +00:00
|
|
|
values.put(History.VISITS, oldVisits + visits);
|
|
|
|
if (title != null) {
|
|
|
|
values.put(History.TITLE, title);
|
|
|
|
}
|
2011-12-19 21:56:11 +00:00
|
|
|
|
2012-02-15 19:24:21 +00:00
|
|
|
cr.update(mHistoryUriWithProfile,
|
2011-12-19 21:56:11 +00:00
|
|
|
values,
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { uri });
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-08 16:37:21 +00:00
|
|
|
public Cursor getAllVisitedHistory(ContentResolver cr) {
|
2012-02-15 19:24:21 +00:00
|
|
|
Cursor c = cr.query(mHistoryUriWithProfile,
|
2011-12-08 16:37:21 +00:00
|
|
|
new String[] { History.URL },
|
|
|
|
History.VISITS + " > 0",
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
|
|
|
|
return new LocalDBCursor(c);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-08 16:37:21 +00:00
|
|
|
public Cursor getRecentHistory(ContentResolver cr, int limit) {
|
2012-04-24 22:59:30 +00:00
|
|
|
Cursor c = cr.query(combinedUriWithLimit(limit),
|
|
|
|
new String[] { Combined._ID,
|
|
|
|
Combined.BOOKMARK_ID,
|
2012-05-14 18:44:34 +00:00
|
|
|
Combined.HISTORY_ID,
|
2012-04-24 22:59:30 +00:00
|
|
|
Combined.URL,
|
|
|
|
Combined.TITLE,
|
|
|
|
Combined.FAVICON,
|
2012-06-10 23:44:50 +00:00
|
|
|
Combined.DISPLAY,
|
2012-04-24 22:59:30 +00:00
|
|
|
Combined.DATE_LAST_VISITED,
|
|
|
|
Combined.VISITS },
|
2011-12-08 16:37:21 +00:00
|
|
|
History.DATE_LAST_VISITED + " > 0",
|
|
|
|
null,
|
|
|
|
History.DATE_LAST_VISITED + " DESC");
|
|
|
|
|
|
|
|
return new LocalDBCursor(c);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-10-20 00:35:37 +00:00
|
|
|
public void expireHistory(ContentResolver cr, ExpirePriority priority) {
|
|
|
|
Uri url = mHistoryExpireUriWithProfile;
|
|
|
|
url = url.buildUpon().appendQueryParameter(BrowserContract.PARAM_EXPIRE_PRIORITY, priority.toString()).build();
|
|
|
|
cr.delete(url, null, null);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-05-14 18:44:34 +00:00
|
|
|
public void removeHistoryEntry(ContentResolver cr, int id) {
|
|
|
|
cr.delete(mHistoryUriWithProfile,
|
|
|
|
History._ID + " = ?",
|
|
|
|
new String[] { String.valueOf(id) });
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-01-30 15:20:35 +00:00
|
|
|
public void removeHistoryEntry(ContentResolver cr, String url) {
|
|
|
|
int deleted = cr.delete(mHistoryUriWithProfile,
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { url });
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-08 16:37:21 +00:00
|
|
|
public void clearHistory(ContentResolver cr) {
|
2012-02-15 19:24:21 +00:00
|
|
|
cr.delete(mHistoryUriWithProfile, null, null);
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-02-23 18:48:47 +00:00
|
|
|
public Cursor getBookmarksInFolder(ContentResolver cr, long folderId) {
|
2012-03-15 17:01:11 +00:00
|
|
|
Cursor c = null;
|
2012-04-02 18:56:53 +00:00
|
|
|
boolean addDesktopFolder = false;
|
2012-06-02 18:23:45 +00:00
|
|
|
boolean addReadingListFolder = false;
|
2012-03-15 17:01:11 +00:00
|
|
|
|
2012-04-02 18:56:53 +00:00
|
|
|
// We always want to show mobile bookmarks in the root view.
|
|
|
|
if (folderId == Bookmarks.FIXED_ROOT_ID) {
|
2012-05-10 19:08:39 +00:00
|
|
|
folderId = getFolderIdFromGuid(cr, Bookmarks.MOBILE_FOLDER_GUID);
|
2012-03-19 18:22:33 +00:00
|
|
|
|
2012-04-02 18:56:53 +00:00
|
|
|
// We'll add a fake "Desktop Bookmarks" folder to the root view if desktop
|
|
|
|
// bookmarks exist, so that the user can still access non-mobile bookmarks.
|
|
|
|
addDesktopFolder = desktopBookmarksExist(cr);
|
2012-06-02 18:23:45 +00:00
|
|
|
|
|
|
|
// We'll add the Reading List folder to the root view if any reading
|
|
|
|
// list items exist.
|
|
|
|
addReadingListFolder = readingListItemsExist(cr);
|
2012-04-02 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (folderId == Bookmarks.FAKE_DESKTOP_FOLDER_ID) {
|
|
|
|
// Since the "Desktop Bookmarks" folder doesn't actually exist, we
|
|
|
|
// just fake it by querying specifically certain known desktop folders.
|
2012-03-15 17:01:11 +00:00
|
|
|
c = cr.query(mBookmarksUriWithProfile,
|
|
|
|
DEFAULT_BOOKMARK_COLUMNS,
|
|
|
|
Bookmarks.GUID + " = ? OR " +
|
|
|
|
Bookmarks.GUID + " = ? OR " +
|
2012-04-02 18:56:53 +00:00
|
|
|
Bookmarks.GUID + " = ?",
|
|
|
|
new String[] { Bookmarks.TOOLBAR_FOLDER_GUID,
|
2012-03-15 17:01:11 +00:00
|
|
|
Bookmarks.MENU_FOLDER_GUID,
|
|
|
|
Bookmarks.UNFILED_FOLDER_GUID },
|
|
|
|
null);
|
|
|
|
} else {
|
2012-03-20 11:44:32 +00:00
|
|
|
// Right now, we only support showing folder and bookmark type of
|
|
|
|
// entries. We should add support for other types though (bug 737024)
|
2012-03-15 17:01:11 +00:00
|
|
|
c = cr.query(mBookmarksUriWithProfile,
|
|
|
|
DEFAULT_BOOKMARK_COLUMNS,
|
2012-03-20 11:44:32 +00:00
|
|
|
Bookmarks.PARENT + " = ? AND " +
|
|
|
|
"(" + Bookmarks.TYPE + " = ? OR " + Bookmarks.TYPE + " = ?)",
|
|
|
|
new String[] { String.valueOf(folderId),
|
|
|
|
String.valueOf(Bookmarks.TYPE_BOOKMARK),
|
|
|
|
String.valueOf(Bookmarks.TYPE_FOLDER) },
|
2012-03-15 17:01:11 +00:00
|
|
|
null);
|
|
|
|
}
|
2012-02-07 19:03:02 +00:00
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
if (addDesktopFolder || addReadingListFolder) {
|
|
|
|
// Wrap cursor to add fake desktop bookmarks and reading list folders
|
|
|
|
c = new SpecialFoldersCursorWrapper(c, addDesktopFolder, addReadingListFolder);
|
2012-04-02 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 19:03:02 +00:00
|
|
|
return new LocalDBCursor(c);
|
|
|
|
}
|
|
|
|
|
2012-03-19 18:22:33 +00:00
|
|
|
// Returns true if any desktop bookmarks exist, which will be true if the user
|
|
|
|
// has set up sync at one point, or done a profile migration from XUL fennec.
|
|
|
|
private boolean desktopBookmarksExist(ContentResolver cr) {
|
|
|
|
if (mDesktopBookmarksExist != null)
|
|
|
|
return mDesktopBookmarksExist;
|
|
|
|
|
|
|
|
Cursor c = null;
|
|
|
|
int count = 0;
|
|
|
|
try {
|
2012-05-10 19:08:36 +00:00
|
|
|
// Check to see if there are any bookmarks in one of our three
|
|
|
|
// fixed "Desktop Boomarks" folders.
|
2012-03-19 18:22:33 +00:00
|
|
|
c = cr.query(bookmarksUriWithLimit(1),
|
|
|
|
new String[] { Bookmarks._ID },
|
2012-05-10 19:08:36 +00:00
|
|
|
Bookmarks.PARENT + " = ? OR " +
|
|
|
|
Bookmarks.PARENT + " = ? OR " +
|
|
|
|
Bookmarks.PARENT + " = ?",
|
|
|
|
new String[] { String.valueOf(getFolderIdFromGuid(cr, Bookmarks.TOOLBAR_FOLDER_GUID)),
|
|
|
|
String.valueOf(getFolderIdFromGuid(cr, Bookmarks.MENU_FOLDER_GUID)),
|
|
|
|
String.valueOf(getFolderIdFromGuid(cr, Bookmarks.UNFILED_FOLDER_GUID)) },
|
2012-03-19 18:22:33 +00:00
|
|
|
null);
|
|
|
|
count = c.getCount();
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache result for future queries
|
2012-06-02 18:23:45 +00:00
|
|
|
mDesktopBookmarksExist = (count > 0);
|
2012-03-19 18:22:33 +00:00
|
|
|
return mDesktopBookmarksExist;
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
private boolean readingListItemsExist(ContentResolver cr) {
|
|
|
|
if (mReadingListItemsExist != null)
|
|
|
|
return mReadingListItemsExist;
|
|
|
|
|
|
|
|
Cursor c = null;
|
|
|
|
int count = 0;
|
|
|
|
try {
|
|
|
|
c = cr.query(bookmarksUriWithLimit(1),
|
|
|
|
new String[] { Bookmarks._ID },
|
|
|
|
Bookmarks.PARENT + " = ?",
|
|
|
|
new String[] { String.valueOf(Bookmarks.FIXED_READING_LIST_ID) },
|
|
|
|
null);
|
|
|
|
count = c.getCount();
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache result for future queries
|
|
|
|
mReadingListItemsExist = (count > 0);
|
|
|
|
return mReadingListItemsExist;
|
|
|
|
}
|
|
|
|
|
2013-06-10 16:25:35 +00:00
|
|
|
@Override
|
|
|
|
public int getReadingListCount(ContentResolver cr) {
|
|
|
|
// This method is about the Reading List, not normal bookmarks
|
|
|
|
Cursor c = null;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
c = cr.query(mBookmarksUriWithProfile,
|
|
|
|
new String[] { Bookmarks._ID },
|
|
|
|
Bookmarks.PARENT + " = ?",
|
|
|
|
new String[] { String.valueOf(Bookmarks.FIXED_READING_LIST_ID) },
|
|
|
|
null);
|
|
|
|
count = c.getCount();
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-08 16:37:21 +00:00
|
|
|
public boolean isBookmark(ContentResolver cr, String uri) {
|
2012-06-02 18:23:45 +00:00
|
|
|
// This method is about normal bookmarks, not the Reading List
|
2012-06-21 00:56:02 +00:00
|
|
|
int count = 0;
|
|
|
|
try {
|
2012-06-25 22:32:03 +00:00
|
|
|
Cursor c = cr.query(bookmarksUriWithLimit(1),
|
2012-06-21 00:56:02 +00:00
|
|
|
new String[] { Bookmarks._ID },
|
|
|
|
Bookmarks.URL + " = ? AND " +
|
2012-12-28 21:46:04 +00:00
|
|
|
Bookmarks.PARENT + " != ? AND " +
|
2012-06-21 00:56:02 +00:00
|
|
|
Bookmarks.PARENT + " != ?",
|
|
|
|
new String[] { uri,
|
2012-12-28 21:46:04 +00:00
|
|
|
String.valueOf(Bookmarks.FIXED_READING_LIST_ID),
|
|
|
|
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) },
|
2012-06-21 00:56:02 +00:00
|
|
|
Bookmarks.URL);
|
|
|
|
count = c.getCount();
|
|
|
|
c.close();
|
|
|
|
} catch (NullPointerException e) {
|
2012-09-09 01:40:58 +00:00
|
|
|
Log.e(LOGTAG, "NullPointerException in isBookmark");
|
2012-06-21 00:56:02 +00:00
|
|
|
}
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-06-25 22:32:03 +00:00
|
|
|
return (count > 0);
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-06-20 18:10:08 +00:00
|
|
|
public boolean isReadingListItem(ContentResolver cr, String uri) {
|
2012-11-15 14:40:56 +00:00
|
|
|
int count = 0;
|
|
|
|
try {
|
|
|
|
Cursor c = cr.query(mBookmarksUriWithProfile,
|
|
|
|
new String[] { Bookmarks._ID },
|
|
|
|
Bookmarks.URL + " = ? AND " +
|
|
|
|
Bookmarks.PARENT + " == ?",
|
|
|
|
new String[] { uri,
|
|
|
|
String.valueOf(Bookmarks.FIXED_READING_LIST_ID) },
|
|
|
|
Bookmarks.URL);
|
2012-06-20 18:10:08 +00:00
|
|
|
|
2012-11-15 14:40:56 +00:00
|
|
|
count = c.getCount();
|
|
|
|
c.close();
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
Log.e(LOGTAG, "NullPointerException in isReadingListItem");
|
|
|
|
}
|
|
|
|
|
|
|
|
return (count > 0);
|
2012-06-20 18:10:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-02-08 01:55:12 +00:00
|
|
|
public String getUrlForKeyword(ContentResolver cr, String keyword) {
|
2012-02-15 19:24:21 +00:00
|
|
|
Cursor cursor = cr.query(mBookmarksUriWithProfile,
|
2012-02-08 01:55:12 +00:00
|
|
|
new String[] { Bookmarks.URL },
|
|
|
|
Bookmarks.KEYWORD + " = ?",
|
|
|
|
new String[] { keyword },
|
|
|
|
null);
|
|
|
|
|
|
|
|
if (!cursor.moveToFirst()) {
|
|
|
|
cursor.close();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = cursor.getString(cursor.getColumnIndexOrThrow(Bookmarks.URL));
|
|
|
|
cursor.close();
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2012-05-10 19:08:36 +00:00
|
|
|
private synchronized long getFolderIdFromGuid(ContentResolver cr, String guid) {
|
|
|
|
if (mFolderIdMap.containsKey(guid))
|
|
|
|
return mFolderIdMap.get(guid);
|
|
|
|
|
2012-02-23 18:48:47 +00:00
|
|
|
long folderId = -1;
|
2011-12-13 19:47:40 +00:00
|
|
|
Cursor c = null;
|
|
|
|
|
|
|
|
try {
|
2012-02-15 19:24:21 +00:00
|
|
|
c = cr.query(mBookmarksUriWithProfile,
|
2011-12-13 19:47:40 +00:00
|
|
|
new String[] { Bookmarks._ID },
|
|
|
|
Bookmarks.GUID + " = ?",
|
2012-02-23 18:48:47 +00:00
|
|
|
new String[] { guid },
|
2011-12-13 19:47:40 +00:00
|
|
|
null);
|
|
|
|
|
|
|
|
if (c.moveToFirst())
|
2012-02-23 18:48:47 +00:00
|
|
|
folderId = c.getLong(c.getColumnIndexOrThrow(Bookmarks._ID));
|
2011-12-13 19:47:40 +00:00
|
|
|
} finally {
|
|
|
|
if (c != null)
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
|
2012-05-10 19:08:36 +00:00
|
|
|
mFolderIdMap.put(guid, folderId);
|
2012-02-23 18:48:47 +00:00
|
|
|
return folderId;
|
2011-12-13 19:47:40 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 01:10:18 +00:00
|
|
|
/**
|
|
|
|
* Find parents of records that match the provided criteria, and bump their
|
|
|
|
* modified timestamp.
|
|
|
|
*/
|
|
|
|
protected void bumpParents(ContentResolver cr, String param, String value) {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(Bookmarks.DATE_MODIFIED, System.currentTimeMillis());
|
|
|
|
|
|
|
|
String where = param + " = ?";
|
|
|
|
String[] args = new String[] { value };
|
2012-02-15 19:24:21 +00:00
|
|
|
int updated = cr.update(mParentsUriWithProfile, values, where, args);
|
2012-02-15 01:10:18 +00:00
|
|
|
debug("Updated " + updated + " rows to new modified time.");
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
private void addBookmarkItem(ContentResolver cr, String title, String uri, long folderId) {
|
2012-02-15 01:10:18 +00:00
|
|
|
final long now = System.currentTimeMillis();
|
2011-12-08 16:37:21 +00:00
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(Browser.BookmarkColumns.TITLE, title);
|
|
|
|
values.put(Bookmarks.URL, uri);
|
2011-12-13 19:47:40 +00:00
|
|
|
values.put(Bookmarks.PARENT, folderId);
|
2012-02-15 01:10:18 +00:00
|
|
|
values.put(Bookmarks.DATE_MODIFIED, now);
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-11-21 18:23:18 +00:00
|
|
|
// Get the page's favicon ID from the history table
|
|
|
|
Cursor c = cr.query(mHistoryUriWithProfile,
|
|
|
|
new String[] { History.FAVICON_ID },
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { uri },
|
|
|
|
null);
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
int columnIndex = c.getColumnIndexOrThrow(History.FAVICON_ID);
|
|
|
|
if (!c.isNull(columnIndex))
|
|
|
|
values.put(Bookmarks.FAVICON_ID, c.getLong(columnIndex));
|
|
|
|
}
|
|
|
|
c.close();
|
|
|
|
|
2011-12-13 14:46:58 +00:00
|
|
|
// Restore deleted record if possible
|
|
|
|
values.put(Bookmarks.IS_DELETED, 0);
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
int updated = cr.update(mBookmarksUriWithProfile,
|
2011-12-08 16:37:21 +00:00
|
|
|
values,
|
2012-06-02 18:23:45 +00:00
|
|
|
Bookmarks.URL + " = ? AND " +
|
|
|
|
Bookmarks.PARENT + " = ?",
|
|
|
|
new String[] { uri, String.valueOf(folderId) });
|
2011-12-08 16:37:21 +00:00
|
|
|
|
|
|
|
if (updated == 0)
|
2012-06-02 18:23:45 +00:00
|
|
|
cr.insert(mBookmarksUriWithProfile, values);
|
2012-02-15 01:10:18 +00:00
|
|
|
|
|
|
|
// Bump parent modified time using its ID.
|
|
|
|
debug("Bumping parent modified time for addition to: " + folderId);
|
|
|
|
final String where = Bookmarks._ID + " = ?";
|
|
|
|
final String[] args = new String[] { String.valueOf(folderId) };
|
|
|
|
|
|
|
|
ContentValues bumped = new ContentValues();
|
|
|
|
bumped.put(Bookmarks.DATE_MODIFIED, now);
|
2012-02-15 00:23:06 +00:00
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
updated = cr.update(mBookmarksUriWithProfile, bumped, where, args);
|
2012-02-15 01:10:18 +00:00
|
|
|
debug("Updated " + updated + " rows to new modified time.");
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-06-02 18:23:45 +00:00
|
|
|
public void addBookmark(ContentResolver cr, String title, String uri) {
|
|
|
|
long folderId = getFolderIdFromGuid(cr, Bookmarks.MOBILE_FOLDER_GUID);
|
|
|
|
addBookmarkItem(cr, title, uri, folderId);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-02-09 18:01:57 +00:00
|
|
|
public void removeBookmark(ContentResolver cr, int id) {
|
2012-02-15 19:24:21 +00:00
|
|
|
Uri contentUri = mBookmarksUriWithProfile;
|
2012-02-15 01:10:18 +00:00
|
|
|
|
|
|
|
// Do this now so that the item still exists!
|
|
|
|
final String idString = String.valueOf(id);
|
|
|
|
bumpParents(cr, Bookmarks._ID, idString);
|
2012-02-15 00:23:06 +00:00
|
|
|
|
2012-02-15 01:10:18 +00:00
|
|
|
final String[] idArgs = new String[] { idString };
|
|
|
|
final String idEquals = Bookmarks._ID + " = ?";
|
|
|
|
cr.delete(contentUri, idEquals, idArgs);
|
2012-02-09 18:01:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-02-09 18:01:57 +00:00
|
|
|
public void removeBookmarksWithURL(ContentResolver cr, String uri) {
|
2012-02-15 19:24:21 +00:00
|
|
|
Uri contentUri = mBookmarksUriWithProfile;
|
2012-02-15 01:10:18 +00:00
|
|
|
|
|
|
|
// Do this now so that the items still exist!
|
|
|
|
bumpParents(cr, Bookmarks.URL, uri);
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
// Toggling bookmark on an URL should not affect the items in the reading list
|
|
|
|
final String[] urlArgs = new String[] { uri, String.valueOf(Bookmarks.FIXED_READING_LIST_ID) };
|
|
|
|
final String urlEquals = Bookmarks.URL + " = ? AND " + Bookmarks.PARENT + " != ?";
|
|
|
|
|
2012-02-15 01:10:18 +00:00
|
|
|
cr.delete(contentUri, urlEquals, urlArgs);
|
2012-02-15 00:23:06 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-06-02 18:23:45 +00:00
|
|
|
public void addReadingListItem(ContentResolver cr, String title, String uri) {
|
|
|
|
addBookmarkItem(cr, title, uri, Bookmarks.FIXED_READING_LIST_ID);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-06-20 18:10:08 +00:00
|
|
|
public void removeReadingListItemWithURL(ContentResolver cr, String uri) {
|
|
|
|
Uri contentUri = mBookmarksUriWithProfile;
|
|
|
|
|
|
|
|
// Do this now so that the items still exist!
|
|
|
|
bumpParents(cr, Bookmarks.URL, uri);
|
|
|
|
|
|
|
|
final String[] urlArgs = new String[] { uri, String.valueOf(Bookmarks.FIXED_READING_LIST_ID) };
|
|
|
|
final String urlEquals = Bookmarks.URL + " = ? AND " + Bookmarks.PARENT + " == ?";
|
|
|
|
|
|
|
|
cr.delete(contentUri, urlEquals, urlArgs);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-02-15 00:23:06 +00:00
|
|
|
public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) {
|
2012-05-14 18:44:37 +00:00
|
|
|
cr.registerContentObserver(mBookmarksUriWithProfile, false, observer);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-05-14 18:44:37 +00:00
|
|
|
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer) {
|
|
|
|
cr.registerContentObserver(mHistoryUriWithProfile, false, observer);
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-05-07 22:33:07 +00:00
|
|
|
public void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword) {
|
2012-02-08 01:55:12 +00:00
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(Browser.BookmarkColumns.TITLE, title);
|
|
|
|
values.put(Bookmarks.URL, uri);
|
|
|
|
values.put(Bookmarks.KEYWORD, keyword);
|
2012-11-10 23:06:50 +00:00
|
|
|
values.put(Bookmarks.DATE_MODIFIED, System.currentTimeMillis());
|
2012-02-08 01:55:12 +00:00
|
|
|
|
2012-02-15 19:24:21 +00:00
|
|
|
cr.update(mBookmarksUriWithProfile,
|
2012-02-08 04:08:46 +00:00
|
|
|
values,
|
2012-05-07 22:33:07 +00:00
|
|
|
Bookmarks._ID + " = ?",
|
|
|
|
new String[] { String.valueOf(id) });
|
2012-02-08 01:55:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-11-05 11:42:25 +00:00
|
|
|
public Bitmap getFaviconForUrl(ContentResolver cr, String uri) {
|
2012-11-13 18:56:58 +00:00
|
|
|
Cursor c = cr.query(mCombinedUriWithProfile,
|
|
|
|
new String[] { Combined.FAVICON },
|
|
|
|
Combined.URL + " = ?",
|
2011-12-08 16:37:21 +00:00
|
|
|
new String[] { uri },
|
|
|
|
null);
|
|
|
|
|
|
|
|
if (!c.moveToFirst()) {
|
|
|
|
c.close();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
int faviconIndex = c.getColumnIndexOrThrow(Combined.FAVICON);
|
2011-12-08 16:37:21 +00:00
|
|
|
byte[] b = c.getBlob(faviconIndex);
|
|
|
|
c.close();
|
|
|
|
|
2013-05-23 18:42:30 +00:00
|
|
|
if (b == null || b.length == 0)
|
2011-12-08 16:37:21 +00:00
|
|
|
return null;
|
|
|
|
|
2013-04-23 01:03:01 +00:00
|
|
|
return BitmapUtils.decodeByteArray(b);
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-11-13 18:56:58 +00:00
|
|
|
public String getFaviconUrlForHistoryUrl(ContentResolver cr, String uri) {
|
|
|
|
Cursor c = cr.query(mHistoryUriWithProfile,
|
|
|
|
new String[] { History.FAVICON_URL },
|
|
|
|
Combined.URL + " = ?",
|
|
|
|
new String[] { uri },
|
|
|
|
null);
|
|
|
|
|
|
|
|
if (!c.moveToFirst()) {
|
|
|
|
c.close();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
String faviconUrl = c.getString(c.getColumnIndexOrThrow(History.FAVICON_URL));
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
return faviconUrl;
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-10-31 12:34:31 +00:00
|
|
|
public Cursor getFaviconsForUrls(ContentResolver cr, List<String> urls) {
|
|
|
|
StringBuffer selection = new StringBuffer();
|
|
|
|
String[] selectionArgs = new String[urls.size()];
|
|
|
|
|
|
|
|
for (int i = 0; i < urls.size(); i++) {
|
|
|
|
final String url = urls.get(i);
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
selection.append(" OR ");
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
selection.append(Favicons.URL + " = ?");
|
2012-10-31 12:34:31 +00:00
|
|
|
selectionArgs[i] = url;
|
|
|
|
}
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
return cr.query(mCombinedUriWithProfile,
|
|
|
|
new String[] { Combined.URL, Combined.FAVICON },
|
2012-10-31 12:34:31 +00:00
|
|
|
selection.toString(),
|
|
|
|
selectionArgs,
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-11-13 18:56:58 +00:00
|
|
|
public void updateFaviconForUrl(ContentResolver cr, String pageUri,
|
|
|
|
Bitmap favicon, String faviconUri) {
|
2011-12-08 16:37:21 +00:00
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
2012-11-05 11:42:25 +00:00
|
|
|
favicon.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
2011-12-08 16:37:21 +00:00
|
|
|
|
|
|
|
ContentValues values = new ContentValues();
|
2012-11-13 18:56:58 +00:00
|
|
|
values.put(Favicons.URL, faviconUri);
|
|
|
|
values.put(Favicons.DATA, stream.toByteArray());
|
|
|
|
values.put(Favicons.PAGE_URL, pageUri);
|
2011-12-08 16:37:21 +00:00
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
// Update or insert
|
|
|
|
Uri faviconsUri = getAllFaviconsUri().buildUpon().
|
|
|
|
appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
|
2011-12-13 14:46:58 +00:00
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
int updated = cr.update(faviconsUri,
|
2011-12-13 14:46:58 +00:00
|
|
|
values,
|
2012-11-13 18:56:58 +00:00
|
|
|
Favicons.URL + " = ?",
|
|
|
|
new String[] { faviconUri });
|
2011-12-13 14:46:58 +00:00
|
|
|
|
|
|
|
if (updated == 0)
|
2012-11-13 18:56:58 +00:00
|
|
|
cr.insert(mFaviconsUriWithProfile, values);
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2011-12-08 16:37:21 +00:00
|
|
|
public void updateThumbnailForUrl(ContentResolver cr, String uri,
|
|
|
|
BitmapDrawable thumbnail) {
|
|
|
|
Bitmap bitmap = thumbnail.getBitmap();
|
|
|
|
|
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
|
|
|
|
|
|
|
|
ContentValues values = new ContentValues();
|
2012-11-13 18:56:58 +00:00
|
|
|
values.put(Thumbnails.DATA, stream.toByteArray());
|
|
|
|
values.put(Thumbnails.URL, uri);
|
2011-12-13 14:46:58 +00:00
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
int updated = cr.update(mThumbnailsUriWithProfile,
|
2011-12-13 14:46:58 +00:00
|
|
|
values,
|
2012-11-13 18:56:58 +00:00
|
|
|
Thumbnails.URL + " = ?",
|
2011-12-13 14:46:58 +00:00
|
|
|
new String[] { uri });
|
|
|
|
|
|
|
|
if (updated == 0)
|
2012-11-13 18:56:58 +00:00
|
|
|
cr.insert(mThumbnailsUriWithProfile, values);
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-01-31 22:13:33 +00:00
|
|
|
public byte[] getThumbnailForUrl(ContentResolver cr, String uri) {
|
2012-11-13 18:56:58 +00:00
|
|
|
Cursor c = cr.query(mThumbnailsUriWithProfile,
|
|
|
|
new String[] { Thumbnails.DATA },
|
|
|
|
Thumbnails.URL + " = ?",
|
2012-01-31 22:13:33 +00:00
|
|
|
new String[] { uri },
|
|
|
|
null);
|
|
|
|
|
|
|
|
if (!c.moveToFirst()) {
|
|
|
|
c.close();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
int thumbnailIndex = c.getColumnIndexOrThrow(Thumbnails.DATA);
|
2012-01-31 22:13:33 +00:00
|
|
|
|
|
|
|
byte[] b = c.getBlob(thumbnailIndex);
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-10-31 12:34:32 +00:00
|
|
|
public Cursor getThumbnailsForUrls(ContentResolver cr, List<String> urls) {
|
|
|
|
StringBuffer selection = new StringBuffer();
|
|
|
|
String[] selectionArgs = new String[urls.size()];
|
|
|
|
|
|
|
|
for (int i = 0; i < urls.size(); i++) {
|
|
|
|
final String url = urls.get(i);
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
selection.append(" OR ");
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
selection.append(Thumbnails.URL + " = ?");
|
2012-10-31 12:34:32 +00:00
|
|
|
selectionArgs[i] = url;
|
|
|
|
}
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
return cr.query(mThumbnailsUriWithProfile,
|
|
|
|
new String[] { Thumbnails.URL, Thumbnails.DATA },
|
2012-10-31 12:34:32 +00:00
|
|
|
selection.toString(),
|
|
|
|
selectionArgs,
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-10-16 14:07:06 +00:00
|
|
|
public void removeThumbnails(ContentResolver cr) {
|
2012-11-13 18:56:58 +00:00
|
|
|
cr.delete(mThumbnailsUriWithProfile, null, null);
|
2012-10-16 14:07:06 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 22:30:47 +00:00
|
|
|
// Utility function for updating existing history using batch operations
|
|
|
|
public void updateHistoryInBatch(ContentResolver cr,
|
|
|
|
Collection<ContentProviderOperation> operations,
|
|
|
|
String url, String title,
|
|
|
|
long date, int visits) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final String[] projection = new String[] {
|
|
|
|
History._ID,
|
|
|
|
History.VISITS,
|
|
|
|
History.DATE_LAST_VISITED
|
|
|
|
};
|
|
|
|
|
|
|
|
// We need to get the old visit count.
|
|
|
|
cursor = cr.query(getAllHistoryUri(),
|
|
|
|
projection,
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { url },
|
|
|
|
null);
|
|
|
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
|
|
|
// Restore deleted record if possible
|
|
|
|
values.put(History.IS_DELETED, 0);
|
|
|
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
int visitsCol = cursor.getColumnIndexOrThrow(History.VISITS);
|
|
|
|
int dateCol = cursor.getColumnIndexOrThrow(History.DATE_LAST_VISITED);
|
|
|
|
int oldVisits = cursor.getInt(visitsCol);
|
|
|
|
long oldDate = cursor.getLong(dateCol);
|
|
|
|
values.put(History.VISITS, oldVisits + visits);
|
|
|
|
// Only update last visited if newer.
|
|
|
|
if (date > oldDate) {
|
|
|
|
values.put(History.DATE_LAST_VISITED, date);
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-13 05:49:38 +00:00
|
|
|
values.put(History.VISITS, visits);
|
2012-06-25 22:30:47 +00:00
|
|
|
values.put(History.DATE_LAST_VISITED, date);
|
|
|
|
}
|
|
|
|
if (title != null) {
|
|
|
|
values.put(History.TITLE, title);
|
|
|
|
}
|
|
|
|
values.put(History.URL, url);
|
|
|
|
|
|
|
|
Uri historyUri = getAllHistoryUri().buildUpon().
|
|
|
|
appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
|
|
|
|
|
|
|
|
// Update or insert
|
|
|
|
ContentProviderOperation.Builder builder =
|
|
|
|
ContentProviderOperation.newUpdate(historyUri);
|
|
|
|
builder.withSelection(History.URL + " = ?", new String[] { url });
|
|
|
|
builder.withValues(values);
|
|
|
|
|
|
|
|
// Queue the operation
|
|
|
|
operations.add(builder.build());
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateBookmarkInBatch(ContentResolver cr,
|
|
|
|
Collection<ContentProviderOperation> operations,
|
|
|
|
String url, String title, String guid,
|
|
|
|
long parent, long added,
|
|
|
|
long modified, long position,
|
|
|
|
String keyword, int type) {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
if (title == null && url != null) {
|
|
|
|
title = url;
|
|
|
|
}
|
|
|
|
if (title != null) {
|
|
|
|
values.put(Bookmarks.TITLE, title);
|
|
|
|
}
|
|
|
|
if (url != null) {
|
|
|
|
values.put(Bookmarks.URL, url);
|
|
|
|
}
|
|
|
|
if (guid != null) {
|
|
|
|
values.put(SyncColumns.GUID, guid);
|
|
|
|
}
|
|
|
|
if (keyword != null) {
|
|
|
|
values.put(Bookmarks.KEYWORD, keyword);
|
|
|
|
}
|
|
|
|
if (added > 0) {
|
|
|
|
values.put(SyncColumns.DATE_CREATED, added);
|
|
|
|
}
|
|
|
|
if (modified > 0) {
|
|
|
|
values.put(SyncColumns.DATE_MODIFIED, modified);
|
|
|
|
}
|
|
|
|
values.put(Bookmarks.POSITION, position);
|
|
|
|
// Restore deleted record if possible
|
|
|
|
values.put(Bookmarks.IS_DELETED, 0);
|
|
|
|
|
|
|
|
// This assumes no "real" folder has a negative ID. Only
|
|
|
|
// things like the reading list folder do.
|
|
|
|
if (parent < 0) {
|
|
|
|
parent = getFolderIdFromGuid(cr, Bookmarks.MOBILE_FOLDER_GUID);
|
|
|
|
}
|
|
|
|
values.put(Bookmarks.PARENT, parent);
|
|
|
|
values.put(Bookmarks.TYPE, type);
|
|
|
|
|
|
|
|
Uri bookmarkUri = getAllBookmarksUri().buildUpon().
|
|
|
|
appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
|
|
|
|
// Update or insert
|
|
|
|
ContentProviderOperation.Builder builder =
|
|
|
|
ContentProviderOperation.newUpdate(bookmarkUri);
|
2012-06-25 22:31:43 +00:00
|
|
|
if (url != null) {
|
|
|
|
// Bookmarks are defined by their URL and Folder.
|
|
|
|
builder.withSelection(Bookmarks.URL + " = ? AND "
|
|
|
|
+ Bookmarks.PARENT + " = ? AND "
|
|
|
|
+ Bookmarks.PARENT + " != ?",
|
|
|
|
new String[] { url,
|
|
|
|
Long.toString(parent),
|
|
|
|
String.valueOf(Bookmarks.FIXED_READING_LIST_ID)
|
|
|
|
});
|
|
|
|
} else if (title != null) {
|
|
|
|
// Or their title and parent folder. (Folders!)
|
|
|
|
builder.withSelection(Bookmarks.TITLE + " = ? AND "
|
|
|
|
+ Bookmarks.PARENT + " = ? AND "
|
|
|
|
+ Bookmarks.PARENT + " != ?",
|
|
|
|
new String[] { title,
|
|
|
|
Long.toString(parent),
|
|
|
|
String.valueOf(Bookmarks.FIXED_READING_LIST_ID)
|
|
|
|
});
|
|
|
|
} else if (type == Bookmarks.TYPE_SEPARATOR) {
|
|
|
|
// Or their their position (seperators)
|
|
|
|
builder.withSelection(Bookmarks.POSITION + " = ? AND "
|
|
|
|
+ Bookmarks.PARENT + " = ? AND "
|
|
|
|
+ Bookmarks.PARENT + " != ?",
|
|
|
|
new String[] { Long.toString(position),
|
|
|
|
Long.toString(parent),
|
|
|
|
String.valueOf(Bookmarks.FIXED_READING_LIST_ID)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Log.e(LOGTAG, "Bookmark entry without url or title and not a seperator, not added.");
|
|
|
|
}
|
2012-06-25 22:30:47 +00:00
|
|
|
builder.withValues(values);
|
|
|
|
|
|
|
|
// Queue the operation
|
|
|
|
operations.add(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateFaviconInBatch(ContentResolver cr,
|
|
|
|
Collection<ContentProviderOperation> operations,
|
|
|
|
String url, String faviconUrl,
|
|
|
|
String faviconGuid, byte[] data) {
|
|
|
|
ContentValues values = new ContentValues();
|
2012-11-13 18:56:58 +00:00
|
|
|
values.put(Favicons.DATA, data);
|
|
|
|
values.put(Favicons.PAGE_URL, url);
|
2012-06-25 22:30:47 +00:00
|
|
|
if (faviconUrl != null) {
|
2012-11-13 18:56:58 +00:00
|
|
|
values.put(Favicons.URL, faviconUrl);
|
2012-06-25 22:30:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update or insert
|
2012-11-13 18:56:58 +00:00
|
|
|
Uri faviconsUri = getAllFaviconsUri().buildUpon().
|
2012-06-25 22:30:47 +00:00
|
|
|
appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
|
|
|
|
// Update or insert
|
|
|
|
ContentProviderOperation.Builder builder =
|
2012-11-13 18:56:58 +00:00
|
|
|
ContentProviderOperation.newUpdate(faviconsUri);
|
2012-06-25 22:30:47 +00:00
|
|
|
builder.withValues(values);
|
2012-11-13 18:56:58 +00:00
|
|
|
builder.withSelection(Favicons.PAGE_URL + " = ?", new String[] { url });
|
2012-06-25 22:30:47 +00:00
|
|
|
// Queue the operation
|
|
|
|
operations.add(builder.build());
|
|
|
|
}
|
|
|
|
|
2012-04-02 18:56:53 +00:00
|
|
|
// This wrapper adds a fake "Desktop Bookmarks" folder entry to the
|
|
|
|
// beginning of the cursor's data set.
|
2012-07-18 00:54:54 +00:00
|
|
|
private class SpecialFoldersCursorWrapper extends CursorWrapper {
|
2012-06-02 18:23:45 +00:00
|
|
|
private int mIndexOffset;
|
|
|
|
|
|
|
|
private int mDesktopBookmarksIndex = -1;
|
|
|
|
private int mReadingListIndex = -1;
|
|
|
|
|
2012-04-02 18:56:53 +00:00
|
|
|
private boolean mAtDesktopBookmarksPosition = false;
|
2012-06-02 18:23:45 +00:00
|
|
|
private boolean mAtReadingListPosition = false;
|
2012-04-02 18:56:53 +00:00
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
public SpecialFoldersCursorWrapper(Cursor c, boolean showDesktopBookmarks, boolean showReadingList) {
|
2012-04-02 18:56:53 +00:00
|
|
|
super(c);
|
2012-06-02 18:23:45 +00:00
|
|
|
|
|
|
|
mIndexOffset = 0;
|
|
|
|
|
|
|
|
if (showDesktopBookmarks) {
|
|
|
|
mDesktopBookmarksIndex = mIndexOffset;
|
|
|
|
mIndexOffset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showReadingList) {
|
|
|
|
mReadingListIndex = mIndexOffset;
|
|
|
|
mIndexOffset++;
|
|
|
|
}
|
2012-04-02 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2012-06-02 18:23:45 +00:00
|
|
|
return super.getCount() + mIndexOffset;
|
2012-04-02 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean moveToPosition(int position) {
|
2012-06-02 18:23:45 +00:00
|
|
|
mAtDesktopBookmarksPosition = (mDesktopBookmarksIndex == position);
|
|
|
|
mAtReadingListPosition = (mReadingListIndex == position);
|
|
|
|
|
|
|
|
if (mAtDesktopBookmarksPosition || mAtReadingListPosition)
|
2012-04-02 18:56:53 +00:00
|
|
|
return true;
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
return super.moveToPosition(position - mIndexOffset);
|
2012-04-02 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getLong(int columnIndex) {
|
2012-06-02 18:23:45 +00:00
|
|
|
if (!mAtDesktopBookmarksPosition && !mAtReadingListPosition)
|
2012-04-02 18:56:53 +00:00
|
|
|
return super.getLong(columnIndex);
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
if (columnIndex == getColumnIndex(Bookmarks.PARENT)) {
|
2012-04-02 18:56:53 +00:00
|
|
|
return Bookmarks.FIXED_ROOT_ID;
|
2012-06-02 18:23:45 +00:00
|
|
|
}
|
2012-04-02 18:56:53 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInt(int columnIndex) {
|
2012-06-02 18:23:45 +00:00
|
|
|
if (!mAtDesktopBookmarksPosition && !mAtReadingListPosition)
|
2012-04-02 18:56:53 +00:00
|
|
|
return super.getInt(columnIndex);
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
if (columnIndex == getColumnIndex(Bookmarks._ID)) {
|
|
|
|
if (mAtDesktopBookmarksPosition) {
|
|
|
|
return Bookmarks.FAKE_DESKTOP_FOLDER_ID;
|
|
|
|
} else if (mAtReadingListPosition) {
|
|
|
|
return Bookmarks.FIXED_READING_LIST_ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-02 18:56:53 +00:00
|
|
|
if (columnIndex == getColumnIndex(Bookmarks.TYPE))
|
|
|
|
return Bookmarks.TYPE_FOLDER;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getString(int columnIndex) {
|
2012-06-02 18:23:45 +00:00
|
|
|
if (!mAtDesktopBookmarksPosition && !mAtReadingListPosition)
|
2012-04-02 18:56:53 +00:00
|
|
|
return super.getString(columnIndex);
|
|
|
|
|
2012-06-02 18:23:45 +00:00
|
|
|
if (columnIndex == getColumnIndex(Bookmarks.GUID)) {
|
|
|
|
if (mAtDesktopBookmarksPosition) {
|
|
|
|
return Bookmarks.FAKE_DESKTOP_FOLDER_GUID;
|
|
|
|
} else if (mAtReadingListPosition) {
|
|
|
|
return Bookmarks.READING_LIST_FOLDER_GUID;
|
|
|
|
}
|
|
|
|
}
|
2012-04-02 18:56:53 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
private static class LocalDBCursor extends CursorWrapper {
|
2011-12-08 16:37:21 +00:00
|
|
|
public LocalDBCursor(Cursor c) {
|
|
|
|
super(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String translateColumnName(String columnName) {
|
|
|
|
if (columnName.equals(BrowserDB.URLColumns.URL)) {
|
2011-12-13 14:46:58 +00:00
|
|
|
columnName = URLColumns.URL;
|
2011-12-08 16:37:21 +00:00
|
|
|
} else if (columnName.equals(BrowserDB.URLColumns.TITLE)) {
|
2011-12-13 14:46:58 +00:00
|
|
|
columnName = URLColumns.TITLE;
|
2011-12-08 16:37:21 +00:00
|
|
|
} else if (columnName.equals(BrowserDB.URLColumns.FAVICON)) {
|
2012-11-13 18:56:58 +00:00
|
|
|
columnName = FaviconColumns.FAVICON;
|
2011-12-08 16:37:21 +00:00
|
|
|
} else if (columnName.equals(BrowserDB.URLColumns.DATE_LAST_VISITED)) {
|
|
|
|
columnName = History.DATE_LAST_VISITED;
|
2012-01-25 21:10:01 +00:00
|
|
|
} else if (columnName.equals(BrowserDB.URLColumns.VISITS)) {
|
|
|
|
columnName = History.VISITS;
|
2011-12-08 16:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return columnName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getColumnIndex(String columnName) {
|
|
|
|
return super.getColumnIndex(translateColumnName(columnName));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getColumnIndexOrThrow(String columnName) {
|
|
|
|
return super.getColumnIndexOrThrow(translateColumnName(columnName));
|
|
|
|
}
|
|
|
|
}
|
2012-12-28 21:46:04 +00:00
|
|
|
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-12-28 21:46:04 +00:00
|
|
|
public void pinSite(ContentResolver cr, String url, String title, int position) {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
final long now = System.currentTimeMillis();
|
|
|
|
values.put(Bookmarks.TITLE, title);
|
|
|
|
values.put(Bookmarks.URL, url);
|
|
|
|
values.put(Bookmarks.PARENT, Bookmarks.FIXED_PINNED_LIST_ID);
|
|
|
|
values.put(Bookmarks.DATE_MODIFIED, now);
|
|
|
|
values.put(Bookmarks.POSITION, position);
|
|
|
|
values.put(Bookmarks.IS_DELETED, 0);
|
|
|
|
|
|
|
|
// If this site is already pinned, unpin it
|
|
|
|
cr.delete(mBookmarksUriWithProfile,
|
|
|
|
Bookmarks.PARENT + " == ? AND " + Bookmarks.URL + " == ?",
|
|
|
|
new String[] {
|
|
|
|
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID),
|
|
|
|
url
|
|
|
|
});
|
|
|
|
|
|
|
|
// If something is already pinned in this spot update it
|
|
|
|
int updated = cr.update(mBookmarksUriWithProfile,
|
|
|
|
values,
|
|
|
|
Bookmarks.POSITION + " = ? AND " +
|
|
|
|
Bookmarks.PARENT + " = ?",
|
|
|
|
new String[] { Integer.toString(position),
|
|
|
|
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) });
|
|
|
|
|
|
|
|
// Otherwise just insert a new item
|
|
|
|
if (updated == 0) {
|
|
|
|
cr.insert(mBookmarksUriWithProfile, values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-12-28 21:46:04 +00:00
|
|
|
public Cursor getPinnedSites(ContentResolver cr, int limit) {
|
|
|
|
return cr.query(bookmarksUriWithLimit(limit),
|
|
|
|
new String[] { Bookmarks._ID,
|
|
|
|
Bookmarks.URL,
|
|
|
|
Bookmarks.TITLE,
|
|
|
|
Bookmarks.POSITION },
|
|
|
|
Bookmarks.PARENT + " == ?",
|
|
|
|
new String[] { String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) },
|
|
|
|
Bookmarks.POSITION + " ASC");
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-12-28 21:46:04 +00:00
|
|
|
public void unpinSite(ContentResolver cr, int position) {
|
|
|
|
cr.delete(mBookmarksUriWithProfile,
|
|
|
|
Bookmarks.PARENT + " == ? AND " + Bookmarks.POSITION + " = ?",
|
|
|
|
new String[] {
|
|
|
|
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID),
|
|
|
|
Integer.toString(position)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-12-28 21:46:04 +00:00
|
|
|
public void unpinAllSites(ContentResolver cr) {
|
|
|
|
cr.delete(mBookmarksUriWithProfile,
|
|
|
|
Bookmarks.PARENT + " == ?",
|
|
|
|
new String[] {
|
|
|
|
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID)
|
|
|
|
});
|
|
|
|
}
|
2013-01-30 17:26:07 +00:00
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-01-30 17:26:07 +00:00
|
|
|
public boolean isVisited(ContentResolver cr, String uri) {
|
|
|
|
int count = 0;
|
|
|
|
try {
|
|
|
|
Cursor c = cr.query(historyUriWithLimit(1),
|
|
|
|
new String[] { History._ID },
|
|
|
|
History.URL + " = ?",
|
|
|
|
new String[] { uri },
|
|
|
|
History.URL);
|
|
|
|
count = c.getCount();
|
|
|
|
c.close();
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
Log.e(LOGTAG, "NullPointerException in isVisited");
|
|
|
|
}
|
|
|
|
|
|
|
|
return (count > 0);
|
|
|
|
}
|
2011-12-13 14:46:58 +00:00
|
|
|
}
|