| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 if (context->isDocument()) { | 66 if (context->isDocument()) { |
| 67 Document* document = toDocument(context); | 67 Document* document = toDocument(context); |
| 68 return document->frame() && document->page(); | 68 return document->frame() && document->page(); |
| 69 } | 69 } |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat
e& exceptionState) | 73 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat
e& exceptionState) |
| 74 { | 74 { |
| 75 IDB_TRACE("IDBFactory::getDatabaseNames"); | 75 IDB_TRACE("IDBFactory::getDatabaseNames"); |
| 76 if (!isContextValid(scriptState->executionContext())) | 76 if (!isContextValid(scriptState->getExecutionContext())) |
| 77 return nullptr; | 77 return nullptr; |
| 78 if (!scriptState->executionContext()->securityOrigin()->canAccessDatabase())
{ | 78 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { |
| 79 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 79 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
| 80 return nullptr; | 80 return nullptr; |
| 81 } | 81 } |
| 82 | 82 |
| 83 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(),
nullptr); | 83 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(),
nullptr); |
| 84 | 84 |
| 85 if (!m_permissionClient->allowIndexedDB(scriptState->executionContext(), "Da
tabase Listing")) { | 85 if (!m_permissionClient->allowIndexedDB(scriptState->getExecutionContext(),
"Database Listing")) { |
| 86 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 86 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
| 87 return request; | 87 return request; |
| 88 } | 88 } |
| 89 | 89 |
| 90 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre
ate(request).leakPtr(), WebSecurityOrigin(scriptState->executionContext()->secur
ityOrigin())); | 90 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre
ate(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()->ge
tSecurityOrigin())); |
| 91 return request; | 91 return request; |
| 92 } | 92 } |
| 93 | 93 |
| 94 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
unsigned long long version, ExceptionState& exceptionState) | 94 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
unsigned long long version, ExceptionState& exceptionState) |
| 95 { | 95 { |
| 96 IDB_TRACE("IDBFactory::open"); | 96 IDB_TRACE("IDBFactory::open"); |
| 97 if (!version) { | 97 if (!version) { |
| 98 exceptionState.throwTypeError("The version provided must not be 0."); | 98 exceptionState.throwTypeError("The version provided must not be 0."); |
| 99 return nullptr; | 99 return nullptr; |
| 100 } | 100 } |
| 101 return openInternal(scriptState, name, version, exceptionState); | 101 return openInternal(scriptState, name, version, exceptionState); |
| 102 } | 102 } |
| 103 | 103 |
| 104 IDBOpenDBRequest* IDBFactory::openInternal(ScriptState* scriptState, const Strin
g& name, int64_t version, ExceptionState& exceptionState) | 104 IDBOpenDBRequest* IDBFactory::openInternal(ScriptState* scriptState, const Strin
g& name, int64_t version, ExceptionState& exceptionState) |
| 105 { | 105 { |
| 106 IDBDatabase::recordApiCallsHistogram(IDBOpenCall); | 106 IDBDatabase::recordApiCallsHistogram(IDBOpenCall); |
| 107 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoVersion); | 107 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoVersion); |
| 108 if (!isContextValid(scriptState->executionContext())) | 108 if (!isContextValid(scriptState->getExecutionContext())) |
| 109 return nullptr; | 109 return nullptr; |
| 110 if (!scriptState->executionContext()->securityOrigin()->canAccessDatabase())
{ | 110 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { |
| 111 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 111 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
| 112 return nullptr; | 112 return nullptr; |
| 113 } | 113 } |
| 114 | 114 |
| 115 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create(); | 115 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create(); |
| 116 int64_t transactionId = IDBDatabase::nextTransactionId(); | 116 int64_t transactionId = IDBDatabase::nextTransactionId(); |
| 117 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa
llbacks, transactionId, version); | 117 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa
llbacks, transactionId, version); |
| 118 | 118 |
| 119 if (!m_permissionClient->allowIndexedDB(scriptState->executionContext(), nam
e)) { | 119 if (!m_permissionClient->allowIndexedDB(scriptState->getExecutionContext(),
name)) { |
| 120 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 120 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
| 121 return request; | 121 return request; |
| 122 } | 122 } |
| 123 | 123 |
| 124 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB
CallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::create(da
tabaseCallbacks).leakPtr(), WebSecurityOrigin(scriptState->executionContext()->s
ecurityOrigin())); | 124 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB
CallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::create(da
tabaseCallbacks).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); |
| 125 return request; | 125 return request; |
| 126 } | 126 } |
| 127 | 127 |
| 128 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
ExceptionState& exceptionState) | 128 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name,
ExceptionState& exceptionState) |
| 129 { | 129 { |
| 130 IDB_TRACE("IDBFactory::open"); | 130 IDB_TRACE("IDBFactory::open"); |
| 131 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep
tionState); | 131 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep
tionState); |
| 132 } | 132 } |
| 133 | 133 |
| 134 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str
ing& name, ExceptionState& exceptionState) | 134 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str
ing& name, ExceptionState& exceptionState) |
| 135 { | 135 { |
| 136 IDB_TRACE("IDBFactory::deleteDatabase"); | 136 IDB_TRACE("IDBFactory::deleteDatabase"); |
| 137 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); | 137 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); |
| 138 if (!isContextValid(scriptState->executionContext())) | 138 if (!isContextValid(scriptState->getExecutionContext())) |
| 139 return nullptr; | 139 return nullptr; |
| 140 if (!scriptState->executionContext()->securityOrigin()->canAccessDatabase())
{ | 140 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab
ase()) { |
| 141 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 141 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
| 142 return nullptr; | 142 return nullptr; |
| 143 } | 143 } |
| 144 | 144 |
| 145 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0
, IDBDatabaseMetadata::DefaultVersion); | 145 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0
, IDBDatabaseMetadata::DefaultVersion); |
| 146 | 146 |
| 147 if (!m_permissionClient->allowIndexedDB(scriptState->executionContext(), nam
e)) { | 147 if (!m_permissionClient->allowIndexedDB(scriptState->getExecutionContext(),
name)) { |
| 148 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); | 148 request->onError(DOMException::create(UnknownError, permissionDeniedErro
rMessage)); |
| 149 return request; | 149 return request; |
| 150 } | 150 } |
| 151 | 151 |
| 152 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl:
:create(request).leakPtr(), WebSecurityOrigin(scriptState->executionContext()->s
ecurityOrigin())); | 152 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl:
:create(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()
->getSecurityOrigin())); |
| 153 return request; | 153 return request; |
| 154 } | 154 } |
| 155 | 155 |
| 156 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c
onst ScriptValue& secondValue, ExceptionState& exceptionState) | 156 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c
onst ScriptValue& secondValue, ExceptionState& exceptionState) |
| 157 { | 157 { |
| 158 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue,
exceptionState); | 158 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue,
exceptionState); |
| 159 if (exceptionState.hadException()) | 159 if (exceptionState.hadException()) |
| 160 return 0; | 160 return 0; |
| 161 ASSERT(first); | 161 ASSERT(first); |
| 162 if (!first->isValid()) { | 162 if (!first->isValid()) { |
| 163 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 163 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 164 return 0; | 164 return 0; |
| 165 } | 165 } |
| 166 | 166 |
| 167 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu
e, exceptionState); | 167 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu
e, exceptionState); |
| 168 if (exceptionState.hadException()) | 168 if (exceptionState.hadException()) |
| 169 return 0; | 169 return 0; |
| 170 ASSERT(second); | 170 ASSERT(second); |
| 171 if (!second->isValid()) { | 171 if (!second->isValid()) { |
| 172 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 172 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 173 return 0; | 173 return 0; |
| 174 } | 174 } |
| 175 | 175 |
| 176 return static_cast<short>(first->compare(second)); | 176 return static_cast<short>(first->compare(second)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |