michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.db; michael@0: michael@0: import org.mozilla.gecko.AppConstants; michael@0: michael@0: import android.net.Uri; michael@0: import org.mozilla.gecko.mozglue.RobocopTarget; michael@0: michael@0: @RobocopTarget michael@0: public class BrowserContract { michael@0: public static final String AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.browser"; michael@0: public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); michael@0: michael@0: public static final String PASSWORDS_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.passwords"; michael@0: public static final Uri PASSWORDS_AUTHORITY_URI = Uri.parse("content://" + PASSWORDS_AUTHORITY); michael@0: michael@0: public static final String FORM_HISTORY_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.formhistory"; michael@0: public static final Uri FORM_HISTORY_AUTHORITY_URI = Uri.parse("content://" + FORM_HISTORY_AUTHORITY); michael@0: michael@0: public static final String TABS_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.tabs"; michael@0: public static final Uri TABS_AUTHORITY_URI = Uri.parse("content://" + TABS_AUTHORITY); michael@0: michael@0: public static final String HOME_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.home"; michael@0: public static final Uri HOME_AUTHORITY_URI = Uri.parse("content://" + HOME_AUTHORITY); michael@0: michael@0: public static final String PROFILES_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".profiles"; michael@0: public static final Uri PROFILES_AUTHORITY_URI = Uri.parse("content://" + PROFILES_AUTHORITY); michael@0: michael@0: public static final String READING_LIST_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.readinglist"; michael@0: public static final Uri READING_LIST_AUTHORITY_URI = Uri.parse("content://" + READING_LIST_AUTHORITY); michael@0: michael@0: public static final String PARAM_PROFILE = "profile"; michael@0: public static final String PARAM_PROFILE_PATH = "profilePath"; michael@0: public static final String PARAM_LIMIT = "limit"; michael@0: public static final String PARAM_IS_SYNC = "sync"; michael@0: public static final String PARAM_SHOW_DELETED = "show_deleted"; michael@0: public static final String PARAM_IS_TEST = "test"; michael@0: public static final String PARAM_INSERT_IF_NEEDED = "insert_if_needed"; michael@0: public static final String PARAM_INCREMENT_VISITS = "increment_visits"; michael@0: public static final String PARAM_EXPIRE_PRIORITY = "priority"; michael@0: public static final String PARAM_DATASET_ID = "dataset_id"; michael@0: michael@0: static public enum ExpirePriority { michael@0: NORMAL, michael@0: AGGRESSIVE michael@0: } michael@0: michael@0: static public String getFrecencySortOrder(boolean includesBookmarks, boolean asc) { michael@0: final String age = "(" + Combined.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000"; michael@0: michael@0: StringBuilder order = new StringBuilder(Combined.VISITS + " * MAX(1, 100 * 225 / (" + age + "*" + age + " + 225)) "); michael@0: michael@0: if (includesBookmarks) { michael@0: order.insert(0, "(CASE WHEN " + Combined.BOOKMARK_ID + " > -1 THEN 100 ELSE 0 END) + "); michael@0: } michael@0: michael@0: order.append(asc ? " ASC" : " DESC"); michael@0: return order.toString(); michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public interface CommonColumns { michael@0: public static final String _ID = "_id"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public interface DateSyncColumns { michael@0: public static final String DATE_CREATED = "created"; michael@0: public static final String DATE_MODIFIED = "modified"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public interface SyncColumns extends DateSyncColumns { michael@0: public static final String GUID = "guid"; michael@0: public static final String IS_DELETED = "deleted"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public interface URLColumns { michael@0: public static final String URL = "url"; michael@0: public static final String TITLE = "title"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public interface FaviconColumns { michael@0: public static final String FAVICON = "favicon"; michael@0: public static final String FAVICON_ID = "favicon_id"; michael@0: public static final String FAVICON_URL = "favicon_url"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public interface HistoryColumns { michael@0: public static final String DATE_LAST_VISITED = "date"; michael@0: public static final String VISITS = "visits"; michael@0: } michael@0: michael@0: public interface DeletedColumns { michael@0: public static final String ID = "id"; michael@0: public static final String GUID = "guid"; michael@0: public static final String TIME_DELETED = "timeDeleted"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public static final class Favicons implements CommonColumns, DateSyncColumns { michael@0: private Favicons() {} michael@0: michael@0: public static final String TABLE_NAME = "favicons"; michael@0: michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "favicons"); michael@0: michael@0: public static final String URL = "url"; michael@0: public static final String DATA = "data"; michael@0: public static final String PAGE_URL = "page_url"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public static final class Thumbnails implements CommonColumns { michael@0: private Thumbnails() {} michael@0: michael@0: public static final String TABLE_NAME = "thumbnails"; michael@0: michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "thumbnails"); michael@0: michael@0: public static final String URL = "url"; michael@0: public static final String DATA = "data"; michael@0: } michael@0: michael@0: public static final class Profiles { michael@0: private Profiles() {} michael@0: public static final String NAME = "name"; michael@0: public static final String PATH = "path"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public static final class Bookmarks implements CommonColumns, URLColumns, FaviconColumns, SyncColumns { michael@0: private Bookmarks() {} michael@0: michael@0: public static final String TABLE_NAME = "bookmarks"; michael@0: michael@0: public static final String VIEW_WITH_FAVICONS = "bookmarks_with_favicons"; michael@0: michael@0: public static final int FIXED_ROOT_ID = 0; michael@0: public static final int FAKE_DESKTOP_FOLDER_ID = -1; michael@0: public static final int FIXED_READING_LIST_ID = -2; michael@0: public static final int FIXED_PINNED_LIST_ID = -3; michael@0: michael@0: public static final String MOBILE_FOLDER_GUID = "mobile"; michael@0: public static final String PLACES_FOLDER_GUID = "places"; michael@0: public static final String MENU_FOLDER_GUID = "menu"; michael@0: public static final String TAGS_FOLDER_GUID = "tags"; michael@0: public static final String TOOLBAR_FOLDER_GUID = "toolbar"; michael@0: public static final String UNFILED_FOLDER_GUID = "unfiled"; michael@0: public static final String READING_LIST_FOLDER_GUID = "readinglist"; michael@0: public static final String FAKE_DESKTOP_FOLDER_GUID = "desktop"; michael@0: public static final String PINNED_FOLDER_GUID = "pinned"; michael@0: michael@0: public static final int TYPE_FOLDER = 0; michael@0: public static final int TYPE_BOOKMARK = 1; michael@0: public static final int TYPE_SEPARATOR = 2; michael@0: public static final int TYPE_LIVEMARK = 3; michael@0: public static final int TYPE_QUERY = 4; michael@0: michael@0: /* michael@0: * These values are returned by getItemFlags. They're not really michael@0: * exclusive to bookmarks, but there's no better place to put them. michael@0: */ michael@0: public static final int FLAG_SUCCESS = 1 << 1; // The query succeeded. michael@0: public static final int FLAG_BOOKMARK = 1 << 2; michael@0: public static final int FLAG_PINNED = 1 << 3; michael@0: public static final int FLAG_READING = 1 << 4; michael@0: michael@0: public static final Uri FLAGS_URI = Uri.withAppendedPath(AUTHORITY_URI, "flags"); michael@0: michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "bookmarks"); michael@0: public static final Uri PARENTS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "parents"); michael@0: // Hacky API for bulk-updating positions. Bug 728783. michael@0: public static final Uri POSITIONS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "positions"); michael@0: public static final long DEFAULT_POSITION = Long.MIN_VALUE; michael@0: michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/bookmark"; michael@0: public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/bookmark"; michael@0: public static final String TYPE = "type"; michael@0: public static final String PARENT = "parent"; michael@0: public static final String POSITION = "position"; michael@0: public static final String TAGS = "tags"; michael@0: public static final String DESCRIPTION = "description"; michael@0: public static final String KEYWORD = "keyword"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public static final class History implements CommonColumns, URLColumns, HistoryColumns, FaviconColumns, SyncColumns { michael@0: private History() {} michael@0: michael@0: public static final String TABLE_NAME = "history"; michael@0: michael@0: public static final String VIEW_WITH_FAVICONS = "history_with_favicons"; michael@0: michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "history"); michael@0: public static final Uri CONTENT_OLD_URI = Uri.withAppendedPath(AUTHORITY_URI, "history/old"); michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/browser-history"; michael@0: public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/browser-history"; michael@0: } michael@0: michael@0: // Combined bookmarks and history michael@0: @RobocopTarget michael@0: public static final class Combined implements CommonColumns, URLColumns, HistoryColumns, FaviconColumns { michael@0: private Combined() {} michael@0: michael@0: public static final String VIEW_NAME = "combined"; michael@0: michael@0: public static final String VIEW_WITH_FAVICONS = "combined_with_favicons"; michael@0: michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "combined"); michael@0: michael@0: public static final int DISPLAY_NORMAL = 0; michael@0: public static final int DISPLAY_READER = 1; michael@0: michael@0: public static final String BOOKMARK_ID = "bookmark_id"; michael@0: public static final String HISTORY_ID = "history_id"; michael@0: public static final String DISPLAY = "display"; michael@0: } michael@0: michael@0: public static final class Schema { michael@0: private Schema() {} michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "schema"); michael@0: michael@0: public static final String VERSION = "version"; michael@0: } michael@0: michael@0: public static final class Passwords { michael@0: private Passwords() {} michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "passwords"); michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/passwords"; michael@0: michael@0: public static final String ID = "id"; michael@0: public static final String HOSTNAME = "hostname"; michael@0: public static final String HTTP_REALM = "httpRealm"; michael@0: public static final String FORM_SUBMIT_URL = "formSubmitURL"; michael@0: public static final String USERNAME_FIELD = "usernameField"; michael@0: public static final String PASSWORD_FIELD = "passwordField"; michael@0: public static final String ENCRYPTED_USERNAME = "encryptedUsername"; michael@0: public static final String ENCRYPTED_PASSWORD = "encryptedPassword"; michael@0: public static final String ENC_TYPE = "encType"; michael@0: public static final String TIME_CREATED = "timeCreated"; michael@0: public static final String TIME_LAST_USED = "timeLastUsed"; michael@0: public static final String TIME_PASSWORD_CHANGED = "timePasswordChanged"; michael@0: public static final String TIMES_USED = "timesUsed"; michael@0: public static final String GUID = "guid"; michael@0: michael@0: // This needs to be kept in sync with the types defined in toolkit/components/passwordmgr/nsILoginManagerCrypto.idl#45 michael@0: public static final int ENCTYPE_SDR = 1; michael@0: } michael@0: michael@0: public static final class DeletedPasswords implements DeletedColumns { michael@0: private DeletedPasswords() {} michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/deleted-passwords"; michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "deleted-passwords"); michael@0: } michael@0: michael@0: public static final class FormHistory { michael@0: private FormHistory() {} michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "formhistory"); michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/formhistory"; michael@0: michael@0: public static final String ID = "id"; michael@0: public static final String FIELD_NAME = "fieldname"; michael@0: public static final String VALUE = "value"; michael@0: public static final String TIMES_USED = "timesUsed"; michael@0: public static final String FIRST_USED = "firstUsed"; michael@0: public static final String LAST_USED = "lastUsed"; michael@0: public static final String GUID = "guid"; michael@0: } michael@0: michael@0: public static final class DeletedFormHistory implements DeletedColumns { michael@0: private DeletedFormHistory() {} michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "deleted-formhistory"); michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/deleted-formhistory"; michael@0: } michael@0: michael@0: public static final class Tabs implements CommonColumns { michael@0: private Tabs() {} michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(TABS_AUTHORITY_URI, "tabs"); michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/tab"; michael@0: public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/tab"; michael@0: michael@0: // Title of the tab. michael@0: public static final String TITLE = "title"; michael@0: michael@0: // Topmost URL from the history array. Allows processing of this tab without michael@0: // parsing that array. michael@0: public static final String URL = "url"; michael@0: michael@0: // Sync-assigned GUID for client device. NULL for local tabs. michael@0: public static final String CLIENT_GUID = "client_guid"; michael@0: michael@0: // JSON-encoded array of history URL strings, from most recent to least recent. michael@0: public static final String HISTORY = "history"; michael@0: michael@0: // Favicon URL for the tab's topmost history entry. michael@0: public static final String FAVICON = "favicon"; michael@0: michael@0: // Last used time of the tab. michael@0: public static final String LAST_USED = "last_used"; michael@0: michael@0: // Position of the tab. 0 represents foreground. michael@0: public static final String POSITION = "position"; michael@0: } michael@0: michael@0: public static final class Clients { michael@0: private Clients() {} michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(TABS_AUTHORITY_URI, "clients"); michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/client"; michael@0: public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/client"; michael@0: michael@0: // Implicit rowid in SQL table. michael@0: public static final String ROWID = "rowid"; michael@0: michael@0: // Client-provided name string. Could conceivably be null. michael@0: public static final String NAME = "name"; michael@0: michael@0: // Sync-assigned GUID for client device. NULL for local tabs. michael@0: public static final String GUID = "guid"; michael@0: michael@0: // Last modified time for the client's tab record. For remote records, a server michael@0: // timestamp provided by Sync during insertion. michael@0: public static final String LAST_MODIFIED = "last_modified"; michael@0: } michael@0: michael@0: // Data storage for dynamic panels on about:home michael@0: @RobocopTarget michael@0: public static final class HomeItems implements CommonColumns { michael@0: private HomeItems() {} michael@0: public static final Uri CONTENT_FAKE_URI = Uri.withAppendedPath(HOME_AUTHORITY_URI, "items/fake"); michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(HOME_AUTHORITY_URI, "items"); michael@0: michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/homeitem"; michael@0: public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/homeitem"; michael@0: michael@0: public static final String DATASET_ID = "dataset_id"; michael@0: public static final String URL = "url"; michael@0: public static final String TITLE = "title"; michael@0: public static final String DESCRIPTION = "description"; michael@0: public static final String IMAGE_URL = "image_url"; michael@0: public static final String CREATED = "created"; michael@0: public static final String FILTER = "filter"; michael@0: michael@0: public static final String[] DEFAULT_PROJECTION = michael@0: new String[] { _ID, DATASET_ID, URL, TITLE, DESCRIPTION, IMAGE_URL, FILTER }; michael@0: } michael@0: michael@0: /* michael@0: * Contains names and schema definitions for tables and views michael@0: * no longer being used by current ContentProviders. These values are used michael@0: * to make incremental updates to the schema during a database upgrade. Will be michael@0: * removed with bug 947018. michael@0: */ michael@0: static final class Obsolete { michael@0: public static final String TABLE_IMAGES = "images"; michael@0: public static final String VIEW_BOOKMARKS_WITH_IMAGES = "bookmarks_with_images"; michael@0: public static final String VIEW_HISTORY_WITH_IMAGES = "history_with_images"; michael@0: public static final String VIEW_COMBINED_WITH_IMAGES = "combined_with_images"; michael@0: michael@0: public static final class Images implements CommonColumns, SyncColumns { michael@0: private Images() {} michael@0: michael@0: public static final String URL = "url_key"; michael@0: public static final String FAVICON_URL = "favicon_url"; michael@0: public static final String FAVICON = "favicon"; michael@0: public static final String THUMBNAIL = "thumbnail"; michael@0: public static final String _ID = "_id"; michael@0: public static final String GUID = "guid"; michael@0: public static final String DATE_CREATED = "created"; michael@0: public static final String DATE_MODIFIED = "modified"; michael@0: public static final String IS_DELETED = "deleted"; michael@0: } michael@0: michael@0: public static final class Combined { michael@0: private Combined() {} michael@0: michael@0: public static final String THUMBNAIL = "thumbnail"; michael@0: } michael@0: michael@0: static final String TABLE_BOOKMARKS_JOIN_IMAGES = Bookmarks.TABLE_NAME + " LEFT OUTER JOIN " + michael@0: Obsolete.TABLE_IMAGES + " ON " + Bookmarks.TABLE_NAME + "." + Bookmarks.URL + " = " + michael@0: Obsolete.TABLE_IMAGES + "." + Obsolete.Images.URL; michael@0: michael@0: static final String TABLE_HISTORY_JOIN_IMAGES = History.TABLE_NAME + " LEFT OUTER JOIN " + michael@0: Obsolete.TABLE_IMAGES + " ON " + Bookmarks.TABLE_NAME + "." + History.URL + " = " + michael@0: Obsolete.TABLE_IMAGES + "." + Obsolete.Images.URL; michael@0: michael@0: static final String FAVICON_DB = "favicon_urls.db"; michael@0: } michael@0: michael@0: @RobocopTarget michael@0: public static final class ReadingListItems implements CommonColumns, URLColumns, SyncColumns { michael@0: private ReadingListItems() {} michael@0: public static final Uri CONTENT_URI = Uri.withAppendedPath(READING_LIST_AUTHORITY_URI, "items"); michael@0: michael@0: public static final String CONTENT_TYPE = "vnd.android.cursor.dir/readinglistitem"; michael@0: public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/readinglistitem"; michael@0: michael@0: public static final String EXCERPT = "excerpt"; michael@0: public static final String READ = "read"; michael@0: public static final String LENGTH = "length"; michael@0: public static final String DEFAULT_SORT_ORDER = DATE_MODIFIED + " DESC"; michael@0: public static final String[] DEFAULT_PROJECTION = new String[] { _ID, URL, TITLE, EXCERPT, LENGTH }; michael@0: michael@0: // Minimum fields required to create a reading list item. michael@0: public static final String[] REQUIRED_FIELDS = { Bookmarks.URL, Bookmarks.TITLE }; michael@0: michael@0: public static final String TABLE_NAME = "reading_list"; michael@0: } michael@0: michael@0: }