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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 String m_securityOrigin; | 135 String m_securityOrigin; |
136 }; | 136 }; |
137 | 137 |
138 class ExecutableWithDatabase : public RefCounted<ExecutableWithDatabase> { | 138 class ExecutableWithDatabase : public RefCounted<ExecutableWithDatabase> { |
139 public: | 139 public: |
140 ExecutableWithDatabase(ScriptState* scriptState) | 140 ExecutableWithDatabase(ScriptState* scriptState) |
141 : m_scriptState(scriptState) { } | 141 : m_scriptState(scriptState) { } |
142 virtual ~ExecutableWithDatabase() { } | 142 virtual ~ExecutableWithDatabase() { } |
143 void start(IDBFactory*, SecurityOrigin*, const String& databaseName); | 143 void start(IDBFactory*, SecurityOrigin*, const String& databaseName); |
144 virtual void execute(IDBDatabase*) = 0; | 144 virtual void execute(IDBDatabase*) = 0; |
145 virtual RequestCallback* requestCallback() = 0; | 145 virtual RequestCallback* getRequestCallback() = 0; |
146 ExecutionContext* context() const { return m_scriptState->executionContext()
; } | 146 ExecutionContext* context() const { return m_scriptState->getExecutionContex
t(); } |
147 ScriptState* scriptState() const { return m_scriptState.get(); } | 147 ScriptState* getScriptState() const { return m_scriptState.get(); } |
148 private: | 148 private: |
149 RefPtr<ScriptState> m_scriptState; | 149 RefPtr<ScriptState> m_scriptState; |
150 }; | 150 }; |
151 | 151 |
152 class OpenDatabaseCallback final : public EventListener { | 152 class OpenDatabaseCallback final : public EventListener { |
153 public: | 153 public: |
154 static PassRefPtrWillBeRawPtr<OpenDatabaseCallback> create(ExecutableWithDat
abase* executableWithDatabase) | 154 static PassRefPtrWillBeRawPtr<OpenDatabaseCallback> create(ExecutableWithDat
abase* executableWithDatabase) |
155 { | 155 { |
156 return adoptRefWillBeNoop(new OpenDatabaseCallback(executableWithDatabas
e)); | 156 return adoptRefWillBeNoop(new OpenDatabaseCallback(executableWithDatabas
e)); |
157 } | 157 } |
158 | 158 |
159 ~OpenDatabaseCallback() override { } | 159 ~OpenDatabaseCallback() override { } |
160 | 160 |
161 bool operator==(const EventListener& other) const override | 161 bool operator==(const EventListener& other) const override |
162 { | 162 { |
163 return this == &other; | 163 return this == &other; |
164 } | 164 } |
165 | 165 |
166 void handleEvent(ExecutionContext* context, Event* event) override | 166 void handleEvent(ExecutionContext* context, Event* event) override |
167 { | 167 { |
168 if (event->type() != EventTypeNames::success) { | 168 if (event->type() != EventTypeNames::success) { |
169 m_executableWithDatabase->requestCallback()->sendFailure("Unexpected
event type."); | 169 m_executableWithDatabase->getRequestCallback()->sendFailure("Unexpec
ted event type."); |
170 return; | 170 return; |
171 } | 171 } |
172 | 172 |
173 IDBOpenDBRequest* idbOpenDBRequest = static_cast<IDBOpenDBRequest*>(even
t->target()); | 173 IDBOpenDBRequest* idbOpenDBRequest = static_cast<IDBOpenDBRequest*>(even
t->target()); |
174 IDBAny* requestResult = idbOpenDBRequest->resultAsAny(); | 174 IDBAny* requestResult = idbOpenDBRequest->resultAsAny(); |
175 if (requestResult->getType() != IDBAny::IDBDatabaseType) { | 175 if (requestResult->getType() != IDBAny::IDBDatabaseType) { |
176 m_executableWithDatabase->requestCallback()->sendFailure("Unexpected
result type."); | 176 m_executableWithDatabase->getRequestCallback()->sendFailure("Unexpec
ted result type."); |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 IDBDatabase* idbDatabase = requestResult->idbDatabase(); | 180 IDBDatabase* idbDatabase = requestResult->idbDatabase(); |
181 m_executableWithDatabase->execute(idbDatabase); | 181 m_executableWithDatabase->execute(idbDatabase); |
182 V8PerIsolateData::from(m_executableWithDatabase->scriptState()->isolate(
))->runEndOfScopeTasks(); | 182 V8PerIsolateData::from(m_executableWithDatabase->getScriptState()->isola
te())->runEndOfScopeTasks(); |
183 idbDatabase->close(); | 183 idbDatabase->close(); |
184 } | 184 } |
185 | 185 |
186 private: | 186 private: |
187 OpenDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) | 187 OpenDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) |
188 : EventListener(EventListener::CPPEventListenerType) | 188 : EventListener(EventListener::CPPEventListenerType) |
189 , m_executableWithDatabase(executableWithDatabase) { } | 189 , m_executableWithDatabase(executableWithDatabase) { } |
190 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; | 190 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; |
191 }; | 191 }; |
192 | 192 |
193 class UpgradeDatabaseCallback final : public EventListener { | 193 class UpgradeDatabaseCallback final : public EventListener { |
194 public: | 194 public: |
195 static PassRefPtrWillBeRawPtr<UpgradeDatabaseCallback> create(ExecutableWith
Database* executableWithDatabase) | 195 static PassRefPtrWillBeRawPtr<UpgradeDatabaseCallback> create(ExecutableWith
Database* executableWithDatabase) |
196 { | 196 { |
197 return adoptRefWillBeNoop(new UpgradeDatabaseCallback(executableWithData
base)); | 197 return adoptRefWillBeNoop(new UpgradeDatabaseCallback(executableWithData
base)); |
198 } | 198 } |
199 | 199 |
200 ~UpgradeDatabaseCallback() override { } | 200 ~UpgradeDatabaseCallback() override { } |
201 | 201 |
202 bool operator==(const EventListener& other) const override | 202 bool operator==(const EventListener& other) const override |
203 { | 203 { |
204 return this == &other; | 204 return this == &other; |
205 } | 205 } |
206 | 206 |
207 void handleEvent(ExecutionContext* context, Event* event) override | 207 void handleEvent(ExecutionContext* context, Event* event) override |
208 { | 208 { |
209 if (event->type() != EventTypeNames::upgradeneeded) { | 209 if (event->type() != EventTypeNames::upgradeneeded) { |
210 m_executableWithDatabase->requestCallback()->sendFailure("Unexpected
event type."); | 210 m_executableWithDatabase->getRequestCallback()->sendFailure("Unexpec
ted event type."); |
211 return; | 211 return; |
212 } | 212 } |
213 | 213 |
214 // If an "upgradeneeded" event comes through then the database that | 214 // If an "upgradeneeded" event comes through then the database that |
215 // had previously been enumerated was deleted. We don't want to | 215 // had previously been enumerated was deleted. We don't want to |
216 // implicitly re-create it here, so abort the transaction. | 216 // implicitly re-create it here, so abort the transaction. |
217 IDBOpenDBRequest* idbOpenDBRequest = static_cast<IDBOpenDBRequest*>(even
t->target()); | 217 IDBOpenDBRequest* idbOpenDBRequest = static_cast<IDBOpenDBRequest*>(even
t->target()); |
218 NonThrowableExceptionState exceptionState; | 218 NonThrowableExceptionState exceptionState; |
219 idbOpenDBRequest->transaction()->abort(exceptionState); | 219 idbOpenDBRequest->transaction()->abort(exceptionState); |
220 m_executableWithDatabase->requestCallback()->sendFailure("Aborted upgrad
e."); | 220 m_executableWithDatabase->getRequestCallback()->sendFailure("Aborted upg
rade."); |
221 } | 221 } |
222 | 222 |
223 private: | 223 private: |
224 UpgradeDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) | 224 UpgradeDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) |
225 : EventListener(EventListener::CPPEventListenerType) | 225 : EventListener(EventListener::CPPEventListenerType) |
226 , m_executableWithDatabase(executableWithDatabase) { } | 226 , m_executableWithDatabase(executableWithDatabase) { } |
227 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; | 227 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; |
228 }; | 228 }; |
229 | 229 |
230 void ExecutableWithDatabase::start(IDBFactory* idbFactory, SecurityOrigin*, cons
t String& databaseName) | 230 void ExecutableWithDatabase::start(IDBFactory* idbFactory, SecurityOrigin*, cons
t String& databaseName) |
231 { | 231 { |
232 RefPtrWillBeRawPtr<OpenDatabaseCallback> openCallback = OpenDatabaseCallback
::create(this); | 232 RefPtrWillBeRawPtr<OpenDatabaseCallback> openCallback = OpenDatabaseCallback
::create(this); |
233 RefPtrWillBeRawPtr<UpgradeDatabaseCallback> upgradeCallback = UpgradeDatabas
eCallback::create(this); | 233 RefPtrWillBeRawPtr<UpgradeDatabaseCallback> upgradeCallback = UpgradeDatabas
eCallback::create(this); |
234 TrackExceptionState exceptionState; | 234 TrackExceptionState exceptionState; |
235 IDBOpenDBRequest* idbOpenDBRequest = idbFactory->open(scriptState(), databas
eName, exceptionState); | 235 IDBOpenDBRequest* idbOpenDBRequest = idbFactory->open(getScriptState(), data
baseName, exceptionState); |
236 if (exceptionState.hadException()) { | 236 if (exceptionState.hadException()) { |
237 requestCallback()->sendFailure("Could not open database."); | 237 getRequestCallback()->sendFailure("Could not open database."); |
238 return; | 238 return; |
239 } | 239 } |
240 idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded, upgradeCal
lback, false); | 240 idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded, upgradeCal
lback, false); |
241 idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback, fa
lse); | 241 idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback, fa
lse); |
242 } | 242 } |
243 | 243 |
244 static IDBTransaction* transactionForDatabase(ScriptState* scriptState, IDBDatab
ase* idbDatabase, const String& objectStoreName, const String& mode = IndexedDBN
ames::readonly) | 244 static IDBTransaction* transactionForDatabase(ScriptState* scriptState, IDBDatab
ase* idbDatabase, const String& objectStoreName, const String& mode = IndexedDBN
ames::readonly) |
245 { | 245 { |
246 TrackExceptionState exceptionState; | 246 TrackExceptionState exceptionState; |
247 StringOrStringSequenceOrDOMStringList scope; | 247 StringOrStringSequenceOrDOMStringList scope; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 objectStores->addItem(objectStore.release()); | 335 objectStores->addItem(objectStore.release()); |
336 } | 336 } |
337 OwnPtr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::crea
te() | 337 OwnPtr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::crea
te() |
338 .setName(databaseMetadata.name) | 338 .setName(databaseMetadata.name) |
339 .setVersion(databaseMetadata.version) | 339 .setVersion(databaseMetadata.version) |
340 .setObjectStores(objectStores.release()).build(); | 340 .setObjectStores(objectStores.release()).build(); |
341 | 341 |
342 m_requestCallback->sendSuccess(result.release()); | 342 m_requestCallback->sendSuccess(result.release()); |
343 } | 343 } |
344 | 344 |
345 RequestCallback* requestCallback() override { return m_requestCallback.get()
; } | 345 RequestCallback* getRequestCallback() override { return m_requestCallback.ge
t(); } |
346 private: | 346 private: |
347 DatabaseLoader(ScriptState* scriptState, PassOwnPtr<RequestDatabaseCallback>
requestCallback) | 347 DatabaseLoader(ScriptState* scriptState, PassOwnPtr<RequestDatabaseCallback>
requestCallback) |
348 : ExecutableWithDatabase(scriptState) | 348 : ExecutableWithDatabase(scriptState) |
349 , m_requestCallback(requestCallback) { } | 349 , m_requestCallback(requestCallback) { } |
350 OwnPtr<RequestDatabaseCallback> m_requestCallback; | 350 OwnPtr<RequestDatabaseCallback> m_requestCallback; |
351 }; | 351 }; |
352 | 352 |
353 static IDBKey* idbKeyFromInspectorObject(protocol::IndexedDB::Key* key) | 353 static IDBKey* idbKeyFromInspectorObject(protocol::IndexedDB::Key* key) |
354 { | 354 { |
355 IDBKey* idbKey; | 355 IDBKey* idbKey; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 } | 454 } |
455 | 455 |
456 // Continue cursor before making injected script calls, otherwise transa
ction might be finished. | 456 // Continue cursor before making injected script calls, otherwise transa
ction might be finished. |
457 TrackExceptionState exceptionState; | 457 TrackExceptionState exceptionState; |
458 idbCursor->continueFunction(nullptr, nullptr, exceptionState); | 458 idbCursor->continueFunction(nullptr, nullptr, exceptionState); |
459 if (exceptionState.hadException()) { | 459 if (exceptionState.hadException()) { |
460 m_requestCallback->sendFailure("Could not continue cursor."); | 460 m_requestCallback->sendFailure("Could not continue cursor."); |
461 return; | 461 return; |
462 } | 462 } |
463 | 463 |
464 Document* document = toDocument(m_scriptState->executionContext()); | 464 Document* document = toDocument(m_scriptState->getExecutionContext()); |
465 if (!document) | 465 if (!document) |
466 return; | 466 return; |
467 // FIXME: There are no tests for this error showing when a recursive | 467 // FIXME: There are no tests for this error showing when a recursive |
468 // object is inspected. | 468 // object is inspected. |
469 const String16 errorMessage("\"Inspection error. Maximum depth reached?\
""); | 469 const String16 errorMessage("\"Inspection error. Maximum depth reached?\
""); |
470 ScriptState* scriptState = m_scriptState.get(); | 470 ScriptState* scriptState = m_scriptState.get(); |
471 ScriptState::Scope scope(scriptState); | 471 ScriptState::Scope scope(scriptState); |
472 OwnPtr<protocol::Value> keyJsonValue = toProtocolValue(scriptState->cont
ext(), idbCursor->key(scriptState).v8Value()); | 472 OwnPtr<protocol::Value> keyJsonValue = toProtocolValue(scriptState->cont
ext(), idbCursor->key(scriptState).v8Value()); |
473 OwnPtr<protocol::Value> primaryKeyJsonValue = toProtocolValue(scriptStat
e->context(), idbCursor->primaryKey(scriptState).v8Value()); | 473 OwnPtr<protocol::Value> primaryKeyJsonValue = toProtocolValue(scriptStat
e->context(), idbCursor->primaryKey(scriptState).v8Value()); |
474 OwnPtr<protocol::Value> valueJsonValue = toProtocolValue(scriptState->co
ntext(), idbCursor->value(scriptState).v8Value()); | 474 OwnPtr<protocol::Value> valueJsonValue = toProtocolValue(scriptState->co
ntext(), idbCursor->value(scriptState).v8Value()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 public: | 514 public: |
515 static PassRefPtr<DataLoader> create(ScriptState* scriptState, PassOwnPtr<Re
questDataCallback> requestCallback, const String& objectStoreName, const String&
indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize) | 515 static PassRefPtr<DataLoader> create(ScriptState* scriptState, PassOwnPtr<Re
questDataCallback> requestCallback, const String& objectStoreName, const String&
indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize) |
516 { | 516 { |
517 return adoptRef(new DataLoader(scriptState, requestCallback, objectStore
Name, indexName, idbKeyRange, skipCount, pageSize)); | 517 return adoptRef(new DataLoader(scriptState, requestCallback, objectStore
Name, indexName, idbKeyRange, skipCount, pageSize)); |
518 } | 518 } |
519 | 519 |
520 ~DataLoader() override { } | 520 ~DataLoader() override { } |
521 | 521 |
522 void execute(IDBDatabase* idbDatabase) override | 522 void execute(IDBDatabase* idbDatabase) override |
523 { | 523 { |
524 IDBTransaction* idbTransaction = transactionForDatabase(scriptState(), i
dbDatabase, m_objectStoreName); | 524 IDBTransaction* idbTransaction = transactionForDatabase(getScriptState()
, idbDatabase, m_objectStoreName); |
525 if (!idbTransaction) { | 525 if (!idbTransaction) { |
526 m_requestCallback->sendFailure("Could not get transaction"); | 526 m_requestCallback->sendFailure("Could not get transaction"); |
527 return; | 527 return; |
528 } | 528 } |
529 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio
n, m_objectStoreName); | 529 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio
n, m_objectStoreName); |
530 if (!idbObjectStore) { | 530 if (!idbObjectStore) { |
531 m_requestCallback->sendFailure("Could not get object store"); | 531 m_requestCallback->sendFailure("Could not get object store"); |
532 return; | 532 return; |
533 } | 533 } |
534 | 534 |
535 IDBRequest* idbRequest; | 535 IDBRequest* idbRequest; |
536 if (!m_indexName.isEmpty()) { | 536 if (!m_indexName.isEmpty()) { |
537 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName
); | 537 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName
); |
538 if (!idbIndex) { | 538 if (!idbIndex) { |
539 m_requestCallback->sendFailure("Could not get index"); | 539 m_requestCallback->sendFailure("Could not get index"); |
540 return; | 540 return; |
541 } | 541 } |
542 | 542 |
543 idbRequest = idbIndex->openCursor(scriptState(), m_idbKeyRange.get()
, WebIDBCursorDirectionNext); | 543 idbRequest = idbIndex->openCursor(getScriptState(), m_idbKeyRange.ge
t(), WebIDBCursorDirectionNext); |
544 } else { | 544 } else { |
545 idbRequest = idbObjectStore->openCursor(scriptState(), m_idbKeyRange
.get(), WebIDBCursorDirectionNext); | 545 idbRequest = idbObjectStore->openCursor(getScriptState(), m_idbKeyRa
nge.get(), WebIDBCursorDirectionNext); |
546 } | 546 } |
547 RefPtrWillBeRawPtr<OpenCursorCallback> openCursorCallback = OpenCursorCa
llback::create(scriptState(), m_requestCallback.release(), m_skipCount, m_pageSi
ze); | 547 RefPtrWillBeRawPtr<OpenCursorCallback> openCursorCallback = OpenCursorCa
llback::create(getScriptState(), m_requestCallback.release(), m_skipCount, m_pag
eSize); |
548 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback
, false); | 548 idbRequest->addEventListener(EventTypeNames::success, openCursorCallback
, false); |
549 } | 549 } |
550 | 550 |
551 RequestCallback* requestCallback() override { return m_requestCallback.get()
; } | 551 RequestCallback* getRequestCallback() override { return m_requestCallback.ge
t(); } |
552 DataLoader(ScriptState* scriptState, PassOwnPtr<RequestDataCallback> request
Callback, const String& objectStoreName, const String& indexName, IDBKeyRange* i
dbKeyRange, int skipCount, unsigned pageSize) | 552 DataLoader(ScriptState* scriptState, PassOwnPtr<RequestDataCallback> request
Callback, const String& objectStoreName, const String& indexName, IDBKeyRange* i
dbKeyRange, int skipCount, unsigned pageSize) |
553 : ExecutableWithDatabase(scriptState) | 553 : ExecutableWithDatabase(scriptState) |
554 , m_requestCallback(requestCallback) | 554 , m_requestCallback(requestCallback) |
555 , m_objectStoreName(objectStoreName) | 555 , m_objectStoreName(objectStoreName) |
556 , m_indexName(indexName) | 556 , m_indexName(indexName) |
557 , m_idbKeyRange(idbKeyRange) | 557 , m_idbKeyRange(idbKeyRange) |
558 , m_skipCount(skipCount) | 558 , m_skipCount(skipCount) |
559 , m_pageSize(pageSize) | 559 , m_pageSize(pageSize) |
560 { | 560 { |
561 } | 561 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 642 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
643 if (!scriptState) | 643 if (!scriptState) |
644 return; | 644 return; |
645 ScriptState::Scope scope(scriptState); | 645 ScriptState::Scope scope(scriptState); |
646 TrackExceptionState exceptionState; | 646 TrackExceptionState exceptionState; |
647 IDBRequest* idbRequest = idbFactory->getDatabaseNames(scriptState, exception
State); | 647 IDBRequest* idbRequest = idbFactory->getDatabaseNames(scriptState, exception
State); |
648 if (exceptionState.hadException()) { | 648 if (exceptionState.hadException()) { |
649 requestCallback->sendFailure("Could not obtain database names."); | 649 requestCallback->sendFailure("Could not obtain database names."); |
650 return; | 650 return; |
651 } | 651 } |
652 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba
ck::create(requestCallback, document->securityOrigin()->toRawString()), false); | 652 idbRequest->addEventListener(EventTypeNames::success, GetDatabaseNamesCallba
ck::create(requestCallback, document->getSecurityOrigin()->toRawString()), false
); |
653 } | 653 } |
654 | 654 |
655 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St
ring& securityOrigin, const String& databaseName, PassOwnPtr<RequestDatabaseCall
back> requestCallback) | 655 void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, const St
ring& securityOrigin, const String& databaseName, PassOwnPtr<RequestDatabaseCall
back> requestCallback) |
656 { | 656 { |
657 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi
n); | 657 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi
n); |
658 Document* document = assertDocument(errorString, frame); | 658 Document* document = assertDocument(errorString, frame); |
659 if (!document) | 659 if (!document) |
660 return; | 660 return; |
661 IDBFactory* idbFactory = assertIDBFactory(errorString, document); | 661 IDBFactory* idbFactory = assertIDBFactory(errorString, document); |
662 if (!idbFactory) | 662 if (!idbFactory) |
663 return; | 663 return; |
664 | 664 |
665 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 665 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
666 if (!scriptState) | 666 if (!scriptState) |
667 return; | 667 return; |
668 ScriptState::Scope scope(scriptState); | 668 ScriptState::Scope scope(scriptState); |
669 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState,
requestCallback); | 669 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState,
requestCallback); |
670 databaseLoader->start(idbFactory, document->securityOrigin(), databaseName); | 670 databaseLoader->start(idbFactory, document->getSecurityOrigin(), databaseNam
e); |
671 } | 671 } |
672 | 672 |
673 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, | 673 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, |
674 const String& securityOrigin, | 674 const String& securityOrigin, |
675 const String& databaseName, | 675 const String& databaseName, |
676 const String& objectStoreName, | 676 const String& objectStoreName, |
677 const String& indexName, | 677 const String& indexName, |
678 int skipCount, | 678 int skipCount, |
679 int pageSize, | 679 int pageSize, |
680 const Maybe<protocol::IndexedDB::KeyRange>& keyRange, | 680 const Maybe<protocol::IndexedDB::KeyRange>& keyRange, |
(...skipping 11 matching lines...) Expand all Loading... |
692 if (keyRange.isJust() && !idbKeyRange) { | 692 if (keyRange.isJust() && !idbKeyRange) { |
693 *errorString = "Can not parse key range."; | 693 *errorString = "Can not parse key range."; |
694 return; | 694 return; |
695 } | 695 } |
696 | 696 |
697 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 697 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
698 if (!scriptState) | 698 if (!scriptState) |
699 return; | 699 return; |
700 ScriptState::Scope scope(scriptState); | 700 ScriptState::Scope scope(scriptState); |
701 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb
ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize); | 701 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb
ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize); |
702 dataLoader->start(idbFactory, document->securityOrigin(), databaseName); | 702 dataLoader->start(idbFactory, document->getSecurityOrigin(), databaseName); |
703 } | 703 } |
704 | 704 |
705 class ClearObjectStoreListener final : public EventListener { | 705 class ClearObjectStoreListener final : public EventListener { |
706 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener); | 706 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener); |
707 public: | 707 public: |
708 static PassRefPtrWillBeRawPtr<ClearObjectStoreListener> create(PassOwnPtr<Cl
earObjectStoreCallback> requestCallback) | 708 static PassRefPtrWillBeRawPtr<ClearObjectStoreListener> create(PassOwnPtr<Cl
earObjectStoreCallback> requestCallback) |
709 { | 709 { |
710 return adoptRefWillBeNoop(new ClearObjectStoreListener(requestCallback))
; | 710 return adoptRefWillBeNoop(new ClearObjectStoreListener(requestCallback))
; |
711 } | 711 } |
712 | 712 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 | 752 |
753 ClearObjectStore(ScriptState* scriptState, const String& objectStoreName, Pa
ssOwnPtr<ClearObjectStoreCallback> requestCallback) | 753 ClearObjectStore(ScriptState* scriptState, const String& objectStoreName, Pa
ssOwnPtr<ClearObjectStoreCallback> requestCallback) |
754 : ExecutableWithDatabase(scriptState) | 754 : ExecutableWithDatabase(scriptState) |
755 , m_objectStoreName(objectStoreName) | 755 , m_objectStoreName(objectStoreName) |
756 , m_requestCallback(requestCallback) | 756 , m_requestCallback(requestCallback) |
757 { | 757 { |
758 } | 758 } |
759 | 759 |
760 void execute(IDBDatabase* idbDatabase) override | 760 void execute(IDBDatabase* idbDatabase) override |
761 { | 761 { |
762 IDBTransaction* idbTransaction = transactionForDatabase(scriptState(), i
dbDatabase, m_objectStoreName, IndexedDBNames::readwrite); | 762 IDBTransaction* idbTransaction = transactionForDatabase(getScriptState()
, idbDatabase, m_objectStoreName, IndexedDBNames::readwrite); |
763 if (!idbTransaction) { | 763 if (!idbTransaction) { |
764 m_requestCallback->sendFailure("Could not get transaction"); | 764 m_requestCallback->sendFailure("Could not get transaction"); |
765 return; | 765 return; |
766 } | 766 } |
767 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio
n, m_objectStoreName); | 767 IDBObjectStore* idbObjectStore = objectStoreForTransaction(idbTransactio
n, m_objectStoreName); |
768 if (!idbObjectStore) { | 768 if (!idbObjectStore) { |
769 m_requestCallback->sendFailure("Could not get object store"); | 769 m_requestCallback->sendFailure("Could not get object store"); |
770 return; | 770 return; |
771 } | 771 } |
772 | 772 |
773 TrackExceptionState exceptionState; | 773 TrackExceptionState exceptionState; |
774 idbObjectStore->clear(scriptState(), exceptionState); | 774 idbObjectStore->clear(getScriptState(), exceptionState); |
775 ASSERT(!exceptionState.hadException()); | 775 ASSERT(!exceptionState.hadException()); |
776 if (exceptionState.hadException()) { | 776 if (exceptionState.hadException()) { |
777 ExceptionCode ec = exceptionState.code(); | 777 ExceptionCode ec = exceptionState.code(); |
778 m_requestCallback->sendFailure(String::format("Could not clear objec
t store '%s': %d", m_objectStoreName.utf8().data(), ec)); | 778 m_requestCallback->sendFailure(String::format("Could not clear objec
t store '%s': %d", m_objectStoreName.utf8().data(), ec)); |
779 return; | 779 return; |
780 } | 780 } |
781 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt
oreListener::create(m_requestCallback.release()), false); | 781 idbTransaction->addEventListener(EventTypeNames::complete, ClearObjectSt
oreListener::create(m_requestCallback.release()), false); |
782 } | 782 } |
783 | 783 |
784 RequestCallback* requestCallback() override { return m_requestCallback.get()
; } | 784 RequestCallback* getRequestCallback() override { return m_requestCallback.ge
t(); } |
785 private: | 785 private: |
786 const String m_objectStoreName; | 786 const String m_objectStoreName; |
787 OwnPtr<ClearObjectStoreCallback> m_requestCallback; | 787 OwnPtr<ClearObjectStoreCallback> m_requestCallback; |
788 }; | 788 }; |
789 | 789 |
790 void InspectorIndexedDBAgent::clearObjectStore(ErrorString* errorString, const S
tring& securityOrigin, const String& databaseName, const String& objectStoreName
, PassOwnPtr<ClearObjectStoreCallback> requestCallback) | 790 void InspectorIndexedDBAgent::clearObjectStore(ErrorString* errorString, const S
tring& securityOrigin, const String& databaseName, const String& objectStoreName
, PassOwnPtr<ClearObjectStoreCallback> requestCallback) |
791 { | 791 { |
792 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi
n); | 792 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi
n); |
793 Document* document = assertDocument(errorString, frame); | 793 Document* document = assertDocument(errorString, frame); |
794 if (!document) | 794 if (!document) |
795 return; | 795 return; |
796 IDBFactory* idbFactory = assertIDBFactory(errorString, document); | 796 IDBFactory* idbFactory = assertIDBFactory(errorString, document); |
797 if (!idbFactory) | 797 if (!idbFactory) |
798 return; | 798 return; |
799 | 799 |
800 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 800 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
801 if (!scriptState) | 801 if (!scriptState) |
802 return; | 802 return; |
803 ScriptState::Scope scope(scriptState); | 803 ScriptState::Scope scope(scriptState); |
804 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS
tate, objectStoreName, requestCallback); | 804 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS
tate, objectStoreName, requestCallback); |
805 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName
); | 805 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), databaseN
ame); |
806 } | 806 } |
807 | 807 |
808 DEFINE_TRACE(InspectorIndexedDBAgent) | 808 DEFINE_TRACE(InspectorIndexedDBAgent) |
809 { | 809 { |
810 visitor->trace(m_inspectedFrames); | 810 visitor->trace(m_inspectedFrames); |
811 InspectorBaseAgent::trace(visitor); | 811 InspectorBaseAgent::trace(visitor); |
812 } | 812 } |
813 | 813 |
814 } // namespace blink | 814 } // namespace blink |
OLD | NEW |