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