summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 14:29:40 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 14:29:40 +0000
commit5c71640cdf15c2782b8331e9e2623da50ec5d102 (patch)
treeda7cf7505bb23c3e206bdcaab66f064d3edc5936 /chrome/common
parent699f2246bf56e1aadf31e1edd6c5aef9b4b39638 (diff)
downloadchromium_src-5c71640cdf15c2782b8331e9e2623da50ec5d102.zip
chromium_src-5c71640cdf15c2782b8331e9e2623da50ec5d102.tar.gz
chromium_src-5c71640cdf15c2782b8331e9e2623da50ec5d102.tar.bz2
The Chrome half of implementing get/put/remove for object stores (https://bugs.webkit.org/show_bug.cgi?id=41250).
TEST=none BUG=none Review URL: http://codereview.chromium.org/2830030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/indexed_db_key.cc54
-rw-r--r--chrome/common/indexed_db_key.h34
-rw-r--r--chrome/common/render_messages.h99
-rw-r--r--chrome/common/render_messages_internal.h42
-rw-r--r--chrome/common/serialized_script_value.cc37
-rw-r--r--chrome/common/serialized_script_value.h34
6 files changed, 284 insertions, 16 deletions
diff --git a/chrome/common/indexed_db_key.cc b/chrome/common/indexed_db_key.cc
new file mode 100644
index 0000000..1c09ea2
--- /dev/null
+++ b/chrome/common/indexed_db_key.cc
@@ -0,0 +1,54 @@
+// 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/common/indexed_db_key.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+
+using WebKit::WebIDBKey;
+
+IndexedDBKey::IndexedDBKey()
+ : type_(WebIDBKey::InvalidType) {
+}
+
+IndexedDBKey::IndexedDBKey(const WebIDBKey& key)
+ : type_(key.type()),
+ string_(key.type() == WebIDBKey::StringType
+ ? static_cast<string16>(key.string()) : string16()),
+ number_(key.type() == WebIDBKey::NumberType ? key.number() : 0) {
+}
+
+void IndexedDBKey::SetNull() {
+ type_ = WebIDBKey::NullType;
+}
+
+void IndexedDBKey::SetInvalid() {
+ type_ = WebIDBKey::InvalidType;
+}
+
+void IndexedDBKey::Set(const string16& string) {
+ type_ = WebIDBKey::StringType;
+ string_ = string;
+}
+
+void IndexedDBKey::Set(int32_t number) {
+ type_ = WebIDBKey::NumberType;
+ number_ = number;
+}
+
+IndexedDBKey::operator WebIDBKey() const {
+ switch (type_) {
+ case WebIDBKey::NullType:
+ return WebIDBKey::createNull();
+ case WebIDBKey::StringType:
+ return WebIDBKey(string_);
+ case WebIDBKey::NumberType:
+ return WebIDBKey(number_);
+ case WebIDBKey::InvalidType:
+ return WebIDBKey::createInvalid();
+ }
+ NOTREACHED();
+ return WebIDBKey::createInvalid();
+}
diff --git a/chrome/common/indexed_db_key.h b/chrome/common/indexed_db_key.h
new file mode 100644
index 0000000..13bfae3
--- /dev/null
+++ b/chrome/common/indexed_db_key.h
@@ -0,0 +1,34 @@
+// 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_COMMON_INDEXED_DB_KEY_H_
+#define CHROME_COMMON_INDEXED_DB_KEY_H_
+
+#include "base/basictypes.h"
+#include "base/string16.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebIDBKey.h"
+
+class IndexedDBKey {
+ public:
+ IndexedDBKey(); // Defaults to WebKit::WebIDBKey::InvalidType.
+ explicit IndexedDBKey(const WebKit::WebIDBKey& key);
+
+ void SetNull();
+ void SetInvalid();
+ void Set(const string16& string);
+ void Set(int32_t number);
+
+ WebKit::WebIDBKey::Type type() const { return type_; }
+ const string16& string() const { return string_; }
+ int32_t number() const { return number_; }
+
+ operator WebKit::WebIDBKey() const;
+
+ private:
+ WebKit::WebIDBKey::Type type_;
+ string16 string_;
+ int32_t number_;
+};
+
+#endif // CHROME_COMMON_INDEXED_DB_KEY_H_
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 96e8a4c..3a419cc2 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -23,12 +23,14 @@
#include "chrome/common/extensions/extension_extent.h"
#include "chrome/common/extensions/url_pattern.h"
#include "chrome/common/font_descriptor_mac.h"
+#include "chrome/common/indexed_db_key.h"
#include "chrome/common/navigation_gesture.h"
#include "chrome/common/page_transition_types.h"
#include "chrome/common/renderer_preferences.h"
#include "chrome/common/resource_response.h"
#include "chrome/common/translate_errors.h"
#include "chrome/common/view_types.h"
+#include "chrome/common/serialized_script_value.h"
#include "chrome/common/webkit_param_traits.h"
#include "chrome/common/window_container_type.h"
#include "gfx/native_widget_types.h"
@@ -569,7 +571,7 @@ struct ViewHostMsg_IDBDatabaseCreateObjectStore_Params {
string16 name_;
// The keyPath of the object store.
- string16 keypath_;
+ NullableString16 key_path_;
// Whether the object store created should have a key generator.
bool auto_increment_;
@@ -587,7 +589,7 @@ struct ViewHostMsg_IDBObjectStoreCreateIndex_Params {
string16 name_;
// The keyPath of the index.
- string16 keypath_;
+ NullableString16 key_path_;
// Whether the index created has unique keys.
bool unique_;
@@ -1586,6 +1588,87 @@ struct ParamTraits<SyncLoadResult> {
}
};
+template <>
+struct ParamTraits<SerializedScriptValue> {
+ typedef SerializedScriptValue param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.is_null());
+ WriteParam(m, p.is_invalid());
+ WriteParam(m, p.data());
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ bool is_null;
+ bool is_invalid;
+ string16 data;
+ bool ok =
+ ReadParam(m, iter, &is_null) &&
+ ReadParam(m, iter, &is_invalid) &&
+ ReadParam(m, iter, &data);
+ if (!ok)
+ return false;
+ r->set_is_null(is_null);
+ r->set_is_invalid(is_invalid);
+ r->set_data(data);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"<SerializedScriptValue>(");
+ LogParam(p.is_null(), l);
+ l->append(L", ");
+ LogParam(p.is_invalid(), l);
+ l->append(L", ");
+ LogParam(p.data(), l);
+ l->append(L")");
+ }
+};
+
+template <>
+struct ParamTraits<IndexedDBKey> {
+ typedef IndexedDBKey param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, int(p.type()));
+ // TODO(jorlow): Technically, we only need to pack the type being used.
+ WriteParam(m, p.string());
+ WriteParam(m, p.number());
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int type;
+ string16 string;
+ int32 number;
+ bool ok =
+ ReadParam(m, iter, &type) &&
+ ReadParam(m, iter, &string) &&
+ ReadParam(m, iter, &number);
+ if (!ok)
+ return false;
+ switch (type) {
+ case WebKit::WebIDBKey::NullType:
+ r->SetNull();
+ return true;
+ case WebKit::WebIDBKey::StringType:
+ r->Set(string);
+ return true;
+ case WebKit::WebIDBKey::NumberType:
+ r->Set(number);
+ return true;
+ case WebKit::WebIDBKey::InvalidType:
+ r->SetInvalid();
+ return true;
+ }
+ NOTREACHED();
+ return false;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"<IndexedDBKey>(");
+ LogParam(int(p.type()), l);
+ l->append(L", ");
+ LogParam(p.string(), l);
+ l->append(L", ");
+ LogParam(p.number(), l);
+ l->append(L")");
+ }
+};
+
// Traits for FormData structure to pack/unpack.
template <>
struct ParamTraits<webkit_glue::FormData> {
@@ -2553,7 +2636,7 @@ struct ParamTraits<ViewHostMsg_IDBDatabaseCreateObjectStore_Params> {
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.key_path_);
WriteParam(m, p.auto_increment_);
WriteParam(m, p.idb_database_id_);
}
@@ -2561,7 +2644,7 @@ struct ParamTraits<ViewHostMsg_IDBDatabaseCreateObjectStore_Params> {
return
ReadParam(m, iter, &p->response_id_) &&
ReadParam(m, iter, &p->name_) &&
- ReadParam(m, iter, &p->keypath_) &&
+ ReadParam(m, iter, &p->key_path_) &&
ReadParam(m, iter, &p->auto_increment_) &&
ReadParam(m, iter, &p->idb_database_id_);
}
@@ -2571,7 +2654,7 @@ struct ParamTraits<ViewHostMsg_IDBDatabaseCreateObjectStore_Params> {
l->append(L", ");
LogParam(p.name_, l);
l->append(L", ");
- LogParam(p.keypath_, l);
+ LogParam(p.key_path_, l);
l->append(L", ");
LogParam(p.auto_increment_, l);
l->append(L", ");
@@ -2587,7 +2670,7 @@ struct ParamTraits<ViewHostMsg_IDBObjectStoreCreateIndex_Params> {
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.key_path_);
WriteParam(m, p.unique_);
WriteParam(m, p.idb_object_store_id_);
}
@@ -2595,7 +2678,7 @@ struct ParamTraits<ViewHostMsg_IDBObjectStoreCreateIndex_Params> {
return
ReadParam(m, iter, &p->response_id_) &&
ReadParam(m, iter, &p->name_) &&
- ReadParam(m, iter, &p->keypath_) &&
+ ReadParam(m, iter, &p->key_path_) &&
ReadParam(m, iter, &p->unique_) &&
ReadParam(m, iter, &p->idb_object_store_id_);
}
@@ -2605,7 +2688,7 @@ struct ParamTraits<ViewHostMsg_IDBObjectStoreCreateIndex_Params> {
l->append(L", ");
LogParam(p.name_, l);
l->append(L", ");
- LogParam(p.keypath_, l);
+ LogParam(p.key_path_, l);
l->append(L", ");
LogParam(p.unique_, l);
l->append(L", ");
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 2cb4bed..7b66469 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -842,18 +842,24 @@ IPC_BEGIN_MESSAGES(View)
ViewMsg_DOMStorageEvent_Params)
// IDBCallback message handlers.
- IPC_MESSAGE_CONTROL1(ViewMsg_IDBCallbackSuccessReturnNull,
+ IPC_MESSAGE_CONTROL1(ViewMsg_IDBCallbacksSuccessNull,
int32 /* response_id */)
- IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbackSuccessCreateIDBDatabase,
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbacksSuccessIDBDatabase,
int32 /* response_id */,
int32 /* idb_database_id */)
- IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbackSuccessCreateIDBObjectStore,
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbacksSuccessIndexedDBKey,
int32 /* response_id */,
- int32 /* idb_callback_id */)
- IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbackSuccessCreateIDBIndex,
+ IndexedDBKey /* indexed_db_key */)
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbacksSuccessIDBObjectStore,
+ int32 /* response_id */,
+ int32 /* idb_object_store_id */)
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbacksSuccessIDBIndex,
int32 /* response_id */,
int32 /* idb_index_id */)
- IPC_MESSAGE_CONTROL3(ViewMsg_IDBCallbackError,
+ IPC_MESSAGE_CONTROL2(ViewMsg_IDBCallbacksSuccessSerializedScriptValue,
+ int32 /* response_id */,
+ SerializedScriptValue /* serialized_script_value */)
+ IPC_MESSAGE_CONTROL3(ViewMsg_IDBCallbacksError,
int32 /* response_id */,
int /* code */,
string16 /* message */)
@@ -2229,7 +2235,7 @@ IPC_BEGIN_MESSAGES(ViewHost)
// WebIDBIndex::keyPath() message.
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_IDBIndexKeyPath,
int32, /* idb_index_id */
- string16 /* key_path */)
+ NullableString16 /* key_path */)
// WebIDBIndex::unique() message.
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_IDBIndexUnique,
@@ -2248,13 +2254,33 @@ IPC_BEGIN_MESSAGES(ViewHost)
// WebIDBObjectStore::keyPath() message.
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_IDBObjectStoreKeyPath,
int32, /* idb_object_store_id */
- string16 /* keyPath */)
+ NullableString16 /* keyPath */)
// WebIDBObjectStore::indexNames() message.
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_IDBObjectStoreIndexNames,
int32, /* idb_object_store_id */
std::vector<string16> /* index_names */)
+ // WebIDBObjectStore::get() message.
+ IPC_MESSAGE_CONTROL3(ViewHostMsg_IDBObjectStoreGet,
+ int32, /* idb_object_store_id */
+ int32, /* response_id */
+ IndexedDBKey /* key */)
+
+ // WebIDBObjectStore::put() message.
+ IPC_MESSAGE_CONTROL5(ViewHostMsg_IDBObjectStorePut,
+ int32, /* idb_object_store_id */
+ int32, /* response_id */
+ SerializedScriptValue, /* serialized_value */
+ IndexedDBKey, /* key */
+ bool /* add_only */)
+
+ // WebIDBObjectStore::remove() message.
+ IPC_MESSAGE_CONTROL3(ViewHostMsg_IDBObjectStoreRemove,
+ int32, /* idb_object_store_id */
+ int32, /* response_id */
+ IndexedDBKey /* key */)
+
// WebIDBObjectStore::createIndex() message.
IPC_MESSAGE_CONTROL1(ViewHostMsg_IDBObjectStoreCreateIndex,
ViewHostMsg_IDBObjectStoreCreateIndex_Params)
diff --git a/chrome/common/serialized_script_value.cc b/chrome/common/serialized_script_value.cc
new file mode 100644
index 0000000..095f4e6
--- /dev/null
+++ b/chrome/common/serialized_script_value.cc
@@ -0,0 +1,37 @@
+// 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/common/serialized_script_value.h"
+
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+
+using WebKit::WebSerializedScriptValue;
+
+SerializedScriptValue::SerializedScriptValue()
+ : is_null_(true),
+ is_invalid_(false) {
+}
+
+SerializedScriptValue::SerializedScriptValue(
+ bool is_null, bool is_invalid, const string16& data)
+ : is_null_(is_null),
+ is_invalid_(is_invalid),
+ data_(data) {
+}
+
+SerializedScriptValue::SerializedScriptValue(
+ const WebSerializedScriptValue& value)
+ : is_null_(value.isNull()),
+ is_invalid_(value.isNull() ? false : value.toString().isNull()),
+ data_(value.isNull() ? string16()
+ : static_cast<string16>(value.toString())) {
+}
+
+SerializedScriptValue::operator WebSerializedScriptValue() const {
+ if (is_null_)
+ return WebSerializedScriptValue();
+ if (is_invalid_)
+ return WebSerializedScriptValue::createInvalid();
+ return WebSerializedScriptValue::fromString(data_);
+}
diff --git a/chrome/common/serialized_script_value.h b/chrome/common/serialized_script_value.h
new file mode 100644
index 0000000..e464134
--- /dev/null
+++ b/chrome/common/serialized_script_value.h
@@ -0,0 +1,34 @@
+// 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_COMMON_SERIALIZED_SCRIPT_VALUE_H_
+#define CHROME_COMMON_SERIALIZED_SCRIPT_VALUE_H_
+
+#include "base/string16.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebSerializedScriptValue.h"
+
+class SerializedScriptValue {
+ public:
+ SerializedScriptValue();
+ SerializedScriptValue(bool is_null, bool is_invalid, const string16& data);
+ explicit SerializedScriptValue(const WebKit::WebSerializedScriptValue& value);
+
+ void set_is_null(bool is_null) { is_null_ = is_null; }
+ bool is_null() const { return is_null_; }
+
+ void set_is_invalid(bool is_invalid) { is_invalid_ = is_invalid; }
+ bool is_invalid() const { return is_invalid_; }
+
+ void set_data(const string16& data) { data_ = data; }
+ const string16& data() const { return data_; }
+
+ operator WebKit::WebSerializedScriptValue() const;
+
+ private:
+ bool is_null_; // Is this null? If so, none of the other properties are valid.
+ bool is_invalid_; // Is data_ valid?
+ string16 data_; // The wire string format of the serialized script value.
+};
+
+#endif // CHROME_COMMON_SERIALIZED_SCRIPT_VALUE_H_