| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 static bool isContextValid(ExecutionContext* context) | 61 static bool isContextValid(ExecutionContext* context) |
| 62 { | 62 { |
| 63 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); | 63 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); |
| 64 if (context->isDocument()) { | 64 if (context->isDocument()) { |
| 65 Document* document = toDocument(context); | 65 Document* document = toDocument(context); |
| 66 return document->frame() && document->page(); | 66 return document->frame() && document->page(); |
| 67 } | 67 } |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ExecutionContext* context, E
xceptionState& es) | 71 PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ExecutionContext* context, E
xceptionState& exceptionState) |
| 72 { | 72 { |
| 73 IDB_TRACE("IDBFactory::getDatabaseNames"); | 73 IDB_TRACE("IDBFactory::getDatabaseNames"); |
| 74 if (!isContextValid(context)) | 74 if (!isContextValid(context)) |
| 75 return 0; | 75 return 0; |
| 76 if (!context->securityOrigin()->canAccessDatabase()) { | 76 if (!context->securityOrigin()->canAccessDatabase()) { |
| 77 es.throwSecurityError(ExceptionMessages::failedToExecute("getDatabaseNam
es", "IDBFactory", "access to the Indexed Database API is denied in this context
.")); | 77 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("ge
tDatabaseNames", "IDBFactory", "access to the Indexed Database API is denied in
this context.")); |
| 78 return 0; | 78 return 0; |
| 79 } | 79 } |
| 80 | 80 |
| 81 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), 0); | 81 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), 0); |
| 82 m_backend->getDatabaseNames(request, createDatabaseIdentifierFromSecurityOri
gin(context->securityOrigin()), context); | 82 m_backend->getDatabaseNames(request, createDatabaseIdentifierFromSecurityOri
gin(context->securityOrigin()), context); |
| 83 return request; | 83 return request; |
| 84 } | 84 } |
| 85 | 85 |
| 86 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, unsigned long long version, ExceptionState& es) | 86 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, unsigned long long version, ExceptionState& exceptionState) |
| 87 { | 87 { |
| 88 IDB_TRACE("IDBFactory::open"); | 88 IDB_TRACE("IDBFactory::open"); |
| 89 if (!version) { | 89 if (!version) { |
| 90 es.throwUninformativeAndGenericTypeError(); | 90 exceptionState.throwUninformativeAndGenericTypeError(); |
| 91 return 0; | 91 return 0; |
| 92 } | 92 } |
| 93 return openInternal(context, name, version, es); | 93 return openInternal(context, name, version, exceptionState); |
| 94 } | 94 } |
| 95 | 95 |
| 96 PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ExecutionContext* context,
const String& name, int64_t version, ExceptionState& es) | 96 PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ExecutionContext* context,
const String& name, int64_t version, ExceptionState& exceptionState) |
| 97 { | 97 { |
| 98 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBOpenCall, IDBMethodsMax); | 98 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBOpenCall, IDBMethodsMax); |
| 99 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion); | 99 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion); |
| 100 if (name.isNull()) { | 100 if (name.isNull()) { |
| 101 es.throwUninformativeAndGenericTypeError(); | 101 exceptionState.throwUninformativeAndGenericTypeError(); |
| 102 return 0; | 102 return 0; |
| 103 } | 103 } |
| 104 if (!isContextValid(context)) | 104 if (!isContextValid(context)) |
| 105 return 0; | 105 return 0; |
| 106 if (!context->securityOrigin()->canAccessDatabase()) { | 106 if (!context->securityOrigin()->canAccessDatabase()) { |
| 107 es.throwSecurityError(ExceptionMessages::failedToExecute("open", "IDBFac
tory", "access to the Indexed Database API is denied in this context.")); | 107 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("op
en", "IDBFactory", "access to the Indexed Database API is denied in this context
.")); |
| 108 return 0; | 108 return 0; |
| 109 } | 109 } |
| 110 | 110 |
| 111 RefPtr<IDBDatabaseCallbacksImpl> databaseCallbacks = IDBDatabaseCallbacksImp
l::create(); | 111 RefPtr<IDBDatabaseCallbacksImpl> databaseCallbacks = IDBDatabaseCallbacksImp
l::create(); |
| 112 int64_t transactionId = IDBDatabase::nextTransactionId(); | 112 int64_t transactionId = IDBDatabase::nextTransactionId(); |
| 113 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); | 113 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); |
| 114 m_backend->open(name, version, transactionId, request, databaseCallbacks, cr
eateDatabaseIdentifierFromSecurityOrigin(context->securityOrigin()), context); | 114 m_backend->open(name, version, transactionId, request, databaseCallbacks, cr
eateDatabaseIdentifierFromSecurityOrigin(context->securityOrigin()), context); |
| 115 return request; | 115 return request; |
| 116 } | 116 } |
| 117 | 117 |
| 118 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, ExceptionState& es) | 118 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, ExceptionState& exceptionState) |
| 119 { | 119 { |
| 120 IDB_TRACE("IDBFactory::open"); | 120 IDB_TRACE("IDBFactory::open"); |
| 121 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, es); | 121 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, except
ionState); |
| 122 } | 122 } |
| 123 | 123 |
| 124 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ExecutionContext* contex
t, const String& name, ExceptionState& es) | 124 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ExecutionContext* contex
t, const String& name, ExceptionState& exceptionState) |
| 125 { | 125 { |
| 126 IDB_TRACE("IDBFactory::deleteDatabase"); | 126 IDB_TRACE("IDBFactory::deleteDatabase"); |
| 127 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteDatabaseCall, IDBMethodsMax); | 127 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteDatabaseCall, IDBMethodsMax); |
| 128 if (name.isNull()) { | 128 if (name.isNull()) { |
| 129 es.throwUninformativeAndGenericTypeError(); | 129 exceptionState.throwUninformativeAndGenericTypeError(); |
| 130 return 0; | 130 return 0; |
| 131 } | 131 } |
| 132 if (!isContextValid(context)) | 132 if (!isContextValid(context)) |
| 133 return 0; | 133 return 0; |
| 134 if (!context->securityOrigin()->canAccessDatabase()) { | 134 if (!context->securityOrigin()->canAccessDatabase()) { |
| 135 es.throwSecurityError(ExceptionMessages::failedToExecute("deleteDatabase
", "IDBFactory", "access to the Indexed Database API is denied in this context."
)); | 135 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("de
leteDatabase", "IDBFactory", "access to the Indexed Database API is denied in th
is context.")); |
| 136 return 0; | 136 return 0; |
| 137 } | 137 } |
| 138 | 138 |
| 139 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, I
DBDatabaseMetadata::DefaultIntVersion); | 139 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, I
DBDatabaseMetadata::DefaultIntVersion); |
| 140 m_backend->deleteDatabase(name, request, createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin()), context); | 140 m_backend->deleteDatabase(name, request, createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin()), context); |
| 141 return request; | 141 return request; |
| 142 } | 142 } |
| 143 | 143 |
| 144 short IDBFactory::cmp(ExecutionContext* context, const ScriptValue& firstValue,
const ScriptValue& secondValue, ExceptionState& es) | 144 short IDBFactory::cmp(ExecutionContext* context, const ScriptValue& firstValue,
const ScriptValue& secondValue, ExceptionState& exceptionState) |
| 145 { | 145 { |
| 146 DOMRequestState requestState(context); | 146 DOMRequestState requestState(context); |
| 147 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); | 147 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); |
| 148 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); | 148 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); |
| 149 | 149 |
| 150 ASSERT(first); | 150 ASSERT(first); |
| 151 ASSERT(second); | 151 ASSERT(second); |
| 152 | 152 |
| 153 if (!first->isValid() || !second->isValid()) { | 153 if (!first->isValid() || !second->isValid()) { |
| 154 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); | 154 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 155 return 0; | 155 return 0; |
| 156 } | 156 } |
| 157 | 157 |
| 158 return static_cast<short>(first->compare(second.get())); | 158 return static_cast<short>(first->compare(second.get())); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace WebCore | 161 } // namespace WebCore |
| OLD | NEW |