Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 | #include "nsISupports.idl" |
michael@0 | 7 | #include "mozIStorageAsyncConnection.idl" |
michael@0 | 8 | |
michael@0 | 9 | interface mozIStorageAggregateFunction; |
michael@0 | 10 | interface mozIStorageCompletionCallback; |
michael@0 | 11 | interface mozIStorageFunction; |
michael@0 | 12 | interface mozIStorageProgressHandler; |
michael@0 | 13 | interface mozIStorageBaseStatement; |
michael@0 | 14 | interface mozIStorageStatement; |
michael@0 | 15 | interface mozIStorageAsyncStatement; |
michael@0 | 16 | interface mozIStorageStatementCallback; |
michael@0 | 17 | interface mozIStoragePendingStatement; |
michael@0 | 18 | interface nsIFile; |
michael@0 | 19 | |
michael@0 | 20 | /** |
michael@0 | 21 | * mozIStorageConnection represents a database connection attached to |
michael@0 | 22 | * a specific file or to the in-memory data storage. It is the |
michael@0 | 23 | * primary interface for interacting with a database, including |
michael@0 | 24 | * creating prepared statements, executing SQL, and examining database |
michael@0 | 25 | * errors. |
michael@0 | 26 | * |
michael@0 | 27 | * @note From the main thread, you should rather use mozIStorageAsyncConnection. |
michael@0 | 28 | * |
michael@0 | 29 | * @threadsafe |
michael@0 | 30 | */ |
michael@0 | 31 | [scriptable, uuid(4aa2ac47-8d24-4004-9b31-ec0bd85f0cc3)] |
michael@0 | 32 | interface mozIStorageConnection : mozIStorageAsyncConnection { |
michael@0 | 33 | /** |
michael@0 | 34 | * Closes a database connection. Callers must finalize all statements created |
michael@0 | 35 | * for this connection prior to calling this method. It is illegal to use |
michael@0 | 36 | * call this method if any asynchronous statements have been executed on this |
michael@0 | 37 | * connection. |
michael@0 | 38 | * |
michael@0 | 39 | * @throws NS_ERROR_UNEXPECTED |
michael@0 | 40 | * If any statement has been executed asynchronously on this object. |
michael@0 | 41 | * @throws NS_ERROR_UNEXPECTED |
michael@0 | 42 | * If is called on a thread other than the one that opened it. |
michael@0 | 43 | */ |
michael@0 | 44 | void close(); |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Clones a database connection and makes the clone read only if needed. |
michael@0 | 48 | * |
michael@0 | 49 | * @param aReadOnly |
michael@0 | 50 | * If true, the returned database should be put into read-only mode. |
michael@0 | 51 | * Defaults to false. |
michael@0 | 52 | * @return the cloned database connection. |
michael@0 | 53 | * |
michael@0 | 54 | * @throws NS_ERROR_UNEXPECTED |
michael@0 | 55 | * If this connection is a memory database. |
michael@0 | 56 | * @note If your connection is already read-only, you will get a read-only |
michael@0 | 57 | * clone. |
michael@0 | 58 | * @note Due to a bug in SQLite, if you use the shared cache (openDatabase), |
michael@0 | 59 | * you end up with the same privileges as the first connection opened |
michael@0 | 60 | * regardless of what is specified in aReadOnly. |
michael@0 | 61 | * @note The following pragmas are copied over to a read-only clone: |
michael@0 | 62 | * - cache_size |
michael@0 | 63 | * - temp_store |
michael@0 | 64 | * The following pragmas are copied over to a writeable clone: |
michael@0 | 65 | * - cache_size |
michael@0 | 66 | * - temp_store |
michael@0 | 67 | * - foreign_keys |
michael@0 | 68 | * - journal_size_limit |
michael@0 | 69 | * - synchronous |
michael@0 | 70 | * - wal_autocheckpoint |
michael@0 | 71 | * |
michael@0 | 72 | */ |
michael@0 | 73 | mozIStorageConnection clone([optional] in boolean aReadOnly); |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * The default size for SQLite database pages used by mozStorage for new |
michael@0 | 77 | * databases. |
michael@0 | 78 | */ |
michael@0 | 79 | readonly attribute long defaultPageSize; |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * Indicates if the connection is open and ready to use. This will be false |
michael@0 | 83 | * if the connection failed to open, or it has been closed. |
michael@0 | 84 | */ |
michael@0 | 85 | readonly attribute boolean connectionReady; |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * lastInsertRowID returns the row ID from the last INSERT |
michael@0 | 89 | * operation. |
michael@0 | 90 | */ |
michael@0 | 91 | readonly attribute long long lastInsertRowID; |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * affectedRows returns the number of database rows that were changed or |
michael@0 | 95 | * inserted or deleted by last operation. |
michael@0 | 96 | */ |
michael@0 | 97 | readonly attribute long affectedRows; |
michael@0 | 98 | |
michael@0 | 99 | /** |
michael@0 | 100 | * The last error SQLite error code. |
michael@0 | 101 | */ |
michael@0 | 102 | readonly attribute long lastError; |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * The last SQLite error as a string (in english, straight from the |
michael@0 | 106 | * sqlite library). |
michael@0 | 107 | */ |
michael@0 | 108 | readonly attribute AUTF8String lastErrorString; |
michael@0 | 109 | |
michael@0 | 110 | /** |
michael@0 | 111 | * The schema version of the database. This should not be used until the |
michael@0 | 112 | * database is ready. The schema will be reported as zero if it is not set. |
michael@0 | 113 | */ |
michael@0 | 114 | attribute long schemaVersion; |
michael@0 | 115 | |
michael@0 | 116 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 117 | //// Statement creation |
michael@0 | 118 | |
michael@0 | 119 | /** |
michael@0 | 120 | * Create a mozIStorageStatement for the given SQL expression. The |
michael@0 | 121 | * expression may use ? to indicate sequential numbered arguments, |
michael@0 | 122 | * ?1, ?2 etc. to indicate specific numbered arguments or :name and |
michael@0 | 123 | * $var to indicate named arguments. |
michael@0 | 124 | * |
michael@0 | 125 | * @param aSQLStatement |
michael@0 | 126 | * The SQL statement to execute. |
michael@0 | 127 | * @return a new mozIStorageStatement |
michael@0 | 128 | */ |
michael@0 | 129 | mozIStorageStatement createStatement(in AUTF8String aSQLStatement); |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Execute a SQL expression, expecting no arguments. |
michael@0 | 133 | * |
michael@0 | 134 | * @param aSQLStatement The SQL statement to execute |
michael@0 | 135 | */ |
michael@0 | 136 | void executeSimpleSQL(in AUTF8String aSQLStatement); |
michael@0 | 137 | |
michael@0 | 138 | /** |
michael@0 | 139 | * Check if the given table exists. |
michael@0 | 140 | * |
michael@0 | 141 | * @param aTableName |
michael@0 | 142 | * The table to check |
michael@0 | 143 | * @return TRUE if table exists, FALSE otherwise. |
michael@0 | 144 | */ |
michael@0 | 145 | boolean tableExists(in AUTF8String aTableName); |
michael@0 | 146 | |
michael@0 | 147 | /** |
michael@0 | 148 | * Check if the given index exists. |
michael@0 | 149 | * |
michael@0 | 150 | * @param aIndexName The index to check |
michael@0 | 151 | * @return TRUE if the index exists, FALSE otherwise. |
michael@0 | 152 | */ |
michael@0 | 153 | boolean indexExists(in AUTF8String aIndexName); |
michael@0 | 154 | |
michael@0 | 155 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 156 | //// Transactions |
michael@0 | 157 | |
michael@0 | 158 | /** |
michael@0 | 159 | * Returns true if a transaction is active on this connection. |
michael@0 | 160 | */ |
michael@0 | 161 | readonly attribute boolean transactionInProgress; |
michael@0 | 162 | |
michael@0 | 163 | /** |
michael@0 | 164 | * Begin a new transaction. sqlite default transactions are deferred. |
michael@0 | 165 | * If a transaction is active, throws an error. |
michael@0 | 166 | */ |
michael@0 | 167 | void beginTransaction(); |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * Begins a new transaction with the given type. |
michael@0 | 171 | */ |
michael@0 | 172 | const int32_t TRANSACTION_DEFERRED = 0; |
michael@0 | 173 | const int32_t TRANSACTION_IMMEDIATE = 1; |
michael@0 | 174 | const int32_t TRANSACTION_EXCLUSIVE = 2; |
michael@0 | 175 | void beginTransactionAs(in int32_t transactionType); |
michael@0 | 176 | |
michael@0 | 177 | /** |
michael@0 | 178 | * Commits the current transaction. If no transaction is active, |
michael@0 | 179 | * @throws NS_ERROR_UNEXPECTED. |
michael@0 | 180 | * @throws NS_ERROR_NOT_INITIALIZED. |
michael@0 | 181 | */ |
michael@0 | 182 | void commitTransaction(); |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * Rolls back the current transaction. If no transaction is active, |
michael@0 | 186 | * @throws NS_ERROR_UNEXPECTED. |
michael@0 | 187 | * @throws NS_ERROR_NOT_INITIALIZED. |
michael@0 | 188 | */ |
michael@0 | 189 | void rollbackTransaction(); |
michael@0 | 190 | |
michael@0 | 191 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 192 | //// Tables |
michael@0 | 193 | |
michael@0 | 194 | /** |
michael@0 | 195 | * Create the table with the given name and schema. |
michael@0 | 196 | * |
michael@0 | 197 | * If the table already exists, NS_ERROR_FAILURE is thrown. |
michael@0 | 198 | * (XXX at some point in the future it will check if the schema is |
michael@0 | 199 | * the same as what is specified, but that doesn't happen currently.) |
michael@0 | 200 | * |
michael@0 | 201 | * @param aTableName |
michael@0 | 202 | * The table name to be created, consisting of [A-Za-z0-9_], and |
michael@0 | 203 | * beginning with a letter. |
michael@0 | 204 | * @param aTableSchema |
michael@0 | 205 | * The schema of the table; what would normally go between the parens |
michael@0 | 206 | * in a CREATE TABLE statement: e.g., "foo INTEGER, bar STRING". |
michael@0 | 207 | * |
michael@0 | 208 | * @throws NS_ERROR_FAILURE |
michael@0 | 209 | * If the table already exists or could not be created for any other |
michael@0 | 210 | * reason. |
michael@0 | 211 | */ |
michael@0 | 212 | void createTable(in string aTableName, |
michael@0 | 213 | in string aTableSchema); |
michael@0 | 214 | |
michael@0 | 215 | /** |
michael@0 | 216 | * Controls SQLITE_FCNTL_CHUNK_SIZE setting in sqlite. This helps avoid fragmentation |
michael@0 | 217 | * by growing/shrinking the database file in SQLITE_FCNTL_CHUNK_SIZE increments. To |
michael@0 | 218 | * conserve memory on systems short on storage space, this function will have no effect |
michael@0 | 219 | * on mobile devices or if less than 500MiB of space is left available. |
michael@0 | 220 | * |
michael@0 | 221 | * @param aIncrement |
michael@0 | 222 | * The database file will grow in multiples of chunkSize. |
michael@0 | 223 | * @param aDatabaseName |
michael@0 | 224 | * Sqlite database name. "" means pass NULL for zDbName to sqlite3_file_control. |
michael@0 | 225 | * See http://sqlite.org/c3ref/file_control.html for more details. |
michael@0 | 226 | * @throws NS_ERROR_FILE_TOO_BIG |
michael@0 | 227 | * If the system is short on storage space. |
michael@0 | 228 | */ |
michael@0 | 229 | void setGrowthIncrement(in int32_t aIncrement, in AUTF8String aDatabaseName); |
michael@0 | 230 | |
michael@0 | 231 | /** |
michael@0 | 232 | * Enable a predefined virtual table implementation. |
michael@0 | 233 | * |
michael@0 | 234 | * @param aModuleName |
michael@0 | 235 | * The module to enable. Only "filesystem" is currently supported. |
michael@0 | 236 | * |
michael@0 | 237 | * @throws NS_ERROR_FAILURE |
michael@0 | 238 | * For unknown module names. |
michael@0 | 239 | */ |
michael@0 | 240 | [noscript] void enableModule(in ACString aModuleName); |
michael@0 | 241 | }; |