+ public Cursor getCursorForDomainName(String domainName) {
+ // Get a readable database handle.
+ SQLiteDatabase domainsDatabase = this.getReadableDatabase();
+
+ // Prepare the SQL statement to get the `Cursor` for `domainName`.
+ final String GET_CURSOR_FOR_DOMAIN_NAME = "SELECT * FROM " + DOMAINS_TABLE +
+ " WHERE " + DOMAIN_NAME + " = " + "\"" + domainName + "\"";
+
+ // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. We can't close the `Cursor` because we need to us it in the calling activity.
+ return domainsDatabase.rawQuery(GET_CURSOR_FOR_DOMAIN_NAME, null);
+ }
+
+ public int addDomain(String domainName) {
+ // Store the domain data in a `ContentValues`.
+ ContentValues domainContentValues = new ContentValues();
+
+ // Create entries for each field in the database. The ID is created automatically.
+ domainContentValues.put(DOMAIN_NAME, domainName);
+ domainContentValues.put(ENABLE_JAVASCRIPT, false);
+ domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, false);
+ domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, false);
+ domainContentValues.put(ENABLE_DOM_STORAGE, false);
+ domainContentValues.put(ENABLE_FORM_DATA, false);
+ domainContentValues.put(USER_AGENT, "System default user agent");
+ domainContentValues.put(FONT_SIZE, 0);
+ domainContentValues.put(DISPLAY_IMAGES, 0);
+
+ // Get a writable database handle.
+ SQLiteDatabase domainsDatabase = this.getWritableDatabase();
+
+ // Insert a new row and store the resulting database ID. The second argument is `null`, which makes it so that a completely null row cannot be created.
+ int newDomainDatabaseId = (int) domainsDatabase.insert(DOMAINS_TABLE, null, domainContentValues);
+
+ // Close the database handle.
+ domainsDatabase.close();
+
+ return newDomainDatabaseId;
+ }
+
+ public void saveDomain(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled, boolean formDataEnabled, String userAgent, int fontSize,
+ int displayImages) {
+ // Store the domain data in a `ContentValues`.