| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "modules/webdatabase/SQLStatementErrorCallback.h" | 41 #include "modules/webdatabase/SQLStatementErrorCallback.h" |
| 42 #include "modules/webdatabase/SQLTransactionCallback.h" | 42 #include "modules/webdatabase/SQLTransactionCallback.h" |
| 43 #include "modules/webdatabase/SQLTransactionClient.h" // FIXME: Should be used i
n the backend only. | 43 #include "modules/webdatabase/SQLTransactionClient.h" // FIXME: Should be used i
n the backend only. |
| 44 #include "modules/webdatabase/SQLTransactionErrorCallback.h" | 44 #include "modules/webdatabase/SQLTransactionErrorCallback.h" |
| 45 #include "modules/webdatabase/SQLVoidCallback.h" | 45 #include "modules/webdatabase/SQLVoidCallback.h" |
| 46 #include "wtf/StdLibExtras.h" | 46 #include "wtf/StdLibExtras.h" |
| 47 #include "wtf/Vector.h" | 47 #include "wtf/Vector.h" |
| 48 | 48 |
| 49 namespace WebCore { | 49 namespace WebCore { |
| 50 | 50 |
| 51 PassRefPtr<SQLTransaction> SQLTransaction::create(Database* db, PassRefPtr<SQLTr
ansactionCallback> callback, | 51 PassRefPtr<SQLTransaction> SQLTransaction::create(Database* db, PassOwnPtr<SQLTr
ansactionCallback> callback, |
| 52 PassRefPtr<SQLVoidCallback> successCallback, PassRefPtr<SQLTransactionErrorC
allback> errorCallback, | 52 PassOwnPtr<SQLVoidCallback> successCallback, PassOwnPtr<SQLTransactionErrorC
allback> errorCallback, |
| 53 bool readOnly) | 53 bool readOnly) |
| 54 { | 54 { |
| 55 return adoptRef(new SQLTransaction(db, callback, successCallback, errorCallb
ack, readOnly)); | 55 return adoptRef(new SQLTransaction(db, callback, successCallback, errorCallb
ack, readOnly)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 SQLTransaction::SQLTransaction(Database* db, PassRefPtr<SQLTransactionCallback>
callback, | 58 SQLTransaction::SQLTransaction(Database* db, PassOwnPtr<SQLTransactionCallback>
callback, |
| 59 PassRefPtr<SQLVoidCallback> successCallback, PassRefPtr<SQLTransactionErrorC
allback> errorCallback, | 59 PassOwnPtr<SQLVoidCallback> successCallback, PassOwnPtr<SQLTransactionErrorC
allback> errorCallback, |
| 60 bool readOnly) | 60 bool readOnly) |
| 61 : m_database(db) | 61 : m_database(db) |
| 62 , m_callbackWrapper(callback, db->executionContext()) | 62 , m_callbackWrapper(callback, db->executionContext()) |
| 63 , m_successCallbackWrapper(successCallback, db->executionContext()) | 63 , m_successCallbackWrapper(successCallback, db->executionContext()) |
| 64 , m_errorCallbackWrapper(errorCallback, db->executionContext()) | 64 , m_errorCallbackWrapper(errorCallback, db->executionContext()) |
| 65 , m_executeSqlAllowed(false) | 65 , m_executeSqlAllowed(false) |
| 66 , m_readOnly(readOnly) | 66 , m_readOnly(readOnly) |
| 67 { | 67 { |
| 68 ASSERT(m_database); | 68 ASSERT(m_database); |
| 69 ScriptWrappable::init(this); | 69 ScriptWrappable::init(this); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // No error callback, so fast-forward to: | 133 // No error callback, so fast-forward to: |
| 134 // Transaction Step 11 - Rollback the transaction. | 134 // Transaction Step 11 - Rollback the transaction. |
| 135 return SQLTransactionState::CleanupAfterTransactionErrorCallback; | 135 return SQLTransactionState::CleanupAfterTransactionErrorCallback; |
| 136 } | 136 } |
| 137 | 137 |
| 138 SQLTransactionState SQLTransaction::deliverTransactionCallback() | 138 SQLTransactionState SQLTransaction::deliverTransactionCallback() |
| 139 { | 139 { |
| 140 bool shouldDeliverErrorCallback = false; | 140 bool shouldDeliverErrorCallback = false; |
| 141 | 141 |
| 142 // Spec 4.3.2 4: Invoke the transaction callback with the new SQLTransaction
object | 142 // Spec 4.3.2 4: Invoke the transaction callback with the new SQLTransaction
object |
| 143 RefPtr<SQLTransactionCallback> callback = m_callbackWrapper.unwrap(); | 143 OwnPtr<SQLTransactionCallback> callback = m_callbackWrapper.unwrap(); |
| 144 if (callback) { | 144 if (callback) { |
| 145 m_executeSqlAllowed = true; | 145 m_executeSqlAllowed = true; |
| 146 shouldDeliverErrorCallback = !callback->handleEvent(this); | 146 shouldDeliverErrorCallback = !callback->handleEvent(this); |
| 147 m_executeSqlAllowed = false; | 147 m_executeSqlAllowed = false; |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Spec 4.3.2 5: If the transaction callback was null or raised an exception
, jump to the error callback | 150 // Spec 4.3.2 5: If the transaction callback was null or raised an exception
, jump to the error callback |
| 151 SQLTransactionState nextState = SQLTransactionState::RunStatements; | 151 SQLTransactionState nextState = SQLTransactionState::RunStatements; |
| 152 if (shouldDeliverErrorCallback) { | 152 if (shouldDeliverErrorCallback) { |
| 153 m_database->reportStartTransactionResult(5, SQLError::UNKNOWN_ERR, 0); | 153 m_database->reportStartTransactionResult(5, SQLError::UNKNOWN_ERR, 0); |
| 154 m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "the SQLTra
nsactionCallback was null or threw an exception"); | 154 m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "the SQLTra
nsactionCallback was null or threw an exception"); |
| 155 nextState = SQLTransactionState::DeliverTransactionErrorCallback; | 155 nextState = SQLTransactionState::DeliverTransactionErrorCallback; |
| 156 } | 156 } |
| 157 m_database->reportStartTransactionResult(0, -1, 0); // OK | 157 m_database->reportStartTransactionResult(0, -1, 0); // OK |
| 158 return nextState; | 158 return nextState; |
| 159 } | 159 } |
| 160 | 160 |
| 161 SQLTransactionState SQLTransaction::deliverTransactionErrorCallback() | 161 SQLTransactionState SQLTransaction::deliverTransactionErrorCallback() |
| 162 { | 162 { |
| 163 // Spec 4.3.2.10: If exists, invoke error callback with the last | 163 // Spec 4.3.2.10: If exists, invoke error callback with the last |
| 164 // error to have occurred in this transaction. | 164 // error to have occurred in this transaction. |
| 165 RefPtr<SQLTransactionErrorCallback> errorCallback = m_errorCallbackWrapper.u
nwrap(); | 165 OwnPtr<SQLTransactionErrorCallback> errorCallback = m_errorCallbackWrapper.u
nwrap(); |
| 166 if (errorCallback) { | 166 if (errorCallback) { |
| 167 // If we get here with an empty m_transactionError, then the backend | 167 // If we get here with an empty m_transactionError, then the backend |
| 168 // must be waiting in the idle state waiting for this state to finish. | 168 // must be waiting in the idle state waiting for this state to finish. |
| 169 // Hence, it's thread safe to fetch the backend transactionError without | 169 // Hence, it's thread safe to fetch the backend transactionError without |
| 170 // a lock. | 170 // a lock. |
| 171 if (!m_transactionError) | 171 if (!m_transactionError) |
| 172 m_transactionError = m_backend->transactionError(); | 172 m_transactionError = m_backend->transactionError(); |
| 173 | 173 |
| 174 ASSERT(m_transactionError); | 174 ASSERT(m_transactionError); |
| 175 errorCallback->handleEvent(m_transactionError.get()); | 175 errorCallback->handleEvent(m_transactionError.get()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee
dQuota(database()); | 212 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee
dQuota(database()); |
| 213 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement); | 213 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement); |
| 214 | 214 |
| 215 return SQLTransactionState::RunStatements; | 215 return SQLTransactionState::RunStatements; |
| 216 } | 216 } |
| 217 | 217 |
| 218 SQLTransactionState SQLTransaction::deliverSuccessCallback() | 218 SQLTransactionState SQLTransaction::deliverSuccessCallback() |
| 219 { | 219 { |
| 220 // Spec 4.3.2.8: Deliver success callback. | 220 // Spec 4.3.2.8: Deliver success callback. |
| 221 RefPtr<SQLVoidCallback> successCallback = m_successCallbackWrapper.unwrap(); | 221 OwnPtr<SQLVoidCallback> successCallback = m_successCallbackWrapper.unwrap(); |
| 222 if (successCallback) | 222 if (successCallback) |
| 223 successCallback->handleEvent(); | 223 successCallback->handleEvent(); |
| 224 | 224 |
| 225 clearCallbackWrappers(); | 225 clearCallbackWrappers(); |
| 226 | 226 |
| 227 // Schedule a "post-success callback" step to return control to the database
thread in case there | 227 // Schedule a "post-success callback" step to return control to the database
thread in case there |
| 228 // are further transactions queued up for this Database | 228 // are further transactions queued up for this Database |
| 229 return SQLTransactionState::CleanupAndTerminate; | 229 return SQLTransactionState::CleanupAndTerminate; |
| 230 } | 230 } |
| 231 | 231 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 244 m_backend->requestTransitToState(m_nextState); | 244 m_backend->requestTransitToState(m_nextState); |
| 245 return SQLTransactionState::Idle; | 245 return SQLTransactionState::Idle; |
| 246 } | 246 } |
| 247 | 247 |
| 248 void SQLTransaction::performPendingCallback() | 248 void SQLTransaction::performPendingCallback() |
| 249 { | 249 { |
| 250 computeNextStateAndCleanupIfNeeded(); | 250 computeNextStateAndCleanupIfNeeded(); |
| 251 runStateMachine(); | 251 runStateMachine(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void SQLTransaction::executeSQL(const String& sqlStatement, const Vector<SQLValu
e>& arguments, PassRefPtr<SQLStatementCallback> callback, PassRefPtr<SQLStatemen
tErrorCallback> callbackError, ExceptionState& exceptionState) | 254 void SQLTransaction::executeSQL(const String& sqlStatement, const Vector<SQLValu
e>& arguments, PassOwnPtr<SQLStatementCallback> callback, PassOwnPtr<SQLStatemen
tErrorCallback> callbackError, ExceptionState& exceptionState) |
| 255 { | 255 { |
| 256 if (!m_executeSqlAllowed || !m_database->opened()) { | 256 if (!m_executeSqlAllowed || !m_database->opened()) { |
| 257 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); | 257 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); |
| 258 return; | 258 return; |
| 259 } | 259 } |
| 260 | 260 |
| 261 int permissions = DatabaseAuthorizer::ReadWriteMask; | 261 int permissions = DatabaseAuthorizer::ReadWriteMask; |
| 262 if (!m_database->databaseContext()->allowDatabaseAccess()) | 262 if (!m_database->databaseContext()->allowDatabaseAccess()) |
| 263 permissions |= DatabaseAuthorizer::NoAccessMask; | 263 permissions |= DatabaseAuthorizer::NoAccessMask; |
| 264 else if (m_readOnly) | 264 else if (m_readOnly) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 292 } | 292 } |
| 293 | 293 |
| 294 void SQLTransaction::clearCallbackWrappers() | 294 void SQLTransaction::clearCallbackWrappers() |
| 295 { | 295 { |
| 296 // Release the unneeded callbacks, to break reference cycles. | 296 // Release the unneeded callbacks, to break reference cycles. |
| 297 m_callbackWrapper.clear(); | 297 m_callbackWrapper.clear(); |
| 298 m_successCallbackWrapper.clear(); | 298 m_successCallbackWrapper.clear(); |
| 299 m_errorCallbackWrapper.clear(); | 299 m_errorCallbackWrapper.clear(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 PassOwnPtr<SQLTransactionErrorCallback> SQLTransaction::releaseErrorCallback() |
| 303 { |
| 304 return m_errorCallbackWrapper.unwrap(); |
| 305 } |
| 306 |
| 302 } // namespace WebCore | 307 } // namespace WebCore |
| OLD | NEW |