2011-12-02 09:27:56 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07: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-02 09:27:56 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko.db;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
2012-02-14 16:23:06 -08:00
|
|
|
import android.database.ContentObserver;
|
2011-12-02 09:27:56 -08:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
|
|
|
|
public class BrowserDB {
|
2012-01-19 09:23:10 -08:00
|
|
|
public static String ABOUT_PAGES_URL_FILTER = "about:%";
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public static interface URLColumns {
|
|
|
|
public static String URL = "url";
|
|
|
|
public static String TITLE = "title";
|
|
|
|
public static String FAVICON = "favicon";
|
|
|
|
public static String THUMBNAIL = "thumbnail";
|
|
|
|
public static String DATE_LAST_VISITED = "date-last-visited";
|
|
|
|
public static String VISITS = "visits";
|
|
|
|
public static String KEYWORD = "keyword";
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
2012-06-15 09:02:11 -07:00
|
|
|
private static BrowserDBIface sDb = null;
|
2011-12-02 09:27:56 -08:00
|
|
|
|
|
|
|
public interface BrowserDBIface {
|
2012-03-19 11:22:33 -07:00
|
|
|
public void invalidateCachedState();
|
|
|
|
|
2012-01-19 09:23:10 -08:00
|
|
|
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit);
|
|
|
|
|
|
|
|
public Cursor getTopSites(ContentResolver cr, int limit);
|
2011-12-02 09:27:56 -08:00
|
|
|
|
|
|
|
public void updateVisitedHistory(ContentResolver cr, String uri);
|
|
|
|
|
|
|
|
public void updateHistoryTitle(ContentResolver cr, String uri, String title);
|
|
|
|
|
2012-01-25 13:10:01 -08:00
|
|
|
public void updateHistoryEntry(ContentResolver cr, String uri, String title,
|
|
|
|
long date, int visits);
|
2011-12-19 13:56:11 -08:00
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public Cursor getAllVisitedHistory(ContentResolver cr);
|
|
|
|
|
|
|
|
public Cursor getRecentHistory(ContentResolver cr, int limit);
|
|
|
|
|
2012-05-14 11:44:34 -07:00
|
|
|
public void removeHistoryEntry(ContentResolver cr, int id);
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public void clearHistory(ContentResolver cr);
|
|
|
|
|
2012-02-23 10:48:47 -08:00
|
|
|
public Cursor getBookmarksInFolder(ContentResolver cr, long folderId);
|
2012-02-07 11:03:02 -08:00
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public boolean isBookmark(ContentResolver cr, String uri);
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public boolean isReadingListItem(ContentResolver cr, String uri);
|
|
|
|
|
2012-02-07 17:55:12 -08:00
|
|
|
public String getUrlForKeyword(ContentResolver cr, String keyword);
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public void addBookmark(ContentResolver cr, String title, String uri);
|
|
|
|
|
2012-02-09 10:01:57 -08:00
|
|
|
public void removeBookmark(ContentResolver cr, int id);
|
|
|
|
|
|
|
|
public void removeBookmarksWithURL(ContentResolver cr, String uri);
|
2011-12-02 09:27:56 -08:00
|
|
|
|
2012-05-07 15:33:07 -07:00
|
|
|
public void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword);
|
2012-02-07 17:55:12 -08:00
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
public void addReadingListItem(ContentResolver cr, String title, String uri);
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public void removeReadingListItemWithURL(ContentResolver cr, String uri);
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public BitmapDrawable getFaviconForUrl(ContentResolver cr, String uri);
|
|
|
|
|
|
|
|
public void updateFaviconForUrl(ContentResolver cr, String uri, BitmapDrawable favicon);
|
|
|
|
|
|
|
|
public void updateThumbnailForUrl(ContentResolver cr, String uri, BitmapDrawable thumbnail);
|
2012-01-31 14:13:33 -08:00
|
|
|
|
|
|
|
public byte[] getThumbnailForUrl(ContentResolver cr, String uri);
|
2012-02-14 16:23:06 -08:00
|
|
|
|
|
|
|
public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer);
|
2012-05-14 11:44:37 -07:00
|
|
|
|
|
|
|
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
2012-01-11 11:47:19 -08:00
|
|
|
// Forcing local DB no option to switch to Android DB for now
|
2012-06-15 09:02:11 -07:00
|
|
|
sDb = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void initialize(String profile) {
|
|
|
|
sDb = new LocalBrowserDB(profile);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
2012-03-19 11:22:33 -07:00
|
|
|
|
|
|
|
public static void invalidateCachedState() {
|
|
|
|
sDb.invalidateCachedState();
|
|
|
|
}
|
2011-12-02 09:27:56 -08:00
|
|
|
|
2012-01-19 09:23:10 -08:00
|
|
|
public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
|
|
|
|
return sDb.filter(cr, constraint, limit);
|
2012-01-04 21:34:06 -08:00
|
|
|
}
|
|
|
|
|
2012-01-19 09:23:10 -08:00
|
|
|
public static Cursor getTopSites(ContentResolver cr, int limit) {
|
|
|
|
return sDb.getTopSites(cr, limit);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateVisitedHistory(ContentResolver cr, String uri) {
|
|
|
|
sDb.updateVisitedHistory(cr, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateHistoryTitle(ContentResolver cr, String uri, String title) {
|
|
|
|
sDb.updateHistoryTitle(cr, uri, title);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:10:01 -08:00
|
|
|
public static void updateHistoryEntry(ContentResolver cr, String uri, String title,
|
|
|
|
long date, int visits) {
|
|
|
|
sDb.updateHistoryEntry(cr, uri, title, date, visits);
|
2011-12-19 13:56:11 -08:00
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static Cursor getAllVisitedHistory(ContentResolver cr) {
|
|
|
|
return sDb.getAllVisitedHistory(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Cursor getRecentHistory(ContentResolver cr, int limit) {
|
|
|
|
return sDb.getRecentHistory(cr, limit);
|
|
|
|
}
|
|
|
|
|
2012-05-14 11:44:34 -07:00
|
|
|
public static void removeHistoryEntry(ContentResolver cr, int id) {
|
|
|
|
sDb.removeHistoryEntry(cr, id);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static void clearHistory(ContentResolver cr) {
|
|
|
|
sDb.clearHistory(cr);
|
|
|
|
}
|
|
|
|
|
2012-02-23 10:48:47 -08:00
|
|
|
public static Cursor getBookmarksInFolder(ContentResolver cr, long folderId) {
|
|
|
|
return sDb.getBookmarksInFolder(cr, folderId);
|
2012-02-07 11:03:02 -08:00
|
|
|
}
|
|
|
|
|
2012-02-07 17:55:12 -08:00
|
|
|
public static String getUrlForKeyword(ContentResolver cr, String keyword) {
|
|
|
|
return sDb.getUrlForKeyword(cr, keyword);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static boolean isBookmark(ContentResolver cr, String uri) {
|
|
|
|
return sDb.isBookmark(cr, uri);
|
|
|
|
}
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public static boolean isReadingListItem(ContentResolver cr, String uri) {
|
|
|
|
return sDb.isReadingListItem(cr, uri);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static void addBookmark(ContentResolver cr, String title, String uri) {
|
|
|
|
sDb.addBookmark(cr, title, uri);
|
|
|
|
}
|
|
|
|
|
2012-02-09 10:01:57 -08:00
|
|
|
public static void removeBookmark(ContentResolver cr, int id) {
|
|
|
|
sDb.removeBookmark(cr, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeBookmarksWithURL(ContentResolver cr, String uri) {
|
|
|
|
sDb.removeBookmarksWithURL(cr, uri);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
2012-05-07 15:33:07 -07:00
|
|
|
public static void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword) {
|
|
|
|
sDb.updateBookmark(cr, id, uri, title, keyword);
|
2012-02-07 17:55:12 -08:00
|
|
|
}
|
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
public static void addReadingListItem(ContentResolver cr, String title, String uri) {
|
|
|
|
sDb.addReadingListItem(cr, title, uri);
|
|
|
|
}
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public static void removeReadingListItemWithURL(ContentResolver cr, String uri) {
|
|
|
|
sDb.removeReadingListItemWithURL(cr, uri);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static BitmapDrawable getFaviconForUrl(ContentResolver cr, String uri) {
|
|
|
|
return sDb.getFaviconForUrl(cr, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateFaviconForUrl(ContentResolver cr, String uri, BitmapDrawable favicon) {
|
|
|
|
sDb.updateFaviconForUrl(cr, uri, favicon);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateThumbnailForUrl(ContentResolver cr, String uri, BitmapDrawable thumbnail) {
|
|
|
|
sDb.updateThumbnailForUrl(cr, uri, thumbnail);
|
|
|
|
}
|
2012-01-31 14:13:33 -08:00
|
|
|
|
|
|
|
public static byte[] getThumbnailForUrl(ContentResolver cr, String uri) {
|
|
|
|
return sDb.getThumbnailForUrl(cr, uri);
|
|
|
|
}
|
2012-02-14 16:23:06 -08:00
|
|
|
|
|
|
|
public static void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) {
|
|
|
|
sDb.registerBookmarkObserver(cr, observer);
|
|
|
|
}
|
|
|
|
|
2012-05-14 11:44:37 -07:00
|
|
|
public static void registerHistoryObserver(ContentResolver cr, ContentObserver observer) {
|
|
|
|
sDb.registerHistoryObserver(cr, observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unregisterContentObserver(ContentResolver cr, ContentObserver observer) {
|
2012-02-14 16:23:06 -08:00
|
|
|
cr.unregisterContentObserver(observer);
|
|
|
|
}
|
2012-01-04 21:34:06 -08:00
|
|
|
}
|