mobile/android/base/db/BrowserContract.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 package org.mozilla.gecko.db;
michael@0 7
michael@0 8 import org.mozilla.gecko.AppConstants;
michael@0 9
michael@0 10 import android.net.Uri;
michael@0 11 import org.mozilla.gecko.mozglue.RobocopTarget;
michael@0 12
michael@0 13 @RobocopTarget
michael@0 14 public class BrowserContract {
michael@0 15 public static final String AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.browser";
michael@0 16 public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
michael@0 17
michael@0 18 public static final String PASSWORDS_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.passwords";
michael@0 19 public static final Uri PASSWORDS_AUTHORITY_URI = Uri.parse("content://" + PASSWORDS_AUTHORITY);
michael@0 20
michael@0 21 public static final String FORM_HISTORY_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.formhistory";
michael@0 22 public static final Uri FORM_HISTORY_AUTHORITY_URI = Uri.parse("content://" + FORM_HISTORY_AUTHORITY);
michael@0 23
michael@0 24 public static final String TABS_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.tabs";
michael@0 25 public static final Uri TABS_AUTHORITY_URI = Uri.parse("content://" + TABS_AUTHORITY);
michael@0 26
michael@0 27 public static final String HOME_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.home";
michael@0 28 public static final Uri HOME_AUTHORITY_URI = Uri.parse("content://" + HOME_AUTHORITY);
michael@0 29
michael@0 30 public static final String PROFILES_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".profiles";
michael@0 31 public static final Uri PROFILES_AUTHORITY_URI = Uri.parse("content://" + PROFILES_AUTHORITY);
michael@0 32
michael@0 33 public static final String READING_LIST_AUTHORITY = AppConstants.ANDROID_PACKAGE_NAME + ".db.readinglist";
michael@0 34 public static final Uri READING_LIST_AUTHORITY_URI = Uri.parse("content://" + READING_LIST_AUTHORITY);
michael@0 35
michael@0 36 public static final String PARAM_PROFILE = "profile";
michael@0 37 public static final String PARAM_PROFILE_PATH = "profilePath";
michael@0 38 public static final String PARAM_LIMIT = "limit";
michael@0 39 public static final String PARAM_IS_SYNC = "sync";
michael@0 40 public static final String PARAM_SHOW_DELETED = "show_deleted";
michael@0 41 public static final String PARAM_IS_TEST = "test";
michael@0 42 public static final String PARAM_INSERT_IF_NEEDED = "insert_if_needed";
michael@0 43 public static final String PARAM_INCREMENT_VISITS = "increment_visits";
michael@0 44 public static final String PARAM_EXPIRE_PRIORITY = "priority";
michael@0 45 public static final String PARAM_DATASET_ID = "dataset_id";
michael@0 46
michael@0 47 static public enum ExpirePriority {
michael@0 48 NORMAL,
michael@0 49 AGGRESSIVE
michael@0 50 }
michael@0 51
michael@0 52 static public String getFrecencySortOrder(boolean includesBookmarks, boolean asc) {
michael@0 53 final String age = "(" + Combined.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000";
michael@0 54
michael@0 55 StringBuilder order = new StringBuilder(Combined.VISITS + " * MAX(1, 100 * 225 / (" + age + "*" + age + " + 225)) ");
michael@0 56
michael@0 57 if (includesBookmarks) {
michael@0 58 order.insert(0, "(CASE WHEN " + Combined.BOOKMARK_ID + " > -1 THEN 100 ELSE 0 END) + ");
michael@0 59 }
michael@0 60
michael@0 61 order.append(asc ? " ASC" : " DESC");
michael@0 62 return order.toString();
michael@0 63 }
michael@0 64
michael@0 65 @RobocopTarget
michael@0 66 public interface CommonColumns {
michael@0 67 public static final String _ID = "_id";
michael@0 68 }
michael@0 69
michael@0 70 @RobocopTarget
michael@0 71 public interface DateSyncColumns {
michael@0 72 public static final String DATE_CREATED = "created";
michael@0 73 public static final String DATE_MODIFIED = "modified";
michael@0 74 }
michael@0 75
michael@0 76 @RobocopTarget
michael@0 77 public interface SyncColumns extends DateSyncColumns {
michael@0 78 public static final String GUID = "guid";
michael@0 79 public static final String IS_DELETED = "deleted";
michael@0 80 }
michael@0 81
michael@0 82 @RobocopTarget
michael@0 83 public interface URLColumns {
michael@0 84 public static final String URL = "url";
michael@0 85 public static final String TITLE = "title";
michael@0 86 }
michael@0 87
michael@0 88 @RobocopTarget
michael@0 89 public interface FaviconColumns {
michael@0 90 public static final String FAVICON = "favicon";
michael@0 91 public static final String FAVICON_ID = "favicon_id";
michael@0 92 public static final String FAVICON_URL = "favicon_url";
michael@0 93 }
michael@0 94
michael@0 95 @RobocopTarget
michael@0 96 public interface HistoryColumns {
michael@0 97 public static final String DATE_LAST_VISITED = "date";
michael@0 98 public static final String VISITS = "visits";
michael@0 99 }
michael@0 100
michael@0 101 public interface DeletedColumns {
michael@0 102 public static final String ID = "id";
michael@0 103 public static final String GUID = "guid";
michael@0 104 public static final String TIME_DELETED = "timeDeleted";
michael@0 105 }
michael@0 106
michael@0 107 @RobocopTarget
michael@0 108 public static final class Favicons implements CommonColumns, DateSyncColumns {
michael@0 109 private Favicons() {}
michael@0 110
michael@0 111 public static final String TABLE_NAME = "favicons";
michael@0 112
michael@0 113 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "favicons");
michael@0 114
michael@0 115 public static final String URL = "url";
michael@0 116 public static final String DATA = "data";
michael@0 117 public static final String PAGE_URL = "page_url";
michael@0 118 }
michael@0 119
michael@0 120 @RobocopTarget
michael@0 121 public static final class Thumbnails implements CommonColumns {
michael@0 122 private Thumbnails() {}
michael@0 123
michael@0 124 public static final String TABLE_NAME = "thumbnails";
michael@0 125
michael@0 126 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "thumbnails");
michael@0 127
michael@0 128 public static final String URL = "url";
michael@0 129 public static final String DATA = "data";
michael@0 130 }
michael@0 131
michael@0 132 public static final class Profiles {
michael@0 133 private Profiles() {}
michael@0 134 public static final String NAME = "name";
michael@0 135 public static final String PATH = "path";
michael@0 136 }
michael@0 137
michael@0 138 @RobocopTarget
michael@0 139 public static final class Bookmarks implements CommonColumns, URLColumns, FaviconColumns, SyncColumns {
michael@0 140 private Bookmarks() {}
michael@0 141
michael@0 142 public static final String TABLE_NAME = "bookmarks";
michael@0 143
michael@0 144 public static final String VIEW_WITH_FAVICONS = "bookmarks_with_favicons";
michael@0 145
michael@0 146 public static final int FIXED_ROOT_ID = 0;
michael@0 147 public static final int FAKE_DESKTOP_FOLDER_ID = -1;
michael@0 148 public static final int FIXED_READING_LIST_ID = -2;
michael@0 149 public static final int FIXED_PINNED_LIST_ID = -3;
michael@0 150
michael@0 151 public static final String MOBILE_FOLDER_GUID = "mobile";
michael@0 152 public static final String PLACES_FOLDER_GUID = "places";
michael@0 153 public static final String MENU_FOLDER_GUID = "menu";
michael@0 154 public static final String TAGS_FOLDER_GUID = "tags";
michael@0 155 public static final String TOOLBAR_FOLDER_GUID = "toolbar";
michael@0 156 public static final String UNFILED_FOLDER_GUID = "unfiled";
michael@0 157 public static final String READING_LIST_FOLDER_GUID = "readinglist";
michael@0 158 public static final String FAKE_DESKTOP_FOLDER_GUID = "desktop";
michael@0 159 public static final String PINNED_FOLDER_GUID = "pinned";
michael@0 160
michael@0 161 public static final int TYPE_FOLDER = 0;
michael@0 162 public static final int TYPE_BOOKMARK = 1;
michael@0 163 public static final int TYPE_SEPARATOR = 2;
michael@0 164 public static final int TYPE_LIVEMARK = 3;
michael@0 165 public static final int TYPE_QUERY = 4;
michael@0 166
michael@0 167 /*
michael@0 168 * These values are returned by getItemFlags. They're not really
michael@0 169 * exclusive to bookmarks, but there's no better place to put them.
michael@0 170 */
michael@0 171 public static final int FLAG_SUCCESS = 1 << 1; // The query succeeded.
michael@0 172 public static final int FLAG_BOOKMARK = 1 << 2;
michael@0 173 public static final int FLAG_PINNED = 1 << 3;
michael@0 174 public static final int FLAG_READING = 1 << 4;
michael@0 175
michael@0 176 public static final Uri FLAGS_URI = Uri.withAppendedPath(AUTHORITY_URI, "flags");
michael@0 177
michael@0 178 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "bookmarks");
michael@0 179 public static final Uri PARENTS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "parents");
michael@0 180 // Hacky API for bulk-updating positions. Bug 728783.
michael@0 181 public static final Uri POSITIONS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "positions");
michael@0 182 public static final long DEFAULT_POSITION = Long.MIN_VALUE;
michael@0 183
michael@0 184 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/bookmark";
michael@0 185 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/bookmark";
michael@0 186 public static final String TYPE = "type";
michael@0 187 public static final String PARENT = "parent";
michael@0 188 public static final String POSITION = "position";
michael@0 189 public static final String TAGS = "tags";
michael@0 190 public static final String DESCRIPTION = "description";
michael@0 191 public static final String KEYWORD = "keyword";
michael@0 192 }
michael@0 193
michael@0 194 @RobocopTarget
michael@0 195 public static final class History implements CommonColumns, URLColumns, HistoryColumns, FaviconColumns, SyncColumns {
michael@0 196 private History() {}
michael@0 197
michael@0 198 public static final String TABLE_NAME = "history";
michael@0 199
michael@0 200 public static final String VIEW_WITH_FAVICONS = "history_with_favicons";
michael@0 201
michael@0 202 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "history");
michael@0 203 public static final Uri CONTENT_OLD_URI = Uri.withAppendedPath(AUTHORITY_URI, "history/old");
michael@0 204 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/browser-history";
michael@0 205 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/browser-history";
michael@0 206 }
michael@0 207
michael@0 208 // Combined bookmarks and history
michael@0 209 @RobocopTarget
michael@0 210 public static final class Combined implements CommonColumns, URLColumns, HistoryColumns, FaviconColumns {
michael@0 211 private Combined() {}
michael@0 212
michael@0 213 public static final String VIEW_NAME = "combined";
michael@0 214
michael@0 215 public static final String VIEW_WITH_FAVICONS = "combined_with_favicons";
michael@0 216
michael@0 217 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "combined");
michael@0 218
michael@0 219 public static final int DISPLAY_NORMAL = 0;
michael@0 220 public static final int DISPLAY_READER = 1;
michael@0 221
michael@0 222 public static final String BOOKMARK_ID = "bookmark_id";
michael@0 223 public static final String HISTORY_ID = "history_id";
michael@0 224 public static final String DISPLAY = "display";
michael@0 225 }
michael@0 226
michael@0 227 public static final class Schema {
michael@0 228 private Schema() {}
michael@0 229 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "schema");
michael@0 230
michael@0 231 public static final String VERSION = "version";
michael@0 232 }
michael@0 233
michael@0 234 public static final class Passwords {
michael@0 235 private Passwords() {}
michael@0 236 public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "passwords");
michael@0 237 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/passwords";
michael@0 238
michael@0 239 public static final String ID = "id";
michael@0 240 public static final String HOSTNAME = "hostname";
michael@0 241 public static final String HTTP_REALM = "httpRealm";
michael@0 242 public static final String FORM_SUBMIT_URL = "formSubmitURL";
michael@0 243 public static final String USERNAME_FIELD = "usernameField";
michael@0 244 public static final String PASSWORD_FIELD = "passwordField";
michael@0 245 public static final String ENCRYPTED_USERNAME = "encryptedUsername";
michael@0 246 public static final String ENCRYPTED_PASSWORD = "encryptedPassword";
michael@0 247 public static final String ENC_TYPE = "encType";
michael@0 248 public static final String TIME_CREATED = "timeCreated";
michael@0 249 public static final String TIME_LAST_USED = "timeLastUsed";
michael@0 250 public static final String TIME_PASSWORD_CHANGED = "timePasswordChanged";
michael@0 251 public static final String TIMES_USED = "timesUsed";
michael@0 252 public static final String GUID = "guid";
michael@0 253
michael@0 254 // This needs to be kept in sync with the types defined in toolkit/components/passwordmgr/nsILoginManagerCrypto.idl#45
michael@0 255 public static final int ENCTYPE_SDR = 1;
michael@0 256 }
michael@0 257
michael@0 258 public static final class DeletedPasswords implements DeletedColumns {
michael@0 259 private DeletedPasswords() {}
michael@0 260 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/deleted-passwords";
michael@0 261 public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "deleted-passwords");
michael@0 262 }
michael@0 263
michael@0 264 public static final class FormHistory {
michael@0 265 private FormHistory() {}
michael@0 266 public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "formhistory");
michael@0 267 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/formhistory";
michael@0 268
michael@0 269 public static final String ID = "id";
michael@0 270 public static final String FIELD_NAME = "fieldname";
michael@0 271 public static final String VALUE = "value";
michael@0 272 public static final String TIMES_USED = "timesUsed";
michael@0 273 public static final String FIRST_USED = "firstUsed";
michael@0 274 public static final String LAST_USED = "lastUsed";
michael@0 275 public static final String GUID = "guid";
michael@0 276 }
michael@0 277
michael@0 278 public static final class DeletedFormHistory implements DeletedColumns {
michael@0 279 private DeletedFormHistory() {}
michael@0 280 public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "deleted-formhistory");
michael@0 281 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/deleted-formhistory";
michael@0 282 }
michael@0 283
michael@0 284 public static final class Tabs implements CommonColumns {
michael@0 285 private Tabs() {}
michael@0 286 public static final Uri CONTENT_URI = Uri.withAppendedPath(TABS_AUTHORITY_URI, "tabs");
michael@0 287 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/tab";
michael@0 288 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/tab";
michael@0 289
michael@0 290 // Title of the tab.
michael@0 291 public static final String TITLE = "title";
michael@0 292
michael@0 293 // Topmost URL from the history array. Allows processing of this tab without
michael@0 294 // parsing that array.
michael@0 295 public static final String URL = "url";
michael@0 296
michael@0 297 // Sync-assigned GUID for client device. NULL for local tabs.
michael@0 298 public static final String CLIENT_GUID = "client_guid";
michael@0 299
michael@0 300 // JSON-encoded array of history URL strings, from most recent to least recent.
michael@0 301 public static final String HISTORY = "history";
michael@0 302
michael@0 303 // Favicon URL for the tab's topmost history entry.
michael@0 304 public static final String FAVICON = "favicon";
michael@0 305
michael@0 306 // Last used time of the tab.
michael@0 307 public static final String LAST_USED = "last_used";
michael@0 308
michael@0 309 // Position of the tab. 0 represents foreground.
michael@0 310 public static final String POSITION = "position";
michael@0 311 }
michael@0 312
michael@0 313 public static final class Clients {
michael@0 314 private Clients() {}
michael@0 315 public static final Uri CONTENT_URI = Uri.withAppendedPath(TABS_AUTHORITY_URI, "clients");
michael@0 316 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/client";
michael@0 317 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/client";
michael@0 318
michael@0 319 // Implicit rowid in SQL table.
michael@0 320 public static final String ROWID = "rowid";
michael@0 321
michael@0 322 // Client-provided name string. Could conceivably be null.
michael@0 323 public static final String NAME = "name";
michael@0 324
michael@0 325 // Sync-assigned GUID for client device. NULL for local tabs.
michael@0 326 public static final String GUID = "guid";
michael@0 327
michael@0 328 // Last modified time for the client's tab record. For remote records, a server
michael@0 329 // timestamp provided by Sync during insertion.
michael@0 330 public static final String LAST_MODIFIED = "last_modified";
michael@0 331 }
michael@0 332
michael@0 333 // Data storage for dynamic panels on about:home
michael@0 334 @RobocopTarget
michael@0 335 public static final class HomeItems implements CommonColumns {
michael@0 336 private HomeItems() {}
michael@0 337 public static final Uri CONTENT_FAKE_URI = Uri.withAppendedPath(HOME_AUTHORITY_URI, "items/fake");
michael@0 338 public static final Uri CONTENT_URI = Uri.withAppendedPath(HOME_AUTHORITY_URI, "items");
michael@0 339
michael@0 340 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/homeitem";
michael@0 341 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/homeitem";
michael@0 342
michael@0 343 public static final String DATASET_ID = "dataset_id";
michael@0 344 public static final String URL = "url";
michael@0 345 public static final String TITLE = "title";
michael@0 346 public static final String DESCRIPTION = "description";
michael@0 347 public static final String IMAGE_URL = "image_url";
michael@0 348 public static final String CREATED = "created";
michael@0 349 public static final String FILTER = "filter";
michael@0 350
michael@0 351 public static final String[] DEFAULT_PROJECTION =
michael@0 352 new String[] { _ID, DATASET_ID, URL, TITLE, DESCRIPTION, IMAGE_URL, FILTER };
michael@0 353 }
michael@0 354
michael@0 355 /*
michael@0 356 * Contains names and schema definitions for tables and views
michael@0 357 * no longer being used by current ContentProviders. These values are used
michael@0 358 * to make incremental updates to the schema during a database upgrade. Will be
michael@0 359 * removed with bug 947018.
michael@0 360 */
michael@0 361 static final class Obsolete {
michael@0 362 public static final String TABLE_IMAGES = "images";
michael@0 363 public static final String VIEW_BOOKMARKS_WITH_IMAGES = "bookmarks_with_images";
michael@0 364 public static final String VIEW_HISTORY_WITH_IMAGES = "history_with_images";
michael@0 365 public static final String VIEW_COMBINED_WITH_IMAGES = "combined_with_images";
michael@0 366
michael@0 367 public static final class Images implements CommonColumns, SyncColumns {
michael@0 368 private Images() {}
michael@0 369
michael@0 370 public static final String URL = "url_key";
michael@0 371 public static final String FAVICON_URL = "favicon_url";
michael@0 372 public static final String FAVICON = "favicon";
michael@0 373 public static final String THUMBNAIL = "thumbnail";
michael@0 374 public static final String _ID = "_id";
michael@0 375 public static final String GUID = "guid";
michael@0 376 public static final String DATE_CREATED = "created";
michael@0 377 public static final String DATE_MODIFIED = "modified";
michael@0 378 public static final String IS_DELETED = "deleted";
michael@0 379 }
michael@0 380
michael@0 381 public static final class Combined {
michael@0 382 private Combined() {}
michael@0 383
michael@0 384 public static final String THUMBNAIL = "thumbnail";
michael@0 385 }
michael@0 386
michael@0 387 static final String TABLE_BOOKMARKS_JOIN_IMAGES = Bookmarks.TABLE_NAME + " LEFT OUTER JOIN " +
michael@0 388 Obsolete.TABLE_IMAGES + " ON " + Bookmarks.TABLE_NAME + "." + Bookmarks.URL + " = " +
michael@0 389 Obsolete.TABLE_IMAGES + "." + Obsolete.Images.URL;
michael@0 390
michael@0 391 static final String TABLE_HISTORY_JOIN_IMAGES = History.TABLE_NAME + " LEFT OUTER JOIN " +
michael@0 392 Obsolete.TABLE_IMAGES + " ON " + Bookmarks.TABLE_NAME + "." + History.URL + " = " +
michael@0 393 Obsolete.TABLE_IMAGES + "." + Obsolete.Images.URL;
michael@0 394
michael@0 395 static final String FAVICON_DB = "favicon_urls.db";
michael@0 396 }
michael@0 397
michael@0 398 @RobocopTarget
michael@0 399 public static final class ReadingListItems implements CommonColumns, URLColumns, SyncColumns {
michael@0 400 private ReadingListItems() {}
michael@0 401 public static final Uri CONTENT_URI = Uri.withAppendedPath(READING_LIST_AUTHORITY_URI, "items");
michael@0 402
michael@0 403 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/readinglistitem";
michael@0 404 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/readinglistitem";
michael@0 405
michael@0 406 public static final String EXCERPT = "excerpt";
michael@0 407 public static final String READ = "read";
michael@0 408 public static final String LENGTH = "length";
michael@0 409 public static final String DEFAULT_SORT_ORDER = DATE_MODIFIED + " DESC";
michael@0 410 public static final String[] DEFAULT_PROJECTION = new String[] { _ID, URL, TITLE, EXCERPT, LENGTH };
michael@0 411
michael@0 412 // Minimum fields required to create a reading list item.
michael@0 413 public static final String[] REQUIRED_FIELDS = { Bookmarks.URL, Bookmarks.TITLE };
michael@0 414
michael@0 415 public static final String TABLE_NAME = "reading_list";
michael@0 416 }
michael@0 417
michael@0 418 }

mercurial