[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 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 | |
[email protected] | acb9472 | 2011-03-18 01:33:34 | [diff] [blame^] | 5 | #include "content/renderer/renderer_webidbcursor_impl.h" |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 6 | |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 7 | #include "chrome/renderer/render_thread.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 8 | #include "content/common/indexed_db_messages.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 9 | #include "content/renderer/indexed_db_dispatcher.h" |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 10 | |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 11 | using WebKit::WebExceptionCode; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 12 | using WebKit::WebIDBCallbacks; |
| 13 | using WebKit::WebIDBKey; |
| 14 | using WebKit::WebSerializedScriptValue; |
| 15 | |
| 16 | RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id) |
| 17 | : idb_cursor_id_(idb_cursor_id) { |
| 18 | } |
| 19 | |
| 20 | RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { |
[email protected] | 21f6994 | 2011-01-12 10:40:21 | [diff] [blame] | 21 | // It's not possible for there to be pending callbacks that address this |
| 22 | // object since inside WebKit, they hold a reference to the object wich owns |
| 23 | // this object. But, if that ever changed, then we'd need to invalidate |
| 24 | // any such pointers. |
[email protected] | 2ba871b | 2010-12-13 21:11:00 | [diff] [blame] | 25 | RenderThread::current()->Send(new IndexedDBHostMsg_CursorDestroyed( |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 26 | idb_cursor_id_)); |
| 27 | } |
| 28 | |
| 29 | unsigned short RendererWebIDBCursorImpl::direction() const { |
| 30 | int direction; |
| 31 | RenderThread::current()->Send( |
[email protected] | 2ba871b | 2010-12-13 21:11:00 | [diff] [blame] | 32 | new IndexedDBHostMsg_CursorDirection(idb_cursor_id_, &direction)); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 33 | return direction; |
| 34 | } |
| 35 | |
| 36 | WebIDBKey RendererWebIDBCursorImpl::key() const { |
| 37 | IndexedDBKey key; |
| 38 | RenderThread::current()->Send( |
[email protected] | 2ba871b | 2010-12-13 21:11:00 | [diff] [blame] | 39 | new IndexedDBHostMsg_CursorKey(idb_cursor_id_, &key)); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 40 | return key; |
| 41 | } |
| 42 | |
[email protected] | 849991d | 2011-03-02 22:18:45 | [diff] [blame] | 43 | WebIDBKey RendererWebIDBCursorImpl::primaryKey() const { |
| 44 | IndexedDBKey primaryKey; |
| 45 | RenderThread::current()->Send( |
| 46 | new IndexedDBHostMsg_CursorPrimaryKey(idb_cursor_id_, &primaryKey)); |
| 47 | return primaryKey; |
| 48 | } |
| 49 | |
[email protected] | e7fd1980 | 2010-09-17 11:27:26 | [diff] [blame] | 50 | void RendererWebIDBCursorImpl::value( |
| 51 | WebSerializedScriptValue& webScriptValue, |
| 52 | WebIDBKey& webKey) const { |
| 53 | SerializedScriptValue scriptValue; |
| 54 | IndexedDBKey key; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 55 | RenderThread::current()->Send( |
[email protected] | 2ba871b | 2010-12-13 21:11:00 | [diff] [blame] | 56 | new IndexedDBHostMsg_CursorValue(idb_cursor_id_, &scriptValue, |
| 57 | &key)); |
[email protected] | b7d5744 | 2010-09-17 13:56:47 | [diff] [blame] | 58 | // Only one or the other type should have been "returned" to us. |
| 59 | DCHECK(scriptValue.is_null() != (key.type() == WebIDBKey::InvalidType)); |
[email protected] | e7fd1980 | 2010-09-17 11:27:26 | [diff] [blame] | 60 | webScriptValue = scriptValue; |
[email protected] | e7fd1980 | 2010-09-17 11:27:26 | [diff] [blame] | 61 | webKey = key; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value, |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 65 | WebIDBCallbacks* callbacks, |
| 66 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 67 | IndexedDBDispatcher* dispatcher = |
| 68 | RenderThread::current()->indexed_db_dispatcher(); |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 69 | dispatcher->RequestIDBCursorUpdate(SerializedScriptValue(value), callbacks, |
| 70 | idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void RendererWebIDBCursorImpl::continueFunction(const WebIDBKey& key, |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 74 | WebIDBCallbacks* callbacks, |
| 75 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 76 | IndexedDBDispatcher* dispatcher = |
| 77 | RenderThread::current()->indexed_db_dispatcher(); |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 78 | dispatcher->RequestIDBCursorContinue(IndexedDBKey(key), callbacks, |
| 79 | idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 80 | } |
| 81 | |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 82 | void RendererWebIDBCursorImpl::remove(WebIDBCallbacks* callbacks, |
| 83 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 84 | IndexedDBDispatcher* dispatcher = |
| 85 | RenderThread::current()->indexed_db_dispatcher(); |
[email protected] | 6454c0b | 2010-12-03 15:22:50 | [diff] [blame] | 86 | dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 87 | } |