1/* 2 * Copyright (C) 2010, 2013 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26#ifndef WebDatabaseManagerProxy_h 27#define WebDatabaseManagerProxy_h 28 29#if ENABLE(SQL_DATABASE) 30 31#include "APIObject.h" 32#include "Arguments.h" 33#include "GenericCallback.h" 34#include "MessageReceiver.h" 35#include "OriginAndDatabases.h" 36#include "WebContextSupplement.h" 37#include "WebDatabaseManagerProxyClient.h" 38#include <wtf/HashMap.h> 39#include <wtf/PassRefPtr.h> 40 41namespace WebKit { 42 43class WebContext; 44class WebProcessProxy; 45class WebSecurityOrigin; 46 47typedef GenericCallback<API::Array*> ArrayCallback; 48 49class WebDatabaseManagerProxy : public API::ObjectImpl<API::Object::Type::DatabaseManager>, public WebContextSupplement, private IPC::MessageReceiver { 50public: 51 static const char* supplementName(); 52 53 static PassRefPtr<WebDatabaseManagerProxy> create(WebContext*); 54 virtual ~WebDatabaseManagerProxy(); 55 56 void initializeClient(const WKDatabaseManagerClientBase*); 57 58 void getDatabasesByOrigin(std::function<void (API::Array*, CallbackBase::Error)>); 59 void getDatabaseOrigins(std::function<void (API::Array*, CallbackBase::Error)>); 60 void deleteDatabaseWithNameForOrigin(const String& databaseIdentifier, WebSecurityOrigin*); 61 void deleteDatabasesForOrigin(WebSecurityOrigin*); 62 void deleteAllDatabases(); 63 void setQuotaForOrigin(WebSecurityOrigin*, uint64_t quota); 64 65 static String originKey(); 66 static String originQuotaKey(); 67 static String originUsageKey(); 68 static String databaseDetailsKey(); 69 static String databaseDetailsNameKey(); 70 static String databaseDetailsDisplayNameKey(); 71 static String databaseDetailsExpectedUsageKey(); 72 static String databaseDetailsCurrentUsageKey(); 73 static String databaseDetailsCreationTimeKey(); 74 static String databaseDetailsModificationTimeKey(); 75 76 using API::Object::ref; 77 using API::Object::deref; 78 79private: 80 explicit WebDatabaseManagerProxy(WebContext*); 81 82 // WebContextSupplement 83 virtual void contextDestroyed() override; 84 virtual void processDidClose(WebProcessProxy*) override; 85 virtual bool shouldTerminate(WebProcessProxy*) const override; 86 virtual void refWebContextSupplement() override; 87 virtual void derefWebContextSupplement() override; 88 89 // IPC::MessageReceiver 90 virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; 91 92 // Message handlers. 93 void didGetDatabasesByOrigin(const Vector<OriginAndDatabases>& originAndDatabases, uint64_t callbackID); 94 void didGetDatabaseOrigins(const Vector<String>& originIdentifiers, uint64_t callbackID); 95 void didModifyOrigin(const String& originIdentifier); 96 void didModifyDatabase(const String& originIdentifier, const String& databaseIdentifier); 97 98 HashMap<uint64_t, RefPtr<ArrayCallback>> m_arrayCallbacks; 99 WebDatabaseManagerProxyClient m_client; 100}; 101 102} // namespace WebKit 103 104#endif // ENABLE(SQL_DATABASE) 105 106#endif // DatabaseManagerProxy_h 107