summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_callbacks.h64
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc107
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h14
-rw-r--r--chrome/common/render_messages.h52
-rwxr-xr-xchrome/common/render_messages_internal.h55
-rw-r--r--chrome/renderer/indexed_db_dispatcher.cc107
-rw-r--r--chrome/renderer/indexed_db_dispatcher.h33
-rw-r--r--chrome/renderer/renderer_webidbobjectstore_impl.cc45
-rw-r--r--chrome/renderer/renderer_webidbobjectstore_impl.h10
9 files changed, 413 insertions, 74 deletions
diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.h b/chrome/browser/in_process_webkit/indexed_db_callbacks.h
index 8b845d8..56c5fd5 100644
--- a/chrome/browser/in_process_webkit/indexed_db_callbacks.h
+++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.h
@@ -9,31 +9,81 @@
#include "base/logging.h"
#include "base/ref_counted.h"
#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h"
+#include "chrome/common/render_messages.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h"
+// Template magic to figure out what message to send to the renderer based on
+// which (overloaded) onSuccess method we expect to be called.
+template <class Type> struct WebIDBToMsgHelper { };
+template <> struct WebIDBToMsgHelper<WebKit::WebIDBDatabase> {
+ typedef ViewMsg_IDBCallbackSuccessCreateIDBDatabase MsgType;
+};
+template <> struct WebIDBToMsgHelper<WebKit::WebIDBIndex> {
+ typedef ViewMsg_IDBCallbackSuccessCreateIDBIndex MsgType;
+};
+template <> struct WebIDBToMsgHelper<WebKit::WebIDBObjectStore> {
+ typedef ViewMsg_IDBCallbackSuccessCreateIDBObjectStore MsgType;
+};
-template <class WebObjectType, typename SuccessMsgType, typename ErrorMsgType>
-class IndexedDBCallbacks : public WebKit::WebIDBCallbacks {
+// The code the following two classes share.
+class IndexedDBCallbacksBase : public WebKit::WebIDBCallbacks {
public:
- IndexedDBCallbacks(
+ IndexedDBCallbacksBase(
IndexedDBDispatcherHost* dispatcher_host, int32 response_id)
: dispatcher_host_(dispatcher_host), response_id_(response_id) { }
virtual void onError(const WebKit::WebIDBDatabaseError& error) {
- dispatcher_host_->Send(new ErrorMsgType(
+ dispatcher_host_->Send(new ViewMsg_IDBCallbackError(
response_id_, error.code(), error.message()));
}
- virtual void onSuccess(WebObjectType* idb_object) {
- int32 object_id = dispatcher_host_->Add(idb_object);
- dispatcher_host_->Send(new SuccessMsgType(response_id_, object_id));
+ protected:
+ IndexedDBDispatcherHost* dispatcher_host() const {
+ return dispatcher_host_.get();
}
+ int32 response_id() const { return response_id_; }
private:
scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
int32 response_id_;
+ DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase);
+};
+
+// A WebIDBCallbacks implementation that returns an object of WebObjectType.
+template <class WebObjectType>
+class IndexedDBCallbacks : public IndexedDBCallbacksBase {
+ public:
+ IndexedDBCallbacks(
+ IndexedDBDispatcherHost* dispatcher_host, int32 response_id)
+ : IndexedDBCallbacksBase(dispatcher_host, response_id) { }
+
+ virtual void onSuccess(WebObjectType* idb_object) {
+ int32 object_id = dispatcher_host()->Add(idb_object);
+ dispatcher_host()->Send(
+ new typename WebIDBToMsgHelper<WebObjectType>::MsgType(response_id(),
+ object_id));
+ }
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
+};
+
+// A WebIDBCallbacks implementation that doesn't return a result.
+template <>
+class IndexedDBCallbacks<void> : public IndexedDBCallbacksBase {
+ public:
+ IndexedDBCallbacks(
+ IndexedDBDispatcherHost* dispatcher_host, int32 response_id)
+ : IndexedDBCallbacksBase(dispatcher_host, response_id) { }
+
+ virtual void onSuccess() {
+ dispatcher_host()->Send(
+ new ViewMsg_IDBCallbackSuccessReturnNull(response_id()));
+ }
+
+ private:
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 bc29792..8c1b69e 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
@@ -158,6 +158,10 @@ int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database) {
return database_dispatcher_host_->map_.Add(idb_database);
}
+int32 IndexedDBDispatcherHost::Add(WebIDBIndex* idb_index) {
+ return index_dispatcher_host_->map_.Add(idb_index);
+}
+
int32 IndexedDBDispatcherHost::Add(WebIDBObjectStore* idb_object_store) {
return object_store_dispatcher_host_->map_.Add(idb_object_store);
}
@@ -170,10 +174,7 @@ void IndexedDBDispatcherHost::OnIndexedDatabaseOpen(
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
Context()->GetIndexedDatabase()->open(
params.name_, params.description_,
- new IndexedDBCallbacks<WebIDBDatabase,
- ViewMsg_IndexedDatabaseOpenSuccess,
- ViewMsg_IndexedDatabaseOpenError>(
- this, params.response_id_),
+ new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id_),
WebSecurityOrigin::createFromDatabaseIdentifier(params.origin_), NULL);
}
@@ -245,6 +246,10 @@ bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
OnObjectStores)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseCreateObjectStore,
OnCreateObjectStore)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseObjectStore,
+ OnObjectStore)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseRemoveObjectStore,
+ OnRemoveObjectStore)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseDestroyed, OnDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -287,6 +292,7 @@ void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObjectStores(
WebDOMStringList web_object_stores = idb_database->objectStores();
std::vector<string16> object_stores;
+ object_stores.reserve(web_object_stores.length());
for (unsigned i = 0; i < web_object_stores.length(); ++i)
object_stores[i] = web_object_stores.item(i);
ViewHostMsg_IDBDatabaseObjectStores::WriteReplyParams(reply_msg,
@@ -299,15 +305,40 @@ void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
&map_, params.idb_database_id_, NULL,
- ViewHostMsg_IDBDatabaseObjectStores::ID);
+ ViewHostMsg_IDBDatabaseCreateObjectStore::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_));
+ new IndexedDBCallbacks<WebIDBObjectStore>(parent_, params.response_id_));
+}
+
+void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObjectStore(
+ int32 idb_database_id, const string16& name, int32 mode,
+ IPC::Message* reply_msg) {
+ WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
+ &map_, idb_database_id, reply_msg,
+ ViewHostMsg_IDBDatabaseObjectStore::ID);
+ if (!idb_database)
+ return;
+
+ WebIDBObjectStore* object_store = idb_database->objectStore(name, mode);
+ int32 object_id = object_store ? parent_->Add(object_store) : 0;
+ ViewHostMsg_IDBDatabaseObjectStore::WriteReplyParams(
+ reply_msg, !!object_store, object_id);
+ parent_->Send(reply_msg);
+}
+
+void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRemoveObjectStore(
+ int32 idb_database_id, int32 response_id, const string16& name) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
+ &map_, idb_database_id, NULL,
+ ViewHostMsg_IDBDatabaseRemoveObjectStore::ID);
+ if (!idb_database)
+ return;
+ idb_database->removeObjectStore(
+ name, new IndexedDBCallbacks<WebIDBObjectStore>(parent_, response_id));
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
@@ -421,6 +452,64 @@ void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnKeyPath(
&map_, object_id, reply_msg, &WebIDBObjectStore::keyPath);
}
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndexNames(
+ int32 idb_object_store_id, IPC::Message* reply_msg) {
+ WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
+ &map_, idb_object_store_id, reply_msg,
+ ViewHostMsg_IDBObjectStoreIndexNames::ID);
+ if (!idb_object_store)
+ return;
+
+ WebDOMStringList web_index_names = idb_object_store->indexNames();
+ std::vector<string16> index_names;
+ index_names.reserve(web_index_names.length());
+ for (unsigned i = 0; i < web_index_names.length(); ++i)
+ index_names[i] = web_index_names.item(i);
+ ViewHostMsg_IDBObjectStoreIndexNames::WriteReplyParams(reply_msg,
+ index_names);
+ parent_->Send(reply_msg);
+}
+
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnCreateIndex(
+ const ViewHostMsg_IDBObjectStoreCreateIndex_Params& params) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
+ &map_, params.idb_object_store_id_, NULL,
+ ViewHostMsg_IDBObjectStoreCreateIndex::ID);
+ if (!idb_object_store)
+ return;
+ idb_object_store->createIndex(
+ params.name_, params.keypath_, params.unique_,
+ new IndexedDBCallbacks<WebIDBIndex>(parent_, params.response_id_));
+}
+
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndex(
+ int32 idb_object_store_id, const string16& name, IPC::Message* reply_msg) {
+ WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
+ &map_, idb_object_store_id, reply_msg,
+ ViewHostMsg_IDBObjectStoreIndex::ID);
+ if (!idb_object_store)
+ return;
+
+ WebIDBIndex* index = idb_object_store->index(name);
+ int32 object_id = index ? parent_->Add(index) : 0;
+ ViewHostMsg_IDBObjectStoreIndex::WriteReplyParams(reply_msg, !!index,
+ object_id);
+ parent_->Send(reply_msg);
+}
+
+void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnRemoveIndex(
+ int32 idb_object_store_id, int32 response_id, const string16& name) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
+ &map_, idb_object_store_id, NULL,
+ ViewHostMsg_IDBObjectStoreRemoveIndex::ID);
+ if (!idb_object_store)
+ return;
+ idb_object_store->removeIndex(
+ name, new IndexedDBCallbacks<void>(parent_, response_id));
+}
+
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(
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 94be909..368e489 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
@@ -14,6 +14,7 @@
struct ViewHostMsg_IndexedDatabaseOpen_Params;
struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params;
+struct ViewHostMsg_IDBObjectStoreCreateIndex_Params;
namespace WebKit {
class WebIDBDatabase;
@@ -51,6 +52,7 @@ class IndexedDBDispatcherHost
// The various IndexedDBCallbacks children call these methods to add the
// results into the applicable map. See below for more details.
int32 Add(WebKit::WebIDBDatabase* idb_database);
+ int32 Add(WebKit::WebIDBIndex* idb_index);
int32 Add(WebKit::WebIDBObjectStore* idb_object_store);
private:
@@ -91,7 +93,10 @@ class IndexedDBDispatcherHost
void OnObjectStores(int32 idb_database_id, IPC::Message* reply_msg);
void OnCreateObjectStore(
const ViewHostMsg_IDBDatabaseCreateObjectStore_Params& params);
-
+ void OnObjectStore(int32 idb_database_id, const string16& name, int32 mode,
+ IPC::Message* reply_msg);
+ void OnRemoveObjectStore(int32 idb_database_id, int32 response_id,
+ const string16& name);
void OnDestroyed(int32 idb_database_id);
IndexedDBDispatcherHost* parent_;
@@ -125,6 +130,13 @@ class IndexedDBDispatcherHost
void OnName(int32 idb_object_store_id, IPC::Message* reply_msg);
void OnKeyPath(int32 idb_object_store_id, IPC::Message* reply_msg);
+ void OnIndexNames(int32 idb_object_store_id, IPC::Message* reply_msg);
+ void OnCreateIndex(
+ const ViewHostMsg_IDBObjectStoreCreateIndex_Params& params);
+ void OnIndex(int32 idb_object_store_id, const string16& name,
+ IPC::Message* reply_msg);
+ void OnRemoveIndex(int32 idb_object_store_id, int32 response_id,
+ const string16& name);
void OnDestroyed(int32 idb_object_store_id);
IndexedDBDispatcherHost* parent_;
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 6a82112..e501a8b9 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -561,6 +561,24 @@ struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params {
int32 idb_database_id_;
};
+// Used to create an index.
+struct ViewHostMsg_IDBObjectStoreCreateIndex_Params {
+ // The response should have this id.
+ int32 response_id_;
+
+ // The name of the index.
+ string16 name_;
+
+ // The keyPath of the index.
+ string16 keypath_;
+
+ // Whether the index created has unique keys.
+ bool unique_;
+
+ // The object store the index belongs to.
+ int32 idb_object_store_id_;
+};
+
// Allows an extension to execute code in a tab.
struct ViewMsg_ExecuteCode_Params {
ViewMsg_ExecuteCode_Params() {}
@@ -2432,6 +2450,40 @@ struct ParamTraits<ViewHostMsg_IDBDatabaseCreateObjectStore_Params> {
}
};
+// Traits for ViewHostMsg_IDBObjectStoreCreateIndex_Params.
+template <>
+struct ParamTraits<ViewHostMsg_IDBObjectStoreCreateIndex_Params> {
+ typedef ViewHostMsg_IDBObjectStoreCreateIndex_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.unique_);
+ WriteParam(m, p.idb_object_store_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->unique_) &&
+ ReadParam(m, iter, &p->idb_object_store_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.unique_, l);
+ l->append(L", ");
+ LogParam(p.idb_object_store_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 39583a0..4596986 100755
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -845,20 +845,19 @@ IPC_BEGIN_MESSAGES(View)
IPC_MESSAGE_CONTROL1(ViewMsg_DOMStorageEvent,
ViewMsg_DOMStorageEvent_Params)
- // IndexedDatabase::open message responses.
- IPC_MESSAGE_CONTROL2(ViewMsg_IndexedDatabaseOpenSuccess,
+ // IDBCallback message handlers.
+ IPC_MESSAGE_CONTROL1(ViewMsg_IDBCallbackSuccessReturnNull,
+ int32 /* response_id */)
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbackSuccessCreateIDBDatabase,
int32 /* response_id */,
int32 /* idb_database_id */)
- IPC_MESSAGE_CONTROL3(ViewMsg_IndexedDatabaseOpenError,
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbackSuccessCreateIDBObjectStore,
int32 /* response_id */,
- int /* code */,
- string16 /* message */)
-
- // IDBDatabase::createObjectStore message responses.
- IPC_MESSAGE_CONTROL2(ViewMsg_IDBDatabaseCreateObjectStoreSuccess,
+ int32 /* idb_callback_id */)
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbackSuccessCreateIDBIndex,
int32 /* response_id */,
- int32 /* object_store_id */)
- IPC_MESSAGE_CONTROL3(ViewMsg_IDBDatabaseCreateObjectStoreError,
+ int32 /* idb_index_id */)
+ IPC_MESSAGE_CONTROL3(ViewMsg_IDBCallbackError,
int32 /* response_id */,
int /* code */,
string16 /* message */)
@@ -2208,6 +2207,20 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBDatabaseCreateObjectStore,
ViewHostMsg_IDBDatabaseCreateObjectStore_Params)
+ // WebIDBDatabase::objectStore() message.
+ IPC_SYNC_MESSAGE_CONTROL3_2(ViewHostMsg_IDBDatabaseObjectStore,
+ int32, /* idb_database_id */
+ string16, /* name */
+ int32, /* mode */
+ bool, /* success */
+ int32 /* idb_object_store_id */)
+
+ // WebIDBDatabase::removeObjectStore() message.
+ IPC_MESSAGE_CONTROL3(ViewHostMsg_IDBDatabaseRemoveObjectStore,
+ int32, /* idb_database_id */
+ int32, /* response_id */
+ string16 /* name */)
+
// WebIDBDatabase::~WebIDBDatabase() message.
IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBDatabaseDestroyed,
int32 /* idb_database_id */)
@@ -2241,6 +2254,28 @@ IPC_BEGIN_MESSAGES(ViewHost)
int32, /* idb_object_store_id */
string16 /* keyPath */)
+ // WebIDBObjectStore::indexNames() message.
+ IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_IDBObjectStoreIndexNames,
+ int32, /* idb_object_store_id */
+ std::vector<string16> /* index_names */)
+
+ // WebIDBObjectStore::createIndex() message.
+ IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBObjectStoreCreateIndex,
+ ViewHostMsg_IDBObjectStoreCreateIndex_Params)
+
+ // WebIDBObjectStore::index() message.
+ IPC_SYNC_MESSAGE_CONTROL2_2(ViewHostMsg_IDBObjectStoreIndex,
+ int32, /* idb_object_store_id */
+ string16, /* name */
+ bool, /* success */
+ int32 /* idb_index_id */)
+
+ // WebIDBObjectStore::removeIndex() message.
+ IPC_MESSAGE_CONTROL3(ViewHostMsg_IDBObjectStoreRemoveIndex,
+ int32, /* idb_object_store_id */
+ int32, /* response_id */
+ string16 /* name */)
+
// WebIDBObjectStore::~WebIDBObjectStore() message.
IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBObjectStoreDestroyed,
int32 /* idb_object_store_id */)
diff --git a/chrome/renderer/indexed_db_dispatcher.cc b/chrome/renderer/indexed_db_dispatcher.cc
index fcb5b68..8834b0a 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_webidbindex_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"
@@ -28,12 +29,16 @@ IndexedDBDispatcher::~IndexedDBDispatcher() {
bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg)
- IPC_MESSAGE_HANDLER(ViewMsg_IndexedDatabaseOpenSuccess,
- OnIndexedDatabaseOpenSuccess)
- IPC_MESSAGE_HANDLER(ViewMsg_IndexedDatabaseOpenError,
- OnIndexedDatabaseOpenError)
- IPC_MESSAGE_HANDLER(ViewMsg_IDBDatabaseCreateObjectStoreSuccess,
- OnIDBDatabaseCreateObjectStoreSuccess)
+ IPC_MESSAGE_HANDLER(ViewMsg_IDBCallbackSuccessReturnNull,
+ OnSuccessReturnNull)
+ IPC_MESSAGE_HANDLER(ViewMsg_IDBCallbackSuccessCreateIDBDatabase,
+ OnSuccessCreateIDBDatabase)
+ IPC_MESSAGE_HANDLER(ViewMsg_IDBCallbackSuccessCreateIDBObjectStore,
+ OnSuccessCreateIDBObjectStore)
+ IPC_MESSAGE_HANDLER(ViewMsg_IDBCallbackSuccessCreateIDBIndex,
+ OnSuccessCreateIDBIndex)
+ IPC_MESSAGE_HANDLER(ViewMsg_IDBCallbackError,
+ OnError)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -53,8 +58,7 @@ void IndexedDBDispatcher::RequestIndexedDatabaseOpen(
ViewHostMsg_IndexedDatabaseOpen_Params params;
params.routing_id_ = render_view->routing_id();
- params.response_id_ = indexed_database_open_callbacks_.Add(
- callbacks.release());
+ params.response_id_ = pending_callbacks_.Add(callbacks.release());
params.origin_ = origin;
params.name_ = name;
params.description_ = description;
@@ -67,8 +71,7 @@ void IndexedDBDispatcher::RequestIDBDatabaseCreateObjectStore(
scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
ViewHostMsg_IDBDatabaseCreateObjectStore_Params params;
- params.response_id_ = idb_database_create_object_store_callbacks_.Add(
- callbacks.release());
+ params.response_id_ = pending_callbacks_.Add(callbacks.release());
params.name_ = name;
params.keypath_ = keypath;
params.auto_increment_ = auto_increment;
@@ -77,34 +80,72 @@ void IndexedDBDispatcher::RequestIDBDatabaseCreateObjectStore(
new ViewHostMsg_IDBDatabaseCreateObjectStore(params));
}
-void IndexedDBDispatcher::OnIndexedDatabaseOpenSuccess(
- int32 response_id, int32 idb_database_id) {
- WebKit::WebIDBCallbacks* callbacks =
- indexed_database_open_callbacks_.Lookup(response_id);
- callbacks->onSuccess(new RendererWebIDBDatabaseImpl(idb_database_id));
- indexed_database_open_callbacks_.Remove(response_id);
+void IndexedDBDispatcher::RequestIDBDatabaseRemoveObjectStore(
+ const string16& name, WebIDBCallbacks* callbacks_ptr,
+ int32 idb_database_id) {
+ scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
+
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBDatabaseRemoveObjectStore(
+ idb_database_id, pending_callbacks_.Add(callbacks.release()), name));
}
-void IndexedDBDispatcher::OnIndexedDatabaseOpenError(
- int32 response_id, int code, const string16& message) {
- WebKit::WebIDBCallbacks* callbacks =
- indexed_database_open_callbacks_.Lookup(response_id);
- callbacks->onError(WebIDBDatabaseError(code, message));
- indexed_database_open_callbacks_.Remove(response_id);
+void IndexedDBDispatcher::RequestIDBObjectStoreCreateIndex(
+ const string16& name, const string16& keypath, bool unique,
+ WebIDBCallbacks* callbacks_ptr, int32 idb_object_store_id) {
+ scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
+
+ ViewHostMsg_IDBObjectStoreCreateIndex_Params params;
+ params.response_id_ = pending_callbacks_.Add(callbacks.release());
+ params.name_ = name;
+ params.keypath_ = keypath;
+ params.unique_ = unique;
+ params.idb_object_store_id_ = idb_object_store_id;
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBObjectStoreCreateIndex(params));
+}
+
+void IndexedDBDispatcher::RequestIDBObjectStoreRemoveIndex(
+ const string16& name, WebIDBCallbacks* callbacks_ptr,
+ int32 idb_object_store_id) {
+ scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
+
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBObjectStoreRemoveIndex(
+ idb_object_store_id, pending_callbacks_.Add(callbacks.release()),
+ name));
+}
+
+void IndexedDBDispatcher::OnSuccessReturnNull(int32 response_id) {
+ WebKit::WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
+ callbacks->onSuccess();
+ pending_callbacks_.Remove(response_id);
+}
+
+void IndexedDBDispatcher::OnSuccessCreateIDBDatabase(int32 response_id,
+ int32 object_id) {
+ WebKit::WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
+ callbacks->onSuccess(new RendererWebIDBDatabaseImpl(object_id));
+ pending_callbacks_.Remove(response_id);
+}
+
+void IndexedDBDispatcher::OnSuccessCreateIDBObjectStore(int32 response_id,
+ int32 object_id) {
+ WebKit::WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
+ callbacks->onSuccess(new RendererWebIDBObjectStoreImpl(object_id));
+ pending_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::OnSuccessCreateIDBIndex(int32 response_id,
+ int32 object_id) {
+ WebKit::WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
+ callbacks->onSuccess(new RendererWebIDBIndexImpl(object_id));
+ pending_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);
+void IndexedDBDispatcher::OnError(int32 response_id, int code,
+ const string16& message) {
+ WebKit::WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
callbacks->onError(WebIDBDatabaseError(code, message));
- idb_database_create_object_store_callbacks_.Remove(response_id);
+ pending_callbacks_.Remove(response_id);
}
diff --git a/chrome/renderer/indexed_db_dispatcher.h b/chrome/renderer/indexed_db_dispatcher.h
index 13e4376..a9eb1cb 100644
--- a/chrome/renderer/indexed_db_dispatcher.h
+++ b/chrome/renderer/indexed_db_dispatcher.h
@@ -34,24 +34,29 @@ class IndexedDBDispatcher {
const string16& name, const string16& keypath, bool auto_increment,
WebKit::WebIDBCallbacks* callbacks, int32 idb_database_id);
+ void RequestIDBDatabaseRemoveObjectStore(
+ const string16& name, WebKit::WebIDBCallbacks* callbacks,
+ int32 idb_database_id);
+
+ void RequestIDBObjectStoreCreateIndex(
+ const string16& name, const string16& keypath, bool unique,
+ WebKit::WebIDBCallbacks* callbacks, int32 idb_object_store_id);
+
+ void RequestIDBObjectStoreRemoveIndex(
+ const string16& name, WebKit::WebIDBCallbacks* callbacks,
+ int32 idb_object_store_id);
+
private:
- // Message handlers. For each message we send, we need to handle both the
- // success and the error case.
- void OnIndexedDatabaseOpenSuccess(int32 response_id,
- 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);
+ // IDBCallback message handlers.
+ void OnSuccessReturnNull(int32 response_id);
+ void OnSuccessCreateIDBDatabase(int32 response_id, int32 object_id);
+ void OnSuccessCreateIDBObjectStore(int32 response_id, int32 object_id);
+ void OnSuccessCreateIDBIndex(int32 response_id, int32 object_id);
+ void OnError(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_;
+ IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_;
DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
};
diff --git a/chrome/renderer/renderer_webidbobjectstore_impl.cc b/chrome/renderer/renderer_webidbobjectstore_impl.cc
index 70e0840..79c0da8 100644
--- a/chrome/renderer/renderer_webidbobjectstore_impl.cc
+++ b/chrome/renderer/renderer_webidbobjectstore_impl.cc
@@ -7,10 +7,14 @@
#include "chrome/common/render_messages.h"
#include "chrome/renderer/indexed_db_dispatcher.h"
#include "chrome/renderer/render_thread.h"
+#include "chrome/renderer/renderer_webidbindex_impl.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDOMStringList.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+using WebKit::WebDOMStringList;
using WebKit::WebFrame;
using WebKit::WebIDBCallbacks;
+using WebKit::WebIDBIndex;
using WebKit::WebString;
RendererWebIDBObjectStoreImpl::RendererWebIDBObjectStoreImpl(
@@ -36,3 +40,44 @@ WebString RendererWebIDBObjectStoreImpl::keyPath() const {
new ViewHostMsg_IDBObjectStoreKeyPath(idb_object_store_id_, &result));
return result;
}
+
+WebDOMStringList RendererWebIDBObjectStoreImpl::indexNames() const {
+ std::vector<string16> result;
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBObjectStoreIndexNames(idb_object_store_id_, &result));
+ WebDOMStringList web_result;
+ for (std::vector<string16>::const_iterator it = result.begin();
+ it != result.end(); ++it) {
+ web_result.append(*it);
+ }
+ return web_result;
+}
+
+void RendererWebIDBObjectStoreImpl::createIndex(
+ const WebString& name, const WebString& key_path, bool unique,
+ WebIDBCallbacks* callbacks) {
+ IndexedDBDispatcher* dispatcher =
+ RenderThread::current()->indexed_db_dispatcher();
+ dispatcher->RequestIDBObjectStoreCreateIndex(
+ name, key_path, unique, callbacks, idb_object_store_id_);
+
+}
+
+WebIDBIndex* RendererWebIDBObjectStoreImpl::index(const WebString& name) {
+ bool success;
+ int32 idb_index_id;
+ RenderThread::current()->Send(
+ new ViewHostMsg_IDBObjectStoreIndex(idb_object_store_id_, name,
+ &success, &idb_index_id));
+ if (!success)
+ return NULL;
+ return new RendererWebIDBIndexImpl(idb_index_id);
+}
+
+void RendererWebIDBObjectStoreImpl::removeIndex(const WebString& name,
+ WebIDBCallbacks* callbacks) {
+ IndexedDBDispatcher* dispatcher =
+ RenderThread::current()->indexed_db_dispatcher();
+ dispatcher->RequestIDBObjectStoreRemoveIndex(name, callbacks,
+ idb_object_store_id_);
+}
diff --git a/chrome/renderer/renderer_webidbobjectstore_impl.h b/chrome/renderer/renderer_webidbobjectstore_impl.h
index ecada92..06625fd 100644
--- a/chrome/renderer/renderer_webidbobjectstore_impl.h
+++ b/chrome/renderer/renderer_webidbobjectstore_impl.h
@@ -12,6 +12,7 @@
namespace WebKit {
class WebFrame;
class WebIDBCallbacks;
+class WebIDBIndex;
class WebString;
}
@@ -23,6 +24,15 @@ class RendererWebIDBObjectStoreImpl : public WebKit::WebIDBObjectStore {
// WebKit::WebIDBObjectStore
virtual WebKit::WebString name() const;
virtual WebKit::WebString keyPath() const;
+ virtual WebKit::WebDOMStringList indexNames() const;
+
+ void createIndex(const WebKit::WebString& name,
+ const WebKit::WebString& key_path, bool unique,
+ WebKit::WebIDBCallbacks* callbacks);
+ // Transfers ownership of the WebIDBIndex to the caller.
+ WebKit::WebIDBIndex* index(const WebKit::WebString& name);
+ void removeIndex(const WebKit::WebString& name,
+ WebKit::WebIDBCallbacks* callbacks);
private:
int32 idb_object_store_id_;