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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 Document* document = toDocument(context); | 69 Document* document = toDocument(context); |
70 return document->frame() && document->page(); | 70 return document->frame() && document->page(); |
71 } | 71 } |
72 return true; | 72 return true; |
73 } | 73 } |
74 | 74 |
75 PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ExecutionContext* context, E
xceptionState& exceptionState) | 75 PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ExecutionContext* context, E
xceptionState& exceptionState) |
76 { | 76 { |
77 IDB_TRACE("IDBFactory::getDatabaseNames"); | 77 IDB_TRACE("IDBFactory::getDatabaseNames"); |
78 if (!isContextValid(context)) | 78 if (!isContextValid(context)) |
79 return 0; | 79 return nullptr; |
80 if (!context->securityOrigin()->canAccessDatabase()) { | 80 if (!context->securityOrigin()->canAccessDatabase()) { |
81 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 81 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
82 return 0; | 82 return nullptr; |
83 } | 83 } |
84 | 84 |
85 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::createNull(
), 0); | 85 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::createNull(
), 0); |
86 | 86 |
87 if (!m_permissionClient->allowIndexedDB(context, "Database Listing")) { | 87 if (!m_permissionClient->allowIndexedDB(context, "Database Listing")) { |
88 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); | 88 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); |
89 return request; | 89 return request; |
90 } | 90 } |
91 | 91 |
92 blink::Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksIm
pl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(contex
t->securityOrigin())); | 92 blink::Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksIm
pl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(contex
t->securityOrigin())); |
93 return request; | 93 return request; |
94 } | 94 } |
95 | 95 |
96 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, unsigned long long version, ExceptionState& exceptionState) | 96 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, unsigned long long version, ExceptionState& exceptionState) |
97 { | 97 { |
98 IDB_TRACE("IDBFactory::open"); | 98 IDB_TRACE("IDBFactory::open"); |
99 if (!version) { | 99 if (!version) { |
100 exceptionState.throwTypeError("The version provided must not be 0."); | 100 exceptionState.throwTypeError("The version provided must not be 0."); |
101 return 0; | 101 return nullptr; |
102 } | 102 } |
103 return openInternal(context, name, version, exceptionState); | 103 return openInternal(context, name, version, exceptionState); |
104 } | 104 } |
105 | 105 |
106 PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ExecutionContext* context,
const String& name, int64_t version, ExceptionState& exceptionState) | 106 PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ExecutionContext* context,
const String& name, int64_t version, ExceptionState& exceptionState) |
107 { | 107 { |
108 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBOpenCall, IDBMethodsMax); | 108 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBOpenCall, IDBMethodsMax); |
109 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion); | 109 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion); |
110 if (name.isNull()) { | 110 if (name.isNull()) { |
111 exceptionState.throwTypeError("The name provided must not be empty."); | 111 exceptionState.throwTypeError("The name provided must not be empty."); |
112 return 0; | 112 return nullptr; |
113 } | 113 } |
114 if (!isContextValid(context)) | 114 if (!isContextValid(context)) |
115 return 0; | 115 return nullptr; |
116 if (!context->securityOrigin()->canAccessDatabase()) { | 116 if (!context->securityOrigin()->canAccessDatabase()) { |
117 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 117 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
118 return 0; | 118 return nullptr; |
119 } | 119 } |
120 | 120 |
121 RefPtr<IDBDatabaseCallbacks> databaseCallbacks = IDBDatabaseCallbacks::creat
e(); | 121 RefPtr<IDBDatabaseCallbacks> databaseCallbacks = IDBDatabaseCallbacks::creat
e(); |
122 int64_t transactionId = IDBDatabase::nextTransactionId(); | 122 int64_t transactionId = IDBDatabase::nextTransactionId(); |
123 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); | 123 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databas
eCallbacks, transactionId, version); |
124 | 124 |
125 if (!m_permissionClient->allowIndexedDB(context, name)) { | 125 if (!m_permissionClient->allowIndexedDB(context, name)) { |
126 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); | 126 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); |
127 return request; | 127 return request; |
128 } | 128 } |
129 | 129 |
130 blink::Platform::current()->idbFactory()->open(name, version, transactionId,
WebIDBCallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::cr
eate(databaseCallbacks.release()).leakPtr(), createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin())); | 130 blink::Platform::current()->idbFactory()->open(name, version, transactionId,
WebIDBCallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::cr
eate(databaseCallbacks.release()).leakPtr(), createDatabaseIdentifierFromSecurit
yOrigin(context->securityOrigin())); |
131 return request; | 131 return request; |
132 } | 132 } |
133 | 133 |
134 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, ExceptionState& exceptionState) | 134 PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* context, const S
tring& name, ExceptionState& exceptionState) |
135 { | 135 { |
136 IDB_TRACE("IDBFactory::open"); | 136 IDB_TRACE("IDBFactory::open"); |
137 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, except
ionState); | 137 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, except
ionState); |
138 } | 138 } |
139 | 139 |
140 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ExecutionContext* contex
t, const String& name, ExceptionState& exceptionState) | 140 PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ExecutionContext* contex
t, const String& name, ExceptionState& exceptionState) |
141 { | 141 { |
142 IDB_TRACE("IDBFactory::deleteDatabase"); | 142 IDB_TRACE("IDBFactory::deleteDatabase"); |
143 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteDatabaseCall, IDBMethodsMax); | 143 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd
APICalls", IDBDeleteDatabaseCall, IDBMethodsMax); |
144 if (name.isNull()) { | 144 if (name.isNull()) { |
145 exceptionState.throwTypeError("The name provided must not be empty."); | 145 exceptionState.throwTypeError("The name provided must not be empty."); |
146 return 0; | 146 return nullptr; |
147 } | 147 } |
148 if (!isContextValid(context)) | 148 if (!isContextValid(context)) |
149 return 0; | 149 return nullptr; |
150 if (!context->securityOrigin()->canAccessDatabase()) { | 150 if (!context->securityOrigin()->canAccessDatabase()) { |
151 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); | 151 exceptionState.throwSecurityError("access to the Indexed Database API is
denied in this context."); |
152 return 0; | 152 return nullptr; |
153 } | 153 } |
154 | 154 |
155 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, I
DBDatabaseMetadata::DefaultIntVersion); | 155 RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, nullptr
, 0, IDBDatabaseMetadata::DefaultIntVersion); |
156 | 156 |
157 if (!m_permissionClient->allowIndexedDB(context, name)) { | 157 if (!m_permissionClient->allowIndexedDB(context, name)) { |
158 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); | 158 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes
sage)); |
159 return request; | 159 return request; |
160 } | 160 } |
161 | 161 |
162 blink::Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbac
ksImpl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(co
ntext->securityOrigin())); | 162 blink::Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbac
ksImpl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(co
ntext->securityOrigin())); |
163 return request; | 163 return request; |
164 } | 164 } |
165 | 165 |
166 short IDBFactory::cmp(ExecutionContext* context, const ScriptValue& firstValue,
const ScriptValue& secondValue, ExceptionState& exceptionState) | 166 short IDBFactory::cmp(ExecutionContext* context, const ScriptValue& firstValue,
const ScriptValue& secondValue, ExceptionState& exceptionState) |
167 { | 167 { |
168 DOMRequestState requestState(context); | 168 DOMRequestState requestState(context); |
169 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); | 169 RefPtr<IDBKey> first = scriptValueToIDBKey(&requestState, firstValue); |
170 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); | 170 RefPtr<IDBKey> second = scriptValueToIDBKey(&requestState, secondValue); |
171 | 171 |
172 ASSERT(first); | 172 ASSERT(first); |
173 ASSERT(second); | 173 ASSERT(second); |
174 | 174 |
175 if (!first->isValid() || !second->isValid()) { | 175 if (!first->isValid() || !second->isValid()) { |
176 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 176 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
177 return 0; | 177 return 0; |
178 } | 178 } |
179 | 179 |
180 return static_cast<short>(first->compare(second.get())); | 180 return static_cast<short>(first->compare(second.get())); |
181 } | 181 } |
182 | 182 |
183 } // namespace WebCore | 183 } // namespace WebCore |
OLD | NEW |