Commit 36867044 authored by beidson@apple.com's avatar beidson@apple.com
Browse files

DatabaseProcess: Add "UniqueIDBDatabase" that multiple WebProcesses can connect to

https://bugs.webkit.org/show_bug.cgi?id=124819

Reviewed by Dan Bernstein.

Source/WebCore:

* Modules/indexeddb/IDBDatabaseBackend.cpp:
(WebCore::IDBDatabaseBackend::~IDBDatabaseBackend): Unregister from the IDBFactory.

Source/WebKit2:

UniqueIDBDatabase instances are per-DatabaseProcess, so it manages the set of them.
* DatabaseProcess/DatabaseProcess.cpp:
(WebKit::DatabaseProcess::getOrCreateUniqueIDBDatabase):
(WebKit::DatabaseProcess::removeUniqueIDBDatabase):
* DatabaseProcess/DatabaseProcess.h:

* DatabaseProcess/DatabaseToWebProcessConnection.h:

Start forwarding things along to the appropriate UniqueIDBDatabase.
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
(WebKit::DatabaseProcessIDBConnection::~DatabaseProcessIDBConnection):
(WebKit::DatabaseProcessIDBConnection::disconnectedFromWebProcess):
(WebKit::DatabaseProcessIDBConnection::establishConnection):
(WebKit::DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata):
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:

A class that represents a single concrete IDB database that multiple WebProcesses can connect to.
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::UniqueIDBDatabase):
(WebKit::UniqueIDBDatabase::~UniqueIDBDatabase):
(WebKit::UniqueIDBDatabase::registerConnection):
(WebKit::UniqueIDBDatabase::unregisterConnection):
(WebKit::UniqueIDBDatabase::getIDBDatabaseMetadata):
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
(WebKit::UniqueIDBDatabase::create):
(WebKit::UniqueIDBDatabase::identifier):

A class to help uniquely identify an IDBDatabase that can be expanded as needed.
Importantly, it knows how to be used as a key in a HashMap.
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.cpp: Added.
(WebKit::UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier):
(WebKit::UniqueIDBDatabaseIdentifier::isHashTableDeletedValue):
(WebKit::UniqueIDBDatabaseIdentifier::hash):
(WebKit::UniqueIDBDatabaseIdentifier::isNull):
(WebKit::operator==):
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.h: Added.
(WebKit::UniqueIDBDatabaseIdentifier::databaseName):
(WebKit::UniqueIDBDatabaseIdentifier::openingOrigin):
(WebKit::UniqueIDBDatabaseIdentifier::mainFrameOrigin):
(WebKit::UniqueIDBDatabaseIdentifierHash::hash):
(WebKit::UniqueIDBDatabaseIdentifierHash::equal):
(WebKit::UniqueIDBDatabaseIdentifierHashTraits::isEmptyValue):

* Shared/SecurityOriginData.cpp:
(WebKit::operator==):
* Shared/SecurityOriginData.h:

* UIProcess/WebContext.cpp:

* WebProcess/Databases/IndexedDB/WebIDBFactoryBackend.cpp:
(WebKit::WebIDBFactoryBackend::open):
(WebKit::WebIDBFactoryBackend::removeIDBDatabaseBackend):

* WebKit2.xcodeproj/project.pbxproj:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159737 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fc4b3b61
2013-11-24 Brady Eidson <beidson@apple.com>
DatabaseProcess: Add "UniqueIDBDatabase" that multiple WebProcesses can connect to
https://bugs.webkit.org/show_bug.cgi?id=124819
Reviewed by Dan Bernstein.
* Modules/indexeddb/IDBDatabaseBackend.cpp:
(WebCore::IDBDatabaseBackend::~IDBDatabaseBackend): Unregister from the IDBFactory.
2013-11-24 Gyuyoung Kim <gyuyoung.kim@samsung.com>
 
