| 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 22 matching lines...) Expand all Loading... |
| 33 #include "bindings/v8/ExceptionState.h" | 33 #include "bindings/v8/ExceptionState.h" |
| 34 #include "bindings/v8/IDBBindingUtilities.h" | 34 #include "bindings/v8/IDBBindingUtilities.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
| 37 #include "modules/indexeddb/IDBDatabase.h" | 37 #include "modules/indexeddb/IDBDatabase.h" |
| 38 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | 38 #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
| 39 #include "modules/indexeddb/IDBFactoryBackendInterface.h" | 39 #include "modules/indexeddb/IDBFactoryBackendInterface.h" |
| 40 #include "modules/indexeddb/IDBHistograms.h" | 40 #include "modules/indexeddb/IDBHistograms.h" |
| 41 #include "modules/indexeddb/IDBKey.h" | 41 #include "modules/indexeddb/IDBKey.h" |
| 42 #include "modules/indexeddb/IDBTracing.h" | 42 #include "modules/indexeddb/IDBTracing.h" |
| 43 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
| 43 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" | 44 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" |
| 44 #include "platform/weborigin/DatabaseIdentifier.h" | 45 #include "platform/weborigin/DatabaseIdentifier.h" |
| 45 #include "platform/weborigin/SecurityOrigin.h" | 46 #include "platform/weborigin/SecurityOrigin.h" |
| 46 #include "public/platform/Platform.h" | 47 #include "public/platform/Platform.h" |
| 48 #include "public/platform/WebIDBFactory.h" |
| 47 | 49 |
| 48 namespace WebCore { | 50 namespace WebCore { |
| 49 | 51 |
| 50 IDBFactory::IDBFactory(IDBFactoryBackendInterface* factory) | 52 static const char permissionDeniedErrorMessage[] = "The user denied permission t
o access the database."; |
| 51 : m_backend(factory) | 53 |
| 54 IDBFactory::IDBFactory(IDBFactoryBackendInterface* permissionClient) |
| 55 : m_permissionClient(permissionClient) |
| 52 { | 56 { |
| 53 // We pass a reference to this object before it can be adopted. | 57 // We pass a reference to this object before it can be adopted. |
| 54 relaxAdoptionRequirement(); | 58 relaxAdoptionRequirement(); |
| 55 ScriptWrappable::init(this); | 59 ScriptWrappable::init(this); |
| 56 } | 60 } |
| 57 | 61 |
| 58 IDBFactory::~IDBFactory() | 62 IDBFactory::~IDBFactory() |
| 59 { | 63 { |
| 60 } | 64 } |
| 61 | 65 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 73 { | 77 { |
| 74 IDB_TRACE("IDBFactory::getDatabaseNames"); | 78 IDB_TRACE("IDBFactory::getDatabaseNames"); |
| 75 if (!isContextValid(context)) | 79 if (!isContextValid(context)) |
| 76 return 0; | 80 return 0; |
| 77 if (!context->securityOrigin()->canAccessDatabase()) { | 81 if (!context->securityOrigin()->canAccessDatabase()) { |
| 78 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("ge
tDatabaseNames", "IDBFactory", "access to the Indexed Database API is denied in
this context.")); | 82 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("ge
tDatabaseNames", "IDBFactory", "access to the Indexed Database API is denied in
this context.")); |
| 79 return 0; | 83 return 0; |
| 80 } | 84 } |
| 81 | 85 |
| 82 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), 0); | 86 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), 0); |
| 83 m_backend->getDatabaseNames(request, createDatabaseIdentifierFromSecurityOri
gin(context->securityOrigin()), context); | 87 |
| 88 |
| 89 if (!m_permissionClient->allowIndexedDB(context, "Database Listing")) { |
| 90 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); |
| 91 return request; |
| 92 } |
| 93 |
| 94 blink::Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksIm
pl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(contex
t->securityOrigin())); |
| 84 return request; | 95 return request; |
| 85 } | 96 } |
| 86 | 97 |
| 87 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, unsigned long long version, ExceptionState& exceptionState) | 98 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, unsigned long long version, ExceptionState& exceptionState) |
| 88 { | 99 { |
| 89 IDB_TRACE("IDBFactory::open"); | 100 IDB_TRACE("IDBFactory::open"); |
| 90 if (!version) { | 101 if (!version) { |
| 91 exceptionState.throwUninformativeAndGenericTypeError(); | 102 exceptionState.throwUninformativeAndGenericTypeError(); |
| 92 return 0; | 103 return 0; |
| 93 } | 104 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 105 if (!isContextValid(context)) | 116 if (!isContextValid(context)) |
| 106 return 0; | 117 return 0; |
| 107 if (!context->securityOrigin()->canAccessDatabase()) { | 118 if (!context->securityOrigin()->canAccessDatabase()) { |
| 108 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("op
en", "IDBFactory", "access to the Indexed Database API is denied in this context
.")); | 119 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("op
en", "IDBFactory", "access to the Indexed Database API is denied in this context
.")); |
| 109 return 0; | 120 return 0; |
| 110 } | 121 } |
| 111 | 122 |
| 112 RefPtr<IDBDatabaseCallbacks> databaseCallbacks = IDBDatabaseCallbacks::creat
e(); | 123 RefPtr<IDBDatabaseCallbacks> databaseCallbacks = IDBDatabaseCallbacks::creat
e(); |
| 113 int64_t transactionId = IDBDatabase::nextTransactionId(); | 124 int64_t transactionId = IDBDatabase::nextTransactionId(); |
| 114 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); | 125 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); |
| 115 m_backend->open(name, version, transactionId, request, WebIDBDatabaseCallbac
ksImpl::create(databaseCallbacks.release()), createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin()), context); | 126 |
| 127 if (!m_permissionClient->allowIndexedDB(context, name)) { |
| 128 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); |
| 129 return request; |
| 130 } |
| 131 |
| 132 blink::Platform::current()->idbFactory()->open(name, version, transactionId,
WebIDBCallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::cr
eate(databaseCallbacks.release()).leakPtr(), createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin())); |
| 116 return request; | 133 return request; |
| 117 } | 134 } |
| 118 | 135 |
| 119 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, ExceptionState& exceptionState) | 136 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, ExceptionState& exceptionState) |
| 120 { | 137 { |
| 121 IDB_TRACE("IDBFactory::open"); | 138 IDB_TRACE("IDBFactory::open"); |
| 122 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, except
ionState); | 139 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, except
ionState); |
| 123 } | 140 } |
| 124 | 141 |
| 125 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ExecutionContext* contex
t, const String& name, ExceptionState& exceptionState) | 142 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ExecutionContext* contex
t, const String& name, ExceptionState& exceptionState) |
| 126 { | 143 { |
| 127 IDB_TRACE("IDBFactory::deleteDatabase"); | 144 IDB_TRACE("IDBFactory::deleteDatabase"); |
| 128 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteDatabaseCall, IDBMethodsMax); | 145 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteDatabaseCall, IDBMethodsMax); |
| 129 if (name.isNull()) { | 146 if (name.isNull()) { |
| 130 exceptionState.throwUninformativeAndGenericTypeError(); | 147 exceptionState.throwUninformativeAndGenericTypeError(); |
| 131 return 0; | 148 return 0; |
| 132 } | 149 } |
| 133 if (!isContextValid(context)) | 150 if (!isContextValid(context)) |
| 134 return 0; | 151 return 0; |
| 135 if (!context->securityOrigin()->canAccessDatabase()) { | 152 if (!context->securityOrigin()->canAccessDatabase()) { |
| 136 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("de
leteDatabase", "IDBFactory", "access to the Indexed Database API is denied in th
is context.")); | 153 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("de
leteDatabase", "IDBFactory", "access to the Indexed Database API is denied in th
is context.")); |
| 137 return 0; | 154 return 0; |
| 138 } | 155 } |
| 139 | 156 |
| 140 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, I
DBDatabaseMetadata::DefaultIntVersion); | 157 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, I
DBDatabaseMetadata::DefaultIntVersion); |
| 141 m_backend->deleteDatabase(name, request, createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin()), context); | 158 |
| 159 if (!m_permissionClient->allowIndexedDB(context, name)) { |
| 160 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); |
| 161 return request; |
| 162 } |
| 163 |
| 164 blink::Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbac
ksImpl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(co
ntext->securityOrigin())); |
| 142 return request; | 165 return request; |
| 143 } | 166 } |
| 144 | 167 |
| 145 short IDBFactory::cmp(ExecutionContext* context, const ScriptValue& firstValue,
const ScriptValue& secondValue, ExceptionState& exceptionState) | 168 short IDBFactory::cmp(ExecutionContext* context, const ScriptValue& firstValue,
const ScriptValue& secondValue, ExceptionState& exceptionState) |
| 146 { | 169 { |
| 147 DOMRequestState requestState(context); | 170 DOMRequestState requestState(context); |
| 148 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); | 171 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); |
| 149 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); | 172 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); |
| 150 | 173 |
| 151 ASSERT(first); | 174 ASSERT(first); |
| 152 ASSERT(second); | 175 ASSERT(second); |
| 153 | 176 |
| 154 if (!first->isValid() || !second->isValid()) { | 177 if (!first->isValid() || !second->isValid()) { |
| 155 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 178 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 156 return 0; | 179 return 0; |
| 157 } | 180 } |
| 158 | 181 |
| 159 return static_cast<short>(first->compare(second.get())); | 182 return static_cast<short>(first->compare(second.get())); |
| 160 } | 183 } |
| 161 | 184 |
| 162 } // namespace WebCore | 185 } // namespace WebCore |
| OLD | NEW |