[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 | |
| 5 | #include "chrome/renderer/renderer_webidbcursor_impl.h" |
| 6 | |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 7 | #include "chrome/common/indexed_db_key.h" |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 8 | #include "chrome/common/render_messages.h" |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 9 | #include "chrome/common/serialized_script_value.h" |
| 10 | #include "chrome/renderer/indexed_db_dispatcher.h" |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 11 | #include "chrome/renderer/render_thread.h" |
| 12 | |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 13 | using WebKit::WebExceptionCode; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 14 | using WebKit::WebIDBCallbacks; |
| 15 | using WebKit::WebIDBKey; |
| 16 | using WebKit::WebSerializedScriptValue; |
| 17 | |
| 18 | RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id) |
| 19 | : idb_cursor_id_(idb_cursor_id) { |
| 20 | } |
| 21 | |
| 22 | RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { |
| 23 | RenderThread::current()->Send(new ViewHostMsg_IDBCursorDestroyed( |
| 24 | idb_cursor_id_)); |
| 25 | } |
| 26 | |
| 27 | unsigned short RendererWebIDBCursorImpl::direction() const { |
| 28 | int direction; |
| 29 | RenderThread::current()->Send( |
| 30 | new ViewHostMsg_IDBCursorDirection(idb_cursor_id_, &direction)); |
| 31 | return direction; |
| 32 | } |
| 33 | |
| 34 | WebIDBKey RendererWebIDBCursorImpl::key() const { |
| 35 | IndexedDBKey key; |
| 36 | RenderThread::current()->Send( |
| 37 | new ViewHostMsg_IDBCursorKey(idb_cursor_id_, &key)); |
| 38 | return key; |
| 39 | } |
| 40 | |
[email protected] | e7fd1980 | 2010-09-17 11:27:26 | [diff] [blame] | 41 | void RendererWebIDBCursorImpl::value( |
| 42 | WebSerializedScriptValue& webScriptValue, |
| 43 | WebIDBKey& webKey) const { |
| 44 | SerializedScriptValue scriptValue; |
| 45 | IndexedDBKey key; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 46 | RenderThread::current()->Send( |
[email protected] | e7fd1980 | 2010-09-17 11:27:26 | [diff] [blame] | 47 | new ViewHostMsg_IDBCursorValue(idb_cursor_id_, &scriptValue, |
| 48 | &key)); |
[email protected] | b7d5744 | 2010-09-17 13:56:47 | [diff] [blame] | 49 | // Only one or the other type should have been "returned" to us. |
| 50 | DCHECK(scriptValue.is_null() != (key.type() == WebIDBKey::InvalidType)); |
[email protected] | e7fd1980 | 2010-09-17 11:27:26 | [diff] [blame] | 51 | webScriptValue = scriptValue; |
[email protected] | e7fd1980 | 2010-09-17 11:27:26 | [diff] [blame] | 52 | webKey = key; |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value, |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 56 | WebIDBCallbacks* callbacks, |
| 57 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 58 | IndexedDBDispatcher* dispatcher = |
| 59 | RenderThread::current()->indexed_db_dispatcher(); |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 60 | dispatcher->RequestIDBCursorUpdate(SerializedScriptValue(value), callbacks, |
| 61 | idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void RendererWebIDBCursorImpl::continueFunction(const WebIDBKey& key, |
[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->RequestIDBCursorContinue(IndexedDBKey(key), callbacks, |
| 70 | idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 71 | } |
| 72 | |
[email protected] | fb033cdc | 2010-10-13 07:19:42 | [diff] [blame] | 73 | void RendererWebIDBCursorImpl::remove(WebIDBCallbacks* callbacks, |
| 74 | WebExceptionCode& ec) { |
[email protected] | 1e2de55 | 2010-09-03 12:15:15 | [diff] [blame] | 75 | IndexedDBDispatcher* dispatcher = |
| 76 | RenderThread::current()->indexed_db_dispatcher(); |
[email protected] | 6454c0b | 2010-12-03 15:22:50 | [diff] [blame^] | 77 | dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec); |
[email protected] | 5196b0cd | 2010-08-11 09:03:52 | [diff] [blame] | 78 | } |