| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 OpenDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) | 184 OpenDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) |
| 185 : EventListener(EventListener::CPPEventListenerType) | 185 : EventListener(EventListener::CPPEventListenerType) |
| 186 , m_executableWithDatabase(executableWithDatabase) { } | 186 , m_executableWithDatabase(executableWithDatabase) { } |
| 187 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; | 187 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 void ExecutableWithDatabase::start(IDBFactory* idbFactory, SecurityOrigin*, cons
t String& databaseName) | 190 void ExecutableWithDatabase::start(IDBFactory* idbFactory, SecurityOrigin*, cons
t String& databaseName) |
| 191 { | 191 { |
| 192 RefPtr<OpenDatabaseCallback> callback = OpenDatabaseCallback::create(this); | 192 RefPtr<OpenDatabaseCallback> callback = OpenDatabaseCallback::create(this); |
| 193 TrackExceptionState exceptionState; | 193 TrackExceptionState exceptionState; |
| 194 IDBOpenDBRequest* idbOpenDBRequest = idbFactory->open(context(), databaseNam
e, exceptionState); | 194 IDBOpenDBRequest* idbOpenDBRequest = idbFactory->open(scriptState(), databas
eName, exceptionState); |
| 195 if (exceptionState.hadException()) { | 195 if (exceptionState.hadException()) { |
| 196 requestCallback()->sendFailure("Could not open database."); | 196 requestCallback()->sendFailure("Could not open database."); |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 idbOpenDBRequest->addEventListener(EventTypeNames::success, callback, false)
; | 199 idbOpenDBRequest->addEventListener(EventTypeNames::success, callback, false)
; |
| 200 } | 200 } |
| 201 | 201 |
| 202 static IDBTransaction* transactionForDatabase(ExecutionContext* executionContext
, IDBDatabase* idbDatabase, const String& objectStoreName, const String& mode =
IDBTransaction::modeReadOnly()) | 202 static IDBTransaction* transactionForDatabase(ExecutionContext* executionContext
, IDBDatabase* idbDatabase, const String& objectStoreName, const String& mode =
IDBTransaction::modeReadOnly()) |
| 203 { | 203 { |
| 204 TrackExceptionState exceptionState; | 204 TrackExceptionState exceptionState; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 RefPtr<OpenCursorCallback> openCursorCallback = OpenCursorCallback::crea
te(scriptState(), m_requestCallback, m_skipCount, m_pageSize); | 503 RefPtr<OpenCursorCallback> openCursorCallback = OpenCursorCallback::crea
te(scriptState(), m_requestCallback, m_skipCount, m_pageSize); |
| 504 | 504 |
| 505 IDBRequest* idbRequest; | 505 IDBRequest* idbRequest; |
| 506 if (!m_indexName.isEmpty()) { | 506 if (!m_indexName.isEmpty()) { |
| 507 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName
); | 507 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName
); |
| 508 if (!idbIndex) { | 508 if (!idbIndex) { |
| 509 m_requestCallback->sendFailure("Could not get index"); | 509 m_requestCallback->sendFailure("Could not get index"); |
| 510 return; | 510 return; |
| 511 } | 511 } |
| 512 | 512 |
| 513 idbRequest = idbIndex->openCursor(context(), m_idbKeyRange.get(), bl
ink::WebIDBCursor::Next); | 513 idbRequest = idbIndex->openCursor(scriptState(), m_idbKeyRange.get()
, blink::WebIDBCursor::Next); |
| 514 } else { | 514 } else { |
| 515 idbRequest = idbObjectStore->openCursor(context(), m_idbKeyRange.get
(), blink::WebIDBCursor::Next); | 515 idbRequest = idbObjectStore->openCursor(scriptState(), m_idbKeyRange
.get(), blink::WebIDBCursor::Next); |
| 516 } | 516 } |
| 517 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback
, false); | 517 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback
, false); |
| 518 } | 518 } |
| 519 | 519 |
| 520 virtual RequestCallback* requestCallback() OVERRIDE { return m_requestCallba
ck.get(); } | 520 virtual RequestCallback* requestCallback() OVERRIDE { return m_requestCallba
ck.get(); } |
| 521 DataLoader(ScriptState* scriptState, PassRefPtr<RequestDataCallback> request
Callback, const String& objectStoreName, const String& indexName, IDBKeyRange* i
dbKeyRange, int skipCount, unsigned pageSize) | 521 DataLoader(ScriptState* scriptState, PassRefPtr<RequestDataCallback> request
Callback, const String& objectStoreName, const String& indexName, IDBKeyRange* i
dbKeyRange, int skipCount, unsigned pageSize) |
| 522 : ExecutableWithDatabase(scriptState) | 522 : ExecutableWithDatabase(scriptState) |
| 523 , m_requestCallback(requestCallback) | 523 , m_requestCallback(requestCallback) |
| 524 , m_objectStoreName(objectStoreName) | 524 , m_objectStoreName(objectStoreName) |
| 525 , m_indexName(indexName) | 525 , m_indexName(indexName) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con
st String& securityOrigin, PassRefPtr<RequestDatabaseNamesCallback> requestCallb
ack) | 616 void InspectorIndexedDBAgent::requestDatabaseNames(ErrorString* errorString, con
st String& securityOrigin, PassRefPtr<RequestDatabaseNamesCallback> requestCallb
ack) |
| 617 { | 617 { |
| 618 LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin); | 618 LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin); |
| 619 Document* document = assertDocument(errorString, frame); | 619 Document* document = assertDocument(errorString, frame); |
| 620 if (!document) | 620 if (!document) |
| 621 return; | 621 return; |
| 622 IDBFactory* idbFactory = assertIDBFactory(errorString, document); | 622 IDBFactory* idbFactory = assertIDBFactory(errorString, document); |
| 623 if (!idbFactory) | 623 if (!idbFactory) |
| 624 return; | 624 return; |
| 625 | 625 |
| 626 ScriptState::Scope scope(ScriptState::forMainWorld(frame)); | 626 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 627 ScriptState::Scope scope(scriptState); |
| 627 TrackExceptionState exceptionState; | 628 TrackExceptionState exceptionState; |
| 628 IDBRequest* idbRequest = idbFactory->getDatabaseNames(document, exceptionSta
te); | 629 IDBRequest* idbRequest = idbFactory->getDatabaseNames(scriptState, exception
State); |
| 629 if (exceptionState.hadException()) { | 630 if (exceptionState.hadException()) { |
| 630 requestCallback->sendFailure("Could not obtain database names."); | 631 requestCallback->sendFailure("Could not obtain database names."); |
| 631 return; | 632 return; |
| 632 } | 633 } |
| 633 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba
ck::create(requestCallback, document->securityOrigin()->toRawString()), false); | 634 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba
ck::create(requestCallback, document->securityOrigin()->toRawString()), false); |
| 634 } | 635 } |
| 635 | 636 |
| 636 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St
ring& securityOrigin, const String& databaseName, PassRefPtr<RequestDatabaseCall
back> requestCallback) | 637 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St
ring& securityOrigin, const String& databaseName, PassRefPtr<RequestDatabaseCall
back> requestCallback) |
| 637 { | 638 { |
| 638 LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin); | 639 LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 m_requestCallback->sendFailure("Could not get transaction"); | 732 m_requestCallback->sendFailure("Could not get transaction"); |
| 732 return; | 733 return; |
| 733 } | 734 } |
| 734 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio
n, m_objectStoreName); | 735 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio
n, m_objectStoreName); |
| 735 if (!idbObjectStore) { | 736 if (!idbObjectStore) { |
| 736 m_requestCallback->sendFailure("Could not get object store"); | 737 m_requestCallback->sendFailure("Could not get object store"); |
| 737 return; | 738 return; |
| 738 } | 739 } |
| 739 | 740 |
| 740 TrackExceptionState exceptionState; | 741 TrackExceptionState exceptionState; |
| 741 // FXIME: Can we remove the local variable idbRequest? | 742 idbObjectStore->clear(scriptState(), exceptionState); |
| 742 IDBRequest* idbRequest ALLOW_UNUSED = idbObjectStore->clear(context(), e
xceptionState); | |
| 743 ASSERT(!exceptionState.hadException()); | 743 ASSERT(!exceptionState.hadException()); |
| 744 if (exceptionState.hadException()) { | 744 if (exceptionState.hadException()) { |
| 745 ExceptionCode ec = exceptionState.code(); | 745 ExceptionCode ec = exceptionState.code(); |
| 746 m_requestCallback->sendFailure(String::format("Could not clear objec
t store '%s': %d", m_objectStoreName.utf8().data(), ec)); | 746 m_requestCallback->sendFailure(String::format("Could not clear objec
t store '%s': %d", m_objectStoreName.utf8().data(), ec)); |
| 747 return; | 747 return; |
| 748 } | 748 } |
| 749 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt
oreListener::create(m_requestCallback), false); | 749 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt
oreListener::create(m_requestCallback), false); |
| 750 } | 750 } |
| 751 | 751 |
| 752 virtual RequestCallback* requestCallback() OVERRIDE { return m_requestCallba
ck.get(); } | 752 virtual RequestCallback* requestCallback() OVERRIDE { return m_requestCallba
ck.get(); } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 765 if (!idbFactory) | 765 if (!idbFactory) |
| 766 return; | 766 return; |
| 767 | 767 |
| 768 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 768 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 769 ScriptState::Scope scope(scriptState); | 769 ScriptState::Scope scope(scriptState); |
| 770 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS
tate, objectStoreName, requestCallback); | 770 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS
tate, objectStoreName, requestCallback); |
| 771 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName
); | 771 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName
); |
| 772 } | 772 } |
| 773 | 773 |
| 774 } // namespace WebCore | 774 } // namespace WebCore |
| OLD | NEW |