summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webkit/api/public/WebDatabase.h85
-rw-r--r--webkit/api/public/WebDatabaseObserver.h48
-rw-r--r--webkit/api/public/WebSecurityOrigin.h4
-rw-r--r--webkit/api/src/WebDatabase.cpp144
-rw-r--r--webkit/api/src/WebSecurityOrigin.cpp8
-rw-r--r--webkit/webkit.gyp3
6 files changed, 292 insertions, 0 deletions
diff --git a/webkit/api/public/WebDatabase.h b/webkit/api/public/WebDatabase.h
new file mode 100644
index 0000000..b59b06b
--- /dev/null
+++ b/webkit/api/public/WebDatabase.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2009 Google 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:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 WebDatabase_h
+#define WebDatabase_h
+
+#include "WebCommon.h"
+#include "WebSecurityOrigin.h"
+
+#if WEBKIT_IMPLEMENTATION
+namespace WebCore { class Database; }
+namespace WTF { template <typename T> class PassRefPtr; }
+#endif
+
+namespace WebKit {
+class WebDatabaseObserver;
+class WebDatabasePrivate;
+class WebString;
+
+class WebDatabase {
+public:
+ WebDatabase() : m_private(0) { }
+ WebDatabase(const WebDatabase& d) : m_private(0) { assign(d); }
+ ~WebDatabase() { reset(); }
+
+ WebDatabase& operator=(const WebDatabase& d) { assign(d); return *this; }
+
+ WEBKIT_API void reset();
+ WEBKIT_API void assign(const WebDatabase&);
+ bool isNull() const { return m_private == 0; }
+
+ WEBKIT_API WebString name() const;
+ WEBKIT_API WebString displayName() const;
+ WEBKIT_API unsigned long estimatedSize() const;
+ WEBKIT_API WebSecurityOrigin securityOrigin() const;
+
+ WEBKIT_API static void setObserver(WebDatabaseObserver*);
+ WEBKIT_API static WebDatabaseObserver* observer();
+
+ WEBKIT_API static void updateDatabaseSize(
+ const WebString& originIdentifier, const WebString& databaseName,
+ unsigned long long databaseSize, unsigned long long spaceAvailable);
+
+#if WEBKIT_IMPLEMENTATION
+ WebDatabase(const WTF::PassRefPtr<WebCore::Database>&);
+ WebDatabase& operator=(const WTF::PassRefPtr<WebCore::Database>&);
+ operator WTF::PassRefPtr<WebCore::Database>() const;
+#endif
+
+private:
+ void assign(WebDatabasePrivate*);
+
+ WebDatabasePrivate* m_private;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/webkit/api/public/WebDatabaseObserver.h b/webkit/api/public/WebDatabaseObserver.h
new file mode 100644
index 0000000..da85c93
--- /dev/null
+++ b/webkit/api/public/WebDatabaseObserver.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2009 Google 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:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 WebDatabaseObserver_h
+#define WebDatabaseObserver_h
+
+namespace WebKit {
+class WebDatabase;
+
+class WebDatabaseObserver {
+public:
+ virtual void databaseOpened(const WebDatabase&) = 0;
+ virtual void databaseModified(const WebDatabase&) = 0;
+ virtual void databaseClosed(const WebDatabase&) = 0;
+protected:
+ ~WebDatabaseObserver() {}
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/webkit/api/public/WebSecurityOrigin.h b/webkit/api/public/WebSecurityOrigin.h
index 1905643..cbb1a3d 100644
--- a/webkit/api/public/WebSecurityOrigin.h
+++ b/webkit/api/public/WebSecurityOrigin.h
@@ -55,6 +55,10 @@ namespace WebKit {
bool isNull() const { return m_private == 0; }
+ // Returns a string representation of this SecurityOrigin that can be used as a file.
+ // Should be used in storage APIs only.
+ WEBKIT_API WebString databaseIdentifier();
+
WEBKIT_API WebString toString() const;
#if WEBKIT_IMPLEMENTATION
diff --git a/webkit/api/src/WebDatabase.cpp b/webkit/api/src/WebDatabase.cpp
new file mode 100644
index 0000000..d702eaf
--- /dev/null
+++ b/webkit/api/src/WebDatabase.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2009 Google 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:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 "WebDatabase.h"
+
+#include "Database.h"
+#include "DatabaseThread.h"
+#include "Document.h"
+#include "KURL.h"
+#include "SecurityOrigin.h"
+#include "WebDatabaseObserver.h"
+#include "WebString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static WebDatabaseObserver* databaseObserver = 0;
+
+class WebDatabasePrivate : public Database {
+};
+
+void WebDatabase::reset()
+{
+ assign(0);
+}
+
+void WebDatabase::assign(const WebDatabase& other)
+{
+ WebDatabasePrivate* d = const_cast<WebDatabasePrivate*>(other.m_private);
+ if (d)
+ d->ref();
+ assign(d);
+}
+
+WebString WebDatabase::name() const
+{
+ if (m_private)
+ return m_private->stringIdentifier();
+
+ return WebString::fromUTF8("null");
+}
+
+WebString WebDatabase::displayName() const
+{
+// FIXME: add the Database::displayName() method.
+// if (m_private)
+// return m_private->displayName();
+
+ return WebString::fromUTF8("null");
+}
+
+unsigned long WebDatabase::estimatedSize() const
+{
+// FIXME: add the Database::estimatedSize() method.
+// if (m_private)
+// return m_private->estimatedSize();
+
+ return -1;
+}
+
+WebSecurityOrigin WebDatabase::securityOrigin() const
+{
+// FIXME: add the Database::threadSafeSecurityOrigin() method.
+// if (m_private)
+// return WebSecurityOrigin(m_private->threadSafeSecurityOrigin());
+
+ return WebSecurityOrigin();
+}
+
+void WebDatabase::setObserver(WebDatabaseObserver* observer)
+{
+ databaseObserver = observer;
+}
+
+WebDatabaseObserver* WebDatabase::observer()
+{
+ return databaseObserver;
+}
+
+void WebDatabase::updateDatabaseSize(
+ const WebString& originIdentifier, const WebString& databaseName,
+ unsigned long long databaseSize, unsigned long long spaceAvailable)
+{
+// FIXME: add the QuotaTracker class.
+// WebCore::QuotaTracker::instance().updateDatabaseSize(
+// originIdentifier, databaseName, databaseSize, spaceAvailable);
+}
+
+WebDatabase::WebDatabase(const WTF::PassRefPtr<Database>& database)
+ : m_private(static_cast<WebDatabasePrivate*>(database.releaseRef()))
+{
+}
+
+WebDatabase& WebDatabase::operator=(const WTF::PassRefPtr<Database>& database)
+{
+ assign(static_cast<WebDatabasePrivate*>(database.releaseRef()));
+ return *this;
+}
+
+WebDatabase::operator WTF::PassRefPtr<Database>() const
+{
+ return PassRefPtr<Database>(const_cast<WebDatabasePrivate*>(m_private));
+}
+
+void WebDatabase::assign(WebDatabasePrivate* d)
+{
+ // d is already ref'd for us by the caller
+ if (m_private)
+ m_private->deref();
+ m_private = d;
+}
+
+} // namespace WebKit
diff --git a/webkit/api/src/WebSecurityOrigin.cpp b/webkit/api/src/WebSecurityOrigin.cpp
index c0563af..8368c83 100644
--- a/webkit/api/src/WebSecurityOrigin.cpp
+++ b/webkit/api/src/WebSecurityOrigin.cpp
@@ -55,6 +55,14 @@ void WebSecurityOrigin::assign(const WebSecurityOrigin& other)
assign(p);
}
+WebString WebSecurityOrigin::databaseIdentifier()
+{
+ if (m_private)
+ return m_private->databaseIdentifier();
+
+ return WebString::fromUTF8("null");
+}
+
WebString WebSecurityOrigin::toString() const
{
if (m_private)
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 813ae44..1eeb244 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -93,6 +93,8 @@
'api/public/WebCString.h',
'api/public/WebCursorInfo.h',
'api/public/WebData.h',
+ 'api/public/WebDatabase.h',
+ 'api/public/WebDatabaseObserver.h',
'api/public/WebDataSource.h',
'api/public/WebDevToolsAgent.h',
'api/public/WebDevToolsAgentClient.h',
@@ -207,6 +209,7 @@
'api/src/WebCString.cpp',
'api/src/WebCursorInfo.cpp',
'api/src/WebData.cpp',
+ 'api/src/WebDatabase.cpp',
'api/src/WebDataSourceImpl.cpp',
'api/src/WebDataSourceImpl.h',
'api/src/WebDragData.cpp',