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

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

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring after Passing URLRequestContextGetter. Created 4 years, 4 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
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 16 matching lines...) Expand all
27 */ 27 */
28 28
29 #include "modules/indexeddb/IDBFactory.h" 29 #include "modules/indexeddb/IDBFactory.h"
30 30
31 #include "bindings/core/v8/ExceptionState.h" 31 #include "bindings/core/v8/ExceptionState.h"
32 #include "bindings/modules/v8/V8BindingForModules.h" 32 #include "bindings/modules/v8/V8BindingForModules.h"
33 #include "core/dom/DOMException.h" 33 #include "core/dom/DOMException.h"
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/ExceptionCode.h" 35 #include "core/dom/ExceptionCode.h"
36 #include "modules/indexeddb/IDBDatabase.h" 36 #include "modules/indexeddb/IDBDatabase.h"
37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" 37 #include "modules/indexeddb/IDBDatabaseObserverImpl.h"
38 #include "modules/indexeddb/IDBKey.h" 38 #include "modules/indexeddb/IDBKey.h"
39 #include "modules/indexeddb/IDBTracing.h" 39 #include "modules/indexeddb/IDBTracing.h"
40 #include "modules/indexeddb/IndexedDBClient.h" 40 #include "modules/indexeddb/IndexedDBClient.h"
41 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
42 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h"
43 #include "platform/Histogram.h" 41 #include "platform/Histogram.h"
44 #include "platform/weborigin/SecurityOrigin.h" 42 #include "platform/weborigin/SecurityOrigin.h"
43 #include "public/platform/InterfaceProvider.h"
45 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
46 #include "public/platform/WebSecurityOrigin.h" 45 #include "public/platform/WebSecurityOrigin.h"
47 #include "public/platform/modules/indexeddb/WebIDBFactory.h"
48 #include <memory>
49 46
50 namespace blink { 47 namespace blink {
51 48
52 static const char permissionDeniedErrorMessage[] = "The user denied permission t o access the database."; 49 static const char permissionDeniedErrorMessage[] = "The user denied permission t o access the database.";
53 50
54 IDBFactory::IDBFactory() 51 IDBFactory::IDBFactory()
55 { 52 {
53 // TODO(cmumford): I'm sure this can fail.
54 // TODO(cmumford): Should we connect (lazily) once and share the Mojo
55 // factory between all IDBFactory's?
56 Platform::current()->interfaceProvider()->getInterface(mojo::GetProxy(&m_pro xy));
57 DCHECK(m_proxy);
58 }
59
60 IDBFactory::~IDBFactory()
61 {
56 } 62 }
57 63
58 static bool isContextValid(ExecutionContext* context) 64 static bool isContextValid(ExecutionContext* context)
59 { 65 {
60 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); 66 ASSERT(context->isDocument() || context->isWorkerGlobalScope());
61 if (context->isDocument()) { 67 if (context->isDocument()) {
62 Document* document = toDocument(context); 68 Document* document = toDocument(context);
63 return document->frame() && document->page(); 69 return document->frame() && document->page();
64 } 70 }
65 return true; 71 return true;
66 } 72 }
67 73
68 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat e& exceptionState) 74 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat e& exceptionState)
69 { 75 {
70 IDB_TRACE("IDBFactory::getDatabaseNames"); 76 IDB_TRACE("IDBFactory::getDatabaseNames");
71 if (!isContextValid(scriptState->getExecutionContext())) 77 if (!isContextValid(scriptState->getExecutionContext()))
72 return nullptr; 78 return nullptr;
73 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 79 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
74 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 80 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
75 return nullptr; 81 return nullptr;
76 } 82 }
77 83
78 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(), nullptr); 84 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(), nullptr);
79 85
80 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), "Database Listing")) { 86 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), "Database Listing")) {
81 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 87 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
82 return request; 88 return request;
83 } 89 }
84 90
85 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre ate(request).release(), WebSecurityOrigin(scriptState->getExecutionContext()->ge tSecurityOrigin())); 91 m_proxy->GetDatabaseNames(scriptState->getExecutionContext()->getSecurityOri gin());
86 return request; 92 return request;
87 } 93 }
88 94
89 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, unsigned long long version, ExceptionState& exceptionState) 95 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, unsigned long long version, ExceptionState& exceptionState)
90 { 96 {
91 IDB_TRACE("IDBFactory::open"); 97 IDB_TRACE("IDBFactory::open");
92 if (!version) { 98 if (!version) {
93 exceptionState.throwTypeError("The version provided must not be 0."); 99 exceptionState.throwTypeError("The version provided must not be 0.");
94 return nullptr; 100 return nullptr;
95 } 101 }
96 return openInternal(scriptState, name, version, exceptionState); 102 return openInternal(scriptState, name, version, exceptionState);
97 } 103 }
98 104
99 IDBOpenDBRequest* IDBFactory::openInternal(ScriptState* scriptState, const Strin g& name, int64_t version, ExceptionState& exceptionState) 105 IDBOpenDBRequest* IDBFactory::openInternal(ScriptState* scriptState, const Strin g& name, int64_t version, ExceptionState& exceptionState)
100 { 106 {
101 IDBDatabase::recordApiCallsHistogram(IDBOpenCall); 107 IDBDatabase::recordApiCallsHistogram(IDBOpenCall);
102 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoVersion); 108 ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoVersion);
103 if (!isContextValid(scriptState->getExecutionContext())) 109 if (!isContextValid(scriptState->getExecutionContext()))
104 return nullptr; 110 return nullptr;
105 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 111 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
106 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 112 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
107 return nullptr; 113 return nullptr;
108 } 114 }
109 115
110 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create();
111 int64_t transactionId = IDBDatabase::nextTransactionId(); 116 int64_t transactionId = IDBDatabase::nextTransactionId();
112 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa llbacks, transactionId, version); 117 indexed_db::mojom::blink::OpenRequestObserverPtr openRequestObserver;
118 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, transactio nId, version, GetProxy(&openRequestObserver));
119 indexed_db::mojom::blink::DatabaseObserverPtr databaseObserver = IDBDatabase ObserverImpl::Create(request);
113 120
114 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) { 121 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) {
115 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 122 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
116 return request; 123 return request;
117 } 124 }
118 125
119 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB CallbacksImpl::create(request).release(), WebIDBDatabaseCallbacksImpl::create(da tabaseCallbacks).release(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin())); 126 indexed_db::mojom::blink::DatabaseFactory::OpenCallback openCallback = conve rtToBaseCallback(WTF::bind(&IDBOpenDBRequest::onOpenResult, wrapWeakPersistent(r equest)));
127
128 m_proxy->Open(name, version, transactionId, scriptState->getExecutionContext ()->getSecurityOrigin(), std::move(openRequestObserver), std::move(databaseObser ver), openCallback);
120 return request; 129 return request;
121 } 130 }
122 131
123 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, ExceptionState& exceptionState) 132 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, ExceptionState& exceptionState)
124 { 133 {
125 IDB_TRACE("IDBFactory::open"); 134 IDB_TRACE("IDBFactory::open");
126 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep tionState); 135 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep tionState);
127 } 136 }
128 137
129 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str ing& name, ExceptionState& exceptionState) 138 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str ing& name, ExceptionState& exceptionState)
130 { 139 {
131 IDB_TRACE("IDBFactory::deleteDatabase"); 140 IDB_TRACE("IDBFactory::deleteDatabase");
132 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); 141 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall);
133 if (!isContextValid(scriptState->getExecutionContext())) 142 if (!isContextValid(scriptState->getExecutionContext()))
134 return nullptr; 143 return nullptr;
135 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 144 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
136 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 145 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
137 return nullptr; 146 return nullptr;
138 } 147 }
139 148
140 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0 , IDBDatabaseMetadata::DefaultVersion); 149 indexed_db::mojom::blink::OpenRequestObserverPtr openRequestObserver;
150 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, 0, IDBData baseMetadata::DefaultVersion, GetProxy(&openRequestObserver));
141 151
142 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) { 152 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) {
143 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 153 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
144 return request; 154 return request;
145 } 155 }
146 156
147 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl: :create(request).release(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin())); 157 m_proxy->DeleteDatabase(name, scriptState->getExecutionContext()->getSecurit yOrigin());
148 return request; 158 return request;
149 } 159 }
150 160
151 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c onst ScriptValue& secondValue, ExceptionState& exceptionState) 161 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c onst ScriptValue& secondValue, ExceptionState& exceptionState)
152 { 162 {
153 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue, exceptionState); 163 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue, exceptionState);
154 if (exceptionState.hadException()) 164 if (exceptionState.hadException())
155 return 0; 165 return 0;
156 ASSERT(first); 166 ASSERT(first);
157 if (!first->isValid()) { 167 if (!first->isValid()) {
158 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage); 168 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
159 return 0; 169 return 0;
160 } 170 }
161 171
162 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu e, exceptionState); 172 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu e, exceptionState);
163 if (exceptionState.hadException()) 173 if (exceptionState.hadException())
164 return 0; 174 return 0;
165 ASSERT(second); 175 ASSERT(second);
166 if (!second->isValid()) { 176 if (!second->isValid()) {
167 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage); 177 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
168 return 0; 178 return 0;
169 } 179 }
170 180
171 return static_cast<short>(first->compare(second)); 181 return static_cast<short>(first->compare(second));
172 } 182 }
173 183
174 } // namespace blink 184 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/indexeddb/IDBFactory.h ('k') | third_party/WebKit/Source/modules/indexeddb/IDBIndex.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698