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

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: Some (incomplete) work on struct traits. Created 4 years, 5 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 17 matching lines...) Expand all
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/IDBDatabaseCallbacks.h"
38 #include "modules/indexeddb/IDBDatabaseObserver.h"
38 #include "modules/indexeddb/IDBKey.h" 39 #include "modules/indexeddb/IDBKey.h"
40 #include "modules/indexeddb/IDBOpenRequestObserver.h"
39 #include "modules/indexeddb/IDBTracing.h" 41 #include "modules/indexeddb/IDBTracing.h"
40 #include "modules/indexeddb/IndexedDBClient.h" 42 #include "modules/indexeddb/IndexedDBClient.h"
43 #include "modules/indexeddb/ResponseHandler.h"
41 #include "modules/indexeddb/WebIDBCallbacksImpl.h" 44 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
42 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" 45 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h"
43 #include "platform/Histogram.h" 46 #include "platform/Histogram.h"
44 #include "platform/weborigin/SecurityOrigin.h" 47 #include "platform/weborigin/SecurityOrigin.h"
45 #include "public/platform/Platform.h" 48 #include "public/platform/Platform.h"
46 #include "public/platform/WebSecurityOrigin.h" 49 #include "public/platform/WebSecurityOrigin.h"
47 #include "public/platform/modules/indexeddb/WebIDBFactory.h" 50
48 #include <memory> 51 using indexed_db::mojom::blink::IDBDatabaseObserverImpl;
52 using indexed_db::mojom::blink::IDBOpenRequestObserverImpl;
49 53
50 namespace blink { 54 namespace blink {
51 55
52 static const char permissionDeniedErrorMessage[] = "The user denied permission t o access the database."; 56 static const char permissionDeniedErrorMessage[] = "The user denied permission t o access the database.";
53 57
54 IDBFactory::IDBFactory() 58 IDBFactory::IDBFactory()
55 { 59 {
56 } 60 }
57 61
62 IDBFactory::~IDBFactory()
63 {
64 }
65
58 static bool isContextValid(ExecutionContext* context) 66 static bool isContextValid(ExecutionContext* context)
59 { 67 {
60 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); 68 ASSERT(context->isDocument() || context->isWorkerGlobalScope());
61 if (context->isDocument()) { 69 if (context->isDocument()) {
62 Document* document = toDocument(context); 70 Document* document = toDocument(context);
63 return document->frame() && document->page(); 71 return document->frame() && document->page();
64 } 72 }
65 return true; 73 return true;
66 } 74 }
67 75
68 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat e& exceptionState) 76 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat e& exceptionState)
69 { 77 {
70 IDB_TRACE("IDBFactory::getDatabaseNames"); 78 IDB_TRACE("IDBFactory::getDatabaseNames");
71 if (!isContextValid(scriptState->getExecutionContext())) 79 if (!isContextValid(scriptState->getExecutionContext()))
72 return nullptr; 80 return nullptr;
73 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 81 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
74 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 82 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
75 return nullptr; 83 return nullptr;
76 } 84 }
77 85
78 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(), nullptr); 86 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(), nullptr);
79 87
80 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), "Database Listing")) { 88 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), "Database Listing")) {
81 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 89 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
82 return request; 90 return request;
83 } 91 }
84 92
85 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre ate(request).release(), WebSecurityOrigin(scriptState->getExecutionContext()->ge tSecurityOrigin())); 93 m_backend->GetDatabaseNames(scriptState->getExecutionContext()->getSecurityO rigin());
86 return request; 94 return request;
87 } 95 }
88 96
89 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, unsigned long long version, ExceptionState& exceptionState) 97 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, unsigned long long version, ExceptionState& exceptionState)
90 { 98 {
91 IDB_TRACE("IDBFactory::open"); 99 IDB_TRACE("IDBFactory::open");
92 if (!version) { 100 if (!version) {
93 exceptionState.throwTypeError("The version provided must not be 0."); 101 exceptionState.throwTypeError("The version provided must not be 0.");
94 return nullptr; 102 return nullptr;
95 } 103 }
(...skipping 13 matching lines...) Expand all
109 117
110 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create(); 118 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create();
111 int64_t transactionId = IDBDatabase::nextTransactionId(); 119 int64_t transactionId = IDBDatabase::nextTransactionId();
112 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa llbacks, transactionId, version); 120 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa llbacks, transactionId, version);
113 121
114 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) { 122 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) {
115 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 123 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
116 return request; 124 return request;
117 } 125 }
118 126
119 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB CallbacksImpl::create(request).release(), WebIDBDatabaseCallbacksImpl::create(da tabaseCallbacks).release(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin())); 127 m_backend->Open(name, version, transactionId, scriptState->getExecutionConte xt()->getSecurityOrigin(), IDBOpenRequestObserverImpl::Create(), IDBDatabaseObse rverImpl::Create(), ResponseHandler::createOpenCallback(request));
120 return request; 128 return request;
121 } 129 }
122 130
123 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, ExceptionState& exceptionState) 131 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, ExceptionState& exceptionState)
124 { 132 {
125 IDB_TRACE("IDBFactory::open"); 133 IDB_TRACE("IDBFactory::open");
126 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep tionState); 134 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep tionState);
127 } 135 }
128 136
129 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str ing& name, ExceptionState& exceptionState) 137 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str ing& name, ExceptionState& exceptionState)
130 { 138 {
131 IDB_TRACE("IDBFactory::deleteDatabase"); 139 IDB_TRACE("IDBFactory::deleteDatabase");
132 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); 140 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall);
133 if (!isContextValid(scriptState->getExecutionContext())) 141 if (!isContextValid(scriptState->getExecutionContext()))
134 return nullptr; 142 return nullptr;
135 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 143 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
136 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 144 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
137 return nullptr; 145 return nullptr;
138 } 146 }
139 147
140 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0 , IDBDatabaseMetadata::DefaultVersion); 148 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0 , IDBDatabaseMetadata::DefaultVersion);
141 149
142 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) { 150 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) {
143 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 151 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
144 return request; 152 return request;
145 } 153 }
146 154
147 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl: :create(request).release(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin())); 155 m_backend->DeleteDatabase(name, scriptState->getExecutionContext()->getSecur ityOrigin());
148 return request; 156 return request;
149 } 157 }
150 158
151 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c onst ScriptValue& secondValue, ExceptionState& exceptionState) 159 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c onst ScriptValue& secondValue, ExceptionState& exceptionState)
152 { 160 {
153 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue, exceptionState); 161 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue, exceptionState);
154 if (exceptionState.hadException()) 162 if (exceptionState.hadException())
155 return 0; 163 return 0;
156 ASSERT(first); 164 ASSERT(first);
157 if (!first->isValid()) { 165 if (!first->isValid()) {
158 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage); 166 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
159 return 0; 167 return 0;
160 } 168 }
161 169
162 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu e, exceptionState); 170 IDBKey* second = ScriptValue::to<IDBKey*>(scriptState->isolate(), secondValu e, exceptionState);
163 if (exceptionState.hadException()) 171 if (exceptionState.hadException())
164 return 0; 172 return 0;
165 ASSERT(second); 173 ASSERT(second);
166 if (!second->isValid()) { 174 if (!second->isValid()) {
167 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage); 175 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
168 return 0; 176 return 0;
169 } 177 }
170 178
171 return static_cast<short>(first->compare(second)); 179 return static_cast<short>(first->compare(second));
172 } 180 }
173 181
174 } // namespace blink 182 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698