| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/renderer_webidbdatabase_impl.h" | |
| 6 | |
| 7 #include "chrome/renderer/render_thread.h" | |
| 8 #include "chrome/renderer/renderer_webidbobjectstore_impl.h" | |
| 9 #include "chrome/renderer/renderer_webidbtransaction_impl.h" | |
| 10 #include "content/common/indexed_db_messages.h" | |
| 11 #include "content/renderer/indexed_db_dispatcher.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | |
| 14 | |
| 15 using WebKit::WebDOMStringList; | |
| 16 using WebKit::WebExceptionCode; | |
| 17 using WebKit::WebFrame; | |
| 18 using WebKit::WebIDBCallbacks; | |
| 19 using WebKit::WebIDBDatabaseCallbacks; | |
| 20 using WebKit::WebIDBTransaction; | |
| 21 using WebKit::WebString; | |
| 22 using WebKit::WebVector; | |
| 23 | |
| 24 RendererWebIDBDatabaseImpl::RendererWebIDBDatabaseImpl(int32 idb_database_id) | |
| 25 : idb_database_id_(idb_database_id) { | |
| 26 } | |
| 27 | |
| 28 RendererWebIDBDatabaseImpl::~RendererWebIDBDatabaseImpl() { | |
| 29 // It's not possible for there to be pending callbacks that address this | |
| 30 // object since inside WebKit, they hold a reference to the object which owns | |
| 31 // this object. But, if that ever changed, then we'd need to invalidate | |
| 32 // any such pointers. | |
| 33 RenderThread::current()->Send(new IndexedDBHostMsg_DatabaseDestroyed( | |
| 34 idb_database_id_)); | |
| 35 } | |
| 36 | |
| 37 WebString RendererWebIDBDatabaseImpl::name() const { | |
| 38 string16 result; | |
| 39 RenderThread::current()->Send( | |
| 40 new IndexedDBHostMsg_DatabaseName(idb_database_id_, &result)); | |
| 41 return result; | |
| 42 } | |
| 43 | |
| 44 WebString RendererWebIDBDatabaseImpl::version() const { | |
| 45 string16 result; | |
| 46 RenderThread::current()->Send( | |
| 47 new IndexedDBHostMsg_DatabaseVersion(idb_database_id_, &result)); | |
| 48 return result; | |
| 49 } | |
| 50 | |
| 51 WebDOMStringList RendererWebIDBDatabaseImpl::objectStoreNames() const { | |
| 52 std::vector<string16> result; | |
| 53 RenderThread::current()->Send( | |
| 54 new IndexedDBHostMsg_DatabaseObjectStoreNames(idb_database_id_, &result)); | |
| 55 WebDOMStringList webResult; | |
| 56 for (std::vector<string16>::const_iterator it = result.begin(); | |
| 57 it != result.end(); ++it) { | |
| 58 webResult.append(*it); | |
| 59 } | |
| 60 return webResult; | |
| 61 } | |
| 62 | |
| 63 WebKit::WebIDBObjectStore* RendererWebIDBDatabaseImpl::createObjectStore( | |
| 64 const WebKit::WebString& name, | |
| 65 const WebKit::WebString& key_path, | |
| 66 bool auto_increment, | |
| 67 const WebKit::WebIDBTransaction& transaction, | |
| 68 WebExceptionCode& ec) { | |
| 69 IndexedDBHostMsg_DatabaseCreateObjectStore_Params params; | |
| 70 params.name = name; | |
| 71 params.key_path = key_path; | |
| 72 params.auto_increment = auto_increment; | |
| 73 params.transaction_id = IndexedDBDispatcher::TransactionId(transaction); | |
| 74 params.idb_database_id = idb_database_id_; | |
| 75 | |
| 76 int object_store; | |
| 77 RenderThread::current()->Send( | |
| 78 new IndexedDBHostMsg_DatabaseCreateObjectStore( | |
| 79 params, &object_store, &ec)); | |
| 80 if (!object_store) | |
| 81 return NULL; | |
| 82 return new RendererWebIDBObjectStoreImpl(object_store); | |
| 83 } | |
| 84 | |
| 85 void RendererWebIDBDatabaseImpl::deleteObjectStore( | |
| 86 const WebString& name, | |
| 87 const WebIDBTransaction& transaction, | |
| 88 WebExceptionCode& ec) { | |
| 89 RenderThread::current()->Send( | |
| 90 new IndexedDBHostMsg_DatabaseDeleteObjectStore( | |
| 91 idb_database_id_, name, | |
| 92 IndexedDBDispatcher::TransactionId(transaction), &ec)); | |
| 93 } | |
| 94 | |
| 95 void RendererWebIDBDatabaseImpl::setVersion( | |
| 96 const WebString& version, | |
| 97 WebIDBCallbacks* callbacks, | |
| 98 WebExceptionCode& ec) { | |
| 99 IndexedDBDispatcher* dispatcher = | |
| 100 RenderThread::current()->indexed_db_dispatcher(); | |
| 101 dispatcher->RequestIDBDatabaseSetVersion( | |
| 102 version, callbacks, idb_database_id_, &ec); | |
| 103 } | |
| 104 | |
| 105 WebKit::WebIDBTransaction* RendererWebIDBDatabaseImpl::transaction( | |
| 106 const WebDOMStringList& names, | |
| 107 unsigned short mode, | |
| 108 unsigned long timeout, | |
| 109 WebExceptionCode& ec) { | |
| 110 std::vector<string16> object_stores; | |
| 111 object_stores.reserve(names.length()); | |
| 112 for (unsigned int i = 0; i < names.length(); ++i) | |
| 113 object_stores.push_back(names.item(i)); | |
| 114 | |
| 115 int transaction_id; | |
| 116 RenderThread::current()->Send( | |
| 117 new IndexedDBHostMsg_DatabaseTransaction( | |
| 118 idb_database_id_, object_stores, mode, | |
| 119 timeout, &transaction_id, &ec)); | |
| 120 if (!transaction_id) | |
| 121 return NULL; | |
| 122 return new RendererWebIDBTransactionImpl(transaction_id); | |
| 123 } | |
| 124 | |
| 125 void RendererWebIDBDatabaseImpl::close() { | |
| 126 IndexedDBDispatcher* dispatcher = | |
| 127 RenderThread::current()->indexed_db_dispatcher(); | |
| 128 dispatcher->RequestIDBDatabaseClose(idb_database_id_); | |
| 129 } | |
| 130 | |
| 131 void RendererWebIDBDatabaseImpl::open(WebIDBDatabaseCallbacks* callbacks) { | |
| 132 IndexedDBDispatcher* dispatcher = | |
| 133 RenderThread::current()->indexed_db_dispatcher(); | |
| 134 dispatcher->RequestIDBDatabaseOpen(callbacks, idb_database_id_); | |
| 135 } | |
| OLD | NEW |