| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 | 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "modules/indexeddb/IDBFactory.h" | 30 #include "modules/indexeddb/IDBFactory.h" |
| 31 | 31 |
| 32 #include "bindings/v8/ExceptionState.h" |
| 32 #include "bindings/v8/IDBBindingUtilities.h" | 33 #include "bindings/v8/IDBBindingUtilities.h" |
| 33 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 34 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/page/Frame.h" | 36 #include "core/page/Frame.h" |
| 36 #include "core/page/Page.h" | 37 #include "core/page/Page.h" |
| 37 #include "core/page/PageGroup.h" | 38 #include "core/page/PageGroup.h" |
| 38 #include "core/platform/HistogramSupport.h" | 39 #include "core/platform/HistogramSupport.h" |
| 39 #include "core/workers/WorkerGlobalScope.h" | 40 #include "core/workers/WorkerGlobalScope.h" |
| 40 #include "core/workers/WorkerLoaderProxy.h" | 41 #include "core/workers/WorkerLoaderProxy.h" |
| 41 #include "core/workers/WorkerThread.h" | 42 #include "core/workers/WorkerThread.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 static bool isContextValid(ScriptExecutionContext* context) | 68 static bool isContextValid(ScriptExecutionContext* context) |
| 68 { | 69 { |
| 69 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); | 70 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); |
| 70 if (context->isDocument()) { | 71 if (context->isDocument()) { |
| 71 Document* document = toDocument(context); | 72 Document* document = toDocument(context); |
| 72 return document->frame() && document->page(); | 73 return document->frame() && document->page(); |
| 73 } | 74 } |
| 74 return true; | 75 return true; |
| 75 } | 76 } |
| 76 | 77 |
| 77 PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ScriptExecutionContext* cont
ext, ExceptionCode& ec) | 78 PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ScriptExecutionContext* cont
ext, ExceptionState& es) |
| 78 { | 79 { |
| 79 IDB_TRACE("IDBFactory::getDatabaseNames"); | 80 IDB_TRACE("IDBFactory::getDatabaseNames"); |
| 80 if (!isContextValid(context)) | 81 if (!isContextValid(context)) |
| 81 return 0; | 82 return 0; |
| 82 if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) { | 83 if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) { |
| 83 ec = SecurityError; | 84 es.throwDOMException(SecurityError); |
| 84 return 0; | 85 return 0; |
| 85 } | 86 } |
| 86 | 87 |
| 87 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), 0); | 88 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), 0); |
| 88 m_backend->getDatabaseNames(request, createDatabaseIdentifierFromSecurityOri
gin(context->securityOrigin()), context); | 89 m_backend->getDatabaseNames(request, createDatabaseIdentifierFromSecurityOri
gin(context->securityOrigin()), context); |
| 89 return request; | 90 return request; |
| 90 } | 91 } |
| 91 | 92 |
| 92 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, c
onst String& name, unsigned long long version, ExceptionCode& ec) | 93 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, c
onst String& name, unsigned long long version, ExceptionState& es) |
| 93 { | 94 { |
| 94 IDB_TRACE("IDBFactory::open"); | 95 IDB_TRACE("IDBFactory::open"); |
| 95 if (!version) { | 96 if (!version) { |
| 96 ec = TypeError; | 97 es.throwTypeError(); |
| 97 return 0; | 98 return 0; |
| 98 } | 99 } |
| 99 return openInternal(context, name, version, ec); | 100 return openInternal(context, name, version, es); |
| 100 } | 101 } |
| 101 | 102 |
| 102 PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* co
ntext, const String& name, int64_t version, ExceptionCode& ec) | 103 PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* co
ntext, const String& name, int64_t version, ExceptionState& es) |
| 103 { | 104 { |
| 104 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBOpenCall, IDBMethodsMax); | 105 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBOpenCall, IDBMethodsMax); |
| 105 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion); | 106 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion); |
| 106 if (name.isNull()) { | 107 if (name.isNull()) { |
| 107 ec = TypeError; | 108 es.throwTypeError(); |
| 108 return 0; | 109 return 0; |
| 109 } | 110 } |
| 110 if (!isContextValid(context)) | 111 if (!isContextValid(context)) |
| 111 return 0; | 112 return 0; |
| 112 if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) { | 113 if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) { |
| 113 ec = SecurityError; | 114 es.throwDOMException(SecurityError); |
| 114 return 0; | 115 return 0; |
| 115 } | 116 } |
| 116 | 117 |
| 117 RefPtr<IDBDatabaseCallbacksImpl> databaseCallbacks = IDBDatabaseCallbacksImp
l::create(); | 118 RefPtr<IDBDatabaseCallbacksImpl> databaseCallbacks = IDBDatabaseCallbacksImp
l::create(); |
| 118 int64_t transactionId = IDBDatabase::nextTransactionId(); | 119 int64_t transactionId = IDBDatabase::nextTransactionId(); |
| 119 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); | 120 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); |
| 120 m_backend->open(name, version, transactionId, request, databaseCallbacks, cr
eateDatabaseIdentifierFromSecurityOrigin(context->securityOrigin()), context); | 121 m_backend->open(name, version, transactionId, request, databaseCallbacks, cr
eateDatabaseIdentifierFromSecurityOrigin(context->securityOrigin()), context); |
| 121 return request; | 122 return request; |
| 122 } | 123 } |
| 123 | 124 |
| 124 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, c
onst String& name, ExceptionCode& ec) | 125 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, c
onst String& name, ExceptionState& es) |
| 125 { | 126 { |
| 126 IDB_TRACE("IDBFactory::open"); | 127 IDB_TRACE("IDBFactory::open"); |
| 127 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, ec); | 128 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, es); |
| 128 } | 129 } |
| 129 | 130 |
| 130 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ScriptExecutionContext*
context, const String& name, ExceptionCode& ec) | 131 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ScriptExecutionContext*
context, const String& name, ExceptionState& es) |
| 131 { | 132 { |
| 132 IDB_TRACE("IDBFactory::deleteDatabase"); | 133 IDB_TRACE("IDBFactory::deleteDatabase"); |
| 133 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBDeleteDatabaseCall, IDBMethodsMax); | 134 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls",
IDBDeleteDatabaseCall, IDBMethodsMax); |
| 134 if (name.isNull()) { | 135 if (name.isNull()) { |
| 135 ec = TypeError; | 136 es.throwTypeError(); |
| 136 return 0; | 137 return 0; |
| 137 } | 138 } |
| 138 if (!isContextValid(context)) | 139 if (!isContextValid(context)) |
| 139 return 0; | 140 return 0; |
| 140 if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) { | 141 if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) { |
| 141 ec = SecurityError; | 142 es.throwDOMException(SecurityError); |
| 142 return 0; | 143 return 0; |
| 143 } | 144 } |
| 144 | 145 |
| 145 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, I
DBDatabaseMetadata::DefaultIntVersion); | 146 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, I
DBDatabaseMetadata::DefaultIntVersion); |
| 146 m_backend->deleteDatabase(name, request, createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin()), context); | 147 m_backend->deleteDatabase(name, request, createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin()), context); |
| 147 return request; | 148 return request; |
| 148 } | 149 } |
| 149 | 150 |
| 150 short IDBFactory::cmp(ScriptExecutionContext* context, const ScriptValue& firstV
alue, const ScriptValue& secondValue, ExceptionCode& ec) | 151 short IDBFactory::cmp(ScriptExecutionContext* context, const ScriptValue& firstV
alue, const ScriptValue& secondValue, ExceptionState& es) |
| 151 { | 152 { |
| 152 DOMRequestState requestState(context); | 153 DOMRequestState requestState(context); |
| 153 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); | 154 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); |
| 154 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); | 155 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); |
| 155 | 156 |
| 156 ASSERT(first); | 157 ASSERT(first); |
| 157 ASSERT(second); | 158 ASSERT(second); |
| 158 | 159 |
| 159 if (!first->isValid() || !second->isValid()) { | 160 if (!first->isValid() || !second->isValid()) { |
| 160 ec = DataError; | 161 es.throwDOMException(DataError); |
| 161 return 0; | 162 return 0; |
| 162 } | 163 } |
| 163 | 164 |
| 164 return static_cast<short>(first->compare(second.get())); | 165 return static_cast<short>(first->compare(second.get())); |
| 165 } | 166 } |
| 166 | 167 |
| 167 } // namespace WebCore | 168 } // namespace WebCore |
| OLD | NEW |