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 #include "ImmutableArray.h"
30 #include "ImmutableDictionary.h"
31 #include "WebDatabaseManagerMessages.h"
32 #include "WebContext.h"
33 #include "WebSecurityOrigin.h"
35 using namespace WebCore;
39 String WebDatabaseManagerProxy::originKey()
41 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerOriginKey"));
45 String WebDatabaseManagerProxy::originQuotaKey()
47 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerOriginQuotaKey"));
51 String WebDatabaseManagerProxy::originUsageKey()
53 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerOriginUsageKey"));
57 String WebDatabaseManagerProxy::databaseDetailsKey()
59 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsKey"));
63 String WebDatabaseManagerProxy::databaseDetailsNameKey()
65 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsNameKey"));
69 String WebDatabaseManagerProxy::databaseDetailsDisplayNameKey()
71 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsDisplayNameKey"));
75 String WebDatabaseManagerProxy::databaseDetailsExpectedUsageKey()
77 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsExpectedUsageKey"));
81 String WebDatabaseManagerProxy::databaseDetailsCurrentUsageKey()
83 DEFINE_STATIC_LOCAL(String, key, ("WebDatabaseManagerDatabaseDetailsCurrentUsageKey"));
87 PassRefPtr<WebDatabaseManagerProxy> WebDatabaseManagerProxy::create(WebContext* webContext)
89 return adoptRef(new WebDatabaseManagerProxy(webContext));
92 WebDatabaseManagerProxy::WebDatabaseManagerProxy(WebContext* webContext)
93 : m_webContext(webContext)
97 WebDatabaseManagerProxy::~WebDatabaseManagerProxy()
101 void WebDatabaseManagerProxy::invalidate()
103 invalidateCallbackMap(m_arrayCallbacks);
106 bool WebDatabaseManagerProxy::shouldTerminate(WebProcessProxy*) const
108 return m_arrayCallbacks.isEmpty();
111 void WebDatabaseManagerProxy::initializeClient(const WKDatabaseManagerClient* client)
113 m_client.initialize(client);
116 void WebDatabaseManagerProxy::getDatabasesByOrigin(PassRefPtr<ArrayCallback> prpCallback)
118 RefPtr<ArrayCallback> callback = prpCallback;
119 uint64_t callbackID = callback->callbackID();
120 m_arrayCallbacks.set(callbackID, callback.release());
122 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
123 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::GetDatabasesByOrigin(callbackID));
126 void WebDatabaseManagerProxy::didGetDatabasesByOrigin(const Vector<OriginAndDatabases>& originAndDatabasesVector, uint64_t callbackID)
128 RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID);
130 // FIXME: Log error or assert.
134 size_t originAndDatabasesCount = originAndDatabasesVector.size();
135 Vector<RefPtr<APIObject> > result(originAndDatabasesCount);
137 for (size_t i = 0; i < originAndDatabasesCount; ++i) {
138 const OriginAndDatabases& originAndDatabases = originAndDatabasesVector[i];
140 RefPtr<APIObject> origin = WebSecurityOrigin::create(originAndDatabases.originIdentifier);
142 size_t databasesCount = originAndDatabases.databases.size();
143 Vector<RefPtr<APIObject> > databases(databasesCount);
145 for (size_t j = 0; j < databasesCount; ++j) {
146 const DatabaseDetails& details = originAndDatabases.databases[i];
147 HashMap<String, RefPtr<APIObject> > detailsMap;
149 detailsMap.set(databaseDetailsNameKey(), WebString::create(details.name()));
150 detailsMap.set(databaseDetailsDisplayNameKey(), WebString::create(details.displayName()));
151 detailsMap.set(databaseDetailsExpectedUsageKey(), WebUInt64::create(details.expectedUsage()));
152 detailsMap.set(databaseDetailsCurrentUsageKey(), WebUInt64::create(details.currentUsage()));
153 databases.append(ImmutableDictionary::adopt(detailsMap));
156 HashMap<String, RefPtr<APIObject> > originAndDatabasesMap;
157 originAndDatabasesMap.set(originKey(), origin);
158 originAndDatabasesMap.set(originQuotaKey(), WebUInt64::create(originAndDatabases.originQuota));
159 originAndDatabasesMap.set(originUsageKey(), WebUInt64::create(originAndDatabases.originUsage));
160 originAndDatabasesMap.set(databaseDetailsKey(), ImmutableArray::adopt(databases));
162 result.append(ImmutableDictionary::adopt(originAndDatabasesMap));
165 RefPtr<ImmutableArray> resultArray = ImmutableArray::adopt(result);
166 callback->performCallbackWithReturnValue(resultArray.get());
169 void WebDatabaseManagerProxy::getDatabaseOrigins(PassRefPtr<ArrayCallback> prpCallback)
171 RefPtr<ArrayCallback> callback = prpCallback;
172 uint64_t callbackID = callback->callbackID();
173 m_arrayCallbacks.set(callbackID, callback.release());
175 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
176 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::GetDatabaseOrigins(callbackID));
179 void WebDatabaseManagerProxy::didGetDatabaseOrigins(const Vector<String>& originIdentifiers, uint64_t callbackID)
181 RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID);
183 // FIXME: Log error or assert.
187 size_t originIdentifiersCount = originIdentifiers.size();
188 Vector<RefPtr<APIObject> > securityOrigins(originIdentifiersCount);
190 for (size_t i = 0; i < originIdentifiersCount; ++i)
191 securityOrigins[i] = WebSecurityOrigin::create(originIdentifiers[i]);
193 callback->performCallbackWithReturnValue(ImmutableArray::adopt(securityOrigins).get());
196 void WebDatabaseManagerProxy::deleteDatabaseWithNameForOrigin(const String& databaseIdentifier, WebSecurityOrigin* origin)
198 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
199 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::DeleteDatabaseWithNameForOrigin(databaseIdentifier, origin->databaseIdentifier()));
202 void WebDatabaseManagerProxy::deleteDatabasesForOrigin(WebSecurityOrigin* origin)
204 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
205 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::DeleteDatabasesForOrigin(origin->databaseIdentifier()));
208 void WebDatabaseManagerProxy::deleteAllDatabases()
210 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
211 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::DeleteAllDatabases());
214 void WebDatabaseManagerProxy::setQuotaForOrigin(WebSecurityOrigin* origin, uint64_t quota)
216 // FIXME (Multi-WebProcess): Databases shouldn't be stored in the web process.
217 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebDatabaseManager::SetQuotaForOrigin(origin->databaseIdentifier(), quota));
220 void WebDatabaseManagerProxy::didModifyOrigin(const String& originIdentifier)
222 RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier);
223 m_client.didModifyOrigin(this, origin.get());
226 void WebDatabaseManagerProxy::didModifyDatabase(const String& originIdentifier, const String& databaseIdentifier)
228 RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier);
229 m_client.didModifyDatabase(this, origin.get(), databaseIdentifier);
232 } // namespace WebKit