2011-12-02 09:27:56 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Lucas Rocha <lucasr@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
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:%";
|
|
|
|
|
2011-12-02 09:27:56 -08: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";
|
2012-01-25 13:10:01 -08:00
|
|
|
public static String VISITS = "visits";
|
2012-02-07 17:55:12 -08:00
|
|
|
public static String KEYWORD = "keyword";
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private static BrowserDBIface sDb;
|
|
|
|
|
|
|
|
public interface BrowserDBIface {
|
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-01-25 13:10:01 -08:00
|
|
|
public int getMaxHistoryCount();
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public void clearHistory(ContentResolver cr);
|
|
|
|
|
2012-02-07 11:03:02 -08:00
|
|
|
public Cursor getMobileBookmarks(ContentResolver cr);
|
|
|
|
|
|
|
|
public Cursor getDesktopBookmarks(ContentResolver cr);
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public boolean isBookmark(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-02-07 17:55:12 -08:00
|
|
|
public void updateBookmark(ContentResolver cr, String oldUri, String uri, String title, String keyword);
|
|
|
|
|
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);
|
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
|
|
|
|
sDb = new LocalBrowserDB(BrowserContract.DEFAULT_PROFILE);
|
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-01-25 13:10:01 -08:00
|
|
|
public static int getMaxHistoryCount() {
|
|
|
|
return sDb.getMaxHistoryCount();
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static void clearHistory(ContentResolver cr) {
|
|
|
|
sDb.clearHistory(cr);
|
|
|
|
}
|
|
|
|
|
2012-02-07 11:03:02 -08:00
|
|
|
public static Cursor getMobileBookmarks(ContentResolver cr) {
|
|
|
|
return sDb.getMobileBookmarks(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Cursor getDesktopBookmarks(ContentResolver cr) {
|
|
|
|
return sDb.getDesktopBookmarks(cr);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-07 17:55:12 -08:00
|
|
|
public static void updateBookmark(ContentResolver cr, String oldUri, String uri, String title, String keyword) {
|
|
|
|
sDb.updateBookmark(cr, oldUri, uri, title, keyword);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unregisterBookmarkObserver(ContentResolver cr, ContentObserver observer) {
|
|
|
|
cr.unregisterContentObserver(observer);
|
|
|
|
}
|
2012-01-04 21:34:06 -08:00
|
|
|
}
|