| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  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 PassRefPtr<IDBTransaction> transactionForDatabase(ExecutionContext* execu
     tionContext, IDBDatabase* idbDatabase, const String& objectStoreName, const Stri
     ng& mode = IDBTransaction::modeReadOnly()) |  202 static PassRefPtr<IDBTransaction> transactionForDatabase(ExecutionContext* execu
     tionContext, IDBDatabase* idbDatabase, const String& objectStoreName, const Stri
     ng& mode = IDBTransaction::modeReadOnly()) | 
|  203 { |  203 { | 
|  204     TrackExceptionState exceptionState; |  204     TrackExceptionState exceptionState; | 
|  205     RefPtr<IDBTransaction> idbTransaction = idbDatabase->transaction(executionCo
     ntext, objectStoreName, mode, exceptionState); |  205     RefPtr<IDBTransaction> idbTransaction = idbDatabase->transaction(executionCo
     ntext, objectStoreName, mode, exceptionState); | 
|  206     if (exceptionState.hadException()) |  206     if (exceptionState.hadException()) | 
|  207         return 0; |  207         return nullptr; | 
|  208     return idbTransaction; |  208     return idbTransaction; | 
|  209 } |  209 } | 
|  210  |  210  | 
|  211 static PassRefPtr<IDBObjectStore> objectStoreForTransaction(IDBTransaction* idbT
     ransaction, const String& objectStoreName) |  211 static PassRefPtr<IDBObjectStore> objectStoreForTransaction(IDBTransaction* idbT
     ransaction, const String& objectStoreName) | 
|  212 { |  212 { | 
|  213     TrackExceptionState exceptionState; |  213     TrackExceptionState exceptionState; | 
|  214     RefPtr<IDBObjectStore> idbObjectStore = idbTransaction->objectStore(objectSt
     oreName, exceptionState); |  214     RefPtr<IDBObjectStore> idbObjectStore = idbTransaction->objectStore(objectSt
     oreName, exceptionState); | 
|  215     if (exceptionState.hadException()) |  215     if (exceptionState.hadException()) | 
|  216         return 0; |  216         return nullptr; | 
|  217     return idbObjectStore; |  217     return idbObjectStore; | 
|  218 } |  218 } | 
|  219  |  219  | 
|  220 static PassRefPtr<IDBIndex> indexForObjectStore(IDBObjectStore* idbObjectStore, 
     const String& indexName) |  220 static PassRefPtr<IDBIndex> indexForObjectStore(IDBObjectStore* idbObjectStore, 
     const String& indexName) | 
