summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandreip@chromium.org <andreip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 16:58:32 +0000
committerandreip@chromium.org <andreip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 16:58:32 +0000
commitd0c005ad4a569e41db0fc011d5b93aed76442228 (patch)
treec83ac95647e175019ab6ae33d518ddba1717b7c9
parent0f53f5628ec01d743afade7de5e8ae350ca6880b (diff)
downloadchromium_src-d0c005ad4a569e41db0fc011d5b93aed76442228.zip
chromium_src-d0c005ad4a569e41db0fc011d5b93aed76442228.tar.gz
chromium_src-d0c005ad4a569e41db0fc011d5b93aed76442228.tar.bz2
Implement IDBDatabase::createObjectStore. Also refactor IndexedDBCallbacks.
This CL is a clone of http://codereview.chromium.org/2607001/show which was reviewd and LGTM'ed by Jeremy Orlow. Review URL: http://codereview.chromium.org/2740003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49267 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_callbacks.cc29
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_callbacks.h28
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc113
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h29
-rw-r--r--chrome/chrome_browser.gypi1
-rw-r--r--chrome/chrome_renderer.gypi2
-rw-r--r--chrome/common/render_messages.h52
-rwxr-xr-xchrome/common/render_messages_internal.h27
-rw-r--r--chrome/renderer/indexed_db_dispatcher.cc35
-rw-r--r--chrome/renderer/indexed_db_dispatcher.h10
-rw-r--r--chrome/renderer/renderer_webidbdatabase_impl.cc12
-rw-r--r--chrome/renderer/renderer_webidbdatabase_impl.h9
-rw-r--r--chrome/renderer/renderer_webidbobjectstore_impl.cc38
-rw-r--r--chrome/renderer/renderer_webidbobjectstore_impl.h31
14 files changed, 347 insertions, 69 deletions
diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.cc b/chrome/browser/in_process_webkit/indexed_db_callbacks.cc
deleted file mode 100644
index 82a48aa..0000000
--- a/chrome/browser/in_process_webkit/indexed_db_callbacks.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/in_process_webkit/indexed_db_callbacks.h"
-
-#include "base/logging.h"
-#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h"
-
-using WebKit::WebIDBDatabase;
-using WebKit::WebSerializedScriptValue;
-
-IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* parent,
- int32 response_id)
- : parent_(parent),
- response_id_(response_id) {
-}
-
-IndexedDBCallbacks::~IndexedDBCallbacks() {
-}
-
-void IndexedDBCallbacks::onSuccess(WebIDBDatabase* idb_database) {
- NOTREACHED();
-}
-
-void IndexedDBCallbacks::onSuccess(const WebSerializedScriptValue& value) {
- NOTREACHED();
-}
-
diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.h b/chrome/browser/in_process_webkit/indexed_db_callbacks.h
index 4b104a7..8b845d8 100644
--- a/chrome/browser/in_process_webkit/indexed_db_callbacks.h
+++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.h
@@ -6,28 +6,32 @@
#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_
#include "base/basictypes.h"
+#include "base/logging.h"
#include "base/ref_counted.h"
+#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h"
-class IndexedDBDispatcherHost;
+template <class WebObjectType, typename SuccessMsgType, typename ErrorMsgType>
class IndexedDBCallbacks : public WebKit::WebIDBCallbacks {
public:
- IndexedDBCallbacks(IndexedDBDispatcherHost* parent, int32 response_id);
- virtual ~IndexedDBCallbacks();
+ IndexedDBCallbacks(
+ IndexedDBDispatcherHost* dispatcher_host, int32 response_id)
+ : dispatcher_host_(dispatcher_host), response_id_(response_id) { }
- // We define default versions of these functions which simply DCHECK.
- // For each WebIDBCallbacks implementation, there should only be one success
- // callback that can possibly be called.
- virtual void onSuccess(WebKit::WebIDBDatabase* idb_database);
- virtual void onSuccess(const WebKit::WebSerializedScriptValue& value);
+ virtual void onError(const WebKit::WebIDBDatabaseError& error) {
+ dispatcher_host_->Send(new ErrorMsgType(
+ response_id_, error.code(), error.message()));
+ }
- protected:
- IndexedDBDispatcherHost* parent() { return parent_.get(); }
- int32 response_id() const { return response_id_; }
+ virtual void onSuccess(WebObjectType* idb_object) {
+ int32 object_id = dispatcher_host_->Add(idb_object);
+ dispatcher_host_->Send(new SuccessMsgType(response_id_, object_id));
+ }
private:
- scoped_refptr<IndexedDBDispatcherHost> parent_;
+ scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
int32 response_id_;
DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
index 9d612c5de..41291c1 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
@@ -15,6 +15,7 @@
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBIndex.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBObjectStore.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
@@ -22,6 +23,7 @@ using WebKit::WebDOMStringList;
using WebKit::WebIDBDatabase;
using WebKit::WebIDBDatabaseError;
using WebKit::WebIDBIndex;
+using WebKit::WebIDBObjectStore;
using WebKit::WebSecurityOrigin;
IndexedDBDispatcherHost::IndexedDBDispatcherHost(
@@ -32,6 +34,8 @@ IndexedDBDispatcherHost::IndexedDBDispatcherHost(
new DatabaseDispatcherHost(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(index_dispatcher_host_(
new IndexDispatcherHost(this))),
+ ALLOW_THIS_IN_INITIALIZER_LIST(object_store_dispatcher_host_(
+ new ObjectStoreDispatcherHost(this))),
process_handle_(0) {
DCHECK(sender_);
DCHECK(webkit_context_.get());
@@ -78,12 +82,16 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) {
case ViewHostMsg_IDBDatabaseName::ID:
case ViewHostMsg_IDBDatabaseDescription::ID:
case ViewHostMsg_IDBDatabaseVersion::ID:
+ case ViewHostMsg_IDBDatabaseCreateObjectStore::ID:
case ViewHostMsg_IDBDatabaseObjectStores::ID:
case ViewHostMsg_IDBDatabaseDestroyed::ID:
case ViewHostMsg_IDBIndexName::ID:
case ViewHostMsg_IDBIndexKeyPath::ID:
case ViewHostMsg_IDBIndexUnique::ID:
case ViewHostMsg_IDBIndexDestroyed::ID:
+ case ViewHostMsg_IDBObjectStoreName::ID:
+ case ViewHostMsg_IDBObjectStoreKeyPath::ID:
+ case ViewHostMsg_IDBObjectStoreDestroyed::ID:
break;
default:
return false;
@@ -126,7 +134,8 @@ void IndexedDBDispatcherHost::OnMessageReceivedWebKit(
bool msg_is_ok = true;
bool handled =
database_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
- index_dispatcher_host_->OnMessageReceived(message, &msg_is_ok);
+ index_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
+ object_store_dispatcher_host_->OnMessageReceived(message, &msg_is_ok);
if (!handled) {
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, msg_is_ok)
@@ -143,28 +152,13 @@ void IndexedDBDispatcherHost::OnMessageReceivedWebKit(
}
}
-int32 IndexedDBDispatcherHost::AddIDBDatabase(WebIDBDatabase* idb_database) {
+int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database) {
return database_dispatcher_host_->map_.Add(idb_database);
}
-class IndexedDatabaseOpenCallbacks : public IndexedDBCallbacks {
- public:
- IndexedDatabaseOpenCallbacks(IndexedDBDispatcherHost* parent,
- int32 response_id)
- : IndexedDBCallbacks(parent, response_id) {
- }
-
- virtual void onError(const WebIDBDatabaseError& error) {
- parent()->Send(new ViewMsg_IndexedDatabaseOpenError(
- response_id(), error.code(), error.message()));
- }
-
- virtual void onSuccess(WebIDBDatabase* idb_database) {
- int32 idb_database_id = parent()->AddIDBDatabase(idb_database);
- parent()->Send(new ViewMsg_IndexedDatabaseOpenSuccess(response_id(),
- idb_database_id));
- }
-};
+int32 IndexedDBDispatcherHost::Add(WebIDBObjectStore* idb_object_store) {
+ return object_store_dispatcher_host_->map_.Add(idb_object_store);
+}
void IndexedDBDispatcherHost::OnIndexedDatabaseOpen(
const ViewHostMsg_IndexedDatabaseOpen_Params& params) {
@@ -174,7 +168,10 @@ void IndexedDBDispatcherHost::OnIndexedDatabaseOpen(
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
Context()->GetIndexedDatabase()->open(
params.name_, params.description_,
- new IndexedDatabaseOpenCallbacks(this, params.response_id_),
+ new IndexedDBCallbacks<WebIDBDatabase,
+ ViewMsg_IndexedDatabaseOpenSuccess,
+ ViewMsg_IndexedDatabaseOpenError>(
+ this, params.response_id_),
WebSecurityOrigin::createFromDatabaseIdentifier(params.origin_), NULL);
}
@@ -192,8 +189,7 @@ ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess(
if (!return_object) {
BrowserRenderProcessHost::BadMessageTerminateProcess(message_type,
process_handle_);
- if (reply_msg)
- delete reply_msg;
+ delete reply_msg;
}
return return_object;
}
@@ -245,6 +241,8 @@ bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseVersion, OnVersion)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseObjectStores,
OnObjectStores)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseCreateObjectStore,
+ OnCreateObjectStore)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseDestroyed, OnDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -294,6 +292,22 @@ void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObjectStores(
parent_->Send(reply_msg);
}
+void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
+ const ViewHostMsg_IDBDatabaseCreateObjectStore_Params& params) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
+ &map_, params.idb_database_id_, NULL,
+ ViewHostMsg_IDBDatabaseObjectStores::ID);
+ if (!idb_database)
+ return;
+ idb_database->createObjectStore(
+ params.name_, params.keypath_, params.auto_increment_,
+ new IndexedDBCallbacks<WebIDBObjectStore,
+ ViewMsg_IDBDatabaseCreateObjectStoreSuccess,
+ ViewMsg_IDBDatabaseCreateObjectStoreError>(
+ parent_, params.response_id_));
+}
+
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(&map_, object_id,
@@ -357,3 +371,56 @@ void IndexedDBDispatcherHost::IndexDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(&map_, object_id, ViewHostMsg_IDBIndexDestroyed::ID);
}
+
+//////////////////////////////////////////////////////////////////////
+// IndexedDBDispatcherHost::ObjectStoreDispatcherHost
+//
+
+IndexedDBDispatcherHost::ObjectStoreDispatcherHost::ObjectStoreDispatcherHost(
+ IndexedDBDispatcherHost* parent)
+ : parent_(parent) {
+}
+
+IndexedDBDispatcherHost::
+ObjectStoreDispatcherHost::~ObjectStoreDispatcherHost() {
+}
+
+bool IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnMessageReceived(
+ const IPC::Message& message, bool* msg_is_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::ObjectStoreDispatcherHost,
+ message, *msg_is_ok)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreName, OnName)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreKeyPath,
+ OnKeyPath)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreDestroyed, OnDestroyed)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::Send(
+ IPC::Message* message) {
+ // The macro magic in OnMessageReceived requires this to link, but it should
+ // never actually be called.
+ NOTREACHED();
+ parent_->Send(message);
+}
+
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnName(
+ int32 object_id, IPC::Message* reply_msg) {
+ parent_->SyncGetter<string16, ViewHostMsg_IDBObjectStoreName>(
+ &map_, object_id, reply_msg, &WebIDBObjectStore::name);
+}
+
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnKeyPath(
+ int32 object_id, IPC::Message* reply_msg) {
+ parent_->SyncGetter<string16, ViewHostMsg_IDBObjectStoreKeyPath>(
+ &map_, object_id, reply_msg, &WebIDBObjectStore::keyPath);
+}
+
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDestroyed(
+ int32 object_id) {
+ parent_->DestroyObject(
+ &map_, object_id, ViewHostMsg_IDBObjectStoreDestroyed::ID);
+}
diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
index a5b1920..94be909 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
@@ -13,10 +13,12 @@
#include "ipc/ipc_message.h"
struct ViewHostMsg_IndexedDatabaseOpen_Params;
+struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params;
namespace WebKit {
class WebIDBDatabase;
class WebIDBIndex;
+class WebIDBObjectStore;
}
// Handles all IndexedDB related messages from a particular renderer process.
@@ -48,8 +50,8 @@ class IndexedDBDispatcherHost
// The various IndexedDBCallbacks children call these methods to add the
// results into the applicable map. See below for more details.
- int32 AddIDBDatabase(WebKit::WebIDBDatabase* idb_database);
- // TODO(andreip/jorlow): Add functions for other maps here.
+ int32 Add(WebKit::WebIDBDatabase* idb_database);
+ int32 Add(WebKit::WebIDBObjectStore* idb_object_store);
private:
friend class base::RefCountedThreadSafe<IndexedDBDispatcherHost>;
@@ -77,7 +79,7 @@ class IndexedDBDispatcherHost
class DatabaseDispatcherHost {
public:
- DatabaseDispatcherHost(IndexedDBDispatcherHost* parent);
+ explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent);
~DatabaseDispatcherHost();
bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
@@ -87,6 +89,9 @@ class IndexedDBDispatcherHost
void OnDescription(int32 idb_database_id, IPC::Message* reply_msg);
void OnVersion(int32 idb_database_id, IPC::Message* reply_msg);
void OnObjectStores(int32 idb_database_id, IPC::Message* reply_msg);
+ void OnCreateObjectStore(
+ const ViewHostMsg_IDBDatabaseCreateObjectStore_Params& params);
+
void OnDestroyed(int32 idb_database_id);
IndexedDBDispatcherHost* parent_;
@@ -95,7 +100,7 @@ class IndexedDBDispatcherHost
class IndexDispatcherHost {
public:
- IndexDispatcherHost(IndexedDBDispatcherHost* parent);
+ explicit IndexDispatcherHost(IndexedDBDispatcherHost* parent);
~IndexDispatcherHost();
bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
@@ -110,6 +115,21 @@ class IndexedDBDispatcherHost
IDMap<WebKit::WebIDBIndex, IDMapOwnPointer> map_;
};
+ class ObjectStoreDispatcherHost {
+ public:
+ explicit ObjectStoreDispatcherHost(IndexedDBDispatcherHost* parent);
+ ~ObjectStoreDispatcherHost();
+
+ bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
+ void Send(IPC::Message* message);
+
+ void OnName(int32 idb_object_store_id, IPC::Message* reply_msg);
+ void OnKeyPath(int32 idb_object_store_id, IPC::Message* reply_msg);
+ void OnDestroyed(int32 idb_object_store_id);
+
+ IndexedDBDispatcherHost* parent_;
+ IDMap<WebKit::WebIDBObjectStore, IDMapOwnPointer> map_;
+ };
// Only use on the IO thread.
IPC::Message::Sender* sender_;
@@ -119,6 +139,7 @@ class IndexedDBDispatcherHost
// Only access on WebKit thread.
scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_;
scoped_ptr<IndexDispatcherHost> index_dispatcher_host_;
+ scoped_ptr<ObjectStoreDispatcherHost> object_store_dispatcher_host_;
// If we get a corrupt message from a renderer, we need to kill it using this
// handle.
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 3082864..80884d2 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1608,7 +1608,6 @@
'browser/in_process_webkit/dom_storage_namespace.h',
'browser/in_process_webkit/dom_storage_permission_request.cc',
'browser/in_process_webkit/dom_storage_permission_request.h',
- 'browser/in_process_webkit/indexed_db_callbacks.cc',
'browser/in_process_webkit/indexed_db_callbacks.h',
'browser/in_process_webkit/indexed_db_context.cc',
'browser/in_process_webkit/indexed_db_context.h',
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index a97268f..d240bf2 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -150,6 +150,8 @@
'renderer/renderer_webidbdatabase_impl.h',
'renderer/renderer_webidbindex_impl.cc',
'renderer/renderer_webidbindex_impl.h',
+ 'renderer/renderer_webidbobjectstore_impl.cc',
+ 'renderer/renderer_webidbobjectstore_impl.h',
'renderer/renderer_webindexeddatabase_impl.cc',
'renderer/renderer_webindexeddatabase_impl.h',
'renderer/renderer_webkitclient_impl.cc',
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index f5e4d72..b85e3dca 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -543,6 +543,24 @@ struct ViewHostMsg_IndexedDatabaseOpen_Params {
string16 description_;
};
+// Used to create an object store.
+struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params {
+ // The response should have this id.
+ int32 response_id_;
+
+ // The name of the object store.
+ string16 name_;
+
+ // The keyPath of the object store.
+ string16 keypath_;
+
+ // Whether the object store created should have a key generator.
+ bool auto_increment_;
+
+ // The database the object store belongs to.
+ int32 idb_database_id_;
+};
+
// Allows an extension to execute code in a tab.
struct ViewMsg_ExecuteCode_Params {
ViewMsg_ExecuteCode_Params() {}
@@ -2355,6 +2373,40 @@ struct ParamTraits<ViewHostMsg_IndexedDatabaseOpen_Params> {
}
};
+// Traits for ViewHostMsg_IDBDatabaseCreateObjectStore_Params.
+template <>
+struct ParamTraits<ViewHostMsg_IDBDatabaseCreateObjectStore_Params> {
+ typedef ViewHostMsg_IDBDatabaseCreateObjectStore_Params param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.response_id_);
+ WriteParam(m, p.name_);
+ WriteParam(m, p.keypath_);
+ WriteParam(m, p.auto_increment_);
+ WriteParam(m, p.idb_database_id_);
+ }
+ static bool Read(const Message* m, void** iter, param_type* p) {
+ return
+ ReadParam(m, iter, &p->response_id_) &&
+ ReadParam(m, iter, &p->name_) &&
+ ReadParam(m, iter, &p->keypath_) &&
+ ReadParam(m, iter, &p->auto_increment_) &&
+ ReadParam(m, iter, &p->idb_database_id_);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"(");
+ LogParam(p.response_id_, l);
+ l->append(L", ");
+ LogParam(p.name_, l);
+ l->append(L", ");
+ LogParam(p.keypath_, l);
+ l->append(L", ");
+ LogParam(p.auto_increment_, l);
+ l->append(L", ");
+ LogParam(p.idb_database_id_, l);
+ l->append(L")");
+ }
+};
+
// Traits for ViewHostMsg_CreateWorker_Params
template <>
struct ParamTraits<ViewHostMsg_CreateWorker_Params> {
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 4bddbf7..88725ad 100755
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -858,6 +858,15 @@ IPC_BEGIN_MESSAGES(View)
int /* code */,
string16 /* message */)
+ // IDBDatabase::createObjectStore message responses.
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBDatabaseCreateObjectStoreSuccess,
+ int32 /* response_id */,
+ int32 /* object_store_id */)
+ IPC_MESSAGE_CONTROL3(ViewMsg_IDBDatabaseCreateObjectStoreError,
+ int32 /* response_id */,
+ int /* code */,
+ string16 /* message */)
+
#if defined(IPC_MESSAGE_LOG_ENABLED)
// Tell the renderer process to begin or end IPC message logging.
IPC_MESSAGE_CONTROL1(ViewMsg_SetIPCLoggingEnabled,
@@ -2200,6 +2209,10 @@ IPC_BEGIN_MESSAGES(ViewHost)
int32, /* idb_database_id */
std::vector<string16> /* objectStores */)
+ // WebIDBDatabase::createObjectStore() message.
+ IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBDatabaseCreateObjectStore,
+ ViewHostMsg_IDBDatabaseCreateObjectStore_Params)
+
// WebIDBDatabase::~WebIDBDatabase() message.
IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBDatabaseDestroyed,
int32 /* idb_database_id */)
@@ -2223,6 +2236,20 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBIndexDestroyed,
int32 /* idb_index_id */)
+ // WebIDBObjectStore::name() message.
+ IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_IDBObjectStoreName,
+ int32, /* idb_object_store_id */
+ string16 /* name */)
+
+ // WebIDBObjectStore::keyPath() message.
+ IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_IDBObjectStoreKeyPath,
+ int32, /* idb_object_store_id */
+ string16 /* keyPath */)
+
+ // WebIDBObjectStore::~WebIDBObjectStore() message.
+ IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBObjectStoreDestroyed,
+ int32 /* idb_object_store_id */)
+
// Get file size in bytes. Set result to -1 if failed to get the file size.
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetFileSize,
FilePath /* path */,
diff --git a/chrome/renderer/indexed_db_dispatcher.cc b/chrome/renderer/indexed_db_dispatcher.cc
index 64c0ec1..fcb5b68 100644
--- a/chrome/renderer/indexed_db_dispatcher.cc
+++ b/chrome/renderer/indexed_db_dispatcher.cc
@@ -8,6 +8,7 @@
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/render_view.h"
#include "chrome/renderer/renderer_webidbdatabase_impl.h"
+#include "chrome/renderer/renderer_webidbobjectstore_impl.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
@@ -31,6 +32,8 @@ bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnIndexedDatabaseOpenSuccess)
IPC_MESSAGE_HANDLER(ViewMsg_IndexedDatabaseOpenError,
OnIndexedDatabaseOpenError)
+ IPC_MESSAGE_HANDLER(ViewMsg_IDBDatabaseCreateObjectStoreSuccess,
+ OnIDBDatabaseCreateObjectStoreSuccess)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -58,6 +61,22 @@ void IndexedDBDispatcher::RequestIndexedDatabaseOpen(
RenderThread::current()->Send(new ViewHostMsg_IndexedDatabaseOpen(params));
}
+void IndexedDBDispatcher::RequestIDBDatabaseCreateObjectStore(
+ const string16& name, const string16& keypath, bool auto_increment,
+ WebIDBCallbacks* callbacks_ptr, int32 idb_database_id) {
+ scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
+
+ ViewHostMsg_IDBDatabaseCreateObjectStore_Params params;
+ params.response_id_ = idb_database_create_object_store_callbacks_.Add(
+ callbacks.release());
+ params.name_ = name;
+ params.keypath_ = keypath;
+ params.auto_increment_ = auto_increment;
+ params.idb_database_id_ = idb_database_id;
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBDatabaseCreateObjectStore(params));
+}
+
void IndexedDBDispatcher::OnIndexedDatabaseOpenSuccess(
int32 response_id, int32 idb_database_id) {
WebKit::WebIDBCallbacks* callbacks =
@@ -73,3 +92,19 @@ void IndexedDBDispatcher::OnIndexedDatabaseOpenError(
callbacks->onError(WebIDBDatabaseError(code, message));
indexed_database_open_callbacks_.Remove(response_id);
}
+
+void IndexedDBDispatcher::OnIDBDatabaseCreateObjectStoreSuccess(
+ int32 response_id, int32 idb_object_store_id) {
+ WebKit::WebIDBCallbacks* callbacks =
+ idb_database_create_object_store_callbacks_.Lookup(response_id);
+ callbacks->onSuccess(new RendererWebIDBObjectStoreImpl(idb_object_store_id));
+ idb_database_create_object_store_callbacks_.Remove(response_id);
+}
+
+void IndexedDBDispatcher::OnIDBDatabaseCreateObjectStoreError(
+ int32 response_id, int code, const string16& message) {
+ WebKit::WebIDBCallbacks* callbacks =
+ idb_database_create_object_store_callbacks_.Lookup(response_id);
+ callbacks->onError(WebIDBDatabaseError(code, message));
+ idb_database_create_object_store_callbacks_.Remove(response_id);
+}
diff --git a/chrome/renderer/indexed_db_dispatcher.h b/chrome/renderer/indexed_db_dispatcher.h
index 6c86602..13e4376 100644
--- a/chrome/renderer/indexed_db_dispatcher.h
+++ b/chrome/renderer/indexed_db_dispatcher.h
@@ -30,6 +30,10 @@ class IndexedDBDispatcher {
WebKit::WebIDBCallbacks* callbacks, const string16& origin,
WebKit::WebFrame* web_frame);
+ void RequestIDBDatabaseCreateObjectStore(
+ const string16& name, const string16& keypath, bool auto_increment,
+ WebKit::WebIDBCallbacks* callbacks, int32 idb_database_id);
+
private:
// Message handlers. For each message we send, we need to handle both the
// success and the error case.
@@ -37,11 +41,17 @@ class IndexedDBDispatcher {
int32 idb_database_id);
void OnIndexedDatabaseOpenError(int32 response_id, int code,
const string16& message);
+ void OnIDBDatabaseCreateObjectStoreSuccess(int32 response_id,
+ int32 idb_object_store_id);
+ void OnIDBDatabaseCreateObjectStoreError(int32 response_id, int code,
+ const string16& message);
// Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be
// destroyed and used on the same thread it was created on.
IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer>
indexed_database_open_callbacks_;
+ IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer>
+ idb_database_create_object_store_callbacks_;
DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
};
diff --git a/chrome/renderer/renderer_webidbdatabase_impl.cc b/chrome/renderer/renderer_webidbdatabase_impl.cc
index bc28210..140b16f 100644
--- a/chrome/renderer/renderer_webidbdatabase_impl.cc
+++ b/chrome/renderer/renderer_webidbdatabase_impl.cc
@@ -7,8 +7,11 @@
#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/indexed_db_dispatcher.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
using WebKit::WebDOMStringList;
+using WebKit::WebFrame;
+using WebKit::WebIDBCallbacks;
using WebKit::WebString;
using WebKit::WebVector;
@@ -55,3 +58,12 @@ WebDOMStringList RendererWebIDBDatabaseImpl::objectStores() {
}
return webResult;
}
+
+void RendererWebIDBDatabaseImpl::createObjectStore(
+ const WebString& name, const WebString& key_path, bool auto_increment,
+ WebIDBCallbacks* callbacks) {
+ IndexedDBDispatcher* dispatcher =
+ RenderThread::current()->indexed_db_dispatcher();
+ dispatcher->RequestIDBDatabaseCreateObjectStore(
+ name, key_path, auto_increment, callbacks, idb_database_id_);
+}
diff --git a/chrome/renderer/renderer_webidbdatabase_impl.h b/chrome/renderer/renderer_webidbdatabase_impl.h
index b0dfa9a..4c21ada 100644
--- a/chrome/renderer/renderer_webidbdatabase_impl.h
+++ b/chrome/renderer/renderer_webidbdatabase_impl.h
@@ -9,6 +9,12 @@
#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h"
+namespace WebKit {
+class WebFrame;
+class WebIDBCallbacks;
+class WebString;
+}
+
class RendererWebIDBDatabaseImpl : public WebKit::WebIDBDatabase {
public:
explicit RendererWebIDBDatabaseImpl(int32 idb_database_id);
@@ -19,6 +25,9 @@ class RendererWebIDBDatabaseImpl : public WebKit::WebIDBDatabase {
virtual WebKit::WebString description();
virtual WebKit::WebString version();
virtual WebKit::WebDOMStringList objectStores();
+ virtual void createObjectStore(
+ const WebKit::WebString& name, const WebKit::WebString& key_path,
+ bool auto_increment, WebKit::WebIDBCallbacks* callbacks);
private:
int32 idb_database_id_;
diff --git a/chrome/renderer/renderer_webidbobjectstore_impl.cc b/chrome/renderer/renderer_webidbobjectstore_impl.cc
new file mode 100644
index 0000000..70e0840
--- /dev/null
+++ b/chrome/renderer/renderer_webidbobjectstore_impl.cc
@@ -0,0 +1,38 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/renderer_webidbobjectstore_impl.h"
+
+#include "chrome/common/render_messages.h"
+#include "chrome/renderer/indexed_db_dispatcher.h"
+#include "chrome/renderer/render_thread.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+
+using WebKit::WebFrame;
+using WebKit::WebIDBCallbacks;
+using WebKit::WebString;
+
+RendererWebIDBObjectStoreImpl::RendererWebIDBObjectStoreImpl(
+ int32 idb_object_store_id)
+ : idb_object_store_id_(idb_object_store_id) {
+}
+
+RendererWebIDBObjectStoreImpl::~RendererWebIDBObjectStoreImpl() {
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBObjectStoreDestroyed(idb_object_store_id_));
+}
+
+WebString RendererWebIDBObjectStoreImpl::name() const {
+ string16 result;
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBObjectStoreName(idb_object_store_id_, &result));
+ return result;
+}
+
+WebString RendererWebIDBObjectStoreImpl::keyPath() const {
+ string16 result;
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBObjectStoreKeyPath(idb_object_store_id_, &result));
+ return result;
+}
diff --git a/chrome/renderer/renderer_webidbobjectstore_impl.h b/chrome/renderer/renderer_webidbobjectstore_impl.h
new file mode 100644
index 0000000..ecada92
--- /dev/null
+++ b/chrome/renderer/renderer_webidbobjectstore_impl.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_RENDERER_WEBIDBOBJECTSTORE_IMPL_H_
+#define CHROME_RENDERER_RENDERER_WEBIDBOBJECTSTORE_IMPL_H_
+
+#include "base/basictypes.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBObjectStore.h"
+
+namespace WebKit {
+class WebFrame;
+class WebIDBCallbacks;
+class WebString;
+}
+
+class RendererWebIDBObjectStoreImpl : public WebKit::WebIDBObjectStore {
+ public:
+ explicit RendererWebIDBObjectStoreImpl(int32 idb_object_store_id);
+ virtual ~RendererWebIDBObjectStoreImpl();
+
+ // WebKit::WebIDBObjectStore
+ virtual WebKit::WebString name() const;
+ virtual WebKit::WebString keyPath() const;
+
+ private:
+ int32 idb_object_store_id_;
+};
+
+#endif // CHROME_RENDERER_RENDERER_WEBIDBOBJECTSTORE_IMPL_H_