2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebDatabaseManagerProxy.h"
29 #if ENABLE(SQL_DATABASE)
31 #include "ImmutableArray.h"
32 #include "ImmutableDictionary.h"
33 #include "WebDatabaseManagerMessages.h"
34 #include "WebContext.h"
35 #include "WebSecurityOrigin.h"
37 using namespace WebCore;
41 String WebDatabaseManagerProxy::originKey()
43 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerOriginKey"));
47 String WebDatabaseManagerProxy::originQuotaKey()
49 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerOriginQuotaKey"));
53 String WebDatabaseManagerProxy::originUsageKey()
55 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerOriginUsageKey"));
59 String WebDatabaseManagerProxy::databaseDetailsKey()
61 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsKey"));
65 String WebDatabaseManagerProxy::databaseDetailsNameKey()
67 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsNameKey"));
71 String WebDatabaseManagerProxy::databaseDetailsDisplayNameKey()
73 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsDisplayNameKey"));
77 String WebDatabaseManagerProxy::databaseDetailsExpectedUsageKey()
79 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsExpectedUsageKey"));
83 String WebDatabaseManagerProxy::databaseDetailsCurrentUsageKey()
85 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsCurrentUsageKey"));
89 PassRefPtr<WebDatabaseManagerProxy> WebDatabaseManagerProxy::create(WebContext* webContext)
91 return adoptRef(new WebDatabaseManagerProxy(webContext));
94 WebDatabaseManagerProxy::WebDatabaseManagerProxy(WebContext* webContext)
95 : m_webContext(webContext)
99 WebDatabaseManagerProxy::~WebDatabaseManagerProxy()
103 void WebDatabaseManagerProxy::invalidate()
105 invalidateCallbackMap(m_arrayCallbacks);
108 bool WebDatabaseManagerProxy::shouldTerminate(WebProcessProxy*) const
110 return m_arrayCallbacks.isEmpty();
113 void WebDatabaseManagerProxy::initializeClient(const WKDatabaseManagerClient* client)
115 m_client.initialize(client);
118 void WebDatabaseManagerProxy::getDatabasesByOrigin(PassRefPtr<ArrayCallback> prpCallback)
120 RefPtr<ArrayCallback> callback = prpCallback;
121 uint64_t callbackID = callback->callbackID();
122 m_arrayCallbacks.set(callbackID, callback.release());
124 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
125 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::GetDatabasesByOrigin(callbackID));
128 void WebDatabaseManagerProxy::didGetDatabasesByOrigin(const Vector<OriginAndDatabases>& originAndDatabasesVector, uint64_t callbackID)
130 RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID);
132 // FIXME: Log error or assert.
136 size_t originAndDatabasesCount = originAndDatabasesVector.size();
137 Vector<RefPtr<APIObject> > result(originAndDatabasesCount);
139 for (size_t i = 0; i < originAndDatabasesCount; ++i) {
140 const OriginAndDatabases& originAndDatabases = originAndDatabasesVector[i];
142 RefPtr<APIObject> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originAndDatabases.originIdentifier);
144 size_t databasesCount = originAndDatabases.databases.size();
145 Vector<RefPtr<APIObject> > databases(databasesCount);
147 for (size_t j = 0; j < databasesCount; ++j) {
148 const DatabaseDetails& details = originAndDatabases.databases[i];
149 HashMap<String, RefPtr<APIObject> > detailsMap;
151 detailsMap.set(databaseDetailsNameKey(), WebString::create(details.name()));
152 detailsMap.set(databaseDetailsDisplayNameKey(), WebString::create(details.displayName()));
153 detailsMap.set(databaseDetailsExpectedUsageKey(), WebUInt64::create(details.expectedUsage()));
154 detailsMap.set(databaseDetailsCurrentUsageKey(), WebUInt64::create(details.currentUsage()));
155 databases.append(ImmutableDictionary::adopt(detailsMap));
158 HashMap<String, RefPtr<APIObject> > originAndDatabasesMap;
159 originAndDatabasesMap.set(originKey(), origin);
160 originAndDatabasesMap.set(originQuotaKey(), WebUInt64::create(originAndDatabases.originQuota));
161 originAndDatabasesMap.set(originUsageKey(), WebUInt64::create(originAndDatabases.originUsage));
162 originAndDatabasesMap.set(databaseDetailsKey(), ImmutableArray::adopt(databases));
164 result.append(ImmutableDictionary::adopt(originAndDatabasesMap));
167 RefPtr<ImmutableArray> resultArray = ImmutableArray::adopt(result);
168 callback->performCallbackWithReturnValue(resultArray.get());
171 void WebDatabaseManagerProxy::getDatabaseOrigins(PassRefPtr<ArrayCallback> prpCallback)
173 RefPtr<ArrayCallback> callback = prpCallback;
174 uint64_t callbackID = callback->callbackID();
175 m_arrayCallbacks.set(callbackID, callback.release());
177 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
178 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::GetDatabaseOrigins(callbackID));
181 void WebDatabaseManagerProxy::didGetDatabaseOrigins(const Vector<String>& originIdentifiers, uint64_t callbackID)
183 RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID);
185 // FIXME: Log error or assert.
189 size_t originIdentifiersCount = originIdentifiers.size();
190 Vector<RefPtr<APIObject> > securityOrigins(originIdentifiersCount);
192 for (size_t i = 0; i < originIdentifiersCount; ++i)
193 securityOrigins[i] = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifiers[i]);
195 callback->performCallbackWithReturnValue(ImmutableArray::adopt(securityOrigins).get());
198 void WebDatabaseManagerProxy::deleteDatabaseWithNameForOrigin(const String& databaseIdentifier, WebSecurityOrigin* origin)
200 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
201 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::DeleteDatabaseWithNameForOrigin(databaseIdentifier, origin->databaseIdentifier()));
204 void WebDatabaseManagerProxy::deleteDatabasesForOrigin(WebSecurityOrigin* origin)
206 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
207 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::DeleteDatabasesForOrigin(origin->databaseIdentifier()));
210 void WebDatabaseManagerProxy::deleteAllDatabases()
212 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
213 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::DeleteAllDatabases());
216 #if ENABLE(TIZEN_SQL_DATABASE)
217 void WebDatabaseManagerProxy::getDatabasePath(PassRefPtr<DatabaseStringCallback> prpCallback)
219 RefPtr<DatabaseStringCallback> callback = prpCallback;
220 uint64_t callbackID = callback->callbackID();
221 m_databaseStringCallbacks.set(callbackID, callback.release());
223 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
224 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::GetDatabasePath(callbackID));
227 void WebDatabaseManagerProxy::didGetDatabasePath(const String& path, uint64_t callbackID)
229 RefPtr<DatabaseStringCallback> callback = m_databaseStringCallbacks.take(callbackID);
231 // FIXME: Log error or assert.
235 m_databaseStringCallbacks.remove(callbackID);
236 callback->performCallbackWithReturnValue(path.impl());
239 void WebDatabaseManagerProxy::getQuotaForOrigin(PassRefPtr<DatabaseUInt64Callback> prpCallback, WebSecurityOrigin* origin)
241 RefPtr<DatabaseUInt64Callback> callback = prpCallback;
242 uint64_t callbackID = callback->callbackID();
243 m_databaseUInt64Callbacks.set(callbackID, callback.release());
245 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
246 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::GetQuotaForOrigin(callbackID, origin->databaseIdentifier()));
249 void WebDatabaseManagerProxy::didGetQuotaForOrigin(const uint64_t quota, uint64_t callbackID)
251 RefPtr<DatabaseUInt64Callback> callback = m_databaseUInt64Callbacks.take(callbackID);
253 // FIXME: Log error or assert.
257 m_databaseUInt64Callbacks.remove(callbackID);
258 callback->performCallbackWithReturnValue(WebUInt64::create(quota).leakRef());
261 void WebDatabaseManagerProxy::getUsageForOrigin(PassRefPtr<DatabaseUInt64Callback> prpCallback, WebSecurityOrigin* origin)
263 RefPtr<DatabaseUInt64Callback> callback = prpCallback;
264 uint64_t callbackID = callback->callbackID();
265 m_databaseUInt64Callbacks.set(callbackID, callback.release());
267 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
268 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::GetUsageForOrigin(callbackID, origin->databaseIdentifier()));
271 void WebDatabaseManagerProxy::didGetUsageForOrigin(const uint64_t usage, uint64_t callbackID)
273 RefPtr<DatabaseUInt64Callback> callback = m_databaseUInt64Callbacks.take(callbackID);
275 // FIXME: Log error or assert.
279 callback->performCallbackWithReturnValue(WebUInt64::create(usage).leakRef());
283 void WebDatabaseManagerProxy::setQuotaForOrigin(WebSecurityOrigin* origin, uint64_t quota)
285 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
286 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::SetQuotaForOrigin(origin->databaseIdentifier(), quota));
289 void WebDatabaseManagerProxy::didModifyOrigin(const String& originIdentifier)
291 RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
292 m_client.didModifyOrigin(this, origin.get());
295 void WebDatabaseManagerProxy::didModifyDatabase(const String& originIdentifier, const String& databaseIdentifier)
297 RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
298 m_client.didModifyDatabase(this, origin.get(), databaseIdentifier);
301 } // namespace WebKit
303 #endif // ENABLE(SQL_DATABASE)