|  221 { |  221 { | 
|  222     TrackExceptionState exceptionState; |  222     TrackExceptionState exceptionState; | 
|  223     RefPtr<IDBIndex> idbIndex = idbObjectStore->index(indexName, exceptionState)
     ; |  223     RefPtr<IDBIndex> idbIndex = idbObjectStore->index(indexName, exceptionState)
     ; | 
|  224     if (exceptionState.hadException()) |  224     if (exceptionState.hadException()) | 
|  225         return 0; |  225         return nullptr; | 
|  226     return idbIndex; |  226     return idbIndex; | 
|  227 } |  227 } | 
|  228  |  228  | 
|  229 static PassRefPtr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPath) |  229 static PassRefPtr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPath) | 
|  230 { |  230 { | 
|  231     RefPtr<KeyPath> keyPath; |  231     RefPtr<KeyPath> keyPath; | 
|  232     switch (idbKeyPath.type()) { |  232     switch (idbKeyPath.type()) { | 
|  233     case IDBKeyPath::NullType: |  233     case IDBKeyPath::NullType: | 
|  234         keyPath = KeyPath::create().setType(KeyPath::Type::Null); |  234         keyPath = KeyPath::create().setType(KeyPath::Type::Null); | 
|  235         break; |  235         break; | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  311         , m_requestCallback(requestCallback) { } |  311         , m_requestCallback(requestCallback) { } | 
|  312     RefPtr<RequestDatabaseCallback> m_requestCallback; |  312     RefPtr<RequestDatabaseCallback> m_requestCallback; | 
|  313 }; |  313 }; | 
|  314  |  314  | 
|  315 static PassRefPtr<IDBKey> idbKeyFromInspectorObject(JSONObject* key) |  315 static PassRefPtr<IDBKey> idbKeyFromInspectorObject(JSONObject* key) | 
|  316 { |  316 { | 
|  317     RefPtr<IDBKey> idbKey; |  317     RefPtr<IDBKey> idbKey; | 
|  318  |  318  | 
|  319     String type; |  319     String type; | 
|  320     if (!key->getString("type", &type)) |  320     if (!key->getString("type", &type)) | 
|  321         return 0; |  321         return nullptr; | 
|  322  |  322  | 
|  323     DEFINE_STATIC_LOCAL(String, number, ("number")); |  323     DEFINE_STATIC_LOCAL(String, number, ("number")); | 
|  324     DEFINE_STATIC_LOCAL(String, string, ("string")); |  324     DEFINE_STATIC_LOCAL(String, string, ("string")); | 
|  325     DEFINE_STATIC_LOCAL(String, date, ("date")); |  325     DEFINE_STATIC_LOCAL(String, date, ("date")); | 
|  326     DEFINE_STATIC_LOCAL(String, array, ("array")); |  326     DEFINE_STATIC_LOCAL(String, array, ("array")); | 
|  327  |  327  | 
|  328     if (type == number) { |  328     if (type == number) { | 
|  329         double number; |  329         double number; | 
|  330         if (!key->getNumber("number", &number)) |  330         if (!key->getNumber("number", &number)) | 
|  331             return 0; |  331             return nullptr; | 
|  332         idbKey = IDBKey::createNumber(number); |  332         idbKey = IDBKey::createNumber(number); | 
|  333     } else if (type == string) { |  333     } else if (type == string) { | 
|  334         String string; |  334         String string; | 
|  335         if (!key->getString("string", &string)) |  335         if (!key->getString("string", &string)) | 
|  336             return 0; |  336             return nullptr; | 
|  337         idbKey = IDBKey::createString(string); |  337         idbKey = IDBKey::createString(string); | 
|  338     } else if (type == date) { |  338     } else if (type == date) { | 
|  339         double date; |  339         double date; | 
|  340         if (!key->getNumber("date", &date)) |  340         if (!key->getNumber("date", &date)) | 
|  341             return 0; |  341             return nullptr; | 
|  342         idbKey = IDBKey::createDate(date); |  342         idbKey = IDBKey::createDate(date); | 
|  343     } else if (type == array) { |  343     } else if (type == array) { | 
|  344         IDBKey::KeyArray keyArray; |  344         IDBKey::KeyArray keyArray; | 
|  345         RefPtr<JSONArray> array = key->getArray("array"); |  345         RefPtr<JSONArray> array = key->getArray("array"); | 
|  346         for (size_t i = 0; i < array->length(); ++i) { |  346         for (size_t i = 0; i < array->length(); ++i) { | 
|  347             RefPtr<JSONValue> value = array->get(i); |  347             RefPtr<JSONValue> value = array->get(i); | 
|  348             RefPtr<JSONObject> object; |  348             RefPtr<JSONObject> object; | 
|  349             if (!value->asObject(&object)) |  349             if (!value->asObject(&object)) | 
|  350                 return 0; |  350                 return nullptr; | 
|  351             keyArray.append(idbKeyFromInspectorObject(object.get())); |  351             keyArray.append(idbKeyFromInspectorObject(object.get())); | 
|  352         } |  352         } | 
|  353         idbKey = IDBKey::createArray(keyArray); |  353         idbKey = IDBKey::createArray(keyArray); | 
|  354     } else { |  354     } else { | 
|  355         return 0; |  355         return nullptr; | 
|  356     } |  356     } | 
|  357  |  357  | 
|  358     return idbKey.release(); |  358     return idbKey.release(); | 
|  359 } |  359 } | 
|  360  |  360  | 
|  361 static PassRefPtr<IDBKeyRange> idbKeyRangeFromKeyRange(JSONObject* keyRange) |  361 static PassRefPtr<IDBKeyRange> idbKeyRangeFromKeyRange(JSONObject* keyRange) | 
|  362 { |  362 { | 
|  363     RefPtr<JSONObject> lower = keyRange->getObject("lower"); |  363     RefPtr<JSONObject> lower = keyRange->getObject("lower"); | 
|  364     RefPtr<IDBKey> idbLower = lower ? idbKeyFromInspectorObject(lower.get()) : 0
     ; |  364     RefPtr<IDBKey> idbLower = lower ? idbKeyFromInspectorObject(lower.get()) : n
     ullptr; | 
|  365     if (lower && !idbLower) |  365     if (lower && !idbLower) | 
|  366         return 0; |  366         return nullptr; | 
|  367  |  367  | 
|  368     RefPtr<JSONObject> upper = keyRange->getObject("upper"); |  368     RefPtr<JSONObject> upper = keyRange->getObject("upper"); | 
|  369     RefPtr<IDBKey> idbUpper = upper ? idbKeyFromInspectorObject(upper.get()) : 0
     ; |  369     RefPtr<IDBKey> idbUpper = upper ? idbKeyFromInspectorObject(upper.get()) : n
     ullptr; | 
|  370     if (upper && !idbUpper) |  370     if (upper && !idbUpper) | 
|  371         return 0; |  371         return nullptr; | 
|  372  |  372  | 
|  373     bool lowerOpen; |  373     bool lowerOpen; | 
|  374     if (!keyRange->getBoolean("lowerOpen", &lowerOpen)) |  374     if (!keyRange->getBoolean("lowerOpen", &lowerOpen)) | 
|  375         return 0; |  375         return nullptr; | 
|  376     IDBKeyRange::LowerBoundType lowerBoundType = lowerOpen ? IDBKeyRange::LowerB
     oundOpen : IDBKeyRange::LowerBoundClosed; |  376     IDBKeyRange::LowerBoundType lowerBoundType = lowerOpen ? IDBKeyRange::LowerB
     oundOpen : IDBKeyRange::LowerBoundClosed; | 
|  377  |  377  | 
|  378     bool upperOpen; |  378     bool upperOpen; | 
|  379     if (!keyRange->getBoolean("upperOpen", &upperOpen)) |  379     if (!keyRange->getBoolean("upperOpen", &upperOpen)) | 
|  380         return 0; |  380         return nullptr; | 
|  381     IDBKeyRange::UpperBoundType upperBoundType = upperOpen ? IDBKeyRange::UpperB
     oundOpen : IDBKeyRange::UpperBoundClosed; |  381     IDBKeyRange::UpperBoundType upperBoundType = upperOpen ? IDBKeyRange::UpperB
     oundOpen : IDBKeyRange::UpperBoundClosed; | 
|  382  |  382  | 
|  383     RefPtr<IDBKeyRange> idbKeyRange = IDBKeyRange::create(idbLower, idbUpper, lo
     werBoundType, upperBoundType); |  383     RefPtr<IDBKeyRange> idbKeyRange = IDBKeyRange::create(idbLower, idbUpper, lo
     werBoundType, upperBoundType); | 
|  384     return idbKeyRange.release(); |  384     return idbKeyRange.release(); | 
|  385 } |  385 } | 
|  386  |  386  | 
|  387 class DataLoader; |  387 class DataLoader; | 
|  388  |  388  | 
|  389 class OpenCursorCallback FINAL : public EventListener { |  389 class OpenCursorCallback FINAL : public EventListener { | 
|  390 public: |  390 public: | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  429             return; |  429             return; | 
|  430         } |  430         } | 
|  431  |  431  | 
|  432         if (m_result->length() == m_pageSize) { |  432         if (m_result->length() == m_pageSize) { | 
|  433             end(true); |  433             end(true); | 
|  434             return; |  434             return; | 
|  435         } |  435         } | 
|  436  |  436  | 
|  437         // Continue cursor before making injected script calls, otherwise transa
     ction might be finished. |  437         // Continue cursor before making injected script calls, otherwise transa
     ction might be finished. | 
|  438         TrackExceptionState exceptionState; |  438         TrackExceptionState exceptionState; | 
|  439         idbCursor->continueFunction(0, 0, exceptionState); |  439         idbCursor->continueFunction(nullptr, nullptr, exceptionState); | 
|  440         if (exceptionState.hadException()) { |  440         if (exceptionState.hadException()) { | 
|  441             m_requestCallback->sendFailure("Could not continue cursor."); |  441             m_requestCallback->sendFailure("Could not continue cursor."); | 
|  442             return; |  442             return; | 
|  443         } |  443         } | 
|  444  |  444  | 
|  445         Document* document = toDocument(context); |  445         Document* document = toDocument(context); | 
|  446         if (!document) |  446         if (!document) | 
|  447             return; |  447             return; | 
|  448         ScriptState* scriptState = mainWorldScriptState(document->frame()); |  448         ScriptState* scriptState = mainWorldScriptState(document->frame()); | 
|  449  |  449  | 
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  662 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, const String
     & securityOrigin, const String& databaseName, const String& objectStoreName, con
     st String& indexName, int skipCount, int pageSize, const RefPtr<JSONObject>* key
     Range, PassRefPtr<RequestDataCallback> requestCallback) |  662 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, const String
     & securityOrigin, const String& databaseName, const String& objectStoreName, con
     st String& indexName, int skipCount, int pageSize, const RefPtr<JSONObject>* key
     Range, PassRefPtr<RequestDataCallback> requestCallback) | 
