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