Chromium Code Reviews| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 m_backend->requestTransitToState(m_nextState); | 262 m_backend->requestTransitToState(m_nextState); |
| 263 return SQLTransactionState::Idle; | 263 return SQLTransactionState::Idle; |
| 264 } | 264 } |
| 265 | 265 |
| 266 void SQLTransaction::performPendingCallback() | 266 void SQLTransaction::performPendingCallback() |
| 267 { | 267 { |
| 268 computeNextStateAndCleanupIfNeeded(); | 268 computeNextStateAndCleanupIfNeeded(); |
| 269 runStateMachine(); | 269 runStateMachine(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void SQLTransaction::executeSQL(const String& sqlStatement, const Vector<SQLValu e>& arguments, SQLStatementCallback* callback, SQLStatementErrorCallback* callba ckError, ExceptionState& exceptionState) | 272 void SQLTransaction::executeSql(const String& sqlStatement, const Nullable<Vecto r<ScriptValue>>& arguments, SQLStatementCallback* callback, SQLStatementErrorCal lback* callbackError, ExceptionState& exceptionState) |
| 273 { | 273 { |
| 274 if (!m_executeSqlAllowed) { | 274 if (!m_executeSqlAllowed) { |
| 275 exceptionState.throwDOMException(InvalidStateError, "SQL execution is di sallowed."); | 275 exceptionState.throwDOMException(InvalidStateError, "SQL execution is di sallowed."); |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 | 278 |
| 279 if (!m_database->opened()) { | 279 if (!m_database->opened()) { |
| 280 exceptionState.throwDOMException(InvalidStateError, "The database has no t been opened."); | 280 exceptionState.throwDOMException(InvalidStateError, "The database has no t been opened."); |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 | 283 |
| 284 int permissions = DatabaseAuthorizer::ReadWriteMask; | 284 int permissions = DatabaseAuthorizer::ReadWriteMask; |
| 285 if (!m_database->databaseContext()->allowDatabaseAccess()) | 285 if (!m_database->databaseContext()->allowDatabaseAccess()) |
| 286 permissions |= DatabaseAuthorizer::NoAccessMask; | 286 permissions |= DatabaseAuthorizer::NoAccessMask; |
| 287 else if (m_readOnly) | 287 else if (m_readOnly) |
| 288 permissions |= DatabaseAuthorizer::ReadOnlyMask; | 288 permissions |= DatabaseAuthorizer::ReadOnlyMask; |
| 289 | 289 |
| 290 Vector<SQLValue> sqlArguments; | |
| 291 if (!arguments.isNull()) { | |
| 292 const Vector<ScriptValue>& args = arguments.get(); | |
| 293 for (unsigned i = 0; i < args.size(); ++i) { | |
| 294 v8::Local<v8::Value> arg = args[i].v8Value(); | |
|
jsbell
2015/03/03 18:33:14
Can we factor this out into toSQLValue(const Scrip
haraken
2015/03/04 02:00:07
Sounds nice to put the function into IDBBindingUti
bashi
2015/03/04 03:33:02
Is is possible to use toImplArray()? (You need to
| |
| 295 if (arg.IsEmpty() || arg->IsNull()) { | |
| 296 sqlArguments.append(SQLValue()); | |
| 297 } else if (arg->IsNumber()) { | |
| 298 sqlArguments.append(SQLValue(arg->NumberValue())); | |
|
bashi
2015/03/04 03:33:02
FYI, NumberValue() is going to be deprecated. Numb
| |
| 299 } else { | |
| 300 TOSTRING_VOID(V8StringResource<>, stringValue, arg); | |
| 301 sqlArguments.append(SQLValue(stringValue)); | |
| 302 } | |
| 303 } | |
| 304 } | |
| 290 SQLStatement* statement = SQLStatement::create(m_database.get(), callback, c allbackError); | 305 SQLStatement* statement = SQLStatement::create(m_database.get(), callback, c allbackError); |
| 291 m_backend->executeSQL(statement, sqlStatement, arguments, permissions); | 306 m_backend->executeSQL(statement, sqlStatement, sqlArguments, permissions); |
| 307 } | |
| 308 | |
| 309 void SQLTransaction::executeSql(const String& sqlStatement, ExceptionState& exce ptionState) | |
| 310 { | |
| 311 executeSql(sqlStatement, Vector<ScriptValue>(), nullptr, nullptr, exceptionS tate); | |
| 292 } | 312 } |
| 293 | 313 |
| 294 bool SQLTransaction::computeNextStateAndCleanupIfNeeded() | 314 bool SQLTransaction::computeNextStateAndCleanupIfNeeded() |
| 295 { | 315 { |
| 296 // Only honor the requested state transition if we're not supposed to be | 316 // Only honor the requested state transition if we're not supposed to be |
| 297 // cleaning up and shutting down: | 317 // cleaning up and shutting down: |
| 298 if (m_database->opened()) { | 318 if (m_database->opened()) { |
| 299 setStateToRequestedState(); | 319 setStateToRequestedState(); |
| 300 ASSERT(m_nextState == SQLTransactionState::End | 320 ASSERT(m_nextState == SQLTransactionState::End |
| 301 || m_nextState == SQLTransactionState::DeliverTransactionCallback | 321 || m_nextState == SQLTransactionState::DeliverTransactionCallback |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 320 m_successCallback.clear(); | 340 m_successCallback.clear(); |
| 321 m_errorCallback.clear(); | 341 m_errorCallback.clear(); |
| 322 } | 342 } |
| 323 | 343 |
| 324 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback() | 344 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback() |
| 325 { | 345 { |
| 326 return m_errorCallback.release(); | 346 return m_errorCallback.release(); |
| 327 } | 347 } |
| 328 | 348 |
| 329 } // namespace blink | 349 } // namespace blink |
| OLD | NEW |