|  663 { |  663 { | 
|  664     Frame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin); |  664     Frame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin); | 
|  665     Document* document = assertDocument(errorString, frame); |  665     Document* document = assertDocument(errorString, frame); | 
|  666     if (!document) |  666     if (!document) | 
|  667         return; |  667         return; | 
|  668     IDBFactory* idbFactory = assertIDBFactory(errorString, document); |  668     IDBFactory* idbFactory = assertIDBFactory(errorString, document); | 
|  669     if (!idbFactory) |  669     if (!idbFactory) | 
|  670         return; |  670         return; | 
|  671  |  671  | 
|  672     RefPtr<IDBKeyRange> idbKeyRange = keyRange ? idbKeyRangeFromKeyRange(keyRang
     e->get()) : 0; |  672     RefPtr<IDBKeyRange> idbKeyRange = keyRange ? idbKeyRangeFromKeyRange(keyRang
     e->get()) : nullptr; | 
|  673     if (keyRange && !idbKeyRange) { |  673     if (keyRange && !idbKeyRange) { | 
|  674         *errorString = "Can not parse key range."; |  674         *errorString = "Can not parse key range."; | 
|  675         return; |  675         return; | 
|  676     } |  676     } | 
|  677  |  677  | 
|  678     // FIXME: This should probably use ScriptState/ScriptScope instead of V8 API |  678     // FIXME: This should probably use ScriptState/ScriptScope instead of V8 API | 
|  679     v8::Isolate* isolate = toIsolate(frame); |  679     v8::Isolate* isolate = toIsolate(frame); | 
|  680     v8::HandleScope handleScope(isolate); |  680     v8::HandleScope handleScope(isolate); | 
|  681     v8::Handle<v8::Context> context = toV8Context(isolate, document->frame(), DO
     MWrapperWorld::mainWorld()); |  681     v8::Handle<v8::Context> context = toV8Context(isolate, document->frame(), DO
     MWrapperWorld::mainWorld()); | 
|  682     ASSERT(!context.IsEmpty()); |  682     ASSERT(!context.IsEmpty()); | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  785     v8::HandleScope handleScope(isolate); |  785     v8::HandleScope handleScope(isolate); | 
|  786     v8::Handle<v8::Context> context = toV8Context(isolate, document->frame(), DO
     MWrapperWorld::mainWorld()); |  786     v8::Handle<v8::Context> context = toV8Context(isolate, document->frame(), DO
     MWrapperWorld::mainWorld()); | 
|  787     ASSERT(!context.IsEmpty()); |  787     ASSERT(!context.IsEmpty()); | 
|  788     v8::Context::Scope contextScope(context); |  788     v8::Context::Scope contextScope(context); | 
|  789  |  789  | 
|  790     RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(documen
     t, objectStoreName, requestCallback); |  790     RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(documen
     t, objectStoreName, requestCallback); | 
|  791     clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName
     ); |  791     clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName
     ); | 
|  792 } |  792 } | 
|  793  |  793  | 
|  794 } // namespace WebCore |  794 } // namespace WebCore | 
| OLD | NEW |