1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/db/BrowserContract.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,418 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.db; 1.10 + 1.11 +import org.mozilla.gecko.AppConstants; 1.12 + 1.13 +import android.net.Uri; 1.14 +import org.mozilla.gecko.mozglue.RobocopTarget; 1.15 + 1.16 +@RobocopTarget 1.17 +public class BrowserContract { 1.18 + public static final String AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.browser"; 1.19 + public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); 1.20 + 1.21 + public static final String PASSWORDS_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.passwords"; 1.22 + public static final Uri PASSWORDS_AUTHORITY_URI = Uri.parse("content://" + PASSWORDS_AUTHORITY); 1.23 + 1.24 + public static final String FORM_HISTORY_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.formhistory"; 1.25 + public static final Uri FORM_HISTORY_AUTHORITY_URI = Uri.parse("content://" + FORM_HISTORY_AUTHORITY); 1.26 + 1.27 + public static final String TABS_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.tabs"; 1.28 + public static final Uri TABS_AUTHORITY_URI = Uri.parse("content://" + TABS_AUTHORITY); 1.29 + 1.30 + public static final String HOME_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.home"; 1.31 + public static final Uri HOME_AUTHORITY_URI = Uri.parse("content://" + HOME_AUTHORITY); 1.32 + 1.33 + public static final String PROFILES_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".profiles"; 1.34 + public static final Uri PROFILES_AUTHORITY_URI = Uri.parse("content://" + PROFILES_AUTHORITY); 1.35 + 1.36 + public static final String READING_LIST_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.readinglist"; 1.37 + public static final Uri READING_LIST_AUTHORITY_URI = Uri.parse("content://" + READING_LIST_AUTHORITY); 1.38 + 1.39 + public static final String PARAM_PROFILE = "profile"; 1.40 + public static final String PARAM_PROFILE_PATH = "profilePath"; 1.41 + public static final String PARAM_LIMIT = "limit"; 1.42 + public static final String PARAM_IS_SYNC = "sync"; 1.43 + public static final String PARAM_SHOW_DELETED = "show_deleted"; 1.44 + public static final String PARAM_IS_TEST = "test"; 1.45 + public static final String PARAM_INSERT_IF_NEEDED = "insert_if_needed"; 1.46 + public static final String PARAM_INCREMENT_VISITS = "increment_visits"; 1.47 + public static final String PARAM_EXPIRE_PRIORITY = "priority"; 1.48 + public static final String PARAM_DATASET_ID = "dataset_id"; 1.49 + 1.50 + static public enum ExpirePriority { 1.51 + NORMAL, 1.52 + AGGRESSIVE 1.53 + } 1.54 + 1.55 + static public String getFrecencySortOrder(boolean includesBookmarks, boolean asc) { 1.56 + final String age = "(" + Combined.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000"; 1.57 + 1.58 + StringBuilder order = new StringBuilder(Combined.VISITS + " * MAX(1, 100 * 225 / (" + age + "*" + age + " + 225)) "); 1.59 + 1.60 + if (includesBookmarks) { 1.61 + order.insert(0, "(CASE WHEN " + Combined.BOOKMARK_ID + " > -1 THEN 100 ELSE 0 END) + "); 1.62 + } 1.63 + 1.64 + order.append(asc ? " ASC" : " DESC"); 1.65 + return order.toString(); 1.66 + } 1.67 + 1.68 + @RobocopTarget 1.69 + public interface CommonColumns { 1.70 + public static final String _ID = "_id"; 1.71 + } 1.72 + 1.73 + @RobocopTarget 1.74 + public interface DateSyncColumns { 1.75 + public static final String DATE_CREATED = "created"; 1.76 + public static final String DATE_MODIFIED = "modified"; 1.77 + } 1.78 + 1.79 + @RobocopTarget 1.80 + public interface SyncColumns extends DateSyncColumns { 1.81 + public static final String GUID = "guid"; 1.82 + public static final String IS_DELETED = "deleted"; 1.83 + } 1.84 + 1.85 + @RobocopTarget 1.86 + public interface URLColumns { 1.87 + public static final String URL = "url"; 1.88 + public static final String TITLE = "title"; 1.89 + } 1.90 + 1.91 + @RobocopTarget 1.92 + public interface FaviconColumns { 1.93 + public static final String FAVICON = "favicon"; 1.94 + public static final String FAVICON_ID = "favicon_id"; 1.95 + public static final String FAVICON_URL = "favicon_url"; 1.96 + } 1.97 + 1.98 + @RobocopTarget 1.99 + public interface HistoryColumns { 1.100 + public static final String DATE_LAST_VISITED = "date"; 1.101 + public static final String VISITS = "visits"; 1.102 + } 1.103 + 1.104 + public interface DeletedColumns { 1.105 + public static final String ID = "id"; 1.106 + public static final String GUID = "guid"; 1.107 + public static final String TIME_DELETED = "timeDeleted"; 1.108 + } 1.109 + 1.110 + @RobocopTarget 1.111 + public static final class Favicons implements CommonColumns, DateSyncColumns { 1.112 + private Favicons() {} 1.113 + 1.114 + public static final String TABLE_NAME = "favicons"; 1.115 + 1.116 + public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "favicons"); 1.117 + 1.118 + public static final String URL = "url"; 1.119 + public static final String DATA = "data"; 1.120 + public static final String PAGE_URL = "page_url"; 1.121 + } 1.122 + 1.123 + @RobocopTarget 1.124 + public static final class Thumbnails implements CommonColumns { 1.125 + private Thumbnails() {} 1.126 + 1.127 + public static final String TABLE_NAME = "thumbnails"; 1.128 + 1.129 + public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "thumbnails"); 1.130 + 1.131 + public static final String URL = "url"; 1.132 + public static final String DATA = "data"; 1.133 + } 1.134 + 1.135 + public static final class Profiles { 1.136 + private Profiles() {} 1.137 + public static final String NAME = "name"; 1.138 + public static final String PATH = "path"; 1.139 + } 1.140 + 1.141 + @RobocopTarget 1.142 + public static final class Bookmarks implements CommonColumns, URLColumns, FaviconColumns, SyncColumns { 1.143 + private Bookmarks() {} 1.144 + 1.145 + public static final String TABLE_NAME = "bookmarks"; 1.146 + 1.147 + public static final String VIEW_WITH_FAVICONS = "bookmarks_with_favicons"; 1.148 + 1.149 + public static final int FIXED_ROOT_ID = 0; 1.150 + public static final int FAKE_DESKTOP_FOLDER_ID = -1; 1.151 + public static final int FIXED_READING_LIST_ID = -2; 1.152 + public static final int FIXED_PINNED_LIST_ID = -3; 1.153 + 1.154 + public static final String MOBILE_FOLDER_GUID = "mobile"; 1.155 + public static final String PLACES_FOLDER_GUID = "places"; 1.156 + public static final String MENU_FOLDER_GUID = "menu"; 1.157 + public static final String TAGS_FOLDER_GUID = "tags"; 1.158 + public static final String TOOLBAR_FOLDER_GUID = "toolbar"; 1.159 + public static final String UNFILED_FOLDER_GUID = "unfiled"; 1.160 + public static final String READING_LIST_FOLDER_GUID = "readinglist"; 1.161 + public static final String FAKE_DESKTOP_FOLDER_GUID = "desktop"; 1.162 + public static final String PINNED_FOLDER_GUID = "pinned"; 1.163 + 1.164 + public static final int TYPE_FOLDER = 0; 1.165 + public static final int TYPE_BOOKMARK = 1; 1.166 + public static final int TYPE_SEPARATOR = 2; 1.167 + public static final int TYPE_LIVEMARK = 3; 1.168 + public static final int TYPE_QUERY = 4; 1.169 + 1.170 + /* 1.171 + * These values are returned by getItemFlags. They're not really 1.172 + * exclusive to bookmarks, but there's no better place to put them. 1.173 + */ 1.174 + public static final int FLAG_SUCCESS = 1 << 1; // The query succeeded. 1.175 + public static final int FLAG_BOOKMARK = 1 << 2; 1.176 + public static final int FLAG_PINNED = 1 << 3; 1.177 + public static final int FLAG_READING = 1 << 4; 1.178 + 1.179 + public static final Uri FLAGS_URI = Uri.withAppendedPath(AUTHORITY_URI, "flags"); 1.180 + 1.181 + public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "bookmarks"); 1.182 + public static final Uri PARENTS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "parents"); 1.183 + // Hacky API for bulk-updating positions. Bug 728783. 1.184 + public static final Uri POSITIONS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "positions"); 1.185 + public static final long DEFAULT_POSITION = Long.MIN_VALUE; 1.186 + 1.187 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/bookmark"; 1.188 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/bookmark"; 1.189 + public static final String TYPE = "type"; 1.190 + public static final String PARENT = "parent"; 1.191 + public static final String POSITION = "position"; 1.192 + public static final String TAGS = "tags"; 1.193 + public static final String DESCRIPTION = "description"; 1.194 + public static final String KEYWORD = "keyword"; 1.195 + } 1.196 + 1.197 + @RobocopTarget 1.198 + public static final class History implements CommonColumns, URLColumns, HistoryColumns, FaviconColumns, SyncColumns { 1.199 + private History() {} 1.200 + 1.201 + public static final String TABLE_NAME = "history"; 1.202 + 1.203 + public static final String VIEW_WITH_FAVICONS = "history_with_favicons"; 1.204 + 1.205 + public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "history"); 1.206 + public static final Uri CONTENT_OLD_URI = Uri.withAppendedPath(AUTHORITY_URI, "history/old"); 1.207 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/browser-history"; 1.208 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/browser-history"; 1.209 + } 1.210 + 1.211 + // Combined bookmarks and history 1.212 + @RobocopTarget 1.213 + public static final class Combined implements CommonColumns, URLColumns, HistoryColumns, FaviconColumns { 1.214 + private Combined() {} 1.215 + 1.216 + public static final String VIEW_NAME = "combined"; 1.217 + 1.218 + public static final String VIEW_WITH_FAVICONS = "combined_with_favicons"; 1.219 + 1.220 + public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "combined"); 1.221 + 1.222 + public static final int DISPLAY_NORMAL = 0; 1.223 + public static final int DISPLAY_READER = 1; 1.224 + 1.225 + public static final String BOOKMARK_ID = "bookmark_id"; 1.226 + public static final String HISTORY_ID = "history_id"; 1.227 + public static final String DISPLAY = "display"; 1.228 + } 1.229 + 1.230 + public static final class Schema { 1.231 + private Schema() {} 1.232 + public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "schema"); 1.233 + 1.234 + public static final String VERSION = "version"; 1.235 + } 1.236 + 1.237 + public static final class Passwords { 1.238 + private Passwords() {} 1.239 + public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "passwords"); 1.240 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/passwords"; 1.241 + 1.242 + public static final String ID = "id"; 1.243 + public static final String HOSTNAME = "hostname"; 1.244 + public static final String HTTP_REALM = "httpRealm"; 1.245 + public static final String FORM_SUBMIT_URL = "formSubmitURL"; 1.246 + public static final String USERNAME_FIELD = "usernameField"; 1.247 + public static final String PASSWORD_FIELD = "passwordField"; 1.248 + public static final String ENCRYPTED_USERNAME = "encryptedUsername"; 1.249 + public static final String ENCRYPTED_PASSWORD = "encryptedPassword"; 1.250 + public static final String ENC_TYPE = "encType"; 1.251 + public static final String TIME_CREATED = "timeCreated"; 1.252 + public static final String TIME_LAST_USED = "timeLastUsed"; 1.253 + public static final String TIME_PASSWORD_CHANGED = "timePasswordChanged"; 1.254 + public static final String TIMES_USED = "timesUsed"; 1.255 + public static final String GUID = "guid"; 1.256 + 1.257 + // This needs to be kept in sync with the types defined in toolkit/components/passwordmgr/nsILoginManagerCrypto.idl#45 1.258 + public static final int ENCTYPE_SDR = 1; 1.259 + } 1.260 + 1.261 + public static final class DeletedPasswords implements DeletedColumns { 1.262 + private DeletedPasswords() {} 1.263 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/deleted-passwords"; 1.264 + public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "deleted-passwords"); 1.265 + } 1.266 + 1.267 + public static final class FormHistory { 1.268 + private FormHistory() {} 1.269 + public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "formhistory"); 1.270 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/formhistory"; 1.271 + 1.272 + public static final String ID = "id"; 1.273 + public static final String FIELD_NAME = "fieldname"; 1.274 + public static final String VALUE = "value"; 1.275 + public static final String TIMES_USED = "timesUsed"; 1.276 + public static final String FIRST_USED = "firstUsed"; 1.277 + public static final String LAST_USED = "lastUsed"; 1.278 + public static final String GUID = "guid"; 1.279 + } 1.280 + 1.281 + public static final class DeletedFormHistory implements DeletedColumns { 1.282 + private DeletedFormHistory() {} 1.283 + public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "deleted-formhistory"); 1.284 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/deleted-formhistory"; 1.285 + } 1.286 + 1.287 + public static final class Tabs implements CommonColumns { 1.288 + private Tabs() {} 1.289 + public static final Uri CONTENT_URI = Uri.withAppendedPath(TABS_AUTHORITY_URI, "tabs"); 1.290 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/tab"; 1.291 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/tab"; 1.292 + 1.293 + // Title of the tab. 1.294 + public static final String TITLE = "title"; 1.295 + 1.296 + // Topmost URL from the history array. Allows processing of this tab without 1.297 + // parsing that array. 1.298 + public static final String URL = "url"; 1.299 + 1.300 + // Sync-assigned GUID for client device. NULL for local tabs. 1.301 + public static final String CLIENT_GUID = "client_guid"; 1.302 + 1.303 + // JSON-encoded array of history URL strings, from most recent to least recent. 1.304 + public static final String HISTORY = "history"; 1.305 + 1.306 + // Favicon URL for the tab's topmost history entry. 1.307 + public static final String FAVICON = "favicon"; 1.308 + 1.309 + // Last used time of the tab. 1.310 + public static final String LAST_USED = "last_used"; 1.311 + 1.312 + // Position of the tab. 0 represents foreground. 1.313 + public static final String POSITION = "position"; 1.314 + } 1.315 + 1.316 + public static final class Clients { 1.317 + private Clients() {} 1.318 + public static final Uri CONTENT_URI = Uri.withAppendedPath(TABS_AUTHORITY_URI, "clients"); 1.319 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/client"; 1.320 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/client"; 1.321 + 1.322 + // Implicit rowid in SQL table. 1.323 + public static final String ROWID = "rowid"; 1.324 + 1.325 + // Client-provided name string. Could conceivably be null. 1.326 + public static final String NAME = "name"; 1.327 + 1.328 + // Sync-assigned GUID for client device. NULL for local tabs. 1.329 + public static final String GUID = "guid"; 1.330 + 1.331 + // Last modified time for the client's tab record. For remote records, a server 1.332 + // timestamp provided by Sync during insertion. 1.333 + public static final String LAST_MODIFIED = "last_modified"; 1.334 + } 1.335 + 1.336 + // Data storage for dynamic panels on about:home 1.337 + @RobocopTarget 1.338 + public static final class HomeItems implements CommonColumns { 1.339 + private HomeItems() {} 1.340 + public static final Uri CONTENT_FAKE_URI = Uri.withAppendedPath(HOME_AUTHORITY_URI, "items/fake"); 1.341 + public static final Uri CONTENT_URI = Uri.withAppendedPath(HOME_AUTHORITY_URI, "items"); 1.342 + 1.343 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/homeitem"; 1.344 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/homeitem"; 1.345 + 1.346 + public static final String DATASET_ID = "dataset_id"; 1.347 + public static final String URL = "url"; 1.348 + public static final String TITLE = "title"; 1.349 + public static final String DESCRIPTION = "description"; 1.350 + public static final String IMAGE_URL = "image_url"; 1.351 + public static final String CREATED = "created"; 1.352 + public static final String FILTER = "filter"; 1.353 + 1.354 + public static final String[] DEFAULT_PROJECTION = 1.355 + new String[] { _ID, DATASET_ID, URL, TITLE, DESCRIPTION, IMAGE_URL, FILTER }; 1.356 + } 1.357 + 1.358 + /* 1.359 + * Contains names and schema definitions for tables and views 1.360 + * no longer being used by current ContentProviders. These values are used 1.361 + * to make incremental updates to the schema during a database upgrade. Will be 1.362 + * removed with bug 947018. 1.363 + */ 1.364 + static final class Obsolete { 1.365 + public static final String TABLE_IMAGES = "images"; 1.366 + public static final String VIEW_BOOKMARKS_WITH_IMAGES = "bookmarks_with_images"; 1.367 + public static final String VIEW_HISTORY_WITH_IMAGES = "history_with_images"; 1.368 + public static final String VIEW_COMBINED_WITH_IMAGES = "combined_with_images"; 1.369 + 1.370 + public static final class Images implements CommonColumns, SyncColumns { 1.371 + private Images() {} 1.372 + 1.373 + public static final String URL = "url_key"; 1.374 + public static final String FAVICON_URL = "favicon_url"; 1.375 + public static final String FAVICON = "favicon"; 1.376 + public static final String THUMBNAIL = "thumbnail"; 1.377 + public static final String _ID = "_id"; 1.378 + public static final String GUID = "guid"; 1.379 + public static final String DATE_CREATED = "created"; 1.380 + public static final String DATE_MODIFIED = "modified"; 1.381 + public static final String IS_DELETED = "deleted"; 1.382 + } 1.383 + 1.384 + public static final class Combined { 1.385 + private Combined() {} 1.386 + 1.387 + public static final String THUMBNAIL = "thumbnail"; 1.388 + } 1.389 + 1.390 + static final String TABLE_BOOKMARKS_JOIN_IMAGES = Bookmarks.TABLE_NAME + " LEFT OUTER JOIN " + 1.391 + Obsolete.TABLE_IMAGES + " ON " + Bookmarks.TABLE_NAME + "." + Bookmarks.URL + " = " + 1.392 + Obsolete.TABLE_IMAGES + "." + Obsolete.Images.URL; 1.393 + 1.394 + static final String TABLE_HISTORY_JOIN_IMAGES = History.TABLE_NAME + " LEFT OUTER JOIN " + 1.395 + Obsolete.TABLE_IMAGES + " ON " + Bookmarks.TABLE_NAME + "." + History.URL + " = " + 1.396 + Obsolete.TABLE_IMAGES + "." + Obsolete.Images.URL; 1.397 + 1.398 + static final String FAVICON_DB = "favicon_urls.db"; 1.399 + } 1.400 + 1.401 + @RobocopTarget 1.402 + public static final class ReadingListItems implements CommonColumns, URLColumns, SyncColumns { 1.403 + private ReadingListItems() {} 1.404 + public static final Uri CONTENT_URI = Uri.withAppendedPath(READING_LIST_AUTHORITY_URI, "items"); 1.405 + 1.406 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/readinglistitem"; 1.407 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/readinglistitem"; 1.408 + 1.409 + public static final String EXCERPT = "excerpt"; 1.410 + public static final String READ = "read"; 1.411 + public static final String LENGTH = "length"; 1.412 + public static final String DEFAULT_SORT_ORDER = DATE_MODIFIED + " DESC"; 1.413 + public static final String[] DEFAULT_PROJECTION = new String[] { _ID, URL, TITLE, EXCERPT, LENGTH }; 1.414 + 1.415 + // Minimum fields required to create a reading list item. 1.416 + public static final String[] REQUIRED_FIELDS = { Bookmarks.URL, Bookmarks.TITLE }; 1.417 + 1.418 + public static final String TABLE_NAME = "reading_list"; 1.419 + } 1.420 + 1.421 +}