Generate toHTMLMarquee|OListElement() to cleanup static_cast<>
......@@ -124,6 +124,7 @@ void IDBDatabaseBackend::didOpenInternalAsync(const IDBDatabaseMetadata& metadat
IDBDatabaseBackend::~IDBDatabaseBackend()
{
m_factory->removeIDBDatabaseBackend(m_identifier);
}
void IDBDatabaseBackend::createObjectStore(int64_t transactionId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
......@@ -447,7 +448,6 @@ void IDBDatabaseBackend::openConnection(PassRefPtr<IDBCallbacks> prpCallbacks, P
processPendingCalls();
}
void IDBDatabaseBackend::openConnectionInternal(PassRefPtr<IDBCallbacks> prpCallbacks, PassRefPtr<IDBDatabaseCallbacks> prpDatabaseCallbacks, int64_t transactionId, uint64_t version)
{
ASSERT(m_pendingDeleteCalls.isEmpty());
......
2013-11-24 Brady Eidson <beidson@apple.com>
DatabaseProcess: Add "UniqueIDBDatabase" that multiple WebProcesses can connect to
https://bugs.webkit.org/show_bug.cgi?id=124819
Reviewed by Dan Bernstein.
UniqueIDBDatabase instances are per-DatabaseProcess, so it manages the set of them.
* DatabaseProcess/DatabaseProcess.cpp:
(WebKit::DatabaseProcess::getOrCreateUniqueIDBDatabase):
(WebKit::DatabaseProcess::removeUniqueIDBDatabase):
* DatabaseProcess/DatabaseProcess.h:
* DatabaseProcess/DatabaseToWebProcessConnection.h:
Start forwarding things along to the appropriate UniqueIDBDatabase.
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
(WebKit::DatabaseProcessIDBConnection::~DatabaseProcessIDBConnection):
(WebKit::DatabaseProcessIDBConnection::disconnectedFromWebProcess):
(WebKit::DatabaseProcessIDBConnection::establishConnection):
(WebKit::DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata):
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
A class that represents a single concrete IDB database that multiple WebProcesses can connect to.
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::UniqueIDBDatabase):
(WebKit::UniqueIDBDatabase::~UniqueIDBDatabase):
(WebKit::UniqueIDBDatabase::registerConnection):
(WebKit::UniqueIDBDatabase::unregisterConnection):
(WebKit::UniqueIDBDatabase::getIDBDatabaseMetadata):
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
(WebKit::UniqueIDBDatabase::create):
(WebKit::UniqueIDBDatabase::identifier):
A class to help uniquely identify an IDBDatabase that can be expanded as needed.
Importantly, it knows how to be used as a key in a HashMap.
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.cpp: Added.
(WebKit::UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier):
(WebKit::UniqueIDBDatabaseIdentifier::isHashTableDeletedValue):
(WebKit::UniqueIDBDatabaseIdentifier::hash):
(WebKit::UniqueIDBDatabaseIdentifier::isNull):
(WebKit::operator==):
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.h: Added.
(WebKit::UniqueIDBDatabaseIdentifier::databaseName):
(WebKit::UniqueIDBDatabaseIdentifier::openingOrigin):
(WebKit::UniqueIDBDatabaseIdentifier::mainFrameOrigin):
(WebKit::UniqueIDBDatabaseIdentifierHash::hash):
(WebKit::UniqueIDBDatabaseIdentifierHash::equal):
(WebKit::UniqueIDBDatabaseIdentifierHashTraits::isEmptyValue):
* Shared/SecurityOriginData.cpp:
(WebKit::operator==):
* Shared/SecurityOriginData.h:
* UIProcess/WebContext.cpp:
* WebProcess/Databases/IndexedDB/WebIDBFactoryBackend.cpp:
(WebKit::WebIDBFactoryBackend::open):
(WebKit::WebIDBFactoryBackend::removeIDBDatabaseBackend):
* WebKit2.xcodeproj/project.pbxproj:
2013-11-24 Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>, Arunprasad Rajkumar <arurajku@cisco.com>
[WK2][GTK] Adding SpatialNavigation setting to webkit2
......
......@@ -29,6 +29,7 @@
#include "DatabaseProcessCreationParameters.h"
#include "DatabaseProcessProxyMessages.h"
#include "DatabaseToWebProcessConnection.h"
#include "UniqueIDBDatabase.h"
#if ENABLE(DATABASE_PROCESS)
......@@ -68,6 +69,27 @@ void DatabaseProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::St
RunLoop::current()->stop();
}
PassRefPtr<UniqueIDBDatabase> DatabaseProcess::getOrCreateUniqueIDBDatabase(const UniqueIDBDatabaseIdentifier& identifier)
{
auto addResult = m_idbDatabases.add(identifier, nullptr);
if (!addResult.isNewEntry)
return addResult.iterator->value;
RefPtr<UniqueIDBDatabase> database = UniqueIDBDatabase::create(identifier);
addResult.iterator->value = database.get();
return database.release();
}
void DatabaseProcess::removeUniqueIDBDatabase(const UniqueIDBDatabase& database)
{
const UniqueIDBDatabaseIdentifier& identifier = database.identifier();
ASSERT(m_idbDatabases.contains(identifier));
// FIXME: Perform necessary shut down of the unique database before it is actually destroyed.
m_idbDatabases.remove(identifier);
}
void DatabaseProcess::initializeDatabaseProcess(const DatabaseProcessCreationParameters& parameters)
{
m_indexedDatabaseDirectory = parameters.indexedDatabaseDirectory;
......
......@@ -29,10 +29,12 @@
#if ENABLE(DATABASE_PROCESS)
#include "ChildProcess.h"
#include "UniqueIDBDatabaseIdentifier.h"
namespace WebKit {
class DatabaseToWebProcessConnection;
class UniqueIDBDatabase;
struct DatabaseProcessCreationParameters;
......@@ -43,6 +45,9 @@ public:
const String& indexedDatabaseDirectory() const { return m_indexedDatabaseDirectory; }
PassRefPtr<UniqueIDBDatabase> getOrCreateUniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
void removeUniqueIDBDatabase(const UniqueIDBDatabase&);
private:
DatabaseProcess();
~DatabaseProcess();
......@@ -66,6 +71,8 @@ private:
Vector<RefPtr<DatabaseToWebProcessConnection>> m_databaseToWebProcessConnections;
String m_indexedDatabaseDirectory;
HashMap<UniqueIDBDatabaseIdentifier, RefPtr<UniqueIDBDatabase>> m_idbDatabases;
};
} // namespace WebKit
......
......@@ -27,6 +27,7 @@
#define DatabaseToWebProcessConnection_h
#include "Connection.h"
#include "DatabaseProcessIDBConnection.h"
#include "MessageSender.h"
#include <wtf/HashMap.h>
......@@ -35,8 +36,6 @@
namespace WebKit {
class DatabaseProcessIDBConnection;
class DatabaseToWebProcessConnection : public RefCounted<DatabaseToWebProcessConnection>, public CoreIPC::Connection::Client, public CoreIPC::MessageSender {
public:
static PassRefPtr<DatabaseToWebProcessConnection> create(CoreIPC::Connection::Identifier);
......
......@@ -28,7 +28,9 @@
#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#include "DatabaseProcess.h"
#include "DatabaseToWebProcessConnection.h"
#include "UniqueIDBDatabase.h"
#include "WebCoreArgumentCoders.h"
#include "WebIDBServerConnectionMessages.h"
#include <WebCore/IDBDatabaseMetadata.h>
......@@ -45,32 +47,29 @@ DatabaseProcessIDBConnection::DatabaseProcessIDBConnection(DatabaseToWebProcessC
DatabaseProcessIDBConnection::~DatabaseProcessIDBConnection()
{
ASSERT(!m_uniqueIDBDatabase);
}
void DatabaseProcessIDBConnection::disconnectedFromWebProcess()
{
// Do any necessary cleanup work here.
m_uniqueIDBDatabase->unregisterConnection(*this);
m_uniqueIDBDatabase.clear();
}
void DatabaseProcessIDBConnection::establishConnection(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin)
{
// This method should only be called once, so the stored database name should still be null.
// Also, it is invalid to set the stored database name to the null string.
ASSERT(m_databaseName.isNull());
ASSERT(!databaseName.isNull());
m_databaseName = databaseName;
m_openingOrigin = openingOrigin;
m_mainFrameOrigin = mainFrameOrigin;
m_uniqueIDBDatabase = DatabaseProcess::shared().getOrCreateUniqueIDBDatabase(UniqueIDBDatabaseIdentifier(databaseName, openingOrigin, mainFrameOrigin));
m_uniqueIDBDatabase->registerConnection(*this);
}
void DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata(uint64_t requestID)
{
// FIXME: This method is successfully called by messaging from the WebProcess, and calls back with dummy data.
// Needs real implementation.
ASSERT(m_uniqueIDBDatabase);
IDBDatabaseMetadata data;
send(Messages::WebIDBServerConnection::DidGetOrEstablishIDBDatabaseMetadata(requestID, false, data));
RefPtr<DatabaseProcessIDBConnection> connection(this);
m_uniqueIDBDatabase->getIDBDatabaseMetadata([connection, requestID](bool success, const IDBDatabaseMetadata& metadata) {
connection->send(Messages::WebIDBServerConnection::DidGetOrEstablishIDBDatabaseMetadata(requestID, success, metadata));
});
}
CoreIPC::Connection* DatabaseProcessIDBConnection::messageSenderConnection()
......
......@@ -31,11 +31,13 @@
#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#include "SecurityOriginData.h"
#include "UniqueIDBDatabaseIdentifier.h"
#include <wtf/text/WTFString.h>
namespace WebKit {
class DatabaseToWebProcessConnection;
class UniqueIDBDatabase;
class DatabaseProcessIDBConnection : public RefCounted<DatabaseProcessIDBConnection>, public CoreIPC::MessageSender {
public:
......@@ -65,9 +67,7 @@ private:
Ref<DatabaseToWebProcessConnection> m_connection;
uint64_t m_serverConnectionIdentifier;
String m_databaseName;
SecurityOriginData m_openingOrigin;
SecurityOriginData m_mainFrameOrigin;
RefPtr<UniqueIDBDatabase> m_uniqueIDBDatabase;
};
} // namespace WebKit
......
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "UniqueIDBDatabase.h"
#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#include "DatabaseProcess.h"
#include "DatabaseProcessIDBConnection.h"
#include <WebCore/IDBDatabaseMetadata.h>
using namespace WebCore;
namespace WebKit {
UniqueIDBDatabase::UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier& identifier)
: m_identifier(identifier)
{
}
UniqueIDBDatabase::~UniqueIDBDatabase()
{
}
void UniqueIDBDatabase::registerConnection(DatabaseProcessIDBConnection& connection)
{
ASSERT(!m_connections.contains(&connection));
m_connections.add(&connection);
}
void UniqueIDBDatabase::unregisterConnection(DatabaseProcessIDBConnection& connection)
{
ASSERT(m_connections.contains(&connection));
m_connections.remove(&connection);
if (m_connections.isEmpty())
DatabaseProcess::shared().removeUniqueIDBDatabase(*this);
}
void UniqueIDBDatabase::getIDBDatabaseMetadata(std::function<void(bool, const WebCore::IDBDatabaseMetadata&)> completionCallback)
{
// FIXME: This method is successfully called by messaging from the WebProcess, and calls back with dummy data.
// Needs real implementation.
IDBDatabaseMetadata metadata;
completionCallback(false, metadata);
}
} // namespace WebKit
#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UniqueIDBDatabase_h
#define UniqueIDBDatabase_h
#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#include "UniqueIDBDatabaseIdentifier.h"
#include <functional>
#include <wtf/HashSet.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
struct IDBDatabaseMetadata;
}
namespace WebKit {
class DatabaseProcessIDBConnection;
struct SecurityOriginData;
class UniqueIDBDatabase : public RefCounted<UniqueIDBDatabase> {
public:
static PassRefPtr<UniqueIDBDatabase> create(const UniqueIDBDatabaseIdentifier& identifier)
{
return adoptRef(new UniqueIDBDatabase(identifier));
}
~UniqueIDBDatabase();
const UniqueIDBDatabaseIdentifier& identifier() const { return m_identifier; }
void registerConnection(DatabaseProcessIDBConnection&);
void unregisterConnection(DatabaseProcessIDBConnection&);
void getIDBDatabaseMetadata(std::function<void(bool, const WebCore::IDBDatabaseMetadata&)> completionCallback);
private:
UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
UniqueIDBDatabaseIdentifier m_identifier;
HashSet<RefPtr<DatabaseProcessIDBConnection>> m_connections;
};
} // namespace WebKit
#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#endif // UniqueIDBDatabase_h
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "UniqueIDBDatabaseIdentifier.h"
#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#include <wtf/text/StringBuilder.h>
namespace WebKit {
UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier()
{
}
UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin)
: m_databaseName(databaseName)
, m_openingOrigin(openingOrigin)
, m_mainFrameOrigin(mainFrameOrigin)
{
// While it is valid to have an empty database name, it is not valid to have a null one.
ASSERT(!m_databaseName.isNull());
}
UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier(WTF::HashTableDeletedValueType)
: m_databaseName(WTF::HashTableDeletedValue)
{
}
bool UniqueIDBDatabaseIdentifier::isHashTableDeletedValue() const
{
return m_databaseName.isHashTableDeletedValue();
}
unsigned UniqueIDBDatabaseIdentifier::hash() const
{
unsigned hashCodes[7] = {
m_databaseName.impl() ? m_databaseName.impl()->hash() : 0,
m_openingOrigin.protocol.impl() ? m_openingOrigin.protocol.impl()->hash() : 0,
m_openingOrigin.host.impl() ? m_openingOrigin.host.impl()->hash() : 0,
static_cast<unsigned>(m_openingOrigin.port),
m_mainFrameOrigin.protocol.impl() ? m_mainFrameOrigin.protocol.impl()->hash() : 0,
m_mainFrameOrigin.host.impl() ? m_mainFrameOrigin.host.impl()->hash() : 0,
static_cast<unsigned>(m_mainFrameOrigin.port)
};
return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
}
bool UniqueIDBDatabaseIdentifier::isNull() const
{
// Only a default constructed UniqueIDBDatabaseIdentifier can have a null database name.
return m_databaseName.isNull();
}
bool operator==(const UniqueIDBDatabaseIdentifier& a, const UniqueIDBDatabaseIdentifier& b)
{
if (&a == &b)
return true;
return a.databaseName() == b.databaseName()
&& a.openingOrigin() == b.openingOrigin()
&& a.mainFrameOrigin() == b.mainFrameOrigin();
}
} // namespace WebKit
#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UniqueIDBDatabaseIdentifier_h
#define UniqueIDBDatabaseIdentifier_h
#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#include "SecurityOriginData.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebKit {
class UniqueIDBDatabaseIdentifier {
public:
UniqueIDBDatabaseIdentifier();
UniqueIDBDatabaseIdentifier(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin);
bool isNull() const;
const String& databaseName() const { return m_databaseName; }
const SecurityOriginData& openingOrigin() const { return m_openingOrigin; }
const SecurityOriginData& mainFrameOrigin() const { return m_mainFrameOrigin; }
UniqueIDBDatabaseIdentifier(WTF::HashTableDeletedValueType);
bool isHashTableDeletedValue() const;
unsigned hash() const;
private:
String m_databaseName;
SecurityOriginData m_openingOrigin;
SecurityOriginData m_mainFrameOrigin;
};
bool operator==(const UniqueIDBDatabaseIdentifier&, const UniqueIDBDatabaseIdentifier&);
struct UniqueIDBDatabaseIdentifierHash {
static unsigned hash(const UniqueIDBDatabaseIdentifier& identifier) { return identifier.hash(); }
static bool equal(const UniqueIDBDatabaseIdentifier& a, const UniqueIDBDatabaseIdentifier& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = false;
};
struct UniqueIDBDatabaseIdentifierHashTraits : WTF::SimpleClassHashTraits<UniqueIDBDatabaseIdentifier> {
static const bool hasIsEmptyValueFunction = true;
static bool isEmptyValue(const UniqueIDBDatabaseIdentifier& info) { return info.isNull(); }
};
} // namespace WebKit
namespace WTF {
template<> struct HashTraits<WebKit::UniqueIDBDatabaseIdentifier> : WebKit::UniqueIDBDatabaseIdentifierHashTraits { };
template<> struct DefaultHash<WebKit::UniqueIDBDatabaseIdentifier> {
typedef WebKit::UniqueIDBDatabaseIdentifierHash Hash;
};
} // namespaec WTF
#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
#endif // UniqueIDBDatabaseIdentifier_h
......@@ -89,4 +89,14 @@ void performAPICallbackWithSecurityOriginDataVector(const Vector<SecurityOriginD
callback->performCallbackWithReturnValue(API::Array::create(std::move(securityOrigins)).get());
}
bool operator==(const SecurityOriginData& a, const SecurityOriginData& b)