Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/modules/indexeddb/IDBFactory.cpp

Issue 295163005: Remove ScriptState::current() from IDBRequest (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 static bool isContextValid(ExecutionContext* context) 72 static bool isContextValid(ExecutionContext* context)
73 { 73 {
74 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); 74 ASSERT(context->isDocument() || context->isWorkerGlobalScope());
75 if (context->isDocument()) { 75 if (context->isDocument()) {
76 Document* document = toDocument(context); 76 Document* document = toDocument(context);
77 return document->frame() && document->page(); 77 return document->frame() && document->page();
78 } 78 }
79 return true; 79 return true;
80 } 80 }
81 81
82 PassRefPtrWillBeRawPtr<IDBRequest> IDBFactory::getDatabaseNames(ExecutionContext * context, ExceptionState& exceptionState) 82 PassRefPtrWillBeRawPtr<IDBRequest> IDBFactory::getDatabaseNames(ScriptState* scr iptState, ExceptionState& exceptionState)
83 { 83 {
84 IDB_TRACE("IDBFactory::getDatabaseNames"); 84 IDB_TRACE("IDBFactory::getDatabaseNames");
85 if (!isContextValid(context)) 85 if (!isContextValid(scriptState->executionContext()))
86 return nullptr; 86 return nullptr;
87 if (!context->securityOrigin()->canAccessDatabase()) { 87 if (!scriptState->executionContext()->securityOrigin()->canAccessDatabase()) {
88 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 88 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
89 return nullptr; 89 return nullptr;
90 } 90 }
91 91
92 RefPtrWillBeRawPtr<IDBRequest> request = IDBRequest::create(context, IDBAny: :createNull(), 0); 92 RefPtrWillBeRawPtr<IDBRequest> request = IDBRequest::create(scriptState, IDB Any::createNull(), 0);
93 93
94 if (!m_permissionClient->allowIndexedDB(context, "Database Listing")) { 94 if (!m_permissionClient->allowIndexedDB(scriptState->executionContext(), "Da tabase Listing")) {
95 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes sage)); 95 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes sage));
96 return request; 96 return request;
97 } 97 }
98 98
99 blink::Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksIm pl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(contex t->securityOrigin())); 99 blink::Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksIm pl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(script State->executionContext()->securityOrigin()));
100 return request; 100 return request;
101 } 101 }
102 102
103 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* cont ext, const String& name, unsigned long long version, ExceptionState& exceptionSt ate) 103 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::open(ScriptState* scriptSta te, const String& name, unsigned long long version, ExceptionState& exceptionSta te)
104 { 104 {
105 IDB_TRACE("IDBFactory::open"); 105 IDB_TRACE("IDBFactory::open");
106 if (!version) { 106 if (!version) {
107 exceptionState.throwTypeError("The version provided must not be 0."); 107 exceptionState.throwTypeError("The version provided must not be 0.");
108 return nullptr; 108 return nullptr;
109 } 109 }
110 return openInternal(context, name, version, exceptionState); 110 return openInternal(scriptState, name, version, exceptionState);
111 } 111 }
112 112
113 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::openInternal(ExecutionConte xt* context, const String& name, int64_t version, ExceptionState& exceptionState ) 113 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptState* s criptState, const String& name, int64_t version, ExceptionState& exceptionState)
114 { 114 {
115 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd APICalls", IDBOpenCall, IDBMethodsMax); 115 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd APICalls", IDBOpenCall, IDBMethodsMax);
116 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion); 116 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion);
117 if (name.isNull()) { 117 if (name.isNull()) {
118 exceptionState.throwTypeError("The name provided must not be empty."); 118 exceptionState.throwTypeError("The name provided must not be empty.");
119 return nullptr; 119 return nullptr;
120 } 120 }
121 if (!isContextValid(context)) 121 if (!isContextValid(scriptState->executionContext()))
122 return nullptr; 122 return nullptr;
123 if (!context->securityOrigin()->canAccessDatabase()) { 123 if (!scriptState->executionContext()->securityOrigin()->canAccessDatabase()) {
124 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 124 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
125 return nullptr; 125 return nullptr;
126 } 126 }
127 127
128 RefPtrWillBeRawPtr<IDBDatabaseCallbacks> databaseCallbacks = IDBDatabaseCall backs::create(); 128 RefPtrWillBeRawPtr<IDBDatabaseCallbacks> databaseCallbacks = IDBDatabaseCall backs::create();
129 int64_t transactionId = IDBDatabase::nextTransactionId(); 129 int64_t transactionId = IDBDatabase::nextTransactionId();
130 RefPtrWillBeRawPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(cont ext, databaseCallbacks, transactionId, version); 130 RefPtrWillBeRawPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(scri ptState, databaseCallbacks, transactionId, version);
131 131
132 if (!m_permissionClient->allowIndexedDB(context, name)) { 132 if (!m_permissionClient->allowIndexedDB(scriptState->executionContext(), nam e)) {
133 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes sage)); 133 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes sage));
134 return request; 134 return request;
135 } 135 }
136 136
137 blink::Platform::current()->idbFactory()->open(name, version, transactionId, WebIDBCallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::cr eate(databaseCallbacks.release()).leakPtr(), createDatabaseIdentifierFromSecurit yOrigin(context->securityOrigin())); 137 blink::Platform::current()->idbFactory()->open(name, version, transactionId, WebIDBCallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::cr eate(databaseCallbacks.release()).leakPtr(), createDatabaseIdentifierFromSecurit yOrigin(scriptState->executionContext()->securityOrigin()));
138 return request; 138 return request;
139 } 139 }
140 140
141 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::open(ExecutionContext* cont ext, const String& name, ExceptionState& exceptionState) 141 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::open(ScriptState* scriptSta te, const String& name, ExceptionState& exceptionState)
142 { 142 {
143 IDB_TRACE("IDBFactory::open"); 143 IDB_TRACE("IDBFactory::open");
144 return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, except ionState); 144 return openInternal(scriptState, name, IDBDatabaseMetadata::NoIntVersion, ex ceptionState);
145 } 145 }
146 146
147 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ExecutionCon text* context, const String& name, ExceptionState& exceptionState) 147 PassRefPtrWillBeRawPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ScriptState* scriptState, const String& name, ExceptionState& exceptionState)
148 { 148 {
149 IDB_TRACE("IDBFactory::deleteDatabase"); 149 IDB_TRACE("IDBFactory::deleteDatabase");
150 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd APICalls", IDBDeleteDatabaseCall, IDBMethodsMax); 150 blink::Platform::current()->histogramEnumeration("WebCore.IndexedDB.FrontEnd APICalls", IDBDeleteDatabaseCall, IDBMethodsMax);
151 if (name.isNull()) { 151 if (name.isNull()) {
152 exceptionState.throwTypeError("The name provided must not be empty."); 152 exceptionState.throwTypeError("The name provided must not be empty.");
153 return nullptr; 153 return nullptr;
154 } 154 }
155 if (!isContextValid(context)) 155 if (!isContextValid(scriptState->executionContext()))
156 return nullptr; 156 return nullptr;
157 if (!context->securityOrigin()->canAccessDatabase()) { 157 if (!scriptState->executionContext()->securityOrigin()->canAccessDatabase()) {
158 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 158 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
159 return nullptr; 159 return nullptr;
160 } 160 }
161 161
162 RefPtrWillBeRawPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(cont ext, nullptr, 0, IDBDatabaseMetadata::DefaultIntVersion); 162 RefPtrWillBeRawPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(scri ptState, nullptr, 0, IDBDatabaseMetadata::DefaultIntVersion);
163 163
164 if (!m_permissionClient->allowIndexedDB(context, name)) { 164 if (!m_permissionClient->allowIndexedDB(scriptState->executionContext(), nam e)) {
165 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes sage)); 165 request->onError(DOMError::create(UnknownError, permissionDeniedErrorMes sage));
166 return request; 166 return request;
167 } 167 }
168 168
169 blink::Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbac ksImpl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(co ntext->securityOrigin())); 169 blink::Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbac ksImpl::create(request).leakPtr(), createDatabaseIdentifierFromSecurityOrigin(sc riptState->executionContext()->securityOrigin()));
170 return request; 170 return request;
171 } 171 }
172 172
173 short IDBFactory::cmp(ExecutionContext* context, const ScriptValue& firstValue, const ScriptValue& secondValue, ExceptionState& exceptionState) 173 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c onst ScriptValue& secondValue, ExceptionState& exceptionState)
174 { 174 {
175 RefPtrWillBeRawPtr<IDBKey> first = scriptValueToIDBKey(toIsolate(context), f irstValue); 175 RefPtrWillBeRawPtr<IDBKey> first = scriptValueToIDBKey(scriptState->isolate( ), firstValue);
176 RefPtrWillBeRawPtr<IDBKey> second = scriptValueToIDBKey(toIsolate(context), secondValue); 176 RefPtrWillBeRawPtr<IDBKey> second = scriptValueToIDBKey(scriptState->isolate (), secondValue);
177 177
178 ASSERT(first); 178 ASSERT(first);
179 ASSERT(second); 179 ASSERT(second);
180 180
181 if (!first->isValid() || !second->isValid()) { 181 if (!first->isValid() || !second->isValid()) {
182 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage); 182 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
183 return 0; 183 return 0;
184 } 184 }
185 185
186 return static_cast<short>(first->compare(second.get())); 186 return static_cast<short>(first->compare(second.get()));
187 } 187 }
188 188
189 } // namespace WebCore 189 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698